I’m trying to get bindable uniforms working properly but I had no luck, it has a very strange behaviour. This is what I do:
1- First I create the bindable uniform buffer:
GLuint buffer;
glGenBuffers(1,&buffer);
glBindBuffer(GL_UNIFORM_BUFFER_EXT,buffer);
GLfloat dat[8];
dat[0] = 1.0f;
dat[1] = 1.0f;
dat[2] = 1.0f;
dat[3] = 1.0f;
dat[4] = 1.0f;
dat[5] = 1.0f;
dat[6] = 1.0f;
dat[7] = 1.0f;
glBufferData(GL_UNIFORM_BUFFER_EXT,8*sizeof(float),dat,GL_STATIC_READ);
2- I create my fragment shader:
#extension GL_EXT_bindable_uniform: enable
bindable uniform float data[8];
void main(){
float val = data[0];
gl_FragColor = vec4(val,val,val,1.0); }
3- Bind the bindable uniform to the shader:
GLint loc = glGetUniformLocationARB(program_handle,location.c_str());
glBindBuffer(GL_UNIFORM_BUFFER_EXT, buffer);
glUniformBufferEXT(program_handle,loc,buffer);
4- Use the shader.
glUseProgramObjectARB(program_handle);
NOTE:
- no opengl errors produced.
The problem is that the bindable uniform seems to be bound to the shader to the correct location (uniform variable), but I can 't get the correct values accessing to the buffer data[8]in the shader! Only data[0] and data[1] seem to work! the others data[3…7] give me 0.
I am unable to figure out what the problem is. I would really appreciate your help, because this is driving me crazy!
Thank you in advance.
(Running on WindowsXP + GeForce 8800 with the latest drivers.)