Problem with bindable uniform buffers


i want to use bindable uniform buffers to swap the uniform data fast within my main program logic. But this does not seems to work. My image is just black. Perhaps someone sees a problem within my code?

binding the the uniform:

GLuint loc2 = glGetUniformLocation(shaderProgram,“specColor”);
float sc = 0.4f;
GLint buffersize = glGetUniformBufferSizeEXT(shaderProgram,loc2);
GLuint uniform_buffer;
glGenBuffers(1, &uniform_buffer);
glBindBuffer(GL_UNIFORM_BUFFER_EXT, uniform_buffer);
glBufferData(GL_UNIFORM_BUFFER_EXT, buffersize, &sc, GL_STATIC_READ);
glUniformBufferEXT(shaderProgram,loc2, uniform_buffer);

fragment shader:

#version 120
#extension EXT_gpu_shader4 : enable
#extension GL_EXT_bindable_uniform : enable
bindable uniform float specColor;

void main() {
vec4 color2 = vec4(specColor,0.0,0.0,1.0);
gl_FragColor = color2;

And i have another question. I wonder if using texture buffer objects (tbo) via uniform ‘samplerBuffer’ swaps the data as fast a normal sampler which is declared as bindable would do. Are those both extensions comparable? They are both backed up by a buffer object and therefore comparable, nor?



Don’t use EXT_bindable_uniform. It’s not a very good spec; it’s hard to know how everything should be laid out in the buffer object. Any hardware that could support it also supports ARB_uniform_buffers, which is a much better spec.

Try that

bindable uniform float specColor[buffersize];

vec4 color2 = vec4(specColor[0],0.0,0.0,1.0);

I tried that but it had the same result. float returned with 0.0.

And my
GLint buffersize = glGetUniformBufferSizeEXT(shaderProgram,loc2);

is 0 - might this be correct?

I currently do not know how to debug this.

Hi Jotschi,

Why are you using GL_STATIC_READ? Since glBufferData’s usage is just a hint, I don’t think this is the problem, but if you plan on writing to the buffer frequently, you should provide an appropriate hint. See NVIDIA’s Using VBOs, the advice also applies to UBOs.



what do you mean with ARB_uniform_buffers? I can’t find such extension. Do you mean VBO,PBO, TBO’s (Buffer Objects in general)?

No, I mean GL_ARB_uniform_buffer_object. If you have recent drivers from either NVIDIA or ATi, this is available to you.

Hi Patrick,

yes i want to write to the buffer frequently. I just used GL_STATIC_READ because i thought it should work with any mode? I switched to GL_DYNAMIC_READ by my float is still 0.0.

Perhaps Alfonse is right and the bindable extension is not quite good and i should use buffer objects without it instead. But i thought i could save some time which is consumed when redefining the uniform via glUniform1f(loc2,sc); eg. Instead of using glBindBuffer. And i can only use glBindBuffer to change my uniform value (without calling a glUnform** call) when using texture buffer objects via a sampler buffer samplerBuffer.

The bindable uniform extension sounds like i could make any uniform type accessible via a buffer object and therefor using the DMA direct memory access performance benefit. As described for buffer objects.

I hope i made my point clear enough. If not so please tell me and i try to clarify my self.

Perhaps Alfonse is right and the bindable extension is not quite good and i should use buffer objects without it instead.

That’s not what I said. EXT_bindable_uniform and ARB_uniform_buffer_objects both do the same thing. They allow you to store uniforms in buffer objects. It’s just that the ARB extension is better in every way.

I once used the EXT_bindable_uniform extension just when it was released. I had to notice that a float,vec2,vec3 and vec4 always do take the size of 4 floats. So basically if you have a bindable uniform of the type float you would still have to use a buffer of the size of 4 floats where the last 3 ones are unused.
Exactly because of this memory layout problem it was recommended to you to use the ARB extension.

Yes I understand. I read the specs. Very interesting extension. Thank you.

I adapted the spec’s example. Usable with freeglut 2.6.0

Perhaps someone finds this useful.