| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 36 | Fog::~Fog() |
|---|
| 37 | { |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | 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 | } |
|---|