1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version.  The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * OpenSceneGraph Public License for more details.
12 */
13 #include <osg/GLExtensions>
14 #include <osg/State>
15 #include <osg/Fog>
16 #include <osg/Notify>
17 
18 using namespace osg;
19 
20 #ifndef GL_FOG_COORDINATE_SOURCE
21     #define GL_FOG_COORDINATE_SOURCE    0x8450
22 #endif
23 
Fog()24 Fog::Fog()
25 {
26     _mode = EXP;
27     _density = 1.0f;
28     _start   = 0.0f;
29     _end     = 1.0f;
30     _color.set( 0.0f, 0.0f, 0.0f, 0.0f);
31     _fogCoordinateSource = FRAGMENT_DEPTH;
32     _useRadialFog = false;
33 }
34 
35 
~Fog()36 Fog::~Fog()
37 {
38 }
39 
apply(State & state) const40 void Fog::apply(State& state) const
41 {
42 #ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
43 
44 #ifdef OSG_GLES1_AVAILABLE
45     #define glFogi glFogx
46 #endif
47 
48     glFogi( GL_FOG_MODE,     _mode );
49 
50     glFogf( GL_FOG_DENSITY,  _density );
51     glFogf( GL_FOG_START,    _start );
52     glFogf( GL_FOG_END,      _end );
53     glFogfv( GL_FOG_COLOR,    (GLfloat*)_color.ptr() );
54 
55     static bool fogCoordExtensionSupported = osg::isGLExtensionSupported(state.getContextID(),"GL_EXT_fog_coord");
56     if (fogCoordExtensionSupported)
57     {
58         glFogi(GL_FOG_COORDINATE_SOURCE,_fogCoordinateSource);
59     }
60 
61     static bool fogDistanceExtensionSupported = osg::isGLExtensionSupported(state.getContextID(),"GL_NV_fog_distance");
62     if (fogDistanceExtensionSupported)
63     {
64         if(_useRadialFog)
65             glFogf(GL_FOG_DISTANCE_MODE_NV, GL_EYE_RADIAL_NV);
66         else
67             glFogf(GL_FOG_DISTANCE_MODE_NV, GL_EYE_PLANE_ABSOLUTE_NV);
68     }
69 
70 #else
71     OSG_NOTICE<<"Warning: Fog::apply(State&) - not supported."<<std::endl;
72 #endif
73 }
74