Issue with attachTexture function in ofFbo

Hi all,

I’m currently facing a problem when trying to attach multiple textures to a single framebuffer object via the attachTexture function. My bare bone codes for doing this is as follows:

std::array<int, 2> frameBufferSize = {1280, 720};
mColorTexture.allocate(frameBufferSize[0], frameBufferSize[1], GL_RGBA16F);
mBrightTexture1.allocate(frameBufferSize[0], frameBufferSize[1], GL_RGBA16F);

mColorBrightFbo.allocate(frameBufferSize[0], frameBufferSize[1], GL_RGBA16F);
mColorBrightFbo.attachTexture(mColorTexture, GL_RGBA16F, 0);
mColorBrightFbo.attachTexture(mBrightTexture1, GL_RGBA16F, 1);

During the later shading stages, I can’t render into the second attached texture.

When looking at the source code for the ofFbo class, I notice that the attachTexture member function doesn’t extend the activeDrawBuffers member variable ( contrary to the createAndAttachTexture function ). To circumvent this problem, I’ve resorted to the following (temporary) hack: I moved the activeDrawBuffers member variable to the public section of the ofFbo class. This allows me to manually extend the activeDrawBuffers with the following to calls:

mColorBrightFbo.activeDrawBuffers.push_back(GL_COLOR_ATTACHMENT0 + 0);
mColorBrightFbo.activeDrawBuffers.push_back(GL_COLOR_ATTACHMENT0 + 1);

Doing so fixes the problem that I couldn’t render into the second texture.

I’m now wondering if this behaviour is a bug or if I’m using the ofFbo class in an incorrect manner.

I greatly appreciate any advice about this.

Best regards

 Daniel

Hi there!

Right after you do ofFbo::begin(), are you calling ofFbo::activateAllDrawBuffers()?

Hi,

yes, I’m doing this.

just a brief note:

Another method that allows me to avoid the above mentioned problem is to execute the following OpenGL call right after executing the activateAllDrawBuffers function of the ofFbo:

GLuint attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glDrawBuffers(2, attachments);

Does this provide any clue why this doesn’t happen automatically when using the framebuffer object?

Thanks and best regards

Daniel

How are allocating your ofFbo? Are you using the ofFbo::Settings object?

You need to set numColorbuffers to 3.

No, I haven’t been using the settings object.

If I understand correctly, by allocating the ofFbo with a settings object whose numColorbuffers value is greater than 1, the ofFbo will automatically create these additional textures for me. If this is the case, then that is not what I need, since I’m trying to implement a mechanism in which different ofFbo objects share the same textures. Does there exist a mechanism that allows me to specify the number of color buffers but avoids their automated creation?

Yes, it automatically creates. But you can still attach your textures, like you intended on your first post.

Ok, so its no problem if the automated mechanism creates some textures in vain?

I’ve followed your recommendation and attached my own textures after the automated texture creation part. This works fine. Thanks a lot for your advice!

Best regards

Daniel