BlendColor 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_BLENDCOLOR
  14. #define OSG_BLENDCOLOR 1
  15. #include <osg/GL>
  16. #include <osg/StateAttribute>
  17. #include <osg/ref_ptr>
  18. #include <osg/Vec4>
  19. namespace osg {
  20. /** Encapsulates OpenGL blend/transparency state. */
  21. class OSG_EXPORT BlendColor : public StateAttribute
  22. {
  23. public :
  24. BlendColor();
  25. BlendColor(const osg::Vec4& constantColor);
  26. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  27. BlendColor(const BlendColor& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  28. StateAttribute(trans,copyop),
  29. _constantColor(trans._constantColor) {}
  30. META_StateAttribute(osg, BlendColor,BLENDCOLOR);
  31. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  32. virtual int compare(const StateAttribute& sa) const
  33. {
  34. // Check for equal types, then create the rhs variable
  35. // used by the COMPARE_StateAttribute_Parameter macros below.
  36. COMPARE_StateAttribute_Types(BlendColor,sa)
  37. // Compare each parameter in turn against the rhs.
  38. COMPARE_StateAttribute_Parameter(_constantColor)
  39. return 0; // Passed all the above comparison macros, so must be equal.
  40. }
  41. virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
  42. {
  43. usage.usesMode(GL_BLEND);
  44. return true;
  45. }
  46. void setConstantColor(const osg::Vec4& color) { _constantColor = color; }
  47. inline osg::Vec4& getConstantColor() { return _constantColor; }
  48. inline const osg::Vec4& getConstantColor() const { return _constantColor; }
  49. virtual void apply(State& state) const;
  50. protected :
  51. virtual ~BlendColor();
  52. osg::Vec4 _constantColor;
  53. };
  54. }
  55. #endif