views:

566

answers:

1

I need to display 480 x 320 background image in OpenGL ES. The thing is I experienced a bit of a slow down in iPhone when I use 512 x 512 texture size. So I am finding an optimum case for rendering iPhone resolution size background in OpenGL ES. How should I slice the background in this case to obtain the best possible performance? My main concern is speed. Should I go for 256 x 256 or other texture sizes here?

+6  A: 

First of all, are you testing performance on the Simulator? If so, stop immediately and try it on actual hardware. Performance testing on the simulator is worthless.

With that out of the way, I'm not sure how many of these you've already implemented, so I apologize if I'm giving you what you already know:

  • If you're drawing a fullscreen opaque background every frame, you don't need a GL_CLEAR call
    gmaclachlan points out you should clear the buffers every run for performance reasons
  • Use texture compression (PVRTC) if the compression artifacts aren't an issue, it's hardware accelerated
  • Use a 16-bit texture for the background if you can't use PVRTC
  • Make sure you're not trying to depth test/alpha blend the background if there's nothing under it
  • Use the OES_Draw_Texture extension if you're using fixed-function

    int rect[4] = {0, 0, 480, 320};
    glBindTexture(GL_TEXTURE_2D, texBackground);
    glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
    glDrawTexiOES(0, 0, z, 480, 320);

Beyond that, try grabbing just that segment of your code and seeing just how many background per second it's capable of spitting out.

Chris Peredun
Just a note: it's always a good idea to use glClear() at the start of the frame (even if you're going to overwrite the frame entirely) on this hardware - it means that the driver knows no information needs to be kept from the previous frame and saves all the work involved in doing that.
gmaclachlan