public UniformBase(Shader owner, string name, int uniformLocation, ActiveUniformType type) { this.owner = owner; Name = name; location = uniformLocation; this.type = type; }
public static string GL_type_to_string(ActiveUniformType type) { switch (type) { case ActiveUniformType.Bool: return("bool"); case ActiveUniformType.Int: return("int"); case ActiveUniformType.Float: return("float"); case ActiveUniformType.FloatVec2: return("vec2"); case ActiveUniformType.FloatVec3: return("vec3"); case ActiveUniformType.FloatVec4: return("vec4"); case ActiveUniformType.FloatMat2: return("mat2"); case ActiveUniformType.FloatMat3: return("mat3"); case ActiveUniformType.FloatMat4: return("mat4"); case ActiveUniformType.Sampler2D: return("sampler2D"); case ActiveUniformType.Sampler3D: return("sampler3D"); case ActiveUniformType.SamplerCube: return("samplerCube"); case ActiveUniformType.Sampler2DShadow: return("sampler2DShadow"); default: break; } return("other"); }
private static int GetSortingKey(string name, ActiveUniformType type) { switch (type) { case ActiveUniformType.Bool: case ActiveUniformType.Int: return(ShaderParams.GetSortingKey(name, typeof(int))); case ActiveUniformType.BoolVec2: case ActiveUniformType.IntVec2: return(ShaderParams.GetSortingKey(name, typeof(IntVector2))); case ActiveUniformType.Float: return(ShaderParams.GetSortingKey(name, typeof(float))); case ActiveUniformType.FloatVec2: return(ShaderParams.GetSortingKey(name, typeof(Vector2))); case ActiveUniformType.FloatVec3: return(ShaderParams.GetSortingKey(name, typeof(Vector3))); case ActiveUniformType.FloatVec4: return(ShaderParams.GetSortingKey(name, typeof(Vector4))); case ActiveUniformType.FloatMat4: return(ShaderParams.GetSortingKey(name, typeof(Matrix44))); default: throw new NotSupportedException(); } }
private bool CheckIfTextureSetIsValid(string name, Texture texture, int textureUnit) { ActiveUniformType uniformType = ShaderTypeConversions.GetUniformType(texture.TextureTarget); bool validUniform = errorLog.IsValidUniform(activeUniformByName, name, uniformType); if (!validUniform) { LogInvalidUniformSetRaiseEvent(name, texture, uniformType); } bool validSamplerType = errorLog.IsValidSamplerType(textureUnit, uniformType); if (!validSamplerType) { var textureSetArgs = new TextureSetEventArgs() { Name = name, Type = uniformType, TextureUnit = textureUnit, Value = texture }; OnTextureUnitTypeMismatch?.Invoke(this, textureSetArgs); } bool validSet = validUniform && validSamplerType; return(validSet); }
public ShaderDataType UniformTypeToDataType(ActiveUniformType type) { switch (type) { case ActiveUniformType.Float: return(ShaderDataType.Float); case ActiveUniformType.FloatVec2: return(ShaderDataType.Float2); case ActiveUniformType.FloatVec3: return(ShaderDataType.Float3); case ActiveUniformType.FloatVec4: return(ShaderDataType.Float4); case ActiveUniformType.FloatMat4: return(ShaderDataType.Mat4); case ActiveUniformType.Sampler2D: return(ShaderDataType.Texture2D); case ActiveUniformType.SamplerCube: return(ShaderDataType.TextureCube); default: Logger.LogError(Logger.ErrorState.Critical, "Unsupported shader data type"); return(ShaderDataType.InvalidType); } }
// Uniform in the default uniform block public Uniform(string name, int index, int count, ActiveUniformType type) { this.name = name; this.index = index; this.count = count; this.type = type; }
public ShaderUniformData(string name, int location, int size, ActiveUniformType type) { this.Name = name; this.Location = location; this.Size = size; this.Type = type; }
private unsafe UniformSetter GetSetterFunction(ActiveUniformType uniformType) { switch (uniformType) { case ActiveUniformType.FloatMat4: return((int location, IntPtr data, int dataSizeInBytes, int offsetInBytes) => { float *dataPtr = (float *)data.ToPointer(); int numMatrices = dataSizeInBytes / sizeof(Matrix4x4); int offsetElements = offsetInBytes / sizeof(float); dataPtr += offsetElements; GL.UniformMatrix4(location, numMatrices, false, dataPtr); Utilities.CheckLastGLES3Error(); }); case ActiveUniformType.FloatVec2: return((int location, IntPtr data, int dataSizeInBytes, int offsetInBytes) => { float *dataPtr = (float *)data.ToPointer(); int numFloat2s = dataSizeInBytes / sizeof(Vector2); int offsetElements = offsetInBytes / sizeof(float); dataPtr += offsetElements; GL.UniformMatrix4(location, numFloat2s, false, dataPtr); Utilities.CheckLastGLES3Error(); }); case ActiveUniformType.FloatVec3: return((int location, IntPtr data, int dataSizeInBytes, int offsetInBytes) => { float *dataPtr = (float *)data.ToPointer(); int numFloat3s = dataSizeInBytes / sizeof(Vector3); int offsetElements = offsetInBytes / sizeof(float); dataPtr += offsetElements; GL.UniformMatrix4(location, numFloat3s, false, dataPtr); Utilities.CheckLastGLES3Error(); }); case ActiveUniformType.FloatVec4: return((int location, IntPtr data, int dataSizeInBytes, int offsetInBytes) => { float *dataPtr = (float *)data.ToPointer(); int numFloat4s = dataSizeInBytes / sizeof(Vector4); int offsetElements = offsetInBytes / sizeof(float); dataPtr += offsetElements; GL.UniformMatrix4(location, numFloat4s, false, dataPtr); Utilities.CheckLastGLES3Error(); }); default: return((int location, IntPtr data, int dataSizeInBytes, int offsetInBytes) => { float *dataPtr = (float *)data.ToPointer(); int numMatrices = dataSizeInBytes / sizeof(Matrix4x4); int offsetElements = offsetInBytes / sizeof(float); dataPtr += offsetElements; GL.UniformMatrix4(location, numMatrices, false, dataPtr); Utilities.CheckLastGLES3Error(); }); } }
private ActiveUniformType getBaseSampler(ActiveUniformType type) { if (type == ActiveUniformType.Sampler1D || type == ActiveUniformType.Sampler1DShadow || type == ActiveUniformType.IntSampler1D || type == ActiveUniformType.UnsignedIntSampler1D) { return(ActiveUniformType.Sampler1D); } if (type == ActiveUniformType.Sampler2D || type == ActiveUniformType.Sampler2DShadow || type == ActiveUniformType.IntSampler2D || type == ActiveUniformType.UnsignedIntSampler2D || type == ActiveUniformType.IntSampler2DRect || type == ActiveUniformType.UnsignedIntSampler2DRect || type == ActiveUniformType.IntSampler2DMultisample || type == ActiveUniformType.Sampler2DMultisample || type == ActiveUniformType.Sampler2DRectShadow || type == ActiveUniformType.UnsignedIntSampler2D || type == ActiveUniformType.UnsignedIntSampler2DMultisample) { return(ActiveUniformType.Sampler2D); } if (type == ActiveUniformType.Sampler3D || type == ActiveUniformType.IntSampler3D || type == ActiveUniformType.UnsignedIntSampler3D || type == ActiveUniformType.UnsignedIntSampler3D) { return(ActiveUniformType.Sampler3D); } if (type == ActiveUniformType.SamplerCube || type == ActiveUniformType.IntSamplerCube || type == ActiveUniformType.SamplerCubeShadow || type == ActiveUniformType.UnsignedIntSamplerCube) { return(ActiveUniformType.SamplerCube); } return(ActiveUniformType.Sampler1D); }
public static UniformDefinition Create(string name, int[] values, List <string> aliases = null) { if (values.Length > 4) { throw new ContentException("Values must contain 1 - 4 integers."); } if (aliases == null) { aliases = new List <string>(); } ActiveUniformType type = ActiveUniformType.Int; if (values.Length == 2) { type = ActiveUniformType.IntVec2; } if (values.Length == 3) { type = ActiveUniformType.IntVec3; } if (values.Length == 4) { type = ActiveUniformType.IntVec4; } return(new UniformDefinition(name, type, aliases, new UniformValueContent(Minotaur.Graphics.UniformValueType.Int, values.Cast <object>().ToArray()))); }
public ShaderUniform(string name, int location, int size, ActiveUniformType uniformType) { Name = name; Location = location; Size = size; UniformType = uniformType; }
public ShaderUniformInfo(string name, int location, int size, ActiveUniformType type) { Name = name; Location = location; Size = size; Type = type; }
public UniformDefinition(string name, ActiveUniformType type, List <string> aliases, UniformValueContent value) { Name = name; Type = type; Aliases = new List <string>(aliases); Value = value; }
internal ProgramUniform(Program program, string name, int index, int location, ActiveUniformType type, int count) : base(program, name, index) { this.type = type; this.location = location; this.count = count; }
public ShaderUniformInfo(ShaderProgram program, string name, ActiveUniformType type, int size, int location) { Program = program; Name = name; Type = type; Location = location; }
public static uint getBaseSize(ActiveUniformType type) { switch (type) { case ActiveUniformType.Bool: return 1; case ActiveUniformType.Double: return 2; case ActiveUniformType.Float: return 1; /*case ActiveUniformType.Image1D: return 1; case ActiveUniformType.Image2D: return 1; case ActiveUniformType.Image3D: return 1;*/ case ActiveUniformType.Int: return 1; case ActiveUniformType.Sampler1D: return 1; case ActiveUniformType.Sampler2D: return 1; case ActiveUniformType.Sampler3D: return 1; case ActiveUniformType.UnsignedInt: return 1; } return 1; }
private MojoShader.MOJOSHADER_symbolType getSymbolType(ActiveUniformType type) { ActiveUniformType baseType = UniformTypeInfos.getBaseType(type); switch (baseType) { case ActiveUniformType.Int: case ActiveUniformType.UnsignedInt: return(MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_INT); case ActiveUniformType.Float: case ActiveUniformType.Double: return(MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_FLOAT); case ActiveUniformType.Sampler1D: return(MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLER1D); case ActiveUniformType.Sampler2D: return(MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLER2D); case ActiveUniformType.Sampler3D: return(MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLER3D); case ActiveUniformType.SamplerCube: return(MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLERCUBE); } return(MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_VOID); }
#pragma warning disable CS0246 // 未能找到类型或命名空间名“ActiveUniformType”(是否缺少 using 指令或程序集引用?) public static ShaderParameterType TranslateActiveUniformType(ActiveUniformType type) #pragma warning restore CS0246 // 未能找到类型或命名空间名“ActiveUniformType”(是否缺少 using 指令或程序集引用?) { switch (type) { case ActiveUniformType.Float: return(ShaderParameterType.Float); case ActiveUniformType.FloatVec2: return(ShaderParameterType.Vector2); case ActiveUniformType.FloatVec3: return(ShaderParameterType.Vector3); case ActiveUniformType.FloatVec4: return(ShaderParameterType.Vector4); case ActiveUniformType.FloatMat4: return(ShaderParameterType.Matrix); case ActiveUniformType.Sampler2D: return(ShaderParameterType.Texture2D); default: throw new InvalidOperationException("Unsupported shader parameter type."); } }
private void ValidateType(ActiveUniformType type) { if (this.Type == type) { return; } throw new InvalidOperationException("The value you passed does not fit the uniforms type."); }
internal Uniform(CompiledShader cs, int location, string name, ActiveUniformType type, int size) { this.shader = cs; this.Location = location; this.Name = name; this.Type = type; this.Size = size; }
public ProgramUniform(string name, int slot, int size, ActiveUniformType type) { Name = name; Slot = slot; Size = size; Type = type; }
public UniformBase(Shader owner, string name, int uniformLocation, ActiveUniformType type) { this.owner = owner; Name = name; location = uniformLocation; IsArray = name.EndsWith("[0]"); this.type = type; }
public static uint getElementSize(ActiveUniformType type) { ActiveUniformType baseType = getBaseType(type); uint baseSize = getBaseSize(baseType); uint elementCount = getElementCount(type, baseType); return(baseSize * elementCount); }
public MaterialData(string name, int location, object data, ActiveUniformType type) { this.Name = name; this.Data = data; this.GLType = type; this.Location = location; NeedUpdate = true; }
internal ActiveUniform(string name, uint index, int size, ActiveUniformType type, int offset) { Size = size; Index = index; Name = name; Type = type; Offset = offset; }
public static uint getColumnCount(ActiveUniformType type) { switch (type) { case ActiveUniformType.FloatMat2: return(getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float)); case ActiveUniformType.FloatMat3: return(getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float)); case ActiveUniformType.FloatMat4: return(getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float)); case ActiveUniformType.FloatMat2x3: return(getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float)); case ActiveUniformType.FloatMat2x4: return(getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float)); case ActiveUniformType.FloatMat3x2: return(getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float)); case ActiveUniformType.FloatMat3x4: return(getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float)); case ActiveUniformType.FloatMat4x2: return(getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float)); case ActiveUniformType.FloatMat4x3: return(getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float)); } if (getBaseType(type) == type) { return(1); } if (type <= ActiveUniformType.BoolVec4 && type >= ActiveUniformType.BoolVec2) { return((uint)(type - ActiveUniformType.BoolVec2) + 2); } if (type <= ActiveUniformType.DoubleVec4 && type >= ActiveUniformType.DoubleVec2) { return((uint)(type - ActiveUniformType.DoubleVec2) + 2); } if (type <= ActiveUniformType.FloatVec4 && type >= ActiveUniformType.FloatVec2) { return((uint)(type - ActiveUniformType.FloatVec2) + 2); } if (type <= ActiveUniformType.IntVec4 && type >= ActiveUniformType.IntVec2) { return((uint)(type - ActiveUniformType.IntVec2) + 2); } if (type <= ActiveUniformType.UnsignedIntVec4 && type >= ActiveUniformType.UnsignedIntVec2) { return((uint)(type - ActiveUniformType.UnsignedIntVec2) + 2); } return(1); }
public void GetActiveUniform(uint program, uint index, int bufsize, int[] length, int[] size, uint[] type, StringBuilder name) { ActiveUniformType[] _types = new ActiveUniformType[type.Length]; for (int i = 0; i < type.Length; i++) { _types[i] = (ActiveUniformType)type[i]; } GL.GetActiveUniform(program, index, bufsize, length, size, _types, name); }
public static ActiveUniformType getBaseType(ActiveUniformType type) { if (type <= ActiveUniformType.BoolVec4 && type >= ActiveUniformType.Bool) return ActiveUniformType.Bool; if (type <= ActiveUniformType.DoubleVec4 && type >= ActiveUniformType.DoubleVec2 || type == ActiveUniformType.Double) return ActiveUniformType.Double; if (type <= ActiveUniformType.FloatVec4 && type >= ActiveUniformType.FloatVec2 || type == ActiveUniformType.Float) return ActiveUniformType.Float; if (type == ActiveUniformType.Image1DArray) return ActiveUniformType.Image1D; if (type == ActiveUniformType.Image2DArray) return ActiveUniformType.Image2D; if (type == ActiveUniformType.Image2DMultisampleArray) return ActiveUniformType.Image2DMultisample; if (type == ActiveUniformType.ImageCubeMapArray) return ActiveUniformType.ImageCube; if (type <= ActiveUniformType.IntVec4 && type >= ActiveUniformType.IntVec2 || type == ActiveUniformType.Int) return ActiveUniformType.Int; if (type == ActiveUniformType.IntSampler1DArray) return ActiveUniformType.IntSampler1D; if (type == ActiveUniformType.IntSampler2DArray) return ActiveUniformType.IntSampler2D; if (type == ActiveUniformType.IntSampler2DMultisampleArray) return ActiveUniformType.IntSampler2DMultisample; if (type == ActiveUniformType.IntSamplerCubeMapArray) return ActiveUniformType.IntSamplerCube; if (type == ActiveUniformType.Sampler1DArray || type == ActiveUniformType.Sampler1DArrayShadow) return ActiveUniformType.Sampler1D; if (type == ActiveUniformType.Sampler2DArray || type == ActiveUniformType.Sampler2DArrayShadow) return ActiveUniformType.Sampler2D; if (type == ActiveUniformType.SamplerCubeMapArray || type == ActiveUniformType.SamplerCubeMapArrayShadow) return ActiveUniformType.SamplerCube; if (type == ActiveUniformType.UnsignedIntImage1DArray) return ActiveUniformType.UnsignedIntImage1D; if (type == ActiveUniformType.UnsignedIntImage2DArray) return ActiveUniformType.UnsignedIntImage2D; if (type == ActiveUniformType.UnsignedIntImage2DMultisampleArray) return ActiveUniformType.UnsignedIntImage2DMultisample; if (type == ActiveUniformType.UnsignedIntImageCubeMapArray) return ActiveUniformType.UnsignedIntImageCube; if (type == ActiveUniformType.UnsignedIntSampler1DArray) return ActiveUniformType.UnsignedIntSampler1D; if (type == ActiveUniformType.UnsignedIntSampler2DArray) return ActiveUniformType.UnsignedIntSampler2D; if (type == ActiveUniformType.UnsignedIntSampler2DMultisampleArray) return ActiveUniformType.UnsignedIntSampler2DMultisample; if (type == ActiveUniformType.UnsignedIntSamplerCubeMapArray) return ActiveUniformType.UnsignedIntSamplerCube; if (type <= ActiveUniformType.UnsignedIntVec4 && type >= ActiveUniformType.UnsignedIntVec2 || type == ActiveUniformType.UnsignedInt) return ActiveUniformType.UnsignedInt; if (type <= ActiveUniformType.FloatMat4 && type >= ActiveUniformType.FloatMat2) return ActiveUniformType.Float; if (type <= ActiveUniformType.FloatMat4x3 && type >= ActiveUniformType.FloatMat2x3) return ActiveUniformType.Float; return type; }
public GLUniform(ActiveUniformType type, int index, int location, int count, string name, int componentCount, int componentSize) { Type = type; Index = index; Location = location; Count = count; Name = name; ComponentCount = componentCount; ComponentSize = componentSize; }
public OpenGLUniformStorageAdapter(int programID, int uniformLocation) { _programID = programID; _uniformLocation = uniformLocation; int typeVal; GL.GetActiveUniforms(_programID, 1, ref uniformLocation, ActiveUniformParameter.UniformType, out typeVal); _uniformType = (ActiveUniformType)typeVal; _setterFunction = GetSetterFunction(_uniformType); }
public static uint getElementCount(ActiveUniformType type, ActiveUniformType baseType) { switch (type) { case ActiveUniformType.FloatMat2: return(getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float)); case ActiveUniformType.FloatMat3: return(getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float)); case ActiveUniformType.FloatMat4: return(getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float)); case ActiveUniformType.FloatMat2x3: return(getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float)); case ActiveUniformType.FloatMat2x4: return(getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float)); case ActiveUniformType.FloatMat3x2: return(getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float)); case ActiveUniformType.FloatMat3x4: return(getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float)); case ActiveUniformType.FloatMat4x2: return(getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float)); case ActiveUniformType.FloatMat4x3: return(getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float)); } if (type == baseType) { return(1); } switch (baseType) { case ActiveUniformType.Bool: return((uint)(type - ActiveUniformType.Bool) + 1); case ActiveUniformType.Double: return((uint)(type - ActiveUniformType.DoubleVec2) + 2); case ActiveUniformType.Float: return((uint)(type - ActiveUniformType.FloatVec2) + 2); case ActiveUniformType.Int: return((uint)(type - ActiveUniformType.IntVec2) + 2); case ActiveUniformType.UnsignedInt: return((uint)(type - ActiveUniformType.UnsignedIntVec2) + 2); } return(1); }
private void LoadSampler(MojoShader.MOJOSHADER_symbol sym, ActiveUniformType type) { MojoShader.MOJOSHADER_sampler s = new MojoShader.MOJOSHADER_sampler(); s.index = (int)sym.register_index; s.name = sym.name; s.texbem = 0; s.type = getSamplerType(UniformTypeInfos.getBaseType(type)); Samplers.Add(s); }
public ShaderUniform( string uniformName, int location, ActiveUniformType uniformType, int uniformSize) { UniformName = uniformName; Location = location; UniformType = uniformType; UniformSize = uniformSize; }
public static string GetActiveUniform(int program, int index, out int size, out ActiveUniformType type) { string uniform = GL.GetActiveUniform(program, index, out size, out type); if (enableErrorCheck) { LogErrors(); } return(uniform); }
private static void MeasureActiveUniform(ActiveUniformType type, out int componentCount, out int componentSize) { switch (type) { case ActiveUniformType.Float: componentCount = 1; componentSize = sizeof(float); break; case ActiveUniformType.FloatVec2: componentCount = 2; componentSize = sizeof(float); break; case ActiveUniformType.FloatVec4: componentCount = 4; componentSize = sizeof(float); break; case ActiveUniformType.FloatMat4: componentCount = 16; componentSize = sizeof(float); break; case ActiveUniformType.Image2D: componentCount = 1; componentSize = sizeof(int); break; default: throw new NotImplementedException(); } }
static UniformType GetUniformType(ActiveUniformType t) { switch (t) { case ActiveUniformType.Bool: return UniformType.@bool; case ActiveUniformType.Double: return UniformType.@double; case ActiveUniformType.DoubleVec2: return UniformType.Vector2d; case ActiveUniformType.DoubleVec3: return UniformType.Vector3d; case ActiveUniformType.DoubleVec4: return UniformType.Vector4d; case ActiveUniformType.Float: return UniformType.@float; case ActiveUniformType.FloatMat2: return UniformType.Matrix2; case ActiveUniformType.FloatMat2x3: return UniformType.Matrix2x3; case ActiveUniformType.FloatMat2x4: return UniformType.Matrix2x4; case ActiveUniformType.FloatMat3: return UniformType.Matrix3; case ActiveUniformType.FloatMat3x2: return UniformType.Matrix3x2; case ActiveUniformType.FloatMat3x4: return UniformType.Matrix3x4; case ActiveUniformType.FloatMat4: return UniformType.Matrix4; case ActiveUniformType.FloatMat4x2: return UniformType.Matrix4x2; case ActiveUniformType.FloatMat4x3: return UniformType.Matrix4x3; case ActiveUniformType.FloatVec2: return UniformType.Vector2; case ActiveUniformType.FloatVec3: return UniformType.Vector3; case ActiveUniformType.FloatVec4: return UniformType.Vector4; case ActiveUniformType.Image1D: break; case ActiveUniformType.Image1DArray: break; case ActiveUniformType.Image2D: break; case ActiveUniformType.Image2DArray: break; case ActiveUniformType.Image2DMultisample: break; case ActiveUniformType.Image2DMultisampleArray: break; case ActiveUniformType.Image2DRect: break; case ActiveUniformType.Image3D: break; case ActiveUniformType.ImageBuffer: break; case ActiveUniformType.ImageCube: break; case ActiveUniformType.ImageCubeMapArray: break; case ActiveUniformType.Int: return UniformType.@int; case ActiveUniformType.IntImage1D: break; case ActiveUniformType.IntImage1DArray: break; case ActiveUniformType.IntImage2D: break; case ActiveUniformType.IntImage2DArray: break; case ActiveUniformType.IntImage2DMultisample: break; case ActiveUniformType.IntImage2DMultisampleArray: break; case ActiveUniformType.IntImage2DRect: break; case ActiveUniformType.IntImage3D: break; case ActiveUniformType.IntImageBuffer: break; case ActiveUniformType.IntImageCube: break; case ActiveUniformType.IntImageCubeMapArray: break; case ActiveUniformType.IntSampler1D: case ActiveUniformType.IntSampler1DArray: case ActiveUniformType.IntSampler2D: case ActiveUniformType.IntSampler2DArray: case ActiveUniformType.IntSampler2DMultisample: case ActiveUniformType.IntSampler2DMultisampleArray: case ActiveUniformType.IntSampler2DRect: case ActiveUniformType.IntSampler3D: case ActiveUniformType.IntSamplerBuffer: case ActiveUniformType.IntSamplerCube: case ActiveUniformType.IntSamplerCubeMapArray: return UniformType.Texture; case ActiveUniformType.IntVec2: break; case ActiveUniformType.IntVec3: break; case ActiveUniformType.IntVec4: break; case ActiveUniformType.Sampler1D: case ActiveUniformType.Sampler1DArray: case ActiveUniformType.Sampler1DArrayShadow: case ActiveUniformType.Sampler1DShadow: case ActiveUniformType.Sampler2D: case ActiveUniformType.Sampler2DArray: case ActiveUniformType.Sampler2DArrayShadow: case ActiveUniformType.Sampler2DMultisample: case ActiveUniformType.Sampler2DMultisampleArray: case ActiveUniformType.Sampler2DRect: case ActiveUniformType.Sampler2DRectShadow: case ActiveUniformType.Sampler2DShadow: case ActiveUniformType.Sampler3D: case ActiveUniformType.SamplerBuffer: case ActiveUniformType.SamplerCube: case ActiveUniformType.SamplerCubeMapArray: case ActiveUniformType.SamplerCubeMapArrayShadow: case ActiveUniformType.SamplerCubeShadow: return UniformType.Texture; case ActiveUniformType.UnsignedInt: return UniformType.@uint; case ActiveUniformType.UnsignedIntAtomicCounter: break; case ActiveUniformType.UnsignedIntImage1D: break; case ActiveUniformType.UnsignedIntImage1DArray: break; case ActiveUniformType.UnsignedIntImage2D: break; case ActiveUniformType.UnsignedIntImage2DArray: break; case ActiveUniformType.UnsignedIntImage2DMultisample: break; case ActiveUniformType.UnsignedIntImage2DMultisampleArray: break; case ActiveUniformType.UnsignedIntImage2DRect: break; case ActiveUniformType.UnsignedIntImage3D: break; case ActiveUniformType.UnsignedIntImageBuffer: break; case ActiveUniformType.UnsignedIntImageCube: break; case ActiveUniformType.UnsignedIntImageCubeMapArray: break; case ActiveUniformType.UnsignedIntSampler1D: case ActiveUniformType.UnsignedIntSampler1DArray: case ActiveUniformType.UnsignedIntSampler2D: case ActiveUniformType.UnsignedIntSampler2DArray: case ActiveUniformType.UnsignedIntSampler2DMultisample: case ActiveUniformType.UnsignedIntSampler2DMultisampleArray: case ActiveUniformType.UnsignedIntSampler2DRect: case ActiveUniformType.UnsignedIntSampler3D: case ActiveUniformType.UnsignedIntSamplerBuffer: case ActiveUniformType.UnsignedIntSamplerCube: case ActiveUniformType.UnsignedIntSamplerCubeMapArray: return UniformType.Texture; case ActiveUniformType.UnsignedIntVec2: break; case ActiveUniformType.UnsignedIntVec3: break; case ActiveUniformType.UnsignedIntVec4: break; default: break; } throw new Exception("Type: " + t.ToString() + " is not supported at this time."); }
static string GetDrawCommand(ActiveUniformType t, string name) { switch (t) { case ActiveUniformType.Int: case ActiveUniformType.UnsignedInt: case ActiveUniformType.Double: case ActiveUniformType.Float: case ActiveUniformType.Bool: return "GL.Uniform1(__" + name + ", uniform_" + name + ");"; case ActiveUniformType.BoolVec2: break; case ActiveUniformType.BoolVec3: break; case ActiveUniformType.BoolVec4: break; case ActiveUniformType.DoubleVec2: case ActiveUniformType.FloatVec2: return "GL.Uniform2(__" + name + ", uniform_" + name + ");"; case ActiveUniformType.FloatVec3: case ActiveUniformType.DoubleVec3: return "GL.Uniform3(__" + name + ", uniform_" + name + ");"; case ActiveUniformType.FloatVec4: case ActiveUniformType.DoubleVec4: return "GL.Uniform4(__" + name + ", uniform_" + name + ");"; case ActiveUniformType.FloatMat2: return "GL.UniformMatrix2(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat2x3: return "GL.UniformMatrix2x3(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat2x4: return "GL.UniformMatrix2x4(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat3: return "GL.UniformMatrix3(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat3x2: return "GL.UniformMatrix3x2(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat3x4: return "GL.UniformMatrix3x4(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat4: return "GL.UniformMatrix4(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat4x2: return "GL.UniformMatrix4x2(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.FloatMat4x3: return "GL.UniformMatrix4x3(__" + name + ", TransposeMatrix, ref uniform_" + name + ");"; case ActiveUniformType.Image1D: break; case ActiveUniformType.Image1DArray: break; case ActiveUniformType.Image2D: break; case ActiveUniformType.Image2DArray: break; case ActiveUniformType.Image2DMultisample: break; case ActiveUniformType.Image2DMultisampleArray: break; case ActiveUniformType.Image2DRect: break; case ActiveUniformType.Image3D: break; case ActiveUniformType.ImageBuffer: break; case ActiveUniformType.ImageCube: break; case ActiveUniformType.ImageCubeMapArray: break; case ActiveUniformType.IntImage1D: break; case ActiveUniformType.IntImage1DArray: break; case ActiveUniformType.IntImage2D: break; case ActiveUniformType.IntImage2DArray: break; case ActiveUniformType.IntImage2DMultisample: break; case ActiveUniformType.IntImage2DMultisampleArray: break; case ActiveUniformType.IntImage2DRect: break; case ActiveUniformType.IntImage3D: break; case ActiveUniformType.IntImageBuffer: break; case ActiveUniformType.IntImageCube: break; case ActiveUniformType.IntImageCubeMapArray: break; case ActiveUniformType.IntSampler1D: break; case ActiveUniformType.IntSampler1DArray: break; case ActiveUniformType.IntSampler2D: break; case ActiveUniformType.IntSampler2DArray: break; case ActiveUniformType.IntSampler2DMultisample: break; case ActiveUniformType.IntSampler2DMultisampleArray: break; case ActiveUniformType.IntSampler2DRect: break; case ActiveUniformType.IntSampler3D: break; case ActiveUniformType.IntSamplerBuffer: break; case ActiveUniformType.IntSamplerCube: break; case ActiveUniformType.IntSamplerCubeMapArray: break; case ActiveUniformType.IntVec2: break; case ActiveUniformType.IntVec3: break; case ActiveUniformType.IntVec4: break; case ActiveUniformType.UnsignedIntAtomicCounter: break; case ActiveUniformType.UnsignedIntImage1D: break; case ActiveUniformType.UnsignedIntImage1DArray: break; case ActiveUniformType.UnsignedIntImage2D: break; case ActiveUniformType.UnsignedIntImage2DArray: break; case ActiveUniformType.UnsignedIntImage2DMultisample: break; case ActiveUniformType.UnsignedIntImage2DMultisampleArray: break; case ActiveUniformType.UnsignedIntImage2DRect: break; case ActiveUniformType.UnsignedIntImage3D: break; case ActiveUniformType.UnsignedIntImageBuffer: break; case ActiveUniformType.UnsignedIntImageCube: break; case ActiveUniformType.UnsignedIntImageCubeMapArray: break; case ActiveUniformType.UnsignedIntSampler1D: break; case ActiveUniformType.UnsignedIntSampler1DArray: break; case ActiveUniformType.UnsignedIntSampler2D: break; case ActiveUniformType.UnsignedIntSampler2DArray: break; case ActiveUniformType.UnsignedIntSampler2DMultisample: break; case ActiveUniformType.UnsignedIntSampler2DMultisampleArray: break; case ActiveUniformType.UnsignedIntSampler2DRect: break; case ActiveUniformType.UnsignedIntSampler3D: break; case ActiveUniformType.UnsignedIntSamplerBuffer: break; case ActiveUniformType.UnsignedIntSamplerCube: break; case ActiveUniformType.UnsignedIntSamplerCubeMapArray: break; case ActiveUniformType.UnsignedIntVec2: break; case ActiveUniformType.UnsignedIntVec3: break; case ActiveUniformType.UnsignedIntVec4: break; default: break; } return ""; }
private void AddUniform(EffectReflection effectReflection, int uniformSize, int uniformCount, string uniformName, ActiveUniformType uniformType) { // clean the name if (uniformName.Contains(".")) { uniformName = uniformName.Substring(0, uniformName.IndexOf('.')); } if (uniformName.Contains("[")) { uniformName = uniformName.Substring(0, uniformName.IndexOf('[')); } if (GraphicsDevice.IsOpenGLES2) { var indexOfConstantBufferDescription = effectReflection.ConstantBuffers.FindIndex(x => x.Name == "Globals"); var indexOfConstantBuffer = effectReflection.ResourceBindings.FindIndex(x => x.Param.RawName == "Globals"); if (indexOfConstantBufferDescription == -1 || indexOfConstantBuffer == -1) { reflectionResult.Error("Unable to find uniform [{0}] in any constant buffer", uniformName); return; } var constantBufferDescription = effectReflection.ConstantBuffers[indexOfConstantBufferDescription]; var constantBuffer = effectReflection.ResourceBindings[indexOfConstantBuffer]; var elementSize = uniformSize; // For array, each element is rounded to register size if (uniformSize%16 != 0 && uniformCount > 1) { constantBufferDescription.Size = (constantBufferDescription.Size + 15)/16*16; uniformSize = (uniformSize + 15)/16*16; } // Check if it can fits in the same register, otherwise starts at the next one if (uniformCount == 1 && constantBufferDescription.Size/16 != (constantBufferDescription.Size + uniformSize - 1)/16) constantBufferDescription.Size = (constantBufferDescription.Size + 15)/16*16; var indexOfUniform = -1; for (var tentativeIndex = 0; tentativeIndex < constantBufferDescription.Members.Length; ++tentativeIndex) { if (constantBufferDescription.Members[tentativeIndex].Param.RawName == uniformName) { indexOfUniform = tentativeIndex; break; } } var variable = constantBufferDescription.Members[indexOfUniform]; variable.Param.Type = GetTypeFromActiveUniformType(uniformType); //variable.SourceOffset = variableIndexGroup.Offset; variable.Offset = constantBufferDescription.Size; variable.Count = uniformCount; variable.Size = uniformSize*uniformCount; constantBufferDescription.Type = ConstantBufferType.ConstantBuffer; constantBuffer.SlotStart = 0; constantBufferDescription.Members[indexOfUniform] = variable; effectReflection.ResourceBindings[indexOfConstantBuffer] = constantBuffer; // No need to compare last element padding. // TODO: In case of float1/float2 arrays (rare) it is quite non-optimal to do a CompareMemory var compareSize = uniformSize*(uniformCount - 1) + elementSize; Uniforms.Add(new Uniform { Type = uniformType, Count = uniformCount, CompareSize = compareSize, Offset = constantBufferDescription.Size, #if SILICONSTUDIO_PLATFORM_ANDROID UniformIndex = GL.GetUniformLocation(resourceId, new StringBuilder(uniformName)) #else UniformIndex = GL.GetUniformLocation(resourceId, uniformName) #endif }); constantBufferDescription.Size += uniformSize*uniformCount; } else { // check that this uniform is in a constant buffer foreach (var constantBuffer in effectReflection.ConstantBuffers) { foreach (var member in constantBuffer.Members) { if (member.Param.RawName.Equals(uniformName)) return; } } throw new Exception("The uniform value " + uniformName + " is defined outside of a uniform block in OpenGL ES 3, which is not supported by the engine."); } }
public static uint getElementSize(ActiveUniformType type) { ActiveUniformType baseType = getBaseType(type); uint baseSize = getBaseSize(baseType); uint elementCount = getElementCount(type, baseType); return baseSize * elementCount; }
private MojoShader.MOJOSHADER_symbolType getSymbolType(ActiveUniformType type) { ActiveUniformType baseType = UniformTypeInfos.getBaseType(type); switch (baseType) { case ActiveUniformType.Int: case ActiveUniformType.UnsignedInt: return MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_INT; case ActiveUniformType.Float: case ActiveUniformType.Double: return MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_FLOAT; case ActiveUniformType.Sampler1D: return MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLER1D; case ActiveUniformType.Sampler2D: return MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLER2D; case ActiveUniformType.Sampler3D: return MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLER3D; case ActiveUniformType.SamplerCube: return MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_SAMPLERCUBE; } return MojoShader.MOJOSHADER_symbolType.MOJOSHADER_SYMTYPE_VOID; }
private void AddUniform(EffectReflection effectReflection, bool[] validConstantBuffers, int uniformSize, int uniformCount, string uniformName, ActiveUniformType uniformType) { // OpenGL ES 2 is adding uniform for each cbuffer member, so we need to remove array and struct indexers so that we can identify it in cbuffer and find offset var uniformParts = new List<UniformPart>(8); var uniformLastStart = 0; for (var index = 0; index <= uniformName.Length; index++) { char c = index == uniformName.Length ? '.' : uniformName[index]; // Treat string end same as '.' if (c == '.' || c == '[') { var uniformPart = new UniformPart { Start = uniformLastStart, Count = index - uniformLastStart, Indexer = -1 }; // Read array index (if any) if (c == '[') { var indexerStart = ++index; while (uniformName[index] != ']') index++; // TODO: Avoid substring uniformPart.Indexer = int.Parse(uniformName.Substring(indexerStart, index - indexerStart)); index++; } uniformParts.Add(uniformPart); uniformLastStart = index + 1; } } var variableName = uniformName.Substring(0, uniformParts[0].Count); // check that this uniform is in a constant buffer int indexOfConstantBuffer = -1; int indexOfMember = -1; EffectConstantBufferDescription constantBufferDescription = null; for (int cbIndex = 0; cbIndex < effectReflection.ConstantBuffers.Count; cbIndex++) { var currentConstantBuffer = effectReflection.ConstantBuffers[cbIndex]; for (int index = 0; index < currentConstantBuffer.Members.Length; index++) { var member = currentConstantBuffer.Members[index]; if (member.RawName.Equals(variableName)) { indexOfConstantBuffer = cbIndex; indexOfMember = index; constantBufferDescription = currentConstantBuffer; break; } } if (constantBufferDescription != null) break; } if (constantBufferDescription == null) { throw new Exception("The uniform value " + variableName + " is defined outside of a uniform block, which is not supported by the engine."); } var indexOfResource = effectReflection.ResourceBindings.FindIndex(x => x.RawName == constantBufferDescription.Name); if (indexOfResource == -1) { reflectionResult.Error("Unable to find uniform [{0}] in any constant buffer", uniformName); return; } //var constantBufferDescription = effectReflection.ConstantBuffers[indexOfConstantBufferDescription]; var constantBuffer = effectReflection.ResourceBindings[indexOfResource]; // First time we encounter this cbuffer? if (!validConstantBuffers[indexOfConstantBuffer]) { constantBuffer.SlotStart = ConstantBufferOffsets.Length - 1; // Find next cbuffer slot Array.Resize(ref ConstantBufferOffsets, ConstantBufferOffsets.Length + 1); effectReflection.ResourceBindings[indexOfResource] = constantBuffer; ConstantBufferOffsets[constantBuffer.SlotStart + 1] = ConstantBufferOffsets[constantBuffer.SlotStart] + constantBufferDescription.Size; validConstantBuffers[indexOfConstantBuffer] = true; } //var elementSize = uniformSize; // For array, each element is rounded to register size //if (uniformSize%16 != 0 && uniformCount > 1) //{ // constantBufferDescription.Size = (constantBufferDescription.Size + 15)/16*16; // uniformSize = (uniformSize + 15)/16*16; //} // Check if it can fits in the same register, otherwise starts at the next one //if (uniformCount == 1 && constantBufferDescription.Size/16 != (constantBufferDescription.Size + uniformSize - 1)/16) // constantBufferDescription.Size = (constantBufferDescription.Size + 15)/16*16; var variable = constantBufferDescription.Members[indexOfMember]; // Resolve array/member var offset = variable.Offset; var type = variable.Type; for (int i = 0; i < uniformParts.Count; ++i) { var uniformPart = uniformParts[i]; // Apply member if (i > 0) { if (type.Members == null) throw new InvalidOperationException($"Tried to find member \"{uniformName.Substring(uniformPart.Start, uniformPart.Count)}\" on a non-struct type when processing \"{uniformName}\""); bool memberFound = false; for (int memberIndex = 0; memberIndex < type.Members.Length; ++memberIndex) { var member = type.Members[memberIndex]; if (string.Compare(member.Name, 0, uniformName, uniformPart.Start, uniformPart.Count) == 0) { // Adjust offset and set new type offset += member.Offset; type = member.Type; memberFound = true; break; } } if (!memberFound) throw new InvalidOperationException($"Couldn't find member \"{uniformName.Substring(uniformPart.Start, uniformPart.Count)}\" on struct type \"{type.Name}\" when processing \"{uniformName}\""); } // Apply indexer for arrays if (uniformPart.Indexer != -1) { offset += (type.ElementSize + 15) / 16 * 16 * uniformPart.Indexer; } } // Check type if (type.Type != GetTypeFromActiveUniformType(uniformType)) throw new InvalidOperationException($"Uniform [{uniformName}] of type [{variable.Type.Type}] doesn't match OpenGL shader expected type [{GetTypeFromActiveUniformType(uniformType)}]"); // No need to compare last element padding. // TODO: In case of float1/float2 arrays (rare) it is quite non-optimal to do a CompareMemory //variable.Size = uniformSize * (uniformCount - 1) + elementSize; //constantBufferDescription.Members[indexOfUniform] = variable; Uniforms.Add(new Uniform { Type = uniformType, Count = uniformCount, CompareSize = uniformSize + (uniformSize + 15)/16*16 * (uniformCount - 1), ConstantBufferSlot = constantBuffer.SlotStart, Offset = offset, UniformIndex = GL.GetUniformLocation(ProgramId, uniformName) }); }
private ActiveUniformType getBaseSampler(ActiveUniformType type) { if (type == ActiveUniformType.Sampler1D || type == ActiveUniformType.Sampler1DShadow || type == ActiveUniformType.IntSampler1D || type == ActiveUniformType.UnsignedIntSampler1D) return ActiveUniformType.Sampler1D; if (type == ActiveUniformType.Sampler2D || type == ActiveUniformType.Sampler2DShadow || type == ActiveUniformType.IntSampler2D || type == ActiveUniformType.UnsignedIntSampler2D || type == ActiveUniformType.IntSampler2DRect || type == ActiveUniformType.UnsignedIntSampler2DRect || type == ActiveUniformType.IntSampler2DMultisample || type == ActiveUniformType.Sampler2DMultisample || type == ActiveUniformType.Sampler2DRectShadow || type == ActiveUniformType.UnsignedIntSampler2D || type == ActiveUniformType.UnsignedIntSampler2DMultisample) return ActiveUniformType.Sampler2D; if (type == ActiveUniformType.Sampler3D || type == ActiveUniformType.IntSampler3D || type == ActiveUniformType.UnsignedIntSampler3D || type == ActiveUniformType.UnsignedIntSampler3D) return ActiveUniformType.Sampler3D; if (type == ActiveUniformType.SamplerCube || type == ActiveUniformType.IntSamplerCube || type == ActiveUniformType.SamplerCubeShadow || type == ActiveUniformType.UnsignedIntSamplerCube) return ActiveUniformType.SamplerCube; return ActiveUniformType.Sampler1D; }
private static EffectParameterClass GetClassFromActiveUniformType(ActiveUniformType type) { switch (type) { case ActiveUniformType.Int: case ActiveUniformType.Float: case ActiveUniformType.Bool: return EffectParameterClass.Scalar; case ActiveUniformType.FloatVec2: case ActiveUniformType.FloatVec3: case ActiveUniformType.FloatVec4: case ActiveUniformType.IntVec2: case ActiveUniformType.IntVec3: case ActiveUniformType.IntVec4: case ActiveUniformType.BoolVec2: case ActiveUniformType.BoolVec3: case ActiveUniformType.BoolVec4: case ActiveUniformType.UnsignedIntVec2: case ActiveUniformType.UnsignedIntVec3: case ActiveUniformType.UnsignedIntVec4: return EffectParameterClass.Vector; case ActiveUniformType.FloatMat2: case ActiveUniformType.FloatMat3: case ActiveUniformType.FloatMat4: case ActiveUniformType.FloatMat2x3: case ActiveUniformType.FloatMat2x4: case FloatMat3x2: case ActiveUniformType.FloatMat3x4: case ActiveUniformType.FloatMat4x2: case ActiveUniformType.FloatMat4x3: return EffectParameterClass.MatrixColumns; //return EffectParameterClass.MatrixRows; //return EffectParameterClass.Vector; case ActiveUniformType.Sampler2D: case ActiveUniformType.SamplerCube: case ActiveUniformType.Sampler3D: case ActiveUniformType.Sampler2DShadow: case ActiveUniformType.Sampler2DArray: case ActiveUniformType.Sampler2DArrayShadow: case ActiveUniformType.SamplerCubeShadow: case ActiveUniformType.IntSampler2D: case ActiveUniformType.IntSampler3D: case ActiveUniformType.IntSamplerCube: case ActiveUniformType.IntSampler2DArray: case ActiveUniformType.UnsignedIntSampler2D: case ActiveUniformType.UnsignedIntSampler3D: case ActiveUniformType.UnsignedIntSamplerCube: case ActiveUniformType.UnsignedIntSampler2DArray: #if !SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES case ActiveUniformType.Sampler1D: case ActiveUniformType.Sampler1DShadow: case ActiveUniformType.Sampler2DRect: case ActiveUniformType.Sampler2DRectShadow: case ActiveUniformType.Sampler1DArray: case ActiveUniformType.SamplerBuffer: case ActiveUniformType.Sampler1DArrayShadow: case ActiveUniformType.IntSampler1D: case ActiveUniformType.IntSampler2DRect: case ActiveUniformType.IntSampler1DArray: case ActiveUniformType.IntSamplerBuffer: case ActiveUniformType.UnsignedIntSampler1D: case ActiveUniformType.UnsignedIntSampler2DRect: case ActiveUniformType.UnsignedIntSampler1DArray: case ActiveUniformType.UnsignedIntSamplerBuffer: case ActiveUniformType.Sampler2DMultisample: case ActiveUniformType.IntSampler2DMultisample: case ActiveUniformType.UnsignedIntSampler2DMultisample: case ActiveUniformType.Sampler2DMultisampleArray: case ActiveUniformType.IntSampler2DMultisampleArray: case ActiveUniformType.UnsignedIntSampler2DMultisampleArray: #endif return EffectParameterClass.TextureBuffer; default: //TODO: log error ? return EffectParameterClass.Object; } }
public static UniformType To(ActiveUniformType type) { switch (type) { case ActiveUniformType.Int: return UniformType.Int; case ActiveUniformType.Float: return UniformType.Float; case ActiveUniformType.FloatVec2: return UniformType.FloatVector2; case ActiveUniformType.FloatVec3: return UniformType.FloatVector3; case ActiveUniformType.FloatVec4: return UniformType.FloatVector4; case ActiveUniformType.IntVec2: return UniformType.IntVector2; case ActiveUniformType.IntVec3: return UniformType.IntVector3; case ActiveUniformType.IntVec4: return UniformType.IntVector4; case ActiveUniformType.Bool: return UniformType.Bool; case ActiveUniformType.BoolVec2: return UniformType.BoolVector2; case ActiveUniformType.BoolVec3: return UniformType.BoolVector3; case ActiveUniformType.BoolVec4: return UniformType.BoolVector4; case ActiveUniformType.FloatMat2: return UniformType.FloatMatrix22; case ActiveUniformType.FloatMat3: return UniformType.FloatMatrix33; case ActiveUniformType.FloatMat4: return UniformType.FloatMatrix44; case ActiveUniformType.Sampler1D: return UniformType.Sampler1D; case ActiveUniformType.Sampler2D: return UniformType.Sampler2D; case ActiveUniformType.Sampler2DRect: return UniformType.Sampler2DRectangle; case ActiveUniformType.Sampler2DRectShadow: return UniformType.Sampler2DRectangleShadow; case ActiveUniformType.Sampler3D: return UniformType.Sampler3D; case ActiveUniformType.SamplerCube: return UniformType.SamplerCube; case ActiveUniformType.Sampler1DShadow: return UniformType.Sampler1DShadow; case ActiveUniformType.Sampler2DShadow: return UniformType.Sampler2DShadow; case ActiveUniformType.FloatMat2x3: return UniformType.FloatMatrix23; case ActiveUniformType.FloatMat2x4: return UniformType.FloatMatrix24; case ActiveUniformType.FloatMat3x2: return UniformType.FloatMatrix32; case ActiveUniformType.FloatMat3x4: return UniformType.FloatMatrix34; case ActiveUniformType.FloatMat4x2: return UniformType.FloatMatrix42; case ActiveUniformType.FloatMat4x3: return UniformType.FloatMatrix43; case ActiveUniformType.Sampler1DArray: return UniformType.Sampler1DArray; case ActiveUniformType.Sampler2DArray: return UniformType.Sampler2DArray; case ActiveUniformType.Sampler1DArrayShadow: return UniformType.Sampler1DArrayShadow; case ActiveUniformType.Sampler2DArrayShadow: return UniformType.Sampler2DArrayShadow; case ActiveUniformType.SamplerCubeShadow: return UniformType.SamplerCubeShadow; case ActiveUniformType.IntSampler1D: return UniformType.IntSampler1D; case ActiveUniformType.IntSampler2D: return UniformType.IntSampler2D; case ActiveUniformType.IntSampler2DRect: return UniformType.IntSampler2DRectangle; case ActiveUniformType.IntSampler3D: return UniformType.IntSampler3D; case ActiveUniformType.IntSamplerCube: return UniformType.IntSamplerCube; case ActiveUniformType.IntSampler1DArray: return UniformType.IntSampler1DArray; case ActiveUniformType.IntSampler2DArray: return UniformType.IntSampler2DArray; case ActiveUniformType.UnsignedIntSampler1D: return UniformType.UnsignedIntSampler1D; case ActiveUniformType.UnsignedIntSampler2D: return UniformType.UnsignedIntSampler2D; case ActiveUniformType.UnsignedIntSampler2DRect: return UniformType.UnsignedIntSampler2DRectangle; case ActiveUniformType.UnsignedIntSampler3D: return UniformType.UnsignedIntSampler3D; case ActiveUniformType.UnsignedIntSamplerCube: return UniformType.UnsignedIntSamplerCube; case ActiveUniformType.UnsignedIntSampler1DArray: return UniformType.UnsignedIntSampler1DArray; } throw new ArgumentException("type"); }
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type) { int length; GetProgram(program, OpenGL.ProgramParameter.ACTIVE_ATTRIBUTE_MAX_LENGTH, out length); StringBuilder sb = new StringBuilder(length == 0 ? 1 : length); GetActiveUniform( program, uniformIndex, sb.Capacity, out length, out size, out type, sb); return sb.ToString(); }
private void GivenProgramHasUniform( string name, int expectedLocation = 2, ActiveUniformType type = ActiveUniformType.FloatMat4) { var uniform = new ShaderUniform(name, expectedLocation, 8, type); adapter.Setup(a => a.GetUniformLocation(program.Handle, name)) .Returns(expectedLocation); adapter.Setup(a => a.GetActiveUniform(program.Handle, expectedLocation, It.IsAny<int>())) .Returns(uniform); program.Link(); program.GetUniformLocation(name); }
public Variable(int location, string name, ActiveUniformType type) { Location = location; Name = name; Type = type; }
private MojoShader.MOJOSHADER_samplerType getSamplerType(ActiveUniformType type) { ActiveUniformType t = getBaseSampler(type); switch (t) { case ActiveUniformType.Sampler1D: return MojoShader.MOJOSHADER_samplerType.MOJOSHADER_SAMPLER_1D; case ActiveUniformType.Sampler2D: return MojoShader.MOJOSHADER_samplerType.MOJOSHADER_SAMPLER_2D; case ActiveUniformType.SamplerCube: return MojoShader.MOJOSHADER_samplerType.MOJOSHADER_SAMPLER_CUBE; case ActiveUniformType.Sampler3D: return MojoShader.MOJOSHADER_samplerType.MOJOSHADER_SAMPLER_VOLUME; } return MojoShader.MOJOSHADER_samplerType.MOJOSHADER_SAMPLER_UNKNOWN; }
public UniformInfo(string name, int size, ActiveUniformType type) { _type = type; _size = size; _name = name; }
public static uint getColumnCount(ActiveUniformType type) { switch (type) { case ActiveUniformType.FloatMat2: return getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float); case ActiveUniformType.FloatMat3: return getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float); case ActiveUniformType.FloatMat4: return getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float); case ActiveUniformType.FloatMat2x3: return getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float); case ActiveUniformType.FloatMat2x4: return getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float); case ActiveUniformType.FloatMat3x2: return getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float); case ActiveUniformType.FloatMat3x4: return getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float); case ActiveUniformType.FloatMat4x2: return getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float); case ActiveUniformType.FloatMat4x3: return getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float); } if (getBaseType(type) == type) return 1; if (type <= ActiveUniformType.BoolVec4 && type >= ActiveUniformType.BoolVec2) return (uint)(type - ActiveUniformType.BoolVec2) + 2; if (type <= ActiveUniformType.DoubleVec4 && type >= ActiveUniformType.DoubleVec2) return (uint)(type - ActiveUniformType.DoubleVec2) + 2; if (type <= ActiveUniformType.FloatVec4 && type >= ActiveUniformType.FloatVec2) return (uint)(type - ActiveUniformType.FloatVec2) + 2; if (type <= ActiveUniformType.IntVec4 && type >= ActiveUniformType.IntVec2) return (uint)(type - ActiveUniformType.IntVec2) + 2; if (type <= ActiveUniformType.UnsignedIntVec4 && type >= ActiveUniformType.UnsignedIntVec2) return (uint)(type - ActiveUniformType.UnsignedIntVec2) + 2; return 1; }
private static int GetCountFromActiveUniformType(ActiveUniformType type) { switch (type) { case ActiveUniformType.Int: case ActiveUniformType.Float: case ActiveUniformType.Bool: return 1; case ActiveUniformType.IntVec2: case ActiveUniformType.UnsignedIntVec2: case ActiveUniformType.FloatVec2: case ActiveUniformType.BoolVec2: return 2; case ActiveUniformType.IntVec3: case ActiveUniformType.UnsignedIntVec3: case ActiveUniformType.FloatVec3: case ActiveUniformType.BoolVec3: return 3; case ActiveUniformType.IntVec4: case ActiveUniformType.UnsignedIntVec4: case ActiveUniformType.FloatVec4: case ActiveUniformType.BoolVec4: case ActiveUniformType.FloatMat2: return 4; case ActiveUniformType.FloatMat2x3: case FloatMat3x2: return 6; case ActiveUniformType.FloatMat2x4: case ActiveUniformType.FloatMat4x2: return 8; case ActiveUniformType.FloatMat3: return 9; case ActiveUniformType.FloatMat3x4: case ActiveUniformType.FloatMat4x3: return 12; case ActiveUniformType.FloatMat4: return 16; case ActiveUniformType.Sampler2D: case ActiveUniformType.SamplerCube: case ActiveUniformType.Sampler3D: case ActiveUniformType.Sampler2DShadow: case ActiveUniformType.SamplerCubeShadow: case ActiveUniformType.IntSampler2D: case ActiveUniformType.IntSampler3D: case ActiveUniformType.IntSamplerCube: case ActiveUniformType.UnsignedIntSampler2D: case ActiveUniformType.UnsignedIntSampler3D: case ActiveUniformType.UnsignedIntSamplerCube: case ActiveUniformType.Sampler2DArray: case ActiveUniformType.Sampler2DArrayShadow: case ActiveUniformType.IntSampler2DArray: case ActiveUniformType.UnsignedIntSampler2DArray: #if !SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES case ActiveUniformType.Sampler1D: case ActiveUniformType.Sampler1DShadow: case ActiveUniformType.Sampler2DRect: case ActiveUniformType.Sampler2DRectShadow: case ActiveUniformType.IntSampler1D: case ActiveUniformType.IntSampler2DRect: case ActiveUniformType.UnsignedIntSampler1D: case ActiveUniformType.UnsignedIntSampler2DRect: case ActiveUniformType.Sampler1DArray: case ActiveUniformType.Sampler1DArrayShadow: case ActiveUniformType.IntSampler1DArray: case ActiveUniformType.UnsignedIntSampler1DArray: #endif return 1; #if !SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES case ActiveUniformType.SamplerBuffer: case ActiveUniformType.IntSamplerBuffer: case ActiveUniformType.UnsignedIntSamplerBuffer: return 1; case ActiveUniformType.Sampler2DMultisample: case ActiveUniformType.IntSampler2DMultisample: case ActiveUniformType.UnsignedIntSampler2DMultisample: return 1; case ActiveUniformType.Sampler2DMultisampleArray: case ActiveUniformType.IntSampler2DMultisampleArray: case ActiveUniformType.UnsignedIntSampler2DMultisampleArray: #endif return 1; default: //TODO: log error ? return 0; } }
private Uniform CreateUniform( string name, int location, ActiveUniformType type) { switch (type) { case ActiveUniformType.Float: return new UniformFloatGL3x(name, location, this); case ActiveUniformType.FloatVec2: return new UniformFloatVector2GL3x(name, location, this); case ActiveUniformType.FloatVec3: return new UniformFloatVector3GL3x(name, location, this); case ActiveUniformType.FloatVec4: return new UniformFloatVector4GL3x(name, location, this); case ActiveUniformType.Int: return new UniformIntGL3x(name, location, UniformType.Int, this); case ActiveUniformType.IntVec2: return new UniformIntVector2GL3x(name, location, this); case ActiveUniformType.IntVec3: return new UniformIntVector3GL3x(name, location, this); case ActiveUniformType.IntVec4: return new UniformIntVector4GL3x(name, location, this); case ActiveUniformType.Bool: return new UniformBoolGL3x(name, location, this); case ActiveUniformType.BoolVec2: return new UniformBoolVector2GL3x(name, location, this); case ActiveUniformType.BoolVec3: return new UniformBoolVector3GL3x(name, location, this); case ActiveUniformType.BoolVec4: return new UniformBoolVector4GL3x(name, location, this); case ActiveUniformType.FloatMat2: return new UniformFloatMatrix22GL3x(name, location, this); case ActiveUniformType.FloatMat3: return new UniformFloatMatrix33GL3x(name, location, this); case ActiveUniformType.FloatMat4: return new UniformFloatMatrix44GL3x(name, location, this); case ActiveUniformType.FloatMat2x3: return new UniformFloatMatrix23GL3x(name, location, this); case ActiveUniformType.FloatMat2x4: return new UniformFloatMatrix24GL3x(name, location, this); case ActiveUniformType.FloatMat3x2: return new UniformFloatMatrix32GL3x(name, location, this); case ActiveUniformType.FloatMat3x4: return new UniformFloatMatrix34GL3x(name, location, this); case ActiveUniformType.FloatMat4x2: return new UniformFloatMatrix42GL3x(name, location, this); case ActiveUniformType.FloatMat4x3: return new UniformFloatMatrix43GL3x(name, location, this); case ActiveUniformType.Sampler1D: case ActiveUniformType.Sampler2D: case ActiveUniformType.Sampler2DRect: case ActiveUniformType.Sampler2DRectShadow: case ActiveUniformType.Sampler3D: case ActiveUniformType.SamplerCube: case ActiveUniformType.Sampler1DShadow: case ActiveUniformType.Sampler2DShadow: case ActiveUniformType.Sampler1DArray: case ActiveUniformType.Sampler2DArray: case ActiveUniformType.Sampler1DArrayShadow: case ActiveUniformType.Sampler2DArrayShadow: case ActiveUniformType.SamplerCubeShadow: case ActiveUniformType.IntSampler1D: case ActiveUniformType.IntSampler2D: case ActiveUniformType.IntSampler2DRect: case ActiveUniformType.IntSampler3D: case ActiveUniformType.IntSamplerCube: case ActiveUniformType.IntSampler1DArray: case ActiveUniformType.IntSampler2DArray: case ActiveUniformType.UnsignedIntSampler1D: case ActiveUniformType.UnsignedIntSampler2D: case ActiveUniformType.UnsignedIntSampler2DRect: case ActiveUniformType.UnsignedIntSampler3D: case ActiveUniformType.UnsignedIntSamplerCube: case ActiveUniformType.UnsignedIntSampler1DArray: case ActiveUniformType.UnsignedIntSampler2DArray: return new UniformIntGL3x(name, location, TypeConverterGL3x.To(type), this); } // // A new Uniform derived class needs to be added to support this uniform type. // throw new NotSupportedException("An implementation for uniform type " + type.ToString() + " does not exist."); }
private static EffectParameterType GetTypeFromActiveUniformType(ActiveUniformType type) { switch (type) { case ActiveUniformType.Int: case ActiveUniformType.IntVec2: case ActiveUniformType.IntVec3: case ActiveUniformType.IntVec4: return EffectParameterType.Int; case ActiveUniformType.Float: case ActiveUniformType.FloatVec2: case ActiveUniformType.FloatVec3: case ActiveUniformType.FloatVec4: case ActiveUniformType.FloatMat2: case ActiveUniformType.FloatMat3: case ActiveUniformType.FloatMat4: case ActiveUniformType.FloatMat2x3: case ActiveUniformType.FloatMat2x4: case FloatMat3x2: case ActiveUniformType.FloatMat3x4: case ActiveUniformType.FloatMat4x2: case ActiveUniformType.FloatMat4x3: return EffectParameterType.Float; case ActiveUniformType.Bool: case ActiveUniformType.BoolVec2: case ActiveUniformType.BoolVec3: case ActiveUniformType.BoolVec4: return EffectParameterType.Bool; case ActiveUniformType.UnsignedIntVec2: case ActiveUniformType.UnsignedIntVec3: case ActiveUniformType.UnsignedIntVec4: return EffectParameterType.UInt; #if !SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES case ActiveUniformType.Sampler1D: case ActiveUniformType.Sampler1DShadow: case ActiveUniformType.IntSampler1D: case ActiveUniformType.UnsignedIntSampler1D: return EffectParameterType.Texture1D; #endif case ActiveUniformType.Sampler2D: case ActiveUniformType.Sampler2DShadow: case ActiveUniformType.IntSampler2D: case ActiveUniformType.UnsignedIntSampler2D: #if !SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES case ActiveUniformType.Sampler2DRect: case ActiveUniformType.Sampler2DRectShadow: case ActiveUniformType.IntSampler2DRect: case ActiveUniformType.UnsignedIntSampler2DRect: #endif return EffectParameterType.Texture2D; case ActiveUniformType.Sampler3D: case ActiveUniformType.IntSampler3D: case ActiveUniformType.UnsignedIntSampler3D: return EffectParameterType.Texture3D; case ActiveUniformType.SamplerCube: case ActiveUniformType.SamplerCubeShadow: case ActiveUniformType.IntSamplerCube: case ActiveUniformType.UnsignedIntSamplerCube: return EffectParameterType.TextureCube; case ActiveUniformType.Sampler2DArray: case ActiveUniformType.Sampler2DArrayShadow: case ActiveUniformType.IntSampler2DArray: case ActiveUniformType.UnsignedIntSampler2DArray: return EffectParameterType.Texture2DArray; #if !SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES case ActiveUniformType.Sampler1DArray: case ActiveUniformType.Sampler1DArrayShadow: case ActiveUniformType.IntSampler1DArray: case ActiveUniformType.UnsignedIntSampler1DArray: return EffectParameterType.Texture1DArray; case ActiveUniformType.SamplerBuffer: case ActiveUniformType.IntSamplerBuffer: case ActiveUniformType.UnsignedIntSamplerBuffer: return EffectParameterType.TextureBuffer; case ActiveUniformType.Sampler2DMultisample: case ActiveUniformType.IntSampler2DMultisample: case ActiveUniformType.UnsignedIntSampler2DMultisample: return EffectParameterType.Texture2DMultisampled; case ActiveUniformType.Sampler2DMultisampleArray: case ActiveUniformType.IntSampler2DMultisampleArray: case ActiveUniformType.UnsignedIntSampler2DMultisampleArray: return EffectParameterType.Texture2DMultisampledArray; #endif default: //TODO: log error ? return EffectParameterType.Void; } }
public static uint getElementCount(ActiveUniformType type, ActiveUniformType baseType) { switch (type) { case ActiveUniformType.FloatMat2: return getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float); case ActiveUniformType.FloatMat3: return getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float); case ActiveUniformType.FloatMat4: return getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float); case ActiveUniformType.FloatMat2x3: return getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float); case ActiveUniformType.FloatMat2x4: return getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float); case ActiveUniformType.FloatMat3x2: return getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float); case ActiveUniformType.FloatMat3x4: return getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float); case ActiveUniformType.FloatMat4x2: return getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec2, ActiveUniformType.Float); case ActiveUniformType.FloatMat4x3: return getElementCount(ActiveUniformType.FloatVec4, ActiveUniformType.Float) * getElementCount(ActiveUniformType.FloatVec3, ActiveUniformType.Float); } if (type == baseType) return 1; switch (baseType) { case ActiveUniformType.Bool: return (uint)(type - ActiveUniformType.Bool) + 1; case ActiveUniformType.Double: return (uint)(type - ActiveUniformType.DoubleVec2) + 2; case ActiveUniformType.Float: return (uint)(type - ActiveUniformType.FloatVec2) + 2; case ActiveUniformType.Int: return (uint)(type - ActiveUniformType.IntVec2) + 2; case ActiveUniformType.UnsignedInt: return (uint)(type - ActiveUniformType.UnsignedIntVec2) + 2; } return 1; }
public static string GetActiveUniform(int program, int uniformIndex, out int size, out ActiveUniformType type) { int length; GetProgram(program, GetProgramParameterName.ActiveUniformMaxLength, out length); StringBuilder sb = new StringBuilder(length == 0 ? 1 : length); GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb); return sb.ToString(); }
private MojoShader.MOJOSHADER_symbolClass getSymbolClass(ActiveUniformType type) { switch (type) { case ActiveUniformType.FloatMat2: case ActiveUniformType.FloatMat3: case ActiveUniformType.FloatMat4: case ActiveUniformType.FloatMat2x3: case ActiveUniformType.FloatMat2x4: case ActiveUniformType.FloatMat3x2: case ActiveUniformType.FloatMat3x4: case ActiveUniformType.FloatMat4x2: case ActiveUniformType.FloatMat4x3: return MojoShader.MOJOSHADER_symbolClass.MOJOSHADER_SYMCLASS_MATRIX_COLUMNS; case ActiveUniformType.Float: return MojoShader.MOJOSHADER_symbolClass.MOJOSHADER_SYMCLASS_SCALAR; case ActiveUniformType.BoolVec2: case ActiveUniformType.BoolVec3: case ActiveUniformType.BoolVec4: case ActiveUniformType.DoubleVec2: case ActiveUniformType.DoubleVec3: case ActiveUniformType.DoubleVec4: case ActiveUniformType.FloatVec2: case ActiveUniformType.FloatVec3: case ActiveUniformType.FloatVec4: case ActiveUniformType.IntVec2: case ActiveUniformType.IntVec3: case ActiveUniformType.IntVec4: case ActiveUniformType.UnsignedIntVec2: case ActiveUniformType.UnsignedIntVec3: case ActiveUniformType.UnsignedIntVec4: return MojoShader.MOJOSHADER_symbolClass.MOJOSHADER_SYMCLASS_VECTOR; } return MojoShader.MOJOSHADER_symbolClass.MOJOSHADER_SYMCLASS_OBJECT; }