4

I'm currently grabbing a screenshot of an OpenGL ES game using glReadPixels. The screenshots are great however the call to glReadPixels causes a small stutter in the game.

glCopyTexImage2D has been suggested as a more efficient replacement for glReadPixels. How does glCopyTexImage2D work? For some context I'm using this Apple method.

I'm relatively new to OpenGL so any help is much appreciated :-)

SundayMonday
  • 19,147
  • 29
  • 100
  • 154

1 Answers1

12

The time delay is caused by transferring a large amount of memory between GPU and CPU. This can be solved by transferring in chunks, a little bit per frame. But if you read from the framebuffer over a series of frame, the image would be changing meanwhile.

So you make a copy, video RAM into video RAM (very fast), and then it won't change as you transfer it piecemeal.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • How does the VRAM to VRAM copy work? Is it copying the contents of the frame buffer? Perhaps I can use glCopyTexImage2D? – SundayMonday Sep 12 '11 at 21:58
  • 1
    @MrMusic: Yes, it's copying from the frame buffer into an alternate buffer. Depending on OpenGL version, you might use an aux buffer (`glDrawBuffer` and `glReadBuffer` + `glCopyPixels` for the VRAM-VRAM copy, then `glReadBuffer` + `glReadPixels` to pull out just a chunk back to the CPU each frame). On newer versions of OpenGL, you could use a VBO, but since you're using OpenGL ES, try the old way first. – Ben Voigt Sep 12 '11 at 22:14
  • @TatiOverflow: Even if code were provided, you would have to change literally every parameter to suit your particular problem, anyway. What portion of the screen do you need to save? What bit depth are you using? Are any aux buffers already in use? All you would get from a code snippet is the list of functions to call and in what order, and that's already given (in the comments). – Ben Voigt Oct 09 '18 at 18:45
  • i actually found out that if I do glReadPixels and move the processing of the returned array to another thread i am able to speed it up... – TatiOverflow Oct 09 '18 at 23:27