fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Base / OSGLight.cpp
blob02e5f36ffe9a0e350c74abb8eae871b479aed40b
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include "OSGGL.h"
46 #include "OSGRenderAction.h"
47 #include "OSGLightEngine.h"
48 #include "OSGLight.h"
50 OSG_USING_NAMESPACE
52 // Documentation for this class is emited in the
53 // OSGLightBase.cpp file.
54 // To modify it, please change the .fcd file (OSGLight.fcd) and
55 // regenerate the base file.
57 /*-------------------------------------------------------------------------*/
58 /* Set */
60 void Light::setAmbient(Real32 rRed,
61 Real32 rGreen,
62 Real32 rBlue,
63 Real32 rAlpha)
65 editSField(AmbientFieldMask);
67 _sfAmbient.getValue().setValuesRGBA(rRed, rGreen, rBlue, rAlpha);
70 void Light::setDiffuse(Real32 rRed,
71 Real32 rGreen,
72 Real32 rBlue,
73 Real32 rAlpha)
75 editSField(DiffuseFieldMask);
77 _sfDiffuse.getValue().setValuesRGBA(rRed, rGreen, rBlue, rAlpha);
80 void Light::setSpecular(Real32 rRed,
81 Real32 rGreen,
82 Real32 rBlue,
83 Real32 rAlpha)
85 editSField(SpecularFieldMask);
87 _sfSpecular.getValue().setValuesRGBA(rRed, rGreen, rBlue, rAlpha);
90 /*-------------------------------------------------------------------------*/
91 /* Chunk */
93 LightChunk *Light::getChunk(void) const
95 return _pChunk;
98 void Light::makeChunk(void)
100 if(_pChunk == NULL)
102 _pChunk = LightChunk::createLocal();
105 _pChunk->setBeacon (getBeacon ());
106 _pChunk->setAmbient (getAmbient ());
107 _pChunk->setDiffuse (getDiffuse ());
108 _pChunk->setSpecular(getSpecular());
111 /*-------------------------------------------------------------------------*/
112 /* Sync */
114 void Light::changed(ConstFieldMaskArg whichField,
115 UInt32 origin,
116 BitVector details)
118 makeChunk();
120 Inherited::changed(whichField, origin, details);
124 /*-------------------------------------------------------------------------*/
125 /* Dump */
127 void Light::dump( UInt32 uiIndent,
128 const BitVector bvFlags) const
130 Inherited::dump(uiIndent, bvFlags);
133 /*-------------------------------------------------------------------------*/
134 /* Constructors */
136 Light::Light(void) :
137 Inherited ( ),
138 _pChunk (NULL)
142 Light::Light(const Light &source) :
143 Inherited (source ),
144 _pChunk (source._pChunk )
148 /*-------------------------------------------------------------------------*/
149 /* Destructor */
151 Light::~Light(void)
155 /*-------------------------------------------------------------------------*/
156 /* Rendering */
158 Action::ResultE Light::renderEnter(LightEngine::LightTypeE eType,
159 StatElemDesc<StatIntElem> &oStatElem,
160 RenderAction *action )
162 Action::ResultE r = Action::Continue;
164 if(this->getOn() == false)
165 return Action::Continue;
167 if(action->getActivePartition()->getStatCollector() != NULL)
169 action->getActivePartition()->getStatCollector()->getElem(
170 oStatElem)->inc();
173 LightEngine *pLightEngine = this->getLightEngine();
175 if(pLightEngine != NULL && pLightEngine->getEnabled() == true)
177 r = pLightEngine->runOnEnter(this, eType, action);
179 else
181 // ok we can cull the light only when it is invisible and has
182 // no LightEnv parent and local lights are enabled!
183 if (action->pushVisibility())
185 if(action->selectVisibles() == 0)
187 action->popVisibility();
188 return Action::Skip;
192 StateChunk *pChunk = this->getChunk();
194 UInt32 uiSlot = pChunk->getClassId();
196 Int32 iLightIndex = action->allocateLightIndex();
198 action->pushState();
200 if(iLightIndex >= 0)
202 action->addOverride(uiSlot + iLightIndex, pChunk);
204 else
206 SWARNING << "maximum light source limit ("
207 << -iLightIndex
208 << ") is reached"
209 << " skipping light sources!"
210 << std::endl;
214 return r;
217 Action::ResultE Light::renderLeave(LightEngine::LightTypeE eType,
218 Action *action)
220 Action::ResultE r = Action::Continue;
221 RenderAction *a = dynamic_cast<RenderAction *>(action);
223 if(this->getOn() == false)
224 return Action::Continue;
226 LightEngine *pLightEngine = this->getLightEngine();
228 if(pLightEngine != NULL && pLightEngine->getEnabled() == true)
230 r = pLightEngine->runOnLeave(this, eType, a);
232 else
234 a->releaseLightIndex();
235 a->popState();
237 a->popVisibility();
240 return r;
243 /*-------------------------------------------------------------------------*/
244 /* Init */
246 void Light::resolveLinks(void)
248 Inherited::resolveLinks();
250 _pChunk = NULL;
253 //! initialize the static features of the class, e.g. action callbacks
255 void Light::initMethod(InitPhase ePhase)
257 Inherited::initMethod(ePhase);