Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private void LoadUniforms()
        {
            Symbols  = new List <MojoShader.MOJOSHADER_symbol>();
            Samplers = new List <MojoShader.MOJOSHADER_sampler>();
            int count = 0;

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

            int maxNameLength = 0;

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

            for (int uni = 0; uni < count; ++uni)
            {
                int arraySize = 0;
                ActiveUniformType type;
                int actLen = 0;
                GL.GetActiveUniform(program, uni, maxNameLength, out actLen, out arraySize, out type, nameData);

                string name        = nameData.ToString();
                uint   elementSize = UniformTypeInfos.getElementSize(type);

                MojoShader.MOJOSHADER_symbol sym = new MojoShader.MOJOSHADER_symbol();
                sym.name          = name;
                sym.info          = new MojoShader.MOJOSHADER_symbolTypeInfo();
                sym.info.elements = (uint)arraySize;
                sym.info.columns  = UniformTypeInfos.getColumnCount(type);
                sym.info.rows     = UniformTypeInfos.getElementCount(type, UniformTypeInfos.getBaseType(type)) / sym.info.columns;

                sym.info.members         = IntPtr.Zero;
                sym.info.member_count    = 0;
                sym.info.parameter_class = getSymbolClass(type); //TODO:
                sym.info.parameter_type  = getSymbolType(type);  //TODO:

                sym.register_index = (uint)GL.GetUniformLocation(program, name);
                sym.register_count = (uint)arraySize * (uint)Math.Ceiling(elementSize / 4.0f);
                ActiveUniformType baseType = UniformTypeInfos.getBaseType(type);
                if (baseType == ActiveUniformType.Bool)
                {
                    sym.register_set = MojoShader.MOJOSHADER_symbolRegisterSet.MOJOSHADER_SYMREGSET_BOOL;
                }
                else if (baseType == ActiveUniformType.Float)
                {
                    sym.register_set = MojoShader.MOJOSHADER_symbolRegisterSet.MOJOSHADER_SYMREGSET_FLOAT4;
                }
                else if (baseType == ActiveUniformType.Int || baseType == ActiveUniformType.UnsignedInt)
                {
                    sym.register_set = MojoShader.MOJOSHADER_symbolRegisterSet.MOJOSHADER_SYMREGSET_INT4;
                }
                else
                {
                    sym.register_set = MojoShader.MOJOSHADER_symbolRegisterSet.MOJOSHADER_SYMREGSET_SAMPLER;
                }


                Symbols.Add(sym);

                if (sym.register_set == MojoShader.MOJOSHADER_symbolRegisterSet.MOJOSHADER_SYMREGSET_SAMPLER)
                {
                    LoadSampler(sym, type);
                }


                //TODO: add to list


                nameData.Clear();
            }
        }