BlendEquation 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_BLENDEQUATION
  14. #define OSG_BLENDEQUATION 1
  15. #include <osg/StateAttribute>
  16. #ifndef GL_VERSION_1_2
  17. /* Logic Ops */
  18. #define GL_MIN 0x8007
  19. #define GL_MAX 0x8008
  20. #define GL_FUNC_ADD 0x8006
  21. #define GL_FUNC_SUBTRACT 0x800A
  22. #define GL_FUNC_REVERSE_SUBTRACT 0x800B
  23. #endif
  24. #ifndef GL_LOGIC_OP
  25. #define GL_LOGIC_OP 0x0BF1
  26. #endif
  27. #ifndef GL_ALPHA_MIN_SGIX
  28. #define GL_ALPHA_MIN_SGIX 0x8320
  29. #define GL_ALPHA_MAX_SGIX 0x8321
  30. #endif
  31. namespace osg {
  32. /** Encapsulates OpenGL BlendEquation state. */
  33. class OSG_EXPORT BlendEquation : public StateAttribute
  34. {
  35. public :
  36. enum Equation {
  37. RGBA_MIN = GL_MIN,
  38. RGBA_MAX = GL_MAX,
  39. ALPHA_MIN = GL_ALPHA_MIN_SGIX,
  40. ALPHA_MAX = GL_ALPHA_MAX_SGIX,
  41. LOGIC_OP = GL_LOGIC_OP,
  42. FUNC_ADD = GL_FUNC_ADD,
  43. FUNC_SUBTRACT = GL_FUNC_SUBTRACT,
  44. FUNC_REVERSE_SUBTRACT = GL_FUNC_REVERSE_SUBTRACT
  45. };
  46. BlendEquation();
  47. BlendEquation(Equation equation);
  48. BlendEquation(Equation equationRGB, Equation equationAlpha);
  49. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  50. BlendEquation(const BlendEquation& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  51. StateAttribute(trans,copyop),
  52. _equationRGB(trans._equationRGB),
  53. _equationAlpha(trans._equationAlpha){}
  54. META_StateAttribute(osg, BlendEquation,BLENDEQUATION);
  55. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  56. virtual int compare(const StateAttribute& sa) const
  57. {
  58. // Check for equal types, then create the rhs variable
  59. // used by the COMPARE_StateAttribute_Parameter macros below.
  60. COMPARE_StateAttribute_Types(BlendEquation,sa)
  61. // Compare each parameter in turn against the rhs.
  62. COMPARE_StateAttribute_Parameter(_equationRGB)
  63. COMPARE_StateAttribute_Parameter(_equationAlpha)
  64. return 0; // Passed all the above comparison macros, so must be equal.
  65. }
  66. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  67. {
  68. usage.usesMode(GL_BLEND);
  69. return true;
  70. }
  71. inline void setEquation(Equation equation) { _equationRGB = _equationAlpha = equation; }
  72. inline Equation getEquation() const { return _equationRGB; }
  73. inline void setEquationRGB(Equation equation) { _equationRGB = equation; }
  74. inline Equation getEquationRGB() const { return _equationRGB; }
  75. inline void setEquationAlpha(Equation equation) { _equationAlpha = equation; }
  76. inline Equation getEquationAlpha() const { return _equationAlpha; }
  77. virtual void apply(State& state) const;
  78. protected :
  79. virtual ~BlendEquation();
  80. Equation _equationRGB, _equationAlpha;
  81. };
  82. }
  83. #endif