root/OpenSceneGraph/trunk/include/osgUtil/GLObjectsVisitor @ 9377

Revision 9377, 4.4 kB (checked in by robert, 5 years ago)

Introduce NodeVisitor::className and libraryName()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_GLOBJECTSVISITOR
15#define OSGUTIL_GLOBJECTSVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/Geode>
19#include <osg/State>
20
21#include <osgUtil/Export>
22
23namespace osgUtil {
24
25/** Visitor for traversing scene graph and setting each osg::Drawable's _useDisplayList flag,
26  * with option to immediately compile osg::Drawable OpenGL Display lists and
27  * osg::StateAttribute's.
28  */
29class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
30{
31    public:
32
33        /** Operation modes of the.*/
34        enum ModeValues
35        {
36            SWITCH_ON_DISPLAY_LISTS             = 0x1,
37            SWITCH_OFF_DISPLAY_LISTS            = 0x2,
38            COMPILE_DISPLAY_LISTS               = 0x4,
39            COMPILE_STATE_ATTRIBUTES            = 0x8,
40            RELEASE_DISPLAY_LISTS               = 0x10,
41            RELEASE_STATE_ATTRIBUTES            = 0x20,
42            SWITCH_ON_VERTEX_BUFFER_OBJECTS     = 0x40,
43            SWITCH_OFF_VERTEX_BUFFER_OBJECTS    = 0x80,
44            CHECK_BLACK_LISTED_MODES            = 0x100
45        };
46       
47        typedef unsigned int Mode;
48
49        /** Construct a GLObjectsVisitor to traverse all children, operating on
50          * node according to specified mode, such as to compile or release
51          * display list/texture objects etc. Default mode is to compile
52          * GL objects.
53          */
54        GLObjectsVisitor(Mode mode=COMPILE_DISPLAY_LISTS|COMPILE_STATE_ATTRIBUTES|CHECK_BLACK_LISTED_MODES);     
55 
56        META_NodeVisitor("osg","GLObjectsVisitor")
57       
58        virtual void reset()
59        {
60            _drawablesAppliedSet.clear();
61            _stateSetAppliedSet.clear();
62        }
63
64       
65        /** Set the operational mode of what operations to do on the scene graph.*/
66        void setMode(Mode mode) { _mode = mode; }
67
68        /** Get the operational mode.*/
69        Mode getMode() const { return _mode; }
70       
71
72        /** Set the State to use during traversal. */
73        void setState(osg::State* state)
74        {
75            _renderInfo.setState(state);
76        }
77       
78        osg::State* getState()
79        {
80            return _renderInfo.getState();
81        }
82
83        void setRenderInfo(osg::RenderInfo& renderInfo)
84        {
85            _renderInfo = renderInfo;
86        }
87       
88        osg::RenderInfo& getRenderInfo()
89        {
90            return _renderInfo;
91        }
92
93        /** Simply traverse using standard NodeVisitor traverse method.*/
94        virtual void apply(osg::Node& node);
95       
96        /** For each Geode visited set the display list usage according to the
97          * _displayListMode.
98          */
99        virtual void apply(osg::Geode& node);
100
101        void apply(osg::Drawable& drawable);
102        void apply(osg::StateSet& stateset);
103
104    protected:
105
106        typedef std::set<osg::Drawable*> DrawableAppliedSet;
107        typedef std::set<osg::StateSet*> StatesSetAppliedSet;
108
109        Mode                        _mode;
110        osg::RenderInfo             _renderInfo;
111        DrawableAppliedSet          _drawablesAppliedSet;
112        StatesSetAppliedSet         _stateSetAppliedSet;
113        osg::ref_ptr<osg::Program>  _lastCompiledProgram;
114
115};
116
117class OSGUTIL_EXPORT GLObjectsOperation : public osg::GraphicsOperation
118{
119    public:
120
121        GLObjectsOperation(GLObjectsVisitor::Mode mode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|GLObjectsVisitor::CHECK_BLACK_LISTED_MODES);
122
123        GLObjectsOperation(osg::Node* subgraph, GLObjectsVisitor::Mode mode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|GLObjectsVisitor::CHECK_BLACK_LISTED_MODES);
124
125        virtual void operator () (osg::GraphicsContext* context);
126
127    protected:
128   
129        osg::ref_ptr<osg::Node> _subgraph;
130        GLObjectsVisitor::Mode  _mode;
131};
132
133}
134
135#endif
136
Note: See TracBrowser for help on using the browser.