6

我一直在搞乱帧缓冲区并渲染到纹理,我遇到了对它们进行 blit 处理的需要。再次在某些机器上,我GL_INVALID_OPERATIONglBlitFramebuffer通话后立即得到。绑定到帧缓冲区的每个纹理都以完全相同的方式设置,所有相同的大小和参数。此外,当我尝试将整个纹理(之前已成功渲染到)blit 到另一个帧缓冲区时,只有要写入的目标“矩形”小于要读取的矩形(例如,当我想将它blit 到屏幕),它GL_INVALID_OPERATION也会抛出一个。

编辑: 实际上,每当要读取和绘制的矩形具有不同的大小时,它总是会引发错误,因此我不能将纹理粘贴到不同大小的纹理,或者相同大小但不同大小的“渲染到”区域。 ..?

每次我进入手动生成的帧缓冲区时,都会检查状态glCheckFramebufferStatus并始终返回GL_FRAMEBUFFER_COMPLETE.

-有史以来最大的剪辑-,见下文较短的“源代码”,显然有几个 C++ 错误并且不完整,但它仅适用于 GL 调用

当我以屏幕帧缓冲区为目标(通过传递 NULL)调用视口 (Viewport::blit) 的最后一个方法时,会发生 OpenGL 错误。它首先设置自己帧缓冲区的读取缓冲区(绘制缓冲区已设置),然后调用 RenderTarget::blit 调用glBlitFramebuffer. 在 blit 方法中,它绑定了两个缓冲区,您可以看到它glCheckFramebufferStatus在那里调用,但不会返回错误。

我一遍又一遍地阅读这篇文章,但我似乎找不到导致它的错误。当我对我使用的颜色缓冲区进行 blit 时GL_LINEAR,否则我使用GL_NEAREST所有颜色缓冲区GL_RGB32F用作内部格式,而深度缓冲区(我从不 blit)使用GL_DEPTH_COMPONENT32F

编辑,一个更短的例子,只是接受了所有的 GL 调用并填充了我使用的参数

glBindFramebuffer(GL_READ_FRAMEBUFFER, _GL_Framebuffer);
glReadBuffer(GL_COLOR_ATTACHMENT0 + index);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);

// OpenGL error check, does not return an error

glBindFramebuffer(GL_READ_FRAMEBUFFER, _GL_Framebuffer);
GLenum status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
    // Some error checking, fortunately status always turns out to be complete
}
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

glBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, target, (target == GL_COLOR_BUFFER_BIT) ? GL_LINEAR : GL_NEAREST);

// If the source/destination read/draw rectangles are different in size, GL_INVALID_OPERATION is cought here

以及 Framebuffer/Texture 创建:

glGenFramebuffer(1, &_GL_Framebuffer);

glGenTextures(1, &_GL_ZBuffer);
glBindTexture(GL_TEXTURE_2D, _GL_ZBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, screenWidth, screenHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);

glBindFramebuffer(GL_FRAMEBUFFER, _GL_Framebuffer);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT + 0, _GL_ZBuffer, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

int writeIndices[BUFFER_COUNT];
for(unsigned int i = 0; i < BUFFER_COUNT; ++i)
{
    writeIndices[i] = i;

    glGenTextures(1, &_GL_Texture);
    glBindTexture(GL_TEXTURE_2D, _GL_Texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, screenWidth, screenHeight, 0, GL_RGB, GL_FLOAT, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glBindTexture(GL_TEXTURE_2D, 0);

    glBindFramebuffer(GL_FRAMEBUFFER, _GL_Framebuffer);
    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, _GL_Texture, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    // In the actual code each texture is obviously saved in an object
}

GLenum *enums = new GLenum[BUFFER_COUNT];
for(unsigned int i = 0; i < BUFFER_COUNT; ++i)
{
    // Get index and validate
    int index = *(indices + i); // indices = writeIndices
    if(index < 0 || index >= maxAttachments)
    {
        delete[] enums;
        return false;
    }

    // Set index
    enums[i] = GL_COLOR_ATTACHMENT0 + index;
}

// Set indices
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _GL_Framebuffer);
glDrawBuffers(BUFFER_COUNT, enums);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

delete[] enums;

// OpenGL error check, no errors
4

1 回答 1

6

经过仔细阅读后,我发现多重采样的差异是问题所在。“主”FBO 是由 SFML 设置的,因此只需将启动时的抗锯齿级别设置为 0 即可部分解决问题。

如果绘制/读取矩形的大小不相等,它现在会闪烁,但它会在一些应该工作的机器上不断崩溃。

于 2012-08-11T19:02:12.000 回答