CullStack
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_CULLSTACK
#define OSG_CULLSTACK 1
#include <osg/CullingSet>
#include <osg/CullSettings>
#include <osg/Viewport>
#include <osg/fast_back_stack>
#include <osg/Transform>
namespace osg {
class OSG_EXPORT CullStack : public osg::CullSettings
{
public:
CullStack();
CullStack(const CullStack& cs);
~CullStack();
typedef std::vector<ShadowVolumeOccluder> OccluderList;
void reset();
void pushCullingSet();
void popCullingSet();
void setOccluderList(const ShadowVolumeOccluderList& svol) { _occluderList = svol; }
ShadowVolumeOccluderList& getOccluderList() { return _occluderList; }
const ShadowVolumeOccluderList& getOccluderList() const { return _occluderList; }
void pushViewport(osg::Viewport* viewport);
void popViewport();
void pushProjectionMatrix(osg::RefMatrix* matrix);
void popProjectionMatrix();
void pushModelViewMatrix(osg::RefMatrix* matrix, Transform::ReferenceFrame referenceFrame);
void popModelViewMatrix();
inline float getFrustumVolume() { if (_frustumVolume<0.0f) computeFrustumVolume(); return _frustumVolume; }
float pixelSize(const Vec3& v,float radius) const
{
return getCurrentCullingSet().pixelSize(v,radius);
}
float pixelSize(const BoundingSphere& bs) const
{
return pixelSize(bs.center(),bs.radius());
}
float clampedPixelSize(const Vec3& v,float radius) const
{
return getCurrentCullingSet().clampedPixelSize(v,radius);
}
float clampedPixelSize(const BoundingSphere& bs) const
{
return clampedPixelSize(bs.center(),bs.radius());
}
inline void disableAndPushOccludersCurrentMask(NodePath& nodePath)
{
getCurrentCullingSet().disableAndPushOccludersCurrentMask(nodePath);
}
inline void popOccludersCurrentMask(NodePath& nodePath)
{
getCurrentCullingSet().popOccludersCurrentMask(nodePath);
}
inline bool isCulled(const std::vector<Vec3>& vertices)
{
return getCurrentCullingSet().isCulled(vertices);
}
inline bool isCulled(const BoundingBox& bb)
{
return bb.valid() && getCurrentCullingSet().isCulled(bb);
}
inline bool isCulled(const BoundingSphere& bs)
{
return getCurrentCullingSet().isCulled(bs);
}
inline bool isCulled(const osg::Node& node)
{
if (node.isCullingActive())
{
return getCurrentCullingSet().isCulled(node.getBound());
}
else
{
getCurrentCullingSet().resetCullingMask();
return false;
}
}
inline void pushCurrentMask()
{
getCurrentCullingSet().pushCurrentMask();
}
inline void popCurrentMask()
{
getCurrentCullingSet().popCurrentMask();
}
typedef std::vector< CullingSet > CullingStack;
inline CullingStack& getClipSpaceCullingStack() { return _clipspaceCullingStack; }
inline CullingStack& getProjectionCullingStack() { return _projectionCullingStack; }
inline CullingStack& getModelViewCullingStack() { return _modelviewCullingStack; }
inline CullingSet& getCurrentCullingSet() { return *_back_modelviewCullingStack; }
inline const CullingSet& getCurrentCullingSet() const { return *_back_modelviewCullingStack; }
inline osg::Viewport* getViewport();
inline const osg::Viewport* getViewport() const;
inline osg::RefMatrix* getModelViewMatrix();
inline const osg::RefMatrix* getModelViewMatrix() const;
inline osg::RefMatrix* getProjectionMatrix();
inline const osg::RefMatrix* getProjectionMatrix() const;
inline osg::Matrix getWindowMatrix() const;
inline const osg::RefMatrix* getMVPW();
inline const osg::Vec3& getReferenceViewPoint() const { return _referenceViewPoints.back(); }
inline void pushReferenceViewPoint(const osg::Vec3& viewPoint) { _referenceViewPoints.push_back(viewPoint); }
inline void popReferenceViewPoint() { _referenceViewPoints.pop_back(); }
inline const osg::Vec3& getEyeLocal() const { return _eyePointStack.back(); }
inline const osg::Vec3& getViewPointLocal() const { return _viewPointStack.back(); }
inline const osg::Vec3 getUpLocal() const
{
const osg::Matrix& matrix = *_modelviewStack.back();
return osg::Vec3(matrix(0,1),matrix(1,1),matrix(2,1));
}
inline const osg::Vec3 getLookVectorLocal() const
{
const osg::Matrix& matrix = *_modelviewStack.back();
return osg::Vec3(-matrix(0,2),-matrix(1,2),-matrix(2,2));
}
typedef fast_back_stack< ref_ptr<RefMatrix> > MatrixStack;
MatrixStack& getProjectionStack() { return _projectionStack; }
const MatrixStack& getProjectionStack() const { return _projectionStack; }
MatrixStack& getModelViewStack() { return _modelviewStack; }
const MatrixStack& getModelViewStack() const { return _modelviewStack; }
MatrixStack& getMVPWStack() { return _MVPW_Stack; }
const MatrixStack& getMVPWStack() const { return _MVPW_Stack; }
protected:
// base set of shadow volume occluder to use in culling.
ShadowVolumeOccluderList _occluderList;
MatrixStack _projectionStack;
MatrixStack _modelviewStack;
MatrixStack _MVPW_Stack;
typedef fast_back_stack<ref_ptr<Viewport> > ViewportStack;
ViewportStack _viewportStack;
typedef fast_back_stack<Vec3> EyePointStack;
EyePointStack _referenceViewPoints;
EyePointStack _eyePointStack;
EyePointStack _viewPointStack;
CullingStack _clipspaceCullingStack;
CullingStack _projectionCullingStack;
CullingStack _modelviewCullingStack;
unsigned int _index_modelviewCullingStack;
CullingSet* _back_modelviewCullingStack;
void computeFrustumVolume();
float _frustumVolume;
unsigned int _bbCornerNear;
unsigned int _bbCornerFar;
ref_ptr<osg::RefMatrix> _identity;
typedef std::vector< osg::ref_ptr<osg::RefMatrix> > MatrixList;
MatrixList _reuseMatrixList;
unsigned int _currentReuseMatrixIndex;
inline osg::RefMatrix* createOrReuseMatrix(const osg::Matrix& value);
};
inline osg::Viewport* CullStack::getViewport()
{
return _viewportStack.empty() ? 0 : _viewportStack.back().get();
}
inline const osg::Viewport* CullStack::getViewport() const
{
return _viewportStack.empty() ? 0 : _viewportStack.back().get();
}
inline osg::RefMatrix* CullStack::getModelViewMatrix()
{
return _modelviewStack.empty() ? _identity.get() : _modelviewStack.back().get();
}
inline const osg::RefMatrix* CullStack::getModelViewMatrix() const
{
return _modelviewStack.empty() ? _identity.get() : _modelviewStack.back().get();
}
inline osg::RefMatrix* CullStack::getProjectionMatrix()
{
return _projectionStack.empty() ? _identity.get() : _projectionStack.back().get();
}
inline const osg::RefMatrix* CullStack::getProjectionMatrix() const
{
return _projectionStack.empty() ? _identity.get() : _projectionStack.back().get();
}
inline osg::Matrix CullStack::getWindowMatrix() const
{
if (!_viewportStack.empty())
{
osg::Viewport* viewport = _viewportStack.back().get();
return viewport->computeWindowMatrix();
}
else
{
return *_identity;
}
}
inline const osg::RefMatrix* CullStack::getMVPW()
{
if (!_MVPW_Stack.empty())
{
if (!_MVPW_Stack.back())
{
_MVPW_Stack.back() = createOrReuseMatrix(*getModelViewMatrix());
(*_MVPW_Stack.back()) *= *(getProjectionMatrix());
(*_MVPW_Stack.back()) *= getWindowMatrix();
}
return _MVPW_Stack.back().get();
}
else
{
return _identity.get();
}
}
inline RefMatrix* CullStack::createOrReuseMatrix(const osg::Matrix& value)
{
// skip of any already reused matrix.
while (_currentReuseMatrixIndex<_reuseMatrixList.size() &&
_reuseMatrixList[_currentReuseMatrixIndex]->referenceCount()>1)
{
++_currentReuseMatrixIndex;
}
// if still within list, element must be singularly referenced
// there return it to be reused.
if (_currentReuseMatrixIndex<_reuseMatrixList.size())
{
RefMatrix* matrix = _reuseMatrixList[_currentReuseMatrixIndex++].get();
matrix->set(value);
return matrix;
}
// otherwise need to create new matrix.
osg::RefMatrix* matrix = new RefMatrix(value);
_reuseMatrixList.push_back(matrix);
++_currentReuseMatrixIndex;
return matrix;
}
} // end of namespace
#endif
CullSettings
CullingSet
Transform
Viewport
osg::BoundingBoxImpl::valid
bool valid() const
Definition BoundingBox:86
osg::BoundingSphereImpl::center
vec_type & center()
Definition BoundingSphere:83
osg::BoundingSphereImpl::radius
value_type & radius()
Definition BoundingSphere:89
osg::CullSettings
Definition CullSettings:28
osg::CullStack::pushCurrentMask
void pushCurrentMask()
Definition CullStack:123
osg::CullStack::_modelviewStack
MatrixStack _modelviewStack
Definition CullStack:196
osg::CullStack::getModelViewStack
MatrixStack & getModelViewStack()
Definition CullStack:182
osg::CullStack::getMVPW
const osg::RefMatrix * getMVPW()
Definition CullStack:274
osg::CullStack::getViewPointLocal
const osg::Vec3 & getViewPointLocal() const
Definition CullStack:163
osg::CullStack::getOccluderList
const ShadowVolumeOccluderList & getOccluderList() const
Definition CullStack:47
osg::CullStack::MatrixStack
fast_back_stack< ref_ptr< RefMatrix > > MatrixStack
Definition CullStack:177
osg::CullStack::getUpLocal
const osg::Vec3 getUpLocal() const
Definition CullStack:165
osg::CullStack::ViewportStack
fast_back_stack< ref_ptr< Viewport > > ViewportStack
Definition CullStack:199
osg::CullStack::pushProjectionMatrix
void pushProjectionMatrix(osg::RefMatrix *matrix)
osg::CullStack::reset
void reset()
osg::CullStack::getProjectionStack
MatrixStack & getProjectionStack()
Definition CullStack:179
osg::CullStack::clampedPixelSize
float clampedPixelSize(const Vec3 &v, float radius) const
Definition CullStack:74
osg::CullStack::_reuseMatrixList
MatrixList _reuseMatrixList
Definition CullStack:223
osg::CullStack::_currentReuseMatrixIndex
unsigned int _currentReuseMatrixIndex
Definition CullStack:224
osg::CullStack::getLookVectorLocal
const osg::Vec3 getLookVectorLocal() const
Definition CullStack:171
osg::CullStack::computeFrustumVolume
void computeFrustumVolume()
osg::CullStack::getViewport
osg::Viewport * getViewport()
Definition CullStack:231
osg::CullStack::popProjectionMatrix
void popProjectionMatrix()
osg::CullStack::_eyePointStack
EyePointStack _eyePointStack
Definition CullStack:204
osg::CullStack::OccluderList
std::vector< ShadowVolumeOccluder > OccluderList
Definition CullStack:38
osg::CullStack::getModelViewMatrix
osg::RefMatrix * getModelViewMatrix()
Definition CullStack:241
osg::CullStack::_clipspaceCullingStack
CullingStack _clipspaceCullingStack
Definition CullStack:207
osg::CullStack::clampedPixelSize
float clampedPixelSize(const BoundingSphere &bs) const
Definition CullStack:80
osg::CullStack::getWindowMatrix
osg::Matrix getWindowMatrix() const
Definition CullStack:261
osg::CullStack::CullStack
CullStack(const CullStack &cs)
osg::CullStack::getCurrentCullingSet
CullingSet & getCurrentCullingSet()
Definition CullStack:142
osg::CullStack::getClipSpaceCullingStack
CullingStack & getClipSpaceCullingStack()
Definition CullStack:136
osg::CullStack::pushReferenceViewPoint
void pushReferenceViewPoint(const osg::Vec3 &viewPoint)
Definition CullStack:158
osg::CullStack::_projectionStack
MatrixStack _projectionStack
Definition CullStack:194
osg::CullStack::getOccluderList
ShadowVolumeOccluderList & getOccluderList()
Definition CullStack:46
osg::CullStack::getFrustumVolume
float getFrustumVolume()
Definition CullStack:58
osg::CullStack::_referenceViewPoints
EyePointStack _referenceViewPoints
Definition CullStack:203
osg::CullStack::_viewportStack
ViewportStack _viewportStack
Definition CullStack:200
osg::CullStack::getReferenceViewPoint
const osg::Vec3 & getReferenceViewPoint() const
Definition CullStack:157
osg::CullStack::createOrReuseMatrix
osg::RefMatrix * createOrReuseMatrix(const osg::Matrix &value)
Definition CullStack:292
osg::CullStack::_bbCornerNear
unsigned int _bbCornerNear
Definition CullStack:217
osg::CullStack::popModelViewMatrix
void popModelViewMatrix()
osg::CullStack::getProjectionCullingStack
CullingStack & getProjectionCullingStack()
Definition CullStack:138
osg::CullStack::getMVPWStack
const MatrixStack & getMVPWStack() const
Definition CullStack:186
osg::CullStack::MatrixList
std::vector< osg::ref_ptr< osg::RefMatrix > > MatrixList
Definition CullStack:222
osg::CullStack::getModelViewStack
const MatrixStack & getModelViewStack() const
Definition CullStack:183
osg::CullStack::isCulled
bool isCulled(const std::vector< Vec3 > &vertices)
Definition CullStack:95
osg::CullStack::popViewport
void popViewport()
osg::CullStack::getMVPWStack
MatrixStack & getMVPWStack()
Definition CullStack:185
osg::CullStack::_occluderList
ShadowVolumeOccluderList _occluderList
Definition CullStack:191
osg::CullStack::pixelSize
float pixelSize(const BoundingSphere &bs) const
Definition CullStack:68
osg::CullStack::_identity
ref_ptr< osg::RefMatrix > _identity
Definition CullStack:220
osg::CullStack::_index_modelviewCullingStack
unsigned int _index_modelviewCullingStack
Definition CullStack:211
osg::CullStack::disableAndPushOccludersCurrentMask
void disableAndPushOccludersCurrentMask(NodePath &nodePath)
Definition CullStack:85
osg::CullStack::~CullStack
~CullStack()
osg::CullStack::_MVPW_Stack
MatrixStack _MVPW_Stack
Definition CullStack:197
osg::CullStack::popOccludersCurrentMask
void popOccludersCurrentMask(NodePath &nodePath)
Definition CullStack:90
osg::CullStack::setOccluderList
void setOccluderList(const ShadowVolumeOccluderList &svol)
Definition CullStack:45
osg::CullStack::pushCullingSet
void pushCullingSet()
osg::CullStack::_projectionCullingStack
CullingStack _projectionCullingStack
Definition CullStack:208
osg::CullStack::_bbCornerFar
unsigned int _bbCornerFar
Definition CullStack:218
osg::CullStack::_frustumVolume
float _frustumVolume
Definition CullStack:215
osg::CullStack::_viewPointStack
EyePointStack _viewPointStack
Definition CullStack:205
osg::CullStack::getCurrentCullingSet
const CullingSet & getCurrentCullingSet() const
Definition CullStack:143
osg::CullStack::popCurrentMask
void popCurrentMask()
Definition CullStack:128
osg::CullStack::getProjectionMatrix
osg::RefMatrix * getProjectionMatrix()
Definition CullStack:251
osg::CullStack::pushModelViewMatrix
void pushModelViewMatrix(osg::RefMatrix *matrix, Transform::ReferenceFrame referenceFrame)
osg::CullStack::isCulled
bool isCulled(const BoundingSphere &bs)
Definition CullStack:105
osg::CullStack::isCulled
bool isCulled(const BoundingBox &bb)
Definition CullStack:100
osg::CullStack::EyePointStack
fast_back_stack< Vec3 > EyePointStack
Definition CullStack:202
osg::CullStack::isCulled
bool isCulled(const osg::Node &node)
Definition CullStack:110
osg::CullStack::getModelViewCullingStack
CullingStack & getModelViewCullingStack()
Definition CullStack:140
osg::CullStack::pixelSize
float pixelSize(const Vec3 &v, float radius) const
Definition CullStack:62
osg::CullStack::pushViewport
void pushViewport(osg::Viewport *viewport)
osg::CullStack::popReferenceViewPoint
void popReferenceViewPoint()
Definition CullStack:159
osg::CullStack::getEyeLocal
const osg::Vec3 & getEyeLocal() const
Definition CullStack:161
osg::CullStack::CullingStack
std::vector< CullingSet > CullingStack
Definition CullStack:134
osg::CullStack::_back_modelviewCullingStack
CullingSet * _back_modelviewCullingStack
Definition CullStack:212
osg::CullStack::getProjectionStack
const MatrixStack & getProjectionStack() const
Definition CullStack:180
osg::CullStack::popCullingSet
void popCullingSet()
osg::CullStack::_modelviewCullingStack
CullingStack _modelviewCullingStack
Definition CullStack:210
osg::CullStack::CullStack
CullStack()
osg::CullingSet
Definition CullingSet:30
osg::Matrixd::set
void set(const Matrixd &rhs)
Definition Matrixd:71
osg::Node
Definition Node:72
osg::Node::isCullingActive
bool isCullingActive() const
Definition Node:337
osg::Node::getBound
const BoundingSphere & getBound() const
Definition Node:425
osg::Transform::ReferenceFrame
ReferenceFrame
Definition Transform:98
osg::Viewport
Definition Viewport:24
osg::Viewport::computeWindowMatrix
const osg::Matrix computeWindowMatrix() const
Definition Viewport:129
osg::fast_back_stack
Definition fast_back_stack:31
osg::ref_ptr
Definition ref_ptr:32
fast_back_stack
osg
Definition AlphaFunc:19
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::BoundingBox
BoundingBoxd BoundingBox
Definition BoundingBox:257
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Matrix
Matrixd Matrix
Definition Matrix:27
osg::NodePath
std::vector< Node * > NodePath
Definition Node:47
osg::ShadowVolumeOccluderList
std::vector< ShadowVolumeOccluder > ShadowVolumeOccluderList
Definition ShadowVolumeOccluder:125
osg::RefMatrix
RefMatrixd RefMatrix
Definition Matrix:28
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39