ColorMask 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_COLORMASK
  14. #define OSG_COLORMASK 1
  15. #include <osg/Export>
  16. #include <osg/StateAttribute>
  17. namespace osg {
  18. /** Encapsulates OpenGL glColorMaskFunc/Op/Mask functions.
  19. */
  20. class OSG_EXPORT ColorMask : public StateAttribute
  21. {
  22. public :
  23. ColorMask();
  24. ColorMask(bool red,bool green,bool blue,bool alpha):
  25. _red(red),
  26. _green(green),
  27. _blue(blue),
  28. _alpha(alpha) {}
  29. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  30. ColorMask(const ColorMask& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  31. StateAttribute(cm,copyop),
  32. _red(cm._red),
  33. _green(cm._green),
  34. _blue(cm._blue),
  35. _alpha(cm._alpha) {}
  36. META_StateAttribute(osg, ColorMask, COLORMASK);
  37. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  38. virtual int compare(const StateAttribute& sa) const
  39. {
  40. // Check for equal types, then create the rhs variable
  41. // used by the COMPARE_StateAttribute_Parameter macros below.
  42. COMPARE_StateAttribute_Types(ColorMask,sa)
  43. // Compare each parameter in turn against the rhs.
  44. COMPARE_StateAttribute_Parameter(_red)
  45. COMPARE_StateAttribute_Parameter(_green)
  46. COMPARE_StateAttribute_Parameter(_blue)
  47. COMPARE_StateAttribute_Parameter(_alpha)
  48. return 0; // Passed all the above comparison macros, so must be equal.
  49. }
  50. inline void setMask(bool red,bool green,bool blue,bool alpha)
  51. {
  52. _red = red;
  53. _green = green;
  54. _blue = blue;
  55. _alpha = alpha;
  56. }
  57. inline void setRedMask(bool mask) { _red=mask; }
  58. inline bool getRedMask() const { return _red; }
  59. inline void setGreenMask(bool mask) { _green=mask; }
  60. inline bool getGreenMask() const { return _green; }
  61. inline void setBlueMask(bool mask) { _blue=mask; }
  62. inline bool getBlueMask() const { return _blue; }
  63. inline void setAlphaMask(bool mask) { _alpha=mask; }
  64. inline bool getAlphaMask() const { return _alpha; }
  65. virtual void apply(State& state) const;
  66. protected:
  67. virtual ~ColorMask();
  68. bool _red;
  69. bool _green;
  70. bool _blue;
  71. bool _alpha;
  72. };
  73. }
  74. #endif