ClampColor 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_CLAMPCOLOR
  14. #define OSG_CLAMPCOLOR 1
  15. #include <osg/StateAttribute>
  16. #ifndef GL_ARB_color_buffer_float
  17. #define GL_RGBA_FLOAT_MODE_ARB 0x8820
  18. #define GL_CLAMP_VERTEX_COLOR_ARB 0x891A
  19. #define GL_CLAMP_FRAGMENT_COLOR_ARB 0x891B
  20. #define GL_CLAMP_READ_COLOR_ARB 0x891C
  21. #define GL_FIXED_ONLY_ARB 0x891D
  22. #endif
  23. #ifndef GL_FIXED_ONLY
  24. #define GL_FIXED_ONLY GL_FIXED_ONLY_ARB
  25. #define GL_CLAMP_VERTEX_COLOR GL_CLAMP_VERTEX_COLOR_ARB
  26. #define GL_CLAMP_READ_COLOR GL_CLAMP_READ_COLOR_ARB
  27. #define GL_CLAMP_FRAGMENT_COLOR GL_CLAMP_FRAGMENT_COLOR_ARB
  28. #endif
  29. #if defined(OSG_GL3_AVAILABLE)
  30. #define GL_CLAMP_VERTEX_COLOR 0x891A
  31. #define GL_CLAMP_FRAGMENT_COLOR 0x891B
  32. #endif
  33. namespace osg {
  34. /** Encapsulates OpenGL ClampColor state. */
  35. class OSG_EXPORT ClampColor : public StateAttribute
  36. {
  37. public :
  38. ClampColor();
  39. ClampColor(GLenum vertexMode, GLenum fragmentMode, GLenum readMode);
  40. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  41. ClampColor(const ClampColor& rhs,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  42. StateAttribute(rhs,copyop),
  43. _clampVertexColor(rhs._clampVertexColor),
  44. _clampFragmentColor(rhs._clampFragmentColor),
  45. _clampReadColor(rhs._clampReadColor) {}
  46. META_StateAttribute(osg, ClampColor,CLAMPCOLOR);
  47. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  48. virtual int compare(const StateAttribute& sa) const
  49. {
  50. // Check for equal types, then create the rhs variable
  51. // used by the COMPARE_StateAttribute_Parameter macros below.
  52. COMPARE_StateAttribute_Types(ClampColor,sa)
  53. // Compare each parameter in turn against the rhs.
  54. COMPARE_StateAttribute_Parameter(_clampVertexColor)
  55. COMPARE_StateAttribute_Parameter(_clampFragmentColor)
  56. COMPARE_StateAttribute_Parameter(_clampReadColor)
  57. return 0; // Passed all the above comparison macros, so must be equal.
  58. }
  59. void setClampVertexColor(GLenum mode) { _clampVertexColor = mode; }
  60. GLenum getClampVertexColor() const { return _clampVertexColor; }
  61. void setClampFragmentColor(GLenum mode) { _clampFragmentColor = mode; }
  62. GLenum getClampFragmentColor() const { return _clampFragmentColor; }
  63. void setClampReadColor(GLenum mode) { _clampReadColor = mode; }
  64. GLenum getClampReadColor() const { return _clampReadColor; }
  65. virtual void apply(State& state) const;
  66. protected :
  67. virtual ~ClampColor();
  68. GLenum _clampVertexColor;
  69. GLenum _clampFragmentColor;
  70. GLenum _clampReadColor;
  71. };
  72. }
  73. #endif