cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
539 stars 59 forks source link

functions to read texture data to CPU #178

Closed j4yk closed 10 years ago

j4yk commented 10 years ago

glow::Texture currently seems to be missing functions like glGetTexImage to read the texture data back.

I currently adapt the glow particle example for use in our game but we want to emit new particles and remove particles after their lifetime is over. My current idea is to have a countdown value for each particle and occasionally remove particles from the textures where the countdown indicates they have expired. To not reset non-expired particles when resizing the position and velocity textures I would need to get these data back from the GPU. Also to add new particles, which might at some point require enlarging the texture, I would need to save the current data before the new image2D call. I am certainly open for other ideas. ;-)

rlux commented 10 years ago

If the texture is attached to a framebuffer, it is possible to use readPixels on FrameBufferObject. This also allows you to only read partial regions of the texture. I added a simple wrapper for glGetTexImage to Texture. However you still need to know how large the pixel array is.

In the future, we could add convenience methods that compute the size from the type and format parameters, like glraw does. But this might belong to glowutils instead.