Hello,
I’m having trouble getting a simple shader with two uniform blocks to work. Perhaps I don’t completely understand glUniformBlockBinding and glBindBufferBase. I have a simple fragment shader:
#version 150
uniform RedBlock
{
uniform float red;
};
uniform GreenBlock
{
uniform float green;
};
out vec4 FragColor;
void main()
{
FragColor = vec4(red, green, 0, 1);
}
I loop over each uniform block and assign its index as its binding point.
int numberOfUniformBlocks;
GL.GetProgram(program, ProgramParameter.ActiveUniformBlocks, out numberOfUniformBlocks);
for (int i = 0; i < numberOfUniformBlocks; ++i)
{
string uniformBlockName = GL.GetActiveUniformBlockName(program, i);
// ...
GL.UniformBlockBinding(program, i, i);
}
At this point, GreenBlock has a block index and binding point of 0 and RedBlock is 1.
Now if I create a UBO that is the proper size for GreenBlock and write a 1 at the green member’s offset, the triangle actually comes out red!
I am associating the state block (GreenBlock is index 0) with the UBO with:
GL.BindBufferBase(BufferTarget.UniformBuffer, 0, bufferHandle);
Am I using glUniformBlockBinding and glBindBufferBase correctly? Is there any other code I can show to help diagnostis the problem? I am running a NVIDIA GeForce 8 with 191.07 drivers on Windows XP.
Thanks!
Patrick