[osg-users] Multiple cameras sharing multisample fbo

Ravi Mathur ravidavi at utexas.edu
Sat Mar 11 00:17:59 PST 2017

Hi all,

I would like to know how to get multiple slave cameras to successively render to the same texture using multisampling. I've looked at every osg example, but multisampled FBOs are only discussed in the context of a single rendering camera.

Without multisampling life is simple. For example if I have 2 cameras attached to the same color texture, then everything works fine, like this:


backCamera = new Texture2D(); // Also perform texture setup...
backCamera->setRenderOrder(Camera::PRE_RENDER, 0); // Render first
backCamera->attach(Camera::COLOR_BUFFER0, colorTex);

frontCamera = new Texture2D(); // Also perform texture setup...
frontCamera->setRenderOrder(Camera::PRE_RENDER, 1); // Render after backCamera
frontCamera->setClearMask(GL_DEPTH_BUFFER_BIT); // Don't erase backCamera's results
frontCamera->attach(Camera::COLOR_BUFFER0, colorTex);

Unless I'm mistaken, this setup works because the FBOs for both cameras render directly to colorTex, and frontCamera is set to not clear the color buffer.

Now, I want to enable multisampling for frontCamera. I tried simply adding the samples/colorsamples argument to attach(), like so:


frontCamera->attach(Camera::COLOR_BUFFER0, colorTex, 0, 0, false, 2, 2); // 2 samples & colorsamples

This results in the frontCamera's FBO overwriting colorTex entirely, so the backCamera's results are erased. It seems this happens because frontCamera internally renders to a multisampled renderbuffer, then blits this onto colorTex, which overwrites the texture's contents.

So this brings me back to my original question: how do I get the multisample-enabled frontCamera to render ON TOP OF its attached texture instead of overwriting it? Is there a way to "initialize" its renderbuffers with the contents of the texture?

I briefly tried going down the path of using Texture2DMultisample, but there are no examples of that so I didn't get very far.

Thank you!

Read this topic online here:

More information about the osg-users mailing list