diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index 8443e9202..7b19c4319 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -123,7 +123,9 @@ class OSG_EXPORT GraphicsContext : public Object std::string glContextVersion; unsigned int glContextFlags; unsigned int glContextProfileMask; - + + /** return true if glContextVersion is set in the form major.minor, and assign the appropriate major and minor values to the associated parameters.*/ + bool getContextVersion(unsigned int& major, unsigned int& minor) const; // shared context GraphicsContext* sharedContext; diff --git a/src/osg/GraphicsContext.cpp b/src/osg/GraphicsContext.cpp index 5385e8bd9..cf2a07d22 100644 --- a/src/osg/GraphicsContext.cpp +++ b/src/osg/GraphicsContext.cpp @@ -217,6 +217,18 @@ GraphicsContext::Traits::Traits(DisplaySettings* ds): } } +bool GraphicsContext::Traits::getContextVersion(unsigned int& major, unsigned int& minor) const +{ + if (glContextVersion.empty()) return false; + + std::istringstream istr( glContextVersion ); + unsigned char dot; + istr >> major >> dot >> minor; + + return true; +} + + class ContextData { public: diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index 7f4267922..dd71c2576 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -1766,11 +1766,8 @@ HGLRC GraphicsWindowWin32::createContextImplementation() unsigned int idx( 0 ); int attribs[ 16 ]; - std::istringstream istr( _traits->glContextVersion ); - unsigned int major, minor; - unsigned char dot; - istr >> major >> dot >> minor; - if( major < 3 ) + unsigned int major = 1, minor = 0; + if( !_traitrs->getContextVersion(major, minor) || major<3 ) { OSG_NOTIFY( osg::WARN ) << "GL3: Non-GL3 version number: " << _traits->glContextVersion << std::endl; }