changed: gcc8 base update
[opensg.git] / Source / System / State / OpenGL / OSGTextureTransformChunk.cpp
blob0b80b33c1dab2bf7123281f551340406d1b71fcf
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 "OSGTextureTransformChunk.h"
51 #include "OSGWindow.h"
52 #include "OSGCamera.h"
53 #include "OSGViewport.h"
54 #include "OSGTextureBaseChunk.h"
55 #include "OSGDrawEnv.h"
57 OSG_USING_NAMESPACE
59 // Documentation for this class is emited in the
60 // OSGTextureTransformChunkBase.cpp file.
61 // To modify it, please change the .fcd file (OSGTextureTransformChunk.fcd) and
62 // regenerate the base file.
64 /***************************************************************************\
65 * Class variables *
66 \***************************************************************************/
68 StateChunkClass TextureTransformChunk::_class("TextureTransform",
69 osgMaxTexCoords,
70 130);
72 /***************************************************************************\
73 * Class methods *
74 \***************************************************************************/
76 void TextureTransformChunk::initMethod(InitPhase ePhase)
78 Inherited::initMethod(ePhase);
81 /***************************************************************************\
82 * Instance methods *
83 \***************************************************************************/
85 /*-------------------------------------------------------------------------*\
86 - private -
87 \*-------------------------------------------------------------------------*/
89 TextureTransformChunk::TextureTransformChunk(void) :
90 Inherited()
94 TextureTransformChunk::TextureTransformChunk(
95 const TextureTransformChunk &source) :
97 Inherited(source)
101 TextureTransformChunk::~TextureTransformChunk(void)
105 /*------------------------- Chunk Class Access ---------------------------*/
107 const StateChunkClass *TextureTransformChunk::getClass(void) const
109 return &_class;
112 /*------------------------------- Sync -----------------------------------*/
114 void TextureTransformChunk::changed(ConstFieldMaskArg whichField,
115 UInt32 origin,
116 BitVector details)
118 Inherited::changed(whichField, origin, details);
121 /*------------------------------ Output ----------------------------------*/
123 void TextureTransformChunk::dump( UInt32 ,
124 const BitVector ) const
126 SLOG << "Dump TextureTransformChunk NI" << std::endl;
129 /*------------------------------ State ------------------------------------*/
131 void TextureTransformChunk::activate(DrawEnv *pEnv, UInt32 idx)
133 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
134 pEnv->incNumChunkChanges();
136 Window *win = pEnv->getWindow();
138 Real32 ntexcoords;
139 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
140 Window::unknownConstant
143 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
144 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
145 if(ntexcoords == Window::unknownConstant)
146 ntexcoords = 1.0f;
149 if(idx >= static_cast<UInt32>(ntexcoords))
151 #ifdef OSG_DEBUG
152 FWARNING(("TextureTransformChunk::deactivate: Trying to bind "
153 "texcoord unit %d, but Window %p only supports %lf!\n",
154 idx,
155 static_cast<void *>(win),
156 ntexcoords));
157 #endif
158 return;
161 TextureBaseChunk::activateTexture(win, idx);
163 glMatrixMode(GL_TEXTURE);
165 if(getUseCameraBeacon())
167 Matrix m = pEnv->getCameraToWorld();
169 m[3].setValues(0, 0, 0, 1);
170 glLoadMatrixf(m.getValues());
172 else
174 glLoadMatrixf(getMatrix().getValues());
176 glMatrixMode(GL_MODELVIEW);
177 #else
178 OSG_ASSERT(false);
179 #endif
182 void TextureTransformChunk::changeFrom(DrawEnv *pEnv,
183 StateChunk *old,
184 UInt32 idx )
186 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
187 // change from me to me?
188 // this assumes I haven't changed in the meantime. is that a valid
189 // assumption?
191 if ( old == this )
192 return;
194 pEnv->incNumChunkChanges();
196 Window *win = pEnv->getWindow();
198 Real32 ntexcoords;
199 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
200 Window::unknownConstant
203 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
204 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
205 if(ntexcoords == Window::unknownConstant)
206 ntexcoords = 1.0f;
209 if(idx >= static_cast<UInt32>(ntexcoords))
211 #ifdef OSG_DEBUG
212 FWARNING(("TextureTransformChunk::deactivate: Trying to bind "
213 "texcoord unit %d, but Window %p only supports %lf!\n",
214 idx,
215 static_cast<void *>(win),
216 ntexcoords));
217 #endif
218 return;
221 TextureBaseChunk::activateTexture(win, idx);
223 glMatrixMode(GL_TEXTURE);
224 if(getUseCameraBeacon())
226 Matrix m = pEnv->getCameraToWorld();
228 m[3].setValues(0, 0, 0, 1);
229 glLoadMatrixf(m.getValues());
231 else
233 glLoadMatrixf(getMatrix().getValues());
235 glMatrixMode(GL_MODELVIEW);
236 #else
237 OSG_ASSERT(false);
238 #endif
241 void TextureTransformChunk::deactivate(DrawEnv *pEnv, UInt32 idx)
243 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
244 Window *win = pEnv->getWindow();
246 Real32 ntexcoords;
247 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
248 Window::unknownConstant
251 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
252 // sgi doesn't support GL_MAX_TEXTURE_UNITS_ARB!
253 if(ntexcoords == Window::unknownConstant)
254 ntexcoords = 1.0f;
257 if(idx >= static_cast<UInt32>(ntexcoords))
259 #ifdef OSG_DEBUG
260 FWARNING(("TextureTransformChunk::deactivate: Trying to bind"
261 " texcoord unit %d, but Window %p only supports %lf!\n",
262 idx,
263 static_cast<void *>(win),
264 ntexcoords));
265 #endif
266 return;
269 TextureBaseChunk::activateTexture(win, idx);
271 glMatrixMode(GL_TEXTURE);
272 glLoadIdentity();
273 glMatrixMode(GL_MODELVIEW);
274 #else
275 OSG_ASSERT(false);
276 #endif
280 /*-------------------------- Comparison -----------------------------------*/
282 Real32 TextureTransformChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
284 return 0;
287 bool TextureTransformChunk::operator <(const StateChunk &other) const
289 return this < &other;
292 bool TextureTransformChunk::operator ==(const StateChunk &other) const
294 TextureTransformChunk const *tother =
295 dynamic_cast<TextureTransformChunk const*>(&other);
297 if(!tother)
298 return false;
300 if(tother == this)
301 return true;
303 if(getMatrix() != tother->getMatrix())
304 return false;
306 return true;
309 bool TextureTransformChunk::operator !=(const StateChunk &other) const
311 return !(*this == other);