1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
46 #include "OSGRenderAction.h"
47 #include "OSGLightEngine.h"
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 /*-------------------------------------------------------------------------*/
60 void Light::setAmbient(Real32 rRed
,
65 editSField(AmbientFieldMask
);
67 _sfAmbient
.getValue().setValuesRGBA(rRed
, rGreen
, rBlue
, rAlpha
);
70 void Light::setDiffuse(Real32 rRed
,
75 editSField(DiffuseFieldMask
);
77 _sfDiffuse
.getValue().setValuesRGBA(rRed
, rGreen
, rBlue
, rAlpha
);
80 void Light::setSpecular(Real32 rRed
,
85 editSField(SpecularFieldMask
);
87 _sfSpecular
.getValue().setValuesRGBA(rRed
, rGreen
, rBlue
, rAlpha
);
90 /*-------------------------------------------------------------------------*/
93 LightChunk
*Light::getChunk(void) const
98 void Light::makeChunk(void)
102 _pChunk
= LightChunk::createLocal();
105 _pChunk
->setBeacon (getBeacon ());
106 _pChunk
->setAmbient (getAmbient ());
107 _pChunk
->setDiffuse (getDiffuse ());
108 _pChunk
->setSpecular(getSpecular());
111 /*-------------------------------------------------------------------------*/
114 void Light::changed(ConstFieldMaskArg whichField
,
120 Inherited::changed(whichField
, origin
, details
);
124 /*-------------------------------------------------------------------------*/
127 void Light::dump( UInt32 uiIndent
,
128 const BitVector bvFlags
) const
130 Inherited::dump(uiIndent
, bvFlags
);
133 /*-------------------------------------------------------------------------*/
142 Light::Light(const Light
&source
) :
144 _pChunk (source
._pChunk
)
148 /*-------------------------------------------------------------------------*/
155 /*-------------------------------------------------------------------------*/
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(
173 LightEngine
*pLightEngine
= this->getLightEngine();
175 if(pLightEngine
!= NULL
&& pLightEngine
->getEnabled() == true)
177 r
= pLightEngine
->runOnEnter(this, eType
, action
);
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();
192 StateChunk
*pChunk
= this->getChunk();
194 UInt32 uiSlot
= pChunk
->getClassId();
196 Int32 iLightIndex
= action
->allocateLightIndex();
202 action
->addOverride(uiSlot
+ iLightIndex
, pChunk
);
206 SWARNING
<< "maximum light source limit ("
209 << " skipping light sources!"
217 Action::ResultE
Light::renderLeave(LightEngine::LightTypeE eType
,
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
);
234 a
->releaseLightIndex();
243 /*-------------------------------------------------------------------------*/
246 void Light::resolveLinks(void)
248 Inherited::resolveLinks();
253 //! initialize the static features of the class, e.g. action callbacks
255 void Light::initMethod(InitPhase ePhase
)
257 Inherited::initMethod(ePhase
);