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 "OSGWindow.h"
52 #include "OSGDepthChunk.h"
56 // Documentation for this class is emited in the
57 // OSGDepthChunkBase.cpp file.
58 // To modify it, please change the .fcd file (OSGDepthChunk.fcd) and
59 // regenerate the base file.
61 /***************************************************************************\
63 \***************************************************************************/
65 StateChunkClass
DepthChunk::_class("Depth", 1, 50);
67 /***************************************************************************\
69 \***************************************************************************/
71 void DepthChunk::initMethod(InitPhase ePhase
)
73 Inherited::initMethod(ePhase
);
77 /***************************************************************************\
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 DepthChunk::DepthChunk(void) :
92 DepthChunk::DepthChunk(const DepthChunk
&source
) :
97 DepthChunk::~DepthChunk(void)
101 /*------------------------- Chunk Class Access ---------------------------*/
103 const StateChunkClass
*DepthChunk::getClass(void) const
108 /*----------------------------- class specific ----------------------------*/
110 void DepthChunk::changed(ConstFieldMaskArg whichField
,
114 Inherited::changed(whichField
, origin
, details
);
117 void DepthChunk::dump( UInt32
,
118 const BitVector
) const
120 SLOG
<< "Dump DepthChunk NI" << std::endl
;
124 /*------------------------------ State ------------------------------------*/
126 void DepthChunk::activate(DrawEnv
*pEnv
, UInt32
)
128 pEnv
->incNumChunkChanges();
130 if(_sfFunc
.getValue() != GL_NONE
)
132 glDepthFunc(_sfFunc
.getValue());
136 if(getNear() >= 0 && getFar() >= 0)
138 glDepthRange(getNear(), getFar());
144 glEnable(GL_DEPTH_TEST
);
148 glDisable(GL_DEPTH_TEST
);
151 glDepthMask(!getReadOnly());
154 void DepthChunk::changeFrom(DrawEnv
*pEnv
,
155 StateChunk
*old_chunk
,
158 old_chunk
->deactivate(pEnv
, index
);
160 activate(pEnv
, index
);
163 void DepthChunk::deactivate(DrawEnv
*, UInt32
)
165 if(_sfFunc
.getValue() != GL_NONE
)
167 glDepthFunc(GL_LEQUAL
);
171 if(getNear() >= 0 && getFar() >= 0)
179 glEnable(GL_DEPTH_TEST
);
182 glDepthMask(GL_TRUE
);
185 /*-------------------------- Comparison -----------------------------------*/
187 Real32
DepthChunk::switchCost(StateChunk
*)
192 /** \brief assignment
195 bool DepthChunk::operator < (const StateChunk
&other
) const
197 return this < &other
;
203 bool DepthChunk::operator == (const StateChunk
&other
) const
205 DepthChunk
const *tother
= dynamic_cast<DepthChunk
const*>(&other
);
213 if(getEnable() != tother
->getEnable() ||
214 getFunc() != tother
->getFunc() ||
215 getFar() != tother
->getFar() ||
216 getNear() != tother
->getNear() ||
217 getReadOnly() != tother
->getReadOnly() )
228 bool DepthChunk::operator != (const StateChunk
&other
) const
230 return ! (*this == other
);