fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / State / Base / OSGDepthChunk.cpp
blob4fd1fb5e9f5b4f98793e4983c75f947a39f8fe1f
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 "OSGWindow.h"
52 #include "OSGDepthChunk.h"
54 OSG_USING_NAMESPACE
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 /***************************************************************************\
62 * Class variables *
63 \***************************************************************************/
65 StateChunkClass DepthChunk::_class("Depth", 1, 50);
67 /***************************************************************************\
68 * Class methods *
69 \***************************************************************************/
71 void DepthChunk::initMethod(InitPhase ePhase)
73 Inherited::initMethod(ePhase);
77 /***************************************************************************\
78 * Instance methods *
79 \***************************************************************************/
81 /*-------------------------------------------------------------------------*\
82 - private -
83 \*-------------------------------------------------------------------------*/
85 /*----------------------- constructors & destructors ----------------------*/
87 DepthChunk::DepthChunk(void) :
88 Inherited()
92 DepthChunk::DepthChunk(const DepthChunk &source) :
93 Inherited(source)
97 DepthChunk::~DepthChunk(void)
101 /*------------------------- Chunk Class Access ---------------------------*/
103 const StateChunkClass *DepthChunk::getClass(void) const
105 return &_class;
108 /*----------------------------- class specific ----------------------------*/
110 void DepthChunk::changed(ConstFieldMaskArg whichField,
111 UInt32 origin,
112 BitVector details)
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());
135 #ifndef OSG_OGL_ES2
136 if(getNear() >= 0 && getFar() >= 0)
138 glDepthRange(getNear(), getFar());
140 #endif
142 if(getEnable())
144 glEnable(GL_DEPTH_TEST);
146 else
148 glDisable(GL_DEPTH_TEST);
151 glDepthMask(!getReadOnly());
154 void DepthChunk::changeFrom(DrawEnv *pEnv,
155 StateChunk *old_chunk,
156 UInt32 index )
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);
170 #ifndef OSG_OGL_ES2
171 if(getNear() >= 0 && getFar() >= 0)
173 glDepthRange(0, 1);
175 #endif
177 if(!getEnable())
179 glEnable(GL_DEPTH_TEST);
182 glDepthMask(GL_TRUE);
185 /*-------------------------- Comparison -----------------------------------*/
187 Real32 DepthChunk::switchCost(StateChunk *)
189 return 0;
192 /** \brief assignment
195 bool DepthChunk::operator < (const StateChunk &other) const
197 return this < &other;
200 /** \brief equal
203 bool DepthChunk::operator == (const StateChunk &other) const
205 DepthChunk const *tother = dynamic_cast<DepthChunk const*>(&other);
207 if(!tother)
208 return false;
210 if(tother == this)
211 return true;
213 if(getEnable() != tother->getEnable() ||
214 getFunc() != tother->getFunc() ||
215 getFar() != tother->getFar() ||
216 getNear() != tother->getNear() ||
217 getReadOnly() != tother->getReadOnly() )
219 return false;
222 return true;
225 /** \brief unequal
228 bool DepthChunk::operator != (const StateChunk &other) const
230 return ! (*this == other);