Fastest possible way to render 480 x 320 background as iPhone OpenGL ES textures
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 us开发者_如何转开发e 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?
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 may not need a
GL_CLEAR
call- gmaclachlan points out you should clear the buffers every run for performance reasons, however this is contrary to some other user experience. This may differ between hardware and iOS revisions; however, performance can be tested just by commenting out the line. Check before and after.
- If you're using the Z-axis at all (ie: 3D objects over a 2D background, think New Super Mario Bros) you will want to clear the depth buffer
- 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.
精彩评论