I have to perform a double pass convolution on a texture that is actually the color attachment of another render target, and store it in the color attachment of ANOTHER render target. This must be done multiple time, but using the same texture as starting point

What I do now is (a bit abstracted, but what I have abstract is guaranteed to work singularly)

renderOnRT(firstTarget); // This is working. 

for each other RT currRT{
    glBindFramebuffer(GL_FRAMEBUFFER, currRT.frameBufferID);    
    glBindTexture(GL_TEXTURE_2D, firstTarget.colorAttachmentID);
    glBindTexture(GL_TEXTURE_2D, firstTarget.depthAttachmentID);
    glBindBuffer(GL_ARRAY_BUFFER, quadBuffID); // quadBuffID is a VBO for a screen aligned quad. It is fine.
    programX.vertexAttribPointer(POSITION_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);

    glBindTexture(GL_TEXTURE_2D, currRT.colorAttachmentID); // The second pass is done on the previous pass
    glBindTexture(GL_TEXTURE_2D, currRT.depthAttachmentID);
    glBindBuffer(GL_ARRAY_BUFFER, quadBuffID);
    programY.vertexAttribPointer(POSITION_ATTRIBUTE, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
    glDrawArrays(GL_QUADS, 0, 4);

The problem is that I end up with black textures and not the wanted result.

The GLSL programs program(X,Y) works fine, already tested on single targets.

Is there something stupid I am missing?

Even an hint is much appreciated, thanks!

  • \$\begingroup\$ The for contains the double pass convolution step? \$\endgroup\$
    – Cristina
    Commented Jun 12, 2014 at 13:54
  • \$\begingroup\$ @Cristina The programs programX and programY are build with the shaders that perform the convolution, they do work as they give the wanted result with a single target \$\endgroup\$
    – JTulip
    Commented Jun 12, 2014 at 14:08

1 Answer 1


Later edit:

There is a feedback loop in the way you are rendering, read the code again more carefully.

You are drawing to currRT, the first convolution step fills in currRT.colorTexture. Then in the second draw call you use currRT.colorTexture for the second step of the convolution. This produces undefined behavior in GL.

You should use two frame buffers, one that does the first step of the convolution and another that does the second step.

  • \$\begingroup\$ I'm aware of that, when I render it on screen any of those texture I got black ones. And the program I use to render to screen I'm 100% sure works (works fine with other textures). \$\endgroup\$
    – JTulip
    Commented Jun 12, 2014 at 14:23
  • \$\begingroup\$ @JTulip see my update answer. Read the code again more carefully. \$\endgroup\$
    – Cristina
    Commented Jun 12, 2014 at 15:19
  • \$\begingroup\$ Ah! Sorry! Yes, I didn't thought that it was both writing and reading from same texture, thank you very much! I've solved with a temporary FBO! \$\endgroup\$
    – JTulip
    Commented Jun 12, 2014 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .