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"
48 #include "OSGShadeModelChunk.h"
49 #include "OSGDrawEnv.h"
53 /***************************************************************************\
55 \***************************************************************************/
57 /*! \class OSG::ShadeModelChunk
58 ShadeModelChunk controls the shading model used for rendering lines and filled polygons.
61 /***************************************************************************\
63 \***************************************************************************/
65 StateChunkClass
ShadeModelChunk::_class("ShadeModel", 1, 100);
67 /***************************************************************************\
69 \***************************************************************************/
71 void ShadeModelChunk::initMethod (InitPhase ePhase
)
73 Inherited::initMethod(ePhase
);
77 /***************************************************************************\
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 ShadeModelChunk::ShadeModelChunk(void) :
92 ShadeModelChunk::ShadeModelChunk(const ShadeModelChunk
&source
) :
97 ShadeModelChunk::~ShadeModelChunk(void)
101 /*------------------------- Chunk Class Access ---------------------------*/
103 const StateChunkClass
*ShadeModelChunk::getClass(void) const
108 /*------------------------------- Sync -----------------------------------*/
110 void ShadeModelChunk::changed(ConstFieldMaskArg whichField
,
114 Inherited::changed(whichField
, origin
, details
);
117 /*------------------------------ Output ----------------------------------*/
119 void ShadeModelChunk::dump( UInt32
,
120 const BitVector
) const
122 SLOG
<< "Dump ShadeModelChunk NI" << std::endl
;
125 /*------------------------------ State ------------------------------------*/
127 void ShadeModelChunk::activate(DrawEnv
*pEnv
, UInt32
)
129 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
130 pEnv
->incNumChunkChanges();
132 if(getShadeModel() != GL_SMOOTH
)
133 glShadeModel(getShadeModel());
139 void ShadeModelChunk::changeFrom(DrawEnv
*pEnv
,
140 StateChunk
*old_chunk
,
143 ShadeModelChunk
*old
= dynamic_cast<ShadeModelChunk
*>(old_chunk
);
147 FWARNING(("ShadeModelChunk::changeFrom: caught "
148 "non-ShadeModelChunk!\n"));
152 // ShadeModelChunk didn't change so do nothing.
156 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
157 pEnv
->incNumChunkChanges();
159 if(old
->getShadeModel() != getShadeModel())
160 glShadeModel(getShadeModel());
166 void ShadeModelChunk::deactivate(DrawEnv
*, UInt32
)
168 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
169 if(getShadeModel() != GL_SMOOTH
)
170 glShadeModel(GL_SMOOTH
);
177 /*-------------------------- Comparison -----------------------------------*/
179 Real32
ShadeModelChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
184 bool ShadeModelChunk::operator <(const StateChunk
&other
) const
186 return this < &other
;
189 bool ShadeModelChunk::operator ==(const StateChunk
&other
) const
191 ShadeModelChunk
const *tother
=
192 dynamic_cast<ShadeModelChunk
const*>(&other
);
203 bool ShadeModelChunk::operator !=(const StateChunk
&other
) const
205 return !(*this == other
);