root/OpenSceneGraph/trunk/include/osg/View @ 9554

Revision 9554, 6.1 kB (checked in by robert, 5 years ago)

Refactored the view stats.

  • 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 OSG_VIEW
15#define OSG_VIEW 1
16
17#include <osg/Camera>
18#include <osg/Light>
19#include <osg/Stats>
20
21#include <OpenThreads/Mutex>
22
23namespace osg {
24
25/** View - maintains a master camera view and a list of slave cameras that are relative to this master camera.
26  * Note, if no slave cameras are attached to the view then the master camera does both the control and implementation of the rendering of the scene,
27  * but if slave cameras are present then the master controls the view onto the scene, while the slaves implement the rendering of the scene.
28*/
29class OSG_EXPORT View : public virtual osg::Object
30{
31    public :
32
33        View();
34
35        View(const osg::View& view, const osg::CopyOp& copyop=CopyOp::SHALLOW_COPY);
36
37        META_Object(osg,View);
38       
39        /** Take all the settings, Camera and Slaves from the passed in view, leaving it empty. */
40        virtual void take(View& rhs);
41
42
43        /** Set the Stats object used for collect various frame related timing and scene graph stats.*/
44        void setStats(osg::Stats* stats) { _stats = stats; }
45
46        /** Get the Viewers Stats object.*/
47        osg::Stats* getStats() { return _stats.get(); }
48
49        /** Get the Viewers Stats object.*/
50        const osg::Stats* getStats() const { return _stats.get(); }
51
52
53        /** Options for controlling the global lighting used for the view.*/
54        enum LightingMode
55        {
56            NO_LIGHT,
57            HEADLIGHT,
58            SKY_LIGHT
59        };
60       
61        /** Set the global lighting to use for this view.
62          * Defaults to headlight. */
63        void setLightingMode(LightingMode lightingMode);
64
65        /** Get the global lighting used for this view.*/
66        LightingMode getLightingMode() const { return _lightingMode; }
67
68        /** Get the global light.*/
69        void setLight(osg::Light* light) { _light = light; }
70
71        /** Get the global lighting if assigned.*/
72        osg::Light* getLight() { return _light.get(); }
73
74        /** Get the const global lighting if assigned.*/
75        const osg::Light* getLight() const { return _light.get(); }
76
77        /** Set the master camera of the view. */       
78        void setCamera(osg::Camera* camera);
79
80        /** Get the master camera of the view. */       
81        osg::Camera* getCamera() { return _camera.get(); }
82
83        /** Get the const master camera of the view. */       
84        const osg::Camera* getCamera() const { return _camera.get(); }
85
86        /** Set the frame stamp of the view. */       
87        void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
88
89        /** Get the frame stamp of the view. */       
90        osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
91
92        /** Get the frame stamp of the view. */       
93        const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
94
95        /** Slave allows one to up a camera that follows the master with a local offset to the project and view matrices.*/
96        struct Slave
97        {
98            Slave(bool useMastersSceneData=true):
99                _useMastersSceneData(useMastersSceneData) {}
100               
101            Slave(osg::Camera* camera, const osg::Matrixd& projectionOffset, const osg::Matrixd& viewOffset, bool useMastersSceneData=true):
102                _camera(camera),
103                _projectionOffset(projectionOffset),
104                _viewOffset(viewOffset),
105                _useMastersSceneData(useMastersSceneData) {}
106       
107            Slave(const Slave& rhs) :
108                _camera(rhs._camera),
109                _projectionOffset(rhs._projectionOffset),
110                _viewOffset(rhs._viewOffset),
111                _useMastersSceneData(rhs._useMastersSceneData) {}
112
113            Slave& operator = (const Slave& rhs)
114            {
115                _camera = rhs._camera;
116                _projectionOffset = rhs._projectionOffset;
117                _viewOffset = rhs._viewOffset;
118                _useMastersSceneData = rhs._useMastersSceneData;
119                return *this;
120            }
121
122            osg::ref_ptr<osg::Camera>   _camera;
123            osg::Matrixd                _projectionOffset;
124            osg::Matrixd                _viewOffset;
125            bool                        _useMastersSceneData;
126        };
127
128        bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); }
129
130        bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData=true);
131
132        bool removeSlave(unsigned int pos);
133
134        unsigned int getNumSlaves() const { return _slaves.size(); }
135
136        Slave& getSlave(unsigned int pos) { return _slaves[pos]; }
137        const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; }
138
139        unsigned int findSlaveIndexForCamera(osg::Camera* camera) const;
140
141        Slave * findSlaveForCamera(osg::Camera* camera);
142
143        void updateSlaves();
144
145        void updateSlave(unsigned int i);
146
147
148    protected :
149
150        virtual ~View();
151
152        virtual osg::GraphicsOperation* createRenderer(osg::Camera*) { return 0; }
153
154        osg::ref_ptr<osg::Stats>        _stats;
155
156        LightingMode                    _lightingMode;
157        osg::ref_ptr<osg::Light>        _light;
158
159        osg::ref_ptr<osg::Camera>       _camera;
160       
161        typedef std::vector<Slave>      Slaves;
162        Slaves                          _slaves;
163
164        osg::ref_ptr<osg::FrameStamp>   _frameStamp;
165};
166
167}
168
169#endif
Note: See TracBrowser for help on using the browser.