LightSource 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 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_LIGHTSOURCE
  14. #define OSG_LIGHTSOURCE 1
  15. #include <osg/NodeVisitor>
  16. #include <osg/Light>
  17. #include <osg/Group>
  18. namespace osg {
  19. /** Leaf Node for defining a light in the scene. */
  20. class OSG_EXPORT LightSource : public Group
  21. {
  22. public:
  23. LightSource();
  24. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  25. LightSource(const LightSource& ls,
  26. const CopyOp& copyop=CopyOp::SHALLOW_COPY):
  27. Group(ls,copyop),
  28. _value(ls._value),
  29. _light(dynamic_cast<osg::Light*>(copyop(ls._light.get()))),
  30. _referenceFrame(ls._referenceFrame) {}
  31. META_Node(osg, LightSource);
  32. enum ReferenceFrame
  33. {
  34. RELATIVE_RF,
  35. ABSOLUTE_RF
  36. };
  37. /** Set the light sources's ReferenceFrame, either to be relative to its
  38. * parent reference frame, or relative to an absolute coordinate
  39. * frame. RELATIVE_RF is the default.
  40. * Note: setting the ReferenceFrame to be ABSOLUTE_RF will
  41. * also set the CullingActive flag on the light source, and hence all
  42. * of its parents, to false, thereby disabling culling of it and
  43. * all its parents. This is necessary to prevent inappropriate
  44. * culling, but may impact cull times if the absolute light source is
  45. * deep in the scene graph. It is therefore recommended to only use
  46. * absolute light source at the top of the scene.
  47. */
  48. void setReferenceFrame(ReferenceFrame rf);
  49. ReferenceFrame getReferenceFrame() const { return _referenceFrame; }
  50. /** Set the attached light. */
  51. void setLight(Light* light);
  52. /** Get the attached light. */
  53. inline Light* getLight() { return _light.get(); }
  54. /** Get the const attached light. */
  55. inline const Light* getLight() const { return _light.get(); }
  56. /** Set the GLModes on StateSet associated with the LightSource. */
  57. void setStateSetModes(StateSet&,StateAttribute::GLModeValue) const;
  58. /** Set up the local StateSet. */
  59. void setLocalStateSetModes(StateAttribute::GLModeValue value = StateAttribute::ON);
  60. /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
  61. virtual void setThreadSafeRefUnref(bool threadSafe);
  62. virtual BoundingSphere computeBound() const;
  63. protected:
  64. virtual ~LightSource();
  65. StateAttribute::GLModeValue _value;
  66. ref_ptr<Light> _light;
  67. ReferenceFrame _referenceFrame;
  68. };
  69. }
  70. #endif