From f0e7e8e48b8b35d7f4383f40b9da42bb8dd23189 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 24 Apr 2002 20:24:10 +0000 Subject: [PATCH] Removed CullViewState from the distribution, moved CullViewState::CullingMode into CullVisitor, and then removed all references to CullViewState from other parts of the scene graph. --- VisualStudio/osgUtil/osgUtil.dsp | 8 --- include/osgUtil/CullViewState | 89 -------------------------------- include/osgUtil/CullVisitor | 30 ++++++++--- src/Demos/osgtext/main.cpp | 2 +- src/osgGLUT/Viewer.cpp | 37 ++++++------- src/osgUtil/CullViewState.cpp | 33 ------------ src/osgUtil/CullVisitor.cpp | 24 ++++----- src/osgUtil/Makefile | 1 - 8 files changed, 51 insertions(+), 173 deletions(-) delete mode 100644 include/osgUtil/CullViewState delete mode 100644 src/osgUtil/CullViewState.cpp diff --git a/VisualStudio/osgUtil/osgUtil.dsp b/VisualStudio/osgUtil/osgUtil.dsp index 808deed85..4971dc048 100755 --- a/VisualStudio/osgUtil/osgUtil.dsp +++ b/VisualStudio/osgUtil/osgUtil.dsp @@ -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 diff --git a/include/osgUtil/CullViewState b/include/osgUtil/CullViewState deleted file mode 100644 index a0defbc76..000000000 --- a/include/osgUtil/CullViewState +++ /dev/null @@ -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 -#include -#include -#include - -#include - -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 _projection; - osg::ref_ptr _matrix; - osg::ref_ptr _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() #include -#include #include #include @@ -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 EyePointStack; EyePointStack _eyePointStack; - typedef std::vector CullingModeStack; + typedef std::vector CullingModeStack; CullingModeStack _cullingModeStack; unsigned int _bbCornerNear; diff --git a/src/Demos/osgtext/main.cpp b/src/Demos/osgtext/main.cpp index 4a9c26d4e..9c2b658a7 100644 --- a/src/Demos/osgtext/main.cpp +++ b/src/Demos/osgtext/main.cpp @@ -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; diff --git a/src/osgGLUT/Viewer.cpp b/src/osgGLUT/Viewer.cpp index 0a61188f6..65e603efc 100644 --- a/src/osgGLUT/Viewer.cpp +++ b/src/osgGLUT/Viewer.cpp @@ -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 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 = 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 = 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 `"< -#include -#include -#include -#include -#include -#include - -#include - -#include - -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() -{ -} - diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 5e9efa22c..f5e67e004 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -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)); { diff --git a/src/osgUtil/Makefile b/src/osgUtil/Makefile index fee2ad37c..63d6e75f0 100644 --- a/src/osgUtil/Makefile +++ b/src/osgUtil/Makefile @@ -5,7 +5,6 @@ include $(TOPDIR)/Make/makedefs CXXFILES = \ AppVisitor.cpp\ CameraManipulator.cpp\ - CullViewState.cpp\ CullVisitor.cpp\ DepthSortedBin.cpp\ DisplayListVisitor.cpp\