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 "OSGConfig.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"
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 /***************************************************************************\
66 \***************************************************************************/
68 StateChunkClass
TextureTransformChunk::_class("TextureTransform",
72 /***************************************************************************\
74 \***************************************************************************/
76 void TextureTransformChunk::initMethod(InitPhase ePhase
)
78 Inherited::initMethod(ePhase
);
81 /***************************************************************************\
83 \***************************************************************************/
85 /*-------------------------------------------------------------------------*\
87 \*-------------------------------------------------------------------------*/
89 TextureTransformChunk::TextureTransformChunk(void) :
94 TextureTransformChunk::TextureTransformChunk(
95 const TextureTransformChunk
&source
) :
101 TextureTransformChunk::~TextureTransformChunk(void)
105 /*------------------------- Chunk Class Access ---------------------------*/
107 const StateChunkClass
*TextureTransformChunk::getClass(void) const
112 /*------------------------------- Sync -----------------------------------*/
114 void TextureTransformChunk::changed(ConstFieldMaskArg whichField
,
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();
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
)
149 if(idx
>= static_cast<UInt32
>(ntexcoords
))
152 FWARNING(("TextureTransformChunk::deactivate: Trying to bind "
153 "texcoord unit %d, but Window %p only supports %lf!\n",
155 static_cast<void *>(win
),
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());
174 glLoadMatrixf(getMatrix().getValues());
176 glMatrixMode(GL_MODELVIEW
);
182 void TextureTransformChunk::changeFrom(DrawEnv
*pEnv
,
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
194 pEnv
->incNumChunkChanges();
196 Window
*win
= pEnv
->getWindow();
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
)
209 if(idx
>= static_cast<UInt32
>(ntexcoords
))
212 FWARNING(("TextureTransformChunk::deactivate: Trying to bind "
213 "texcoord unit %d, but Window %p only supports %lf!\n",
215 static_cast<void *>(win
),
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());
233 glLoadMatrixf(getMatrix().getValues());
235 glMatrixMode(GL_MODELVIEW
);
241 void TextureTransformChunk::deactivate(DrawEnv
*pEnv
, UInt32 idx
)
243 #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
244 Window
*win
= pEnv
->getWindow();
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
)
257 if(idx
>= static_cast<UInt32
>(ntexcoords
))
260 FWARNING(("TextureTransformChunk::deactivate: Trying to bind"
261 " texcoord unit %d, but Window %p only supports %lf!\n",
263 static_cast<void *>(win
),
269 TextureBaseChunk::activateTexture(win
, idx
);
271 glMatrixMode(GL_TEXTURE
);
273 glMatrixMode(GL_MODELVIEW
);
280 /*-------------------------- Comparison -----------------------------------*/
282 Real32
TextureTransformChunk::switchCost(StateChunk
*OSG_CHECK_ARG(chunk
))
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
);
303 if(getMatrix() != tother
->getMatrix())
309 bool TextureTransformChunk::operator !=(const StateChunk
&other
) const
311 return !(*this == other
);