Results 1 to 2 of 2

Thread: same buffer bound to different targets?

  1. #1
    Member Contributor
    Join Date
    Jul 2018

    same buffer bound to different targets?


    Can you change the target of a buffer?

    For example:

    glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(float), myData,GL_READ_ONLY);

    I later want the same buf to be bound to a GL_SHADER_STORAGE_BUFFER target. Is this even possible?

    glBindBuffer(GL_SHADER_STORAGE_BUFFER, buf);

    If not, what's the best way to accomplish this? I do not want to create two different buffer objects, store the same myData in them and bind them to the two different GL_ARRAY_BUFFER and GL_SHADER_STORAGE_BUFFER targets. The reason is that myData stored in buf gets modified and is made resident on gpu memory. The next target, GL_SHADER_STORAGE_BUFFER, should see the modified memory.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Quote Originally Posted by driver View Post
    Can you change the target of a buffer?

    The specification states that an implementation may optimise storage according to the first target to which the buffer is bound, so you shouldn't "recycle" buffers simply to avoid deleting and creating buffers.

    But it's perfectly legal (and quite common) to bind a buffer to one target to write into it then bind it to a different target to read from it. E.g. copying pixel data by first binding to GL_PIXEL_PACK_BUFFER then later to GL_PIXEL_UNPACK_BUFFER. Or binding to GL_TRANSFORM_FEEDBACK_BUFFER to capture the output from a vertex shader then later binding to GL_ARRAY_BUFFER to use the captured data.

    In the case where you're reading one set of data using multiple interfaces, it may be more efficient to use a separate buffer for each type of access, but it's not guaranteed that's the case, and even if there is a benefit it may not be sufficient to outweigh the cost of using multiple buffers.

Similar Threads

  1. Replies: 1
    Last Post: 10-04-2018, 08:44 AM
  2. get the currently bound VAO?
    By bsabiston in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-19-2012, 02:45 AM
  3. Binding a new vao to already bound buffer
    By mobeen in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-03-2011, 10:08 PM
  4. glBufferSubData for other buffer targets
    By imported_Groovounet in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-30-2008, 06:03 PM
  5. bound textures?
    By supagu in forum OpenGL: GLSL
    Replies: 5
    Last Post: 04-27-2004, 06:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean