OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
View.h
Go to the documentation of this file.
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 
23 namespace osg {
24 
29 class 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 
38 
40  virtual void take(View& rhs);
41 
42 
44  void setStats(osg::Stats* stats) { _stats = stats; }
45 
47  osg::Stats* getStats() { return _stats.get(); }
48 
50  const osg::Stats* getStats() const { return _stats.get(); }
51 
52 
55  {
58  SKY_LIGHT
59  };
60 
63  void setLightingMode(LightingMode lightingMode);
64 
66  LightingMode getLightingMode() const { return _lightingMode; }
67 
69  void setLight(osg::Light* light) { _light = light; }
70 
72  osg::Light* getLight() { return _light.get(); }
73 
75  const osg::Light* getLight() const { return _light.get(); }
76 
78  void setCamera(osg::Camera* camera);
79 
81  osg::Camera* getCamera() { return _camera.get(); }
82 
84  const osg::Camera* getCamera() const { return _camera.get(); }
85 
87  void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
88 
90  osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
91 
93  const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
94 
95 
98  {
99  Slave(bool useMastersSceneData=true):
100  _useMastersSceneData(useMastersSceneData) {}
101 
102  Slave(osg::Camera* camera, const osg::Matrixd& projectionOffset, const osg::Matrixd& viewOffset, bool useMastersSceneData=true):
103  _camera(camera),
104  _projectionOffset(projectionOffset),
105  _viewOffset(viewOffset),
106  _useMastersSceneData(useMastersSceneData) {}
107 
108  Slave(const Slave& rhs) :
109  _camera(rhs._camera),
110  _projectionOffset(rhs._projectionOffset),
111  _viewOffset(rhs._viewOffset),
112  _useMastersSceneData(rhs._useMastersSceneData),
113  _updateSlaveCallback(rhs._updateSlaveCallback) {}
114 
115  virtual ~Slave() {}
116 
117  Slave& operator = (const Slave& rhs)
118  {
119  _camera = rhs._camera;
120  _projectionOffset = rhs._projectionOffset;
121  _viewOffset = rhs._viewOffset;
122  _useMastersSceneData = rhs._useMastersSceneData;
123  _updateSlaveCallback = rhs._updateSlaveCallback;
124  return *this;
125  }
126 
127  struct UpdateSlaveCallback : public virtual Referenced
128  {
129  virtual void updateSlave(osg::View& view, osg::View::Slave& slave) = 0;
130  };
131 
132  void updateSlave(View& view)
133  {
134  if (_updateSlaveCallback.valid()) _updateSlaveCallback->updateSlave(view, *this);
135  else updateSlaveImplementation(view);
136  }
137 
138  virtual void updateSlaveImplementation(View& view);
139 
145  };
146 
147  bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); }
148 
149  bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData=true);
150 
151  bool removeSlave(unsigned int pos);
152 
153  unsigned int getNumSlaves() const { return static_cast<unsigned int>(_slaves.size()); }
154 
155  Slave& getSlave(unsigned int pos) { return _slaves[pos]; }
156  const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; }
157 
158  unsigned int findSlaveIndexForCamera(osg::Camera* camera) const;
159 
160  Slave * findSlaveForCamera(osg::Camera* camera);
161 
162  void updateSlaves();
163 
164  protected :
165 
166  virtual ~View();
167 
169 
171 
174 
176 
177  typedef std::vector<Slave> Slaves;
178  Slaves _slaves;
179 
181 };
182 
183 }
184 
185 #endif
osg::Stats * getStats()
Definition: View.h:47
void setStats(osg::Stats *stats)
Definition: View.h:44
#define OSG_EXPORT
Definition: Export.h:43
void updateSlave(View &view)
Definition: View.h:132
osg::FrameStamp * getFrameStamp()
Definition: View.h:90
bool addSlave(osg::Camera *camera, bool useMastersSceneData=true)
Definition: View.h:147
const osg::Light * getLight() const
Definition: View.h:75
osg::ref_ptr< osg::Light > _light
Definition: View.h:173
static Matrixd identity(void)
Definition: Matrixd.h:438
const Slave & getSlave(unsigned int pos) const
Definition: View.h:156
const osg::Stats * getStats() const
Definition: View.h:50
std::vector< Slave > Slaves
Definition: View.h:177
const osg::FrameStamp * getFrameStamp() const
Definition: View.h:93
Slaves _slaves
Definition: View.h:178
virtual osg::GraphicsOperation * createRenderer(osg::Camera *)
Definition: View.h:168
Slave(bool useMastersSceneData=true)
Definition: View.h:99
osg::ref_ptr< osg::Camera > _camera
Definition: View.h:140
void setLight(osg::Light *light)
Definition: View.h:69
osg::Matrixd _viewOffset
Definition: View.h:142
LightingMode
Definition: View.h:54
osg::ref_ptr< osg::FrameStamp > _frameStamp
Definition: View.h:180
LightingMode getLightingMode() const
Definition: View.h:66
Slave & getSlave(unsigned int pos)
Definition: View.h:155
#define META_Object(library, name)
Definition: Object.h:42
osg::Light * getLight()
Definition: View.h:72
void setFrameStamp(osg::FrameStamp *fs)
Definition: View.h:87
virtual ~Slave()
Definition: View.h:115
LightingMode _lightingMode
Definition: View.h:172
unsigned int getNumSlaves() const
Definition: View.h:153
osg::Matrixd _projectionOffset
Definition: View.h:141
osg::ref_ptr< osg::Camera > _camera
Definition: View.h:175
const osg::Camera * getCamera() const
Definition: View.h:84
Definition: AlphaFunc.h:19
Slave(const Slave &rhs)
Definition: View.h:108
osg::ref_ptr< UpdateSlaveCallback > _updateSlaveCallback
Definition: View.h:144
Slave(osg::Camera *camera, const osg::Matrixd &projectionOffset, const osg::Matrixd &viewOffset, bool useMastersSceneData=true)
Definition: View.h:102
Definition: View.h:29
bool _useMastersSceneData
Definition: View.h:143
osg::ref_ptr< osg::Stats > _stats
Definition: View.h:170
osg::Camera * getCamera()
Definition: View.h:81