efficient texel access in OpenGL
Question
I'm working on a game in OpenGL and here's what I'd like to do:
- During an iteration of game logic, access texels of a texture for computations.
- Still during the same logic interation, possibly modify the texels of the texture.
- Render the game scene with the current version of the texture.
- Start another iteration with similar access to texel data.
I'm having trouble using glGetTexImage() in that the call crashes my program, and I'm not entirely sure this is what I want to be using anyway.
The only straightforward way I can see to do this is to have a buffer in system memory with texel information that I can mess around with, and generate a new OpenGL texture from it every iteration. That seems like a bad move.
Any help?
Solution
There are several possible ways to do this.
- If you don't need any non-textured data to modify your texture you could use a fragment shader. (ping-pong technique might be interesting for that)
- Use glTexSubImage2D if only a small part of the texture is replaced and you don't need to worry about performance or it should work on older graphic cards.
- Use a pixel buffer object. That should be faster then glTexSubImage2D. Some more infos about that can be found here.
OTHER TIPS
I believe glTexSubImage2d is what you are looking for.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow