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,
00460 GL_TEXTURE_ENV_COLOR,
00461 static_cast<const GLfloat*>(getEnvColor().getValuesRGBA()));
00462
00463 if(getEnvMode() == GL_COMBINE_EXT)
00464 {
00465 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, getEnvCombineRGB ());
00466 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, getEnvScaleRGB ());
00467 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, getEnvSource0RGB ());
00468 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, getEnvSource1RGB ());
00469 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, getEnvSource2RGB ());
00470 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, getEnvOperand0RGB());
00471 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, getEnvOperand1RGB());
00472 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, getEnvOperand2RGB());
00473
00474 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, getEnvCombineAlpha ());
00475 glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, getEnvScaleAlpha ());
00476 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, getEnvSource0Alpha ());
00477 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, getEnvSource1Alpha ());
00478 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, getEnvSource2Alpha ());
00479 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT,getEnvOperand0Alpha());
00480 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT,getEnvOperand1Alpha());
00481 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT,getEnvOperand2Alpha());
00482 }
00483
00484 TextureChunk::handleTextureShader(win, GL_TEXTURE_CUBE_MAP_ARB);
00485
00486 if(getShaderOperation() != GL_NONE &&
00487 win->hasExtension(_nvTextureShader) &&
00488 idx == 0)
00489 {
00490 glEnable(GL_TEXTURE_SHADER_NV);
00491 }
00492 glEnable(GL_TEXTURE_CUBE_MAP_ARB);
00493 }
00494
00495 glErr("CubeTextureChunk::activate");
00496 }
00497
00498 void CubeTextureChunk::changeFrom( DrawActionBase *action,
00499 StateChunk *old ,
00500 UInt32 idx )
00501 {
00502
00503 if(action->getWindow()->hasExtension(_arbCubeTex) == false)
00504 return;
00505
00506
00507
00508
00509 if(old == this)
00510 return;
00511
00512
00513
00514 if(getTypeId() != old->getTypeId())
00515 {
00516 old->deactivate(action, idx);
00517 activate(action, idx);
00518 return;
00519 }
00520
00521 CubeTextureChunk *oldp = dynamic_cast<CubeTextureChunk *>(old);
00522
00523 glErr("CubeTextureChunk::changeFrom precheck");
00524
00525 Window *win = action->getWindow();
00526
00527 if(TextureChunk::activateTexture(win, idx))
00528 return;
00529
00530 UInt32 nteximages, ntexcoords, ntexunits;
00531
00532 Real32 dummy = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00533
00534 if(dummy == Window::unknownConstant)
00535 {
00536 ntexunits = 1;
00537 }
00538 else
00539 {
00540 ntexunits = static_cast<UInt32>(dummy);
00541 }
00542
00543 if((dummy = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
00544 Window::unknownConstant
00545 )
00546 {
00547 nteximages = ntexunits;
00548 }
00549 else
00550 {
00551 nteximages = static_cast<UInt32>(dummy);
00552 }
00553
00554 if((dummy = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00555 Window::unknownConstant
00556 )
00557 {
00558 ntexcoords = ntexunits;
00559 }
00560 else
00561 {
00562 ntexcoords = static_cast<UInt32>(dummy);
00563 }
00564
00565 if(idx >= nteximages)
00566 {
00567 #ifdef OSG_DEBUG
00568 FWARNING(("TextureChunk::activate: Trying to bind image unit %d,"
00569 " but Window %p only supports %d!\n",
00570 idx, win, nteximages));
00571 #endif
00572 return;
00573 }
00574
00575 win->validateGLObject(getGLId());
00576
00577 FDEBUG(("CubeTextureChunk::activate - %d\n", getGLId()));
00578
00579 action->getStatistics()->getElem(RenderAction::statNTextures)->inc(getGLId());
00580
00581
00582 if(getImage() != NullFC)
00583 {
00584 action->getStatistics()->getElem(RenderAction::statNTexBytes)->add(
00585 getGLId(), getImage()->getSize() * 6);
00586 }
00587
00588 glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, win->getGLObjectId(getGLId()));
00589
00590 #ifdef GL_NV_point_sprite
00591 if(idx < ntexcoords)
00592 {
00593 if(oldp->getPointSprite() != getPointSprite() &&
00594 win->hasExtension(_nvPointSprite)
00595 )
00596 {
00597 glTexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, getPointSprite());
00598 }
00599 }
00600 #endif
00601
00602 if(idx < nteximages)
00603 {
00604 if(oldp->getLodBias() != getLodBias() &&
00605 win->hasExtension(_extTextureLodBias)
00606 )
00607 {
00608 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT,
00609 getLodBias());
00610 }
00611 }
00612
00613 if(idx < ntexunits)
00614 {
00615 if(oldp->getEnvMode() != getEnvMode())
00616 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, getEnvMode());
00617
00618 glTexEnvfv(GL_TEXTURE_ENV,
00619 GL_TEXTURE_ENV_COLOR,
00620 reinterpret_cast<const GLfloat*>(
00621 getEnvColor().getValuesRGBA()));
00622
00623 if(getEnvMode() == GL_COMBINE_EXT)
00624 {
00625 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, getEnvCombineRGB ());
00626 glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, getEnvScaleRGB ());
00627 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, getEnvSource0RGB ());
00628 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, getEnvSource1RGB ());
00629 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, getEnvSource2RGB ());
00630 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, getEnvOperand0RGB());
00631 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, getEnvOperand1RGB());
00632 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, getEnvOperand2RGB());
00633
00634 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, getEnvCombineAlpha ());
00635 glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, getEnvScaleAlpha ());
00636 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, getEnvSource0Alpha ());
00637 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_EXT, getEnvSource1Alpha ());
00638 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA_EXT, getEnvSource2Alpha ());
00639 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT,getEnvOperand0Alpha());
00640 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT,getEnvOperand1Alpha());
00641 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT,getEnvOperand2Alpha());
00642 }
00643
00644 if(win->hasExtension(_nvTextureShader))
00645 {
00646 if( getShaderOperation() != GL_NONE &&
00647 oldp->getShaderOperation() == GL_NONE
00648 )
00649 {
00650 handleTextureShader(win, GL_TEXTURE_CUBE_MAP_ARB);
00651 if(idx == 0)
00652 glEnable(GL_TEXTURE_SHADER_NV);
00653 }
00654 else if( getShaderOperation() == GL_NONE &&
00655 oldp->getShaderOperation() != GL_NONE
00656 )
00657 {
00658 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
00659 if(idx == 0)
00660 glDisable(GL_TEXTURE_SHADER_NV);
00661 }
00662 }
00663 }
00664
00665 glErr("CubeTextureChunk::changeFrom");
00666 }
00667
00668 void CubeTextureChunk::deactivate(DrawActionBase *action, UInt32 idx)
00669 {
00670
00671 if(action->getWindow()->hasExtension(_arbCubeTex) == false)
00672 return;
00673
00674 Window *win = action->getWindow();
00675
00676 Real32 nteximages, ntexcoords;
00677 if((nteximages = win->getConstantValue(GL_MAX_TEXTURE_IMAGE_UNITS_ARB)) ==
00678 Window::unknownConstant
00679 )
00680 {
00681 nteximages = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00682
00683 if(nteximages == Window::unknownConstant)
00684 nteximages = 1.0f;
00685 }
00686 if((ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_COORDS_ARB)) ==
00687 Window::unknownConstant
00688 )
00689 {
00690 ntexcoords = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00691
00692 if(ntexcoords == Window::unknownConstant)
00693 ntexcoords = 1.0f;
00694 }
00695
00696 if(idx >= static_cast<UInt32>(nteximages))
00697 {
00698 #ifdef OSG_DEBUG
00699 FWARNING(("CubeTextureChunk::deactivate: Trying to bind image unit %d,"
00700 " but Window %p only supports %d!\n",
00701 idx, win, nteximages));
00702 #endif
00703 return;
00704 }
00705
00706
00707 bool isActive = false;
00708
00709 #ifdef GL_NV_point_sprite
00710 if(getPointSprite() &&
00711 win->hasExtension(_nvPointSprite) &&
00712 idx < static_cast<UInt32>(ntexcoords)
00713 )
00714 {
00715 if(!isActive)
00716 {
00717 TextureChunk::activateTexture(win, idx);
00718 isActive = true;
00719 }
00720 glTexEnvi(GL_POINT_SPRITE_NV, GL_COORD_REPLACE_NV, GL_FALSE);
00721 }
00722 #endif
00723
00724 if(getLodBias() != 0.0f &&
00725 win->hasExtension(_extTextureLodBias))
00726 {
00727 if(!isActive)
00728 TextureChunk::activateTexture(win, idx);
00729 glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT,
00730 0.0f);
00731 }
00732
00733 Real32 ntexunits = win->getConstantValue(GL_MAX_TEXTURE_UNITS_ARB);
00734 if(ntexunits == Window::unknownConstant)
00735 ntexunits = 1.0f;
00736
00737 if(idx >= static_cast<UInt32>(ntexunits))
00738 return;
00739
00740 if(!isActive)
00741 TextureChunk::activateTexture(win, idx);
00742
00743 if(getShaderOperation() != GL_NONE &&
00744 win->hasExtension(_nvTextureShader))
00745 {
00746 glTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_NONE);
00747
00748 if(idx == 0)
00749 glDisable(GL_TEXTURE_SHADER_NV);
00750 }
00751
00752 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
00753
00754 glErr("CubeTextureChunk::deactivate");
00755 }
00756
00757
00758
00759 Real32 CubeTextureChunk::switchCost(StateChunk *OSG_CHECK_ARG(chunk))
00760 {
00761 return 0;
00762 }
00763
00764 bool CubeTextureChunk::operator < (const StateChunk &other) const
00765 {
00766 return this < &other;
00767 }
00768
00769 bool CubeTextureChunk::operator == (const StateChunk &other) const
00770 {
00771 CubeTextureChunk const *tother =
00772 dynamic_cast<CubeTextureChunk const*>(&other);
00773
00774 if(!tother)
00775 return false;
00776
00777 if(tother == this)
00778 return true;
00779
00780 return TextureChunk::operator==(other) &&
00781 getPosZImage() == tother->getPosZImage() &&
00782 getPosYImage() == tother->getPosYImage() &&
00783 getNegYImage() == tother->getNegYImage() &&
00784 getPosXImage() == tother->getPosXImage() &&
00785 getNegXImage() == tother->getNegXImage();
00786 }
00787
00788 bool CubeTextureChunk::operator != (const StateChunk &other) const
00789 {
00790 return ! (*this == other);
00791 }
00792
00793
00794
00795
00796 #ifdef __sgi
00797 #pragma set woff 1174
00798 #endif
00799
00800 #ifdef OSG_LINUX_ICC
00801 #pragma warning( disable : 177 )
00802 #endif
00803
00804 namespace
00805 {
00806 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00807 static Char8 cvsid_hpp[] = OSGCUBETEXTURECHUNK_HEADER_CVSID;
00808 static Char8 cvsid_inl[] = OSGCUBETEXTURECHUNK_INLINE_CVSID;
00809 }