Desenhe para renderbuffer fora da tela no OpenGL ES (iPhone)
Estou tentando criar um buffer de renderização fora da tela no OpenGL ES no iPhone. Eu criei o buffer assim:
glGenFramebuffersOES(1, &offscreenFramebuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreenFramebuffer);
glGenRenderbuffersOES(1, &offscreenRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, offscreenRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, offscreenRenderbuffer);
Mas estou confuso sobre como processar o armazenamento. A documentação da Apple diz para usar o método EAGLContext renderBufferStorage: fromDrawable:, mas isso parece funcionar apenas para um buffer de renderização (o principal está sendo exibido). Se eu usar a função normal do OpenGL, glRenderBufferStorageOES, então não consigo fazer com que ele seja exibido. Aqui está o código:
// this is in the initialization section:
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES, backingWidth, backingHeight);
// and this is when I'm trying to draw to it and display it:
glBindFramebufferOES(GL_FRAMEBUFFER_OES, offscreenFramebuffer);
GLfloat vc[] = {
0.0f, 0.0f, 0.0f,
10.0f, 10.0f, 10.0f,
0.0f, 0.0f, 0.0f,
-10.0f, -10.0f, -10.0f,
};
glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vc);
glDrawArrays(GL_LINES, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, offscreenRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
Fazendo desta forma, nada é exibido na tela. No entanto, se eu mudar as referências para "offscreen ... Buffer" para os buffers que foram criados com o método renderBufferStorage, ele funciona bem.
Alguma sugestão?