I’m compiling a shader and want to query its attributes and uniforms after it is linked. I’m calling glGetActiveUniform() and while it is fetching the names of the attributes correctly, the size and type values being returned seem wrong. The returned size of everything is 1 and the with one exception the type values are all 0x8b5* which are not listed in gl.h. (diffuseTexOpacity is returning 0x1406, which is a GL_FLOAT).
How do I get the size and type of these variables? The name/size/type I’m getting is:
“position” / 1 / 0x8b50
“color” / 1/ 0x8b52
“diffuseTexOpacity” / 1/ 0x1406
“diffuseTexture” / 1 / 0x8b5e
“mvpMatrix” / 1 / 0x8b5c
struct AttribInfo
{
GLuint index;
GLint size;
GLenum type;
std::string name;
};
...
f->glGetProgramiv(_programId, GL_ACTIVE_ATTRIBUTES, &count);
for (int i = 0; i < count; i++)
{
AttribInfo info;
f->glGetActiveAttrib(_programId, (GLuint)i, bufSize, &length, &info.size, &info.type, name);
info.name = name;
info.index = i;
_attributes.emplace(info.name, info);
}
f->glGetProgramiv(_programId, GL_ACTIVE_UNIFORMS, &count);
for (int i = 0; i < count; i++)
{
AttribInfo info;
f->glGetActiveUniform(_programId, (GLuint)i, bufSize, &length, &info.size, &info.type, name);
info.name = name;
info.index = i;
_uniforms.emplace(info.name, info);
}
Default.vsh
#version 330 core
attribute vec2 position;
varying vec2 texCoord;
uniform mat4 mvpMatrix;
void main(void)
{
gl_Position = mvpMatrix * vec4(position.xy, 0, 1);
texCoord = position;
}
SolidColor.fsh
#version 330
uniform vec4 color;
uniform sampler2D diffuseTexture;
uniform float diffuseTexOpacity;
in vec2 texCoord;
layout(location = 0) out vec4 fragColor;
void main(void)
{
vec4 texColor = texture(diffuseTexture, texCoord);
fragColor = (1 - diffuseTexOpacity) * color + diffuseTexOpacity * texColor;
}