TexEnv 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_TEXENV
  14. #define OSG_TEXENV 1
  15. #include <osg/GL>
  16. #include <osg/StateAttribute>
  17. #include <osg/Vec4>
  18. #ifndef OSG_GL_FIXED_FUNCTION_AVAILABLE
  19. #define GL_MODULATE 0x2100
  20. #define GL_ADD 0x0104
  21. #define GL_MODULATE 0x2100
  22. #define GL_DECAL 0x2101
  23. #endif
  24. namespace osg {
  25. /** TexEnv encapsulates the OpenGL glTexEnv (texture environment) state.
  26. */
  27. class OSG_EXPORT TexEnv : public StateAttribute
  28. {
  29. public :
  30. enum Mode {
  31. DECAL = GL_DECAL,
  32. MODULATE = GL_MODULATE,
  33. BLEND = GL_BLEND,
  34. REPLACE = GL_REPLACE,
  35. ADD = GL_ADD
  36. };
  37. TexEnv(Mode mode=MODULATE);
  38. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  39. TexEnv(const TexEnv& texenv,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  40. StateAttribute(texenv,copyop),
  41. _mode(texenv._mode),
  42. _color(texenv._color) {}
  43. META_StateAttribute(osg, TexEnv, TEXENV);
  44. virtual bool isTextureAttribute() const { return true; }
  45. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  46. virtual int compare(const StateAttribute& sa) const
  47. {
  48. // Check for equal types, then create the rhs variable
  49. // used by the COMPARE_StateAttribute_Parameter macros below.
  50. COMPARE_StateAttribute_Types(TexEnv,sa)
  51. // Compare each parameter in turn against the rhs.
  52. COMPARE_StateAttribute_Parameter(_mode)
  53. COMPARE_StateAttribute_Parameter(_color)
  54. return 0; // Passed all the above comparison macros, so must be equal.
  55. }
  56. void setMode( Mode mode ) { _mode = mode; }
  57. Mode getMode() const { return _mode; }
  58. void setColor( const Vec4& color ) { _color = color; }
  59. Vec4& getColor() { return _color; }
  60. const Vec4& getColor() const { return _color; }
  61. virtual void apply(State& state) const;
  62. protected :
  63. virtual ~TexEnv( void );
  64. Mode _mode;
  65. osg::Vec4 _color;
  66. };
  67. }
  68. #endif