Moved getenv usage across to safer osg::getEnvVar() usage

This commit is contained in:
Robert Osfield 2017-11-01 17:38:33 +00:00
parent 0e7e06349e
commit 338b0e2b7b
6 changed files with 39 additions and 24 deletions

View File

@ -17,6 +17,7 @@
#include <osg/Config>
#ifdef OSG_ENVVAR_SUPPORTED
#include <stdlib.h>
#include <sstream>
#endif
@ -29,6 +30,15 @@ inline unsigned int getClampedLength(const char* str, unsigned int maxNumChars=4
return i;
}
inline std::string getEnvVar(const char* name)
{
std::string value;
const char* ptr = getenv(name);
if (ptr) value.assign(ptr, getClampedLength(ptr));
return value;
}
template<typename T>
inline bool getEnvVar(const char* name, T& value)
{

View File

@ -15,6 +15,8 @@
#include <osg/Notify>
#include <osg/Math>
#include <osg/buffered_value>
#include <osg/EnvVar>
#include <osg/ApplicationUsage>
#include <stdlib.h>
#include <string.h>
@ -65,6 +67,9 @@ static osg::buffered_object<ExtensionSet> s_gluExtensionSetList;
static osg::buffered_object<std::string> s_gluRendererList;
static osg::buffered_value<int> s_gluInitializedList;
static ApplicationUsageProxy GLEXtension_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_GL_EXTENSION_DISABLE <value>", "Use space deliminarted list of GL extensions to disable associated GL extensions");
static ApplicationUsageProxy GLEXtension_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_MAX_TEXTURE_SIZE <value>", "Clamp the maximum GL texture size to specified value.");
float osg::getGLVersionNumber()
{
// needs to be extended to do proper things with subversions like 1.5.1, etc.
@ -308,8 +313,7 @@ void osg::setGLExtensionDisableString(const std::string& disableString)
std::string& osg::getGLExtensionDisableString()
{
static const char* envVar = getenv("OSG_GL_EXTENSION_DISABLE");
static std::string s_GLExtensionDisableString(envVar?envVar:"Nothing defined");
static std::string s_GLExtensionDisableString(getEnvVar("OSG_GL_EXTENSION_DISABLE"));
return s_GLExtensionDisableString;
}
@ -901,15 +905,12 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
if (validContext) glGetIntegerv(GL_MAX_TEXTURE_SIZE,&maxTextureSize);
char *ptr;
if( (ptr = getenv("OSG_MAX_TEXTURE_SIZE")) != 0)
GLint osg_max_size = maxTextureSize;
if( (getEnvVar("OSG_MAX_TEXTURE_SIZE", osg_max_size)) && osg_max_size<maxTextureSize)
{
GLint osg_max_size = atoi(ptr);
if (osg_max_size<maxTextureSize)
{
maxTextureSize = osg_max_size;
}
maxTextureSize = osg_max_size;
}
setGLExtensionFuncPtr(glTexStorage2D,"glTexStorage2D","glTexStorage2DARB", validContext);

View File

@ -18,6 +18,7 @@
#include <osg/View>
#include <osg/GLObjects>
#include <osg/ContextData>
#include <osg/EnvVar>
#include <osg/FrameBufferObject>
#include <osg/Program>
@ -153,10 +154,10 @@ std::string GraphicsContext::ScreenIdentifier::displayName() const
void GraphicsContext::ScreenIdentifier::readDISPLAY()
{
const char* ptr = 0;
if ((ptr=getenv("DISPLAY")) != 0)
std::string str;
if (getEnvVar("DISPLAY", str))
{
setScreenIdentifier(ptr);
setScreenIdentifier(str);
}
}

View File

@ -12,6 +12,7 @@
*/
#include <osg/Notify>
#include <osg/ApplicationUsage>
#include <osg/EnvVar>
#include <osg/ref_ptr>
#include <string>
#include <stdlib.h>
@ -140,9 +141,8 @@ struct NotifySingleton
_notifyLevel = osg::NOTICE; // Default value
char* OSGNOTIFYLEVEL=getenv("OSG_NOTIFY_LEVEL");
if (!OSGNOTIFYLEVEL) OSGNOTIFYLEVEL=getenv("OSGNOTIFYLEVEL");
if(OSGNOTIFYLEVEL)
std::string OSGNOTIFYLEVEL;
if(getEnvVar("OSG_NOTIFY_LEVEL", OSGNOTIFYLEVEL) || getEnvVar("OSGNOTIFYLEVEL", OSGNOTIFYLEVEL))
{
std::string stringOSGNOTIFYLEVEL(OSGNOTIFYLEVEL);

View File

@ -516,7 +516,6 @@ void Program::apply( osg::State& state ) const
{
// for shader debugging: to minimize performance impact,
// optionally validate based on notify level.
// TODO: enable this using notify level, or perhaps its own getenv()?
#ifndef __APPLE__
if( osg::isNotifyEnabled(osg::INFO) )
pcp->validateProgram();

View File

@ -18,6 +18,7 @@
#include <osg/Drawable>
#include <osg/ApplicationUsage>
#include <osg/ContextData>
#include <osg/EnvVar>
#include <sstream>
#include <algorithm>
@ -75,14 +76,17 @@ State::State():
_checkGLErrors = ONCE_PER_FRAME;
const char* str = getenv("OSG_GL_ERROR_CHECKING");
if (str && (strcmp(str,"ONCE_PER_ATTRIBUTE")==0 || strcmp(str,"ON")==0 || strcmp(str,"on")==0))
std::string str;
if (getEnvVar("OSG_GL_ERROR_CHECKING", str))
{
_checkGLErrors = ONCE_PER_ATTRIBUTE;
}
else if(str && (strcmp(str, "OFF") == 0 || strcmp(str, "off") == 0))
{
_checkGLErrors = NEVER_CHECK_GL_ERRORS;
if (str=="ONCE_PER_ATTRIBUTE" || str=="ON" || str=="on")
{
_checkGLErrors = ONCE_PER_ATTRIBUTE;
}
else if (str=="OFF" || str=="off")
{
_checkGLErrors = NEVER_CHECK_GL_ERRORS;
}
}
_currentActiveTextureUnit=0;