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 #include <OSGGLU.h>
00050 #include <OSGGLEXT.h>
00051
00052 #include "OSGDrawActionBase.h"
00053
00054 #include "OSGCubeTextureChunk.h"
00055 #include "OSGRenderAction.h"
00056 #include "OSGImage.h"
00057
00058 OSG_USING_NAMESPACE
00059
00060
00061
00062
00063
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 CubeTextureChunk::CubeTextureChunk(void) :
00090 Inherited()
00091 {
00092 }
00093
00094 CubeTextureChunk::CubeTextureChunk(const CubeTextureChunk &source) :
00095 Inherited(source)
00096 {
00097 }
00098
00099 CubeTextureChunk::~CubeTextureChunk(void)
00100 {
00101 }
00102
00103
00104
00105 const StateChunkClass *CubeTextureChunk::getClass(void) const
00106 {
00107 return TextureChunk::getClass();
00108 }
00109
00110
00111
00112 void CubeTextureChunk::changed(BitVector whichField, UInt32 origin)
00113 {
00114 if(whichField & PosZImageFieldMask)
00115 {
00116 if(origin & ChangedOrigin::Abstract)
00117 {
00118 if(origin & ChangedOrigin::AbstrIncRefCount)
00119 {
00120 addRefCP(_sfPosZImage.getValue());
00121 }
00122 else
00123 {
00124 ImagePtr pImage = _sfPosZImage.getValue();
00125
00126 _sfPosZImage.setValue(NullFC);
00127
00128 setPosZImage(pImage);
00129 }
00130 }
00131 }
00132
00133 if(whichField & PosXImageFieldMask)
00134 {
00135 if(origin & ChangedOrigin::Abstract)
00136 {
00137 if(origin & ChangedOrigin::AbstrIncRefCount)
00138 {
00139 addRefCP(_sfPosXImage.getValue());
00140 }
00141 else
00142 {
00143 ImagePtr pImage = _sfPosXImage.getValue();
00144
00145 _sfPosXImage.setValue(NullFC);
00146
00147 setPosXImage(pImage);
00148 }
00149 }
00150 }
00151
00152 if(whichField & NegXImageFieldMask)
00153 {
00154 if(origin & ChangedOrigin::Abstract)
00155 {
00156 if(origin & ChangedOrigin::AbstrIncRefCount)
00157 {
00158 addRefCP(_sfNegXImage.getValue());
00159 }
00160 else
00161 {
00162 ImagePtr pImage = _sfNegXImage.getValue();
00163
00164 _sfNegXImage.setValue(NullFC);
00165
00166 setNegXImage(pImage);
00167 }
00168 }
00169 }
00170
00171 if(whichField & PosYImageFieldMask)
00172 {
00173 if(origin & ChangedOrigin::Abstract)
00174 {
00175 if(origin & ChangedOrigin::AbstrIncRefCount)
00176 {
00177 addRefCP(_sfPosYImage.getValue());
00178 }
00179 else
00180 {
00181 ImagePtr pImage = _sfPosYImage.getValue();
00182
00183 _sfPosYImage.setValue(NullFC);
00184
00185 setPosYImage(pImage);
00186 }
00187 }
00188 }
00189
00190 if(whichField & NegYImageFieldMask)
00191 {
00192 if(origin & ChangedOrigin::Abstract)
00193 {
00194 if(origin & ChangedOrigin::AbstrIncRefCount)
00195 {
00196 addRefCP(_sfNegYImage.getValue());
00197 }
00198 else
00199 {
00200 ImagePtr pImage = _sfNegYImage.getValue();
00201
00202 _sfNegYImage.setValue(NullFC);
00203
00204 setNegYImage(pImage);
00205 }
00206 }
00207 }
00208 Inherited::changed(whichField, origin);
00209 }
00210
00211
00212
00213 void CubeTextureChunk::onCreate(const CubeTextureChunk *)
00214 {
00215 if(GlobalSystemState == Startup)
00216 return;
00217
00218
00219
00220
00221 CubeTextureChunkPtr tmpPtr(*this);
00222
00223 beginEditCP(tmpPtr, CubeTextureChunk::GLIdFieldMask);
00224
00225 setGLId(
00226 Window::registerGLObject(
00227 osgTypedMethodVoidFunctor2ObjCPtrPtr<CubeTextureChunkPtr,
00228 Window ,
00229 UInt32>(
00230 tmpPtr,
00231 &CubeTextureChunk::handleGL),
00232 1));
00233
00234 endEditCP(tmpPtr, CubeTextureChunk::GLIdFieldMask);
00235 }
00236
00237 void CubeTextureChunk::onDestroy(void)
00238 {
00239 Inherited::onDestroy();
00240
00241 if(_sfPosZImage.getValue() != NullFC)
00242 subRefCP(_sfPosZImage.getValue());
00243
00244 if(_sfPosXImage.getValue() != NullFC)
00245 subRefCP(_sfPosXImage.getValue());
00246 if(_sfNegXImage.getValue() != NullFC)
00247 subRefCP(_sfNegXImage.getValue());
00248
00249 if(_sfPosYImage.getValue() != NullFC)
00250 subRefCP(_sfPosYImage.getValue());
00251 if(_sfNegYImage.getValue() != NullFC)
00252 subRefCP(_sfNegYImage.getValue());
00253 }
00254
00255
00256
00257 void CubeTextureChunk::dump( UInt32 ,
00258 const BitVector ) const
00259 {
00260 SLOG << "Dump CubeTextureChunk NI" << std::endl;
00261 }
00262
00263
00264
00265
00266 void CubeTextureChunk::handleGL(Window *win, UInt32 idstatus)
00267 {
00268 Window::GLObjectStatusE mode;
00269 UInt32 osgid;
00270 GLuint id;
00271
00272
00273 if(win->hasExtension(_arbCubeTex) == false)
00274 return;
00275
00276 Window::unpackIdStatus(idstatus, osgid, mode);
00277
00278 id = win->getGLObjectId(osgid);
00279
00280 if(mode == Window::destroy)
00281 {
00282 glDeleteTextures(1, &id);
00283 }
00284 else if(mode == Window::finaldestroy)
00285 {
00286
00287 }
00288 else if(mode == Window::initialize || mode == Window::reinitialize)
00289 {
00290 if(mode == Window::initialize)
00291 {
00292 glGenTextures(1, &id);
00293 win->setGLObjectId(osgid, id);
00294 }
00295
00296 handleTexture(win, id,
00297 GL_TEXTURE_CUBE_MAP_ARB,
00298 GL_TEXTURE_CUBE_MAP_ARB,
00299 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
00300 mode, getImage());
00301 handleTexture(win, id,
00302 GL_TEXTURE_CUBE_MAP_ARB,
00303 GL_NONE,
00304 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
00305 Window::initialize, getPosZImage());
00306 handleTexture(win, id,
00307 GL_TEXTURE_CUBE_MAP_ARB,
00308 GL_NONE,
00309 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
00310 Window::initialize, getNegYImage());
00311 handleTexture(win, id,
00312 GL_TEXTURE_CUBE_MAP_ARB,
00313 GL_NONE,
00314 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
00315 Window::initialize, getPosYImage());
00316 handleTexture(win, id,
00317 GL_TEXTURE_CUBE_MAP_ARB,
00318 GL_NONE,
00319 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
00320 Window::initialize, getNegXImage());
00321 handleTexture(win, id,
00322 GL_TEXTURE_CUBE_MAP_ARB,
00323 GL_NONE,
00324 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
00325 Window::initialize, getPosXImage());
00326 }
00327 else if(mode == Window::needrefresh)
00328 {
00329 handleTexture(win, id,
00330 GL_TEXTURE_CUBE_MAP_ARB,
00331 GL_TEXTURE_CUBE_MAP_ARB,
00332 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
00333 mode, getImage());
00334 handleTexture(win, id,
00335 GL_TEXTURE_CUBE_MAP_ARB,
00336 GL_NONE,
00337 GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
00338 mode, getPosZImage());
00339 handleTexture(win, id,
00340 GL_TEXTURE_CUBE_MAP_ARB,
00341 GL_NONE,
00342 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
00343 mode, getNegYImage());
00344 handleTexture(win, id,
00345 GL_TEXTURE_CUBE_MAP_ARB,
00346 GL_NONE,
00347 GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
00348 mode, getPosYImage());
00349 handleTexture(win, id,
00350 GL_TEXTURE_CUBE_MAP_ARB,
00351 GL_NONE,
00352 GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
00353 mode, getNegXImage());
00354 handleTexture(win, id,
00355 GL_TEXTURE_CUBE_MAP_ARB,
00356 GL_NONE,
00357 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
00358 mode, getPosXImage());
00359 }
00360 else
00361 {
00362 SWARNING << "Win:" << win << "TextureChunk(" << this
00363 << "::handleGL: Illegal mode: "
00364 << mode << " for id " << id << std::endl;
00365 }
00366 }
00367
00368
00369
00370
00371 void CubeTextureChunk::activate( DrawActionBase *action, UInt32 idx )
00372 {
00373
00374 if(action->getWindow()->hasExtension(_arbCubeTex) == false)
00375 return;
00376
00377 Window *win = action->getWindow();
00378
00379 Real32 nteximages, ntexcoords;
00380 if((nteximages = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
00381 Window::unknownConstant
00382 )
00383 {
00384 nteximages = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00385
00386 if(nteximages == Window::unknownConstant)
00387 nteximages = 1.0f;
00388 }
00389 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00390 Window::unknownConstant
00391 )
00392 {
00393 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00394
00395 if(ntexcoords == Window::unknownConstant)
00396 ntexcoords = 1.0f;
00397 }
00398
00399 if(idx >= static_cast<UInt32>(nteximages))
00400 {
00401 #ifdef OSG_DEBUG
00402 FWARNING(("CubeTextureChunk::activate: Trying to bind image unit %d,"
00403 " but Window %p only supports %d!\n",
00404 idx, win, nteximages));
00405 #endif
00406 return;
00407 }
00408
00409 TextureChunk::activateTexture(win, idx);
00410
00411 win->validateGLObject(getGLId());
00412
00413 glErr("CubeTextureChunk::activate precheck");
00414
00415 FDEBUG(("CubeTextureChunk::activate - %d\n", getGLId()));
00416
00417 action->getStatistics()->getElem(RenderAction::statNTextures)->inc(idx);
00418
00419
00420 if(getImage() != NullFC)
00421 {
00422 action->getStatistics()->getElem(RenderAction::statNTexBytes)->add(
00423 getGLId(), getImage()->getSize() * 6);
00424 }
00425
00426 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, win->getGLObjectId(getGLId()));
00427
00428 #ifdef GL_NV_point_sprite
00429 if(idx < static_cast<UInt32>(ntexcoords))
00430 {
00431 if(getPointSprite() &&
00432 win->hasExtension(_nvPointSprite))
00433 {
00434 glTexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, GL_TRUE);
00435 }
00436 }
00437 #endif
00438
00439 if(idx < static_cast<UInt32>(nteximages))
00440 {
00441 if(getLodBias() != 0.0f &&
00442 win->hasExtension(_extTextureLodBias))
00443 {
00444 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT,
00445 getLodBias());
00446 }
00447 }
00448
00449 Real32 ntexunits = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00450
00451
00452 if(ntexunits == Window::unknownConstant)
00453 ntexunits = 1.0f;
00454
00455 if(idx < static_cast<UInt32>(ntexunits))
00456 {
00457
00458 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, getEnvMode());
00459 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
00460 (GLfloat*)getEnvColor().getValuesRGBA());
00461
00462 if(getEnvMode() == GL_COMBINE_EXT)
00463 {
00464 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, getEnvCombineRGB ());
00465 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, getEnvScaleRGB ());
00466 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, getEnvSource0RGB ());
00467 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, getEnvSource1RGB ());
00468 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, getEnvSource2RGB ());
00469 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, getEnvOperand0RGB());
00470 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, getEnvOperand1RGB());
00471 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, getEnvOperand2RGB());
00472
00473 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, getEnvCombineAlpha ());
00474 glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, getEnvScaleAlpha ());
00475 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, getEnvSource0Alpha ());
00476 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, getEnvSource1Alpha ());
00477 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, getEnvSource2Alpha ());
00478 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT,getEnvOperand0Alpha());
00479 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT,getEnvOperand1Alpha());
00480 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT,getEnvOperand2Alpha());
00481 }
00482
00483 TextureChunk::handleTextureShader(win, GL_TEXTURE_CUBE_MAP_ARB);
00484
00485 if(getShaderOperation() != GL_NONE &&
00486 win->hasExtension(_nvTextureShader) &&
00487 idx == 0)
00488 {
00489 glEnable(GL_TEXTURE_SHADER_NV);
00490 }
00491 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
00492 }
00493
00494 glErr("CubeTextureChunk::activate");
00495 }
00496
00497 void CubeTextureChunk::changeFrom( DrawActionBase *action,
00498 StateChunk *old ,
00499 UInt32 idx )
00500 {
00501
00502 if(action->getWindow()->hasExtension(_arbCubeTex) == false)
00503 return;
00504
00505
00506
00507
00508 if(old == this)
00509 return;
00510
00511
00512
00513 if(getTypeId() != old->getTypeId())
00514 {
00515 old->deactivate(action, idx);
00516 activate(action, idx);
00517 return;
00518 }
00519
00520 CubeTextureChunk *oldp = dynamic_cast<CubeTextureChunk *>(old);
00521
00522 glErr("CubeTextureChunk::changeFrom precheck");
00523
00524 Window *win = action->getWindow();
00525
00526 if(TextureChunk::activateTexture(win, idx))
00527 return;
00528
00529 UInt32 nteximages, ntexcoords, ntexunits;
00530
00531 Real32 dummy = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00532
00533 if(dummy == Window::unknownConstant)
00534 {
00535 ntexunits = 1;
00536 }
00537 else
00538 {
00539 ntexunits = static_cast<UInt32>(dummy);
00540 }
00541
00542 if((dummy = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
00543 Window::unknownConstant
00544 )
00545 {
00546 nteximages = ntexunits;
00547 }
00548 else
00549 {
00550 nteximages = static_cast<UInt32>(dummy);
00551 }
00552
00553 if((dummy = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00554 Window::unknownConstant
00555 )
00556 {
00557 ntexcoords = ntexunits;
00558 }
00559 else
00560 {
00561 ntexcoords = static_cast<UInt32>(dummy);
00562 }
00563
00564 if(idx >= nteximages)
00565 {
00566 #ifdef OSG_DEBUG
00567 FWARNING(("TextureChunk::activate: Trying to bind image unit %d,"
00568 " but Window %p only supports %d!\n",
00569 idx, win, nteximages));
00570 #endif
00571 return;
00572 }
00573
00574 win->validateGLObject(getGLId());
00575
00576 FDEBUG(("CubeTextureChunk::activate - %d\n", getGLId()));
00577
00578 action->getStatistics()->getElem(RenderAction::statNTextures)->inc(getGLId());
00579
00580
00581 if(getImage() != NullFC)
00582 {
00583 action->getStatistics()->getElem(RenderAction::statNTexBytes)->add(
00584 getGLId(), getImage()->getSize() * 6);
00585 }
00586
00587 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, win->getGLObjectId(getGLId()));
00588
00589 #ifdef GL_NV_point_sprite
00590 if(idx < ntexcoords)
00591 {
00592 if(oldp->getPointSprite() != getPointSprite() &&
00593 win->hasExtension(_nvPointSprite)
00594 )
00595 {
00596 glTexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, getPointSprite());
00597 }
00598 }
00599 #endif
00600
00601 if(idx < nteximages)
00602 {
00603 if(oldp->getLodBias() != getLodBias() &&
00604 win->hasExtension(_extTextureLodBias)
00605 )
00606 {
00607 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT,
00608 getLodBias());
00609 }
00610 }
00611
00612 if(idx < ntexunits)
00613 {
00614 if(oldp->getEnvMode() != getEnvMode())
00615 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, getEnvMode());
00616
00617 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,
00618 (GLfloat*)getEnvColor().getValuesRGBA());
00619
00620 if(getEnvMode() == GL_COMBINE_EXT)
00621 {
00622 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, getEnvCombineRGB ());
00623 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, getEnvScaleRGB ());
00624 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, getEnvSource0RGB ());
00625 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, getEnvSource1RGB ());
00626 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, getEnvSource2RGB ());
00627 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, getEnvOperand0RGB());
00628 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, getEnvOperand1RGB());
00629 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, getEnvOperand2RGB());
00630
00631 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, getEnvCombineAlpha ());
00632 glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, getEnvScaleAlpha ());
00633 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, getEnvSource0Alpha ());
00634 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, getEnvSource1Alpha ());
00635 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, getEnvSource2Alpha ());
00636 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT,getEnvOperand0Alpha());
00637 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT,getEnvOperand1Alpha());
00638 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT,getEnvOperand2Alpha());
00639 }
00640
00641 if(win->hasExtension(_nvTextureShader))
00642 {
00643 if( getShaderOperation() != GL_NONE &&
00644 oldp->getShaderOperation() == GL_NONE
00645 )
00646 {
00647 handleTextureShader(win, GL_TEXTURE_CUBE_MAP_ARB);
00648 if(idx == 0)
00649 glEnable(GL_TEXTURE_SHADER_NV);
00650 }
00651 else if( getShaderOperation() == GL_NONE &&
00652 oldp->getShaderOperation() != GL_NONE
00653 )
00654 {
00655 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
00656 if(idx == 0)
00657 glDisable(GL_TEXTURE_SHADER_NV);
00658 }
00659 }
00660 }
00661
00662 glErr("CubeTextureChunk::changeFrom");
00663 }
00664
00665 void CubeTextureChunk::deactivate(DrawActionBase *action, UInt32 idx)
00666 {
00667
00668 if(action->getWindow()->hasExtension(_arbCubeTex) == false)
00669 return;
00670
00671 Window *win = action->getWindow();
00672
00673 Real32 nteximages, ntexcoords;
00674 if((nteximages = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
00675 Window::unknownConstant
00676 )
00677 {
00678 nteximages = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00679
00680 if(nteximages == Window::unknownConstant)
00681 nteximages = 1.0f;
00682 }
00683 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00684 Window::unknownConstant
00685 )
00686 {
00687 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00688
00689 if(ntexcoords == Window::unknownConstant)
00690 ntexcoords = 1.0f;
00691 }
00692
00693 if(idx >= static_cast<UInt32>(nteximages))
00694 {
00695 #ifdef OSG_DEBUG
00696 FWARNING(("CubeTextureChunk::deactivate: Trying to bind image unit %d,"
00697 " but Window %p only supports %d!\n",
00698 idx, win, nteximages));
00699 #endif
00700 return;
00701 }
00702
00703
00704 bool isActive = false;
00705
00706 #ifdef GL_NV_point_sprite
00707 if(getPointSprite() &&
00708 win->hasExtension(_nvPointSprite) &&
00709 idx < static_cast<UInt32>(ntexcoords)
00710 )
00711 {
00712 if(!isActive)
00713 {
00714 TextureChunk::activateTexture(win, idx);
00715 isActive = true;
00716 }
00717 glTexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, GL_FALSE);
00718 }
00719 #endif
00720
00721 if(getLodBias() != 0.0f &&
00722 win->hasExtension(_extTextureLodBias))
00723 {
00724 if(!isActive)
00725 TextureChunk::activateTexture(win, idx);
00726 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT,
00727 0.0f);
00728 }
00729
00730 Real32 ntexunits = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00731 if(ntexunits == Window::unknownConstant)
00732 ntexunits = 1.0f;
00733
00734 if(idx >= static_cast<UInt32>(ntexunits))
00735 return;
00736
00737 if(!isActive)
00738 TextureChunk::activateTexture(win, idx);
00739
00740 if(getShaderOperation() != GL_NONE &&
00741 win->hasExtension(_nvTextureShader))
00742 {
00743 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
00744
00745 if(idx == 0)
00746 glDisable(GL_TEXTURE_SHADER_NV);
00747 }
00748
00749 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
00750
00751 glErr("CubeTextureChunk::deactivate");
00752 }
00753
00754
00755
00756 Real32 CubeTextureChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00757 {
00758 return 0;
00759 }
00760
00761 bool CubeTextureChunk::operator < (const StateChunk &other) const
00762 {
00763 return this < &other;
00764 }
00765
00766 bool CubeTextureChunk::operator == (const StateChunk &other) const
00767 {
00768 CubeTextureChunk const *tother =
00769 dynamic_cast<CubeTextureChunk const*>(&other);
00770
00771 if(!tother)
00772 return false;
00773
00774 if(tother == this)
00775 return true;
00776
00777 return TextureChunk::operator==(other) &&
00778 getPosZImage() == tother->getPosZImage() &&
00779 getPosYImage() == tother->getPosYImage() &&
00780 getNegYImage() == tother->getNegYImage() &&
00781 getPosXImage() == tother->getPosXImage() &&
00782 getNegXImage() == tother->getNegXImage();
00783 }
00784
00785 bool CubeTextureChunk::operator != (const StateChunk &other) const
00786 {
00787 return ! (*this == other);
00788 }
00789
00790
00791
00792
00793 #ifdef __sgi
00794 #pragma set woff 1174
00795 #endif
00796
00797 #ifdef OSG_LINUX_ICC
00798 #pragma warning( disable : 177 )
00799 #endif
00800
00801 namespace
00802 {
00803 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00804 static Char8 cvsid_hpp[] = OSGCUBETEXTURECHUNK_HEADER_CVSID;
00805 static Char8 cvsid_inl[] = OSGCUBETEXTURECHUNK_INLINE_CVSID;
00806 }