cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

bobdobbs
Journeyman III

Buffer to Buffer Copy not working

The following code doesn't actually seem to copy data correctly on either an HD7750 or an HD6450

               GLuint tempVBO;
          glGenBuffers(1, &tempVBO);
          glBindBuffer(GL_COPY_READ_BUFFER, tempVBO);
                glBindBuffer(GL_ARRAY_BUFFER, srcVBO);
          glBufferData(GL_COPY_READ_BUFFER, oldByteCount, NULL, GL_STATIC_COPY);
          glCopyBufferSubData(GL_ARRAY_BUFFER, GL_COPY_READ_BUFFER, 0, 0, oldByteCount);
     
          glBufferData(GL_ARRAY_BUFFER, newByteCount, NULL, GL_STATIC_DRAW);
          
          glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_ARRAY_BUFFER, 0, 0, oldByteCount);

          glBindBuffer(GL_COPY_READ_BUFFER, 0);
          glBindBuffer(GL_ARRAY_BUFFER,0);
          glDeleteBuffers(1, &tempVBO);

After running that code , if the data is read back using map buffer it will be all zeros or garbage.  However if any other memory operation is performed it'll work.

For instance  the following code will correctly copy the data between buffers.  The original code works fine on the various NVIDIA cards I've tested.

                GLuint tempVBO;
          glGenBuffers(1, &tempVBO);
          glBindBuffer(GL_COPY_READ_BUFFER, tempVBO);
                glBindBuffer(GL_ARRAY_BUFFER, srcVBO);
          glBufferData(GL_COPY_READ_BUFFER, oldByteCount, NULL, GL_STATIC_COPY);
          //glSubBufferData, glBufferData with one byte, whatever
          glMapBuffer(GL_COPY_READ_BUFFER, GL_READ_ONLY);
          glUnmapBuffer(GL_COPY_READ_BUFFER);
     
          glCopyBufferSubData(GL_ARRAY_BUFFER, GL_COPY_READ_BUFFER, 0, 0, oldByteCount);
     
          glBufferData(GL_ARRAY_BUFFER, newByteCount, NULL, GL_STATIC_DRAW);
          
          glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
          glUnmapBuffer(GL_ARRAY_BUFFER);

          glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_ARRAY_BUFFER, 0, 0, oldByteCount);

          glBindBuffer(GL_COPY_READ_BUFFER, 0);
          glBindBuffer(GL_ARRAY_BUFFER,0);
          glDeleteBuffers(1, &tempVBO);

What am I missing here?

0 Likes
0 Replies