diff --git a/include/osg/Fog b/include/osg/Fog index 1b9400735..62a2aeedc 100644 --- a/include/osg/Fog +++ b/include/osg/Fog @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 @@ -17,6 +17,17 @@ #include #include +#ifndef GL_FOG_DISTANCE_MODE_NV + #define GL_FOG_DISTANCE_MODE_NV 0x855A +#endif +#ifndef GL_EYE_PLANE_ABSOLUTE_NV + #define GL_EYE_PLANE_ABSOLUTE_NV 0x855C +#endif +#ifndef GL_EYE_RADIAL_NV + #define GL_EYE_RADIAL_NV 0x855B +#endif + + #ifndef GL_FOG_COORDINATE #define GL_FOG_COORDINATE 0x8451 #endif @@ -52,7 +63,8 @@ class OSG_EXPORT Fog : public StateAttribute _start(fog._start), _end(fog._end), _color(fog._color), - _fogCoordinateSource(fog._fogCoordinateSource) {} + _fogCoordinateSource(fog._fogCoordinateSource), + _useRadialFog(fog._useRadialFog) {} META_StateAttribute(osg, Fog,FOG); @@ -70,6 +82,7 @@ class OSG_EXPORT Fog : public StateAttribute COMPARE_StateAttribute_Parameter(_end) COMPARE_StateAttribute_Parameter(_color) COMPARE_StateAttribute_Parameter(_fogCoordinateSource) + COMPARE_StateAttribute_Parameter(_useRadialFog) return 0; // passed all the above comparison macro's, must be equal. } @@ -98,8 +111,11 @@ class OSG_EXPORT Fog : public StateAttribute inline void setEnd( float end ) { _end = end; } inline float getEnd() const { return _end; } - inline void setColor( const Vec4 &color ) { _color = color; } - inline const Vec4& getColor() const { return _color; } + inline void setColor( const Vec4 &color ) { _color = color; } + inline const Vec4& getColor() const { return _color; } + + inline void setUseRadialFog( bool useRadialFog ) { _useRadialFog = useRadialFog; } + inline bool getUseRadialFog() const { return _useRadialFog; } enum FogCoordinateSource { @@ -122,6 +138,7 @@ class OSG_EXPORT Fog : public StateAttribute float _end; Vec4 _color; GLint _fogCoordinateSource; + bool _useRadialFog; }; } diff --git a/src/osg/Fog.cpp b/src/osg/Fog.cpp index bc07562e6..71c67601e 100644 --- a/src/osg/Fog.cpp +++ b/src/osg/Fog.cpp @@ -29,6 +29,7 @@ Fog::Fog() _end = 1.0f; _color.set( 0.0f, 0.0f, 0.0f, 0.0f); _fogCoordinateSource = FRAGMENT_DEPTH; + _useRadialFog = false; } @@ -51,11 +52,21 @@ void Fog::apply(State& state) const glFogf( GL_FOG_END, _end ); glFogfv( GL_FOG_COLOR, (GLfloat*)_color.ptr() ); - static bool fogCoordExtensionSuppoted = osg::isGLExtensionSupported(state.getContextID(),"GL_EXT_fog_coord"); - if (fogCoordExtensionSuppoted) + static bool fogCoordExtensionSupported = osg::isGLExtensionSupported(state.getContextID(),"GL_EXT_fog_coord"); + if (fogCoordExtensionSupported) { glFogi(GL_FOG_COORDINATE_SOURCE,_fogCoordinateSource); } + + static bool fogDistanceExtensionSupported = osg::isGLExtensionSupported(state.getContextID(),"GL_NV_fog_distance"); + if (fogDistanceExtensionSupported) + { + if(_useRadialFog) + glFogf(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV); + else + glFogf(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV); + } + #else OSG_NOTICE<<"Warning: Fog::apply(State&) - not supported."<