Exemple #1
0
        private bool FindUniforms(Dictionary <string, UniformValue> nameUniformDict, Dictionary <int, UniformValue> locationUniformDict)
        {
            nameUniformDict.Clear(); locationUniformDict.Clear();
            int nextLoc = 0;

            foreach (var shader in this.attachedShaders)
            {
                foreach (var item in shader.UniformVariableDict)
                {
                    string          varName = item.Key;
                    UniformVariable v       = item.Value;
                    if (nameUniformDict.ContainsKey(varName))
                    {
                        if (v.fieldInfo.FieldType != nameUniformDict[varName].variable.fieldInfo.FieldType)
                        {
                            this.logInfo = string.Format("Different uniform variable types of the same name[{0}!]", varName);
                            return(false);
                        }
                    }
                    else
                    {
                        v.location = nextLoc;
                        int byteSize = this.GetByteSize(v.fieldInfo.FieldType);
                        nextLoc += byteSize;
                        var value = new UniformValue(v, null);
                        nameUniformDict.Add(varName, value);
                        locationUniformDict.Add(v.location, value);
                    }
                }
            }

            return(true);
        }
Exemple #2
0
        private void Uniform3i(int location, int v0, int v1, int v2)
        {
            if (location < 0)
            {
                return;
            }

            ShaderProgram program = this.currentShaderProgram;

            if (program == null)
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }
            UniformVariable v = program.GetUniformVariable(location);

            if (v == null)
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }
            FieldInfo fieldInfo = v.fieldInfo;

            if (fieldInfo.FieldType.IsArray)
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }                                                                                      // TODO: not sure about this line.

            program.SetUniform3i(location, v0, v1, v2);
        }
Exemple #3
0
        private void UniformMatrix4fv(int location, int count, bool transpose, float[] value)
        {
            if (location < 0 || value == null || value.Length != 16)
            {
                return;
            }

            ShaderProgram program = this.currentShaderProgram;

            if (program == null)
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }
            // TODO:GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the glUniform command.
            if (count < 0)
            {
                SetLastError(ErrorCode.InvalidValue); return;
            }

            UniformVariable v = program.GetUniformVariable(location);

            if (v == null)
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }
            FieldInfo fieldInfo = v.fieldInfo;

            if ((count > 1) && (!fieldInfo.FieldType.IsArray))
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }

            program.SetUniform4fv(location, count, transpose, value);
        }
Exemple #4
0
        private string FindUniformVariables(Type shaderCodeType, Dictionary <string, UniformVariable> dict)
        {
            dict.Clear();
            foreach (var item in shaderCodeType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                object[] inAttribute = item.GetCustomAttributes(typeof(UniformAttribute), false);
                if (inAttribute != null && inAttribute.Length > 0) // this is a 'uniform ...;' field.
                {
                    var v = new UniformVariable(item);
                    dict.Add(item.Name, v);
                }
            }

            return(string.Empty);
        }
Exemple #5
0
        private void Uniform1fv(int location, int count, float[] value)
        {
            if (location < 0 || value == null || value.Length != 1)
            {
                return;
            }

            ShaderProgram program = this.currentShaderProgram;

            if (program == null)
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }
            // TODO:GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the glUniform command.
            if (count < 0)
            {
                SetLastError(ErrorCode.InvalidValue); return;
            }

            UniformVariable v = program.GetUniformVariable(location);

            if (v == null)
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }
            FieldInfo fieldInfo = v.fieldInfo;

            if ((count > 1) && (!fieldInfo.FieldType.IsArray))
            {
                SetLastError(ErrorCode.InvalidOperation); return;
            }

            var copy = new float[count];

            for (int i = 0; i < count; i++)
            {
                copy[i] = value[i];
            }
            program.SetUniform(location, copy);
        }
Exemple #6
0
 public UniformValue(UniformVariable variable, Object value = null)
 {
     this.variable = variable;
     this.value    = value;
 }