Show
Ignore:
Timestamp:
11/25/08 11:57:14 (6 years ago)
Author:
robert
Message:

From Jaromir Vitek, "In attachment are another fixes for using packed depth+stencil (PDS).

* When used PDS RenderStage::runCameraSetUp sets flag that FBO has already stencil,depth buffer attached. Prevents adding next depth buffer.
* Sets correct traits for p-buffer if used PDS and something goes wrong with FBO setup or p-buffer is used directly.
* Adds warning to camera if user add depth/stencil already attached through PDS.
* Sets blitMask when use blit to resolve buffer.

There is also new example with using multisampled FBO."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgpackeddepthstencil/osgpackeddepthstencil.cpp

    r9204 r9239  
     1/* OpenSceneGraph example, osgpackeddepthstencil. 
     2* 
     3*  Permission is hereby granted, free of charge, to any person obtaining a copy 
     4*  of this software and associated documentation files (the "Software"), to deal 
     5*  in the Software without restriction, including without limitation the rights 
     6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
     7*  copies of the Software, and to permit persons to whom the Software is 
     8*  furnished to do so, subject to the following conditions: 
     9* 
     10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
     11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
     12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
     13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
     14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
     15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
     16*  THE SOFTWARE. 
     17*/ 
     18 
    119#include <osg/GLExtensions> 
    220#include <osg/Node> 
     
    725#include <osg/ColorMask> 
    826#include <osg/Geode> 
     27#include <osg/FrameBufferObject> 
    928 
    1029#include <osgViewer/Viewer> 
    1130#include <osgViewer/ViewerEventHandlers> 
    1231 
     32#include <iostream> 
    1333 
    1434osg::Geode* createMask() 
     
    98118    osg::ArgumentParser arguments(&argc,argv); 
    99119 
     120    arguments.getApplicationUsage()->addCommandLineOption("--fbo","Use Frame Buffer Object for render to texture, where supported."); 
     121    arguments.getApplicationUsage()->addCommandLineOption("--pbuffer-rtt","Use Pixel Buffer for render to texture, where supported."); 
     122    arguments.getApplicationUsage()->addCommandLineOption("--nopds", "Don't use packed depth stencil."); 
     123    arguments.getApplicationUsage()->addCommandLineOption("--fbo-samples",""); 
     124    arguments.getApplicationUsage()->addCommandLineOption("--color-samples", ""); 
     125 
    100126    // construct the viewer. 
    101127    osgViewer::Viewer viewer(arguments); 
     
    103129    // add stats 
    104130    viewer.addEventHandler( new osgViewer::StatsHandler() ); 
     131 
     132    // if user request help write it out to cout. 
     133    if (arguments.read("-h") || arguments.read("--help")) 
     134    { 
     135        arguments.getApplicationUsage()->write(std::cout); 
     136        return 1; 
     137    } 
     138 
     139    osg::Camera::RenderTargetImplementation renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; 
     140    int colorSamples = 0, samples = 0; 
     141    bool usePDS = true; 
     142 
     143    while (arguments.read("--fbo")) { renderImplementation = osg::Camera::FRAME_BUFFER_OBJECT; } 
     144    while (arguments.read("--pbuffer-rtt")) { renderImplementation = osg::Camera::PIXEL_BUFFER_RTT; } 
     145    while (arguments.read("--nopds")) { usePDS = false; }  
     146    while (arguments.read("--fbo-samples", samples)) {} 
     147    while (arguments.read("--color-samples", colorSamples)) {} 
     148     
    105149 
    106150    osg::Group* rootNode = new osg::Group; 
     
    126170    rttCamera->setViewport(0, 0, 1024, 1024); 
    127171    rttCamera->setRenderOrder(osg::Camera::PRE_RENDER); 
    128     rttCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); 
    129      
    130 #define USE_PACKED_DEPTH_STENCIL 
    131  
    132 #ifdef USE_PACKED_DEPTH_STENCIL 
    133     rttCamera->attach(osg::Camera::PACKED_DEPTH_STENCIL_BUFFER, GL_DEPTH_STENCIL_EXT); 
    134 #else 
    135     // this doesn't work on NVIDIA/Vista 64bit 
    136     // FBO status = 0x8cd6 (FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT) 
    137     rttCamera->attach(osg::Camera::DEPTH_BUFFER, GL_DEPTH_COMPONENT); 
    138     rttCamera->attach(osg::Camera::STENCIL_BUFFER, GL_STENCIL_INDEX_EXT); 
    139 #endif 
    140     rttCamera->attach(osg::Camera::COLOR_BUFFER, texture); 
     172    rttCamera->setRenderTargetImplementation(renderImplementation); 
     173 
     174    if(usePDS) 
     175    { 
     176        rttCamera->attach(osg::Camera::PACKED_DEPTH_STENCIL_BUFFER, GL_DEPTH_STENCIL_EXT); 
     177    } 
     178    else 
     179    { 
     180        // this doesn't work on NVIDIA/Vista 64bit 
     181        // FBO status = 0x8cd6 (FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT) 
     182        rttCamera->attach(osg::Camera::DEPTH_BUFFER, GL_DEPTH_COMPONENT); 
     183        rttCamera->attach(osg::Camera::STENCIL_BUFFER, GL_STENCIL_INDEX8_EXT); 
     184    } 
     185 
     186    rttCamera->attach(osg::Camera::COLOR_BUFFER, texture, 0, 0, false, samples, colorSamples); 
    141187    rttCamera->setCullingMode(osg::Camera::VIEW_FRUSTUM_SIDES_CULLING); 
    142188