为什么我会收到 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT?
我正在使用 NDK r6b 开发 Android 2.2 应用程序。我正在开发 OpenGL ES 2.0 代码作为本机代码 (C++)。
我有这个 C++ 代码:
RenderingEngine2::RenderingEngine2()
{
// Create & bind the color buffer so that the caller can allocate its space.
glGenRenderbuffers(1, &m_renderbuffer);
checkGlError("01 - glGenRenderbuffers");
glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffer);
checkGlError("02 - glBindRenderbuffer");
LOG("RenderingEngine2::RenderingEngine2()");
}
void RenderingEngine2::Initialize(int width, int height)
{
LOG("RenderingEngine2::Initialize");
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, width, height);
// Create the framebuffer object and attach the color buffer.
glGenFramebuffers(1, &m_framebuffer);
checkGlError("03 - glGenFramebuffers");
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
checkGlError("04 - glBindFramebuffer");
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER,
m_renderbuffer);
checkGlError("05 - glFramebufferRenderbuffer");
GLint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status == GL_FRAMEBUFFER_COMPLETE)
{
LOG("Framebuffer completed");
}
else
{
LOGE("Framebuffer error: (0x%x)", status);
}
glViewport(0, 0, width, height);
checkGlError("06 - glViewPort");
m_simpleProgram = BuildProgram(SimpleVertexShader, SimpleFragmentShader);
glUseProgram(m_simpleProgram);
checkGlError("07 - glUseProgram");
// Initialize the projection matrix.
ApplyOrtho(2, 3);
// Initialize rotation animation state.
OnRotate(DeviceOrientationPortrait);
m_currentAngle = m_desiredAngle;
}
当我运行它时,我得到一个 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT。
你知道为什么吗?
I'm developing an Android 2.2 app with NDK r6b. I'm developing OpenGL ES 2.0 code as native code (C++).
I have this C++ code:
RenderingEngine2::RenderingEngine2()
{
// Create & bind the color buffer so that the caller can allocate its space.
glGenRenderbuffers(1, &m_renderbuffer);
checkGlError("01 - glGenRenderbuffers");
glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffer);
checkGlError("02 - glBindRenderbuffer");
LOG("RenderingEngine2::RenderingEngine2()");
}
void RenderingEngine2::Initialize(int width, int height)
{
LOG("RenderingEngine2::Initialize");
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, width, height);
// Create the framebuffer object and attach the color buffer.
glGenFramebuffers(1, &m_framebuffer);
checkGlError("03 - glGenFramebuffers");
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
checkGlError("04 - glBindFramebuffer");
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER,
m_renderbuffer);
checkGlError("05 - glFramebufferRenderbuffer");
GLint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status == GL_FRAMEBUFFER_COMPLETE)
{
LOG("Framebuffer completed");
}
else
{
LOGE("Framebuffer error: (0x%x)", status);
}
glViewport(0, 0, width, height);
checkGlError("06 - glViewPort");
m_simpleProgram = BuildProgram(SimpleVertexShader, SimpleFragmentShader);
glUseProgram(m_simpleProgram);
checkGlError("07 - glUseProgram");
// Initialize the projection matrix.
ApplyOrtho(2, 3);
// Initialize rotation animation state.
OnRotate(DeviceOrientationPortrait);
m_currentAngle = m_desiredAngle;
}
When I run it, I get a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT.
Do you know why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您忘记使用 glRenderbufferStorage() 分配渲染缓冲区。
You forgot to allocate your render buffer with glRenderbufferStorage().
一个可能的解决方案是使用默认的窗口系统提供的帧缓冲区,即 0。
我不喜欢这个解决方案因为我不知道为什么我可以' t 生成 FrameBuffer 或者我是否可以使用默认窗口系统提供的帧缓冲区。
这是我的修改代码:
A possible solution is to use the default window-system-provided framebuffer, which is 0.
I don't like this solution because I don't know why I can't generate a FrameBuffer or if I can use the default window-system-provided framebuffer.
Here is my modified code:
尝试创建深度和模板渲染缓冲区:
然后将它们附加到帧缓冲区:
Try to create depth and stencil renderbuffers:
and then attach them to the framebuffer: