fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Base / OSGMultiLightChunk.h
blob7dc48c6c9edce85eeaca522144ae27ae6706ed0f
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * * * This library is free software; you can redistribute it and/or modify it *
15 * under the terms of the GNU Library General Public License as published *
16 * by the Free Software Foundation, version 2. *
17 * *
18 * This library is distributed in the hope that it will be useful, but *
19 * WITHOUT ANY WARRANTY; without even the implied warranty of *
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
21 * Library General Public License for more details. *
22 * *
23 * You should have received a copy of the GNU Library General Public *
24 * License along with this library; if not, write to the Free Software *
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
26 * *
27 \*---------------------------------------------------------------------------*/
28 /*---------------------------------------------------------------------------*\
29 * Changes *
30 * *
31 * *
32 * *
33 * *
34 * *
35 * *
36 \*---------------------------------------------------------------------------*/
38 #ifndef _OSGMULTILIGHTCHUNK_H_
39 #define _OSGMULTILIGHTCHUNK_H_
40 #ifdef __sgi
41 #pragma once
42 #endif
44 #include "OSGMultiLightChunkBase.h"
46 OSG_BEGIN_NAMESPACE
48 struct OSG_SYSTEM_DLLMAPPING MultiLight
50 enum Type
52 POINT_LIGHT = 1,
53 DIRECTIONAL_LIGHT = 2,
54 SPOT_LIGHT = 3,
55 CINEMA_LIGHT = 4
58 enum Layout {
59 SIMPLE_LAYOUT = 0x01, // Color,Intensity,RangeCutOff
60 RANGE_LAYOUT = 0x02, // RangeCutOn, RangeCutOff
61 ZONE_LAYOUT = 0x04, // RangeNearZone, RangeFarZone
62 OPENGL_LAYOUT = 0x08, // Ambient-, Diffuse-, Specular Intensity, Attenuation
63 CINEMA_LAYOUT = 0x10 // SuperEllipses
66 explicit MultiLight(Type e);
68 Pnt3f position;
69 Vec3f direction;
70 Color3f color;
71 Real32 intensity;
72 Vec3f ambientIntensity;
73 Vec3f diffuseIntensity;
74 Vec3f specularIntensity;
75 Vec3f attenuation;
76 Real32 spotlightAngle;
77 Real32 spotExponent;
78 Real32 innerSuperEllipsesWidth;
79 Real32 innerSuperEllipsesHeight;
80 Real32 outerSuperEllipsesWidth;
81 Real32 outerSuperEllipsesHeight;
82 Real32 superEllipsesRoundness;
83 Real32 superEllipsesTwist;
84 Real32 rangeCutOn;
85 Real32 rangeCutOff;
86 Real32 rangeNearZone;
87 Real32 rangeFarZone;
88 Type type;
89 bool enabled;
90 NodeRefPtr beacon;
93 /*! \brief MultiLightChunk class. See \ref
94 PageSystemMultiLightChunk for a description.
97 class OSG_SYSTEM_DLLMAPPING MultiLightChunk : public MultiLightChunkBase
99 protected:
101 /*========================== PUBLIC =================================*/
103 public:
105 typedef MultiLightChunkBase Inherited;
106 typedef MultiLightChunk Self;
108 /*---------------------------------------------------------------------*/
109 /*! \name Interface */
110 /*! \{ */
112 UInt32 addLight (MultiLight::Type eType);
113 UInt32 addLight (const MultiLight& light);
114 void updateLight (const UInt32 idx, const MultiLight& light);
115 void removeLight (const UInt32 idx);
116 void clearLights ();
117 UInt32 numLights () const;
118 void setLayoutType (UInt32 layout);
120 const Pnt3f &getPosition (const UInt32 idx) const;
121 const Vec3f &getDirection (const UInt32 idx) const;
122 const Color3f &getColor (const UInt32 idx) const;
123 Real32 getIntensity (const UInt32 idx) const;
124 const Vec3f &getAmbientIntensity (const UInt32 idx) const;
125 const Vec3f &getDiffuseIntensity (const UInt32 idx) const;
126 const Vec3f &getSpecularIntensity (const UInt32 idx) const;
127 const Vec3f &getAttenuation (const UInt32 idx) const;
128 Real32 getRange (const UInt32 idx) const;
129 Real32 getSpotlightAngle (const UInt32 idx) const;
130 Real32 getSpotExponent (const UInt32 idx) const;
131 Real32 getInnerSuperEllipsesWidth (const UInt32 idx) const;
132 Real32 getInnerSuperEllipsesHeight (const UInt32 idx) const;
133 Real32 getOuterSuperEllipsesWidth (const UInt32 idx) const;
134 Real32 getOuterSuperEllipsesHeight (const UInt32 idx) const;
135 Real32 getSuperEllipsesRoundness (const UInt32 idx) const;
136 Real32 getSuperEllipsesTwist (const UInt32 idx) const;
137 Real32 getRangeCutOn (const UInt32 idx) const;
138 Real32 getRangeCutOff (const UInt32 idx) const;
139 Real32 getRangeNearZone (const UInt32 idx) const;
140 Real32 getRangeFarZone (const UInt32 idx) const;
141 UInt8 getType (const UInt32 idx) const;
142 bool getEnabled (const UInt32 idx) const;
143 Node* getBeacon (const UInt32 idx) const;
145 void setPosition (const UInt32 idx, const Pnt3f& position);
146 void setDirection (const UInt32 idx, const Vec3f& direction);
147 void setColor (const UInt32 idx, const Color3f& color);
148 void setIntensity (const UInt32 idx, Real32 intensity);
149 void setAmbientIntensity (const UInt32 idx, const Vec3f& intensity);
150 void setDiffuseIntensity (const UInt32 idx, const Vec3f& intensity);
151 void setSpecularIntensity (const UInt32 idx, const Vec3f& intensity);
152 void setAttenuation (const UInt32 idx, const Vec3f& attenuation);
153 void setRange (const UInt32 idx, Real32 range);
154 void setSpotlightAngle (const UInt32 idx, Real32 angle);
155 void setSpotExponent (const UInt32 idx, Real32 exponent);
156 void setInnerSuperEllipsesWidth (const UInt32 idx, Real32 width);
157 void setInnerSuperEllipsesHeight (const UInt32 idx, Real32 height);
158 void setOuterSuperEllipsesWidth (const UInt32 idx, Real32 width);
159 void setOuterSuperEllipsesHeight (const UInt32 idx, Real32 height);
160 void setSuperEllipsesRoundness (const UInt32 idx, Real32 roundness);
161 void setSuperEllipsesTwist (const UInt32 idx, Real32 twist);
162 void setRangeCutOn (const UInt32 idx, Real32 cutOn);
163 void setRangeCutOff (const UInt32 idx, Real32 cutOff);
164 void setRangeNearZone (const UInt32 idx, Real32 nearZone);
165 void setRangeFarZone (const UInt32 idx, Real32 farZone);
166 void setType (const UInt32 idx, MultiLight::Type eType);
167 void setEnabled (const UInt32 idx, bool flag);
168 void setBeacon (const UInt32 idx, Node* const beacon);
170 void changedBeacon ();
172 std::string getLightProgSnippet () const;
174 /*! \} */
176 /*---------------------------------------------------------------------*/
177 /*! \name Sync */
178 /*! \{ */
180 virtual void changed(ConstFieldMaskArg whichField,
181 UInt32 origin,
182 BitVector details );
184 /*! \} */
185 /*---------------------------------------------------------------------*/
186 /*! \name Output */
187 /*! \{ */
189 virtual void dump( UInt32 uiIndent = 0,
190 const BitVector bvFlags = 0) const;
192 /*! \} */
193 /*---------------------------------------------------------------------*/
194 /*! \name State */
195 /*! \{ */
197 virtual void activate (DrawEnv *pEnv,
198 UInt32 index = 0);
200 virtual void changeFrom (DrawEnv *pEnv,
201 StateChunk *pOld,
202 UInt32 index = 0);
204 virtual void deactivate (DrawEnv *pEnv,
205 UInt32 index = 0);
207 /*! \} */
208 /*---------------------------------------------------------------------*/
209 /*! \name OpenGL handling */
210 /*! \{ */
211 /*! \} */
212 /*========================= PROTECTED ===============================*/
214 protected:
215 bool _bUpdateBuffer;
217 ChangedFunctor _cameraCB;
219 // Variables should all be in MultiLightChunkBase.
221 void onCreate (const MultiLightChunk *source = NULL);
222 void onCreateAspect(const MultiLightChunk *createAspect,
223 const MultiLightChunk *source = NULL);
224 void onDestroy ( UInt32 uiContainerId );
226 /*---------------------------------------------------------------------*/
227 /*! \name Constructors */
228 /*! \{ */
230 MultiLightChunk(void);
231 MultiLightChunk(const MultiLightChunk &source);
233 /*! \} */
234 /*---------------------------------------------------------------------*/
235 /*! \name Destructors */
236 /*! \{ */
238 virtual ~MultiLightChunk(void);
240 /*! \} */
241 /*---------------------------------------------------------------------*/
242 /*! \name Init */
243 /*! \{ */
245 static void initMethod(InitPhase ePhase);
247 /*! \} */
248 /*========================== PRIVATE ================================*/
250 private:
252 friend class FieldContainer;
253 friend class MultiLightChunkBase;
255 /*---------------------------------------------------------------------*/
256 /*! \name buffer */
257 /*! \{ */
258 void transformToWorldSpace (DrawEnv* pEnv,
259 Node* beacon,
260 const Pnt3f& position_bs,
261 const Vec3f& direction_bs,
262 Pnt3f& position_ws,
263 Vec3f& direction_ws) const;
265 void transformToEyeSpace (DrawEnv* pEnv,
266 Node* beacon,
267 const Pnt3f& position_bs,
268 const Vec3f& direction_bs,
269 Pnt3f& position_es,
270 Vec3f& direction_es) const;
272 void calcDirectionalLightMatrices (DrawEnv* pEnv,
273 Node* beacon,
274 const Vec3f& direction_bs,
275 Matrix& matLSFromWS,
276 Matrix& matLSFromES) const;
278 void calcPointLightMatrices (DrawEnv* pEnv,
279 Node* beacon,
280 const Pnt3f& position_bs,
281 Matrix& matLSFromWS,
282 Matrix& matLSFromES) const;
284 void calcSpotLightMatrices (DrawEnv* pEnv,
285 Node* beacon,
286 const Pnt3f& position_bs,
287 const Vec3f& direction_bs,
288 Matrix& matLSFromWS,
289 Matrix& matLSFromES) const;
291 void calcPointLightRange (DrawEnv* pEnv,
292 const Vec3f attenuation,
293 Real32 threshold,
294 Real32& outNear,
295 Real32& outFar) const;
297 std::size_t calcLightBufferSize () const;
298 std::vector<UInt8> createLightBuffer (DrawEnv* pEnv) const;
299 void createLightState (DrawEnv* pEnv);
300 void updateLightState (DrawEnv* pEnv);
302 /*! \} */
304 bool check_invariant() const;
306 // prohibit default functions (move to 'public' if you need one)
307 void operator =(const MultiLightChunk &source);
310 typedef MultiLightChunk *MultiLightChunkP;
312 OSG_END_NAMESPACE
314 #include "OSGMultiLightChunkBase.inl"
315 #include "OSGMultiLightChunk.inl"
317 #endif /* _OSGMULTILIGHTCHUNK_H_ */