I am working on an IOS game using the OpenGL pipeline. I have been able to render the graphics I want to the screen, however, I am calling glDrawElements
too many times and have some concerns about running into performance issues eventually. I have several static elements in my game that do not need to be render on every render cycle. Is there a way I can render static elements to one frame buffer and dynamic elements to another?
Here's the code I have tried:
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;
}
In this case I have created two frame buffers previously: interFrameBuffer
for static elements and constFrameBuffer
for dynamic elements. Am I missing something?