Multiple uniform blocks


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.


Hi – I was so glad to stumble across this post, as I’m having the exact same problem, and it’s driving me crazy! At least I’m not alone. Did you ever figure this out? If so, can you post the fix?


  • cort

EDIT: I’ve tested on the following platforms:

  • Vista, ATI Radeon HD 3450, Catalyst 9.11 drivers
  • Windows 7, ATI Radeon HD 5850, Catalyst 10.2 drivers

Funny, I just saw your post and was hoping to spot a fix. I haven’t tried this recently but I am planning on testing next time I upgrade drivers. I’ll keep you posted.


Idem, this is no longer an issue in AMD OpenGL drivers

Looks good. I have it working on:

  • ATI HD 5870, Catalyst 10.7, Windows Vista 64
  • NVIDIA GeForce 8400 GS 258.96, Windows XP 32


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.