【发布时间】:2014-05-29 16:31:09
【问题描述】:
我正在使用 OpenGL 管道开发 IOS 游戏。我已经能够将我想要的图形渲染到屏幕上,但是,我调用glDrawElements 的次数太多,并且担心最终会遇到性能问题。我的游戏中有几个不需要在每个渲染周期都渲染的静态元素。有没有办法可以将静态元素渲染到一个帧缓冲区并将动态元素渲染到另一个?
这是我尝试过的代码:
static BOOL renderThisFrameBuffer = YES;
if (renderThisFrameBuffer) {
glBindFramebuffer(GL_FRAMEBUFFER, interFrameBuffer);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
// Set up projection matrix
CC3GLMatrix *projection = [CC3GLMatrix matrix];
float h = 4.0f * OpenGLView.frame.size.height / OpenGLView.frame.size.width;
[projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:50];
glUniformMatrix4fv(projectionUniform, 1, 0, projection.glMatrix);
glViewport(0, 0, OpenGLView.frame.size.width, OpenGLView.frame.size.height);
for (BoardSpace *boardSpace in spaceArray){
[boardSpace drawWithMatrix:modelView];
}
[context presentRenderbuffer:GL_RENDERBUFFER];
glBindFramebuffer(GL_FRAMEBUFFER, constFrameBuffer);
renderThisFrameBuffer = false;
}
在这种情况下,我之前创建了两个帧缓冲区:interFrameBuffer 用于静态元素,constFrameBuffer 用于动态元素。我错过了什么吗?
【问题讨论】:
标签: opengl-es opengl-es-2.0 framebuffer