PDA

View Full Version : PBO - glBufferSubData(): offset questions



lodder
07-10-2009, 06:47 AM
Hi,

I am using a PBO to update a texture. Each frame one line is updated. The documentation for glBufferSubData says:

Specifies the offset into the buffer object's data store where data replacement will begin, measured in bytes.

I am always setting the offset to 0:


size_t offset = 0;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboTexture);
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, offset, size, newColors);

Then the update:

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, line, textureWidth, 1, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));

In my understanding this code should always overwrite the very first row in my texture. But the real offset is taken from the glTexSubImage2D()-call, so I can pass whatever I want into glBufferSubData()?

earthquad
07-10-2009, 10:21 AM
if this is for video update you may want to search the advanced forum.

lodder
07-15-2009, 04:48 AM
No, it is not for video display.

Has nobody an idea or explanation? :(

_NK47
07-15-2009, 06:42 AM
seems that you pass glTexSubImage2D(NULL) pointer at the end where it asks for pixel data pointer to overwrite with.

Dark Photon
07-15-2009, 07:00 AM
I am using a PBO to update a texture...

glBufferSubData(GL_PIXEL_UNPACK_BUFFER, offset, size, newColors);...
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, line, textureWidth, 1, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
...But the real offset is taken from the glTexSubImage2D()-call, so I can pass whatever I want into glBufferSubData()?
No. What you feed glBufferSubData is the offset for the write into the buffer object. What you feed glTexSubImage2D is the offset for its read "from" the buffer object. Two separate operations.

Say you glBufferSubData 4 bytes at offset 0 with contents "ABCD" (silly example), then you point glTexSubImage2D at it with BUFFER_OFFSET(0). The texture will pull starting at the "A". Or pass BUFFER_OFFSET(1), and it'll start pulling at "B".

Now let's say after this you glBufferSubData 2 bytes at offset 1 with contents "ZZ". This'll update your buffer contents to be "AZZD". Then if you point glTexSubImage2D at it with BUFFER_OFFSET(0), it'll start pulling at "A". Or pass BUFFER_OFFSET(1), and it'll start pulling at the first "Z".

glBufferSubData - update a portion of an existing buffer object
glTexSubImage2D - update a portion of a texture (e.g. from a portion of a buffer object)

lodder
08-04-2009, 01:51 AM
Dark Photon, thank you! :)