Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Problem with bindable uniform buffers

  1. #1

    Problem with bindable uniform buffers

    Hi,

    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);
    glUseProgram(shaderProgram);
    glUniform1f(loc2,sc);

    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?

    Greetings,

    Jotschi

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,924

    Re: Problem with bindable uniform buffers

    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.

  3. #3
    Intern Contributor
    Join Date
    Nov 2009
    Location
    Ukraine
    Posts
    80

    Re: Problem with bindable uniform buffers

    Try that

    bindable uniform float specColor[buffersize];
    ...
    vec4 color2 = vec4(specColor[0],0.0,0.0,1.0);

  4. #4

    Re: Problem with bindable uniform buffers

    Quote Originally Posted by YarUnderoaker
    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.

  5. #5
    Junior Member Regular Contributor pjcozzi's Avatar
    Join Date
    Jun 2004
    Location
    Philadelphia, PA
    Posts
    196

    Re: Problem with bindable uniform buffers

    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.

    Regards,
    Patrick

  6. #6

    Re: Problem with bindable uniform buffers

    Hi,

    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)?

    Quote Originally Posted by Alfonse Reinheart
    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.

  7. #7
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,924

    Re: Problem with bindable uniform buffers

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

  8. #8

    Re: Problem with bindable uniform buffers

    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.

    Quote Originally Posted by pjcozzi
    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.

  9. #9
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    5,924

    Re: Problem with bindable uniform buffers

    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.

  10. #10
    Intern Newbie
    Join Date
    Mar 2008
    Posts
    36

    Re: Problem with bindable uniform buffers

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •