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 \*---------------------------------------------------------------------------*/
39 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
46 #include "OSGConfig.h"
50 #include "OSGLightModelChunk.h"
51 #include "OSGDrawEnv.h"
55 // Documentation for this class is emited in the
56 // OSGLightModelChunkBase.cpp file.
57 // To modify it, please change the .fcd file (OSGLightModelChunk.fcd) and
58 // regenerate the base file.
60 /***************************************************************************\
62 \***************************************************************************/
63 StateChunkClass
LightModelChunk::_class("LightModel", 1, 100);
65 /***************************************************************************\
67 \***************************************************************************/
69 void LightModelChunk::initMethod(InitPhase ePhase
)
71 Inherited::initMethod(ePhase
);
75 /***************************************************************************\
77 \***************************************************************************/
79 /*-------------------------------------------------------------------------*\
81 \*-------------------------------------------------------------------------*/
83 /*----------------------- constructors & destructors ----------------------*/
85 LightModelChunk::LightModelChunk(void) :
90 LightModelChunk::LightModelChunk(const LightModelChunk
&source
) :
95 LightModelChunk::~LightModelChunk(void)
99 /*----------------------------- class specific ----------------------------*/
101 const StateChunkClass
*LightModelChunk::getClass(void) const
106 void LightModelChunk::changed(ConstFieldMaskArg whichField
,
110 Inherited::changed(whichField
, origin
, details
);
113 void LightModelChunk::dump( UInt32 uiIndent
,
114 const BitVector bvFlags
) const
116 Inherited::dump(uiIndent
, bvFlags
);
118 if((bvFlags
& AmbientFieldMask
) != 0)
120 indentLog(uiIndent
, PLOG
);
121 PLOG
<< "ambient " << _sfAmbient
.getValue() << "\n";
124 if((bvFlags
& ColorControlFieldMask
) != 0)
126 indentLog(uiIndent
, PLOG
);
127 PLOG
<< "colorControl "
128 << GLDefineMapper::the()->toString(_sfColorControl
.getValue())
132 if((bvFlags
& LocalViewerFieldMask
) != 0)
134 indentLog(uiIndent
, PLOG
);
135 PLOG
<< "localViewer " << _sfLocalViewer
.getValue() << "\n";
139 /*------------------------------ State ------------------------------------*/
141 void LightModelChunk::activate(DrawEnv
*pEnv
, UInt32
)
143 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
144 pEnv
->incNumChunkChanges();
146 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
,
147 _sfAmbient
.getValue().getValuesRGBA());
149 if(_sfColorControl
.getValue() != GL_SINGLE_COLOR
)
151 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL
, _sfColorControl
.getValue());
154 if(_sfLocalViewer
.getValue())
156 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER
, 1);
160 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER
, 0);
167 void LightModelChunk::changeFrom(DrawEnv
*pEnv
,
168 StateChunk
*old_chunk
,
171 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
172 LightModelChunk
*old
= dynamic_cast<LightModelChunk
*>(old_chunk
);
176 FWARNING(( "LightModelChunk::changeFrom: caught "
177 "non-LightModelChunk!\n"));
181 // LightModelChunk didn't change so do nothing.
185 pEnv
->incNumChunkChanges();
187 if(old
->_sfAmbient
.getValue() != _sfAmbient
.getValue())
189 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
,
190 _sfAmbient
.getValue().getValuesRGBA());
193 if(_sfColorControl
.getValue() != old
->_sfColorControl
.getValue())
195 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL
, _sfColorControl
.getValue());
198 if(_sfLocalViewer
.getValue() != old
->_sfLocalViewer
.getValue())
200 if(_sfLocalViewer
.getValue())
202 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER
, 1);
206 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER
, 0);
214 void LightModelChunk::deactivate(DrawEnv
*pEnv
, UInt32
)
216 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
217 GLfloat ambient
[] = {0.2f
, 0.2f
, 0.2f
, 1.0f
};
218 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, ambient
);
220 if(_sfColorControl
.getValue() != GL_SINGLE_COLOR
)
222 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL
, GL_SINGLE_COLOR
);
225 if(_sfLocalViewer
.getValue())
227 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER
, 0);
234 /*-------------------------- Comparison -----------------------------------*/
236 Real32
LightModelChunk::switchCost(StateChunk
*)
241 bool LightModelChunk::operator < (const StateChunk
&other
) const
243 return this < &other
;
246 bool LightModelChunk::operator == (const StateChunk
&other
) const
248 LightModelChunk
const *tother
= dynamic_cast<LightModelChunk
const*>(&other
);
256 if(getAmbient () != tother
->getAmbient () ||
257 getColorControl() != tother
->getColorControl() ||
258 getLocalViewer () != tother
->getLocalViewer () )
264 bool LightModelChunk::operator != (const StateChunk
&other
) const
266 return ! (*this == other
);