gpt4 book ai didi

android - 在 android 上使用帧缓冲区时,场景不渲染

转载 作者:行者123 更新时间:2023-11-29 21:59:57 26 4
gpt4 key购买 nike

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

初始化代码:

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() 时,没有返回错误。我在这里遗漏了什么吗?

最佳答案

好的,在阅读 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.

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

关于android - 在 android 上使用帧缓冲区时,场景不渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12210564/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com