Changeset 10786

Show
Ignore:
Timestamp:
11/19/09 17:39:03 (4 years ago)
Author:
robert
Message:

From Wojciech Lewandowski, refactor to FBO setup to use the osg::Camera implicit buffer attachements.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgUtil/RenderStage.cpp

    r10736 r10786  
    2525 
    2626#include <osgUtil/RenderStage> 
    27  
    28 #define FORCE_COLOR_ATTACHMENT  1 
    29 #define FORCE_DEPTH_ATTACHMENT  1 
    3027 
    3128using namespace osg; 
     
    350347            unsigned colorSamples = 0; 
    351348 
     349            // This is not a cut and paste error. Set BOTH local masks 
     350            // to the value of the Camera's use render buffers mask. 
     351            // We'll change this if and only if we decide we're doing MSFBO. 
     352            unsigned int renderBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true); 
     353            unsigned int resolveBuffersMask = _camera->getImplicitBufferAttachmentRenderMask(true); 
     354 
    352355            if (fbo_ext->isMultisampleSupported()) 
    353356            { 
     
    371374                { 
    372375                    fbo_multisample = new osg::FrameBufferObject; 
    373                 } 
    374             } 
    375              
     376 
     377                    // Use the value of the Camera's use resolve buffers mask as the 
     378                    // resolve mask. 
     379                    resolveBuffersMask = _camera->getImplicitBufferAttachmentResolveMask(true); 
     380                } 
     381            } 
     382 
    376383            for(osg::Camera::BufferAttachmentMap::iterator itr = bufferAttachments.begin(); 
    377384                itr != bufferAttachments.end(); 
     
    431438            } 
    432439 
    433 #if FORCE_DEPTH_ATTACHMENT 
    434440            if (!depthAttached) 
    435             {                 
    436                 fbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_DEPTH_COMPONENT24))); 
    437                 if (fbo_multisample.valid()) 
     441            { 
     442                // If doing MSFBO (and therefore need two FBOs, one for multisampled rendering and one for  
     443                // final resolve), then configure "fbo" as the resolve FBO, and When done  
     444                // configuring, swap it into "_resolveFbo" (see line 554). But, if not  
     445                // using MSFBO, then "fbo" is just the render fbo. 
     446                // If using MSFBO, then resolveBuffersMask  
     447                // is the value set by the app for the resolve buffers. But if not using  
     448                // MSFBO, then resolveBuffersMask is the value set by the app for render  
     449                // buffers. In both cases, resolveBuffersMask is used to configure "fbo". 
     450                if( resolveBuffersMask & osg::Camera::IMPLICIT_DEPTH_BUFFER_ATTACHMENT ) 
     451                { 
     452                    fbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_DEPTH_COMPONENT24))); 
     453                    depthAttached = true; 
     454                } 
     455                if (fbo_multisample.valid() && 
     456                    ( renderBuffersMask & osg::Camera::IMPLICIT_DEPTH_BUFFER_ATTACHMENT ) ) 
    438457                { 
    439458                    fbo_multisample->setAttachment(osg::Camera::DEPTH_BUFFER, 
     
    441460                        height, GL_DEPTH_COMPONENT24, samples, colorSamples))); 
    442461                } 
    443                 depthAttached = true; 
    444             } 
    445 #endif 
    446  
    447 #if FORCE_COLOR_ATTACHMENT 
     462            } 
     463            if (!stencilAttached) 
     464            { 
     465                if( resolveBuffersMask & osg::Camera::IMPLICIT_STENCIL_BUFFER_ATTACHMENT ) 
     466                { 
     467                    fbo->setAttachment(osg::Camera::STENCIL_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_STENCIL_INDEX8_EXT))); 
     468                    stencilAttached = true; 
     469                } 
     470                if (fbo_multisample.valid() && 
     471                    ( renderBuffersMask & osg::Camera::IMPLICIT_STENCIL_BUFFER_ATTACHMENT ) ) 
     472                { 
     473                    fbo_multisample->setAttachment(osg::Camera::STENCIL_BUFFER, 
     474                        osg::FrameBufferAttachment(new osg::RenderBuffer(width, 
     475                        height, GL_STENCIL_INDEX8_EXT, samples, colorSamples))); 
     476                } 
     477            } 
     478 
    448479            if (!colorAttached) 
    449480            { 
    450                 fbo->setAttachment(osg::Camera::COLOR_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_RGB))); 
    451                 if (fbo_multisample.valid()) 
     481                if( resolveBuffersMask & osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT ) 
     482                { 
     483                    fbo->setAttachment(osg::Camera::COLOR_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(width, height, GL_RGB))); 
     484                    colorAttached = true; 
     485                } 
     486                if (fbo_multisample.valid() && 
     487                    ( renderBuffersMask & osg::Camera::IMPLICIT_COLOR_BUFFER_ATTACHMENT ) ) 
    452488                { 
    453489                    fbo_multisample->setAttachment(osg::Camera::COLOR_BUFFER, 
     
    455491                        height, GL_RGB, samples, colorSamples))); 
    456492                } 
    457                 colorAttached = true; 
    458             } 
    459 #endif 
     493            } 
    460494 
    461495            fbo->apply(state);