Show
Ignore:
Timestamp:
12/26/07 23:00:28 (7 years ago)
Author:
robert
Message:

From Paul Martz, "The osgocclusionquery example contained some duplicate code that was also in the core OSG occlusion query code. This change removes the need for that."

Files:
1 modified

Legend:

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

    r7731 r7754  
    6464// NodeVisitors and utility functions for OcclusionQueryNode 
    6565 
    66 // Create and return a StateSet appropriate for performing an occlusion 
    67 //   query test (disable lighting, texture mapping, etc). Probably some 
    68 //   room for improvement here. Could disable shaders, for example. 
    69 osg::StateSet* 
    70 initOQState() 
    71 { 
    72     osg::StateSet* state = new osg::StateSet; 
    73     // TBD Possible bug, need to allow user to set render bin number. 
    74     state->setRenderBinDetails( 9, "RenderBin" ); 
    75  
    76     state->setMode( GL_LIGHTING, osg::StateAttribute::OFF | 
    77         osg::StateAttribute::PROTECTED); 
    78     state->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF | 
    79         osg::StateAttribute::PROTECTED); 
    80     state->setMode( GL_CULL_FACE, osg::StateAttribute::ON | 
    81         osg::StateAttribute::PROTECTED); 
    82  
    83     osg::ColorMask* cm = new osg::ColorMask( false, false, false, false ); 
    84     state->setAttributeAndModes( cm, osg::StateAttribute::ON | 
    85         osg::StateAttribute::PROTECTED); 
    86     osg::Depth* d = new osg::Depth( osg::Depth::LEQUAL, 0.f, 1.f, false ); 
    87     state->setAttributeAndModes( d, osg::StateAttribute::ON | 
    88         osg::StateAttribute::PROTECTED); 
    89     osg::PolygonMode* pm = new osg::PolygonMode( 
    90         osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL ); 
    91     state->setAttributeAndModes( pm, osg::StateAttribute::ON | 
    92         osg::StateAttribute::PROTECTED); 
    93  
    94     osg::PolygonOffset* po = new osg::PolygonOffset( -1., -1. ); 
    95     state->setAttributeAndModes( po, osg::StateAttribute::ON | 
    96         osg::StateAttribute::PROTECTED); 
    97  
    98     return state; 
    99 } 
    100  
    101 // Create and return a StateSet for rendering a debug representation of query geometry. 
    102 osg::StateSet* 
    103 initOQDebugState() 
    104 { 
    105     osg::StateSet* debugState = new osg::StateSet; 
    106  
    107     debugState->setMode( GL_LIGHTING, osg::StateAttribute::OFF | 
    108         osg::StateAttribute::PROTECTED); 
    109     debugState->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF | 
    110         osg::StateAttribute::PROTECTED); 
    111     debugState->setMode( GL_CULL_FACE, osg::StateAttribute::ON | 
    112         osg::StateAttribute::PROTECTED); 
    113  
    114     osg::PolygonMode* pm = new osg::PolygonMode( 
    115         osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE ); 
    116     debugState->setAttributeAndModes( pm, osg::StateAttribute::ON | 
    117         osg::StateAttribute::PROTECTED); 
    118  
    119     osg::PolygonOffset* po = new osg::PolygonOffset( -1., -1. ); 
    120     debugState->setAttributeAndModes( po, osg::StateAttribute::ON | 
    121         osg::StateAttribute::PROTECTED); 
    122  
    123     return debugState; 
    124 } 
    125  
    12666// Use this visitor to insert OcclusionQueryNodes (OQNs) in the 
    12767//   visited subgraph. Only one OQN will test any particular node 
     
    321261    _occluderThreshold( 5000 ) 
    322262{ 
    323     // Init StateSet for occlusion query geometry. 
    324     _state = initOQState(); 
    325     // Initialize StateSet for debug geometry 
    326     _debugState = initOQDebugState(); 
     263    // Create a dummy OcclusionQueryNode just so we can get its state. 
     264    // We'll then share that state between all OQNs we add to the visited scene graph. 
     265    osg::ref_ptr<osg::OcclusionQueryNode> oqn = new osg::OcclusionQueryNode; 
     266 
     267    osg::StateSet* ss( NULL ); 
     268    osg::StateSet* ssDebug( NULL ); 
     269    oqn->getQueryStateSets( ss, ssDebug ); 
     270    _state = ss; 
     271    _debugState = ssDebug; 
    327272} 
    328273