Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6554507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:30+00:00 2026-05-25T12:42:30+00:00

Can someone tell me about the seemingly needlessly complicated Uniform Buffers? I’ve read the

  • 0

Can someone tell me about the seemingly needlessly complicated Uniform Buffers? I’ve read the section in OpenGL Superbible 5, I’ve looked at some examples on blogs and I’ve read the official spec, and I still don’t get it.

Specifically, all examples seem to require a shader program to begin with in order to setup the uniform buffer initially with glGetActiveUniformsiv. I don’t understand this. Why doesn’t the interface allow you to define the structure without referring to a shader program, validating the buffer/s formats against the program at link time?

Secondly, if I get the structure layout from one program, assuming the structure layout is the same for all programs that use the set of uniforms, is the structure guaranteed to have the same offsets, data sizes and so on? I would assume so.

Thirdly, I don’t understand binding points. I have to call glBindBufferBase with an index, and then call glUniformBlockBinding with a block index and the index I passed into glBindBufferBase. I’m having trouble visualising exactly what’s going on here. The Superbible lacks clarity, as does the spec and the samples I’ve seen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:42:31+00:00Added an answer on May 25, 2026 at 12:42 pm
    1. Why exactly would you want to? Personally, unless you have a serious data shortage problem and need every byte, I see no reason to use anything other than std140. It makes the code so much cleaner.

      However, if you’re dead-set on avoiding std140, read on.

    2. The specification thoroughly explained this: it’s all in the layout qualifiers.

      There are exactly 3 layout qualifiers: packed, shared, and std140. packed means that the implementation is free to arrange everything pretty much as it wants. This includes removing uniforms that the current program does not use. So the layout is implementation-defined, and certain uniforms within that layout may have been optimized away.

      shared means that the implementation is free to arrange the data just like packed. However, it must provide storage for each of the uniforms. This makes it possible to share uniform layout among programs, hence the name. shared also requires that the implementation will provide a consistent layout for consistent definitions across programs. Therefore, you only need to do the querying for one layout.

      To answer your first question, you could if you so desire create a fake program with shared layout. You could use it just to query the layout for the uniform block. Then, as long as the layout is consistent across other programs (with the shared layout), the layouts will all be the same. So there’s no need for a special API for it.

      std140 however means that the layout of a uniform block is defined explicitly by the OpenGL implementation, byte for byte. This implicitly allows sharing, since two identical uniform blocks under this specification will have the identical layout. And since the implementation cannot optimize away uniforms in a std140 layout block, everything is perfect.

      Again, there is almost no reason to avoid std140. Not unless you are under very, very severe memory constraints.

    3. It’s the exact same mechanism as for textures. The only difference is that uniform block names are not themselves uniforms.

      Texture objects are bound to texture image units, using glActiveTexture(GL_TEXTURE0 + i);glBindTexture(), where i is the texture image unit index. You now need to tell the shader which sampler uses that image unit. However, OpenGL doesn’t let you do the association directly with the name; you have to convert the sampler name into an index location. So you get the uniform location to a particular sampler with glGetUniformLocation. Once you have the uniform location, you can associate the texture image unit with that location by calling glUniform1i(loc, i), where again i is the texture image unit you bound the texture to.

      Uniform buffer objects are bound to uniform buffer binding points, using glBindBufferRange(GL_UNIFORM_BUFFER, i, ...), where i is the uniform buffer binding point. You now need to tell the shader which uniform block uses that binding point. However, OpenGL doesn’t let you do the association directly with the name; you have to convert the uniform block into an index location. So you get the index to a particular uniform block with glGetUniformBlockIndex. Once you have the index, you can associate the uniform buffer binding point with that index by calling glUniformBlockBinding(program, index, i), where again i is the uniform buffer binding points you bound the uniform buffer to.

      See? Exactly the same. They use different terms, but structurally, they’re the same. If you need a picture, then you can find a more thorough discussion that includes a diagram here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone tell me two things about the net panel in firebug? why is
Reading a post about redis I saw this word: REPL . Can someone tell
Can someone tell me what the SSIS package is all about? I am totally
Can someone tell me what exactly is that about? I have table and inside
Can someone tell me what exactly is that about? I have table and inside
Can someone please tell me more about performance monitor object ASP.NET Apps v1.1.4322 Anonymous
Can someone tell me if I'm just going about the setup the wrong way?
Can someone tell me why this string won't unserialize? I've tried just about everything
Can someone tell me if its possible to create relative as opposed to absolute
Can someone tell me why this is not displaying the form? If I go

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.