openscenegraph
Fog
Go to the documentation of this file.
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
14#ifndef OSG_FOG
15#define OSG_FOG 1
16
17#include <osg/StateAttribute>
18#include <osg/Vec4>
19
20#ifndef GL_FOG_DISTANCE_MODE_NV
21 #define GL_FOG_DISTANCE_MODE_NV 0x855A
22#endif
23#ifndef GL_EYE_PLANE_ABSOLUTE_NV
24 #define GL_EYE_PLANE_ABSOLUTE_NV 0x855C
25#endif
26#ifndef GL_EYE_RADIAL_NV
27 #define GL_EYE_RADIAL_NV 0x855B
28#endif
29
30
31#ifndef GL_FOG_COORDINATE
32 #define GL_FOG_COORDINATE 0x8451
33#endif
34#ifndef GL_FRAGMENT_DEPTH
35 #define GL_FRAGMENT_DEPTH 0x8452
36#endif
37
38#ifndef GL_FOG
39 #define GL_FOG 0x0B60
40 #define GL_EXP 0x0800
41 #define GL_EXP2 0x0801
42#endif
43
44#ifndef GL_FOG_HINT
45 #define GL_FOG_HINT 0x0C54
46#endif
47
48namespace osg {
49
50
51/** Fog - encapsulates OpenGL fog state. */
52class OSG_EXPORT Fog : public StateAttribute
53{
54 public :
55
56 Fog();
57
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),
61 _mode(fog._mode),
62 _density(fog._density),
63 _start(fog._start),
64 _end(fog._end),
65 _color(fog._color),
66 _fogCoordinateSource(fog._fogCoordinateSource),
67 _useRadialFog(fog._useRadialFog) {}
68
69 META_StateAttribute(osg, Fog,FOG);
70
71 /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
72 virtual int compare(const StateAttribute& sa) const
73 {
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)
77
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)
86
87 return 0; // passed all the above comparison macros, must be equal.
88 }
89
90 virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
91 {
92 usage.usesMode(GL_FOG);
93 return true;
94 }
95
96 enum Mode {
97 LINEAR = GL_LINEAR,
98 EXP = GL_EXP,
99 EXP2 = GL_EXP2
100 };
101
102 inline void setMode( Mode mode ) { _mode = mode; }
103 inline Mode getMode() const { return _mode; }
104
105 inline void setDensity( float density ) { _density = density; }
106 inline float getDensity() const { return _density; }
107
108 inline void setStart( float start ) { _start = start; }
109 inline float getStart() const { return _start; }
110
111 inline void setEnd( float end ) { _end = end; }
112 inline float getEnd() const { return _end; }
113
114 inline void setColor( const Vec4 &color ) { _color = color; }
115 inline const Vec4& getColor() const { return _color; }
116
117 inline void setUseRadialFog( bool useRadialFog ) { _useRadialFog = useRadialFog; }
118 inline bool getUseRadialFog() const { return _useRadialFog; }
119
120 enum FogCoordinateSource
121 {
122 FOG_COORDINATE = GL_FOG_COORDINATE,
123 FRAGMENT_DEPTH = GL_FRAGMENT_DEPTH
124 };
125
126 inline void setFogCoordinateSource(GLint source) { _fogCoordinateSource = source; }
127 inline GLint getFogCoordinateSource() const { return _fogCoordinateSource; }
128
129 virtual void apply(State& state) const;
130
131 protected :
132
133 virtual ~Fog();
134
135 Mode _mode;
136 float _density;
137 float _start;
138 float _end;
139 Vec4 _color;
140 GLint _fogCoordinateSource;
141 bool _useRadialFog;
142};
143
144}
145
146#endif