This class makes the usage of a vertex and fragment programs (low-level or high-level), with a given set of parameters, explicit.
Using a vertex or fragment program can get fairly complex; besides the fairly rudimentary process of binding a program to the GPU for rendering, managing usage has few complications, such as:
  • Programs can be high level (e.g. Cg, GLSlang) or low level (assembler). Using either should be relatively seamless, although high-level programs give you the advantage of being able to use named parameters, instead of just indexed registers
  • Programs and parameters can be shared between multiple usages, in order to save memory
  • When you define a user of a program, such as a material, you often want to be able to set up the definition but not load / compile / assemble the program at that stage, because it is not needed just yet. The program should be loaded when it is first needed, or earlier if specifically requested. The program may not be defined at this time, you may want to have scripts that can set up the definitions independent of the order in which those scripts are loaded.
This class packages up those details so you don't have to worry about them. For example, this class lets you define a high-level program and set up the parameters for it, without having loaded the program (which you normally could not do). When the program is loaded and compiled, this class will then validate the parameters you supplied earlier and turn them into runtime parameters.

Just incase it wasn't clear from the above, this class provides linkage to both GpuProgram and HighLevelGpuProgram, despite its name.

Inheritance: DisposableObject, Resource.IListener
        /// <summary>
        ///		Creates and returns a copy of this GpuProgramUsage object.
        /// </summary>
        /// <returns></returns>
        public GpuProgramUsage Clone()
        {
            GpuProgramUsage usage = new GpuProgramUsage(type);

            usage.program    = program;
            usage.parameters = parameters.Clone();

            return(usage);
        }
Ejemplo n.º 2
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;
 }
        /// <summary>
        ///		Creates and returns a copy of this GpuProgramUsage object.
        /// </summary>
        /// <returns></returns>
        public GpuProgramUsage Clone()
        {
            GpuProgramUsage usage = new GpuProgramUsage(type);
            usage.program = program;
            usage.parameters = parameters.Clone();

            return usage;
        }
Ejemplo n.º 4
0
		/// <summary>
		/// </summary>
		public void SetShadowReceiverVertexProgram( string name )
		{
			// turn off vertex programs when the name is set to null
			if ( name.Length == 0 )
			{
				_shadowReceiverVertexProgramUsage = null;
			}
			else
			{
				// create a new usage object
				if ( !this.HasShadowReceiverVertexProgram )
				{
					_shadowReceiverVertexProgramUsage = new GpuProgramUsage( GpuProgramType.Vertex );
				}

				_shadowReceiverVertexProgramUsage.ProgramName = name;
			}

			// needs recompilation
			_parent.NotifyNeedsRecompile();
		}
Ejemplo n.º 5
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"></param>
		/// <param name="resetParams"></param>
		public void SetGeometryProgram( string name, bool resetParams )
		{
			// turn off fragment programs when the name is set to null
			if ( name.Length == 0 )
			{
				_geometryProgramUsage = null;
			}
			else
			{
				// create a new usage object
				if ( !this.HasGeometryProgram )
				{
					_geometryProgramUsage = new GpuProgramUsage( GpuProgramType.Geometry );
				}

				_geometryProgramUsage.ProgramName = name;
			}

			// needs recompilation
			_parent.NotifyNeedsRecompile();
		}
 public HLSLFixedFunctionProgram()
 {
     vertexProgramUsage = new GpuProgramUsage( GpuProgramType.Vertex, null );
     fragmentProgramUsage = new GpuProgramUsage( GpuProgramType.Fragment, null );
     fixedFunctionState = new FixedFunctionState();
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="resetParams"></param>
        public void SetVertexProgram(string name, bool resetParams)
        {
            // turn off vertex programs when the name is set to null
            if(name.Length == 0) {
                vertexProgramUsage = null;
            }
            else {
                // create a new usage object
                if(!this.HasVertexProgram) {
                    vertexProgramUsage = new GpuProgramUsage(GpuProgramType.Vertex);
                }

                vertexProgramUsage.ProgramName = name;
            }

            // needs recompilation
            parent.NotifyNeedsRecompile();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="resetParams"></param>
        public void SetShadowCasterFragmentProgram(string name)
        {
            // turn off fragment programs when the name is set to null
            if (name.Length == 0)
            {
                shadowCasterFragmentProgramUsage = null;
            }
            else
            {
                // create a new usage object
                if (!this.HasShadowCasterFragmentProgram)
                {
                    shadowCasterFragmentProgramUsage = new GpuProgramUsage(GpuProgramType.Fragment);
                }

                shadowCasterFragmentProgramUsage.ProgramName = name;
            }

            // needs recompilation
            parent.NotifyNeedsRecompile();
        }
Ejemplo n.º 10
0
		public void SetShadowCasterVertexProgram( string name )
		{
			// turn off vertex programs when the name is set to null
			if ( name.Length == 0 )
			{
				this.shadowCasterVertexProgramUsage = null;
			}
			else
			{
				// create a new usage object
				if ( !HasShadowCasterVertexProgram )
				{
					this.shadowCasterVertexProgramUsage = new GpuProgramUsage( GpuProgramType.Vertex, this );
				}

				this.shadowCasterVertexProgramUsage.SetProgramName( name );
			}

			// needs recompilation
			this._parent.NotifyNeedsRecompile();
		}
Ejemplo n.º 11
0
		public void SetVertexProgram( string name, bool resetParams )
#endif
		{
			lock ( _gpuProgramChangeMutex )
			{
				if ( VertexProgramName == name )
				{
					return;
				}

				// turn off vertex programs when the name is set to null
				if ( string.IsNullOrEmpty( name ) )
				{
					this._vertexProgramUsage.SafeDispose();
					this._vertexProgramUsage = null;
				}
				else
				{
					// create a new usage object
					if ( !HasVertexProgram )
					{
						this._vertexProgramUsage = new GpuProgramUsage( GpuProgramType.Vertex, this );
					}

					this._vertexProgramUsage.SetProgramName( name, resetParams );
				}

				// needs recompilation
				this._parent.NotifyNeedsRecompile();

				//TODO
				//if( Pass::getHashFunction() == Pass::getBuiltinHashFunction( Pass::MIN_GPU_PROGRAM_CHANGE ) )
				//    _dirtyHash();
			}
		}
Ejemplo n.º 12
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"></param>
		/// <param name="resetParams"></param>
		public void SetFragmentProgram( string name, bool resetParams )
		{
			// turn off fragment programs when the name is set to null
			if ( name.Length == 0 )
			{
				this._fragmentProgramUsage = null;
			}
			else
			{
				// create a new usage object
				if ( !HasFragmentProgram )
				{
					this._fragmentProgramUsage = new GpuProgramUsage( GpuProgramType.Fragment, this );
				}

				this._fragmentProgramUsage.SetProgramName( name, resetParams );
			}

			// needs recompilation
			this._parent.NotifyNeedsRecompile();
		}