changed: gcc8 base update
[opensg.git] / Source / System / State / OpenGL / OSGLightModelChunk.cpp
blob017966a0a015f53e6bba9ff40824cdede98df831
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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
46 #include "OSGConfig.h"
48 #include "OSGGLEXT.h"
50 #include "OSGLightModelChunk.h"
51 #include "OSGDrawEnv.h"
53 OSG_USING_NAMESPACE
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 /***************************************************************************\
61 * Class variables *
62 \***************************************************************************/
63 StateChunkClass LightModelChunk::_class("LightModel", 1, 100);
65 /***************************************************************************\
66 * Class methods *
67 \***************************************************************************/
69 void LightModelChunk::initMethod(InitPhase ePhase)
71 Inherited::initMethod(ePhase);
75 /***************************************************************************\
76 * Instance methods *
77 \***************************************************************************/
79 /*-------------------------------------------------------------------------*\
80 - private -
81 \*-------------------------------------------------------------------------*/
83 /*----------------------- constructors & destructors ----------------------*/
85 LightModelChunk::LightModelChunk(void) :
86 Inherited()
90 LightModelChunk::LightModelChunk(const LightModelChunk &source) :
91 Inherited(source)
95 LightModelChunk::~LightModelChunk(void)
99 /*----------------------------- class specific ----------------------------*/
101 const StateChunkClass *LightModelChunk::getClass(void) const
103 return &_class;
106 void LightModelChunk::changed(ConstFieldMaskArg whichField,
107 UInt32 origin,
108 BitVector details)
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())
129 << "\n";
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);
158 else
160 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
162 #else
163 OSG_ASSERT(false);
164 #endif
167 void LightModelChunk::changeFrom(DrawEnv *pEnv,
168 StateChunk *old_chunk,
169 UInt32 )
171 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
172 LightModelChunk *old = dynamic_cast<LightModelChunk *>(old_chunk);
174 if(old == NULL)
176 FWARNING(( "LightModelChunk::changeFrom: caught "
177 "non-LightModelChunk!\n"));
178 return;
181 // LightModelChunk didn't change so do nothing.
182 if(old == this)
183 return;
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);
204 else
206 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
209 #else
210 OSG_ASSERT(false);
211 #endif
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);
229 #else
230 OSG_ASSERT(false);
231 #endif
234 /*-------------------------- Comparison -----------------------------------*/
236 Real32 LightModelChunk::switchCost(StateChunk *)
238 return 0;
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);
250 if(!tother)
251 return false;
253 if(tother == this)
254 return true;
256 if(getAmbient () != tother->getAmbient () ||
257 getColorControl() != tother->getColorControl() ||
258 getLocalViewer () != tother->getLocalViewer () )
259 return false;
261 return true;
264 bool LightModelChunk::operator != (const StateChunk &other) const
266 return ! (*this == other);