Mircea Ispas
Mircea Ispas

Reputation: 20790

OpenGL/OpenGL ES update texture

I need to change parts from a texture, but to be aware of the current texture data instead of just replaceing it.

I tried to use glTexSubImage2D, but it replaces the current data without giving me the posibility to specify some kind of operation between current data and new data.

One solution wold be to cache texture data in memory and do the blend operation before using glTexSubImage2Dand use glTexSubImage2D with the result, but this will just waste the memory...

Is there any function common to both desktop OpenGL and OpenGL ES 2.0 that will allow me to do this?

Upvotes: 0

Views: 1291

Answers (1)

Christian Rau
Christian Rau

Reputation: 45948

Of course glTexSubImage2D overwrites any previous data and doing it on the CPU isn't an option at all (it won't just waste memory, but even more important, time).

What you can do though is use a framebuffer object (FBO). You attach the destination texture as color render target of the FBO and then just render the new data on top of it by rendering a textured quad. The sub-region can be adjusted by either the viewport setting or the quad size and position. For the actual operation you can then either use the existing OpenGL blending functionality if sufficient, or you use a custom fragment shader for it (but in this case you can't just render the new data on top of the old, but have to use both new and old data as textures and render the stuff into a completely new texture, since otherwise you don't have access to the old data inside the shader).

Upvotes: 2

Related Questions