1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
17#include <osg/StateAttribute>
20#ifndef GL_FOG_DISTANCE_MODE_NV
21 #define GL_FOG_DISTANCE_MODE_NV 0x855A
23#ifndef GL_EYE_PLANE_ABSOLUTE_NV
24 #define GL_EYE_PLANE_ABSOLUTE_NV 0x855C
26#ifndef GL_EYE_RADIAL_NV
27 #define GL_EYE_RADIAL_NV 0x855B
31#ifndef GL_FOG_COORDINATE
32 #define GL_FOG_COORDINATE 0x8451
34#ifndef GL_FRAGMENT_DEPTH
35 #define GL_FRAGMENT_DEPTH 0x8452
41 #define GL_EXP2 0x0801
45 #define GL_FOG_HINT 0x0C54
51/** Fog - encapsulates OpenGL fog state. */
52class OSG_EXPORT Fog : public StateAttribute
58 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
59 Fog(const Fog& fog,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
60 StateAttribute(fog,copyop),
62 _density(fog._density),
66 _fogCoordinateSource(fog._fogCoordinateSource),
67 _useRadialFog(fog._useRadialFog) {}
69 META_StateAttribute(osg, Fog,FOG);
71 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
72 virtual int compare(const StateAttribute& sa) const
74 // check the types are equal and then create the rhs variable
75 // used by the COMPARE_StateAttribute_Parameter macros below.
76 COMPARE_StateAttribute_Types(Fog,sa)
78 // compare each parameter in turn against the rhs.
79 COMPARE_StateAttribute_Parameter(_mode)
80 COMPARE_StateAttribute_Parameter(_density)
81 COMPARE_StateAttribute_Parameter(_start)
82 COMPARE_StateAttribute_Parameter(_end)
83 COMPARE_StateAttribute_Parameter(_color)
84 COMPARE_StateAttribute_Parameter(_fogCoordinateSource)
85 COMPARE_StateAttribute_Parameter(_useRadialFog)
87 return 0; // passed all the above comparison macros, must be equal.
90 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
92 usage.usesMode(GL_FOG);
102 inline void setMode( Mode mode ) { _mode = mode; }
103 inline Mode getMode() const { return _mode; }
105 inline void setDensity( float density ) { _density = density; }
106 inline float getDensity() const { return _density; }
108 inline void setStart( float start ) { _start = start; }
109 inline float getStart() const { return _start; }
111 inline void setEnd( float end ) { _end = end; }
112 inline float getEnd() const { return _end; }
114 inline void setColor( const Vec4 &color ) { _color = color; }
115 inline const Vec4& getColor() const { return _color; }
117 inline void setUseRadialFog( bool useRadialFog ) { _useRadialFog = useRadialFog; }
118 inline bool getUseRadialFog() const { return _useRadialFog; }
120 enum FogCoordinateSource
122 FOG_COORDINATE = GL_FOG_COORDINATE,
123 FRAGMENT_DEPTH = GL_FRAGMENT_DEPTH
126 inline void setFogCoordinateSource(GLint source) { _fogCoordinateSource = source; }
127 inline GLint getFogCoordinateSource() const { return _fogCoordinateSource; }
129 virtual void apply(State& state) const;
140 GLint _fogCoordinateSource;