Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: UBO Binding Issue

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    4

    UBO Binding Issue

    Hello everyone!

    So I am having an issue with UBOs, to be more precise with binding them to the correct Uniform Block inside the shader.

    First a few things about what I have checked:
    The binding seems to be consistent with what I have defined with glUniformBlockBinding (I also tested it with shader binding and it also exposes the correct values) - I tested this via RenderDoc and
    Code :
    glGetActiveUniformBlockiv(shader_handle, program_resource_index, GL_UNIFORM_BLOCK_BINDING, &binding);

    if I call
    Code :
    glBindBufferBase(GL_UNIFORM_BUFFER, binding, ubo_handle)
    it does not bind to anything unless binding happens to equal an index of an uniform block. So now I obviously could use glBindBufferBase to just bind to every shader inside the system, but I specifically wanted to implement UBOs in order to reduce the Uniform write operations.

    To go over the exact procedure: I compile and link the programs, use glUniformBlockBinding as "post-build-event", then assemble the scene (this includes creating the UBOs and putting data in them) and then I render while swapping UBO when needed.

    Lets assume I have a Shader with the following Uniform Blocks:
    Light - index: 0 - binding: 1
    Camera - index: 1 - binding: 10
    Material - index: 2 - binding: 0

    so I would expect that if I
    Code :
    GLuint ubo_handle = 123; //lets assume this handle is valid
    glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo_handle)
    , the light would now take the data from that ubo, instead what happens is that Camera now takes the data from this ubo 123.

    I am using glfw 3.1.2 Win32 and glew 2.1.0, this is vendor independant and happens on multiple Windows OS, OpenGL 4.0 and GL_ARB_shading_language_420pack is available.

    As essential values inside the shaders stay undefined I see my defined clear color instead of anything.

  2. #2
    Intern Contributor
    Join Date
    Oct 2014
    Posts
    65
    I usually just write myself wrapper classes for all those low level API calls and never touch them again if they work as expected. So I forget the exact details of every API function quiet fast. BUT:

    Light - index: 0 - binding: 1
    Camera - index: 1 - binding: 10
    Material - index: 2 - binding: 0
    glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo_handle)
    If you want the light to use the UBO, shouldn't the passed index be 0? You specified the index of the camera to be 1 and you pass this index.
    Last edited by ProgrammerX; 07-12-2018 at 03:46 AM.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    4
    Quote Originally Posted by ProgrammerX View Post
    I usually just write myself wrapper classes for all those low level API calls and never touch them again if they work as expected. So I forget the exact details of every API function quiet fast. BUT:

    If you want the light to use the UBO, shouldn't the passed index be 0? You specified the index of the camera to be 1 and you pass this index.
    This is precisely my problem, I do not want to Bind the UBO on the index, but rather the Block Binding so that every shader that has that block binding defined gets the camera and I don't have to bind my camera per shader anymore.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,926
    Quote Originally Posted by ProgrammerX View Post
    If you want the light to use the UBO, shouldn't the passed index be 0? You specified the index of the camera to be 1 and you pass this index.
    glBindBufferBase() takes the binding point, not the uniform block index. There wouldn't be much point to glUniformBlockBinding() (or binding points generally) otherwise.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    4
    I started to think I am chasing ghosts after checking with
    Code :
    glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, binding_index, &bound_buffer);
    Seems like I stumbled upon a bug in RenderDoc and then did an error myself when trying to query the bound buffers by using
    Code :
    glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, uniform_block_index, &bound_buffer);
    as I used low binding numbers (0,1,2)

    This doesn't change that inside renderdoc the values for camera are garbage even though the padding on 3 mat4 should be the simplest one... I need to further investigate for now

  6. #6
    Intern Contributor
    Join Date
    Oct 2014
    Posts
    65
    Quote Originally Posted by GClements View Post
    glBindBufferBase() takes the binding point, not the uniform block index. There wouldn't be much point to glUniformBlockBinding() (or binding points generally) otherwise.
    Yeah, as I said: Did it once. Worked. Forgot about it. I just checked the documentation of glUniformBlockBinding and the parameter naming there is index. Only if you actually start reading what index is (what I didn't) they talk about binding points. That's where my confusion came from.
    So I had to reread some stuff about UBOs and check some of my classes code to understand the problem

  7. #7
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    4
    Quote Originally Posted by Stefl1504 View Post
    This doesn't change that inside renderdoc the values for camera are garbage even though the padding on 3 mat4 should be the simplest one... I need to further investigate for now
    So I checked with a nightly build and identified where my data padding was wrong - indeed the combination of me querying wrong and the data display (not the capture) in the RenderDoc 1.0 build being wrong led me to believe that I was using glBindBufferBase wrong or forget to set something

Posting Permissions

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