Axiom.Demos.DeferredShadingSystem.MaterialGenerator.GetMaterial C# (CSharp) Méthode

GetMaterial() public méthode

public GetMaterial ( UInt32 permutation ) : Material
permutation System.UInt32
Résultat Axiom.Graphics.Material
        public Material GetMaterial( MaterialPermutation permutation )
        {
            Material material = null;

            // Check input validity
            int totalBits = this._bitNames.Count;
            int totalPerms = 1 << totalBits;
            Debug.Assert( permutation < totalPerms );

            // Check if material/shader permutation already was generated
            if ( this._materialCache.ContainsKey( permutation ) )
            {
                material = this._materialCache[ permutation ];
            }
            else
            {
                // Create it
                Material template = this.GetTemplateMaterial( permutation );
                GpuProgram vertexShader = this.GetVertexShader( permutation );
                GpuProgram fragmentShader = this.GetPixelShader( permutation );

                // Create material name
                StringBuilder name = new StringBuilder( this._materialBaseName );
                for ( int bit = 0; bit < totalBits; bit++ )
                {
                    if ( ( permutation & ( 1 << bit ) ) != 0 )
                    {
                        name.Append( this._bitNames[ bit ] );
                    }
                }

                LogManager.Instance.Write( String.Format( "DeferredShading : Created Material {0}, VertexShader {1}, PixelShader {2}", name, vertexShader.Name, fragmentShader.Name ) );

                // Create material from template, and set shaders

                material = template.Clone( name.ToString() );
                Technique technique = material.GetTechnique( 0 );
                Pass pass = technique.GetPass( 0 );
                pass.SetFragmentProgram( fragmentShader.Name );
                pass.SetVertexProgram( vertexShader.Name );

                // And store it
                this._materialCache.Add( permutation, material );
            }

            return material;
        }