views:

544

answers:

2

I'm writing an app that offloads some heavy drawing into an EAGLView, and it does some lightweight stuff in UIKit on top. It seems that the GL render during an orientation change is cached somewhere, and I can't figure out how to get access to it. Specifically:

  • After an orientation change, calling glClear(GL_COLOR_BUFFER_BIT) isn't enough to clear the GL display (drawing is cached somewhere?) How can I clear this cache?
  • After an orientation change, glReadPixel() can no longer access pixels drawn before the orientation change. How can I get access to where this is stored?
A: 

I'm not a expert but I was reading the Optimizing OpenGL ES for iPhone OS and it stated:

Avoid Mixing OpenGL ES with Native Platform Rendering

You may like to check it out to see if it helps.

Shane Powell
A: 

After an orientation change, calling glClear(GL_COLOR_BUFFER_BIT) isn't enough to clear the GL display (drawing is cached somewhere?) How can I clear this cache?

You're drawing too an offscreen image. That image only becomes available for CoreAnimation compositing when you call -presentRenderbuffer.

After an orientation change, glReadPixel() can no longer access pixels drawn before the orientation change. How can I get access to where this is stored?

I assume you're using the RetainedBacking option. Without that option, you can never read the contents of a previous frame, even outside of rotation. When you call -presentRenderbuffer, the contents of the offscreen image are shipped off to CA for compositing, and a new image takes its place. The contents of the new image are undefined.

Assuming you are using something derived from the EAGLView sample code and that you are using RetainedBacking, when the rotation occurs, your framebuffer is resized by deallocating and reallocating. Any of the existing contents will be lost when this occurs.

You can either:
1) save the contents yourself across the transition by calling ReadPixels
2) never reallocate the framebuffer, and instead rotate the UIView (or CALayer) using the transform property. Doing so can cause quite a performance hit during compositing, but you'll get the rotation you're looking for without having to resize your framebuffer.

Frogblast