无法绘制到QOpenGLFramebufferObject

我有一个QOpenGLFramebufferObject,已经在我的应用程序中使用texture()进行写入和读取。我添加了第二个颜色附件以包括一些其他数据,但似乎没有数据写入其中。

// creating the FBO (this has been working)
_drawFbo = new QOpenGLFramebufferObject(PAINT_FBO_WIDTH,PAINT_FBO_WIDTH,QOpenGLFramebufferObject::Depth);

// now I'm adding another color attachment
_drawFbo->addColorAttachment(PAINT_FBO_WIDTH,PAINT_FBO_WIDTH);

然后在绑定着色器时,在我的着色器中我写两个附件:

layout(location=0) out vec4 meshWithPaintColor;
layout(location=1) out vec4 primitiveId;

void main() {
    ...
    meshWithPaintColor = vec4(finalColor,0);
    primitiveId = vec4(1,1,1);

当我尝试使用绑定到着色器采样器的textures()[1]值从第二个附件读取时,该值似乎始终为零。

我需要对QOpenGLFramebufferObject做任何事情以允许绘制第二个颜色附件吗?

colin2625 回答:无法绘制到QOpenGLFramebufferObject

事实上,我确实必须自己调用glDrawBuffers。我认为这是由FBO绑定处理的,但显然不是。

    QOpenGLExtraFunctions* f = QOpenGLContext::currentContext()->extraFunctions();
    GLenum bufs[2] = { GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1 };
    f->glDrawBuffers(2,bufs);

对于我来说,FBO抽象支持颜色附件,但是使用它们需要额外的功能,这对我来说似乎很奇怪。

本文链接:https://www.f2er.com/3154917.html

大家都在问