changed: gcc8 base update
[opensg.git] / Source / System / State / Base / OSGPolygonChunk.cpp
blob308a72a49fe956579b6408e49b7586a6fa201ee8
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 "OSGGL.h"
50 #include "OSGPolygonChunk.h"
51 #include "OSGDrawEnv.h"
53 OSG_USING_NAMESPACE
55 // Documentation for this class is emited in the
56 // OSGPolygonChunkBase.cpp file.
57 // To modify it, please change the .fcd file (OSGPolygonChunk.fcd) and
58 // regenerate the base file.
60 /***************************************************************************\
61 * Class variables *
62 \***************************************************************************/
64 #ifndef OSG_OGL_ES2
65 StateChunkClass PolygonChunk::_class("Polygon", 1, 50);
66 #else
67 StateChunkClass PolygonChunk::_class("Polygon", 1, 110);
68 #endif
70 /***************************************************************************\
71 * Class methods *
72 \***************************************************************************/
74 void PolygonChunk::initMethod(InitPhase ePhase)
76 Inherited::initMethod(ePhase);
79 /***************************************************************************\
80 * Instance methods *
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
84 - private -
85 \*-------------------------------------------------------------------------*/
88 /*------------- constructors & destructors --------------------------------*/
90 PolygonChunk::PolygonChunk(void) :
91 Inherited()
95 PolygonChunk::PolygonChunk(const PolygonChunk &source) :
96 Inherited(source)
100 PolygonChunk::~PolygonChunk(void)
104 /*------------------------- Chunk Class Access ---------------------------*/
106 const StateChunkClass *PolygonChunk::getClass(void) const
108 return &_class;
111 /*------------------------------- Sync -----------------------------------*/
113 void PolygonChunk::changed(ConstFieldMaskArg whichField,
114 UInt32 origin,
115 BitVector details)
117 Inherited::changed(whichField, origin, details);
120 /*------------------------------ Output ----------------------------------*/
122 void PolygonChunk::dump( UInt32 uiIndent,
123 const BitVector bvFlags) const
125 Inherited::dump(uiIndent, bvFlags);
129 /*------------------------------ State ------------------------------------*/
131 void PolygonChunk::activate(DrawEnv *pEnv, UInt32)
133 // cullFace
134 pEnv->incNumChunkChanges();
136 if(_sfCullFace.getValue() != GL_NONE)
138 glCullFace(_sfCullFace.getValue());
139 glEnable(GL_CULL_FACE);
142 // frontFace
144 if(_sfFrontFace.getValue() != GL_CCW)
145 glFrontFace(_sfFrontFace.getValue());
147 #ifndef OSG_OGL_ES2
148 // smooth
150 if(_sfSmooth.getValue())
151 glEnable(GL_POLYGON_SMOOTH);
152 #endif
154 #ifndef OSG_OGL_ES2
155 // mode
157 # if !defined(OSG_OGL_COREONLY)
158 if(_sfFrontMode.getValue() != GL_FILL)
159 glPolygonMode(GL_FRONT, _sfFrontMode.getValue());
161 if(_sfBackMode.getValue() != GL_FILL)
162 glPolygonMode(GL_BACK, _sfBackMode.getValue());
163 # else
164 if(_sfFrontMode.getValue() != GL_FILL)
165 glPolygonMode(GL_FRONT_AND_BACK, _sfFrontMode.getValue());
166 # endif
167 #endif
169 #ifndef OSG_OGL_ES2
170 // offset
172 if(_sfOffsetFactor.getValue() != 0.f || _sfOffsetBias.getValue() != 0.f)
173 glPolygonOffset(_sfOffsetFactor.getValue(), _sfOffsetBias.getValue());
175 if(_sfOffsetPoint.getValue())
176 glEnable(GL_POLYGON_OFFSET_POINT);
178 if(_sfOffsetLine.getValue())
179 glEnable(GL_POLYGON_OFFSET_LINE);
181 if(_sfOffsetFill.getValue())
182 glEnable(GL_POLYGON_OFFSET_FILL);
183 #endif
185 #if !defined(OSG_OGL_COREONLY)
186 // stipple
188 if(_mfStipple.size() == 32)
190 glPolygonStipple(reinterpret_cast<const GLubyte *>(&(_mfStipple[0])));
191 glEnable(GL_POLYGON_STIPPLE);
193 #endif
197 void PolygonChunk::changeFrom(DrawEnv *pEnv, StateChunk *old_chunk, UInt32)
199 PolygonChunk const *old = dynamic_cast<PolygonChunk const*>(old_chunk);
201 // change from me to me?
202 // this assumes I haven't changed in the meantime. is that a valid
203 // assumption?
205 if(old == this)
206 return;
208 pEnv->incNumChunkChanges();
210 // cullFace
212 if(_sfCullFace.getValue() != old->_sfCullFace.getValue())
214 if(_sfCullFace.getValue() != GL_NONE)
216 glCullFace(_sfCullFace.getValue());
217 glEnable(GL_CULL_FACE);
219 else
221 glDisable(GL_CULL_FACE);
225 // frontFace
227 if(_sfFrontFace.getValue() != old->_sfFrontFace.getValue())
229 glFrontFace(_sfFrontFace.getValue());
232 #ifndef OSG_OGL_ES2
233 // smooth
235 if(_sfSmooth.getValue() != old->_sfSmooth.getValue())
237 if(_sfSmooth.getValue())
239 glEnable(GL_POLYGON_SMOOTH);
241 else
243 glDisable(GL_POLYGON_SMOOTH);
246 #endif
248 #ifndef OSG_OGL_ES2
249 // mode
251 # if !defined(OSG_OGL_COREONLY)
252 if(_sfFrontMode.getValue() != old->_sfFrontMode.getValue())
253 glPolygonMode(GL_FRONT, _sfFrontMode.getValue());
255 if(_sfBackMode.getValue() != old->_sfBackMode.getValue())
256 glPolygonMode(GL_BACK, _sfBackMode.getValue());
257 # else
258 if(_sfFrontMode.getValue() != old->_sfFrontMode.getValue())
259 glPolygonMode(GL_FRONT_AND_BACK, _sfFrontMode.getValue());
260 # endif
261 #endif
263 #ifndef OSG_OGL_ES2
264 // offset
266 if(_sfOffsetFactor.getValue() != old->_sfOffsetFactor.getValue() ||
267 _sfOffsetBias.getValue() != old->_sfOffsetBias.getValue())
269 glPolygonOffset(_sfOffsetFactor.getValue(), _sfOffsetBias.getValue());
272 if(_sfOffsetPoint.getValue() != old->_sfOffsetPoint.getValue())
274 if(_sfOffsetPoint.getValue())
276 glEnable(GL_POLYGON_OFFSET_POINT);
278 else
280 glDisable(GL_POLYGON_OFFSET_POINT);
284 if(_sfOffsetLine.getValue() != old->_sfOffsetLine.getValue())
286 if(_sfOffsetLine.getValue())
288 glEnable(GL_POLYGON_OFFSET_LINE);
290 else
292 glDisable(GL_POLYGON_OFFSET_LINE);
296 if(_sfOffsetFill.getValue() != old->_sfOffsetFill.getValue())
298 if(_sfOffsetFill.getValue())
300 glEnable(GL_POLYGON_OFFSET_FILL);
302 else
304 glDisable(GL_POLYGON_OFFSET_FILL);
307 #endif
309 #if !defined(OSG_OGL_COREONLY)
310 // stipple
312 if(_mfStipple.getValues() != old->_mfStipple.getValues())
314 if(_mfStipple.size() == 32)
316 glPolygonStipple(
317 reinterpret_cast<const GLubyte *>(&(_mfStipple[0])));
318 glEnable(GL_POLYGON_STIPPLE);
320 else glDisable(GL_POLYGON_STIPPLE);
322 #endif
325 void PolygonChunk::deactivate(DrawEnv *, UInt32)
328 // cullFace
330 if(_sfCullFace.getValue() != GL_NONE)
331 glDisable(GL_CULL_FACE);
333 // frontFace
335 if(_sfFrontFace.getValue() != GL_CCW)
336 glFrontFace(GL_CCW);
338 #ifndef OSG_OGL_ES2
339 // smooth
341 if(_sfSmooth.getValue())
342 glDisable(GL_POLYGON_SMOOTH);
343 #endif
345 #ifndef OSG_OGL_ES2
346 // mode
348 # if !defined(OSG_OGL_COREONLY)
349 if(_sfFrontMode.getValue() != GL_FILL)
350 glPolygonMode(GL_FRONT, GL_FILL);
352 if(_sfBackMode.getValue() != GL_FILL)
353 glPolygonMode(GL_BACK, GL_FILL);
354 # else
355 if(_sfFrontMode.getValue() != GL_FILL)
356 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
357 # endif
358 #endif
360 #ifndef OSG_OGL_ES2
361 // offset
363 if(_sfOffsetPoint.getValue())
364 glDisable(GL_POLYGON_OFFSET_POINT);
366 if(_sfOffsetLine.getValue())
367 glDisable(GL_POLYGON_OFFSET_LINE);
369 if(_sfOffsetFill.getValue())
370 glDisable(GL_POLYGON_OFFSET_FILL);
371 #endif
373 #if !defined(OSG_OGL_COREONLY)
374 // stipple
376 if(_mfStipple.size() == 32)
377 glDisable(GL_POLYGON_STIPPLE);
378 #endif
382 /*-------------------------- Comparison -----------------------------------*/
384 Real32 PolygonChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
386 return 0;
389 bool PolygonChunk::operator <(const StateChunk &other) const
391 return this < &other;
394 bool PolygonChunk::operator ==(const StateChunk &other) const
396 PolygonChunk const *tother = dynamic_cast<PolygonChunk const*>(&other);
398 if(!tother)
399 return false;
401 if(tother == this)
402 return true;
404 if(getCullFace() != tother->getCullFace() ||
405 getFrontFace() != tother->getFrontFace() ||
406 getSmooth() != tother->getSmooth() ||
407 getFrontMode() != tother->getFrontMode() ||
408 getBackMode() != tother->getBackMode() ||
409 getOffsetPoint() != tother->getOffsetPoint() ||
410 getOffsetLine() != tother->getOffsetLine() ||
411 getOffsetFill() != tother->getOffsetFill() ||
412 getOffsetFactor() != tother->getOffsetFactor() ||
413 getOffsetBias() != tother->getOffsetBias() ||
414 getMFStipple()->size() != tother->getMFStipple()->size()
416 return false;
418 // would need to compare the whole stipple data
419 // cheap trick: if != 0 take as different
421 if( getMFStipple()->size() != 0 ||
422 tother->getMFStipple()->size() != 0
424 return false;
426 return true;
429 bool PolygonChunk::operator !=(const StateChunk &other) const
431 return !(*this == other);