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 "OSGTextureObjRefChunk.h"
59 //#define OSG_DUMP_TEX
63 // Documentation for this class is emited in the
64 // OSGTextureObjRefChunkBase.cpp file.
65 // To modify it, please change the .fcd file (OSGTextureObjRefChunk.fcd) and
66 // regenerate the base file.
68 /***************************************************************************\
70 \***************************************************************************/
72 /***************************************************************************\
74 \***************************************************************************/
76 /*-------------------------------------------------------------------------*\
78 \*-------------------------------------------------------------------------*/
80 void TextureObjRefChunk::initMethod(InitPhase ePhase
)
82 Inherited::initMethod(ePhase
);
85 /***************************************************************************\
87 \***************************************************************************/
89 /*-------------------------------------------------------------------------*\
91 \*-------------------------------------------------------------------------*/
94 /*------------- constructors & destructors --------------------------------*/
96 TextureObjRefChunk::TextureObjRefChunk(void) :
101 TextureObjRefChunk::TextureObjRefChunk(const TextureObjRefChunk
&source
) :
106 TextureObjRefChunk::~TextureObjRefChunk(void)
110 /*------------------------- Chunk Class Access ---------------------------*/
112 /*------------------------------- Sync -----------------------------------*/
114 /*! React to field changes.
115 Note: this function also handles CubeTexture changes, make sure to keep
116 it consistent with the cubeTexture specifics
119 void TextureObjRefChunk::changed(ConstFieldMaskArg whichField
,
123 Inherited::changed(whichField
, origin
, details
);
126 bool TextureObjRefChunk::isTransparent(void) const
128 // Even if the texture has alpha, the Blending is makes the sorting
129 // important, thus textures per se are not transparent
134 /*----------------------------- onCreate --------------------------------*/
136 void TextureObjRefChunk::onCreate(const TextureObjRefChunk
*source
)
138 Inherited::onCreate(source
);
141 void TextureObjRefChunk::onCreateAspect(const TextureObjRefChunk
*createAspect
,
142 const TextureObjRefChunk
*source
)
144 Inherited::onCreateAspect(createAspect
, source
);
147 /*------------------------------ Output ----------------------------------*/
149 void TextureObjRefChunk::dump( UInt32
OSG_CHECK_ARG(uiIndent
),
150 const BitVector
OSG_CHECK_ARG(bvFlags
)) const
152 SLOG
<< "Dump TextureObjRefChunk NI" << std::endl
;
156 /*------------------------------ State ------------------------------------*/
159 void TextureObjRefChunk::activate(DrawEnv
*pEnv
, UInt32 idx
)
161 Window
*pWin
= pEnv
->getWindow();
163 pEnv
->incNumChunkChanges();
165 if(activateTexture(pWin
, idx
))
166 return; // trying to access too many textures
168 if(this->getOsgGLId() != 0)
170 glBindTexture(this->getTarget(),
171 pWin
->getGLObjectId(this->getOsgGLId()));
175 glBindTexture(this->getTarget(),
179 pEnv
->setActiveTexTarget(idx
, this->getTarget());
181 glEnable(this->getTarget());
185 void TextureObjRefChunk::changeFrom(DrawEnv
*pEnv
,
189 // change from me to me?
190 // this assumes I haven't changed in the meantime.
191 // is that a valid assumption?
195 pEnv
->incNumChunkChanges();
197 Window
*pWin
= pEnv
->getWindow();
199 if(activateTexture(pWin
, idx
))
200 return; // trying to access too many textures
202 if(this->getOsgGLId() != 0)
204 glBindTexture(this->getTarget(),
205 pWin
->getGLObjectId(this->getOsgGLId()));
209 glBindTexture(this->getTarget(),
213 pEnv
->setActiveTexTarget(idx
, this->getTarget());
215 glEnable(this->getTarget());
218 void TextureObjRefChunk::deactivate(DrawEnv
*pEnv
, UInt32 idx
)
220 Window
*pWin
= pEnv
->getWindow();
222 if(activateTexture(pWin
, idx
))
223 return; // trying to access too many textures
225 glDisable(this->getTarget());
227 pEnv
->setActiveTexTarget(idx
, GL_NONE
);
230 /*-------------------------- Comparison -----------------------------------*/
232 Real32
TextureObjRefChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
237 bool TextureObjRefChunk::operator < (const StateChunk
&other
) const
239 return this < &other
;
242 bool TextureObjRefChunk::operator == (const StateChunk
&other
) const
244 bool returnValue
= false;
249 bool TextureObjRefChunk::operator != (const StateChunk
&other
) const
251 return ! (*this == other
);
254 void TextureObjRefChunk::validate(DrawEnv
*)
258 Int32
TextureObjRefChunk::getOpenGLId(DrawEnv
*pEnv
)
260 if(this->getOsgGLId() != 0)
262 return pEnv
->getWindow()->getGLObjectId(this->getOsgGLId());
266 return this->getOglGLId();
270 GLenum
TextureObjRefChunk::determineInternalFormat(void)
272 return _sfInternalFormat
.getValue();