/// <summary> /// Returns the number of floats needed by the given type. /// </summary> /// <param name="type"> </param> /// <returns> </returns> protected static int GetParameterFloatCount(Axiom.Graphics.GpuProgramParameters.GpuConstantType type) { int floatCount = 0; switch (type) { case GpuProgramParameters.GpuConstantType.Float1: floatCount = 1; break; case GpuProgramParameters.GpuConstantType.Float2: floatCount = 2; break; case GpuProgramParameters.GpuConstantType.Float3: floatCount = 3; break; case GpuProgramParameters.GpuConstantType.Float4: floatCount = 4; break; default: throw new Axiom.Core.AxiomException("Invalid parameter float type."); } return(floatCount); }
/// <summary> /// Returns the parameter mask of by the given parameter type. /// <example> /// X|Y for FLOAT2 etc.. /// </example> /// </summary> /// <param name="type"> </param> /// <returns> </returns> protected static int GetParameterMaskByType(Axiom.Graphics.GpuProgramParameters.GpuConstantType type) { int paramMask = 0; switch (type) { case GpuProgramParameters.GpuConstantType.Float1: paramMask = (int)Operand.OpMask.X; break; case GpuProgramParameters.GpuConstantType.Float2: paramMask = ((int)Operand.OpMask.X | (int)Operand.OpMask.Y); break; case GpuProgramParameters.GpuConstantType.Float3: paramMask = ((int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z); break; case GpuProgramParameters.GpuConstantType.Float4: paramMask = ((int)Operand.OpMask.X | (int)Operand.OpMask.Y | (int)Operand.OpMask.Z | (int)Operand.OpMask.W); break; default: throw new Axiom.Core.AxiomException("Invalid paramter float type."); } return(paramMask); }
/// <summary> /// </summary> /// <param name="type"> </param> /// <param name="index"> </param> /// <param name="variability"> default is .All </param> /// <param name="suggestedName"> </param> /// <param name="size"> Default is 0 </param> /// <returns> </returns> public UniformParameter ResolveParameter(Axiom.Graphics.GpuProgramParameters.GpuConstantType type, int index, GpuProgramParameters.GpuParamVariability variability, string suggestedName, int size) { UniformParameter param = null; if (index == -1) { index = 0; //find the next availalbe index of the target type for (int i = 0; i < this.parameters.Count; i++) { if (this.parameters[i].Type == type && this.parameters[i].IsAutoConstantParameter == false) { index++; } } } else { //Check if parameter already exits param = GetParameterByType(type, index); if (param != null) { return(param); } } //Create new parameter. param = ParameterFactory.CreateUniform(type, index, (int)variability, suggestedName, size); AddParameter(param); return(param); }
/// <summary> /// Creates the destination parameter by a given class and index. /// </summary> /// <param name="usage"> </param> /// <param name="index"> </param> protected void CreateDestinationParamter(int usage, int index) { Axiom.Graphics.GpuProgramParameters.GpuConstantType dstParamType = Graphics.GpuProgramParameters.GpuConstantType.Unknown; switch (UsedFloatCount) { case 1: dstParamType = Graphics.GpuProgramParameters.GpuConstantType.Float1; break; case 2: dstParamType = Graphics.GpuProgramParameters.GpuConstantType.Float2; break; case 3: dstParamType = Graphics.GpuProgramParameters.GpuConstantType.Float3; break; case 4: dstParamType = Graphics.GpuProgramParameters.GpuConstantType.Float4; break; } if (usage == (int)Operand.OpSemantic.In) { this.dstParameter = ParameterFactory.CreateInTexcoord(dstParamType, index, Parameter.ContentType.Unknown); } else { this.dstParameter = ParameterFactory.CreateOutTexcoord(dstParamType, index, Parameter.ContentType.Unknown); } }
public UniformParameter GetParameterByType(Axiom.Graphics.GpuProgramParameters.GpuConstantType type, int index) { foreach (var param in this.parameters) { if (param.Type == type && param.Index == index) { return(param); } } return(null); }
protected override bool ResolveParameters(ProgramSet programSet) { Program vsProgram = programSet.CpuVertexProgram; Program psProgram = programSet.CpuFragmentProgram; Function vsMain = vsProgram.EntryPointFunction; Function psMain = psProgram.EntryPointFunction; //Define vertex shader parameters used to find the positon of the textures in the atlas var indexContent = (Parameter.ContentType)((int)Parameter.ContentType.TextureCoordinate0 + this.atlasTexcoordPos); Axiom.Graphics.GpuProgramParameters.GpuConstantType indexType = GpuProgramParameters.GpuConstantType.Float4; this.vsInpTextureTableIndex = vsMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, this.atlasTexcoordPos, indexContent, indexType); //Define parameters to carry the information on the location of the texture from the vertex to the pixel shader for (int i = 0; i < TextureAtlasSampler.MaxTextures; i++) { if (this.isAtlasTextureUnits[i] == true) { this.vsTextureTable[i] = vsProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float4, -1, GpuProgramParameters.GpuParamVariability.Global, "AtlasData", this.atlasTableDatas[i].Count); this.vsOutTextureDatas[i] = vsMain.ResolveOutputParameter(Parameter.SemanticType.TextureCoordinates, -1, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4); this.psInpTextureData[i] = psMain.ResolveInputParameter(Parameter.SemanticType.TextureCoordinates, this.vsOutTextureDatas[i].Index, Parameter.ContentType.Unknown, GpuProgramParameters.GpuConstantType.Float4); this.psTextureSizes[i] = psProgram.ResolveParameter(GpuProgramParameters.GpuConstantType.Float2, -1, GpuProgramParameters.GpuParamVariability.PerObject, "AtlasSize"); } } return(true); }
/// <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="type"> The desried data type of the auto 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, Axiom.Graphics.GpuProgramParameters.GpuConstantType type, 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, type); AddParameter(param); return(param); }
private void WriteForwardDeclarations(StreamWriter stream, Program program) { stream.WriteLine("//-----------------------------------------------------------------------------"); stream.WriteLine("// FORWARD DECLARATIONS"); stream.WriteLine("//-----------------------------------------------------------------------------"); var forwardDecl = new List <string>(); // hold all generated function declarations var functionList = program.Functions; foreach (var curFunction in functionList) { var atomInstances = curFunction.AtomInstances; for (int i = 0; i < atomInstances.Count; i++) { var itAtom = atomInstances[i]; //Skip non function invocation atoms if (!(itAtom is FunctionInvocation)) { continue; } var funcInvoc = itAtom as FunctionInvocation; int itOperator = 0; int itOperatorEnd = funcInvoc.OperandList.Count; //Start with function declaration string funcDecl = funcInvoc.ReturnType + " " + funcInvoc.FunctionName + "("; //Now iterate overall operands while (itOperator != itOperatorEnd) { Parameter param = funcInvoc.OperandList[itOperator].Parameter; Operand.OpSemantic opSemantic = funcInvoc.OperandList[itOperator].Semantic; int opMask = funcInvoc.OperandList[itOperator].Mask; Axiom.Graphics.GpuProgramParameters.GpuConstantType gpuType = GpuProgramParameters.GpuConstantType.Unknown; //Write the semantic in, out, inout switch (opSemantic) { case Operand.OpSemantic.In: funcDecl += "in "; break; case Operand.OpSemantic.Out: funcDecl += "out "; break; case Operand.OpSemantic.InOut: funcDecl += "inout "; break; default: break; } //Swizzle masks are only defined fro types like vec2, vec3, vec4 if (opMask == (int)Operand.OpMask.All) { gpuType = param.Type; } else { //Now we have to conver the mask to operator gpuType = Operand.GetGpuConstantType(opMask); } //We need a valid type otherwise glsl compilation will not work if (gpuType == GpuProgramParameters.GpuConstantType.Unknown) { throw new Core.AxiomException("Cannot convert Operand.OpMask to GpuConstantType"); } //Write the operand type. funcDecl += this.gpuConstTypeMap[gpuType]; itOperator++; //move over all operators with indirection while ((itOperator != itOperatorEnd) && (funcInvoc.OperandList[itOperator].IndirectionLevel != 0)) { itOperator++; } //Prepare for the next operand if (itOperator != itOperatorEnd) { funcDecl += ", "; } } //Write function call closer. funcDecl += ");\n"; //Push the generated declaration into the vector //duplicate declarations will be removed later. forwardDecl.Add(funcDecl); } } //Now remove duplicate declaration, first we have to sort the vector. forwardDecl.Sort(); forwardDecl = forwardDecl.Distinct().ToList(); foreach (var it in forwardDecl) { stream.Write(it); } }
public UniformParameter ResolveParameter(Axiom.Graphics.GpuProgramParameters.GpuConstantType type, int index, GpuProgramParameters.GpuParamVariability variability, string suggestedName) { return(ResolveParameter(type, index, variability, suggestedName, 0)); }