changed: gcc8 base update
[opensg.git] / Source / System / State / Auxiliary / OSGTextureObjRefChunk.cpp
blob847b20ebf3727c577a67c2b3dfdfdcece7659f1f
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 <boost/bind.hpp>
48 #include "OSGConfig.h"
50 #include "OSGGL.h"
51 #include "OSGGLU.h"
52 #include "OSGGLEXT.h"
53 #include "OSGImage.h"
55 #include "OSGDrawEnv.h"
57 #include "OSGTextureObjRefChunk.h"
59 //#define OSG_DUMP_TEX
61 OSG_USING_NAMESPACE
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 /***************************************************************************\
69 * Class variables *
70 \***************************************************************************/
72 /***************************************************************************\
73 * Class methods *
74 \***************************************************************************/
76 /*-------------------------------------------------------------------------*\
77 - private -
78 \*-------------------------------------------------------------------------*/
80 void TextureObjRefChunk::initMethod(InitPhase ePhase)
82 Inherited::initMethod(ePhase);
85 /***************************************************************************\
86 * Instance methods *
87 \***************************************************************************/
89 /*-------------------------------------------------------------------------*\
90 - private -
91 \*-------------------------------------------------------------------------*/
94 /*------------- constructors & destructors --------------------------------*/
96 TextureObjRefChunk::TextureObjRefChunk(void) :
97 Inherited()
101 TextureObjRefChunk::TextureObjRefChunk(const TextureObjRefChunk &source) :
102 Inherited(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,
120 UInt32 origin,
121 BitVector details)
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
130 return false;
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()));
173 else
175 glBindTexture(this->getTarget(),
176 this->getOglGLId());
179 pEnv->setActiveTexTarget(idx, this->getTarget());
181 glEnable(this->getTarget());
185 void TextureObjRefChunk::changeFrom(DrawEnv *pEnv,
186 StateChunk *old ,
187 UInt32 idx )
189 // change from me to me?
190 // this assumes I haven't changed in the meantime.
191 // is that a valid assumption?
192 if(old == this)
193 return;
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()));
207 else
209 glBindTexture(this->getTarget(),
210 this->getOglGLId());
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))
234 return 0;
237 bool TextureObjRefChunk::operator < (const StateChunk &other) const
239 return this < &other;
242 bool TextureObjRefChunk::operator == (const StateChunk &other) const
244 bool returnValue = false;
246 return returnValue;
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());
264 else
266 return this->getOglGLId();
270 GLenum TextureObjRefChunk::determineInternalFormat(void)
272 return _sfInternalFormat.getValue();