OpenSceneGraph 3.6.5
CullStack
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_CULLSTACK
15#define OSG_CULLSTACK 1
16
17#include <osg/CullingSet>
18#include <osg/CullSettings>
19#include <osg/Viewport>
20#include <osg/fast_back_stack>
21#include <osg/Transform>
22
23namespace osg {
24
28{
29
30 public:
31
32
34 CullStack(const CullStack& cs);
35
37
38 typedef std::vector<ShadowVolumeOccluder> OccluderList;
39
40 void reset();
41
44
48
49 void pushViewport(osg::Viewport* viewport);
51
54
57
59
60
62 float pixelSize(const Vec3& v,float radius) const
63 {
64 return getCurrentCullingSet().pixelSize(v,radius);
65 }
66
68 float pixelSize(const BoundingSphere& bs) const
69 {
70 return pixelSize(bs.center(),bs.radius());
71 }
72
74 float clampedPixelSize(const Vec3& v,float radius) const
75 {
76 return getCurrentCullingSet().clampedPixelSize(v,radius);
77 }
78
80 float clampedPixelSize(const BoundingSphere& bs) const
81 {
82 return clampedPixelSize(bs.center(),bs.radius());
83 }
84
86 {
87 getCurrentCullingSet().disableAndPushOccludersCurrentMask(nodePath);
88 }
89
90 inline void popOccludersCurrentMask(NodePath& nodePath)
91 {
92 getCurrentCullingSet().popOccludersCurrentMask(nodePath);
93 }
94
95 inline bool isCulled(const std::vector<Vec3>& vertices)
96 {
97 return getCurrentCullingSet().isCulled(vertices);
98 }
99
100 inline bool isCulled(const BoundingBox& bb)
101 {
102 return bb.valid() && getCurrentCullingSet().isCulled(bb);
103 }
104
105 inline bool isCulled(const BoundingSphere& bs)
106 {
107 return getCurrentCullingSet().isCulled(bs);
108 }
109
110 inline bool isCulled(const osg::Node& node)
111 {
112 if (node.isCullingActive())
113 {
114 return getCurrentCullingSet().isCulled(node.getBound());
115 }
116 else
117 {
118 getCurrentCullingSet().resetCullingMask();
119 return false;
120 }
121 }
122
123 inline void pushCurrentMask()
124 {
125 getCurrentCullingSet().pushCurrentMask();
126 }
127
128 inline void popCurrentMask()
129 {
130 getCurrentCullingSet().popCurrentMask();
131 }
132
133
134 typedef std::vector< CullingSet > CullingStack;
135
137
139
141
144
145 inline osg::Viewport* getViewport();
146 inline const osg::Viewport* getViewport() const;
147
148 inline osg::RefMatrix* getModelViewMatrix();
149 inline const osg::RefMatrix* getModelViewMatrix() const;
150
151 inline osg::RefMatrix* getProjectionMatrix();
152 inline const osg::RefMatrix* getProjectionMatrix() const;
153
154 inline osg::Matrix getWindowMatrix() const;
155 inline const osg::RefMatrix* getMVPW();
156
157 inline const osg::Vec3& getReferenceViewPoint() const { return _referenceViewPoints.back(); }
158 inline void pushReferenceViewPoint(const osg::Vec3& viewPoint) { _referenceViewPoints.push_back(viewPoint); }
159 inline void popReferenceViewPoint() { _referenceViewPoints.pop_back(); }
160
161 inline const osg::Vec3& getEyeLocal() const { return _eyePointStack.back(); }
162
163 inline const osg::Vec3& getViewPointLocal() const { return _viewPointStack.back(); }
164
165 inline const osg::Vec3 getUpLocal() const
166 {
167 const osg::Matrix& matrix = *_modelviewStack.back();
168 return osg::Vec3(matrix(0,1),matrix(1,1),matrix(2,1));
169 }
170
171 inline const osg::Vec3 getLookVectorLocal() const
172 {
173 const osg::Matrix& matrix = *_modelviewStack.back();
174 return osg::Vec3(-matrix(0,2),-matrix(1,2),-matrix(2,2));
175 }
176
178
181
184
186 const MatrixStack& getMVPWStack() const { return _MVPW_Stack; }
187
188 protected:
189
190 // base set of shadow volume occluder to use in culling.
192
193
195
198
201
206
209
213
216
217 unsigned int _bbCornerNear;
218 unsigned int _bbCornerFar;
219
221
222 typedef std::vector< osg::ref_ptr<osg::RefMatrix> > MatrixList;
225
226 inline osg::RefMatrix* createOrReuseMatrix(const osg::Matrix& value);
227
228
229};
230
232{
233 return _viewportStack.empty() ? 0 : _viewportStack.back().get();
234}
235
237{
238 return _viewportStack.empty() ? 0 : _viewportStack.back().get();
239}
240
242{
243 return _modelviewStack.empty() ? _identity.get() : _modelviewStack.back().get();
244}
245
247{
248 return _modelviewStack.empty() ? _identity.get() : _modelviewStack.back().get();
249}
250
252{
253 return _projectionStack.empty() ? _identity.get() : _projectionStack.back().get();
254}
255
257{
258 return _projectionStack.empty() ? _identity.get() : _projectionStack.back().get();
259}
260
262{
263 if (!_viewportStack.empty())
264 {
265 osg::Viewport* viewport = _viewportStack.back().get();
266 return viewport->computeWindowMatrix();
267 }
268 else
269 {
270 return *_identity;
271 }
272}
273
275{
276 if (!_MVPW_Stack.empty())
277 {
278 if (!_MVPW_Stack.back())
279 {
281 (*_MVPW_Stack.back()) *= *(getProjectionMatrix());
282 (*_MVPW_Stack.back()) *= getWindowMatrix();
283 }
284 return _MVPW_Stack.back().get();
285 }
286 else
287 {
288 return _identity.get();
289 }
290}
291
293{
294 // skip of any already reused matrix.
296 _reuseMatrixList[_currentReuseMatrixIndex]->referenceCount()>1)
297 {
299 }
300
301 // if still within list, element must be singularly referenced
302 // there return it to be reused.
304 {
306 matrix->set(value);
307 return matrix;
308 }
309
310 // otherwise need to create new matrix.
311 osg::RefMatrix* matrix = new RefMatrix(value);
312 _reuseMatrixList.push_back(matrix);
314 return matrix;
315}
316
317} // end of namespace
318
319#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec3f Vec3
Definition Vec3:21
BoundingBoxd BoundingBox
Definition BoundingBox:257
BoundingSphered BoundingSphere
Definition BoundingSphere:308
Matrixd Matrix
Definition Matrix:27
std::vector< Node * > NodePath
A vector of Nodes pointers which is used to describe the path from a root node to a descendant.
Definition Node:47
std::vector< ShadowVolumeOccluder > ShadowVolumeOccluderList
A list of ShadowVolumeOccluder, used by CollectOccluderVisitor and CullVistor's.
Definition ShadowVolumeOccluder:125
RefMatrixd RefMatrix
Definition Matrix:28
vec_type & center()
Returns the center of the bounding sphere.
Definition BoundingSphere:77
value_type & radius()
Returns the radius of the bounding sphere.
Definition BoundingSphere:83
bool valid() const
Returns true if the bounding box extents are valid, false otherwise.
Definition BoundingBox:86
A CullingSet class which contains a frustum and a list of occluders.
Definition CullingSet:30
Definition CullSettings:28
void pushCurrentMask()
Definition CullStack:123
MatrixStack _modelviewStack
Definition CullStack:196
MatrixStack & getModelViewStack()
Definition CullStack:182
const osg::RefMatrix * getMVPW()
Definition CullStack:274
const osg::Vec3 & getViewPointLocal() const
Definition CullStack:163
const ShadowVolumeOccluderList & getOccluderList() const
Definition CullStack:47
fast_back_stack< ref_ptr< RefMatrix > > MatrixStack
Definition CullStack:177
const osg::Vec3 getUpLocal() const
Definition CullStack:165
fast_back_stack< ref_ptr< Viewport > > ViewportStack
Definition CullStack:199
void pushProjectionMatrix(osg::RefMatrix *matrix)
MatrixStack & getProjectionStack()
Definition CullStack:179
float clampedPixelSize(const Vec3 &v, float radius) const
Compute the pixel size of an object at position v, with specified radius.
Definition CullStack:74
MatrixList _reuseMatrixList
Definition CullStack:223
unsigned int _currentReuseMatrixIndex
Definition CullStack:224
const osg::Vec3 getLookVectorLocal() const
Definition CullStack:171
void computeFrustumVolume()
osg::Viewport * getViewport()
Definition CullStack:231
void popProjectionMatrix()
EyePointStack _eyePointStack
Definition CullStack:204
std::vector< ShadowVolumeOccluder > OccluderList
Definition CullStack:38
osg::RefMatrix * getModelViewMatrix()
Definition CullStack:241
CullingStack _clipspaceCullingStack
Definition CullStack:207
float clampedPixelSize(const BoundingSphere &bs) const
Compute the pixel size of the bounding sphere.
Definition CullStack:80
osg::Matrix getWindowMatrix() const
Definition CullStack:261
CullStack(const CullStack &cs)
CullingSet & getCurrentCullingSet()
Definition CullStack:142
CullingStack & getClipSpaceCullingStack()
Definition CullStack:136
void pushReferenceViewPoint(const osg::Vec3 &viewPoint)
Definition CullStack:158
MatrixStack _projectionStack
Definition CullStack:194
ShadowVolumeOccluderList & getOccluderList()
Definition CullStack:46
float getFrustumVolume()
Definition CullStack:58
EyePointStack _referenceViewPoints
Definition CullStack:203
ViewportStack _viewportStack
Definition CullStack:200
const osg::Vec3 & getReferenceViewPoint() const
Definition CullStack:157
osg::RefMatrix * createOrReuseMatrix(const osg::Matrix &value)
Definition CullStack:292
unsigned int _bbCornerNear
Definition CullStack:217
void popModelViewMatrix()
CullingStack & getProjectionCullingStack()
Definition CullStack:138
const MatrixStack & getMVPWStack() const
Definition CullStack:186
std::vector< osg::ref_ptr< osg::RefMatrix > > MatrixList
Definition CullStack:222
const MatrixStack & getModelViewStack() const
Definition CullStack:183
bool isCulled(const std::vector< Vec3 > &vertices)
Definition CullStack:95
void popViewport()
MatrixStack & getMVPWStack()
Definition CullStack:185
ShadowVolumeOccluderList _occluderList
Definition CullStack:191
float pixelSize(const BoundingSphere &bs) const
Compute the pixel size of the bounding sphere.
Definition CullStack:68
ref_ptr< osg::RefMatrix > _identity
Definition CullStack:220
unsigned int _index_modelviewCullingStack
Definition CullStack:211
void disableAndPushOccludersCurrentMask(NodePath &nodePath)
Definition CullStack:85
MatrixStack _MVPW_Stack
Definition CullStack:197
void popOccludersCurrentMask(NodePath &nodePath)
Definition CullStack:90
void setOccluderList(const ShadowVolumeOccluderList &svol)
Definition CullStack:45
void pushCullingSet()
CullingStack _projectionCullingStack
Definition CullStack:208
unsigned int _bbCornerFar
Definition CullStack:218
float _frustumVolume
Definition CullStack:215
EyePointStack _viewPointStack
Definition CullStack:205
const CullingSet & getCurrentCullingSet() const
Definition CullStack:143
void popCurrentMask()
Definition CullStack:128
osg::RefMatrix * getProjectionMatrix()
Definition CullStack:251
void pushModelViewMatrix(osg::RefMatrix *matrix, Transform::ReferenceFrame referenceFrame)
bool isCulled(const BoundingSphere &bs)
Definition CullStack:105
bool isCulled(const BoundingBox &bb)
Definition CullStack:100
fast_back_stack< Vec3 > EyePointStack
Definition CullStack:202
bool isCulled(const osg::Node &node)
Definition CullStack:110
CullingStack & getModelViewCullingStack()
Definition CullStack:140
float pixelSize(const Vec3 &v, float radius) const
Compute the pixel size of an object at position v, with specified radius.
Definition CullStack:62
void pushViewport(osg::Viewport *viewport)
void popReferenceViewPoint()
Definition CullStack:159
const osg::Vec3 & getEyeLocal() const
Definition CullStack:161
std::vector< CullingSet > CullingStack
Definition CullStack:134
CullingSet * _back_modelviewCullingStack
Definition CullStack:212
const MatrixStack & getProjectionStack() const
Definition CullStack:180
void popCullingSet()
CullingStack _modelviewCullingStack
Definition CullStack:210
Simple stack implementation that keeps the back() cached locally for fast access rather than at the b...
Definition fast_back_stack:31
void set(const Matrixd &rhs)
Definition Matrixd:71
Base class for all internal nodes in the scene graph.
Definition Node:72
bool isCullingActive() const
Return true if this node can be culled by view frustum, occlusion or small feature culling during the...
Definition Node:337
const BoundingSphere & getBound() const
Definition Node:425
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
ReferenceFrame
Definition Transform:98
Encapsulate OpenGL glViewport.
Definition Viewport:24
const osg::Matrix computeWindowMatrix() const
Compute the Window Matrix which takes projected coords into Window coordinates.
Definition Viewport:129
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.