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
00047 #include <OSGConfig.h>
00048 #include <OSGGL.h>
00049 #include <OSGGLEXT.h>
00050 #include <OSGSlicer.h>
00051 #include <OSGGLU.h>
00052
00053 #include "OSGDVRIsoShader.h"
00054
00055 OSG_USING_NAMESPACE
00056
00057
00058
00059
00060 UInt32 DVRIsoShader::_ARB_multitexture = Window::invalidExtensionID;
00061 UInt32 DVRIsoShader::_EXT_texture3D = Window::invalidExtensionID;
00062 UInt32 DVRIsoShader::_NV_register_combiners = Window::invalidExtensionID;
00063 UInt32 DVRIsoShader::_NV_register_combiners2 = Window::invalidExtensionID;
00064 UInt32 DVRIsoShader::_SGI_color_matrix = Window::invalidExtensionID;
00065 UInt32 DVRIsoShader::_ARB_fragment_program = Window::invalidExtensionID;
00066 UInt32 DVRIsoShader::_EXT_secondary_color = Window::invalidExtensionID;
00067
00068
00069 UInt32 DVRIsoShader::_funcActiveTextureARB =
00070 Window::invalidFunctionID;
00071
00072 UInt32 DVRIsoShader::_funcMultiTexCoord2dARB =
00073 Window::invalidFunctionID;
00074
00075 UInt32 DVRIsoShader::_funcTexImage3DEXT =
00076 Window::invalidFunctionID;
00077
00078 UInt32 DVRIsoShader::_funcCombinerParameteriNV =
00079 Window::invalidFunctionID;
00080
00081 UInt32 DVRIsoShader::_funcCombinerParameterfvNV =
00082 Window::invalidFunctionID;
00083
00084 UInt32 DVRIsoShader::_funcCombinerStageParameterfvNV =
00085 Window::invalidFunctionID;
00086
00087 UInt32 DVRIsoShader::_funcSecondaryColor3fEXT =
00088 Window::invalidFunctionID;
00089
00090 UInt32 DVRIsoShader::_funcSecondaryColor3fvEXT =
00091 Window::invalidFunctionID;
00092
00093 UInt32 DVRIsoShader::_funcCombinerInputNV =
00094 Window::invalidFunctionID;
00095
00096 UInt32 DVRIsoShader::_funcCombinerOutputNV =
00097 Window::invalidFunctionID;
00098
00099 UInt32 DVRIsoShader::_funcFinalCombinerInputNV =
00100 Window::invalidFunctionID;
00101
00106
00107
00108 #ifndef GL_VERSION_1_2
00109 # define GL_FUNC_TEXIMAGE3D OSG_DLSYM_UNDERSCORE"glTexImage3DEXT"
00110 # define GL_FUNC_TEXSUBIMAGE3D OSG_DLSYM_UNDERSCORE"glTexSubImage3DEXT"
00111 #else
00112 # define GL_FUNC_TEXIMAGE3D OSG_DLSYM_UNDERSCORE"glTexImage3D"
00113 # define GL_FUNC_TEXSUBIMAGE3D OSG_DLSYM_UNDERSCORE"glTexSubImage3D"
00114 #endif
00115
00117 DVRIsoShader::DVRIsoShader(void) :
00118 Inherited()
00119 {
00120 m_gradientImage = NullFC;
00121 m_shadingMode = SM_NONE;
00122 m_pFragProg = NullFC;
00123 m_textureId = -1;
00124
00125
00126 _ARB_multitexture =
00127 Window::registerExtension("GL_ARB_multitexture" );
00128
00129 _EXT_texture3D =
00130 Window::registerExtension("GL_EXT_texture3D" );
00131
00132 _EXT_secondary_color =
00133 Window::registerExtension("GL_EXT_secondary_color" );
00134
00135 _NV_register_combiners =
00136 Window::registerExtension("GL_NV_register_combiners" );
00137
00138 _NV_register_combiners2 =
00139 Window::registerExtension("GL_NV_register_combiners2");
00140
00141 _SGI_color_matrix =
00142 Window::registerExtension("GL_SGI_color_matrix" );
00143
00144 _ARB_fragment_program =
00145 Window::registerExtension("GL_ARB_fragment_program" );
00146
00147
00148 _funcActiveTextureARB =
00149 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glActiveTextureARB",
00150 _ARB_multitexture);
00151
00152 _funcMultiTexCoord2dARB =
00153 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glMultiTexCoord2dARB",
00154 _ARB_multitexture);
00155
00156 _funcTexImage3DEXT =
00157 Window::registerFunction(GL_FUNC_TEXIMAGE3D,
00158 _EXT_texture3D, 0x0102);
00159
00160 _funcCombinerParameteriNV =
00161 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glCombinerParameteriNV",
00162 _NV_register_combiners);
00163
00164 _funcCombinerParameterfvNV =
00165 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glCombinerParameterfvNV",
00166 _NV_register_combiners);
00167
00168 _funcCombinerStageParameterfvNV =
00169 Window::registerFunction(
00170 OSG_DLSYM_UNDERSCORE"glCombinerStageParameterfvNV",
00171 _NV_register_combiners);
00172
00173 _funcSecondaryColor3fEXT =
00174 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glSecondaryColor3fEXT",
00175 _EXT_secondary_color);
00176
00177 _funcSecondaryColor3fvEXT =
00178 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glSecondaryColor3fvEXT",
00179 _EXT_secondary_color);
00180
00181 _funcCombinerInputNV =
00182 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glCombinerInputNV",
00183 _NV_register_combiners);
00184
00185 _funcCombinerOutputNV =
00186 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glCombinerOutputNV",
00187 _NV_register_combiners);
00188
00189 _funcFinalCombinerInputNV =
00190 Window::registerFunction(OSG_DLSYM_UNDERSCORE"glFinalCombinerInputNV",
00191 _NV_register_combiners);
00192
00193 }
00194
00196 DVRIsoShader::DVRIsoShader(const DVRIsoShader &source) :
00197 Inherited(source)
00198 {
00199 m_gradientImage = NullFC;
00200 m_shadingMode = SM_NONE;
00201 m_pFragProg = NullFC;
00202 m_textureId = -1;
00203 }
00204
00206 DVRIsoShader::~DVRIsoShader(void)
00207 {
00208 if(m_pFragProg != NullFC)
00209 {
00210 subRefCP(m_pFragProg);
00211
00212 m_pFragProg = NullFC;
00213 }
00214
00215 if(m_gradientImage != NullFC)
00216 {
00217 subRefCP(m_gradientImage);
00218
00219 m_gradientImage = NullFC;
00220 }
00221
00222 m_textureId = -1;
00223 }
00224
00225
00226
00228 void DVRIsoShader::initMethod(void)
00229 {
00230 }
00231
00233
00234 void DVRIsoShader::changed(BitVector whichField, UInt32 origin)
00235 {
00236
00237 if(whichField & ShadeModeFieldMask)
00238 setActiveShadeMode(SM_AUTO);
00239
00240 Inherited::changed(whichField, origin);
00241 }
00242
00244 void DVRIsoShader::dump( UInt32 ,
00245 const BitVector ) const
00246 {
00247 SLOG << "Dump DVRIsoShader NI" << std::endl;
00248 }
00249
00250
00251 bool DVRIsoShader::initialize(DVRVolume *volume, DrawActionBase *action)
00252 {
00253
00254 DVRVolumeTexturePtr vol = DVRVOLUME_PARAMETER(volume, DVRVolumeTexture);
00255
00256 if((volume == NULL) || (vol == NullFC))
00257 {
00258 SWARNING << "DVRIsoShader - NO Volume" << std::endl;
00259 return false;
00260 }
00261
00262
00263 tryMode(volume, action, getShadeMode());
00264
00265 GLenum nInternalFormat = GL_RGBA;
00266 GLenum nExternalFormat = GL_RGBA;
00267
00268
00269 if(m_gradientImage != NullFC)
00270 subRefCP(m_gradientImage);
00271
00272 m_gradientImage = createGradientImage(vol);
00273
00274 addRefCP(m_gradientImage);
00275
00276 if((m_shadingMode == SM_REGISTER_COMBINERS_MULTI2D) ||
00277 (m_shadingMode == SM_FRAGMENT_PROGRAM_2D ) )
00278 {
00279
00280 m_textureId = volume->getTextureManager().registerTexture(
00281 m_gradientImage,
00282 nInternalFormat,
00283 nExternalFormat,
00284 true,
00285 0,
00286 1);
00287 }
00288 else
00289 {
00290
00291 m_textureId = volume->getTextureManager().registerTexture(
00292 m_gradientImage,
00293 nInternalFormat,
00294 nExternalFormat,
00295 true,
00296 0,
00297 -1);
00298 }
00299
00300 if( m_textureId < 0)
00301 {
00302 SWARNING << "DVRIsoShader - Could not register texture: "
00303 << m_textureId
00304 << std::endl;
00305
00306 subRefCP(m_gradientImage);
00307
00308 return false;
00309 }
00310
00311 return true;
00312 }
00313
00314
00315
00316 void DVRIsoShader::activate(DVRVolume *volume, DrawActionBase *action)
00317 {
00318
00319
00320
00321 if(getActiveShadeMode() == SM_AUTO)
00322 {
00323 cleanup (volume, action);
00324 initialize(volume, action);
00325
00326
00327 beginEditCP(DVRVolumePtr(volume), DVRVolume::ShaderFieldMask);
00328 endEditCP(DVRVolumePtr (volume), DVRVolume::ShaderFieldMask);
00329 }
00330
00331 switch(m_shadingMode)
00332 {
00333 case SM_COLORMATRIX_2D:
00334 case SM_COLORMATRIX_3D:
00335 activate_ColorMatrixShading(volume, action);
00336 break;
00337
00338 case SM_REGISTER_COMBINERS_2D:
00339 case SM_REGISTER_COMBINERS_MULTI2D:
00340 case SM_REGISTER_COMBINERS_3D:
00341 activate_NVRegisterCombinerShading(volume, action);
00342 break;
00343
00344 case SM_FRAGMENT_PROGRAM_2D:
00345 case SM_FRAGMENT_PROGRAM_3D:
00346 activate_FragmentProgramShading(volume, action);
00347 break;
00348
00349 case SM_NONE:
00350 default:
00351 break;
00352 }
00353 }
00354
00355
00356
00357 void DVRIsoShader::brickActivate(DVRVolume *, DrawActionBase *, Brick *)
00358 {
00359 FDEBUG(("DVRIsoShader::brickActivate - nothing to do\n"));
00360 }
00361
00362
00363
00364 void DVRIsoShader::deactivate(DVRVolume *volume, DrawActionBase *action)
00365 {
00366 switch(m_shadingMode)
00367 {
00368 case SM_COLORMATRIX_2D:
00369 case SM_COLORMATRIX_3D:
00370 deactivate_ColorMatrixShading(volume, action);
00371 break;
00372
00373 case SM_REGISTER_COMBINERS_2D:
00374 case SM_REGISTER_COMBINERS_MULTI2D:
00375 case SM_REGISTER_COMBINERS_3D:
00376 deactivate_NVRegisterCombinerShading(volume, action);
00377 break;
00378
00379 case SM_FRAGMENT_PROGRAM_2D:
00380 case SM_FRAGMENT_PROGRAM_3D:
00381 deactivate_FragmentProgramShading(volume, action);
00382 break;
00383
00384 case SM_NONE:
00385 default:
00386 break;
00387 }
00388 }
00389
00390
00391
00392 void DVRIsoShader::cleanup(DVRVolume *volume, DrawActionBase *)
00393 {
00394 if(m_pFragProg != NullFC)
00395 {
00396 subRefCP(m_pFragProg);
00397
00398 m_pFragProg = NullFC;
00399 }
00400
00401 if(m_gradientImage != NullFC)
00402 {
00403 subRefCP(m_gradientImage);
00404
00405 m_gradientImage = NullFC;
00406 }
00407
00408 if (m_textureId != -1)
00409 {
00410 volume->getTextureManager().unregisterTexture(m_textureId);
00411 }
00412 }
00413
00414
00415
00416
00417 void DVRIsoShader::renderSlice(DVRVolume *volume,
00418 DrawActionBase *action,
00419 Real32 *data,
00420 UInt32 vertices,
00421 UInt32 values )
00422 {
00423 switch(m_shadingMode)
00424 {
00425 case SM_REGISTER_COMBINERS_MULTI2D:
00426 renderSlice_NVRegisterCombinerShading(volume,
00427 action,
00428 data,
00429 vertices,
00430 values);
00431 break;
00432
00433 case SM_FRAGMENT_PROGRAM_2D:
00434 renderSlice_FragmentProgramShading(volume,
00435 action,
00436 data,
00437 vertices,
00438 values);
00439 break;
00440 default:
00441 break;
00442 }
00443 }
00444
00445
00446
00447 void DVRIsoShader::renderSlice(DVRVolume *volume,
00448 DrawActionBase *action,
00449 DVRRenderSlice *clippedSlice)
00450 {
00451 switch(m_shadingMode)
00452 {
00453 case SM_REGISTER_COMBINERS_MULTI2D:
00454 renderSlice_NVRegisterCombinerShading(volume,action,clippedSlice);
00455 break;
00456
00457 case SM_FRAGMENT_PROGRAM_2D:
00458 renderSlice_FragmentProgramShading(volume,action,clippedSlice);
00459 break;
00460
00461 default:
00462 break;
00463 }
00464 }
00465
00466
00467
00468
00469 bool DVRIsoShader::hasRenderCallback(void)
00470 {
00471 switch(m_shadingMode)
00472 {
00473 case SM_REGISTER_COMBINERS_MULTI2D:
00474 return true;
00475
00476 case SM_FRAGMENT_PROGRAM_2D:
00477 return true;
00478
00479 default:
00480 break;
00481 }
00482
00483 return false;
00484 }
00485
00486
00487
00488 bool DVRIsoShader::useMTSlabs(void)
00489 {
00490 switch(m_shadingMode)
00491 {
00492 case SM_REGISTER_COMBINERS_MULTI2D:
00493 return true;
00494
00495 case SM_FRAGMENT_PROGRAM_2D:
00496 return true;
00497
00498 default:
00499 break;
00500 }
00501
00502 return false;
00503 }
00504
00505
00506
00507 ImagePtr DVRIsoShader::createGradientImage(DVRVolumeTexturePtr volTex)
00508 {
00509 int resX = (int) volTex->getImage()->getWidth();
00510 int resY = (int) volTex->getImage()->getHeight();
00511 int resZ = (int) volTex->getImage()->getDepth();
00512
00513 int nGradSetSize = resX * resY * resZ * 4;
00514 int zOff = resX * resY;
00515 int yOff = resX;
00516
00517
00518
00519 UChar8 *volData = volTex->getImage()->getData();
00520
00521 UChar8 *gradbuffer = new UChar8[nGradSetSize];
00522
00523 Vec3f gradient;
00524
00525 for(int z = 0 ; z < resZ ; z++)
00526 {
00527 for(int y = 0 ; y < resY ; y++)
00528 {
00529 for(int x = 0 ; x < resX ; x++)
00530 {
00531
00532 if(x == 0)
00533 {
00534 gradient = Vec3f(-1.0, 0.0, 0.0);
00535 }
00536 else if (x == resX-1)
00537 {
00538 gradient = Vec3f( 1.0, 0.0, 0.0);
00539 }
00540 else if (y == 0)
00541 {
00542 gradient = Vec3f(0.0, -1.0, 0.0);
00543 }
00544 else if (y == resY-1)
00545 {
00546 gradient = Vec3f(0.0, 1.0, 0.0);
00547 }
00548 else if (z == 0)
00549 {
00550 gradient = Vec3f(0.0, 0.0, -1.0);
00551 } else if (z == resZ-1)
00552 {
00553 gradient = Vec3f(0.0, 0.0, 1.0);
00554 }
00555 else
00556 {
00557 UChar8 &dataXl =
00558 volData[z * zOff + y * yOff + x - 1];
00559
00560 UChar8 &dataXr =
00561 volData[z * zOff + y * yOff + x + 1];
00562
00563 UChar8 &dataYb =
00564 volData[z * zOff + (y - 1) * yOff + x ];
00565
00566 UChar8 &dataYt =
00567 volData[z * zOff + (y + 1) * yOff + x ];
00568
00569 UChar8 &dataZf =
00570 volData[(z - 1) * zOff + y * yOff + x ];
00571
00572 UChar8 &dataZn =
00573 volData[(z + 1) * zOff + y * yOff + x ];
00574
00575 gradient = Vec3f((float)(dataXl - dataXr),
00576 (float)(dataYb - dataYt),
00577 (float)(dataZf - dataZn));
00578
00579 if(gradient.length() != 0.0)
00580 gradient.normalize();
00581
00582 }
00583
00584 gradbuffer[4 * (z * zOff + y * yOff + x) ]
00585 = (UChar8) (127.0 + gradient[0] * 127.0);
00586
00587 gradbuffer[4 * (z * zOff + y * yOff + x) + 1]
00588 = (UChar8) (127.0 + gradient[1] * 127.0);
00589
00590 gradbuffer[4 * (z * zOff + y * yOff + x) + 2]
00591 = (UChar8) (127.0 + gradient[2] * 127.0);
00592
00593 gradbuffer[4 * (z * zOff + y * yOff + x) + 3]
00594 = volData[z * zOff + y * yOff + x ];
00595
00596 }
00597
00598 }
00599
00600 }
00601
00602 ImagePtr m_gradientImage = Image::create();
00603
00604 m_gradientImage->set(Image::OSG_RGBA_PF,
00605 resX,
00606 resY,
00607 resZ,
00608 1,
00609 1,
00610 0.0,
00611 gradbuffer);
00612
00613 delete [] gradbuffer;
00614
00615 return m_gradientImage;
00616 }
00617
00618
00619
00620 void DVRIsoShader::getLightSources(DirLightList &diffuseLights,
00621 DirLightList &specularLights,
00622 Color4f &ambientLight )
00623 {
00624 ambientLight .clear();
00625 diffuseLights .clear();
00626 specularLights.clear();
00627
00628 GLint maxNumLights;
00629
00630 glGetIntegerv(GL_MAX_LIGHTS, &maxNumLights);
00631
00632 GLfloat lightPos [4];
00633 GLfloat diffuseColor [4];
00634 GLfloat specularColor[4];
00635 GLfloat ambientColor [4];
00636
00637 for(int i = 0; i < maxNumLights; i++)
00638 {
00639 if(glIsEnabled(GLenum(GL_LIGHT0 + i)))
00640 {
00641 glGetLightfv(GLenum(GL_LIGHT0 + i), GL_POSITION, lightPos );
00642 glGetLightfv(GLenum(GL_LIGHT0 + i), GL_AMBIENT, ambientColor );
00643 glGetLightfv(GLenum(GL_LIGHT0 + i), GL_DIFFUSE, diffuseColor );
00644 glGetLightfv(GLenum(GL_LIGHT0 + i), GL_SPECULAR, specularColor);
00645
00646
00647
00648
00649
00650 if(1.0 == lightPos[3] + 1.0)
00651 {
00652 DirLight light;
00653
00654
00655 light.dir.setValues(lightPos[0],lightPos[1],lightPos[2]);
00656
00657
00658
00659
00660 if(diffuseColor[0] > 1e-6 ||
00661 diffuseColor[1] > 1e-6 ||
00662 diffuseColor[2] > 1e-6)
00663 {
00664 light.color = Color4f(diffuseColor[0],
00665 diffuseColor[1],
00666 diffuseColor[2],
00667 0.0f);
00668
00669 diffuseLights.push_back(light);
00670 }
00671
00672
00673 if(specularColor[0] > 1e-6 ||
00674 specularColor[1] > 1e-6 ||
00675 specularColor[2] > 1e-6)
00676 {
00677 light.color = Color4f(specularColor[0],
00678 specularColor[1],
00679 specularColor[2],
00680 0.0f);
00681
00682 specularLights.push_back(light);
00683 }
00684
00685
00686 for(unsigned int i = 0; i < 4; i++)
00687 {
00688 ambientLight[i] += ambientColor[i];
00689 }
00690 }
00691 }
00692 }
00693
00694
00695 glGetFloatv(GL_LIGHT_MODEL_AMBIENT,ambientColor);
00696
00697 for(unsigned int i = 0; i < 4; i++)
00698 {
00699 ambientLight[i] += ambientColor[i];
00700 }
00701 }
00702
00703
00704
00705 bool DVRIsoShader::checkGLVersion(GLfloat minVersion)
00706 {
00707 char *versionString = (char*) glGetString(GL_VERSION);
00708
00709 if(atof(versionString) >= minVersion)
00710 return true;
00711 else
00712 return false;
00713 }
00714
00715
00717 UInt8 DVRIsoShader::selectMode(DVRVolume *volume, DrawActionBase *action)
00718 {
00719 if(isModeSupported(volume, action, SM_FRAGMENT_PROGRAM_3D))
00720 {
00721 FINFO(("DVRIsoShader - Autoselect: Using 3D textures and "
00722 "fragment program...\n"));
00723
00724 return SM_FRAGMENT_PROGRAM_3D;
00725 }
00726
00727 if(isModeSupported(volume, action, SM_FRAGMENT_PROGRAM_2D))
00728 {
00729 FINFO(("DVRIsoShader - Autoselect: Using 2D textures and "
00730 "fragment program...\n"));
00731
00732 return SM_FRAGMENT_PROGRAM_2D;
00733 }
00734
00735 if(isModeSupported(volume, action, SM_REGISTER_COMBINERS_3D))
00736 {
00737 FINFO(("DVRIsoShader - Autoselect: Using 3D textures and "
00738 "register combiners...\n"));
00739
00740 return SM_REGISTER_COMBINERS_3D;
00741 }
00742
00743 if(isModeSupported(volume, action, SM_REGISTER_COMBINERS_MULTI2D))
00744 {
00745 FINFO(("DVRIsoShader - Autoselect: Using 2D multi textures and "
00746 "register combiners...\n"));
00747
00748 return SM_REGISTER_COMBINERS_MULTI2D;
00749 }
00750
00751 if(isModeSupported(volume, action, SM_REGISTER_COMBINERS_2D))
00752 {
00753 FINFO(("DVRIsoShader - Autoselect: Using 2D textures and "
00754 "register combiners...\n"));
00755
00756 return SM_REGISTER_COMBINERS_2D;
00757 }
00758
00759 if(isModeSupported(volume, action, SM_COLORMATRIX_3D))
00760 {
00761 FINFO(("DVRIsoShader - Autoselect: Using 3D textures and "
00762 "color matrix...\n"));
00763
00764 return SM_COLORMATRIX_3D;
00765 }
00766
00767 if(isModeSupported(volume, action, SM_COLORMATRIX_2D))
00768 {
00769 FINFO(("DVRIsoShader - Autoselect: Using 2D textures and "
00770 "color matrix...\n"));
00771
00772 return SM_COLORMATRIX_2D;
00773 }
00774
00775 SWARNING << "DVRIsoShader - None of the implemented shading algorithms"
00776 <<std::endl
00777 <<"is supported by this hardware!"
00778 <<std::endl;
00779
00780 return SM_NONE;
00781 }
00782
00784 bool DVRIsoShader::isModeSupported(DVRVolume *volume,
00785 DrawActionBase *action,
00786 UInt8 mode )
00787 {
00788 Window *win = action->getWindow();
00789
00790 if(!win)
00791 {
00792 SWARNING << "DVRIsoShader - No valid window" << std::endl;
00793 return false;
00794 }
00795
00796 GLint numStencil;
00797 bool forceTexture2D = false;
00798 bool forceTexture3D = false;
00799
00800 if(volume->getTextures2D() == 1)
00801 {
00802 forceTexture2D = true;
00803 SLOG << "DVRIsoShader - 2D textures forced" << std::endl;
00804 }
00805 else if(volume->getTextures2D() == 0)
00806 {
00807 forceTexture3D = true;
00808 SLOG << "DVRIsoShader - 3D textures forced" << std::endl;
00809 }
00810
00811 switch(mode)
00812 {
00813 case SM_COLORMATRIX_2D:
00814 glGetIntegerv(GL_STENCIL_BITS, &numStencil);
00815
00816 return
00817 numStencil > 0 &&
00818 (win->hasExtension(_SGI_color_matrix) ||
00819 checkGLVersion(1.2) ) &&
00820 !forceTexture3D;
00821
00822 case SM_COLORMATRIX_3D:
00823 glGetIntegerv(GL_STENCIL_BITS,&numStencil);
00824
00825 return
00826 numStencil > 0 &&
00827 win->hasExtension(_EXT_texture3D) &&
00828 (win->hasExtension(_SGI_color_matrix) ||
00829 checkGLVersion(1.2) ) &&
00830 !forceTexture2D;
00831
00832 case SM_REGISTER_COMBINERS_2D:
00833 return
00834 win->hasExtension(_NV_register_combiners) && !forceTexture3D;
00835
00836 case SM_REGISTER_COMBINERS_MULTI2D:
00837 return
00838 win->hasExtension(_ARB_multitexture ) &&
00839 win->hasExtension(_NV_register_combiners) &&
00840 !forceTexture3D;
00841
00842 case SM_REGISTER_COMBINERS_3D:
00843 return
00844 win->hasExtension(_EXT_texture3D ) &&
00845 win->hasExtension(_NV_register_combiners) &&
00846 !forceTexture2D;
00847
00848 case SM_FRAGMENT_PROGRAM_2D:
00849 return
00850 win->hasExtension(_ARB_multitexture ) &&
00851 win->hasExtension(_ARB_fragment_program) &&
00852 !forceTexture3D;
00853
00854 case SM_FRAGMENT_PROGRAM_3D:
00855 return
00856 win->hasExtension(_EXT_texture3D ) &&
00857 win->hasExtension(_ARB_fragment_program) &&
00858 !forceTexture2D;
00859
00860 case SM_NONE:
00861 return true;
00862
00863 default:
00864 break;
00865 }
00866
00867 return false;
00868 }
00869
00871 bool DVRIsoShader::tryMode(DVRVolume *volume,
00872 DrawActionBase *action,
00873 UInt8 mode )
00874 {
00875 if(mode != SM_AUTO)
00876 {
00877
00878 if(isModeSupported( volume, action, mode ))
00879 {
00880 SWARNING << "DVRIsoShader - User specified shading mode "
00881 << int(mode)
00882 << std::endl;
00883
00884 m_shadingMode = mode;
00885 }
00886 else
00887 {
00888 SWARNING << "DVRIsoShader - Unsupported shading mode requested "
00889 << int(mode)
00890 << " disabling shading"
00891 << std::endl;
00892
00893 m_shadingMode = SM_NONE;
00894 }
00895 }
00896 else
00897 {
00898
00899 m_shadingMode = selectMode(volume, action);
00900 }
00901
00902 setActiveShadeMode(m_shadingMode);
00903
00904 return m_shadingMode == mode;
00905 }
00906
00907
00908
00909
00910
00911 #ifdef __sgi
00912 #pragma set woff 1174
00913 #endif
00914
00915 #ifdef OSG_LINUX_ICC
00916 #pragma warning( disable : 177 )
00917 #endif
00918
00919 namespace
00920 {
00921 static char cvsid_cpp[] = "@(#)$Id: $";
00922 static char cvsid_hpp[] = OSGDVRISOSHADER_HEADER_CVSID;
00923 static char cvsid_inl[] = OSGDVRISOSHADER_INLINE_CVSID;
00924 }