views:

436

answers:

2

I'm working on a game in OpenGL and here's what I'd like to do:

  1. During an iteration of game logic, access texels of a texture for computations.
  2. Still during the same logic interation, possibly modify the texels of the texture.
  3. Render the game scene with the current version of the texture.
  4. 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?

A: 

I believe glTexSubImage2d is what you are looking for.

Zifre
+3  A: 

There are several possible ways to do this.

  1. 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)
  2. 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.
  3. Use a pixel buffer object. That should be faster then glTexSubImage2D. Some more infos about that can be found here.
Maurice Gilden
Great answer, thanks!The PDF you linked to for additional pixel buffer object info also has an interesting discussion about general OpenGL performance related to internal texture formats.
dim fish