OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OverlayNode.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 OSGSIM_OVERLAYNODE
15 #define OSGSIM_OVERLAYNODE 1
16 
17 #include <osg/buffered_value>
18 #include <osg/Camera>
19 #include <osg/Texture2D>
20 #include <osg/TexGenNode>
21 #include <osg/Geode>
22 
23 #include <osgUtil/CullVisitor>
24 
25 #include <osgSim/Export>
26 
27 namespace osgSim {
28 
32 {
33  public :
34 
36  {
39  VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY
40  };
41 
42  OverlayNode(OverlayTechnique technique=OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY);
43 
45 
47 
48  virtual void traverse(osg::NodeVisitor& nv);
49 
50 
51  void setOverlayTechnique(OverlayTechnique technique);
52  OverlayTechnique getOverlayTechnique() const { return _overlayTechnique; }
53 
55  void setRenderTargetImplementation(osg::Camera::RenderTargetImplementation impl);
56 
58  void setOverlaySubgraph(osg::Node* node);
59 
61  osg::Node* getOverlaySubgraph() { return _overlaySubgraph.get(); }
62 
64  const osg::Node* getOverlaySubgraph() const { return _overlaySubgraph.get(); }
65 
66 
68  void dirtyOverlayTexture();
69 
71  void setContinuousUpdate(bool update) { _continuousUpdate = update; }
72 
74  bool getContinuousUpdate() const { return _continuousUpdate; }
75 
81  void setOverlayBaseHeight(double baseHeight) { _overlayBaseHeight = baseHeight; }
82 
84  double getOverlayBaseHeight() const { return _overlayBaseHeight; }
85 
87  void setOverlayClearColor(const osg::Vec4& color) { _overlayClearColor = color; }
88 
90  const osg::Vec4& getOverlayClearColor() const { return _overlayClearColor; }
91 
93  void setTexEnvMode(GLenum mode);
94 
96  GLenum getTexEnvMode() const { return _texEnvMode; }
97 
99  void setOverlayTextureUnit(unsigned int unit);
100 
102  unsigned int getOverlayTextureUnit() const { return _textureUnit; }
103 
105  void setOverlayTextureSizeHint(unsigned int size);
106 
108  unsigned int getOverlayTextureSizeHint() const { return _textureSizeHint; }
109 
110 
112  virtual void setThreadSafeRefUnref(bool threadSafe);
113 
115  virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/);
116 
120  virtual void releaseGLObjects(osg::State* = 0) const;
121 
122  protected :
123 
124  virtual ~OverlayNode() {}
125 
126  void init();
127  void init_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY();
128  void init_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY();
129  void init_VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY();
130 
131  void traverse_OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVisitor& nv);
132  void traverse_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVisitor& nv);
133  void traverse_VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY(osg::NodeVisitor& nv);
134 
135 
136  void updateMainSubgraphStateSet();
137 
139 
140  mutable TextureObjectValidList _textureObjectValidList;
141 
143 
144 
145  // overlay subgraph is render to a texture
147 
150 
151  // texture to render to, and to read from.
152  GLenum _texEnvMode;
153  unsigned int _textureUnit;
154  unsigned int _textureSizeHint;
156 
160 
162 
163  struct OverlayData : public osg::Referenced
164  {
165 
166  void setThreadSafeRefUnref(bool threadSafe);
167  void resizeGLObjectBuffers(unsigned int maxSize);
168  void releaseGLObjects(osg::State* state= 0) const;
169 
177 
179 
182  };
183 
184  typedef std::map<osgUtil::CullVisitor*, osg::ref_ptr<OverlayData> > OverlayDataMap;
185 
187  OverlayDataMap _overlayDataMap;
188 
189  OverlayNode::OverlayData* getOverlayData(osgUtil::CullVisitor* cv);
190 
191 };
192 
193 }
194 
195 #endif
#define OSGSIM_EXPORT
Definition: Export.h:38
osg::Camera::RenderTargetImplementation _renderTargetImpl
Definition: OverlayNode.h:161
virtual ~OverlayNode()
Definition: OverlayNode.h:124
This class provides an object-oriented thread mutex interface.
Definition: Mutex.h:31
osg::ref_ptr< osg::Uniform > _y0
Definition: OverlayNode.h:180
double getOverlayBaseHeight() const
Definition: OverlayNode.h:84
osg::Node * getOverlaySubgraph()
Definition: OverlayNode.h:61
osg::ref_ptr< osg::Camera > _camera
Definition: OverlayNode.h:170
osg::ref_ptr< osg::Node > _overlaySubgraph
Definition: OverlayNode.h:146
const osg::Vec4 & getOverlayClearColor() const
Definition: OverlayNode.h:90
#define META_Node(library, name)
Definition: Node.h:59
OverlayTechnique _overlayTechnique
Definition: OverlayNode.h:142
void setContinuousUpdate(bool update)
Definition: OverlayNode.h:71
osg::ref_ptr< osg::TexGenNode > _texgenNode
Definition: OverlayNode.h:173
unsigned int _textureSizeHint
Definition: OverlayNode.h:154
osg::Vec4 _overlayClearColor
Definition: OverlayNode.h:155
osg::ref_ptr< osg::Uniform > _lightingEnabled
Definition: OverlayNode.h:181
osg::ref_ptr< osg::Texture2D > _texture
Definition: OverlayNode.h:174
unsigned int getOverlayTextureUnit() const
Definition: OverlayNode.h:102
OpenThreads::Mutex _overlayDataMapMutex
Definition: OverlayNode.h:186
void setOverlayClearColor(const osg::Vec4 &color)
Definition: OverlayNode.h:87
void setOverlayBaseHeight(double baseHeight)
Definition: OverlayNode.h:81
GLenum getTexEnvMode() const
Definition: OverlayNode.h:96
osg::ref_ptr< osg::Geode > _geode
Definition: OverlayNode.h:176
osg::buffered_value< int > TextureObjectValidList
Definition: OverlayNode.h:138
osg::ref_ptr< osg::StateSet > _mainStateSet
Definition: OverlayNode.h:149
RenderTargetImplementation
Definition: Camera.h:289
osg::ref_ptr< osg::StateSet > _overlayStateSet
Definition: OverlayNode.h:171
osg::ref_ptr< osg::StateSet > _overlayStateSet
Definition: OverlayNode.h:148
osg::ref_ptr< osg::Program > _mainSubgraphProgram
Definition: OverlayNode.h:178
unsigned int _textureUnit
Definition: OverlayNode.h:153
OverlayDataMap _overlayDataMap
Definition: OverlayNode.h:187
std::map< osgUtil::CullVisitor *, osg::ref_ptr< OverlayData > > OverlayDataMap
Definition: OverlayNode.h:184
bool getContinuousUpdate() const
Definition: OverlayNode.h:74
Definition: Node.h:71
TextureObjectValidList _textureObjectValidList
Definition: OverlayNode.h:140
const osg::Node * getOverlaySubgraph() const
Definition: OverlayNode.h:64
unsigned int getOverlayTextureSizeHint() const
Definition: OverlayNode.h:108
OverlayTechnique getOverlayTechnique() const
Definition: OverlayNode.h:52
osg::ref_ptr< osg::StateSet > _mainSubgraphStateSet
Definition: OverlayNode.h:172