optimizing iPhone OpenGL ES fill rate

前端 未结 7 860

I have an Open GL ES game on the iPhone. My framerate is pretty sucky, ~20fps. Using the Xcode OpenGL ES performance tool on an iPhone 3G, it shows:

Renderer Utilization

7条回答
  •  死守一世寂寞
    2021-01-31 22:40

    I wanted to chime in with an additional answer, change the Framebuffer backing to be a 16bit format as opposed to a 32 bit format.

    if ((self = [super initWithCoder:coder])) 
        {
        eaglLayer = (CAEAGLLayer *)self.layer;
        eaglLayer.opaque = YES;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                                [NSNumber numberWithBool:NO], 
                                                kEAGLDrawablePropertyRetainedBacking, 
                                                kEAGLColorFormatRGB565,  //kEAGLColorFormatRGBA8 = large frame buff 32bit  // kEAGLColorFormatRGB565 = 16bit frame buffer.
                                                kEAGLDrawablePropertyColorFormat, 
                                                nil];        
    }
    

    What woke me up to this was the XCode profiler. It kept complaining about using to large a frame buffer, eventually I found it in my init section. http://developer.apple.com/library/ios/#documentation/iPhone/Reference/EAGLDrawable_Ref/EAGLDrawable/EAGLDrawable.html . That single change allowed my games on iPad, Retina, and iPods to go to 60 FPS. I have yet to re-release them with this change as I just found it out 3 days ago :) but I do not think I plan to release at 60fps, 30fps is just fine for casual games, and I found that my sound effects cut the frame rate down, so either resample, play the sfx in another thread, or other solutions to keep that frame rate up if I decide to go with 60fps.
    Don't forget to discard the buffers that are not used to display..

    if (fiOSver >= 4.0f) {
        const GLenum discards[]  = {GL_DEPTH_ATTACHMENT_OES};
        glDiscardFramebufferEXT(GL_FRAMEBUFFER_OES,1,discards);
    }
    
    [m_oglContext presentRenderbuffer:GL_RENDERBUFFER_OES];
    

提交回复
热议问题