Replaced getenv calls with safer osg::getEnvVar usage

This commit is contained in:
Robert Osfield 2017-11-02 10:00:28 +00:00
parent 338b0e2b7b
commit 239b0faa4c
2 changed files with 95 additions and 135 deletions

View File

@ -16,6 +16,7 @@
#include <osg/Math> #include <osg/Math>
#include <osg/Notify> #include <osg/Notify>
#include <osg/GL> #include <osg/GL>
#include <osg/EnvVar>
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <algorithm> #include <algorithm>
@ -391,222 +392,182 @@ static ApplicationUsageProxy DisplaySetting_e33(ApplicationUsage::ENVIRONMENTAL_
void DisplaySettings::readEnvironmentalVariables() void DisplaySettings::readEnvironmentalVariables()
{ {
const char* ptr = 0; std::string value;
if (getEnvVar("OSG_DISPLAY_TYPE", value))
if ((ptr = getenv("OSG_DISPLAY_TYPE")) != 0)
{ {
if (strcmp(ptr,"MONITOR")==0) if (value=="MONITOR")
{ {
_displayType = MONITOR; _displayType = MONITOR;
} }
else else
if (strcmp(ptr,"POWERWALL")==0) if (value=="POWERWALL")
{ {
_displayType = POWERWALL; _displayType = POWERWALL;
} }
else else
if (strcmp(ptr,"REALITY_CENTER")==0) if (value=="REALITY_CENTER")
{ {
_displayType = REALITY_CENTER; _displayType = REALITY_CENTER;
} }
else else
if (strcmp(ptr,"HEAD_MOUNTED_DISPLAY")==0) if (value=="HEAD_MOUNTED_DISPLAY")
{ {
_displayType = HEAD_MOUNTED_DISPLAY; _displayType = HEAD_MOUNTED_DISPLAY;
} }
} }
if( (ptr = getenv("OSG_STEREO_MODE")) != 0) if (getEnvVar("OSG_STEREO_MODE", value))
{ {
if (strcmp(ptr,"QUAD_BUFFER")==0) if (value=="QUAD_BUFFER")
{ {
_stereoMode = QUAD_BUFFER; _stereoMode = QUAD_BUFFER;
} }
else if (strcmp(ptr,"ANAGLYPHIC")==0) else if (value=="ANAGLYPHIC")
{ {
_stereoMode = ANAGLYPHIC; _stereoMode = ANAGLYPHIC;
} }
else if (strcmp(ptr,"HORIZONTAL_SPLIT")==0) else if (value=="HORIZONTAL_SPLIT")
{ {
_stereoMode = HORIZONTAL_SPLIT; _stereoMode = HORIZONTAL_SPLIT;
} }
else if (strcmp(ptr,"VERTICAL_SPLIT")==0) else if (value=="VERTICAL_SPLIT")
{ {
_stereoMode = VERTICAL_SPLIT; _stereoMode = VERTICAL_SPLIT;
} }
else if (strcmp(ptr,"LEFT_EYE")==0) else if (value=="LEFT_EYE")
{ {
_stereoMode = LEFT_EYE; _stereoMode = LEFT_EYE;
} }
else if (strcmp(ptr,"RIGHT_EYE")==0) else if (value=="RIGHT_EYE")
{ {
_stereoMode = RIGHT_EYE; _stereoMode = RIGHT_EYE;
} }
else if (strcmp(ptr,"HORIZONTAL_INTERLACE")==0) else if (value=="HORIZONTAL_INTERLACE")
{ {
_stereoMode = HORIZONTAL_INTERLACE; _stereoMode = HORIZONTAL_INTERLACE;
} }
else if (strcmp(ptr,"VERTICAL_INTERLACE")==0) else if (value=="VERTICAL_INTERLACE")
{ {
_stereoMode = VERTICAL_INTERLACE; _stereoMode = VERTICAL_INTERLACE;
} }
else if (strcmp(ptr,"CHECKERBOARD")==0) else if (value=="CHECKERBOARD")
{ {
_stereoMode = CHECKERBOARD; _stereoMode = CHECKERBOARD;
} }
} }
if( (ptr = getenv("OSG_STEREO")) != 0) if (getEnvVar("OSG_STEREO", value))
{ {
if (strcmp(ptr,"OFF")==0) if (value=="OFF")
{ {
_stereo = false; _stereo = false;
} }
else else
if (strcmp(ptr,"ON")==0) if (value=="ON")
{ {
_stereo = true; _stereo = true;
} }
} }
if( (ptr = getenv("OSG_EYE_SEPARATION")) != 0) getEnvVar("OSG_EYE_SEPARATION", _eyeSeparation);
{ getEnvVar("OSG_SCREEN_WIDTH", _screenWidth);
_eyeSeparation = osg::asciiToFloat(ptr); getEnvVar("OSG_SCREEN_HEIGHT", _screenHeight);
} getEnvVar("OSG_SCREEN_DISTANCE", _screenDistance);
if( (ptr = getenv("OSG_SCREEN_WIDTH")) != 0) if (getEnvVar("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING", value))
{ {
_screenWidth = osg::asciiToFloat(ptr); if (value=="LEFT_EYE_LEFT_VIEWPORT")
}
if( (ptr = getenv("OSG_SCREEN_HEIGHT")) != 0)
{
_screenHeight = osg::asciiToFloat(ptr);
}
if( (ptr = getenv("OSG_SCREEN_DISTANCE")) != 0)
{
_screenDistance = osg::asciiToFloat(ptr);
}
if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING")) != 0)
{
if (strcmp(ptr,"LEFT_EYE_LEFT_VIEWPORT")==0)
{ {
_splitStereoHorizontalEyeMapping = LEFT_EYE_LEFT_VIEWPORT; _splitStereoHorizontalEyeMapping = LEFT_EYE_LEFT_VIEWPORT;
} }
else else
if (strcmp(ptr,"LEFT_EYE_RIGHT_VIEWPORT")==0) if (value=="LEFT_EYE_RIGHT_VIEWPORT")
{ {
_splitStereoHorizontalEyeMapping = LEFT_EYE_RIGHT_VIEWPORT; _splitStereoHorizontalEyeMapping = LEFT_EYE_RIGHT_VIEWPORT;
} }
} }
if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION")) != 0) getEnvVar("OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION", _splitStereoHorizontalSeparation);
{
_splitStereoHorizontalSeparation = atoi(ptr);
}
if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING")) != 0) if (getEnvVar("OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING", value))
{ {
if (strcmp(ptr,"LEFT_EYE_TOP_VIEWPORT")==0) if (value=="LEFT_EYE_TOP_VIEWPORT")
{ {
_splitStereoVerticalEyeMapping = LEFT_EYE_TOP_VIEWPORT; _splitStereoVerticalEyeMapping = LEFT_EYE_TOP_VIEWPORT;
} }
else else
if (strcmp(ptr,"LEFT_EYE_BOTTOM_VIEWPORT")==0) if (value=="LEFT_EYE_BOTTOM_VIEWPORT")
{ {
_splitStereoVerticalEyeMapping = LEFT_EYE_BOTTOM_VIEWPORT; _splitStereoVerticalEyeMapping = LEFT_EYE_BOTTOM_VIEWPORT;
} }
} }
if( (ptr = getenv("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO")) != 0) if (getEnvVar("OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO", value))
{ {
if (strcmp(ptr,"OFF")==0) if (value=="OFF")
{ {
_splitStereoAutoAdjustAspectRatio = false; _splitStereoAutoAdjustAspectRatio = false;
} }
else else
if (strcmp(ptr,"ON")==0) if (value=="ON")
{ {
_splitStereoAutoAdjustAspectRatio = true; _splitStereoAutoAdjustAspectRatio = true;
} }
} }
if( (ptr = getenv("OSG_SPLIT_STEREO_VERTICAL_SEPARATION")) != 0) getEnvVar("OSG_SPLIT_STEREO_VERTICAL_SEPARATION", _splitStereoVerticalSeparation);
{
_splitStereoVerticalSeparation = atoi(ptr);
}
if( (ptr = getenv("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS")) != 0) getEnvVar("OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS", _maxNumOfGraphicsContexts);
{
_maxNumOfGraphicsContexts = atoi(ptr);
}
if( (ptr = getenv("OSG_COMPILE_CONTEXTS")) != 0) if (getEnvVar("OSG_COMPILE_CONTEXTS", value))
{ {
if (strcmp(ptr,"OFF")==0) if (value=="OFF")
{ {
_compileContextsHint = false; _compileContextsHint = false;
} }
else else
if (strcmp(ptr,"ON")==0) if (value=="ON")
{ {
_compileContextsHint = true; _compileContextsHint = true;
} }
} }
if( (ptr = getenv("OSG_SERIALIZE_DRAW_DISPATCH")) != 0) if (getEnvVar("OSG_SERIALIZE_DRAW_DISPATCH", value))
{ {
if (strcmp(ptr,"OFF")==0) if (value=="OFF")
{ {
_serializeDrawDispatch = false; _serializeDrawDispatch = false;
} }
else else
if (strcmp(ptr,"ON")==0) if (value=="ON")
{ {
_serializeDrawDispatch = true; _serializeDrawDispatch = true;
} }
} }
if( (ptr = getenv("OSG_USE_SCENEVIEW_FOR_STEREO")) != 0) if (getEnvVar("OSG_USE_SCENEVIEW_FOR_STEREO", value))
{ {
if (strcmp(ptr,"OFF")==0) if (value=="OFF")
{ {
_useSceneViewForStereoHint = false; _useSceneViewForStereoHint = false;
} }
else else
if (strcmp(ptr,"ON")==0) if (value=="ON")
{ {
_useSceneViewForStereoHint = true; _useSceneViewForStereoHint = true;
} }
} }
if( (ptr = getenv("OSG_NUM_DATABASE_THREADS")) != 0) getEnvVar("OSG_NUM_DATABASE_THREADS", _numDatabaseThreadsHint);
{
_numDatabaseThreadsHint = atoi(ptr);
}
if( (ptr = getenv("OSG_NUM_HTTP_DATABASE_THREADS")) != 0) getEnvVar("OSG_NUM_HTTP_DATABASE_THREADS", _numHttpDatabaseThreadsHint);
{
_numHttpDatabaseThreadsHint = atoi(ptr);
}
if( (ptr = getenv("OSG_MULTI_SAMPLES")) != 0) getEnvVar("OSG_MULTI_SAMPLES", _numMultiSamples);
{
_numMultiSamples = atoi(ptr);
}
if( (ptr = getenv("OSG_TEXTURE_POOL_SIZE")) != 0) getEnvVar("OSG_TEXTURE_POOL_SIZE", _maxTexturePoolSize);
{
_maxTexturePoolSize = atoi(ptr);
}
if( (ptr = getenv("OSG_BUFFER_OBJECT_POOL_SIZE")) != 0) getEnvVar("OSG_BUFFER_OBJECT_POOL_SIZE", _maxBufferObjectPoolSize);
{
_maxBufferObjectPoolSize = atoi(ptr);
}
{ // Read implicit buffer attachments combinations for both render and resolve mask { // Read implicit buffer attachments combinations for both render and resolve mask
@ -642,71 +603,65 @@ void DisplaySettings::readEnvironmentalVariables()
} }
} }
if( (ptr = getenv("OSG_GL_VERSION")) != 0 || (ptr = getenv("OSG_GL_CONTEXT_VERSION")) != 0) if (getEnvVar("OSG_GL_VERSION", value) || getEnvVar("OSG_GL_CONTEXT_VERSION", value))
{ {
_glContextVersion = ptr; _glContextVersion = value;
} }
if( (ptr = getenv("OSG_GL_CONTEXT_FLAGS")) != 0) getEnvVar("OSG_GL_CONTEXT_FLAGS", _glContextFlags);
{
_glContextFlags = atoi(ptr);
}
if( (ptr = getenv("OSG_GL_CONTEXT_PROFILE_MASK")) != 0) getEnvVar("OSG_GL_CONTEXT_PROFILE_MASK", _glContextProfileMask);
{
_glContextProfileMask = atoi(ptr);
}
if ((ptr = getenv("OSG_SWAP_METHOD")) != 0) if (getEnvVar("OSG_SWAP_METHOD", value))
{ {
if (strcmp(ptr,"DEFAULT")==0) if (value=="DEFAULT")
{ {
_swapMethod = SWAP_DEFAULT; _swapMethod = SWAP_DEFAULT;
} }
else else
if (strcmp(ptr,"EXCHANGE")==0) if (value=="EXCHANGE")
{ {
_swapMethod = SWAP_EXCHANGE; _swapMethod = SWAP_EXCHANGE;
} }
else else
if (strcmp(ptr,"COPY")==0) if (value=="COPY")
{ {
_swapMethod = SWAP_COPY; _swapMethod = SWAP_COPY;
} }
else else
if (strcmp(ptr,"UNDEFINED")==0) if (value=="UNDEFINED")
{ {
_swapMethod = SWAP_UNDEFINED; _swapMethod = SWAP_UNDEFINED;
} }
} }
if ((ptr = getenv("OSG_SYNC_SWAP_BUFFERS")) != 0) if (getEnvVar("OSG_SYNC_SWAP_BUFFERS", value))
{ {
if (strcmp(ptr,"OFF")==0) if (value=="OFF")
{ {
_syncSwapBuffers = 0; _syncSwapBuffers = 0;
} }
else else
if (strcmp(ptr,"ON")==0) if (value=="ON")
{ {
_syncSwapBuffers = 1; _syncSwapBuffers = 1;
} }
else else
{ {
_syncSwapBuffers = atoi(ptr); _syncSwapBuffers = atoi(value.c_str());
} }
} }
if ((ptr = getenv("OSG_VERTEX_BUFFER_HINT")) != 0) if (getEnvVar("OSG_VERTEX_BUFFER_HINT", value))
{ {
if (strcmp(ptr,"VERTEX_BUFFER_OBJECT")==0 || strcmp(ptr,"VBO")==0) if (value=="VERTEX_BUFFER_OBJECT" || value=="VBO")
{ {
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_BUFFER_OBJECT"<<std::endl; OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_BUFFER_OBJECT"<<std::endl;
_vertexBufferHint = VERTEX_BUFFER_OBJECT; _vertexBufferHint = VERTEX_BUFFER_OBJECT;
} }
else if (strcmp(ptr,"VERTEX_ARRAY_OBJECT")==0 || strcmp(ptr,"VAO")==0) else if (value=="VERTEX_ARRAY_OBJECT" || value=="VAO")
{ {
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_ARRAY_OBJECT"<<std::endl; OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_ARRAY_OBJECT"<<std::endl;
_vertexBufferHint = VERTEX_ARRAY_OBJECT; _vertexBufferHint = VERTEX_ARRAY_OBJECT;
@ -719,50 +674,50 @@ void DisplaySettings::readEnvironmentalVariables()
} }
if ((ptr = getenv("OSG_SHADER_HINT")) != 0) if (getEnvVar("OSG_SHADER_HINT", value))
{ {
if (strcmp(ptr,"GL2")==0) if (value=="GL2")
{ {
setShaderHint(SHADER_GL2); setShaderHint(SHADER_GL2);
} }
else if (strcmp(ptr,"GL3")==0) else if (value=="GL3")
{ {
setShaderHint(SHADER_GL3); setShaderHint(SHADER_GL3);
} }
else if (strcmp(ptr,"GLES2")==0) else if (value=="GLES2")
{ {
setShaderHint(SHADER_GLES2); setShaderHint(SHADER_GLES2);
} }
else if (strcmp(ptr,"GLES3")==0) else if (value=="GLES3")
{ {
setShaderHint(SHADER_GLES3); setShaderHint(SHADER_GLES3);
} }
else if (strcmp(ptr,"NONE")==0) else if (value=="NONE")
{ {
setShaderHint(SHADER_NONE); setShaderHint(SHADER_NONE);
} }
} }
if ((ptr = getenv("OSG_TEXT_SHADER_TECHNIQUE")) != 0) if (getEnvVar("OSG_TEXT_SHADER_TECHNIQUE", value))
{ {
setTextShaderTechnique(ptr); setTextShaderTechnique(value);
} }
if( (ptr = getenv("OSG_KEYSTONE")) != 0) if (getEnvVar("OSG_KEYSTONE", value))
{ {
if (strcmp(ptr,"OFF")==0) if (value=="OFF")
{ {
_keystoneHint = false; _keystoneHint = false;
} }
else else
if (strcmp(ptr,"ON")==0) if (value=="ON")
{ {
_keystoneHint = true; _keystoneHint = true;
} }
} }
if ((ptr = getenv("OSG_KEYSTONE_FILES")) != 0) if (getEnvVar("OSG_KEYSTONE_FILES", value))
{ {
#if defined(WIN32) && !defined(__CYGWIN__) #if defined(WIN32) && !defined(__CYGWIN__)
char delimitor = ';'; char delimitor = ';';
@ -770,7 +725,7 @@ void DisplaySettings::readEnvironmentalVariables()
char delimitor = ':'; char delimitor = ':';
#endif #endif
std::string paths(ptr); std::string paths(value);
if (!paths.empty()) if (!paths.empty())
{ {
std::string::size_type start = 0; std::string::size_type start = 0;
@ -787,27 +742,28 @@ void DisplaySettings::readEnvironmentalVariables()
} }
} }
if( (ptr = getenv("OSG_MENUBAR_BEHAVIOR")) != 0) if (getEnvVar("OSG_MENUBAR_BEHAVIOR", value))
{ {
if (strcmp(ptr,"AUTO_HIDE")==0) if (value=="AUTO_HIDE")
{ {
_OSXMenubarBehavior = MENUBAR_AUTO_HIDE; _OSXMenubarBehavior = MENUBAR_AUTO_HIDE;
} }
else else
if (strcmp(ptr,"FORCE_HIDE")==0) if (value=="FORCE_HIDE")
{ {
_OSXMenubarBehavior = MENUBAR_FORCE_HIDE; _OSXMenubarBehavior = MENUBAR_FORCE_HIDE;
} }
else else
if (strcmp(ptr,"FORCE_SHOW")==0) if (value=="FORCE_SHOW")
{ {
_OSXMenubarBehavior = MENUBAR_FORCE_SHOW; _OSXMenubarBehavior = MENUBAR_FORCE_SHOW;
} }
} }
if( (ptr = getenv("OSG_NvOptimusEnablement")) != 0) int enable = 0;
if (getEnvVar("OSG_NvOptimusEnablement", enable))
{ {
setNvOptimusEnablement(atoi(ptr)); setNvOptimusEnablement(enable);
} }
} }

View File

@ -927,12 +927,16 @@ GLExtensions::GLExtensions(unsigned int in_contextID):
isTextureMaxLevelSupported = (glVersion >= 1.2f); isTextureMaxLevelSupported = (glVersion >= 1.2f);
isTextureStorageEnabled = validContext && ((glVersion >= 4.2f) || isGLExtensionSupported(contextID, "GL_ARB_texture_storage")); isTextureStorageEnabled = validContext && ((glVersion >= 4.2f) || isGLExtensionSupported(contextID, "GL_ARB_texture_storage"));
if ( (ptr = getenv("OSG_GL_TEXTURE_STORAGE")) != 0 && isTextureStorageEnabled)
{
if (strcmp(ptr,"OFF")==0 || strcmp(ptr,"DISABLE")==0 ) isTextureStorageEnabled = false;
else isTextureStorageEnabled = true;
}
if (isTextureStorageEnabled)
{
std::string value;
if (getEnvVar("OSG_GL_TEXTURE_STORAGE", value))
{
if (value=="OFF" || value=="DISABLE") isTextureStorageEnabled = false;
else isTextureStorageEnabled = true;
}
}
// Texture3D extensions // Texture3D extensions
isTexture3DFast = validContext && (OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture3D")); isTexture3DFast = validContext && (OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture3D"));