Axiom.Graphics.Material.GetBestTechnique C# (CSharp) Method

GetBestTechnique() public method

public GetBestTechnique ( int lodIndex, IRenderable renderable ) : Technique
lodIndex int
renderable IRenderable
return Technique
		public Technique GetBestTechnique( int lodIndex, IRenderable renderable )
		{
			Technique technique = null;
			Dictionary<int, Technique> lodTechniques;

			if ( this.SupportedTechniques.Count > 0 )
			{
				if ( !this.bestTechniquesByScheme.ContainsKey( MaterialManager.Instance.ActiveSchemeIndex ) )
				{
					technique = MaterialManager.Instance.ArbitrateMissingTechniqueForActiveScheme( this,
																								   lodIndex,
																								   renderable );
					if ( technique != null )
					{
						return technique;
					}

					// Nope, use default
					// get the first item, will be 0 (the default) if default
					// scheme techniques exist, otherwise the earliest defined
					Dictionary<ushort, Dictionary<int, Technique>>.Enumerator iter = this.bestTechniquesByScheme.GetEnumerator();
					if ( iter.Current.Value == null )
						iter.MoveNext();

					lodTechniques = iter.Current.Value;
				}
				else
				{
					lodTechniques = this.bestTechniquesByScheme[ MaterialManager.Instance.ActiveSchemeIndex ];
				}

				if ( !lodTechniques.ContainsKey( lodIndex ) )
				{
					while ( lodIndex >= 0 || !lodTechniques.ContainsKey( lodIndex ) )
					{
						lodIndex--;
					}

					if ( lodIndex >= 0 )
					{
						technique = lodTechniques[ lodIndex ];
					}
				}
				else
				{
					technique = lodTechniques[ lodIndex ];
				}
			}
			return technique;
		}

Same methods

Material::GetBestTechnique ( ) : Technique
Material::GetBestTechnique ( int lodIndex ) : Technique

Usage Example

 /// <summary>
 /// Set up the rendering for a tree type.  Should be called once per tree type(master trees).
 /// </summary>
 public int SetupRenderMaterial(Material mat, bool setPosition)
 {
     int index = 0;
     if (meterRenderingOfTrees)
     {
         loadMaterialMeter.Enter();
     }
     // mvsm.SetTreeRenderPass() is a special version of SetPass() that just sets the stuff we need for tree rendering
     Pass usedPass = ((Axiom.SceneManagers.Multiverse.SceneManager)TerrainManager.Instance.SceneManager).SetTreeRenderPass(mat.GetBestTechnique(0).GetPass(0), forest);
     if ( setPosition && usedPass.HasVertexProgram )
     {
         index =  usedPass.VertexProgramParameters.GetParamIndex("g_vTreePosition");
     }
     if (meterRenderingOfTrees)
     {
         loadMaterialMeter.Exit();
     }
     return index;
 }