Question about glTexSubImage2D

I have a large texture in memory (non-power of two),which I want to draw binding in card memory only one 512x512 texture which wil be updated according to the current draw area(due to memory,performance and compatibility issues)

My questions are:
1.Can I use glTexSubImage2D(…) for this purpose?
2.Can I replace the texture pixels with pixels from the large texture subarea without copying them to some temporary buffer?
Because according to glTexSubImage2D parameters seems like I can’t do it…

void glTexSubImage2D( GLenum target, //=GL_TEXTURE_2D
GLint level, // = 0
GLint xoffset, // = 0 (of original texture)
GLint yoffset, // = 0 (of original texture)
GLsizei width, // = 512
GLsizei height, // = 512
GLenum format, // = GL_RGB
GLenum type,// = GL_UNSIGNED_BYTE
const GLvoid * data);// = new pixels but the expected size buffer is 512x512?

What you want to do is not very clear…If you just want to copy from your frame buffer to your large texture use glCopyTexSubImage2D. No intermediate texture required.

Well, I’ll try again

I’m drawing a large terrain.While all terrain is non power of two jpeg image in memory and can’t be drawed as one terrain due to it’s size.

So I’m keeping one terrain of size 2048x2048 (since this size will be safe for most of the cards) and I want to update the pixels in the texture while drawing - every 2048 pixels to copy to the texture the relevant pixels from the large image.

The trivial solution is to use intermediate buffer and glTexSubImage2D, but I’m not sure how good this solution is.
I’m looking for most efficient way to do it


it’s not that bad…you may even use threads to do it asynchronously. You may even use tiles of 512x512 size and load multiple textures for each tile instead of one. However you will have to do some kind of streaming and texture updating, that’s obvious enough. glSubTexture is a good solution because it avoids a new texture object creation.

That sounds a good idea.I think Google Earth engine works like this, because you can navigate while some parts of the terrain are still being loaded.
Thanks again