1 /* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2  *
3  * This software is open source and may be redistributed and/or modified under
4  * the terms of the GNU General Public License (GPL) version 2.0.
5  * The full license is in LICENSE.txt file included with this distribution,.
6  *
7  * This software is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * include LICENSE.txt for more details.
11 */
12 
13 #include <osgPresentation/CompileSlideCallback>
14 
15 #include <osgUtil/GLObjectsVisitor>
16 
17 using namespace osgPresentation;
18 
operator ()(const osg::Camera & camera) const19 void CompileSlideCallback::operator()(const osg::Camera & camera) const
20 {
21     osg::GraphicsContext* context = const_cast<osg::GraphicsContext*>(camera.getGraphicsContext());
22     if (!context) return;
23 
24     osg::State* state = context->getState();
25     if (!state) return;
26 
27     const osg::FrameStamp* fs = state->getFrameStamp();
28     if (!fs) return;
29 
30     if (_needCompile)
31     {
32         _frameNumber = fs->getFrameNumber();
33         _needCompile = false;
34     }
35 
36     if (_frameNumber!=fs->getFrameNumber()) return;
37 
38     osgUtil::GLObjectsVisitor globjVisitor(osgUtil::GLObjectsVisitor::COMPILE_DISPLAY_LISTS|
39                                   osgUtil::GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES);
40 
41     globjVisitor.setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
42 
43     globjVisitor.setNodeMaskOverride(0xffffffff);
44 
45     globjVisitor.setState(state);
46 
47     _sceneToCompile->accept(globjVisitor);
48 }
49