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 3 of 3

Thread: Uniform Buffer Object Sharing

  1. #1
    Junior Member Regular Contributor
    Join Date
    May 2008
    Posts
    101

    Uniform Buffer Object Sharing

    I'd like to share a UBO between multiple programs. But, what happens if two programs use the same block name but the contents of the uniform block are slightly different? Is there a way to detect that uniform block are truly the same across multiple programs?

    Thanks.

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2013
    Posts
    130
    Sharing contexts only works in the same process.

    See: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    Quote: "You can only share display lists with rendering contexts within the same process."

    If you use shared contexts the object IDs will be unique. For example two threads each with his own GL context (but shared)
    Code :
    void myThread1WithContext1()
    {
    glGenTextures(1, myTextureId1)
    }
     
    void myThread2WithContext2()
    {
    glGenTextures(1, myTextureId2)
    }

    Will take care for you that myTextureId1 and myTextureId2 will each have a unique ID over the shared contexts.
    But you must use fances or glFinish after one thread worked with an GL Object before signaling the other thread that he can touch that GL Object!

  3. #3
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    873
    Quote Originally Posted by ViolentHamster View Post
    Is there a way to detect that uniform block are truly the same across multiple programs?
    The "shared" and "std140" layout qualifiers should defeat any compiler optimizations that would eliminate unused block members. But you do need to declare the blocks identically in all the programs you intend to share blocks. (You can put the block declaration in its own string, remember that program compilation accepts multiple strings.)

    After linking, you should introspect the block layouts to convince yourself; see glGetActiveUniformsiv, with UNIFORM_OFFSET, UNIFORM_ARRAY_STRIDE, etc.


Posting Permissions

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