为什么我会收到 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT?

发布于 2024-12-05 16:22:02 字数 1881 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无可置疑 2024-12-12 16:22:03

您忘记使用 glRenderbufferStorage() 分配渲染缓冲区。

You forgot to allocate your render buffer with glRenderbufferStorage().

北方的韩爷 2024-12-12 16:22:03

一个可能的解决方案是使用默认的窗口系统提供的帧缓冲区,即 0。

我不喜欢这个解决方案因为我不知道为什么我可以' t 生成 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;
}

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:

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;
}
倒数 2024-12-12 16:22:02

尝试创建深度和模板渲染缓冲区:

// 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);

Try to create depth and stencil renderbuffers:

// 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);

and then attach them to the framebuffer:

glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthRenderbuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencilRenderbuffer);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文