Litty
Litty

Reputation: 1876

Should I provide a full or partial image to glTexSubImage2D?

I have a piece of GLvoid* data that contains an entire image, which is periodically updated throughout my program. I use glTexImage2D to initialize a texture on the GPU with this data.

I would like to use glTexSubImage2D to update parts of the texture as necessary. The documentation for glTexSubImage2D describes the GLvoid* pixels argument as such:

Specifies a pointer to the image data in memory.

What "image data" is this expecting? Can I provide the entire GLvoid* data, or is it expecting a buffer that only contains the data being copied?

If it expects the partial data, is there an alternative way to provide the whole buffer instead?

Upvotes: 1

Views: 1481

Answers (2)

Dmitry Lachinov
Dmitry Lachinov

Reputation: 129

You can provide entire image data with call

glTexSubImage2D( target, level, 0, 0, W, H, format, type, pixels);

W and H are texture width and height, the whole texture will be copied, pixels is W*H array. Or you can provide only modified data with call

glTexSubImage2D( target, level, offset_x, offset_y, w, h, format, type, pixels);

where w and h is weigth and height of modified data so offset_x + w < W and offset_y + y < Y. pixels is w*h array.

Edit:

glPixelStorei( GL_UNPACK_ROW_LENGTH, W);
glPixelStorei( GL_UNPACK_SKIP_PIXELS, offset_x);
glPixelStorei( GL_UNPACK_SKIP_ROWS, offset_y);

glTexSubImage2D( target, level, offset_x, offset_y, w, h, format, type, pixels);

where pixels is W*H

Upvotes: 4

BlueWanderer
BlueWanderer

Reputation: 2691

It's only the data to be copied. Or you will have to waste a lot of memory to upload only a part of the image(sometimes the only part you currently have).

P.S. And it's rather painful that it doesn't even support strided data. So if you have a full image, you can't upload left or right half of it without copying it to a smaller buffer.

Upvotes: 2

Related Questions