Buscar..


Introducción

Se pueden obtener varias características de los objetos del programa a través de la API del programa.

Información del atributo vértice

La información sobre los atributos de vértice se puede recuperar con la función OGL glGetProgram y los parámetros GL_ACTIVE_ATTRIBUTES y GL_ACTIVE_ATTRIBUTE_MAX_LENGTH .

La ubicación de un atributo de sombreado activo puede determinarse por la función OGL glGetAttribLocation , por el índice del atributo.

GLuint shaderProg = ...;
std::map< std::string, GLint > attributeLocation;

GLint maxAttribLen, nAttribs;
glGetProgramiv( shaderProg, GL_ACTIVE_ATTRIBUTES, &nAttribs );
glGetProgramiv( shaderProg, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribLen 
GLint written, size;
GLenum type;
std::vector< GLchar >attrName( maxAttribLen );
for( int attribInx = 0; attribInx < nAttribs; attribInx++ )
{
    glGetActiveAttrib( shaderProg, attribInx, maxAttribLen, &written, &size, &type, &attrName[0] );
    attributeLocation[attrName] = glGetAttribLocation( shaderProg, attrName.data() );
}

Información uniforme

La información sobre los uniformes activos en un programa se puede recuperar con la función OGL glGetProgram y los parámetros GL_ACTIVE_UNIFORMS y GL_ACTIVE_UNIFORM_MAX_LENGTH .

La ubicación de una variable uniforme de sombreado activa puede determinarse por la función OGL glGetActiveUniform , por el índice del atributo.

GLuint shaderProg = ...;
std::map< std::string, GLint > unifomLocation;

GLint maxUniformLen, nUniforms;
glGetProgramiv( shaderProg, GL_ACTIVE_UNIFORMS, &nUniforms );
glGetProgramiv( shaderProg, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen );

GLint written, size;
GLenum type;
std::vector< GLchar >uniformName( maxUniformLen );
for( int uniformInx = 0; uniformInx < nUniforms; uniformInx++ )
{
    glGetActiveUniform( shaderProg, uniformInx, maxUniformLen, &written, &size, &type, &uniformName[0] );
    unifomLocation[uniformName] = glGetUniformLocation( shaderProg, uniformName.data() );
}


Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow