Hi Wojtek,
On Thu, Nov 19, 2009 at 10:08 AM, Robert Osfield
<[email protected]> wrote:
> Thanks. I think what I'll do is check in the changes to include/osg
> and src/osg as they are passive changes - i.e. they won't effect
> functionality. The changes to RenderStage I'll leave till after
> further clarification from yourself.
I have now checked in the changes to include/osg and src/osg, the
changes to RenderStage.cpp I've reverted, the diff against svn/trunk
to apply these changes is attached.
Robert.
Index: RenderStage.cpp
===================================================================
--- RenderStage.cpp (revision 10765)
+++ RenderStage.cpp (working copy)
@@ -25,9 +25,6 @@
#include <osgUtil/RenderStage>
-#define FORCE_COLOR_ATTACHMENT 1
-#define FORCE_DEPTH_ATTACHMENT 1
-
using namespace osg;
using namespace osgUtil;
@@ -349,6 +346,12 @@
unsigned samples = 0;
unsigned colorSamples = 0;
+ // This is not a cut and paste error. Set BOTH local masks
+ // to the value of the Camera's use render buffers mask.
+ // We'll change this if and only if we decide we're doing MSFBO.
+ unsigned int renderBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true);
+ unsigned int resolveBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true);
+
if (fbo_ext->isMultisampleSupported())
{
for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin();
@@ -370,9 +373,13 @@
if (samples)
{
fbo_multisample = new osg::FrameBufferObject;
+
+ // Use the value of the Camera's use resolve buffers mask as the
+ // resolve mask.
+ resolveBuffersMask = _camera->getImplicitBufferAttachmentResolveMask(true);
}
}
-
+
for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin();
itr != bufferAttachments.end();
++itr)
@@ -430,33 +437,63 @@
}
-#if FORCE_DEPTH_ATTACHMENT
if (!depthAttached)
- {
- fbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_DEPTH_COMPONENT24)));
- if (fbo_multisample.valid())
+ {
+ // If doing MSFBO (and therefore need two FBOs, one for multisampled rendering and one for
+ // final resolve), then configure "fbo" as the resolve FBO, and When done
+ // configuring, swap it into "_resolveFbo" (see line 554). But, if not
+ // using MSFBO, then "fbo" is just the render fbo.
+ // If using MSFBO, then resolveBuffersMask
+ // is the value set by the app for the resolve buffers. But if not using
+ // MSFBO, then resolveBuffersMask is the value set by the app for render
+ // buffers. In both cases, resolveBuffersMask is used to configure "fbo".
+ if( resolveBuffersMask & osg::Camera::IMPLICIT_DEPTH_BUFFER_ATTACHMENT )
{
+ fbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_DEPTH_COMPONENT24)));
+ depthAttached = true;
+ }
+ if (fbo_multisample.valid() &&
+ ( renderBuffersMask & osg::Camera::IMPLICIT_DEPTH_BUFFER_ATTACHMENT ) )
+ {
fbo_multisample->setAttachment(osg::Camera::DEPTH_BUFFER,
osg::FrameBufferAttachment(new osg::RenderBuffer(width,
height, GL_DEPTH_COMPONENT24, samples, colorSamples)));
+ depthAttached = true;
}
- depthAttached = true;
}
-#endif
+ if (!stencilAttached)
+ {
+ if( resolveBuffersMask & osg::Camera::IMPLICIT_STENCIL_BUFFER_ATTACHMENT )
+ {
+ fbo->setAttachment(osg::Camera::STENCIL_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_STENCIL_INDEX8_EXT)));
+ stencilAttached = true;
+ }
+ if (fbo_multisample.valid() &&
+ ( renderBuffersMask & osg::Camera::IMPLICIT_STENCIL_BUFFER_ATTACHMENT ) )
+ {
+ fbo_multisample->setAttachment(osg::Camera::STENCIL_BUFFER,
+ osg::FrameBufferAttachment(new osg::RenderBuffer(width,
+ height, GL_STENCIL_INDEX8_EXT, samples, colorSamples)));
+ stencilAttached = true;
+ }
+ }
-#if FORCE_COLOR_ATTACHMENT
if (!colorAttached)
{
- fbo->setAttachment(osg::Camera::COLOR_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_RGB)));
- if (fbo_multisample.valid())
+ if( resolveBuffersMask & osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT )
{
+ fbo->setAttachment(osg::Camera::COLOR_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_RGB)));
+ colorAttached = true;
+ }
+ if (fbo_multisample.valid() &&
+ ( renderBuffersMask & osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT ) )
+ {
fbo_multisample->setAttachment(osg::Camera::COLOR_BUFFER,
osg::FrameBufferAttachment(new osg::RenderBuffer(width,
height, GL_RGB, samples, colorSamples)));
+ colorAttached = true;
}
- colorAttached = true;
}
-#endif
fbo->apply(state);
@@ -904,29 +941,12 @@
if (fbo_supported && _resolveFbo.valid() && fbo_ext->glBlitFramebuffer)
{
- GLbitfield blitMask = 0;
+ // OpenGL 3.1 spec says: "If a buffer is specified in mask and does not
+ // exist in both the read and draw framebuffers, the corresponding bit
+ // is silently ignored." So there is no need to iterate over buffer
+ // attachments to determine the value of mask; just blit all.
+ const GLbitfield blitMask( GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
- //find which buffer types should be copied
- for (FrameBufferObject::AttachmentMap::const_iterator
- it = _resolveFbo->getAttachmentMap().begin(),
- end =_resolveFbo->getAttachmentMap().end(); it != end; ++it)
- {
- switch (it->first)
- {
- case Camera::DEPTH_BUFFER:
- blitMask |= GL_DEPTH_BUFFER_BIT;
- break;
- case Camera::STENCIL_BUFFER:
- blitMask |= GL_STENCIL_BUFFER_BIT;
- break;
- case Camera::PACKED_DEPTH_STENCIL_BUFFER:
- blitMask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
- default:
- blitMask |= GL_COLOR_BUFFER_BIT;
- break;
- }
- }
-
// Bind the resolve framebuffer to blit into.
_fbo->apply(state, FrameBufferObject::READ_FRAMEBUFFER);
_resolveFbo->apply(state, FrameBufferObject::DRAW_FRAMEBUFFER);
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org