本文介绍了在Android上使用帧缓冲区时,场景不会渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试将我的应用程序切换到使用帧缓冲区/渲染缓冲区对象(希望稍后渲染到纹理),但每当我使用帧缓冲区/渲染缓冲区时,什么都不渲染。如果默认帧缓冲区处于打开状态(默认情况下),则渲染效果良好;所有与颜色、深度和模具相关的功能均可完全按照预期工作。
初始化代码:
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];
}
}
FrameBuffer启用代码(将此注释掉允许使用默认缓冲区进行渲染):
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()
时,不返回错误。我是不是错过了什么?
推荐答案
好的,在阅读了OpenGLES2.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.
在我看来,应用程序呈现缓冲区始终在屏幕外而不是像我预期的在屏幕上。如果我没有读错的话,这就是屏幕上没有图像的原因。
这篇关于在Android上使用帧缓冲区时,场景不会渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!