Added support for reading environmental varables in CullSettings.

This commit is contained in:
Robert Osfield
2004-05-05 09:16:12 +00:00
parent 7905aa37b7
commit 8bdb68ef97
4 changed files with 99 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
/* -*-c++-*- OpenSceneGraph - setCullSettingsright (C) 1998-2003 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
@@ -19,13 +19,29 @@
namespace osg {
// forward declare
class ArgumentParser;
class ApplicationUsage;
class SG_EXPORT CullSettings
{
public:
CullSettings() { setDefaults(); }
CullSettings()
{
setDefaults();
readEnvironmentalVariables();
}
CullSettings(ArgumentParser& arguments)
{
setDefaults();
readEnvironmentalVariables();
readCommandLine(arguments);
}
CullSettings(const CullSettings& cs);
CullSettings(const CullSettings& cs) { setCullSettings(cs); }
~CullSettings() {}
CullSettings& operator = (const CullSettings& settings)
@@ -35,9 +51,16 @@ class SG_EXPORT CullSettings
return *this;
}
void setDefaults();
void setCullSettings(const CullSettings& settings);
void setDefaults();
/** read the environmental variables.*/
void readEnvironmentalVariables();
/** read the commandline arguments.*/
void readCommandLine(ArgumentParser& arguments);
/** Switch the creation of Impostors on or off.
* Setting active to false forces the CullVisitor to use the Impostor

View File

@@ -54,11 +54,13 @@ class SG_EXPORT DisplaySettings : public osg::Referenced
DisplaySettings& operator = (const DisplaySettings& vs);
void setDisplaySettings(const DisplaySettings& vs);
void merge(const DisplaySettings& vs);
void setDefaults();
/** read the environmental variables.*/
void readEnvironmentalVariables();
/** read the commandline arguments.*/
@@ -166,7 +168,6 @@ class SG_EXPORT DisplaySettings : public osg::Referenced
virtual ~DisplaySettings();
void copy(const DisplaySettings& vs);
DisplayType _displayType;
bool _stereo;

View File

@@ -12,9 +12,18 @@
*/
#include <osg/CullSettings>
#include <osg/ArgumentParser>
#include <osg/ApplicationUsage>
#include <osg/Notify>
using namespace osg;
CullSettings::CullSettings(const CullSettings& cs)
{
setCullSettings(cs);
}
void CullSettings::setDefaults()
{
_cullingMode = DEFAULT_CULLING;
@@ -51,3 +60,60 @@ void CullSettings::setCullSettings(const CullSettings& settings)
_LODScale = settings._LODScale;
_smallFeatureCullingPixelSize = settings._smallFeatureCullingPixelSize;
}
static ApplicationUsageProxy ApplicationUsageProxyCullSettings_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_COMPUTE_NEAR_FAR_MODE <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 <float>","Set the ratio between near and far planes - must greater than 0.0 but less than 1.0.");
void CullSettings::readEnvironmentalVariables()
{
osg::notify(osg::INFO)<<"CullSettings::readEnvironmentalVariables()"<<std::endl;
char *ptr;
if ((ptr = getenv("OSG_COMPUTE_NEAR_FAR_MODE")) != 0)
{
if (strcmp(ptr,"DO_NOT_COMPUTE_NEAR_FAR")==0) _computeNearFar = DO_NOT_COMPUTE_NEAR_FAR;
else if (strcmp(ptr,"COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES")==0) _computeNearFar = COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES;
else if (strcmp(ptr,"COMPUTE_NEAR_FAR_USING_PRIMITIVES")==0) _computeNearFar = COMPUTE_NEAR_FAR_USING_PRIMITIVES;
osg::notify(osg::INFO)<<"Set compute near far mode to "<<_computeNearFar<<std::endl;
}
if ((ptr = getenv("OSG_NEAR_FAR_RATIO")) != 0)
{
_nearFarRatio = atof(ptr);
osg::notify(osg::INFO)<<"Set near/far ratio to "<<_nearFarRatio<<std::endl;
}
}
void CullSettings::readCommandLine(ArgumentParser& arguments)
{
// report the usage options.
if (arguments.getApplicationUsage())
{
arguments.getApplicationUsage()->addCommandLineOption("--COMPUTE_NEAR_FAR_MODE <mode>","DO_NOT_COMPUTE_NEAR_FAR | COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES | COMPUTE_NEAR_FAR_USING_PRIMITIVES");
arguments.getApplicationUsage()->addCommandLineOption("--NEAR_FAR_RATIO <float>","Set the ratio between near and far planes - must greater than 0.0 but less than 1.0.");
}
std::string str;
while(arguments.read("--COMPUTE_NEAR_FAR_MODE",str))
{
if (str=="DO_NOT_COMPUTE_NEAR_FAR") _computeNearFar = DO_NOT_COMPUTE_NEAR_FAR;
else if (str=="COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES") _computeNearFar = COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES;
else if (str=="COMPUTE_NEAR_FAR_USING_PRIMITIVES") _computeNearFar = COMPUTE_NEAR_FAR_USING_PRIMITIVES;
osg::notify(osg::INFO)<<"Set compute near far mode to "<<_computeNearFar<<std::endl;
}
double value;
while(arguments.read("--NEAR_FAR_RATIO",value))
{
_nearFarRatio = value;
osg::notify(osg::INFO)<<"Set near/far ratio to "<<_nearFarRatio<<std::endl;
}
}

View File

@@ -28,7 +28,7 @@ DisplaySettings* DisplaySettings::instance()
DisplaySettings::DisplaySettings(const DisplaySettings& vs):Referenced()
{
copy(vs);
setDisplaySettings(vs);
}
DisplaySettings::~DisplaySettings()
@@ -39,11 +39,11 @@ DisplaySettings::~DisplaySettings()
DisplaySettings& DisplaySettings::operator = (const DisplaySettings& vs)
{
if (this==&vs) return *this;
copy(vs);
setDisplaySettings(vs);
return *this;
}
void DisplaySettings::copy(const DisplaySettings& vs)
void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
{
_displayType = vs._displayType;
_stereoMode = vs._stereoMode;