ColorMatrix 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_COLORMATRIX
  14. #define OSG_COLORMATRIX 1
  15. #include <osg/Matrix>
  16. #include <osg/StateAttribute>
  17. namespace osg {
  18. /** Encapsulates OpenGL color matrix functionality. */
  19. class OSG_EXPORT ColorMatrix : public StateAttribute
  20. {
  21. public :
  22. ColorMatrix();
  23. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  24. ColorMatrix(const ColorMatrix& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  25. StateAttribute(cm,copyop),
  26. _matrix(cm._matrix) {}
  27. META_StateAttribute(osg, ColorMatrix, COLORMATRIX);
  28. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  29. virtual int compare(const StateAttribute& sa) const
  30. {
  31. // Check for equal types, then create the rhs variable
  32. // used by the COMPARE_StateAttribute_Parameter macros below.
  33. COMPARE_StateAttribute_Types(ColorMatrix,sa)
  34. // Compare each parameter in turn against the rhs.
  35. COMPARE_StateAttribute_Parameter(_matrix)
  36. return 0; // Passed all the above comparison macros, so must be equal.
  37. }
  38. /** Sets the color matrix. */
  39. inline void setMatrix(const Matrix& matrix) { _matrix = matrix; }
  40. /** Gets the color matrix. */
  41. inline Matrix& getMatrix() { return _matrix; }
  42. /** Gets the const color matrix. */
  43. inline const Matrix& getMatrix() const { return _matrix; }
  44. /** Applies as OpenGL texture matrix. */
  45. virtual void apply(State& state) const;
  46. protected:
  47. virtual ~ColorMatrix( void );
  48. Matrix _matrix;
  49. };
  50. }
  51. #endif