Exemplo n.º 1
0
 public ShaderAttribute(string name, int location, int size, ActiveAttribType attribType)
 {
     Name = name;
     Location = location;
     Size = size;
     AttribType = attribType;
 }
Exemplo n.º 2
0
        private void LoadAttributes()
        {
            Attributes = new List <ShaderData.Attribute>();
            int count = 0;

            GL.GetProgram(program, GetProgramParameterName.ActiveAttributes, out count);

            int maxNameLength = 0;

            GL.GetProgram(program, GetProgramParameterName.ActiveAttributeMaxLength, out maxNameLength);
            StringBuilder nameData = new StringBuilder(maxNameLength);

            for (int attrib = 0; attrib < count; ++attrib)
            {
                int arraySize         = 0;
                ActiveAttribType type = ActiveAttribType.None;
                int actLen            = 0;
                GL.GetActiveAttrib(program, attrib, maxNameLength, out actLen, out arraySize, out type, nameData);
                ShaderData.Attribute attribute = new ShaderData.Attribute();
                attribute.name  = nameData.ToString();
                attribute.index = 0;
                MojoShader.MOJOSHADER_usage usage;
                if (usageMapping.TryGetValue(attribute.name, out usage))
                {
                    attribute.usage = EffectObject.ToXNAVertexElementUsage(usage);
                }


                Attributes.Add(attribute);

                nameData.Clear();
            }
        }
Exemplo n.º 3
0
 public ShaderAttributeInfo(ShaderProgram program, string name, ActiveAttribType type, int size, int location)
 {
     Program  = program;
     Name     = name;
     Type     = type;
     Location = location;
 }
Exemplo n.º 4
0
        public static ShaderVertexAttributeType To(ActiveAttribType type)
        {
            switch (type)
            {
                case ActiveAttribType.Float:
                    return ShaderVertexAttributeType.Float;
                case ActiveAttribType.FloatVec2:
                    return ShaderVertexAttributeType.FloatVector2;
                case ActiveAttribType.FloatVec3:
                    return ShaderVertexAttributeType.FloatVector3;
                case ActiveAttribType.FloatVec4:
                    return ShaderVertexAttributeType.FloatVector4;
                case ActiveAttribType.FloatMat2:
                    return ShaderVertexAttributeType.FloatMatrix22;
                case ActiveAttribType.FloatMat3:
                    return ShaderVertexAttributeType.FloatMatrix33;
                case ActiveAttribType.FloatMat4:
                    return ShaderVertexAttributeType.FloatMatrix44;
                case (ActiveAttribType)All.Int:
                    return ShaderVertexAttributeType.Int;
                case (ActiveAttribType)All.IntVec2:
                    return ShaderVertexAttributeType.IntVector2;
                case (ActiveAttribType)All.IntVec3:
                    return ShaderVertexAttributeType.IntVector3;
                case (ActiveAttribType)All.IntVec4:
                    return ShaderVertexAttributeType.IntVector4;
            }

            throw new ArgumentException("type");
        }
Exemplo n.º 5
0
 public ShaderAttributeInfo(string name, int location, int size, ActiveAttribType type)
 {
     Name     = name;
     Location = location;
     Size     = size;
     Type     = type;
 }
Exemplo n.º 6
0
 public ProgramAttribute(string name, int slot, int count, ActiveAttribType type)
 {
     Name  = name;
     Slot  = slot;
     Count = count;
     Type  = type;
 }
Exemplo n.º 7
0
 public ProgramAttribute(string name,
                         int slot, int size, ActiveAttribType type)
 {
     Name = name;
     Slot = slot;
     Size = size;
     Type = type;
 }
Exemplo n.º 8
0
        internal static VertexElementType Convert(ActiveAttribType type)
        {
            if (!attribTypes.ContainsValue(type))
            {
                throw new NotSupportedException("type is not supported");
            }

            return(attribTypes.First((f) => f.Value == type).Key);
        }
Exemplo n.º 9
0
 public void GetActiveAttrib(uint program, uint index, int bufsize, int[] length, int[] size, uint[] type, StringBuilder name)
 {
     ActiveAttribType[] _types = new ActiveAttribType[type.Length];
     for (int i = 0; i < type.Length; i++)
     {
         _types[i] = (ActiveAttribType)type[i];
     }
     GL.GetActiveAttrib(program, index, bufsize, length, size, _types, name);
 }
Exemplo n.º 10
0
        public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
        {
            int length;

            GetProgram(program, ES30.GetProgramParameterName.ActiveAttributeMaxLength, out length);
            StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);

            GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
            return(sb.ToString());
        }
Exemplo n.º 11
0
        public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
        {
            int length;

            GetProgram(program, GetProgramParameterName.ActiveAttributeMaxLength, out length);
            string str;

            GetActiveAttrib(program, index, length == 0 ? 1 : length * 2, out length, out size, out type, out str);
            return(str);
        }
Exemplo n.º 12
0
        public void GetActiveAttrib(uint program, uint index, int bufsize, ref int length, ref int size, ref uint type, StringBuilder name)
        {
            ActiveAttribType _type = new ActiveAttribType();
            int l = 0;
            int s = 0;

            GL.GetActiveAttrib(program, index, bufsize, out l, out s, out _type, name);
            type   = (uint)_type;
            length = l;
            size   = s;
        }
Exemplo n.º 13
0
 public ShaderAttribute(
     string attributeName,
     int index,
     ActiveAttribType attributeType,
     int attributeSize)
 {
     AttributeName = attributeName;
     Index         = index;
     AttributeType = attributeType;
     AttributeSize = attributeSize;
 }
Exemplo n.º 14
0
        public static unsafe string GetActiveAttrib(uint program, uint attributeIndex, out int attributeSize, out ActiveAttribType attributeType)
        {
            int[]         length = new int[1];
            int[]         size   = new int[1];
            StringBuilder result = new StringBuilder();

            ActiveAttribType[] type = new ActiveAttribType[1];
            fixed(int *lenPtr = &length[0])
            fixed(ActiveAttribType * typePtr = &type[0])
            {
                GLCore.GetActiveAttrib(program, attributeIndex, 1024, lenPtr, size, (IntPtr)typePtr, result);
            }
            attributeSize = size[0];
            attributeType = type[0];
            return(result.ToString());
        }
Exemplo n.º 15
0
        public ShaderAttribute CreateShaderAttribute(string nameString, ActiveAttribType type, int location, int sizeElements)
        {
            ShaderAttribute returnValue;

            if (supportedAttributes.ContainsKey(nameString))
            {
                ShaderAttribute supported  = supportedAttributes[nameString];
                ShaderDataType  attribType = AttribTypeToDataType(type);
                if (supported.dataType == attribType)
                {
                    /*
                     * Logger.LogInfoLinePart("Created attribute", System.ConsoleColor.Gray);
                     * Logger.LogInfoLinePart(" (", System.ConsoleColor.Gray);
                     * Logger.LogInfoLinePart("" + location, System.ConsoleColor.Red);
                     * Logger.LogInfoLinePart(") ", System.ConsoleColor.Gray);
                     * Logger.LogInfoLinePart(GetDataTypeString(attribType), System.ConsoleColor.Cyan);
                     * Logger.LogInfoLinePart(" " + nameString, System.ConsoleColor.Gray);
                     * Logger.LogInfoLineEnd();
                     */
                    returnValue = new ShaderAttribute(supported.name, supported.dataType, location, sizeElements);
                }
                else
                {
                    Logger.LogError(Logger.ErrorState.Critical, "Shader data type mismatch with supported uniform type: "
                                    + " Expected: " + GetDataTypeString(supported.dataType)
                                    + " Got: " + GetDataTypeString(attribType));
                    returnValue = new ShaderAttribute(ShaderAttributeName.InvalidAttributeName, ShaderDataType.InvalidType);
                }
            }
            else if (nameString.StartsWith("uc"))
            {
                // Custom attribute is ok
                returnValue = new ShaderAttribute(ShaderAttributeName.CustomAttribute, AttribTypeToDataType(type), location, sizeElements);
            }
            else
            {
                Logger.LogError(Logger.ErrorState.Critical, "Unsupported shader attribute: " + nameString + ", of type:" + GetDataTypeString(AttribTypeToDataType(type)));
                returnValue = new ShaderAttribute(ShaderAttributeName.InvalidAttributeName, ShaderDataType.InvalidType);
            }

            return(returnValue);
        }
Exemplo n.º 16
0
        private Type TypeFromAttributeType(ActiveAttribType type)
        {
            switch (type)
            {
            case ActiveAttribType.Float: return(typeof(float));

            case ActiveAttribType.FloatMat2: return(typeof(float[]));

            case ActiveAttribType.FloatMat3: return(typeof(Matrix3));

            case ActiveAttribType.FloatMat4: return(typeof(Matrix4));

            case ActiveAttribType.FloatVec2: return(typeof(Vector2));

            case ActiveAttribType.FloatVec3: return(typeof(Vector3));

            case ActiveAttribType.FloatVec4: return(typeof(Vector4));

            default: return(typeof(object));
            }
        }
Exemplo n.º 17
0
        public static ShaderVertexAttributeType To(ActiveAttribType type)
        {
            switch (type)
            {
            case ActiveAttribType.Float:
                return(ShaderVertexAttributeType.Float);

            case ActiveAttribType.FloatVec2:
                return(ShaderVertexAttributeType.FloatVector2);

            case ActiveAttribType.FloatVec3:
                return(ShaderVertexAttributeType.FloatVector3);

            case ActiveAttribType.FloatVec4:
                return(ShaderVertexAttributeType.FloatVector4);

            case ActiveAttribType.FloatMat2:
                return(ShaderVertexAttributeType.FloatMatrix22);

            case ActiveAttribType.FloatMat3:
                return(ShaderVertexAttributeType.FloatMatrix33);

            case ActiveAttribType.FloatMat4:
                return(ShaderVertexAttributeType.FloatMatrix44);

            case (ActiveAttribType)All.Int:
                return(ShaderVertexAttributeType.Int);

            case (ActiveAttribType)All.IntVec2:
                return(ShaderVertexAttributeType.IntVector2);

            case (ActiveAttribType)All.IntVec3:
                return(ShaderVertexAttributeType.IntVector3);

            case (ActiveAttribType)All.IntVec4:
                return(ShaderVertexAttributeType.IntVector4);
            }

            throw new ArgumentException("type");
        }
Exemplo n.º 18
0
        /// <summary>
        /// Parses all of the parameters (attributes/uniforms) from the two attached shaders
        /// and then loads their location by passing this shader program into the parameter object.
        /// </summary>
        void GetParams()
        {
            shaderParams = new Dictionary <string, GLShaderProgramParam>();

            var resources    = new int[1];
            var actualLength = new int[1];
            var arraySize    = new int[1];

            glGetProgramiv(ProgramID, ProgramParameter.ActiveAttributes, resources);

            for (uint i = 0; i < resources[0]; i++)
            {
                var type = new ActiveAttribType[1];
                var sb   = new StringBuilder(256);
                glGetActiveAttrib(ProgramID, i, 256, actualLength, arraySize, type, sb);

                if (!shaderParams.ContainsKey(sb.ToString()))
                {
                    var param = new GLShaderProgramParam(TypeFromAttributeType(type[0]), ParamType.Attribute, sb.ToString());
                    shaderParams.Add(param.Name, param);
                    param.GetLocation(this);
                }
            }

            glGetProgramiv(ProgramID, ProgramParameter.ActiveUniforms, resources);

            for (uint i = 0; i < resources[0]; i++)
            {
                var type = new ActiveUniformType[1];
                System.Text.StringBuilder sb = new System.Text.StringBuilder(256);
                glGetActiveUniform(ProgramID, i, 256, actualLength, arraySize, type, sb);

                if (!shaderParams.ContainsKey(sb.ToString()))
                {
                    var param = new GLShaderProgramParam(TypeFromUniformType(type[0]), ParamType.Uniform, sb.ToString());
                    shaderParams.Add(param.Name, param);
                    param.GetLocation(this);
                }
            }
        }
Exemplo n.º 19
0
        public ShaderDataType AttribTypeToDataType(ActiveAttribType type)
        {
            switch (type)
            {
            case ActiveAttribType.Float:
                return(ShaderDataType.Float);

            case ActiveAttribType.FloatVec2:
                return(ShaderDataType.Float2);

            case ActiveAttribType.FloatVec3:
                return(ShaderDataType.Float3);

            case ActiveAttribType.FloatVec4:
                return(ShaderDataType.Float4);

            case ActiveAttribType.FloatMat4:
                return(ShaderDataType.Mat4);

            default:
                Logger.LogError(Logger.ErrorState.Critical, "Unsupported shader data type");
                return(ShaderDataType.InvalidType);
            }
        }
Exemplo n.º 20
0
        void SetAllVars()
        {
            int Ct = 0;

            GL.GetProgram(Handle, GetProgramParameterName.ActiveAttributes, out Ct);
            int              size = -1;
            String           Name = "";
            int              Len  = -1;
            ActiveAttribType T    = ActiveAttribType.None;

            for (int i = 0; i < Ct; i++)
            {
                GL.GetActiveAttrib(Handle, i, 100, out Len, out size, out T, out Name);
                int Pos = Name.IndexOf("[");
                if (Pos > 0)
                {
                    Name = Name.Remove(Pos);
                }
                Field v = new Field(Name);
                v.Kind  = DefKind.Attribute;
                v.AType = T;
                addVar(v);
            }
            ActiveUniformType U = ActiveUniformType.Float;

            GL.GetProgram(Handle, GetProgramParameterName.ActiveUniforms, out Ct);
            for (int i = 0; i < Ct; i++)
            {
                GL.GetActiveUniform(Handle, i, 100, out Len, out size, out U, out Name);

                Field v = new Field(Name);
                v.Kind  = DefKind.Uniform;
                v.UType = U;
                addVar(v);
            }
        }
Exemplo n.º 21
0
        public static string GL_type_to_string(ActiveAttribType type)
        {
            switch (type)
            {
            case ActiveAttribType.Int: return("int");

            case ActiveAttribType.Float: return("float");

            case ActiveAttribType.FloatVec2: return("vec2");

            case ActiveAttribType.FloatVec3: return("vec3");

            case ActiveAttribType.FloatVec4: return("vec4");

            case ActiveAttribType.FloatMat2: return("mat2");

            case ActiveAttribType.FloatMat3: return("mat3");

            case ActiveAttribType.FloatMat4: return("mat4");

            default: break;
            }
            return("other");
        }
Exemplo n.º 22
0
 public ShaderSizeInfo GetTypeSizeInfo(ActiveAttribType type)
 {
     return(GetTypeSizeInfo(AttribTypeToDataType(type)));
 }
Exemplo n.º 23
0
        public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
        {
            int length;
			GetProgram(program, GetProgramParameterName.ActiveAttributeMaxLength, out length);
            StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);

            GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
            return sb.ToString();
        }
Exemplo n.º 24
0
 internal static Format From(ActiveAttribType type)
 {
     return(ByActiveAttributeType[type]);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Parses all of the parameters (attributes/uniforms) from the two attached shaders
        /// and then loads their location by passing this shader program into the parameter object.
        /// </summary>
        private void GetParams()
        {
            shaderParams = new Dictionary <string, ProgramParam>();

#if GET_PROGRAM_INTERFACE
            if (Gl.GetAddress("glGetProgramInterfaceiv") == IntPtr.Zero)
            {
#endif
            int[] resources    = new int[1];
            int[] actualLength = new int[1];
            int[] arraySize    = new int[1];

            Gl.GetProgramiv(ProgramID, ProgramParameter.ActiveAttributes, resources);

            for (int i = 0; i < resources[0]; i++)
            {
                ActiveAttribType[]        type = new ActiveAttribType[1];
                System.Text.StringBuilder sb   = new System.Text.StringBuilder(256);
                Gl.GetActiveAttrib(ProgramID, i, 256, actualLength, arraySize, type, sb);

                if (!shaderParams.ContainsKey(sb.ToString()))
                {
                    ProgramParam param = new ProgramParam(TypeFromAttributeType(type[0]), ParamType.Attribute, sb.ToString());
                    shaderParams.Add(param.Name, param);
                    param.GetLocation(this);
                }
            }

            Gl.GetProgramiv(ProgramID, ProgramParameter.ActiveUniforms, resources);

            for (int i = 0; i < resources[0]; i++)
            {
                ActiveUniformType[]       type = new ActiveUniformType[1];
                System.Text.StringBuilder sb   = new System.Text.StringBuilder(256);
                Gl.GetActiveUniform(ProgramID, (uint)i, 256, actualLength, arraySize, type, sb);

                if (!shaderParams.ContainsKey(sb.ToString()))
                {
                    ProgramParam param = new ProgramParam(TypeFromUniformType(type[0]), ParamType.Uniform, sb.ToString());
                    shaderParams.Add(param.Name, param);
                    param.GetLocation(this);
                }
            }
#if GET_PROGRAM_INTERFACE
        }

        else
        {
            int[] resources = new int[1];
            Gl.GetProgramInterfaceiv(ProgramID, ProgramInterface.ProgramInput, ProgramInterfaceParameterName.ActiveResources, resources);

            for (int i = 0; i < resources[0]; i++)
            {
                int[] values = new int[2];
                Gl.GetProgramResourceiv(ProgramID, ProgramInterface.ProgramInput, (uint)i, 2, new ProgramResourceParameterName[] { ProgramResourceParameterName.NameLength, ProgramResourceParameterName.Type }, 256, null, values);
                System.Text.StringBuilder sb = new System.Text.StringBuilder(values[0]);
                Gl.GetProgramResourceName(ProgramID, ProgramInterface.ProgramInput, (uint)i, values[0], null, sb);

                if (!shaderParams.ContainsKey(sb.ToString()))
                {
                    ProgramParam param = new ProgramParam(TypeFromAttributeType((ActiveAttribType)values[1]), ParamType.Attribute, sb.ToString());
                    shaderParams.Add(param.Name, param);
                    param.GetLocation(this);
                }
            }

            Gl.GetProgramInterfaceiv(ProgramID, ProgramInterface.Uniform, ProgramInterfaceParameterName.ActiveResources, resources);

            for (int i = 0; i < resources[0]; i++)
            {
                int[] values = new int[2];
                Gl.GetProgramResourceiv(ProgramID, ProgramInterface.Uniform, (uint)i, 2, new ProgramResourceParameterName[] { ProgramResourceParameterName.NameLength, ProgramResourceParameterName.Type }, 256, null, values);
                System.Text.StringBuilder sb = new System.Text.StringBuilder(values[0]);
                Gl.GetProgramResourceName(ProgramID, ProgramInterface.Uniform, (uint)i, values[0], null, sb);

                if (!shaderParams.ContainsKey(sb.ToString()))
                {
                    ProgramParam param = new ProgramParam(TypeFromUniformType((ActiveUniformType)values[1]), ParamType.Uniform, sb.ToString());
                    shaderParams.Add(param.Name, param);
                    param.GetLocation(this);
                }
            }
        }
#endif
        }
Exemplo n.º 26
0
 internal ProgramAttribute(Program program, string name, int index, int count, ActiveAttribType type)
     : base(program, name, index)
 {
     this.format = Format.From(type);
     this.count  = count;
     bindFormat  = Formats.Vector4nb;
 }
Exemplo n.º 27
0
 internal ActiveAttribute(string name, int size, ActiveAttribType type)
 {
     Size = size;
     Name = name;
     Type = type;
 }
Exemplo n.º 28
0
 public ShaderAttributeData(string name, int location, int size, int length, ActiveAttribType type)
 {
     this.Name     = name;
     this.Location = location;
     this.Size     = size;
     this.Length   = length;
     this.Type     = type;
 }
Exemplo n.º 29
0
 internal static ShaderElementType FromGl(ActiveAttribType t)
 {
     return(FromGl((ActiveUniformType)t));
 }
Exemplo n.º 30
0
 public GLAttribute(ActiveAttribType type, int location, string name)
 {
     Type = type;
     Location = location;
     Name = name;
 }
Exemplo n.º 31
0
        public static string GetActiveAttrib(int program, int index, out int size, out ActiveAttribType type)
        {
            int length;
            GetProgram(program, OpenTK.Graphics.OpenGL.ProgramParameter.ACTIVE_ATTRIBUTE_MAX_LENGTH, out length);
            StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);

            GetActiveAttrib( program,  index, sb.Capacity, out length, out size, out type, sb);
            return sb.ToString();
        }
Exemplo n.º 32
0
        public static void print_all(GLint program)
        {
            GL_Log("--------------------");
            GL_Log("Shader Program " + program + " info:");
            int param = -1;

            GL.GetProgram(program, ProgramParameter.LinkStatus, out param);
            GL_Log("GL_LINK_STATUS = " + param, true);

            GL.GetProgram(program, ProgramParameter.AttachedShaders, out param);
            GL_Log("GL_ATTACHED_SHADERS = " + param, true);

            GL.GetProgram(program, ProgramParameter.ActiveAttributes, out param);
            GL_Log("GL_ACTIVE_ATTRIBUTES = " + param, true);
            for (int i = 0; i < param; i++)
            {
                ActiveAttribType type = 0;
                int           size    = 0;
                StringBuilder name    = new StringBuilder();
                int           length  = 0;
                GL.GetActiveAttrib(program, i, 64, out length, out size, out type, name);
                if (size > 1)
                {
                    for (int j = 0; j < size; j++)
                    {
                        string long_name = name + "[" + j + "]";
                        int    location  = GL.GetAttribLocation(program, long_name);
                        GL_Log(i + ") Type: " + GL_type_to_string(type) + "   Name: " + long_name + "   Location: " + location, true);
                    }
                }
                else
                {
                    string new_name = name + "";
                    int    location = GL.GetAttribLocation(program, new_name);
                    GL_Log(i + ") Type: " + GL_type_to_string(type) + "   Name: " + new_name + "   Location: " + location, true);
                }
            }

            GL.GetProgram(program, ProgramParameter.ActiveUniforms, out param);
            GL_Log("GL_ACTIVE_UNIFORMS = " + param, true);
            for (int i = 0; i < param; i++)
            {
                ActiveUniformType type = 0;
                int           size     = 0;
                StringBuilder name     = new StringBuilder();
                int           length   = 0;
                GL.GetActiveUniform(program, i, 64, out length, out size, out type, name);
                if (size > 1)
                {
                    for (int j = 0; j < size; j++)
                    {
                        string long_name = name + "[" + j + "]";
                        int    location  = GL.GetUniformLocation(program, long_name);
                        GL_Log(i + ") Type: " + GL_type_to_string(type) + "   Name: " + long_name + "   Location: " + location, true);
                    }
                }
                else
                {
                    string new_name = name + "";
                    int    location = GL.GetUniformLocation(program, new_name);
                    GL_Log(i + ") Type: " + GL_type_to_string(type) + "   Name: " + new_name + "   Location: " + location, true);
                }
            }

            Print_Program_Info_Log(program);
        }
Exemplo n.º 33
0
 public ActiveAttribInfo(int location, ActiveAttribType type, int size)
 {
     this.location = location;
     this.type     = type;
     this.size     = size;
 }