From 4192ef796bc7e35ad534cf2e1a21034a8cee01aa Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 12 Oct 2004 09:54:03 +0000 Subject: [PATCH] Added CullingSettngs::s/getInheritanceMask() and inheritCullSettings(,) method. --- include/osg/CullSettings | 40 ++++++++++++++++++++++++++++-- src/osg/CullSettings.cpp | 29 ++++++++++++---------- src/osgProducer/OsgCameraGroup.cpp | 2 +- src/osgUtil/SceneView.cpp | 4 +-- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/include/osg/CullSettings b/include/osg/CullSettings index ab0d576a6..d712ff5f3 100644 --- a/include/osg/CullSettings +++ b/include/osg/CullSettings @@ -51,10 +51,45 @@ class SG_EXPORT CullSettings return *this; } - void setCullSettings(const CullSettings& settings); - + void setDefaults(); + + enum VariablesMask + { + COMPUTE_NEAR_FAR_MODE = 0x0001, + CULLING_MODE = 0x0002, + LOD_SCALE = 0x0004, + SMALL_FEATURE_CULLING_PIXEL_SIZE = 0x0008, + CLAMP_PROJECTION_MATRIX_CALLBACK = 0x0010, + NEAR_FAR_RATIO = 0x0020, + IMPOSTOR_ACTIVE = 0x0040, + DEPTH_SORT_IMPOSTOR_SPRITES = 0x0080, + IMPOSTOR_PIXEL_ERROR_THRESHOLD = 0x0100, + NUM_FRAMES_TO_KEEP_IMPOSTORS_SPRITES = 0x0200, + CULL_MASK = 0x0400, + CULL_MASK_LEFT = 0x0800, + CULL_MASK_RIGHT = 0x1000, + + NO_VARIABLES = 0x0000, + ALL_VARIABLES = 0xFFFF + }; + + /** Set the inheritance mask used in inheritCullSettings to control which variables get overritten by the passed in CullSettings object.*/ + void setInheritanceMask(unsigned int mask) { _inheritanceMask = mask; } + + /** Get the inheritance mask used in inheritCullSettings to control which variables get overritten by the passed in CullSettings object.*/ + unsigned int getInheritanceMask() const { return _inheritanceMask; } + + /** Set the local cull settings values from specified CullSettings object.*/ + void setCullSettings(const CullSettings& settings) { inheritCullSettings(settings, ALL_VARIABLES); } + + /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ + void inheritCullSettings(const CullSettings& settings) { inheritCullSettings(settings, _inheritanceMask); } + + /** Inherit the local cull settings variable from specified CullSettings object, according to the inheritance mask.*/ + void inheritCullSettings(const CullSettings& settings, unsigned int inheritanceMask); + /** read the environmental variables.*/ void readEnvironmentalVariables(); @@ -181,6 +216,7 @@ class SG_EXPORT CullSettings protected: + unsigned int _inheritanceMask; ComputeNearFarMode _computeNearFar; CullingMode _cullingMode; diff --git a/src/osg/CullSettings.cpp b/src/osg/CullSettings.cpp index aab818c87..87d3a821d 100644 --- a/src/osg/CullSettings.cpp +++ b/src/osg/CullSettings.cpp @@ -26,6 +26,7 @@ CullSettings::CullSettings(const CullSettings& cs) void CullSettings::setDefaults() { + _inheritanceMask = ALL_VARIABLES; _cullingMode = DEFAULT_CULLING; _LODScale = 1.0f; _smallFeatureCullingPixelSize = 2.0f; @@ -45,22 +46,24 @@ void CullSettings::setDefaults() //_nearFarRatio = 0.00005f; } -void CullSettings::setCullSettings(const CullSettings& settings) +void CullSettings::inheritCullSettings(const CullSettings& settings, unsigned int inheritanceMask) { - _computeNearFar = settings._computeNearFar; - _nearFarRatio = settings._nearFarRatio; - _impostorActive = settings._impostorActive; - _depthSortImpostorSprites = settings._depthSortImpostorSprites; - _impostorPixelErrorThreshold = settings._impostorPixelErrorThreshold; - _numFramesToKeepImpostorSprites = settings._numFramesToKeepImpostorSprites; - _cullMask = settings._cullMask; - _cullMaskLeft = settings._cullMaskLeft; - _cullMaskRight = settings._cullMaskRight; - _cullingMode = settings._cullingMode; - _LODScale = settings._LODScale; - _smallFeatureCullingPixelSize = settings._smallFeatureCullingPixelSize; + if (inheritanceMask & COMPUTE_NEAR_FAR_MODE) _computeNearFar = settings._computeNearFar; + if (inheritanceMask & NEAR_FAR_RATIO) _nearFarRatio = settings._nearFarRatio; + if (inheritanceMask & IMPOSTOR_ACTIVE) _impostorActive = settings._impostorActive; + if (inheritanceMask & DEPTH_SORT_IMPOSTOR_SPRITES) _depthSortImpostorSprites = settings._depthSortImpostorSprites; + if (inheritanceMask & IMPOSTOR_PIXEL_ERROR_THRESHOLD) _impostorPixelErrorThreshold = settings._impostorPixelErrorThreshold; + if (inheritanceMask & NUM_FRAMES_TO_KEEP_IMPOSTORS_SPRITES) _numFramesToKeepImpostorSprites = settings._numFramesToKeepImpostorSprites; + if (inheritanceMask & CULL_MASK) _cullMask = settings._cullMask; + if (inheritanceMask & CULL_MASK_LEFT) _cullMaskLeft = settings._cullMaskLeft; + if (inheritanceMask & CULL_MASK_RIGHT) _cullMaskRight = settings._cullMaskRight; + if (inheritanceMask & CULLING_MODE) _cullingMode = settings._cullingMode; + if (inheritanceMask & LOD_SCALE) _LODScale = settings._LODScale; + if (inheritanceMask & SMALL_FEATURE_CULLING_PIXEL_SIZE) _smallFeatureCullingPixelSize = settings._smallFeatureCullingPixelSize; + if (inheritanceMask & CLAMP_PROJECTION_MATRIX_CALLBACK) _clampProjectionMatrixCallback = settings._clampProjectionMatrixCallback; } + static ApplicationUsageProxy ApplicationUsageProxyCullSettings_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_COMPUTE_NEAR_FAR_MODE ","DO_NOT_COMPUTE_NEAR_FAR | COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES | COMPUTE_NEAR_FAR_USING_PRIMITIVES"); static ApplicationUsageProxy ApplicationUsageProxyCullSettings_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_NEAR_FAR_RATIO ","Set the ratio between near and far planes - must greater than 0.0 but less than 1.0."); diff --git a/src/osgProducer/OsgCameraGroup.cpp b/src/osgProducer/OsgCameraGroup.cpp index acf0e1e26..db29adbc8 100644 --- a/src/osgProducer/OsgCameraGroup.cpp +++ b/src/osgProducer/OsgCameraGroup.cpp @@ -618,7 +618,7 @@ void OsgCameraGroup::frame() itr != _shvec.end(); ++itr) { - (*itr)->getSceneView()->setCullSettings(_cullSettings); + (*itr)->getSceneView()->inheritCullSettings(_cullSettings); } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index da143747f..644636cbb 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -483,7 +483,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod if (!_collectOccludersVisistor) _collectOccludersVisistor = new osg::CollectOccludersVisitor; - _collectOccludersVisistor->setCullSettings(*this); + _collectOccludersVisistor->inheritCullSettings(*this); _collectOccludersVisistor->reset(); @@ -528,7 +528,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber()); } - cullVisitor->setCullSettings(*this); + cullVisitor->inheritCullSettings(*this); cullVisitor->setClearNode(NULL); // reset earth sky on each frame.