Fog 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef OSG_FOG
  14. #define OSG_FOG 1
  15. #include <osg/StateAttribute>
  16. #include <osg/Vec4>
  17. #ifndef GL_FOG_DISTANCE_MODE_NV
  18. #define GL_FOG_DISTANCE_MODE_NV 0x855A
  19. #endif
  20. #ifndef GL_EYE_PLANE_ABSOLUTE_NV
  21. #define GL_EYE_PLANE_ABSOLUTE_NV 0x855C
  22. #endif
  23. #ifndef GL_EYE_RADIAL_NV
  24. #define GL_EYE_RADIAL_NV 0x855B
  25. #endif
  26. #ifndef GL_FOG_COORDINATE
  27. #define GL_FOG_COORDINATE 0x8451
  28. #endif
  29. #ifndef GL_FRAGMENT_DEPTH
  30. #define GL_FRAGMENT_DEPTH 0x8452
  31. #endif
  32. #ifndef GL_FOG
  33. #define GL_FOG 0x0B60
  34. #define GL_EXP 0x0800
  35. #define GL_EXP2 0x0801
  36. #endif
  37. #ifndef GL_FOG_HINT
  38. #define GL_FOG_HINT 0x0C54
  39. #endif
  40. namespace osg {
  41. /** Fog - encapsulates OpenGL fog state. */
  42. class OSG_EXPORT Fog : public StateAttribute
  43. {
  44. public :
  45. Fog();
  46. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  47. Fog(const Fog& fog,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  48. StateAttribute(fog,copyop),
  49. _mode(fog._mode),
  50. _density(fog._density),
  51. _start(fog._start),
  52. _end(fog._end),
  53. _color(fog._color),
  54. _fogCoordinateSource(fog._fogCoordinateSource),
  55. _useRadialFog(fog._useRadialFog) {}
  56. META_StateAttribute(osg, Fog,FOG);
  57. /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/
  58. virtual int compare(const StateAttribute& sa) const
  59. {
  60. // check the types are equal and then create the rhs variable
  61. // used by the COMPARE_StateAttribute_Parameter macros below.
  62. COMPARE_StateAttribute_Types(Fog,sa)
  63. // compare each parameter in turn against the rhs.
  64. COMPARE_StateAttribute_Parameter(_mode)
  65. COMPARE_StateAttribute_Parameter(_density)
  66. COMPARE_StateAttribute_Parameter(_start)
  67. COMPARE_StateAttribute_Parameter(_end)
  68. COMPARE_StateAttribute_Parameter(_color)
  69. COMPARE_StateAttribute_Parameter(_fogCoordinateSource)
  70. COMPARE_StateAttribute_Parameter(_useRadialFog)
  71. return 0; // passed all the above comparison macros, must be equal.
  72. }
  73. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  74. {
  75. usage.usesMode(GL_FOG);
  76. return true;
  77. }
  78. enum Mode {
  79. LINEAR = GL_LINEAR,
  80. EXP = GL_EXP,
  81. EXP2 = GL_EXP2
  82. };
  83. inline void setMode( Mode mode ) { _mode = mode; }
  84. inline Mode getMode() const { return _mode; }
  85. inline void setDensity( float density ) { _density = density; }
  86. inline float getDensity() const { return _density; }
  87. inline void setStart( float start ) { _start = start; }
  88. inline float getStart() const { return _start; }
  89. inline void setEnd( float end ) { _end = end; }
  90. inline float getEnd() const { return _end; }
  91. inline void setColor( const Vec4 &color ) { _color = color; }
  92. inline const Vec4& getColor() const { return _color; }
  93. inline void setUseRadialFog( bool useRadialFog ) { _useRadialFog = useRadialFog; }
  94. inline bool getUseRadialFog() const { return _useRadialFog; }
  95. enum FogCoordinateSource
  96. {
  97. FOG_COORDINATE = GL_FOG_COORDINATE,
  98. FRAGMENT_DEPTH = GL_FRAGMENT_DEPTH
  99. };
  100. inline void setFogCoordinateSource(GLint source) { _fogCoordinateSource = source; }
  101. inline GLint getFogCoordinateSource() const { return _fogCoordinateSource; }
  102. virtual void apply(State& state) const;
  103. protected :
  104. virtual ~Fog();
  105. Mode _mode;
  106. float _density;
  107. float _start;
  108. float _end;
  109. Vec4 _color;
  110. GLint _fogCoordinateSource;
  111. bool _useRadialFog;
  112. };
  113. }
  114. #endif