简体   繁体   English

为什么这个 OpenGL 帧缓冲颜色附件不完整?

[英]Why is this OpenGL framebuffer color attachment incomplete?

I've been following this tutorial on rendering to an off-screen texture, but I'm having difficulty creating the render target.我一直在关注这个关于渲染到屏幕外纹理的教程,但是我在创建渲染目标时遇到了困难。 I've registered an error callback function and I'm getting a GL_DEBUG_TYPE_OTHER error back with a GL_DEBUG_SOURCE_API source, which is getting spat out by glCheckNamedFramebufferStatus() with the message:我已经注册了一个错误回调 function 并且我收到一个带有GL_DEBUG_SOURCE_API源的GL_DEBUG_TYPE_OTHER错误,它被glCheckNamedFramebufferStatus()吐出并带有以下消息:

FBO incomplete: color attachment incomplete[0]. FBO 不完整:颜色附件不完整[0]。

I'm struggling to see what I'm missing here, I've double checked the parameters that I'm passing into the OpenGL functions and tried removing the glTexParameteri calls but to no avail.我很难看到我在这里缺少什么,我仔细检查了我传递给 OpenGL 函数的参数,并尝试删除glTexParameteri调用但无济于事。

Any help would be greatly appreciated.任何帮助将不胜感激。

GLuint framebuffer = 0;
GLuint renderedTexture;
GLenum drawBuffers[1] = {GL_COLOR_ATTACHMENTS0};

bool buildOffscreenBuffer()
{
    // creating frame & render texture to draw picker buffer to
    glGenFramebuffers(1,  &framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    glGenTextures(1, &renderedTexture);
                                                                                              
    glBindTexture(GL_TEXTURE_2D, renderedTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1920, 1080,
            0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                                                                                              
    // configuring framebuffer
    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
            renderedTexture, 0);
    glDrawBuffers(1, drawBuffers);
                                                                                              
    return glCheckNamedFramebufferStatus(framebuffer, GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
}

Update: As per derhass ' answer , it seems that GL_RGB isn't required as per the spec.更新:根据derhass回答,根据规范,似乎不需要 GL_RGB。 I've tried updating this to GL_RGBA but I'm getting the same error.我尝试将其更新为 GL_RGBA 但我遇到了同样的错误。 Since this may be implementation related, I'll list my card and driver:由于这可能与实现相关,我将列出我的卡和驱动程序:

Card: RX Vega 56卡:RX Vega 56

Driver: mesa/amdgpu驱动程序:台面/amdgpu

As per the GL spec, GL_RGB is not in the set of required renderable formats , so implementations are free to not support it.根据 GL 规范, GL_RGB不在所需的可渲染格式集中,因此实现可以不支持它。 Try GL_RGBA instead.改用GL_RGBA

Managed to get to the bottom of this.设法弄清了这一点。 I'd actually fixed the bug in simplifying the example for the post.我实际上已经修复了简化帖子示例的错误。

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1920, 1080,
            0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

Was actually getting the width and height from a helper function that from a platform layer, however that function returned a struct {int, int} that I was storing in a struct {float, float} .实际上是从平台层的助手 function 获取宽度和高度,但是 function 返回了一个struct {int, int}我存储在一个struct {float, float}中。 This resulted in garbage being passed as the width and height to glTexImage2D .这导致垃圾作为宽度和高度传递给glTexImage2D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM