/// <summary> /// Creates a new parameters object compatible with this program definition. /// </summary> /// <remarks> /// Unlike low-level assembly programs, parameters objects are specific to the /// program and therefore must be created from it rather than by the /// HighLevelGpuProgramManager. This method creates a new instance of a parameters /// object containing the definition of the parameters this program understands. /// </remarks> /// <returns>A new set of program parameters.</returns> public override GpuProgramParameters CreateParameters() { // create and load named parameters GpuProgramParameters newParams = GpuProgramManager.Instance.CreateParameters(); // Only populate named parameters if we can support this program if (IsSupported) { LoadHighLevel(); // Errors during load may have prevented compile if (IsSupported) { PopulateParameterNames(newParams); } } // copy in default parameters if present if (defaultParams != null) { newParams.CopyConstantsFrom(defaultParams); } return(newParams); }
public UniformParameter( GpuProgramParameters.AutoConstantType autoConstantType, Real autoConstantData, int size, GpuProgramParameters.GpuConstantType type ) : base( Parameter.AutoParameters[ autoConstantType ].Type, Parameter.AutoParameters[ autoConstantType ].Name, SemanticType.Unknown, -1, ContentType.Unknown, size ) { AutoShaderParameter parameterDef = Parameter.AutoParameters[ autoConstantType ]; _name = parameterDef.Name; if ( autoConstantData != 0.0 ) { _name += autoConstantData.ToString(); //replace possible illegal point character in name _name = _name.Replace( '.', '_' ); } _type = type; _semantic = SemanticType.Unknown; _index = -1; _content = Parameter.ContentType.Unknown; this.isAutoConstantReal = true; this.isAutoConstantInt = false; this.autoConstantType = autoConstantType; this.autoConstantRealData = autoConstantData; this.variability = (int)GpuProgramParameters.GpuParamVariability.Global; this._params = null; this.physicalIndex = -1; _size = size; }
protected virtual void PopulateParameterNames(GpuProgramParameters parms) { var defs = ConstantDefinitions; // Axiom: Ogre has SIDE EFFECT here!! parms.NamedConstants = constantDefs; // also set logical / physical maps for programs which use this parms.SetLogicalIndexes(floatLogicalToPhysical, intLogicalToPhysical); }
public override void BindParameters(GpuProgramParameters parameters) { // activate the link program object GLSLLinkProgram linkProgram = GLSLLinkProgramManager.Instance.ActiveLinkProgram; // pass on parameters from params to program object uniforms linkProgram.UpdateUniforms(parameters); }
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; }
public UniformParameter( GpuProgramParameters.GpuConstantType type, string name, SemanticType semantic, int index, ContentType content, int variability, int size ) : base( type, name, semantic, index, content, size ) { this.isAutoConstantInt = false; this.isAutoConstantReal = false; this.autoConstantIntData = 0; this.variability = variability; this._params = null; this.physicalIndex = -1; }
/// <summary> /// Creates a new parameters object compatible with this program definition. /// </summary> /// <remarks> /// It is recommended that you use this method of creating parameters objects /// rather than going direct to GpuProgramManager, because this method will /// populate any implementation-specific extras (like named parameters) where /// they are appropriate. /// </remarks> /// <returns></returns> public virtual GpuProgramParameters CreateParameters() { GpuProgramParameters newParams = GpuProgramManager.Instance.CreateParameters(); // copy the default parameters if they exist if (defaultParams != null) { newParams.CopyConstantsFrom(defaultParams); } return(newParams); }
public void SetConstantFloatArray() { float[] expected = new[] { (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom() }; float[] actual; GpuProgramParameters parameters = new GpuProgramParameters(); //var floatLogical = new GpuLogicalBufferStruct(); //parameters._setLogicalIndexes( floatLogical, new GpuLogicalBufferStruct() ); parameters.SetConstant( 0, expected ); Assert.IsTrue( parameters.GetFloatConstant( 0 ).isSet ); actual = parameters.GetFloatConstant( 0 ).val; Assert.AreEqual( expected, actual ); }
/// <summary> /// Binds named parameters to fp30 programs. /// </summary> /// <param name="parms"></param> public override void BindParameters(GpuProgramParameters parms) { if(parms.HasFloatConstants) { for(int index = 0; index < parms.FloatConstantCount; index++) { string name = parms.GetNameByIndex(index); if(name != null) { GpuProgramParameters.FloatConstantEntry entry = parms.GetFloatConstant(index); // send the params 4 at a time Gl.glProgramNamedParameter4fvNV(programId, name.Length, name, entry.val); } } } }
protected void RecreateParameters() { // Keep a reference to old ones to copy var savedParams = this.parameters; // Create new params this.parameters = this.program.CreateParameters(); // Copy old (matching) values across // Don't use copyConstantsFrom since program may be different if (savedParams != null) { this.parameters.CopyMatchingNamedConstantsFrom(savedParams); } this.recreateParams = false; }
/// <summary> /// Called to pass parameters to the Nvparse program. /// </summary> /// <param name="parms"></param> public override void BindParameters(GpuProgramParameters parms) { // Register combiners uses 2 constants per texture stage (0 and 1) // We have stored these as (stage * 2) + const_index if(parms.HasFloatConstants) { for(int index = 0; index < parms.FloatConstantCount; index++) { GpuProgramParameters.FloatConstantEntry entry = parms.GetFloatConstant(index); if(entry.isSet) { int combinerStage = Gl.GL_COMBINER0_NV + (index / 2); int pname = Gl.GL_CONSTANT_COLOR0_NV + (index % 2); // send the params 4 at a time Gl.glCombinerStageParameterfvNV(combinerStage, pname, entry.val); } } } }
/// <summary> /// Resolve uniform auto constant parameter with associated real data of this program /// </summary> /// <param name="autoType"> The auto type of the desired parameter </param> /// <param name="data"> The data to associate with the auto parameter </param> /// <param name="size"> number of elements in the parameter </param> /// <returns> parameter instance in case of that resolve operation succeeded, otherwise null </returns> public UniformParameter ResolveAutoParameterReal( GpuProgramParameters.AutoConstantType autoType, Real data, int size ) { UniformParameter param = null; //check if parameter already exists. param = GetParameterByAutoType( autoType ); if ( param != null ) { if ( param.IsAutoConstantRealParameter && param.AutoConstantRealData == data ) { param.Size = Axiom.Math.Utility.Max( size, param.Size ); return param; } } //Create new parameter param = new UniformParameter( autoType, data, size ); AddParameter( param ); return param; }
protected override void load() { // load from file and get the source string from it if (LoadFromFile) { var stream = ResourceGroupManager.Instance.OpenResource(this.fileName, Group, true, this); var reader = new StreamReader(stream, System.Text.Encoding.UTF8); this.source = reader.ReadToEnd(); } // Call polymorphic load try { LoadFromSource(); if (this.defaultParams != null) { // Keep a reference to old ones to copy var savedParams = this.defaultParams; // reset params to stop them being referenced in the next create // _defaultParams.SetNull(); // Create new params this.defaultParams = CreateParameters(); // Copy old (matching) values across // Don't use copyConstantsFrom since program may be different this.defaultParams.CopyMatchingNamedConstantsFrom(savedParams); } } catch (Exception ex) { LogManager.Instance.Write( "Gpu program {0} encountered an error during loading and is thus not supported. Details: {1}", Name, ex.Message); this.compileError = true; } }
public override void BindProgramParameters( GpuProgramParameters parms, GpuProgramParameters.GpuParamVariability mask ) { // only supports float constants var floatStruct = parms.FloatLogicalBufferStruct; foreach ( var i in floatStruct.Map ) { if ( ( i.Value.Variability & mask ) != 0 ) { var logicalIndex = i.Key; var pFloat = parms.GetFloatPointer( i.Value.PhysicalIndex ).Pointer; // Iterate over the params, set in 4-float chunks (low-level) for ( var j = 0; j < i.Value.CurrentSize; j += 4 ) { Gl.glSetFragmentShaderConstantATI( Gl.GL_CON_0_ATI + logicalIndex, pFloat.Pin() ); pFloat.UnPin(); pFloat += 4; ++logicalIndex; } } } }
public void UpdateCustomGpuParameter(GpuProgramParameters.AutoConstantEntry entry, GpuProgramParameters gpuParams) { if (this.customParams.Count > entry.Data && this.customParams[entry.Data] != null) { gpuParams.SetConstant(entry.PhysicalIndex, (Vector4)this.customParams[entry.Data]); } }
/// <summary> /// Populate the passed parameters with name->index map, must be overridden. /// </summary> /// <param name="parms"></param> protected abstract void PopulateParameterNames(GpuProgramParameters parms);
/// <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; } } } } } }
public void UpdateCustomGpuParameter(GpuProgramParameters.AutoConstantEntry entry, GpuProgramParameters gpuParams) { if (customParams[entry.data] != null) { gpuParams.SetConstant(entry.index, (Vector4)customParams[entry.data]); } }
public void CopyMatchingNamedConstantsFrom(GpuProgramParameters source) { throw new NotImplementedException(); }
public GpuSharedParametersUsage(GpuSharedParameters sharedParams, GpuProgramParameters gparams) { SharedParameters = sharedParams; this._parameters = gparams; InitCopyData(); }
private void InitShadowDebugPass() { Material matDebug = (Material)MaterialManager.Instance[ SHADOW_VOLUMES_MATERIAL ]; if ( matDebug == null ) { // Create matDebug = (Material) MaterialManager.Instance.Create( SHADOW_VOLUMES_MATERIAL, ResourceGroupManager.InternalResourceGroupName ); this.shadowDebugPass = matDebug.GetTechnique( 0 ).GetPass( 0 ); this.shadowDebugPass.SetSceneBlending( SceneBlendType.Add ); this.shadowDebugPass.LightingEnabled = false; this.shadowDebugPass.DepthWrite = false; TextureUnitState t = this.shadowDebugPass.CreateTextureUnitState(); t.SetColorOperationEx( LayerBlendOperationEx.Modulate, LayerBlendSource.Manual, LayerBlendSource.Current, new ColorEx( 0.7f, 0.0f, 0.2f ) ); this.shadowDebugPass.CullingMode = CullingMode.None; if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) ) { ShadowVolumeExtrudeProgram.Initialize(); // Enable the (infinite) point light extruder for now, just to get some params this.shadowDebugPass.SetVertexProgram( ShadowVolumeExtrudeProgram.GetProgramName( ShadowVolumeExtrudeProgram.Programs.PointLight ) ); this.infiniteExtrusionParams = this.shadowDebugPass.VertexProgramParameters; this.infiniteExtrusionParams.SetAutoConstant( 0, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix ); this.infiniteExtrusionParams.SetAutoConstant( 4, GpuProgramParameters.AutoConstantType.LightPositionObjectSpace ); // Note ignored extra parameter - for compatibility with finite extrusion vertex program this.infiniteExtrusionParams.SetAutoConstant( 5, GpuProgramParameters.AutoConstantType.ShadowExtrusionDistance ); } matDebug.Compile(); } else { this.shadowDebugPass = matDebug.GetTechnique( 0 ).GetPass( 0 ); if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) ) { this.infiniteExtrusionParams = this.shadowDebugPass.VertexProgramParameters; } } }
public void UpdateCustomGpuParameter( GpuProgramParameters.AutoConstantEntry entry, GpuProgramParameters gpuParams ) { if ( customParams[ entry.Data ] != null ) { gpuParams.SetConstant( entry.PhysicalIndex, (Vector4)customParams[ entry.Data ] ); } }
public override void BindProgramParameters( GpuProgramParameters parms, GpuProgramParameters.GpuParamVariability mask ) { var type = programType; // only supports float constants var floatStruct = parms.FloatLogicalBufferStruct; foreach ( var i in floatStruct.Map ) { if ( ( i.Value.Variability & mask ) != 0 ) { var logicalIndex = i.Key; var pFloat = parms.GetFloatConstantList(); var ptr = i.Value.PhysicalIndex; { for ( var j = 0; j < i.Value.CurrentSize; j += 4 ) { var x = pFloat[ ptr + j ]; var y = pFloat[ ptr + j + 1 ]; var z = pFloat[ ptr + j + 2 ]; var w = pFloat[ ptr + j + 3 ]; Gl.glProgramLocalParameter4fARB( type, logicalIndex, x, y, z, w ); ++logicalIndex; } } } } }
/// <summary> /// Update a custom GpuProgramParameters constant which is derived from /// information only this Renderable knows. /// </summary> /// <remarks> /// This method allows a Renderable to map in a custom GPU program parameter /// based on it's own data. This is represented by a GPU auto parameter /// of AutoConstants.Custom, and to allow there to be more than one of these per /// Renderable, the 'data' field on the auto parameter will identify /// which parameter is being updated. The implementation of this method /// must identify the parameter being updated, and call a 'SetConstant' /// method on the passed in <see cref="GpuProgramParameters"/> object, using the details /// provided in the incoming auto constant setting to identify the index /// at which to set the parameter. /// </remarks> /// <param name="constant">The auto constant entry referring to the parameter being updated.</param> /// <param name="parameters">The parameters object which this method should call to set the updated parameters.</param> public void UpdateCustomGpuParameter(GpuProgramParameters.AutoConstantEntry constant, GpuProgramParameters parameters) { }
private void MapTypeAndElementSize(int cgType, bool isRegisterCombiner, GpuProgramParameters.GpuConstantDefinition def) { if ( isRegisterCombiner ) { // register combiners are the only single-float entries in our buffer def.ConstantType = GpuProgramParameters.GpuConstantType.Float1; def.ElementSize = 1; } else { switch ( cgType ) { case Cg.CG_FLOAT: case Cg.CG_FLOAT1: case Cg.CG_HALF: case Cg.CG_HALF1: def.ConstantType = GpuProgramParameters.GpuConstantType.Float1; break; case Cg.CG_FLOAT2: case Cg.CG_HALF2: def.ConstantType = GpuProgramParameters.GpuConstantType.Float2; break; case Cg.CG_FLOAT3: case Cg.CG_HALF3: def.ConstantType = GpuProgramParameters.GpuConstantType.Float3; break; case Cg.CG_FLOAT4: case Cg.CG_HALF4: def.ConstantType = GpuProgramParameters.GpuConstantType.Float4; break; case Cg.CG_FLOAT2x2: case Cg.CG_HALF2x2: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X2; break; case Cg.CG_FLOAT2x3: case Cg.CG_HALF2x3: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X3; break; case Cg.CG_FLOAT2x4: case Cg.CG_HALF2x4: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X4; break; case Cg.CG_FLOAT3x2: case Cg.CG_HALF3x2: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X2; break; case Cg.CG_FLOAT3x3: case Cg.CG_HALF3x3: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X3; break; case Cg.CG_FLOAT3x4: case Cg.CG_HALF3x4: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X4; break; case Cg.CG_FLOAT4x2: case Cg.CG_HALF4x2: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_4X2; break; case Cg.CG_FLOAT4x3: case Cg.CG_HALF4x3: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_4X3; break; case Cg.CG_FLOAT4x4: case Cg.CG_HALF4x4: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_4X4; break; case Cg.CG_INT: case Cg.CG_INT1: def.ConstantType = GpuProgramParameters.GpuConstantType.Int1; break; case Cg.CG_INT2: def.ConstantType = GpuProgramParameters.GpuConstantType.Int2; break; case Cg.CG_INT3: def.ConstantType = GpuProgramParameters.GpuConstantType.Int3; break; case Cg.CG_INT4: def.ConstantType = GpuProgramParameters.GpuConstantType.Int4; break; default: def.ConstantType = GpuProgramParameters.GpuConstantType.Unknown; break; } // Cg pads def.ElementSize = GpuProgramParameters.GpuConstantDefinition.GetElementSize( def.ConstantType, true ); } }
public void UpdateCustomGpuParameter(GpuProgramParameters.AutoConstantEntry constant, GpuProgramParameters parameters) { parameters.SetNamedConstant(_scaleFactorName, ScaleFactor); parameters.SetNamedConstant(_fineBlockOriginName, FineBlockOrigin); }
/// <summary> /// Updates program object uniforms using data from GpuProgramParameters. /// normally called by GLSLGpuProgram.BindParameters() just before rendering occurs. /// </summary> /// <param name="parameters">GPU Parameters to use to update the uniforms params.</param> public void UpdateUniforms(GpuProgramParameters parameters) { for(int i = 0; i < uniformReferences.Count; i++) { UniformReference uniformRef = (UniformReference)uniformReferences[i]; GpuProgramParameters.FloatConstantEntry currentFloatEntry = null; GpuProgramParameters.IntConstantEntry currentIntEntry = null; if(uniformRef.isFloat) { currentFloatEntry = parameters.GetNamedFloatConstant(uniformRef.name); if(currentFloatEntry != null) { if(currentFloatEntry.isSet) { switch(uniformRef.elementCount) { case 1: Gl.glUniform1fvARB(uniformRef.location, 1, currentFloatEntry.val); break; case 2: Gl.glUniform2fvARB(uniformRef.location, 1, currentFloatEntry.val); break; case 3: Gl.glUniform3fvARB(uniformRef.location, 1, currentFloatEntry.val); break; case 4: Gl.glUniform4fvARB(uniformRef.location, 1, currentFloatEntry.val); break; } // end switch } } } else { currentIntEntry = parameters.GetNamedIntConstant(uniformRef.name); if(currentIntEntry != null) { if(currentIntEntry.isSet) { switch(uniformRef.elementCount) { case 1: Gl.glUniform1ivARB(uniformRef.location, 1, currentIntEntry.val); break; case 2: Gl.glUniform2ivARB(uniformRef.location, 1, currentIntEntry.val); break; case 3: Gl.glUniform3ivARB(uniformRef.location, 1, currentIntEntry.val); break; case 4: Gl.glUniform4ivARB(uniformRef.location, 1, currentIntEntry.val); break; } // end switch } } } } }
protected override void PopulateParameterNames( GpuProgramParameters parms ) { parms.NamedConstants = ConstantDefinitions; // Don't set logical / physical maps here, as we can't access parameters by logical index in GLHL. }
protected override void PopulateParameterNames(GpuProgramParameters parms) { // Skip the normal implementation // Ensure we don't complain about missing parameter names parms.IgnoreMissingParameters = true; }
public void SetConstantMatrix4() { float[] expected = new[] { (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom(), (float)Utility.SymmetricRandom() }; float[] actual = new float[16]; GpuProgramParameters parameters = new GpuProgramParameters(); //var floatLogical = new GpuLogicalBufferStruct(); //parameters._setLogicalIndexes( floatLogical, new GpuLogicalBufferStruct() ); parameters.SetConstant( 0, new Matrix4( expected[ 0 ], expected[ 1 ], expected[ 2 ], expected[ 3 ], expected[ 4 ], expected[ 5 ], expected[ 6 ], expected[ 7 ], expected[ 8 ], expected[ 9 ], expected[ 10 ], expected[ 11 ], expected[ 12 ], expected[ 13 ], expected[ 14 ], expected[ 15 ] ) ); GpuProgramParameters.FloatConstantEntry fcEntry; for (int i = 0; i < 4; i++) { fcEntry = parameters.GetFloatConstant(i); Assert.IsTrue(fcEntry.isSet); fcEntry.val.CopyTo(actual, i * 4); } Assert.AreEqual( expected, actual ); }
public void CopyConstantsFrom( GpuProgramParameters source ) { this.floatConstants.Clear(); this.floatConstants.AddRange( source.floatConstants ); this.intConstants.Clear(); this.intConstants.AddRange( source.intConstants ); // Iterate over auto parameters // Clear existing auto constants ClearAutoConstants(); this.autoConstants.AddRange( source.autoConstants.Select( x => x.Clone() ) ); this._combinedVariability = source._combinedVariability; CopySharedParamSetUsage( source._sharedParamSets ); }
protected override void PopulateParameterNames( GpuProgramParameters parms ) { // getConstantDefinitions() not needed in Axiom as the getter already does this implicitly parms.SetNamedConstants(ConstantDefinitions); // Don't set logical / physical maps here, as we can't access parameters by logical index in GLHL. }
public void CopyMatchingNamedConstantsFrom( GpuProgramParameters source ) { if ( this._namedConstants == null || source == null ) { return; } var srcToDestNamedMap = new Dictionary<int, string>(); foreach ( var i in source._namedConstants.Map ) { var paramName = i.Key; var olddef = i.Value; var newdef = FindNamedConstantDefinition( paramName, false ); if ( newdef == null ) { continue; } // Copy data across, based on smallest common definition size var srcsz = olddef.ElementSize*olddef.ArraySize; var destsz = newdef.ElementSize*newdef.ArraySize; var sz = Utility.Min( srcsz, destsz ); if ( newdef.IsFloat ) { Memory.Copy( source.GetFloatPointer( olddef.PhysicalIndex ).Pointer, GetFloatPointer( newdef.PhysicalIndex ).Pointer, sz*sizeof ( float ) ); } else { Memory.Copy( source.GetIntPointer( olddef.PhysicalIndex ).Pointer, GetIntPointer( newdef.PhysicalIndex ).Pointer, sz*sizeof ( int ) ); } // we'll use this map to resolve autos later // ignore the [0] aliases if ( !paramName.EndsWith( "[0]" ) ) { srcToDestNamedMap.Add( olddef.PhysicalIndex, paramName ); } } foreach ( var i in source.autoConstants ) { var autoEntry = i; // find dest physical index if ( srcToDestNamedMap.ContainsKey( autoEntry.PhysicalIndex ) ) { var miSecond = srcToDestNamedMap[ autoEntry.PhysicalIndex ]; if ( autoEntry.FData != 0 ) { SetNamedAutoConstantReal( miSecond, autoEntry.Type, autoEntry.FData ); } else { SetNamedAutoConstant( miSecond, autoEntry.Type, autoEntry.Data ); } } } // Copy shared param sets foreach ( var usage in source._sharedParamSets ) { if ( !IsUsingSharedParameters( usage.Name ) ) { AddSharedParameters( usage.SharedParameters ); } } }
public void UpdateAutoParams( AutoParamDataSource source, GpuProgramParameters.GpuParamVariability mask ) { if (HasVertexProgram) { // Update vertex program auto params _vertexProgramUsage.Params.UpdateAutoParams( source, mask ); } if (HasGeometryProgram) { // Update geometry program auto params _geometryProgramUsage.Params.UpdateAutoParams(source, mask); } if (HasFragmentProgram) { // Update fragment program auto params _fragmentProgramUsage.Params.UpdateAutoParams(source, mask); } }
public GpuProgramParameters( GpuProgramParameters other ) : base() { // let compiler perform shallow copies of structures // AutoConstantEntry, RealConstantEntry, IntConstantEntry this.floatConstants = new FloatConstantList( other.floatConstants ); // vector<float> in ogre => shallow copy this.intConstants = new IntConstantList( other.intConstants ); // vector<int> in ogre => shallow copy this.autoConstants = new AutoConstantsList(); // vector<AutoConstantEntry> in ogre => deep copy foreach ( var ac in other.autoConstants ) { this.autoConstants.Add( ac.Clone() ); } // copy value members this.floatLogicalToPhysical = other.floatLogicalToPhysical; // pointer in ogre => no Clone this.intLogicalToPhysical = other.intLogicalToPhysical; // pointer in ogre => no Clone this._namedConstants = other._namedConstants; // pointer in ogre => no Clone CopySharedParamSetUsage( other._sharedParamSets ); this._combinedVariability = other._combinedVariability; TransposeMatrices = other.TransposeMatrices; this.ignoreMissingParameters = other.ignoreMissingParameters; this.activePassIterationIndex = other.activePassIterationIndex; }
protected void PopulateDef( D3D9.ConstantDescription d3DDesc, GpuProgramParameters.GpuConstantDefinition def ) { def.ArraySize = d3DDesc.Elements; switch ( d3DDesc.Type ) { case D3D9.ParameterType.Int: switch ( d3DDesc.Columns ) { case 1: def.ConstantType = GpuProgramParameters.GpuConstantType.Int1; break; case 2: def.ConstantType = GpuProgramParameters.GpuConstantType.Int2; break; case 3: def.ConstantType = GpuProgramParameters.GpuConstantType.Int3; break; case 4: def.ConstantType = GpuProgramParameters.GpuConstantType.Int4; break; } // columns break; case D3D9.ParameterType.Float: switch ( d3DDesc.Class ) { case D3D9.ParameterClass.MatrixColumns: case D3D9.ParameterClass.MatrixRows: { var firstDim = d3DDesc.RegisterCount/d3DDesc.Elements; var secondDim = d3DDesc.Class == D3D9.ParameterClass.MatrixRows ? d3DDesc.Columns : d3DDesc.Rows; switch ( firstDim ) { case 2: switch ( secondDim ) { case 2: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X2; def.ElementSize = 8; // HLSL always packs break; case 3: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X3; def.ElementSize = 8; // HLSL always packs break; case 4: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_2X4; def.ElementSize = 8; break; } // columns break; case 3: switch ( secondDim ) { case 2: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X2; def.ElementSize = 12; // HLSL always packs break; case 3: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X3; def.ElementSize = 12; // HLSL always packs break; case 4: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_3X4; def.ElementSize = 12; break; } // columns break; case 4: switch ( secondDim ) { case 2: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_4X2; def.ElementSize = 16; // HLSL always packs break; case 3: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_4X3; def.ElementSize = 16; // HLSL always packs break; case 4: def.ConstantType = GpuProgramParameters.GpuConstantType.Matrix_4X4; def.ElementSize = 16; break; } // secondDim break; } // firstDim } break; case D3D9.ParameterClass.Scalar: case D3D9.ParameterClass.Vector: switch ( d3DDesc.Columns ) { case 1: def.ConstantType = GpuProgramParameters.GpuConstantType.Float1; break; case 2: def.ConstantType = GpuProgramParameters.GpuConstantType.Float2; break; case 3: def.ConstantType = GpuProgramParameters.GpuConstantType.Float3; break; case 4: def.ConstantType = GpuProgramParameters.GpuConstantType.Float4; break; } // columns break; } break; default: // not mapping samplers, don't need to take the space break; } ; // D3D9 pads to 4 elements def.ElementSize = GpuProgramParameters.GpuConstantDefinition.GetElementSize( def.ConstantType, true ); }
protected void _updateParameter( GpuProgramParameters programParameters, String paramName, Object value, int sizeInBytes ) { programParameters.AutoAddParamName = true; if ( value is Axiom.Math.Matrix4 ) { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), (Axiom.Math.Matrix4)value ); } else if ( value is Axiom.Core.ColorEx ) { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), (Axiom.Core.ColorEx)value ); } else if ( value is Axiom.Math.Vector3 ) { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), ( (Axiom.Math.Vector3)value ) ); } else if ( value is Axiom.Math.Vector4 ) { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), (Axiom.Math.Vector4)value ); } else if ( value is float[] ) { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), (float[])value ); } else if ( value is int[] ) { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), (int[])value ); } else if ( value is float ) { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), new float[] { (float)value, 0.0f, 0.0f, 0.0f } ); } else { programParameters.SetConstant( programParameters.GetParamIndex( paramName ), (float[])value ); } }
public override void BindProgramParameters(GpuProgramParameters parms, GpuProgramParameters.GpuParamVariability mask) { try { // activate the link program object GLSLLinkProgram linkProgram = GLSLLinkProgramManager.Instance.ActiveLinkProgram; // pass on parameters from params to program object uniforms linkProgram.UpdateUniforms(parms, mask, Type); } catch (Exception e) { LogManager.Instance.Write( "Remove this when validated" ); Debugger.Break(); } }
public GpuProgramParameters Clone() { GpuProgramParameters p = new GpuProgramParameters(); // copy int constants for ( int i = 0; i < intConstants.Count; i++ ) { IntConstantEntry e = intConstants[ i ] as IntConstantEntry; if ( e.isSet ) { p.SetConstant( i, e.val ); } } // copy float constants for ( int i = 0; i < floatConstants.Count; i++ ) { FloatConstantEntry e = floatConstants[ i ] as FloatConstantEntry; if ( e.isSet ) { p.SetConstant( i, e.val ); } } // copy auto constants for ( int i = 0; i < autoConstantList.Count; i++ ) { AutoConstantEntry entry = autoConstantList[ i ] as AutoConstantEntry; p.SetAutoConstant( entry.Clone() ); } // copy named params foreach ( string key in namedParams.Keys ) { p.MapParamNameToIndex( key, namedParams[ key ] ); } for ( int i = 0; i < paramTypeList.Count; i++ ) { } foreach ( ParameterEntry pEntry in paramTypeList ) { p.AddParameterToDefaultsList( pEntry.ParameterType, pEntry.ParameterName ); } // copy value members p.transposeMatrices = transposeMatrices; p.autoAddParamName = autoAddParamName; return p; }
private void InitShadowStencilPass() { Material matStencil = (Material)MaterialManager.Instance[ STENCIL_SHADOW_VOLUMES_MATERIAL ]; if ( matStencil == null ) { // Create matStencil = (Material) MaterialManager.Instance.Create( STENCIL_SHADOW_VOLUMES_MATERIAL, ResourceGroupManager.InternalResourceGroupName ); this.shadowStencilPass = matStencil.GetTechnique( 0 ).GetPass( 0 ); if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) ) { // Enable the finite point light extruder for now, just to get some params this.shadowStencilPass.SetVertexProgram( ShadowVolumeExtrudeProgram.GetProgramName( ShadowVolumeExtrudeProgram.Programs.PointLightFinite ) ); this.finiteExtrusionParams = this.shadowStencilPass.VertexProgramParameters; this.finiteExtrusionParams.SetAutoConstant( 0, GpuProgramParameters.AutoConstantType.WorldViewProjMatrix ); this.finiteExtrusionParams.SetAutoConstant( 4, GpuProgramParameters.AutoConstantType.LightPositionObjectSpace ); this.finiteExtrusionParams.SetAutoConstant( 5, GpuProgramParameters.AutoConstantType.ShadowExtrusionDistance ); } matStencil.Compile(); // Nothing else, we don't use this like a 'real' pass anyway, // it's more of a placeholder } else { this.shadowStencilPass = matStencil.GetTechnique( 0 ).GetPass( 0 ); if ( this.targetRenderSystem.Capabilities.HasCapability( Capabilities.VertexPrograms ) ) { this.finiteExtrusionParams = this.shadowStencilPass.VertexProgramParameters; } } }
/// <summary> /// Copies the values of all constants (including auto constants) from another <see cref="GpuProgramParameters"/> object. /// </summary> /// <param name="source">Set of params to use as the source.</param> public void CopyConstantsFrom( GpuProgramParameters source ) { int i = 0; FloatConstantEntry[] floatEntries = new FloatConstantEntry[ source.floatConstants.Count ]; IntConstantEntry[] intEntries = new IntConstantEntry[ source.intConstants.Count ]; // copy those float and int constants right on in source.floatConstants.CopyTo( floatEntries ); source.intConstants.CopyTo( intEntries ); floatConstants.AddRange( floatEntries ); intConstants.AddRange( intEntries ); // Iterate over auto parameters // Clear existing auto constants ClearAutoConstantType(); for ( i = 0; i < source.autoConstantList.Count; i++ ) { AutoConstantEntry entry = (AutoConstantEntry)source.autoConstantList[ i ]; SetAutoConstant( entry.Clone() ); } // don't forget to copy the named param lookup as well namedParams = new AxiomCollection<int>( source.namedParams ); }