protected internal virtual void copy(float value, ShaderUniformInfo shaderUniformInfo, int index) { if (shaderUniformInfo.Used) { prepareCopy(shaderUniformInfo.Offset + index * 4, 4); data.putFloat(value); } }
protected internal virtual ShaderUniformInfo addShaderUniform(Uniforms uniform, string type, int matrixSize) { ShaderUniformInfo shaderUniformInfo = new ShaderUniformInfo(uniform, type, matrixSize); shaderUniformInfos.Add(shaderUniformInfo); return(shaderUniformInfo); }
protected internal virtual void copy(int value, ShaderUniformInfo shaderUniformInfo) { // Do not copy unused uniform, to avoid overwriting other used uniforms if (shaderUniformInfo.Used) { prepareCopy(shaderUniformInfo.Offset, 4); data.putInt(value); } }
protected internal virtual void copy(int[] values, ShaderUniformInfo shaderUniformInfo, int start, int end) { if (shaderUniformInfo.Used) { prepareCopy(shaderUniformInfo.Offset + start * 4, (end - start) * 4); for (int i = start; i < end; i++) { data.putInt(values[i]); } } }
protected internal virtual void copy(float[] values, ShaderUniformInfo shaderUniformInfo, int start, int end) { if (shaderUniformInfo.Used) { prepareCopy(shaderUniformInfo.Offset + start * 4, (end - start) * 4); for (int i = start; i < end; i++) { float value = values[i]; if (float.IsNaN(value)) { value = 0f; } data.putFloat(value); } } }
protected internal virtual void copy(bool value, ShaderUniformInfo shaderUniformInfo) { copy(value ? 1 : 0, shaderUniformInfo); }
public ShaderContextUBO(IRenderingEngine re) { shaderUniformInfos = new List <ShaderUniformInfo>(); // Add all the shader uniform objects // in the order they have to be defined in the shader structure lightType = addShaderUniform(Uniforms.lightType, "ivec4"); lightKind = addShaderUniform(Uniforms.lightKind, "ivec4"); lightEnabled = addShaderUniform(Uniforms.lightEnabled, "ivec4"); vertexColor = addShaderUniform(Uniforms.vertexColor, "vec4"); colorMask = addShaderUniform(Uniforms.colorMask, "ivec4"); notColorMask = addShaderUniform(Uniforms.notColorMask, "ivec4"); blendSFix = addShaderUniform(Uniforms.blendSFix, "vec3"); blendDFix = addShaderUniform(Uniforms.blendDFix, "vec3"); matFlags = addShaderUniform(Uniforms.matFlags, "ivec3"); ctestRef = addShaderUniform(Uniforms.ctestRef, "ivec3"); ctestMsk = addShaderUniform(Uniforms.ctestMsk, "ivec3"); texShade = addShaderUniform(Uniforms.texShade, "ivec2"); texEnvMode = addShaderUniform(Uniforms.texEnvMode, "ivec2"); ctestFunc = addShaderUniform(Uniforms.ctestFunc, "int"); texMapMode = addShaderUniform(Uniforms.texMapMode, "int"); texMapProj = addShaderUniform(Uniforms.texMapProj, "int"); vinfoColor = addShaderUniform(Uniforms.vinfoColor, "int"); vinfoPosition = addShaderUniform(Uniforms.vinfoPosition, "int"); vinfoTexture = addShaderUniform(Uniforms.vinfoTexture, "int"); vinfoNormal = addShaderUniform(Uniforms.vinfoNormal, "int"); positionScale = addShaderUniform(Uniforms.positionScale, "float"); normalScale = addShaderUniform(Uniforms.normalScale, "float"); textureScale = addShaderUniform(Uniforms.textureScale, "float"); weightScale = addShaderUniform(Uniforms.weightScale, "float"); colorDoubling = addShaderUniform(Uniforms.colorDoubling, "float"); texEnable = addShaderUniform(Uniforms.texEnable, "bool"); lightingEnable = addShaderUniform(Uniforms.lightingEnable, "bool"); vinfoTransform2D = addShaderUniform(Uniforms.vinfoTransform2D, "bool"); ctestEnable = addShaderUniform(Uniforms.ctestEnable, "bool"); lightMode = addShaderUniform(Uniforms.lightMode, "bool"); clutShift = addShaderUniform(Uniforms.clutShift, "int"); clutMask = addShaderUniform(Uniforms.clutMask, "int"); clutOffset = addShaderUniform(Uniforms.clutOffset, "int"); mipmapShareClut = addShaderUniform(Uniforms.mipmapShareClut, "bool"); texPixelFormat = addShaderUniform(Uniforms.texPixelFormat, "int"); stencilTestEnable = addShaderUniform(Uniforms.stencilTestEnable, "bool"); stencilFunc = addShaderUniform(Uniforms.stencilFunc, "int"); stencilRef = addShaderUniform(Uniforms.stencilRef, "int"); stencilMask = addShaderUniform(Uniforms.stencilMask, "int"); stencilOpFail = addShaderUniform(Uniforms.stencilOpFail, "int"); stencilOpZFail = addShaderUniform(Uniforms.stencilOpZFail, "int"); stencilOpZPass = addShaderUniform(Uniforms.stencilOpZPass, "int"); depthTestEnable = addShaderUniform(Uniforms.depthTestEnable, "bool"); depthFunc = addShaderUniform(Uniforms.depthFunc, "int"); depthMask = addShaderUniform(Uniforms.depthMask, "int"); alphaTestEnable = addShaderUniform(Uniforms.alphaTestEnable, "bool"); alphaTestFunc = addShaderUniform(Uniforms.alphaTestFunc, "int"); alphaTestRef = addShaderUniform(Uniforms.alphaTestRef, "int"); alphaTestMask = addShaderUniform(Uniforms.alphaTestMask, "int"); blendTestEnable = addShaderUniform(Uniforms.blendTestEnable, "bool"); blendEquation = addShaderUniform(Uniforms.blendEquation, "int"); blendSrc = addShaderUniform(Uniforms.blendSrc, "int"); blendDst = addShaderUniform(Uniforms.blendDst, "int"); colorMaskEnable = addShaderUniform(Uniforms.colorMaskEnable, "bool"); wrapModeS = addShaderUniform(Uniforms.wrapModeS, "int"); wrapModeT = addShaderUniform(Uniforms.wrapModeT, "int"); copyRedToAlpha = addShaderUniform(Uniforms.copyRedToAlpha, "bool"); fogEnable = addShaderUniform(Uniforms.fogEnable, "bool"); fogColor = addShaderUniform(Uniforms.fogColor, "vec3"); fogEnd = addShaderUniform(Uniforms.fogEnd, "float"); fogScale = addShaderUniform(Uniforms.fogScale, "float"); clipPlaneEnable = addShaderUniform(Uniforms.clipPlaneEnable, "bool"); viewportPos = addShaderUniform(Uniforms.viewportPos, "vec3"); viewportScale = addShaderUniform(Uniforms.viewportScale, "vec3"); numberBones = addShaderUniform(Uniforms.numberBones, "int"); boneMatrix = addShaderUniform(Uniforms.boneMatrix, "mat4", 8); // The following entry has always to be the last one endOfUBO = addShaderUniform(Uniforms.endOfUBO, "int"); StringBuilder s = new StringBuilder(); s.Append(string.Format("layout({0}) uniform {1}\n", uniformMemoryLayout, uniformBlockName)); s.Append(string.Format("{\n")); foreach (ShaderUniformInfo shaderUniformInfo in shaderUniformInfos) { s.Append(string.Format(" {0} {1};\n", shaderUniformInfo.Type, shaderUniformInfo.StructureName)); } s.Append(string.Format("};\n")); shaderUniformText = s.ToString(); }