PBO - glBufferSubData(): offset questions

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()?

if this is for video update you may want to search the advanced forum.

No, it is not for video display.

Has nobody an idea or explanation? :frowning:

seems that you pass glTexSubImage2D(NULL) pointer at the end where it asks for pixel data pointer to overwrite with.

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)

Dark Photon, thank you! :slight_smile: