首页 > 代码库 > OpenGLShader 编程系列 - 查询shader中的Uniforms

OpenGLShader 编程系列 - 查询shader中的Uniforms

    GLint maxUniformLen;
    GLint numUniforms;
    GLint index;

    glGetProgramiv(this->_program, GL_ACTIVE_UNIFORMS, &numUniforms);
    glGetProgramiv(this->_program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen);
    GLchar* uniformName = (GLchar*)malloc(sizeof(GLchar)*maxUniformLen);
    for(index = 0; index < numUniforms; index++)
    {
        GLint size;
        GLenum type;
        GLint location;
        GLint length;

        glGetActiveUniform(this->_program, index, maxUniformLen, &length, &size, &type, uniformName);

        location = glGetUniformLocation(this->_program, uniformName);

        switch(type)
        {
              case GL_FLOAT:
                    //
                    break;
             case GL_FLOAT_VEC2:
                  //
                  break;
             case GL_FLOAT_VEC3:
                  //
                  break;
             case GL_FLOAT_VEC4:
                  //
                  break;
             case GL_INT:
                  //
                  break;
                //.....all type
             default:
                 //
                break;
        }

       

      

    }
    free(uniformName);

OpenGLShader 编程系列 - 查询shader中的Uniforms