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 <boost/bind.hpp>
48 #include "OSGConfig.h"
55 #include "OSGDrawEnv.h"
57 #include "OSGTextureSelectChunk.h"
58 #include "OSGTextureBaseChunk.h"
60 //#define OSG_DUMP_TEX
64 // Documentation for this class is emited in the
65 // OSGTextureSelectChunkBase.cpp file.
66 // To modify it, please change the .fcd file (OSGTextureSelectChunk.fcd) and
67 // regenerate the base file.
69 /***************************************************************************\
71 \***************************************************************************/
73 /***************************************************************************\
75 \***************************************************************************/
77 /*-------------------------------------------------------------------------*\
79 \*-------------------------------------------------------------------------*/
81 void TextureSelectChunk::initMethod(InitPhase ePhase
)
83 Inherited::initMethod(ePhase
);
86 /***************************************************************************\
88 \***************************************************************************/
90 /*-------------------------------------------------------------------------*\
92 \*-------------------------------------------------------------------------*/
95 /*------------- constructors & destructors --------------------------------*/
97 TextureSelectChunk::TextureSelectChunk(void) :
102 TextureSelectChunk::TextureSelectChunk(const TextureSelectChunk
&source
) :
107 TextureSelectChunk::~TextureSelectChunk(void)
111 /*------------------------- Chunk Class Access ---------------------------*/
113 /*------------------------------- Sync -----------------------------------*/
115 /*! React to field changes.
116 Note: this function also handles CubeTexture changes, make sure to keep
117 it consistent with the cubeTexture specifics
120 void TextureSelectChunk::changed(ConstFieldMaskArg whichField
,
124 Inherited::changed(whichField
, origin
, details
);
127 bool TextureSelectChunk::isTransparent(void) const
129 // Even if the texture has alpha, the Blending is makes the sorting
130 // important, thus textures per se are not transparent
135 /*----------------------------- onCreate --------------------------------*/
137 void TextureSelectChunk::onCreate(const TextureSelectChunk
*source
)
139 Inherited::onCreate(source
);
142 void TextureSelectChunk::onCreateAspect(const TextureSelectChunk
*createAspect
,
143 const TextureSelectChunk
*source
)
145 Inherited::onCreateAspect(createAspect
, source
);
148 /*------------------------------ Output ----------------------------------*/
150 void TextureSelectChunk::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
151 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
153 SLOG
<< "Dump TextureSelectChunk NI" << std::endl
;
157 /*------------------------------ State ------------------------------------*/
160 void TextureSelectChunk::activate(DrawEnv
*pEnv
, UInt32 idx
)
162 if(_sfChoice
.getValue() >= _mfTextures
.size())
165 ("TextureSelect::activate choice beyond size %d %" PRISize
"!\n",
166 _sfChoice
.getValue(),
167 _mfTextures
.size ()));
172 this->_mfTextures
[_sfChoice
.getValue()]->activate(pEnv
, idx
);
176 void TextureSelectChunk::changeFrom(DrawEnv
*pEnv
,
180 // change from me to me?
181 // this assumes I haven't changed in the meantime.
182 // is that a valid assumption?
186 if(_sfChoice
.getValue() >= _mfTextures
.size())
189 ("TextureSelect::changeFrom choice beyond size %d %" PRISize
"!\n",
190 _sfChoice
.getValue(),
191 _mfTextures
.size ()));
196 this->_mfTextures
[_sfChoice
.getValue()]->changeFrom(pEnv
, old
, idx
);
199 void TextureSelectChunk::deactivate(DrawEnv
*pEnv
, UInt32 idx
)
201 if(_sfChoice
.getValue() >= _mfTextures
.size())
204 ("TextureSelect::deactivate choice beyond size %d %" PRISize
"!\n",
205 _sfChoice
.getValue(),
206 _mfTextures
.size ()));
211 this->_mfTextures
[_sfChoice
.getValue()]->deactivate(pEnv
, idx
);
214 /*-------------------------- Comparison -----------------------------------*/
216 Real32
TextureSelectChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
221 bool TextureSelectChunk::operator < (const StateChunk
&other
) const
223 return this < &other
;
226 bool TextureSelectChunk::operator == (const StateChunk
&other
) const
228 bool returnValue
= false;
233 bool TextureSelectChunk::operator != (const StateChunk
&other
) const
235 return ! (*this == other
);
238 void TextureSelectChunk::validate(DrawEnv
*pEnv
)
240 if(_sfChoice
.getValue() >= _mfTextures
.size())
243 ("TextureSelect::validate choice beyond size %d %" PRISize
"!\n",
244 _sfChoice
.getValue(),
245 _mfTextures
.size ()));
250 this->_mfTextures
[_sfChoice
.getValue()]->validate(pEnv
);
253 Int32
TextureSelectChunk::getOpenGLId(DrawEnv
*pEnv
)
255 if(_sfChoice
.getValue() >= _mfTextures
.size())
258 ("TextureSelect::validate choice beyond size %d %" PRISize
"!\n",
259 _sfChoice
.getValue(),
260 _mfTextures
.size ()));
265 return this->_mfTextures
[_sfChoice
.getValue()]->getOpenGLId(pEnv
);
268 GLenum
TextureSelectChunk::determineInternalFormat(void)
270 if(_sfChoice
.getValue() >= _mfTextures
.size())
273 ("TextureSelect::validate choice beyond size %d %" PRISize
"!\n",
274 _sfChoice
.getValue(),
275 _mfTextures
.size ()));
280 return this->_mfTextures
[_sfChoice
.getValue()]->determineInternalFormat();