Changeset 9239

Show
Ignore:
Timestamp:
11/25/08 11:57:14 (9 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."

Location:
OpenSceneGraph/trunk
Files:
4 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 
  • OpenSceneGraph/trunk/include/osg/FrameBufferObject

    r9136 r9239  
    2626#define GL_FRAMEBUFFER_EXT                     0x8D40 
    2727#define GL_RENDERBUFFER_EXT                    0x8D41 
    28 #define GL_STENCIL_INDEX_EXT                   0x8D45 
     28// #define GL_STENCIL_INDEX_EXT                   0x8D45  // removed in rev. #114 of the spec 
    2929#define GL_STENCIL_INDEX1_EXT                  0x8D46 
    3030#define GL_STENCIL_INDEX4_EXT                  0x8D47 
  • OpenSceneGraph/trunk/src/osg/Camera.cpp

    r8447 r9239  
    256256void Camera::attach(BufferComponent buffer, GLenum internalFormat) 
    257257{ 
     258    switch(buffer) 
     259    { 
     260    case DEPTH_BUFFER: 
     261        if(_bufferAttachmentMap.find(PACKED_DEPTH_STENCIL_BUFFER) != _bufferAttachmentMap.end()) 
     262        { 
     263            notify(WARN)  
     264                << "Camera: DEPTH_BUFFER already attached as PACKED_DEPTH_STENCIL_BUFFER !"  
     265                << std::endl; 
     266        } 
     267        break; 
     268 
     269    case STENCIL_BUFFER: 
     270        if(_bufferAttachmentMap.find(PACKED_DEPTH_STENCIL_BUFFER) != _bufferAttachmentMap.end()) 
     271        { 
     272            notify(WARN)  
     273                << "Camera: STENCIL_BUFFER already attached as PACKED_DEPTH_STENCIL_BUFFER !"  
     274                << std::endl; 
     275        } 
     276        break; 
     277 
     278    case PACKED_DEPTH_STENCIL_BUFFER: 
     279        if(_bufferAttachmentMap.find(DEPTH_BUFFER) != _bufferAttachmentMap.end()) 
     280        { 
     281            notify(WARN) << "Camera: DEPTH_BUFFER already attached !" << std::endl; 
     282        } 
     283        if(_bufferAttachmentMap.find(STENCIL_BUFFER) != _bufferAttachmentMap.end()) 
     284        { 
     285            notify(WARN) << "Camera: STENCIL_BUFFER already attached !" << std::endl; 
     286        } 
     287        break; 
     288    } 
    258289    _bufferAttachmentMap[buffer]._internalFormat = internalFormat; 
    259290} 
  • OpenSceneGraph/trunk/src/osgUtil/RenderStage.cpp

    r9062 r9239  
    389389                            internalFormat = GL_STENCIL_INDEX8_EXT; 
    390390                            break; 
     391                        case Camera::PACKED_DEPTH_STENCIL_BUFFER: 
     392                            internalFormat = GL_DEPTH_STENCIL_EXT; 
     393                            break; 
    391394                        default: 
    392395                            internalFormat = GL_RGBA; 
     
    402405                if (buffer==osg::Camera::DEPTH_BUFFER) depthAttached = true; 
    403406                else if (buffer==osg::Camera::STENCIL_BUFFER) stencilAttached = true; 
     407                else if (buffer==osg::Camera::PACKED_DEPTH_STENCIL_BUFFER) 
     408                { 
     409                    depthAttached = true; 
     410                    stencilAttached = true; 
     411                } 
    404412                else if (buffer>=osg::Camera::COLOR_BUFFER) colorAttached = true; 
     413                 
    405414            } 
    406415 
     
    559568                        stencilAttached = true; 
    560569                        break; 
     570                    } 
     571                    case(osg::Camera::PACKED_DEPTH_STENCIL_BUFFER): 
     572                    { 
     573                        traits->depth = 24; 
     574                        depthAttached = true; 
     575                        traits->stencil = 8; 
     576                        stencilAttached = true; 
    561577                    } 
    562578                    case(osg::Camera::COLOR_BUFFER): 
     
    863879                blitMask |= GL_STENCIL_BUFFER_BIT; 
    864880                break; 
     881            case Camera::PACKED_DEPTH_STENCIL_BUFFER: 
     882                blitMask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; 
    865883            default: 
    866884                blitMask |= GL_COLOR_BUFFER_BIT;