我正在使用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。
你知道为什么吗?
答案 0 :(得分:0)
您忘了使用glRenderbufferStorage()分配渲染缓冲区。
答案 1 :(得分:0)
可能的解决方案是使用默认的window-system提供的framebuffer,即0。
我不喜欢这个解决方案因为我不知道为什么我不能生成FrameBuffer或者我可以使用默认的window-system提供的framebuffer。
以下是我的已修改代码:
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);
*/
m_framebuffer = (GLuint) 0;
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;
}
答案 2 :(得分:0)
尝试创建深度和模板渲染缓冲区:
// depth
glGenRenderbuffers(1, &m_depthRenderbuffer);
checkGlError("01 - glGenRenderbuffers");
glBindRenderbuffer(GL_RENDERBUFFER, m_depthRenderbuffer);
checkGlError("02 - glBindRenderbuffer");
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
// stencil
glGenRenderbuffers(1, &m_stencilRenderbuffer);
checkGlError("01 - glGenRenderbuffers");
glBindRenderbuffer(GL_RENDERBUFFER, m_stencilRenderbuffer);
checkGlError("02 - glBindRenderbuffer");
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
然后将它们附加到帧缓冲区:
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilRenderbuffer);