View Full Version : Most effecient method for modifying textures?

03-17-2008, 02:25 AM
Part of an app I'm making centers around some textures which I plan to modify fairly often.

At the moment, I'm using glTexImage2D and creating the textures from an array of bytes (data) with the following code :

glGenTextures(1, &generic_texture);
glBindTexture(GL_TEXTURE_2D, generic_texture);
// etc...
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, width, height,0, GL_RGBA, GL_UNSIGNED_BYTE,data);

I'm not sure of the underlying mechanics of glTexImage2D but I assume that part of it is that it copies the (processed?) array into video memory.

The problem is, I'm planning to modify the texture fairly frequently : writing the changes into the array, and then creating a new texture and copying the whole thing to the video memory seems a little redundant and slow - especially if I'm modifying a large texture or a large amount of textures. Really, I'm looking for a way of directly modifying the textures in memory - or at least, something a little less redundant the the method I'm planning to use.

I'm not really familiar with OpenGl though, I'm pretty much a full blown beginner - I've been working off code examples :) - so I don't know if this kind of thing is impossible, if there's a function which caters specifically to this kind of thing, if I assumed wrong, etc.. can anyone help me out here, give me some pointers as to what I should do / be doing differently?

03-17-2008, 03:06 AM
To modify a part of the texture, use glTexSubImage2D function. You may be also interested in pixel buffer object extensions for asynchronous data transfer.

03-17-2008, 08:03 AM
glTexSubImage2D with the whole image is also faster than recreating the texture object all the time.
Depending on what you actually want to change you could also render directly to that texture in a framebuffer object.