/// <summary>
        ///		Initialize the creation of these core vertex programs.
        /// </summary>
        public static void Initialize()
        {
            // only need to initialize once
            if (!isInitialized)
            {
                string syntax = "";

                // flags for which of the programs use finite extrusion
                bool[] vertexProgramFinite =
                    new bool[] { false, false, false, false, true, true, true, true };

                // flags for which of the programs use debug rendering
                bool[] vertexProgramDebug =
                    new bool[] { false, true, false, true, false, true, false, true };

                // types of lights that each of the programs target
                LightType[] vertexProgramLightTypes =
                    new LightType[] {
                    LightType.Point, LightType.Point,
                    LightType.Directional, LightType.Directional,
                    LightType.Point, LightType.Point,
                    LightType.Directional, LightType.Directional
                };

                // load hardware extrusion programs for point & dir lights
                if (GpuProgramManager.Instance.IsSyntaxSupported("arbvp1"))
                {
                    syntax = "arbvp1";
                }
                else if (GpuProgramManager.Instance.IsSyntaxSupported("vs_1_1"))
                {
                    syntax = "vs_1_1";
                }
                else
                {
                    throw new AxiomException("Vertex programs are supposedly supported, but neither arbvp1 nor vs_1_1 syntaxes are supported.");
                }

                // create the programs
                for (int i = 0; i < programNames.Length; i++)
                {
                    // sanity check to make sure it doesn't already exist
                    if (GpuProgramManager.Instance.GetByName(programNames[i]) == null)
                    {
                        string source = ShadowVolumeExtrudeProgram.GetProgramSource(
                            vertexProgramLightTypes[i], syntax, vertexProgramFinite[i], vertexProgramDebug[i]);

                        // create the program from the static source
                        GpuProgram program =
                            GpuProgramManager.Instance.CreateProgramFromString(
                                programNames[i], source, GpuProgramType.Vertex, syntax);

                        // load the program
                        program.Load();
                    }
                }

                isInitialized = true;
            }
        }
コード例 #2
0
        /// <summary>
        ///    Loads a GPU program from a file of assembly.
        /// </summary>
        /// <remarks>
        ///    This method creates a new program of the type specified as the second parameter.
        ///    As with all types of ResourceManager, this class will search for the file in
        ///    all resource locations it has been configured to look in.
        /// </remarks>
        /// <param name="name">
        ///    Identifying name of the program to load.
        /// </param>
        /// <param name="fileName">
        ///    The file to load.
        /// </param>
        /// <param name="type">
        ///    Type of program to create.
        /// </param>
        /// <param name="syntaxCode">
        ///    Syntax code of the program, i.e. vs_1_1, arbvp1, etc.
        /// </param>
        public virtual GpuProgram Load(string name, string fileName, GpuProgramType type, string syntaxCode)
        {
            GpuProgram program = Create(fileName, type, syntaxCode);

            base.Load(program, 1);
            return(program);
        }
コード例 #3
0
        public void SetProgramName(string name, bool resetParams)
#endif
        {
            if (this.program != null)
            {
                this.program.RemoveListener(this);
                this.recreateParams = true;
            }

            // get a reference to the gpu program
            this.program = GpuProgramManager.Instance.GetByName(name);

            if (this.program == null)
            {
                var progType = this.type == GpuProgramType.Vertex
                                   ? "vertex"
                                   : this.type == GpuProgramType.Geometry ? "geometry" : "fragment";
                throw new AxiomException("Unable to locate {0} program called '{1}'", progType, name);
            }

            // Reset parameters
            if (resetParams || this.parameters == null || this.recreateParams)
            {
                RecreateParameters();
            }

            // Listen in on reload events so we can regenerate params
            this.program.AddListener(this);
        }
コード例 #4
0
        /// <summary>
        ///    Loads a GPU program from a string containing the assembly source.
        /// </summary>
        /// <remarks>
        ///    This method creates a new program of the type specified as the second parameter.
        ///    As with all types of ResourceManager, this class will search for the file in
        ///    all resource locations it has been configured to look in.
        /// </remarks>
        /// <param name="name">
        ///    Name used to identify this program.
        /// </param>
        /// <param name="source">
        ///    Source code of the program to load.
        /// </param>
        /// <param name="type">
        ///    Type of program to create.
        /// </param>
        /// <param name="syntaxCode">
        ///    Syntax code of the program, i.e. vs_1_1, arbvp1, etc.
        /// </param>
        public virtual GpuProgram LoadFromString(string name, string source, GpuProgramType type, string syntaxCode)
        {
            GpuProgram program = Create(name, type, syntaxCode);

            program.Source = source;
            base.Load(program, 1);
            return(program);
        }
コード例 #5
0
        /// <summary>
        ///    Create a new, unloaded GpuProgram from a file of assembly.
        /// </summary>
        /// <remarks>
        ///    Use this method in preference to the 'load' methods if you wish to define
        ///    a GpuProgram, but not load it yet; useful for saving memory.
        /// </remarks>
        /// <param name="name">
        ///    The name of the program.
        /// </param>
        /// <param name="fileName">
        ///    The file to load.
        /// </param>
        /// <param name="syntaxCode">
        ///    Name of the syntax to use for the program, i.e. vs_1_1, arbvp1, etc.
        /// </param>
        /// <returns>
        ///    An unloaded GpuProgram instance.
        /// </returns>
        public virtual GpuProgram CreateProgram(string name, string fileName, GpuProgramType type, string syntaxCode)
        {
            GpuProgram program = Create(name, type, syntaxCode);

            program.SourceFile = fileName;
            Add(program);
            return(program);
        }
コード例 #6
0
        /// <summary>
        ///    Create a new, unloaded GpuProgram from a string of assembly code.
        /// </summary>
        /// <remarks>
        ///    Use this method in preference to the 'load' methods if you wish to define
        ///    a GpuProgram, but not load it yet; useful for saving memory.
        /// </remarks>
        /// <param name="name">
        ///    The name of the program.
        /// </param>
        /// <param name="source">
        ///    The asm source of the program to create.
        /// </param>
        /// <param name="syntaxCode">
        ///    Name of the syntax to use for the program, i.e. vs_1_1, arbvp1, etc.
        /// </param>
        /// <returns>An unloaded GpuProgram instance.</returns>
        public virtual GpuProgram CreateProgramFromString(string name, string source, GpuProgramType type, string syntaxCode)
        {
            GpuProgram program = Create(name, type, syntaxCode);

            program.Source = source;
            Add(program);
            return(program);
        }
コード例 #7
0
 public GpuProgramUsage(GpuProgramUsage oth, Pass parent)
     : base()
 {
     this.type    = oth.type;
     this.parent  = parent;
     this.program = oth.Program;
     // nfz: parameters should be copied not just use a shared ptr to the original
     this.parameters     = new GpuProgramParameters(oth.parameters);
     this.recreateParams = false;
 }
コード例 #8
0
        /// <summary>
        ///    Implementation of Resource.Unload.
        /// </summary>
        protected override void UnloadImpl()
        {
            if (assemblerProgram != null)
            {
                assemblerProgram.Unload();
                assemblerProgram = null;
            }

            // polymorphic unload
            UnloadHighLevel();
        }
コード例 #9
0
        protected override void unload()
        {
            if (this.assemblerProgram != null && this.assemblerProgram != this)
            {
                this.assemblerProgram.Creator.Remove(this.assemblerProgram.Handle);
                this.assemblerProgram = null;
            }

            UnloadHighLevel();
            ResetCompileError();
        }
コード例 #10
0
        /// <summary>
        ///     Gets a GpuProgram with the specified name.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public new GpuProgram GetByName(string name)
        {
            // look for a high level program first
            GpuProgram program = HighLevelGpuProgramManager.Instance.GetByName(name);

            // return if found
            if (program != null)
            {
                return(program);
            }

            // return low level program
            return((GpuProgram)base.GetByName(name));
        }
コード例 #11
0
		private void BindTextureSampler( Program cpuProgram, GpuProgram gpuProgram )
		{
			var gpuParams = gpuProgram.DefaultParameters;
			var progParams = cpuProgram.Parameters;

			//Bind the samplers
			foreach ( var curParam in progParams )
			{
				if ( curParam.IsSampler )
				{
					gpuParams.SetNamedConstant( curParam.Name, curParam.Index );
				}
			}
		}
コード例 #12
0
ファイル: ProgramSet.cs プロジェクト: ryan-bunker/axiom3d
		public void Dispose()
		{
			if ( this.vsCpuProgram != null )
			{
				ProgramManager.Instance.DestroyCpuProgram( this.vsCpuProgram );
				this.vsCpuProgram = null;
			}
			if ( this.psCpuProgram != null )
			{
				ProgramManager.Instance.DestroyCpuProgram( this.psCpuProgram );
				this.psCpuProgram = null;
			}

			this.vsGpuProgram = null;
			this.psGpuProgram = null;
		}
コード例 #13
0
		private void BindTextureSamplers( Program cpuProgram, GpuProgram gpuProgram )
		{
			var gpuParams = gpuProgram.DefaultParameters;
			var progParams = cpuProgram.Parameters;

			//bind the samplers
			foreach ( var curParam in progParams )
			{
				if ( curParam.IsSampler )
				{
					// The optimizer may remove some unnecessary parameters, so we should ignore them
					gpuParams.IgnoreMissingParameters = true;
					gpuParams.SetNamedConstant( curParam.Name, curParam.Index );
				}
			}
		}
コード例 #14
0
        /// <summary>
        ///    Binds the specified GpuProgram to the future rendering operations.
        /// </summary>
        /// <param name="program"></param>
        public override void BindGpuProgram(GpuProgram program)
        {
            GLGpuProgram glProgram = (GLGpuProgram)program;

            glProgram.Bind();

            // store the current program in use for eas unbinding later
            if(glProgram.Type == GpuProgramType.Vertex) {
                currentVertexProgram = glProgram;
            }
            else {
                currentFragmentProgram = glProgram;
            }
        }
コード例 #15
0
        /// <summary>
        ///    Implementation of Resource.Unload.
        /// </summary>
        protected override void UnloadImpl()
        {
            if (assemblerProgram != null) {
                assemblerProgram.Unload();
                assemblerProgram = null;
            }

            // polymorphic unload
            UnloadHighLevel();
        }
コード例 #16
0
		/// <summary>
		///   Bind the auto parameters for a given CPU and GPU program set.
		/// </summary>
		/// <param name="pCpuProgram"> </param>
		/// <param name="pGpuProgram"> </param>
		internal void BindAutoParameters( Program pCpuProgram, GpuProgram pGpuProgram )
		{
			var gpuParams = pGpuProgram.DefaultParameters;
			var progParams = pCpuProgram.Parameters;

			for ( int itParams = 0; itParams < progParams.Count; ++itParams )
			{
				UniformParameter curParam = progParams[ itParams ];

				var gpuConstDef = gpuParams.FindNamedConstantDefinition( curParam.Name );

				if ( gpuConstDef != null )
				{
					if ( curParam.IsAutoConstantParameter )
					{
						if ( curParam.IsAutoConstantRealParameter )
						{
							gpuParams.SetNamedAutoConstantReal( curParam.Name,
							                                    curParam.AutoConstantType,
							                                    curParam.AutoConstantRealData );
						}
						else if ( curParam.IsAutoConstantIntParameter )
						{
							gpuParams.SetNamedAutoConstant( curParam.Name,
							                                curParam.AutoConstantType,
							                                curParam.AutoConstantIntData );
						}
					}
				}
					//Case this is not auto constant - we have to update its variablity ourself.
				else
				{
					gpuConstDef.Variability |= (GpuProgramParameters.GpuParamVariability)curParam.Variablity;

					//update variability in the float map.
					if ( gpuConstDef.IsSampler == false )
					{
						var floatLogical = gpuParams.FloatLogicalBufferStruct;
						if ( floatLogical != null )
						{
							for ( int i = 0; i < floatLogical.Map.Count; i++ )
							{
								if ( floatLogical.Map[ i ].PhysicalIndex == gpuConstDef.PhysicalIndex )
								{
									floatLogical.Map[ i ].Variability |= gpuConstDef.Variability;
									break;
								}
							}
						}
					}
				}
			}
		}
コード例 #17
0
        public override void BindGpuProgram(GpuProgram program)
        {
            switch(program.Type) {
                case GpuProgramType.Vertex:
                    VertexShader vertexShader = ((D3DVertexProgram)program).VertexShader;

                    if (cache.vertexShader != vertexShader) {
                        cache.vertexShader = vertexShader;
                        device.VertexShader = vertexShader;
                    }
                    break;

                case GpuProgramType.Fragment:
                    PixelShader pixelShader = ((D3DFragmentProgram)program).PixelShader;

                    if (cache.pixelShader != pixelShader) {
                        cache.pixelShader = pixelShader;
                        device.PixelShader = pixelShader;
                    }
                    break;
            }

            base.BindGpuProgram(program);
        }
コード例 #18
0
ファイル: ProgramManager.cs プロジェクト: ryan-bunker/axiom3d
		private void DestroyGpuProgram( GpuProgram gpuProgram )
		{
			string programName = gpuProgram.Name;
			Resource res = HighLevelGpuProgramManager.Instance.GetByName( programName );

			if ( res != null )
			{
				HighLevelGpuProgramManager.Instance.Remove( programName );
			}
		}
コード例 #19
0
ファイル: OceanSample.cs プロジェクト: ryan-bunker/axiom3d
		/// <summary>
		/// 
		/// </summary>
		/// <param name="pageNum"></param>
		protected void ChangePage( int pageNum )
		{
			if ( this.materialControlsContainer.Count == 0 )
			{
				return;
			}

			this.currentPage = ( pageNum == -1 ) ? ( this.currentPage + 1 )%this.numPages : pageNum;

			string pageText = string.Format( "Parameters {0} / {1}", this.currentPage + 1, this.numPages );
			( (Button)TrayManager.GetWidget( "PageButtonControl" ) ).Caption = pageText;

			if ( this.activeMaterial != null && this.activeMaterial.SupportedTechniques.Count > 0 )
			{
				Technique currentTechnique = this.activeMaterial.SupportedTechniques[ 0 ];
				if ( currentTechnique != null )
				{
					this.activePass = currentTechnique.GetPass( 0 );
					if ( this.activePass != null )
					{
						if ( this.activePass.HasFragmentProgram )
						{
							this.activeFragmentProgram = this.activePass.FragmentProgram;
							this.activeFragmentParameters = this.activePass.FragmentProgramParameters;
						}
						if ( this.activePass.HasVertexProgram )
						{
							this.activeVertexProgram = this.activePass.VertexProgram;
							this.activeVertexParameters = this.activePass.VertexProgramParameters;
						}

						int activeControlCount = this.materialControlsContainer[ this.currentMaterial ].ShaderControlsCount;

						int startControlIndex = this.currentPage*ControlsPerPage;
						int numControls = activeControlCount - startControlIndex;
						if ( numControls <= 0 )
						{
							this.currentPage = 0;
							startControlIndex = 0;
							numControls = activeControlCount;
						}

						for ( int i = 0; i < ControlsPerPage; i++ )
						{
							Slider shaderControlSlider = this.shaderControls[ i ];
							if ( i < numControls )
							{
								shaderControlSlider.Show();

								int controlIndex = startControlIndex + i;
								ShaderControl activeShaderDef =
									this.materialControlsContainer[ this.currentMaterial ].GetShaderControl( controlIndex );
								shaderControlSlider.SetRange( activeShaderDef.MinVal, activeShaderDef.MaxVal, 50, false );
								shaderControlSlider.Caption = activeShaderDef.Name;
								shaderControlSlider.SliderMoved += new SliderMovedHandler( shaderControlSlider_SliderMoved );
								float uniformVal = 0.0f;
								switch ( activeShaderDef.Type )
								{
									case ShaderType.GpuVertex:
									case ShaderType.GpuFragment:
									{
										GpuProgramParameters activeParameters = ( activeShaderDef.Type == ShaderType.GpuVertex )
										                                        	? this.activeVertexParameters
										                                        	: this.activeFragmentParameters;

										if ( activeParameters != null )
										{
											throw new NotImplementedException( "Fix this" );
											//int idx = activeParameters.GetParamIndex( activeShaderDef.ParamName );
											//activeShaderDef.PhysicalIndex = idx;

											//uniformVal = activeParameters.GetNamedFloatConstant( activeShaderDef.ParamName ).val[ activeShaderDef.ElementIndex ];
										}
									}
										break;
									case ShaderType.MatSpecular:
									{
										// get the specular values from the material pass
										ColorEx oldSpec = this.activePass.Specular;
										int x = activeShaderDef.ElementIndex;
										uniformVal = x == 0 ? oldSpec.r : x == 1 ? oldSpec.g : x == 2 ? oldSpec.b : x == 3 ? oldSpec.a : 0;
									}
										break;
									case ShaderType.MatDiffuse:
									{
										// get the specular values from the material pass
										ColorEx oldSpec = this.activePass.Diffuse;
										int x = activeShaderDef.ElementIndex;
										uniformVal = x == 0 ? oldSpec.r : x == 1 ? oldSpec.g : x == 2 ? oldSpec.b : x == 3 ? oldSpec.a : 0;
									}
										break;
									case ShaderType.MatAmbient:
									{
										// get the specular values from the material pass
										ColorEx oldSpec = this.activePass.Ambient;
										int x = activeShaderDef.ElementIndex;
										uniformVal = x == 0 ? oldSpec.r : x == 1 ? oldSpec.g : x == 2 ? oldSpec.b : x == 3 ? oldSpec.a : 0;
									}
										break;
									case ShaderType.MatShininess:
									{
										// get the specular values from the material pass
										uniformVal = this.activePass.Shininess;
									}
										break;
								}
								shaderControlSlider.Value = uniformVal;
							}
						}
					}
				}
			}
		}
コード例 #20
0
		public override void BindGpuProgram( GpuProgram program )
		{
			if ( program == null )
			{
				throw new AxiomException( "Null program bound." );
			}

			var glprg = program as GLES2GpuProgram;
			// Unbind previous gpu program first.
			//
			// Note:
			//  1. Even if both previous and current are the same object, we can't
			//     bypass re-bind completely since the object itself may be modified.
			//     But we can bypass unbind based on the assumption that object
			//     internally GL program type shouldn't be changed after it has
			//     been created. The behavior of bind to a GL program type twice
			//     should be same as unbind and rebind that GL program type, even
			//     for different objects.
			//  2. We also assumed that the program's type (vertex or fragment) should
			//     not be changed during it's in using. If not, the following switch
			//     statement will confuse GL state completely, and we can't fix it
			//     here. To fix this case, we must coding the program implementation
			//     itself, if type is changing (during load/unload, etc), and it's in use,
			//     unbind and notify render system to correct for its state.
			//
			switch ( glprg.Type )
			{
				case GpuProgramType.Vertex:
					if ( this.currentVertexProgram != glprg )
					{
						if ( this.currentVertexProgram != null )
						{
							this.currentVertexProgram.UnbindProgram();
						}
						this.currentVertexProgram = glprg;
					}
					break;
				case GpuProgramType.Fragment:
					if ( this.currentFragmentProgram != glprg )
					{
						if ( this.currentFragmentProgram != null )
						{
							this.currentFragmentProgram.UnbindProgram();
						}
						this.currentFragmentProgram = glprg;
					}
					break;
				case GpuProgramType.Geometry:
				default:
					break;
			}

			glprg.BindProgram();
			base.BindGpuProgram( program );
		}
コード例 #21
0
        public override void BindGpuProgram( GpuProgram program )
        {
            switch ( program.Type )
            {
                case GpuProgramType.Vertex:
                    ActiveD3D9Device.VertexShader = ( (D3DVertexProgram)program ).VertexShader;
                    break;

                case GpuProgramType.Fragment:
                    ActiveD3D9Device.PixelShader = ((D3DFragmentProgram)program).PixelShader;
                    break;

                case GpuProgramType.Geometry:
                    throw new AxiomException( "Geometry shaders not supported with D3D9" );
            }

            // Make sure texcoord index is equal to stage value, As SDK Doc suggests:
            // "When rendering using vertex shaders, each stage's texture coordinate index must be set to its default value."
            // This solves such an errors when working with the Debug runtime -
            // "Direct3D9: (ERROR) :Stage 1 - Texture coordinate index in the stage must be equal to the stage index when programmable vertex pipeline is used".
            for (var nStage=0; nStage < 8; ++nStage)
                SetTextureStageState(nStage, TextureStage.TexCoordIndex, nStage);

            base.BindGpuProgram( program );
        }
コード例 #22
0
ファイル: GpuProgramUsage.cs プロジェクト: WolfgangSt/axiom
 public GpuProgramUsage(GpuProgramUsage oth, Pass parent)
 {
     type = oth.type;
     this.parent = parent;
     program = oth.Program;
     // nfz: parameters should be copied not just use a shared ptr to the original
     parameters = new GpuProgramParameters( oth.parameters );
     recreateParams = false;
 }
コード例 #23
0
ファイル: GpuProgramUsage.cs プロジェクト: WolfgangSt/axiom
        public void SetProgramName(string name, bool resetParams = true)
        {

            if ( program != null )
            {
                // Listener not in place, yet
                //program.RemoveListener( this );
                //recreateParams = true;
            }

            // get a reference to the gpu program
            program = GpuProgramManager.Instance.GetByName(name);

            if ( program == null )
            {
                throw new Exception(string.Format("Unable to locate gpu program named '{0}'", name));
            }

            // Reset parameters 
            if ( resetParams || parameters == null || recreateParams )
            {
                RecreateParameters();
            }

            // Listener not in place, yet
            // Listen in on reload events so we can regenerate params
            //program.AddListener( this );

        }
コード例 #24
0
		private void BindSubShaders( Program program, GpuProgram gpuProgram )
		{
			if ( program.DependencyCount > 0 )
			{
				// Get all attached shaders so we do not attach shaders twice.
				// maybe GLSLProgram should take care of that ( prevent add duplicate shaders )
				string attachedShaders = string.Empty; //TODO: gpuProgram.GetParameter("attach");
				string subSharedDef = string.Empty;

				for ( int i = 0; i < program.DependencyCount; i++ )
				{
					// Here we append _VS and _FS to the library shaders (so max each lib shader
					// is compiled twice once as vertex and once as fragment shader)

					string subShaderName = program.GetDependency( i );
					if ( program.Type == GpuProgramType.Vertex )
					{
						subShaderName += "_VS";
					}
					else
					{
						subShaderName += "_FS";
					}

					//Check if the library shader already compiled
					if ( !HighLevelGpuProgramManager.Instance.ResourceExists( subShaderName ) )
					{
						//Create the library shader
						HighLevelGpuProgram subGpuProgram =
							HighLevelGpuProgramManager.Instance.CreateProgram( subShaderName,
							                                                   ResourceGroupManager.
							                                                   	DefaultResourceGroupName,
							                                                   TargetLanguage, program.Type );

						//Set the source name
						string sourceName = program.GetDependency( i ) + "." + TargetLanguage;
						subGpuProgram.SourceFile = sourceName;

						//If we have compiler errors than stop processing
						if ( subGpuProgram.HasCompileError )
						{
							throw new AxiomException( "Could not compile shader library from the source file: " +
							                          sourceName );
						}

						this.libraryPrograms.Add( subShaderName );
					}

					//Check if the lib shader already attached to this shader
					if ( attachedShaders.Contains( subShaderName ) )
					{
						subSharedDef += subShaderName + " ";
					}
				}

				//Check if we have something to attach
				if ( subSharedDef.Length > 0 )
				{
					var nvpl = new Axiom.Collections.NameValuePairList();
					nvpl.Add( "attach", subSharedDef );
					gpuProgram.SetParameters( nvpl );
				}
			}
		}
コード例 #25
0
 /// <summary>
 ///    Binds a given GpuProgram (but not the parameters). 
 /// </summary>
 /// <remarks>
 ///    Only one GpuProgram of each type can be bound at once, binding another
 ///    one will simply replace the existing one.
 /// </remarks>
 /// <param name="program"></param>
 public virtual void BindGpuProgram(GpuProgram program)
 {
     switch (program.Type) {
         case GpuProgramType.Vertex:
             vertexProgramBound = true;
             break;
         case GpuProgramType.Fragment:
             fragmentProgramBound = true;
             break;
     }
 }
コード例 #26
0
ファイル: GLESRenderSystem.cs プロジェクト: WolfgangSt/axiom
		/// <summary>
		/// 
		/// </summary>
		/// <param name="program"></param>
		public override void BindGpuProgram( GpuProgram program )
		{
			//not implemented
		}
コード例 #27
0
		/// <summary>
		/// Binds a given GpuProgram (but not the parameters). 
		/// </summary>
		/// <remarks>
		/// Only one GpuProgram of each type can be bound at once, binding another
		/// one will simply replace the existing one.
		/// </remarks>
		public override void BindGpuProgram(GpuProgram program)
		{
			if (program == null)
				return;
			// TODO: Set shaders
			switch (program.Type)
			{
				case GpuProgramType.Vertex:
					if (program.IsSkeletalAnimationIncluded)
					{
						useSkinnedEffect = true;
						//LogManager.Instance.Write("Using Skinning Effect.");
						var fx1 = ((XnaVertexProgram)program).Effect as SkinnedEffect;
						if (fx1 == null)
							LogManager.Instance.Write(LogMessageLevel.Normal, false, "Can't get a SkinnedEffect from XnaVertexProgram");
						else
							skinnedEffect = fx1;
					}
					else                       
					{
						useSkinnedEffect = false;
						var fx2 = ((XnaVertexProgram)program).Effect as BasicEffect;
						if (fx2 == null)
							LogManager.Instance.Write(LogMessageLevel.Normal, false, "Can't get a BasicEffect from XnaVertexProgram");
						else
							basicEffect = fx2;
					}
#if SILVERLIGHT
					_device.SetPixelShader(((XnaVertexProgram)program).Effect.PixelShader());
#else
#endif
					break;
				case GpuProgramType.Fragment:
					var fx3 = ((XnaFragmentProgram)program).Effect as BasicEffect;
					if (fx3 == null)
						LogManager.Instance.Write(LogMessageLevel.Normal, false, "Can't get a BasicEffect from XnaFragmentProgram");
					else
						basicEffect = fx3;
#if SILVERLIGHT
					_device.SetVertexShader(((XnaFragmentProgram)program).Effect.VertexShader());
#else
#endif
					break;
				case GpuProgramType.Geometry:
					throw new AxiomException("Geometry shaders not supported with XNA");
			}

			/*
			switch ( program.Type )
			{
				case GpuProgramType.Vertex:
					_device.VertexShader = ( (XnaVertexProgram)program ).VertexShader;
					VertexShaderIsSet = true;
					break;

				case GpuProgramType.Fragment:
					_device.PixelShader = ( (XnaFragmentProgram)program ).PixelShader;
					PixelShaderIsSet = true;
					break;
			}
			 */
			base.BindGpuProgram(program);
		}
コード例 #28
0
		public void SetProgramName( string name, bool resetParams )
#endif
		{
			if ( this.program != null )
			{
				this.program.RemoveListener( this );
				this.recreateParams = true;
			}

			// get a reference to the gpu program
			this.program = GpuProgramManager.Instance.GetByName( name );

			if ( this.program == null )
			{
				var progType = this.type == GpuProgramType.Vertex
				               	? "vertex"
				               	: this.type == GpuProgramType.Geometry ? "geometry" : "fragment";
				throw new AxiomException( "Unable to locate {0} program called '{1}'", progType, name );
			}

			// Reset parameters 
			if ( resetParams || this.parameters == null || this.recreateParams )
			{
				RecreateParameters();
			}

			// Listen in on reload events so we can regenerate params
			this.program.AddListener( this );
		}