开发者

iOS OpenGL ES: when should I bind the frame buffer and render buffer?

I have some OpenGL ES code that looks like this:

- (void)drawView {
    [EAGLContext setCurrentContext:context];

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glViewport(0, 0, backingWidth, backingHeight);

    [game drawFrame];

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];

    [self checkGLError:NO];
}

My question is this: when should I be calling glBindFramebufferOES and glBindRenderbufferOES? To be perfectly honest, I don't remember why I wrote the code in the above sample that way (it was a few months ago), and I'm starting to get back into OpenGL ES on iOS, and I'm trying to figure how how framebuffers and renderbuffers work.

Should I call those functions each frame? Or should I only call them once, before any frames start being drawn?

Edit: should I even be calling glViewport on a per-frame basis? I set up my view开发者_Go百科port in a seperate function well before draw ever gets called - does it make sense to continually call glViewPort each frame?


I have a tendency to forget which calls are redundant or not, but I can comment on what I see in my limited testing here.

You should only need to call glViewport() once when setting up your scene, unless you render offscreen to an FBO of a different size. In that case, you'd use glViewport() to reset the size when you switched between framebuffers.

Likewise, you should only need to use glBindFramebufferOES() once when setting things up, unless you're going to switch FBOs that you are rendering into or rebuild the current FBO due to a change in view size.

In my sample application, I've found that glBindRenderbufferOES() needs to be used before -presentRenderbuffer: in each frame or nothing displays. I may simply be setting something at the wrong time, though.

I'll skirt NDA by telling you that you might want to look into Xcode 4, where there may or may not be a new instrument in Instruments that might help point out these redundant OpenGL ES calls. Hypothetically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜