00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include <OSGConfig.h>
00047
00048 #include <OSGGL.h>
00049
00050 #include "OSGTextureTransformChunk.h"
00051 #include <OSGWindow.h>
00052 #include <OSGDrawActionBase.h>
00053 #include <OSGCamera.h>
00054 #include <OSGViewport.h>
00055 #include <OSGTextureChunk.h>
00056 #include <OSGTexGenChunk.h>
00057
00058 OSG_USING_NAMESPACE
00059
00060
00061
00062
00063
00074
00075
00076
00077
00078 StateChunkClass TextureTransformChunk::_class("TextureTransform",
00079 osgMaxTexCoords);
00080
00081
00082
00083
00084
00085 void TextureTransformChunk::initMethod (void)
00086 {
00087 addInitFunction(&TextureTransformChunk::checkTexChunkOrder);
00088 }
00089
00090 bool TextureTransformChunk::checkTexChunkOrder(void)
00091 {
00092 FINFO(("Check order %d %d\n",
00093 TextureTransformChunk::getStaticClassId(),
00094 TextureChunk ::getStaticClassId()));
00095
00096 if(TextureTransformChunk::getStaticClassId() <
00097 TextureChunk ::getStaticClassId() )
00098 {
00099
00100 _class.swap(
00101 *(const_cast<StateChunkClass *>(TextureChunk::getStaticClass())));
00102 }
00103
00104 return true;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 TextureTransformChunk::TextureTransformChunk(void) :
00116 Inherited()
00117 {
00118 }
00119
00120 TextureTransformChunk::TextureTransformChunk(const TextureTransformChunk &source) :
00121 Inherited(source)
00122 {
00123 }
00124
00125 TextureTransformChunk::~TextureTransformChunk(void)
00126 {
00127 }
00128
00129
00130
00131 const StateChunkClass *TextureTransformChunk::getClass(void) const
00132 {
00133 return &_class;
00134 }
00135
00136
00137
00138 void TextureTransformChunk::changed(BitVector whichField, UInt32 origin)
00139 {
00140 Inherited::changed(whichField, origin);
00141 }
00142
00143
00144
00145 void TextureTransformChunk::dump( UInt32 ,
00146 const BitVector ) const
00147 {
00148 SLOG << "Dump TextureTransformChunk NI" << std::endl;
00149 }
00150
00151
00152
00153 void TextureTransformChunk::activate ( DrawActionBase * action, UInt32 idx )
00154 {
00155 Window *win = action->getWindow();
00156
00157 Real32 ntexcoords;
00158 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00159 Window::unknownConstant
00160 )
00161 {
00162 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00163
00164 if(ntexcoords == Window::unknownConstant)
00165 ntexcoords = 1.0f;
00166 }
00167
00168 if(idx >= static_cast<UInt32>(ntexcoords))
00169 {
00170 #ifdef OSG_DEBUG
00171 FWARNING(("TextureTransformChunk::deactivate: Trying to bind texcoord unit %d,"
00172 " but Window %p only supports %d!\n",
00173 idx, win, ntexcoords));
00174 #endif
00175 return;
00176 }
00177
00178 TextureChunk::activateTexture(win, idx);
00179
00180 glMatrixMode(GL_TEXTURE);
00181
00182
00183 if(getUseCameraBeacon())
00184 {
00185 if(action->getCamera() != NULL && action->getViewport() != NULL)
00186 {
00187 Matrix m;
00188 action->getCamera()->getViewing(m,
00189 action->getViewport()->getPixelWidth(),
00190 action->getViewport()->getPixelHeight());
00191 m.invert();
00192 m[3].setValues(0, 0, 0, 1);
00193
00194 glMultMatrixf(m.getValues());
00195
00196 }
00197 }
00198 else
00199 {
00200 glMultMatrixf(getMatrix().getValues());
00201
00202 }
00203 glMatrixMode(GL_MODELVIEW);
00204 }
00205
00206 void TextureTransformChunk::changeFrom( DrawActionBase * action, StateChunk * old, UInt32 idx )
00207 {
00208
00209
00210 if ( old == this )
00211 return;
00212
00213 Window *win = action->getWindow();
00214
00215 Real32 ntexcoords;
00216 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00217 Window::unknownConstant
00218 )
00219 {
00220 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00221
00222 if(ntexcoords == Window::unknownConstant)
00223 ntexcoords = 1.0f;
00224 }
00225
00226 if(idx >= static_cast<UInt32>(ntexcoords))
00227 {
00228 #ifdef OSG_DEBUG
00229 FWARNING(("TextureTransformChunk::deactivate: Trying to bind texcoord unit %d,"
00230 " but Window %p only supports %d!\n",
00231 idx, win, ntexcoords));
00232 #endif
00233 return;
00234 }
00235
00236 TextureChunk::activateTexture(win, idx);
00237
00238 glMatrixMode(GL_TEXTURE);
00239
00240
00241
00242 if(getUseCameraBeacon())
00243 {
00244 if(action->getCamera() != NULL && action->getViewport() != NULL)
00245 {
00246 Matrix m;
00247 action->getCamera()->getViewing(m,
00248 action->getViewport()->getPixelWidth(),
00249 action->getViewport()->getPixelHeight());
00250 m.invert();
00251 m[3].setValues(0, 0, 0, 1);
00252
00253 glMultMatrixf(m.getValues());
00254
00255 }
00256 }
00257 else
00258 {
00259 glMultMatrixf(getMatrix().getValues());
00260
00261 }
00262 glMatrixMode(GL_MODELVIEW);
00263 }
00264
00265 void TextureTransformChunk::deactivate ( DrawActionBase * action, UInt32 idx )
00266 {
00267 Window *win = action->getWindow();
00268
00269 Real32 ntexcoords;
00270 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00271 Window::unknownConstant
00272 )
00273 {
00274 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00275
00276 if(ntexcoords == Window::unknownConstant)
00277 ntexcoords = 1.0f;
00278 }
00279
00280 if(idx >= static_cast<UInt32>(ntexcoords))
00281 {
00282 #ifdef OSG_DEBUG
00283 FWARNING(("TextureTransformChunk::deactivate: Trying to bind texcoord unit %d,"
00284 " but Window %p only supports %d!\n",
00285 idx, win, ntexcoords));
00286 #endif
00287 return;
00288 }
00289
00290 TextureChunk::activateTexture(win, idx);
00291
00292 glMatrixMode(GL_TEXTURE);
00293
00294 glLoadIdentity();
00295 glMatrixMode(GL_MODELVIEW);
00296 }
00297
00298
00299
00300
00301 Real32 TextureTransformChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00302 {
00303 return 0;
00304 }
00305
00306 bool TextureTransformChunk::operator <(const StateChunk &other) const
00307 {
00308 return this < &other;
00309 }
00310
00311 bool TextureTransformChunk::operator ==(const StateChunk &other) const
00312 {
00313 TextureTransformChunk const *tother =
00314 dynamic_cast<TextureTransformChunk const*>(&other);
00315
00316 if(!tother)
00317 return false;
00318
00319 if(tother == this)
00320 return true;
00321
00322 if(getMatrix() != tother->getMatrix())
00323 return false;
00324
00325 return true;
00326 }
00327
00328 bool TextureTransformChunk::operator !=(const StateChunk &other) const
00329 {
00330 return !(*this == other);
00331 }
00332
00333
00334
00335
00336
00337 #ifdef __sgi
00338 #pragma set woff 1174
00339 #endif
00340
00341 #ifdef OSG_LINUX_ICC
00342 #pragma warning( disable : 177 )
00343 #endif
00344
00345 namespace
00346 {
00347 static char cvsid_cpp[] = "@(#)$Id: $";
00348 static char cvsid_hpp[] = OSGTEXTURETRANSFORMCHUNK_HEADER_CVSID;
00349 static char cvsid_inl[] = OSGTEXTURETRANSFORMCHUNK_INLINE_CVSID;
00350 }