Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance and background images for OpenGL ES/iPhone

I'm developing a 2D game for the iPhone using OpenGL ES and I'd like to use a 320x480 bitmapped image as a persistent background.

My first thought was to create a 320x480 quad and then map a texture onto it that represents the background. So... I created a 512x512 texture with a 320x480 image on it. Then I mapped that to the 320x480 quad.

I draw this background every frame and then draw animated sprites on top of it. This works fine except that the drawing of all of these objects (background + sprites) is too slow.

I did some testing and discovered that my slowdown is in the pixel pipeline. Not surprisingly, the large background image is the main culprit. To prove this, I removed the background draw and everything else rendered very fast.

I am looking for advice on how to keep my background and also improve performance.

Here's some more info:

1) I am currently testing on the Simulator (still waiting on Apple for the license)

2) The background is a PVR texture squeezed down to 128k

3) I had hoped that there might be a way to cache this background into a color buffer but haven't had any luck with that. that may be due to my inexperience with OpenGL ES or it just might be a stupid idea that won't work :)

4) I realize that the entire background does not always have to refresh, just the parts that have been drawn over by the moving sprites. I started to look into techniques for refreshing (as necessary) parts of the the background either as separate textures or with a scissor box, however this seems less than elegant.

Any tips/advice would be greatly appreciated...

Thank you.

like image 814
g-dog Avatar asked Jan 07 '09 20:01

g-dog


1 Answers

  1. Do not do performance testing on the simulator. Ever!
    The differences to the real hardware are huge. In both directions.
  2. If you draw the background every frame:
    Do not clear the framebuffer. The background will overdraw the whole thing anyway.
  3. Do you really need a background texture ?
    What about using a color gradient via vertex colors ?
  4. Try using the 2bit mode for the texture.
  5. Turn of all render steps that you do not need for the background.
    E.g.: Lighting, Blending, Depth-Test, ...

If you could post some of your drawing code it would be a lot easier to help you.

like image 135
Andreas Avatar answered Sep 19 '22 05:09

Andreas