Removed CullViewState from the distribution, moved CullViewState::CullingMode
into CullVisitor, and then removed all references to CullViewState from other parts of the scene graph.
This commit is contained in:
parent
7880fd3354
commit
f0e7e8e48b
@ -101,10 +101,6 @@ SOURCE=..\..\src\osgUtil\CameraManipulator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\CullViewState.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\CullVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -217,10 +213,6 @@ SOURCE=..\..\Include\osgUtil\CameraManipulator
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\CullViewState
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\CullVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -1,89 +0,0 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGUTIL_CULLVIEWSTATE
|
||||
#define OSGUTIL_CULLVIEWSTATE 1
|
||||
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/BoundingBox>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/ClippingVolume>
|
||||
|
||||
#include <osgUtil/Export>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
/** Container class for encapsulating the viewing state in local
|
||||
coordinates, during the cull traversal.
|
||||
*/
|
||||
class OSGUTIL_EXPORT CullViewState : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
CullViewState();
|
||||
|
||||
osg::ref_ptr<osg::Matrix> _projection;
|
||||
osg::ref_ptr<osg::Matrix> _matrix;
|
||||
osg::ref_ptr<osg::Matrix> _inverse;
|
||||
osg::Vec3 _eyePoint;
|
||||
osg::Vec3 _centerPoint;
|
||||
osg::Vec3 _lookVector;
|
||||
osg::Vec3 _upVector;
|
||||
unsigned int _bbCornerFar;
|
||||
unsigned int _bbCornerNear;
|
||||
float _ratio2;
|
||||
|
||||
osg::ClippingVolume _clippingVolume;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
NO_CULLING = 0x00,
|
||||
FRUSTUM_LEFT_CULLING = 0x01,
|
||||
FRUSTUM_RIGHT_CULLING = 0x02,
|
||||
FRUSTUM_BOTTOM_CULLING = 0x04,
|
||||
FRUSTUM_TOP_CULLING = 0x08,
|
||||
FRUSTUM_NEAR_CULLING = 0x10,
|
||||
FRUSTUM_FAR_CULLING = 0x20,
|
||||
VIEW_FRUSTUM_CULLING = 0x3F,
|
||||
SMALL_FEATURE_CULLING = 0x40,
|
||||
ENABLE_ALL_CULLING = 0x7F
|
||||
};
|
||||
|
||||
typedef unsigned int CullingMode;
|
||||
|
||||
inline bool isCulled(const osg::BoundingSphere& sp,CullingMode& mode) const
|
||||
{
|
||||
if (!sp.isValid()) return true;
|
||||
|
||||
if (!_clippingVolume.contains(sp,mode)) return true;
|
||||
|
||||
if (mode&SMALL_FEATURE_CULLING)
|
||||
{
|
||||
osg::Vec3 delta(sp._center-_eyePoint);
|
||||
if (sp.radius2()<delta.length2()*_ratio2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool isCulled(const osg::BoundingBox& bb,CullingMode mode) const
|
||||
{
|
||||
if (!bb.isValid()) return true;
|
||||
|
||||
return !_clippingVolume.contains(bb,mode);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
~CullViewState();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include <osgUtil/RenderGraph>
|
||||
#include <osgUtil/RenderStage>
|
||||
#include <osgUtil/CullViewState>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@ -39,6 +38,23 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
NO_CULLING = 0x00,
|
||||
FRUSTUM_LEFT_CULLING = 0x01,
|
||||
FRUSTUM_RIGHT_CULLING = 0x02,
|
||||
FRUSTUM_BOTTOM_CULLING = 0x04,
|
||||
FRUSTUM_TOP_CULLING = 0x08,
|
||||
FRUSTUM_NEAR_CULLING = 0x10,
|
||||
FRUSTUM_FAR_CULLING = 0x20,
|
||||
VIEW_FRUSTUM_CULLING = 0x3F,
|
||||
SMALL_FEATURE_CULLING = 0x40,
|
||||
ENABLE_ALL_CULLING = 0x7F
|
||||
};
|
||||
|
||||
typedef unsigned int CullingMode;
|
||||
|
||||
|
||||
CullVisitor();
|
||||
virtual ~CullVisitor();
|
||||
|
||||
@ -105,10 +121,10 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
void setTransparencySortMode(TransparencySortMode tsm) { _tsm = tsm; }
|
||||
|
||||
/** Sets the current CullingMode.*/
|
||||
void setCullingMode(CullViewState::CullingMode mode);
|
||||
void setCullingMode(CullingMode mode);
|
||||
|
||||
/** Returns the current CullingMode.*/
|
||||
CullViewState::CullingMode getCullingMode() const;
|
||||
CullingMode getCullingMode() const;
|
||||
|
||||
|
||||
void pushViewport(osg::Viewport* viewport);
|
||||
@ -216,13 +232,13 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
}
|
||||
|
||||
|
||||
inline bool isCulled(const osg::BoundingSphere& sp,CullViewState::CullingMode& mode) const
|
||||
inline bool isCulled(const osg::BoundingSphere& sp,CullingMode& mode) const
|
||||
{
|
||||
if (!sp.isValid()) return true;
|
||||
|
||||
if (!(_modelviewClippingVolumeStack.back().contains(sp,mode))) return true;
|
||||
|
||||
if (mode&CullViewState::SMALL_FEATURE_CULLING)
|
||||
if (mode&SMALL_FEATURE_CULLING)
|
||||
{
|
||||
const float _ratio2 = 0.002f*0.002f;
|
||||
osg::Vec3 delta(sp._center-getEyeLocal());
|
||||
@ -234,7 +250,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
return false;
|
||||
}
|
||||
|
||||
inline const bool isCulled(const osg::BoundingBox& bb,CullViewState::CullingMode mode) const
|
||||
inline const bool isCulled(const osg::BoundingBox& bb,CullingMode mode) const
|
||||
{
|
||||
if (!bb.isValid()) return true;
|
||||
|
||||
@ -370,7 +386,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
typedef std::vector<osg::Vec3> EyePointStack;
|
||||
EyePointStack _eyePointStack;
|
||||
|
||||
typedef std::vector<CullViewState::CullingMode> CullingModeStack;
|
||||
typedef std::vector<CullingMode> CullingModeStack;
|
||||
CullingModeStack _cullingModeStack;
|
||||
|
||||
unsigned int _bbCornerNear;
|
||||
|
@ -463,7 +463,7 @@ public:
|
||||
if(_hudSceneView.valid())
|
||||
{
|
||||
_hudSceneView->getRenderStage()->setClearMask(0);
|
||||
_hudSceneView->getCullVisitor()->setCullingMode(osgUtil::CullViewState::NO_CULLING);
|
||||
_hudSceneView->getCullVisitor()->setCullingMode(osgUtil::CullVisitor::NO_CULLING);
|
||||
_hudSceneView->setCalcNearFar(false);
|
||||
|
||||
_hudCam = osgNew osg::Camera;
|
||||
|
@ -1017,9 +1017,9 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
||||
|
||||
case 'c' :
|
||||
_smallFeatureCullingActive = !_smallFeatureCullingActive;
|
||||
sceneView->getCullVisitor()->setCullingMode((osgUtil::CullViewState::CullingMode)
|
||||
((_smallFeatureCullingActive ? osgUtil::CullViewState::SMALL_FEATURE_CULLING : osgUtil::CullViewState::NO_CULLING) |
|
||||
(_viewFrustumCullingActive ? osgUtil::CullViewState::VIEW_FRUSTUM_CULLING : osgUtil::CullViewState::NO_CULLING)));
|
||||
sceneView->getCullVisitor()->setCullingMode((osgUtil::CullVisitor::CullingMode)
|
||||
((_smallFeatureCullingActive ? osgUtil::CullVisitor::SMALL_FEATURE_CULLING : osgUtil::CullVisitor::NO_CULLING) |
|
||||
(_viewFrustumCullingActive ? osgUtil::CullVisitor::VIEW_FRUSTUM_CULLING : osgUtil::CullVisitor::NO_CULLING)));
|
||||
if (_smallFeatureCullingActive)
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "Small feature culling switched on "<< std::endl;
|
||||
@ -1040,9 +1040,9 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "View frustum culling switched off "<< std::endl;
|
||||
}
|
||||
sceneView->getCullVisitor()->setCullingMode((osgUtil::CullViewState::CullingMode)
|
||||
((_smallFeatureCullingActive ? osgUtil::CullViewState::SMALL_FEATURE_CULLING : osgUtil::CullViewState::NO_CULLING) |
|
||||
(_viewFrustumCullingActive ? osgUtil::CullViewState::VIEW_FRUSTUM_CULLING : osgUtil::CullViewState::NO_CULLING)));
|
||||
sceneView->getCullVisitor()->setCullingMode((osgUtil::CullVisitor::CullingMode)
|
||||
((_smallFeatureCullingActive ? osgUtil::CullVisitor::SMALL_FEATURE_CULLING : osgUtil::CullVisitor::NO_CULLING) |
|
||||
(_viewFrustumCullingActive ? osgUtil::CullVisitor::VIEW_FRUSTUM_CULLING : osgUtil::CullVisitor::NO_CULLING)));
|
||||
break;
|
||||
|
||||
case 'P' :
|
||||
@ -1065,25 +1065,18 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
||||
|
||||
case 'O' :
|
||||
{
|
||||
osg::Viewport* viewport = sceneView->getViewport();
|
||||
if (viewport)
|
||||
{
|
||||
osg::ref_ptr<osg::Viewport> viewport = osgNew osg::Viewport;
|
||||
viewport->setViewport(_wx,_wy,_ww,_wh);
|
||||
std::string filename("screenshot.bmp");
|
||||
|
||||
std::string filename("screenshot.bmp");
|
||||
glReadBuffer(GL_FRONT);
|
||||
osg::ref_ptr<Image> image = osgNew osg::Image;
|
||||
image->readPixels(viewport->x(),viewport->y(),viewport->width(),viewport->height(),
|
||||
GL_RGB,GL_UNSIGNED_BYTE);
|
||||
|
||||
glReadBuffer(GL_FRONT);
|
||||
osg::ref_ptr<Image> image = osgNew osg::Image;
|
||||
image->readPixels(viewport->x(),viewport->y(),viewport->width(),viewport->height(),
|
||||
GL_RGB,GL_UNSIGNED_BYTE);
|
||||
osgDB::writeImageFile(*image,filename);
|
||||
|
||||
osgDB::writeImageFile(*image,filename);
|
||||
|
||||
osg::notify(osg::NOTICE) << "Saved screen image to `"<<filename<<"`"<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE) << "Cannot create snapshot of screen, no valid viewport attached"<< std::endl;
|
||||
}
|
||||
osg::notify(osg::NOTICE) << "Saved screen image to `"<<filename<<"`"<< std::endl;
|
||||
}
|
||||
break;
|
||||
case 'i' :
|
||||
|
@ -1,33 +0,0 @@
|
||||
|
||||
#include <osg/Transform>
|
||||
#include <osg/Geode>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Billboard>
|
||||
#include <osg/LightSource>
|
||||
#include <osg/Impostor>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osgUtil/CullViewState>
|
||||
|
||||
#include <float.h>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgUtil;
|
||||
|
||||
//#define USE_OLD_CULL
|
||||
|
||||
CullViewState::CullViewState()
|
||||
{
|
||||
_projection = NULL;
|
||||
_matrix = NULL;
|
||||
_inverse = NULL;
|
||||
_ratio2 = 0.002f*0.002f;
|
||||
_bbCornerNear = 8; // note this is an error value, valid range is 0..7
|
||||
_bbCornerFar = 8; // these error values are used to show a unset corner.
|
||||
}
|
||||
|
||||
|
||||
CullViewState::~CullViewState()
|
||||
{
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ CullVisitor::CullVisitor()
|
||||
// is a least this one value on the stack, therefore they never
|
||||
// check whether the stack is empty. This shouldn't be a problem
|
||||
// unless there is bug somewhere...
|
||||
_cullingModeStack.push_back(CullViewState::ENABLE_ALL_CULLING);
|
||||
_cullingModeStack.push_back(ENABLE_ALL_CULLING);
|
||||
|
||||
|
||||
//_tsm = LOOK_VECTOR_DISTANCE;
|
||||
@ -335,20 +335,20 @@ void CullVisitor::updateCalculatedNearFar(const osg::Vec3& pos)
|
||||
if (d>_computed_zfar) _computed_zfar = d;
|
||||
}
|
||||
|
||||
void CullVisitor::setCullingMode(CullViewState::CullingMode mode)
|
||||
void CullVisitor::setCullingMode(CullingMode mode)
|
||||
{
|
||||
_cullingModeStack.back()=mode;
|
||||
}
|
||||
|
||||
|
||||
CullViewState::CullingMode CullVisitor::getCullingMode() const
|
||||
CullVisitor::CullingMode CullVisitor::getCullingMode() const
|
||||
{
|
||||
return _cullingModeStack.back();
|
||||
}
|
||||
|
||||
void CullVisitor::apply(Node& node)
|
||||
{
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -375,7 +375,7 @@ void CullVisitor::apply(Geode& node)
|
||||
{
|
||||
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -444,7 +444,7 @@ void CullVisitor::apply(Geode& node)
|
||||
void CullVisitor::apply(Billboard& node)
|
||||
{
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -535,7 +535,7 @@ void CullVisitor::apply(LightSource& node)
|
||||
void CullVisitor::apply(Group& node)
|
||||
{
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -560,7 +560,7 @@ void CullVisitor::apply(Group& node)
|
||||
void CullVisitor::apply(Transform& node)
|
||||
{
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -591,7 +591,7 @@ void CullVisitor::apply(Transform& node)
|
||||
void CullVisitor::apply(Projection& node)
|
||||
{
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -639,7 +639,7 @@ void CullVisitor::apply(Switch& node)
|
||||
void CullVisitor::apply(LOD& node)
|
||||
{
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -687,7 +687,7 @@ void CullVisitor::apply(Impostor& node)
|
||||
const BoundingSphere& bs = node.getBound();
|
||||
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
@ -952,7 +952,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
|
||||
|
||||
// switch off the view frustum culling, since we will have
|
||||
// the whole subgraph in view.
|
||||
_cullingModeStack.push_back((_cullingModeStack.back() & ~CullViewState::VIEW_FRUSTUM_CULLING));
|
||||
_cullingModeStack.push_back((_cullingModeStack.back() & ~VIEW_FRUSTUM_CULLING));
|
||||
|
||||
{
|
||||
|
||||
|
@ -5,7 +5,6 @@ include $(TOPDIR)/Make/makedefs
|
||||
CXXFILES = \
|
||||
AppVisitor.cpp\
|
||||
CameraManipulator.cpp\
|
||||
CullViewState.cpp\
|
||||
CullVisitor.cpp\
|
||||
DepthSortedBin.cpp\
|
||||
DisplayListVisitor.cpp\
|
||||
|
Loading…
Reference in New Issue
Block a user