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 "OSGPolygonChunk.h"
51 #include "OSGDrawEnv.h"
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 /***************************************************************************\
62 \***************************************************************************/
65 StateChunkClass
PolygonChunk::_class("Polygon", 1, 50);
67 StateChunkClass
PolygonChunk::_class("Polygon", 1, 110);
70 /***************************************************************************\
72 \***************************************************************************/
74 void PolygonChunk::initMethod(InitPhase ePhase
)
76 Inherited::initMethod(ePhase
);
79 /***************************************************************************\
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
85 \*-------------------------------------------------------------------------*/
88 /*------------- constructors & destructors --------------------------------*/
90 PolygonChunk::PolygonChunk(void) :
95 PolygonChunk::PolygonChunk(const PolygonChunk
&source
) :
100 PolygonChunk::~PolygonChunk(void)
104 /*------------------------- Chunk Class Access ---------------------------*/
106 const StateChunkClass
*PolygonChunk::getClass(void) const
111 /*------------------------------- Sync -----------------------------------*/
113 void PolygonChunk::changed(ConstFieldMaskArg whichField
,
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
)
134 pEnv
->incNumChunkChanges();
136 if(_sfCullFace
.getValue() != GL_NONE
)
138 glCullFace(_sfCullFace
.getValue());
139 glEnable(GL_CULL_FACE
);
144 if(_sfFrontFace
.getValue() != GL_CCW
)
145 glFrontFace(_sfFrontFace
.getValue());
150 if(_sfSmooth
.getValue())
151 glEnable(GL_POLYGON_SMOOTH
);
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());
164 if(_sfFrontMode
.getValue() != GL_FILL
)
165 glPolygonMode(GL_FRONT_AND_BACK
, _sfFrontMode
.getValue());
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
);
185 #if !defined(OSG_OGL_COREONLY)
188 if(_mfStipple
.size() == 32)
190 glPolygonStipple(reinterpret_cast<const GLubyte
*>(&(_mfStipple
[0])));
191 glEnable(GL_POLYGON_STIPPLE
);
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
208 pEnv
->incNumChunkChanges();
212 if(_sfCullFace
.getValue() != old
->_sfCullFace
.getValue())
214 if(_sfCullFace
.getValue() != GL_NONE
)
216 glCullFace(_sfCullFace
.getValue());
217 glEnable(GL_CULL_FACE
);
221 glDisable(GL_CULL_FACE
);
227 if(_sfFrontFace
.getValue() != old
->_sfFrontFace
.getValue())
229 glFrontFace(_sfFrontFace
.getValue());
235 if(_sfSmooth
.getValue() != old
->_sfSmooth
.getValue())
237 if(_sfSmooth
.getValue())
239 glEnable(GL_POLYGON_SMOOTH
);
243 glDisable(GL_POLYGON_SMOOTH
);
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());
258 if(_sfFrontMode
.getValue() != old
->_sfFrontMode
.getValue())
259 glPolygonMode(GL_FRONT_AND_BACK
, _sfFrontMode
.getValue());
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
);
280 glDisable(GL_POLYGON_OFFSET_POINT
);
284 if(_sfOffsetLine
.getValue() != old
->_sfOffsetLine
.getValue())
286 if(_sfOffsetLine
.getValue())
288 glEnable(GL_POLYGON_OFFSET_LINE
);
292 glDisable(GL_POLYGON_OFFSET_LINE
);
296 if(_sfOffsetFill
.getValue() != old
->_sfOffsetFill
.getValue())
298 if(_sfOffsetFill
.getValue())
300 glEnable(GL_POLYGON_OFFSET_FILL
);
304 glDisable(GL_POLYGON_OFFSET_FILL
);
309 #if !defined(OSG_OGL_COREONLY)
312 if(_mfStipple
.getValues() != old
->_mfStipple
.getValues())
314 if(_mfStipple
.size() == 32)
317 reinterpret_cast<const GLubyte
*>(&(_mfStipple
[0])));
318 glEnable(GL_POLYGON_STIPPLE
);
320 else glDisable(GL_POLYGON_STIPPLE
);
325 void PolygonChunk::deactivate(DrawEnv
*, UInt32
)
330 if(_sfCullFace
.getValue() != GL_NONE
)
331 glDisable(GL_CULL_FACE
);
335 if(_sfFrontFace
.getValue() != GL_CCW
)
341 if(_sfSmooth
.getValue())
342 glDisable(GL_POLYGON_SMOOTH
);
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
);
355 if(_sfFrontMode
.getValue() != GL_FILL
)
356 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
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
);
373 #if !defined(OSG_OGL_COREONLY)
376 if(_mfStipple
.size() == 32)
377 glDisable(GL_POLYGON_STIPPLE
);
382 /*-------------------------- Comparison -----------------------------------*/
384 Real32
PolygonChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
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
);
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()
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
429 bool PolygonChunk::operator !=(const StateChunk
&other
) const
431 return !(*this == other
);