LightModel 2.8 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_LIGHTMODEL
  14. #define OSG_LIGHTMODEL 1
  15. #include <osg/StateAttribute>
  16. #include <osg/Vec4>
  17. namespace osg {
  18. class OSG_EXPORT LightModel : public StateAttribute
  19. {
  20. public :
  21. LightModel();
  22. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  23. LightModel(const LightModel& lw,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  24. StateAttribute(lw,copyop),
  25. _ambient(lw._ambient),
  26. _colorControl(lw._colorControl),
  27. _localViewer(lw._localViewer),
  28. _twoSided(lw._twoSided) {}
  29. META_StateAttribute(osg, LightModel, LIGHTMODEL);
  30. /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
  31. virtual int compare(const StateAttribute& sa) const
  32. {
  33. // check the types are equal and then create the rhs variable
  34. // used by the COMPARE_StateAttribute_Parameter macros below.
  35. COMPARE_StateAttribute_Types(LightModel,sa)
  36. // compare each parameter in turn against the rhs.
  37. COMPARE_StateAttribute_Parameter(_ambient)
  38. COMPARE_StateAttribute_Parameter(_colorControl)
  39. COMPARE_StateAttribute_Parameter(_localViewer)
  40. COMPARE_StateAttribute_Parameter(_twoSided)
  41. return 0; // passed all the above comparison macros, must be equal.
  42. }
  43. void setAmbientIntensity(const osg::Vec4& ambient) { _ambient = ambient; }
  44. const osg::Vec4& getAmbientIntensity() const { return _ambient; }
  45. enum ColorControl
  46. {
  47. SEPARATE_SPECULAR_COLOR,
  48. SINGLE_COLOR
  49. };
  50. void setColorControl(ColorControl cc) { _colorControl = cc; }
  51. inline ColorControl getColorControl() const { return _colorControl; }
  52. void setLocalViewer(bool localViewer) { _localViewer=localViewer; }
  53. inline bool getLocalViewer() const { return _localViewer; }
  54. void setTwoSided(bool twoSided) { _twoSided = twoSided; }
  55. inline bool getTwoSided() const { return _twoSided; }
  56. virtual void apply(State& state) const;
  57. protected :
  58. virtual ~LightModel();
  59. osg::Vec4 _ambient;
  60. ColorControl _colorControl;
  61. bool _localViewer;
  62. bool _twoSided;
  63. };
  64. }
  65. #endif