Hi Christoph,
I reviewed your changes but fee there is a safe way to do this. The
use of local static variable isn't safe so I've replaced the static
code with state.get<GLExtensions> usage that is thread-safe and
multi-context friendly. Changes are outlined below. These are now
checked into the git master and OSG-3.4 branch.
A wider question I'd have though is what glGet("GL_VERSION") is
failing for you. What GL driver and platform are you using?
Robert.
diff --git a/src/osg/LightModel.cpp b/src/osg/LightModel.cpp
index 41c4acc..6617e5d 100644
--- a/src/osg/LightModel.cpp
+++ b/src/osg/LightModel.cpp
@@ -16,6 +16,7 @@
#include <osg/GL>
#include <osg/LightModel>
#include <osg/Notify>
+#include <osg/State>
using namespace osg;
@@ -34,6 +35,8 @@ LightModel::~LightModel()
{
}
+#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
+
// need to define if gl.h version < 1.2.
#ifndef GL_LIGHT_MODEL_COLOR_CONTROL
#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
@@ -47,10 +50,8 @@ LightModel::~LightModel()
#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
#endif
-
-void LightModel::apply(State&) const
+void LightModel::apply(State& state) const
{
-#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
#ifdef OSG_GLES1_AVAILABLE
#define glLightModeli glLightModelx
@@ -58,8 +59,7 @@ void LightModel::apply(State&) const
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,_ambient.ptr());
- static bool s_separateSpecularSupported = strncmp((const
char*)glGetString(GL_VERSION),"1.2",3)>=0;
- if (s_separateSpecularSupported)
+ if (state.get<GLExtensions>()->glVersion>=1.2)
{
if (_colorControl==SEPARATE_SPECULAR_COLOR)
{
@@ -76,8 +76,14 @@ void LightModel::apply(State&) const
#endif
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,_twoSided);
+}
+
#else
+
+void LightModel::apply(State&) const
+{
OSG_NOTICE<<"Warning: LightModel::apply(State&) - not
supported."<<std::endl;
-#endif
}
On 22 September 2016 at 14:09, Christoph Weiss <[email protected]> wrote:
> Hello,
>
> The attached patch fixes a possible segmentation fault in OSG 3.5.1 in
> osg::LightModel that is triggered by glGetString() returning NULL. It's
> still not really thread safe, as before, but safe enough.
>
> --
> Mit freundlichen Grüßen,
>
> Christoph Weiß
>
> WSoptics GmbH
> [email protected]
> +49 8868 181 997 3
> Zugspitzstraße 9
> 86972 Altenstadt
>
> HRB 204558 Gerichtsstand: München B Ust.Id.Nr.: DE289079930
> Geschäftsführer: Florian Sepp, Dr. Christoph Weiß
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org