views:

351

answers:

1

Hi,

Anyone know what the best practices are for drawing multiple layers of 2D OpenGL ES content on the iPhone?

For example, let's say I want to draw a complex fullscreen background texture, followed by a rotating texture, followed by another alpha blended texture on top.

Is there a way to draw the background texture only ONCE, and only draw changes to the upper layers when necessary?

Everything I've found so far indicates that you should always glClear(), then draw everything, every frame, every tick, in the proper order. But there's no sense in drawing something 60 times a second if it doesn't change...

Thanks!

A: 

You don't have to glClear() if your drawing is going to cover every pixel (and you aren't alpha blending with the clear color). (You don't have to draw what you can't see.)

However in most cases you'll need to draw the background every frame. If your animation takes place only in a smaller rectangle than the screen (and the rest stays static) you could perhaps only redraw that rectangle, but that's probably more trouble than it's worth.

What makes your background texture, complex? Is it just large (512x512)?

Jon-Eric
Actually I was just using this as an example... in reality, I'm drawing complex layered content. In the background, it's actually a bunch of lines. Above that, I'm drawing a constantly rotating texture, and above THAT, another series of textures. Since the background is complex (not just 1 texture), it takes time to render, and I wanted to see if I could cache that by only drawing it once. Drawing all 3 layers every frame is proving to be too slow.So far, I've solved this by having 2 EAGLViews, the top one is set to opaque=NO. I just was wondering if there was a better way of doing this.
monkey32
You can render all of the lines to a texture once then and then render that texture every frame. That should help if it's the line drawing that's slow. (You HAVE profiled, right?)
Jon-Eric