0
votes

i want to get the const info( which also called uniform in ogl ) after shaders are compiled.

in d3d9, i can get ID3DXConstantTable by use D3DXGetShaderConstantTable interface, so i can get the const info of vertex shader or fragment shader.

but in ogl, there is no interface for shader but only the interface for program named glGetActiveUniform. used this interface can get all uniforms used by program, but can not know the uniform is used by vertex shader or used by fragment shader.

so is there any way?

1
why downvote? it seems a natural instinct on SO is to lazily ask "why would you want to do that?" instead of address an interesting problem regardless of the application.jozxyqk

1 Answers

2
votes

I don't know for sure that it's not possible but I haven't seen a way to do this. I'll speculate that since uniforms can get optimized out at the linking stage, it makes sense that you can't (or rather, that the effort to include and implement an interface hasn't been made) query the individual shader and see what variables are "active".

As you say, you can get a list of active uniforms for the entire program:
glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &n)
for (i = 0..n)
    glGetActiveUniform(program, i, ...)

But AFAIK there is no way to find which stage references them, and more to the point, which stages they are active in (for the former you could do some code parsing to guess).


The only thing that comes close is with uniform blocks, which aren't available in OpenGL ES2.0:

glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &n)
for (i = 0..n)
    glGetActiveUniformBlockiv(program, i, ...)

Where you can query

  • GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER,
  • GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER,
  • GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER,