OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fog.h
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 
48 namespace osg {
49 
50 
53 {
54  public :
55 
56  Fog();
57 
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 
70 
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.
77 
78  // compare each parameter in turn against the rhs.
84  COMPARE_StateAttribute_Parameter(_fogCoordinateSource)
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 
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 
136  float _density;
137  float _start;
138  float _end;
142 };
143 
144 }
145 
146 #endif
GLint getFogCoordinateSource() const
Definition: Fog.h:127
#define OSG_EXPORT
Definition: Export.h:43
#define GL_EXP2
Definition: Fog.h:41
#define COMPARE_StateAttribute_Types(TYPE, rhs_attribute)
virtual bool getModeUsage(StateAttribute::ModeUsage &usage) const
Definition: Fog.h:90
float getDensity() const
Definition: Fog.h:106
#define GL_FRAGMENT_DEPTH
Definition: Fog.h:35
#define GL_FOG
Definition: Fog.h:39
virtual void usesMode(GLMode mode)=0
float _density
Definition: Fog.h:136
void setColor(const Vec4 &color)
Definition: Fog.h:114
float _start
Definition: Fog.h:137
GLint _fogCoordinateSource
Definition: Fog.h:140
const Vec4 & getColor() const
Definition: Fog.h:115
Definition: Fog.h:52
virtual int compare(const StateAttribute &sa) const
Definition: Fog.h:72
void setDensity(float density)
Definition: Fog.h:105
Fog(const Fog &fog, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: Fog.h:59
Vec4 _color
Definition: Fog.h:139
void setEnd(float end)
Definition: Fog.h:111
void setFogCoordinateSource(GLint source)
Definition: Fog.h:126
#define META_StateAttribute(library, name, type)
FogCoordinateSource
Definition: Fog.h:120
Definition: AlphaFunc.h:19
Mode
Definition: Fog.h:96
#define COMPARE_StateAttribute_Parameter(parameter)
bool getUseRadialFog() const
Definition: Fog.h:118
void setStart(float start)
Definition: Fog.h:108
#define GL_FOG_COORDINATE
Definition: Fog.h:32
void setUseRadialFog(bool useRadialFog)
Definition: Fog.h:117
Mode _mode
Definition: Fog.h:135
float getStart() const
Definition: Fog.h:109
float _end
Definition: Fog.h:138
float getEnd() const
Definition: Fog.h:112
Mode getMode() const
Definition: Fog.h:103
bool _useRadialFog
Definition: Fog.h:141
#define GL_EXP
Definition: Fog.h:40
void setMode(Mode mode)
Definition: Fog.h:102