我正在尝试将我的应用程序切换到使用framebuffer / renderbuffer对象(以后要渲染到纹理),但每当我使用framebuffer / renderbuffer时,都不会渲染。当默认帧缓冲区保持打开时,默认情况下,它呈现正常;所有颜色,深度和模板相关功能都与预期完全一致。
初始化代码:
if(frameBuffer == 0 || !GLES20.glIsFramebuffer(frameBuffer)){
int[] retVal = new int[1];
GLES20.glGenFramebuffers(1, retVal, 0);
frameBuffer = retVal[0];
retVal[0] = 0;
if(renderBufferColour != 0 || !GLES20.glIsRenderbuffer(renderBufferColour)){
GLES20.glGenRenderbuffers(1, retVal, 0);
renderBufferColour = retVal[0];
}
if(renderBufferDepth != 0 || !GLES20.glIsRenderbuffer(renderBufferDepth)){
GLES20.glGenRenderbuffers(1, retVal, 0);
renderBufferDepth = retVal[0];
}
if(renderBufferStencil != 0 || !GLES20.glIsRenderbuffer(renderBufferStencil)){
GLES20.glGenRenderbuffers(1, retVal, 0);
renderBufferStencil = retVal[0];
}
}
启用代码的帧缓冲(注释掉它可以使用默认缓冲区进行渲染):
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer);
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferColour);
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_RGBA4, width, height);
GLES20.glFramebufferRenderbuffer(
GLES20.GL_FRAMEBUFFER,
GLES20.GL_COLOR_ATTACHMENT0,
GLES20.GL_RENDERBUFFER,
renderBufferColour);
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferDepth);
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height);
GLES20.glFramebufferRenderbuffer(
GLES20.GL_FRAMEBUFFER,
GLES20.GL_DEPTH_ATTACHMENT,
GLES20.GL_RENDERBUFFER,
renderBufferDepth);
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, renderBufferStencil);
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_STENCIL_INDEX8, width, height);
GLES20.glFramebufferRenderbuffer(
GLES20.GL_FRAMEBUFFER,
GLES20.GL_STENCIL_ATTACHMENT,
GLES20.GL_RENDERBUFFER,
renderBufferStencil);
if (GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER) != GLES20.GL_FRAMEBUFFER_COMPLETE)
throw new RuntimeException(String.format("Failed to make complete framebuffer object %x", GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER)));
不会抛出结尾处的异常,并且在每个步骤之后检查glGetError()
时,不会返回任何错误。我在这里错过了什么吗?
答案 0 :(得分:2)
好的,在阅读OpenGLES 2.0手册后,我看到了这一段:
By allowing the images of a renderbuffer to be attached to a framebuffer,
OpenGL ES provides a mechanism to support off-screen rendering. Further, by
allowing the images of a texture to be attached to a framebuffer, OpenGL ES provides
a mechanism to support render to texture.
在我看来,应用程序渲染缓冲区总是屏幕外而不是屏幕,正如我所料。如果我已正确阅读,这就是屏幕上没有图像的原因。