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