1

我正在尝试将我的应用程序切换为使用帧缓冲区/渲染缓冲区对象(希望稍后渲染到纹理),但是每当我使用帧缓冲区/渲染缓冲区时,什么都不会渲染。当默认帧缓冲区保持打开状态时,默认情况下,它渲染得很好;所有颜色、深度和模板相关的功能都完全按照预期工作。

初始化代码:

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()在每一步之后检查时,不会返回任何错误。我在这里错过了什么吗?

4

1 回答 1

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.

在我看来,应用程序渲染缓冲区总是在屏幕外而不是在屏幕上,正如我所期望的那样。如果我没看错的话,这就是屏幕上没有图像的原因。

于 2012-09-07T02:55:11.990 回答