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
00057 OSG_USING_NAMESPACE
00058
00059
00060
00061
00062
00073
00074
00075
00076
00077 StateChunkClass TextureTransformChunk::_class("TextureTransform",
00078 osgMaxTexCoords);
00079
00080
00081
00082
00083
00084 void TextureTransformChunk::initMethod (void)
00085 {
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 TextureTransformChunk::TextureTransformChunk(void) :
00097 Inherited()
00098 {
00099 }
00100
00101 TextureTransformChunk::TextureTransformChunk(const TextureTransformChunk &source) :
00102 Inherited(source)
00103 {
00104 }
00105
00106 TextureTransformChunk::~TextureTransformChunk(void)
00107 {
00108 }
00109
00110
00111
00112 const StateChunkClass *TextureTransformChunk::getClass(void) const
00113 {
00114 return &_class;
00115 }
00116
00117
00118
00119 void TextureTransformChunk::changed(BitVector whichField, UInt32 origin)
00120 {
00121 Inherited::changed(whichField, origin);
00122 }
00123
00124
00125
00126 void TextureTransformChunk::dump( UInt32 ,
00127 const BitVector ) const
00128 {
00129 SLOG << "Dump TextureTransformChunk NI" << std::endl;
00130 }
00131
00132
00133
00134 void TextureTransformChunk::activate ( DrawActionBase * action, UInt32 idx )
00135 {
00136 Window *win = action->getWindow();
00137
00138 Real32 ntexcoords;
00139 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00140 Window::unknownConstant
00141 )
00142 {
00143 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00144
00145 if(ntexcoords == Window::unknownConstant)
00146 ntexcoords = 1.0f;
00147 }
00148
00149 if(idx >= static_cast<UInt32>(ntexcoords))
00150 {
00151 #ifdef OSG_DEBUG
00152 FWARNING(("TextureTransformChunk::deactivate: Trying to bind texcoord unit %d,"
00153 " but Window %p only supports %d!\n",
00154 idx, win, ntexcoords));
00155 #endif
00156 return;
00157 }
00158
00159 TextureChunk::activateTexture(win, idx);
00160
00161 glMatrixMode(GL_TEXTURE);
00162 if(getUseCameraBeacon())
00163 {
00164 if(action->getCamera() != NULL && action->getViewport() != NULL)
00165 {
00166 Matrix m;
00167 action->getCamera()->getViewing(m,
00168 action->getViewport()->getPixelWidth(),
00169 action->getViewport()->getPixelHeight());
00170 m.invert();
00171 m[3].setValues(0, 0, 0, 1);
00172 glLoadMatrixf(m.getValues());
00173 }
00174 }
00175 else
00176 {
00177 glLoadMatrixf(getMatrix().getValues());
00178 }
00179 glMatrixMode(GL_MODELVIEW);
00180 }
00181
00182 void TextureTransformChunk::changeFrom( DrawActionBase * action, StateChunk * old, UInt32 idx )
00183 {
00184
00185
00186 if ( old == this )
00187 return;
00188
00189 Window *win = action->getWindow();
00190
00191 Real32 ntexcoords;
00192 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00193 Window::unknownConstant
00194 )
00195 {
00196 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00197
00198 if(ntexcoords == Window::unknownConstant)
00199 ntexcoords = 1.0f;
00200 }
00201
00202 if(idx >= static_cast<UInt32>(ntexcoords))
00203 {
00204 #ifdef OSG_DEBUG
00205 FWARNING(("TextureTransformChunk::deactivate: Trying to bind texcoord unit %d,"
00206 " but Window %p only supports %d!\n",
00207 idx, win, ntexcoords));
00208 #endif
00209 return;
00210 }
00211
00212 TextureChunk::activateTexture(win, idx);
00213
00214 glMatrixMode(GL_TEXTURE);
00215 if(getUseCameraBeacon())
00216 {
00217 if(action->getCamera() != NULL && action->getViewport() != NULL)
00218 {
00219 Matrix m;
00220 action->getCamera()->getViewing(m,
00221 action->getViewport()->getPixelWidth(),
00222 action->getViewport()->getPixelHeight());
00223 m.invert();
00224 m[3].setValues(0, 0, 0, 1);
00225 glLoadMatrixf(m.getValues());
00226 }
00227 }
00228 else
00229 {
00230 glLoadMatrixf(getMatrix().getValues());
00231 }
00232 glMatrixMode(GL_MODELVIEW);
00233 }
00234
00235 void TextureTransformChunk::deactivate ( DrawActionBase * action, UInt32 idx )
00236 {
00237 Window *win = action->getWindow();
00238
00239 Real32 ntexcoords;
00240 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00241 Window::unknownConstant
00242 )
00243 {
00244 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00245
00246 if(ntexcoords == Window::unknownConstant)
00247 ntexcoords = 1.0f;
00248 }
00249
00250 if(idx >= static_cast<UInt32>(ntexcoords))
00251 {
00252 #ifdef OSG_DEBUG
00253 FWARNING(("TextureTransformChunk::deactivate: Trying to bind texcoord unit %d,"
00254 " but Window %p only supports %d!\n",
00255 idx, win, ntexcoords));
00256 #endif
00257 return;
00258 }
00259
00260 TextureChunk::activateTexture(win, idx);
00261
00262 glMatrixMode(GL_TEXTURE);
00263 glLoadIdentity();
00264 glMatrixMode(GL_MODELVIEW);
00265 }
00266
00267
00268
00269
00270 Real32 TextureTransformChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00271 {
00272 return 0;
00273 }
00274
00275 bool TextureTransformChunk::operator <(const StateChunk &other) const
00276 {
00277 return this < &other;
00278 }
00279
00280 bool TextureTransformChunk::operator ==(const StateChunk &other) const
00281 {
00282 TextureTransformChunk const *tother =
00283 dynamic_cast<TextureTransformChunk const*>(&other);
00284
00285 if(!tother)
00286 return false;
00287
00288 if(tother == this)
00289 return true;
00290
00291 if(getMatrix() != tother->getMatrix())
00292 return false;
00293
00294 return true;
00295 }
00296
00297 bool TextureTransformChunk::operator !=(const StateChunk &other) const
00298 {
00299 return !(*this == other);
00300 }
00301
00302
00303
00304
00305
00306 #ifdef __sgi
00307 #pragma set woff 1174
00308 #endif
00309
00310 #ifdef OSG_LINUX_ICC
00311 #pragma warning( disable : 177 )
00312 #endif
00313
00314 namespace
00315 {
00316 static char cvsid_cpp[] = "@(#)$Id: $";
00317 static char cvsid_hpp[] = OSGTEXTURETRANSFORMCHUNK_HEADER_CVSID;
00318 static char cvsid_inl[] = OSGTEXTURETRANSFORMCHUNK_INLINE_CVSID;
00319 }