The fastest way to render 480 x 320 backgrounds as iPhone OpenGL ES textures

I need to display a 480 x 320 background image in OpenGL ES. The fact is that I lost a bit of weight on the iPhone when I use the size of 512 x 512. Thus, I find the best case for rendering iPhone size resolution in OpenGL ES. How should I cut the background in this case to get the best performance? My main problem is speed. Should I use 256 x 256 or other texture sizes here?

+4
source share
1 answer

First of all, do you test performance on the Simulator? If so, stop immediately and try on real hardware. Testing performance on a simulator is futile.

From this point of view, I’m not sure how many of them you have already implemented, so I apologize if I give you what you already know:

  • If you draw a full-screen opaque background for each frame, you may not need to call GL_CLEAR
    • gmaclachlan indicates that you should flush the buffers every time you start for performance reasons, however this is contrary to some other users. This may vary between hardware and iOS versions; however, performance can only be verified by commenting out a line. Check before and after.
    • If you use the Z axis at all (i.e. 3D objects on a 2D background, think of New Super Mario Bros), you will want to clear the depth buffer
  • Use texture compression (PVRTC) if compression artifacts are not a problem, hardware acceleration
  • Use a 16-bit background texture if you cannot use PVRTC
  • Make sure you're not trying to do a depth / alpha mix check if nothing is there
  • Use the OES_Draw_Texture extension if you use a 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);

In addition, try to capture only this code segment and see how much background per second it can spit out.

+7
source

Source: https://habr.com/ru/post/1307438/


All Articles