PDA

View Full Version : Dynamic FBO reuse (2D / 3D textures)



Elurahu
01-29-2011, 10:04 AM
I'm currently implementing a technique which require rendering to a different texture types and the way I'm currently using the FBO are causing me some issues.

What I want to do:
Use a single FBO bound at the start of the rendering pass to dynamically toggle between a MRT consisting of 3x 2D float textures and a MRT consisting of 3x 3D float textures. The 3D texture needs to be bound as layered textures because I need to be able to address the various layeres from a geometry shader.

When first binding the 3x 2D textures everything is fine, and I'm able to render to them without any issues. But after having the 3D volume texture bound I'm unable to render using the 2D texture at the start of the next rendering pass. The reason being that the FBO now believes it's layered! Shouldn't clearing the attachments I'm using be enough? Are there any reason why clearing an attachment slot doesn't clear the slot state?

Does it even make sense to use a single FBO for this, or just switch to using two seperate? The only reason I'm doing it is because of performence.

- Edit

When detaching attachments from the various color attachment slots is it needed to unbind using exactly the same function as when initially bound? Eg. clearing a slot using glFramebufferTexture2D() which was bound using glFramebufferTexture()?

Alfonse Reinheart
01-29-2011, 10:49 AM
Use a single FBO bound at the start of the rendering pass to dynamically toggle between a MRT consisting of 3x 2D float textures and a MRT consisting of 3x 3D float textures. The 3D texture needs to be bound as layered textures because I need to be able to address the various layeres from a geometry shader.

You can't do that. An FBO is either layered or it is not. You will simply have to bind different FBOs to the context.


Are there any reason why clearing an attachment slot doesn't clear the slot state?

It could just be a driver bug, but are you sure you cleared all of them?


The only reason I'm doing it is because of performence.

If you're actively attaching and unattaching images to the FBO the way you suggest every frame, I'd guess that you're already suffering any performance impact you might get from just switching FBOs.

Elurahu
01-29-2011, 10:56 AM
Thank you very much Alfonse for the answer.

When is a FBO registered as being layered? When you first bind a layered texture? What I meant about it not clearing the state I meant that an attachment state is still showing up as being layered even after clearing it.

Alfonse Reinheart
01-29-2011, 11:12 AM
When is a FBO registered as being layered?

An FBO is not "registered" as being layered. It either is or is not layered based on what is attached to it. That's why I said that it could be a driver bug, or you forgot to unattach something.

If it's a driver bug, the best way to avoid it is to just use two FBOs.

Elurahu
01-29-2011, 11:17 AM
There we go! Thank you Alfonse :)