00001
00002 #include <OSGConfig.h>
00003 #include <OSGDVRShader.h>
00004 #include <OSGDrawActionBase.h>
00005 #include <OSGDVRVolume.h>
00006 #include <OSGDVRVolumeTexture.h>
00007 #include <OSGDVRIsoSurface.h>
00008 #include <OSGSlicer.h>
00009 #include <OSGWindow.h>
00010 #include <OSGCamera.h>
00011 #include <OSGColor.h>
00012 #include <OSGGL.h>
00013 #include <OSGGLU.h>
00014 #include <OSGGLEXT.h>
00015 #include "OSGDVRIsoShader.h"
00016
00017 #include <math.h>
00018
00019 OSG_USING_NAMESPACE
00020
00021 typedef void (OSG_APIENTRY *CombinerParameteriNVFunc )( GLenum,
00022 const GLint );
00023 typedef void (OSG_APIENTRY *CombinerInputNVFunc )( GLenum,
00024 GLenum,
00025 GLenum,
00026 GLenum,
00027 GLenum,
00028 GLenum );
00029 typedef void (OSG_APIENTRY *CombinerOutputNVFunc )( GLenum,
00030 GLenum,
00031 GLenum,
00032 GLenum,
00033 GLenum,
00034 GLenum,
00035 GLenum,
00036 GLboolean,
00037 GLboolean,
00038 GLboolean);
00039 typedef void (OSG_APIENTRY *FinalCombinerInputNVFunc )( GLenum,
00040 GLenum,
00041 GLenum,
00042 GLenum);
00043
00044 typedef void (OSG_APIENTRY *CombinerParameterfvNVFunc )( GLenum,
00045 GLfloat *);
00046 typedef void (OSG_APIENTRY *SecondaryColor3fvEXTFunc )( GLfloat *);
00047 typedef void (OSG_APIENTRY *CombinerStageParameterfvNVFunc)( GLenum,
00048 GLenum,
00049 GLfloat *);
00050
00051 typedef void (OSG_APIENTRY *ActiveTextureARBFunc )( GLenum );
00052 typedef void (OSG_APIENTRY *MultiTexCoord2dARBFunc )( GLenum,
00053 GLdouble,
00054 GLdouble );
00055
00056
00057
00058 void DVRIsoShader::initCombiners_IsoSurfaceDiffuse(DrawActionBase *action)
00059 {
00060 Window *win = action->getWindow();
00061
00062
00063 CombinerParameteriNVFunc CombinerParameteriNV =
00064 (CombinerParameteriNVFunc) win->getFunction(_funcCombinerParameteriNV);
00065
00066 CombinerInputNVFunc CombinerInputNV =
00067 (CombinerInputNVFunc) win->getFunction (_funcCombinerInputNV );
00068
00069 CombinerOutputNVFunc CombinerOutputNV =
00070 (CombinerOutputNVFunc) win->getFunction (_funcCombinerOutputNV );
00071
00072 if((m_maxCombiners > 7) && m_hasPerStageConstants)
00073 {
00074
00075 CombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV,
00076 5 + 3 * ((m_maxCombiners-5) / 3));
00077 }
00078 else
00079 {
00080 CombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 2);
00081 }
00082
00083
00084
00085
00086
00087
00088
00089 CombinerInputNV(GL_COMBINER0_NV,
00090 GL_RGB,
00091 GL_VARIABLE_A_NV,
00092 GL_TEXTURE0_ARB,
00093 GL_EXPAND_NORMAL_NV,
00094 GL_RGB);
00095
00096
00097 CombinerInputNV(GL_COMBINER0_NV,
00098 GL_RGB,
00099 GL_VARIABLE_B_NV,
00100 GL_CONSTANT_COLOR0_NV,
00101 GL_UNSIGNED_INVERT_NV,
00102 GL_ALPHA);
00103
00104
00105 CombinerInputNV(GL_COMBINER0_NV,
00106 GL_RGB,
00107 GL_VARIABLE_C_NV,
00108 GL_TEXTURE1_ARB,
00109 GL_EXPAND_NORMAL_NV,
00110 GL_RGB);
00111
00112
00113 CombinerInputNV(GL_COMBINER0_NV,
00114 GL_RGB,
00115 GL_VARIABLE_D_NV,
00116 GL_CONSTANT_COLOR0_NV,
00117 GL_UNSIGNED_IDENTITY_NV,
00118 GL_ALPHA);
00119
00120
00121
00122
00123
00124 CombinerInputNV(GL_COMBINER0_NV,
00125 GL_ALPHA,
00126 GL_VARIABLE_A_NV,
00127 GL_TEXTURE0_ARB,
00128 GL_UNSIGNED_IDENTITY_NV,
00129 GL_ALPHA);
00130
00131
00132 CombinerInputNV(GL_COMBINER0_NV,
00133 GL_ALPHA,
00134 GL_VARIABLE_B_NV,
00135 GL_CONSTANT_COLOR0_NV,
00136 GL_UNSIGNED_INVERT_NV,
00137 GL_ALPHA);
00138
00139
00140 CombinerInputNV(GL_COMBINER0_NV,
00141 GL_ALPHA,
00142 GL_VARIABLE_C_NV,
00143 GL_TEXTURE1_ARB,
00144 GL_UNSIGNED_IDENTITY_NV,
00145 GL_ALPHA);
00146
00147
00148 CombinerInputNV(GL_COMBINER0_NV,
00149 GL_ALPHA,
00150 GL_VARIABLE_D_NV,
00151 GL_CONSTANT_COLOR0_NV,
00152 GL_UNSIGNED_IDENTITY_NV,
00153 GL_ALPHA);
00154
00155
00156
00157
00158 CombinerOutputNV(GL_COMBINER0_NV,
00159 GL_RGB,
00160 GL_DISCARD_NV,
00161 GL_DISCARD_NV,
00162 GL_SPARE0_NV,
00163 GL_NONE,
00164 GL_NONE,
00165 GL_FALSE,
00166 GL_FALSE,
00167 GL_FALSE);
00168
00169
00170 CombinerOutputNV(GL_COMBINER0_NV,
00171 GL_ALPHA,
00172 GL_DISCARD_NV,
00173 GL_DISCARD_NV,
00174 GL_SPARE0_NV,
00175 GL_NONE,
00176 GL_NONE,
00177 GL_FALSE,
00178 GL_FALSE,
00179 GL_FALSE);
00180
00181
00182
00183
00184
00185
00186
00187
00188 CombinerInputNV(GL_COMBINER1_NV,
00189 GL_RGB,
00190 GL_VARIABLE_A_NV,
00191 GL_SPARE0_NV,
00192 GL_SIGNED_IDENTITY_NV,
00193 GL_RGB);
00194
00195
00196 CombinerInputNV(GL_COMBINER1_NV,
00197 GL_RGB,
00198 GL_VARIABLE_B_NV,
00199 GL_CONSTANT_COLOR0_NV,
00200 GL_EXPAND_NORMAL_NV,
00201 GL_RGB);
00202
00203
00204 CombinerInputNV(GL_COMBINER1_NV,
00205 GL_RGB,
00206 GL_VARIABLE_C_NV,
00207 GL_SPARE0_NV,
00208 GL_SIGNED_IDENTITY_NV,
00209 GL_RGB);
00210
00211
00212 CombinerInputNV(GL_COMBINER1_NV,
00213 GL_RGB,
00214 GL_VARIABLE_D_NV,
00215 GL_CONSTANT_COLOR1_NV,
00216 GL_EXPAND_NORMAL_NV,
00217 GL_RGB);
00218
00219
00220
00221
00222 CombinerOutputNV(GL_COMBINER1_NV,
00223 GL_RGB,
00224 GL_TEXTURE0_ARB,
00225 GL_TEXTURE1_ARB,
00226 GL_DISCARD_NV,
00227 GL_NONE,
00228 GL_NONE,
00229 GL_TRUE,
00230 GL_TRUE,
00231 GL_FALSE);
00232
00233 CombinerOutputNV(GL_COMBINER1_NV,
00234 GL_ALPHA,
00235 GL_DISCARD_NV,
00236 GL_DISCARD_NV,
00237 GL_DISCARD_NV,
00238 GL_NONE,
00239 GL_NONE,
00240 GL_FALSE,
00241 GL_FALSE,
00242 GL_FALSE);
00243
00244
00245 if((m_maxCombiners > 7) && m_hasPerStageConstants)
00246 {
00247 initCombiners_DiffuseMultiCombiners(action);
00248 }
00249 else
00250 {
00251 initCombiners_Diffuse2Combiners(action);
00252 }
00253 }
00254
00255 void DVRIsoShader::initCombiners_Diffuse2Combiners(DrawActionBase *action)
00256 {
00257 Window *win = action->getWindow();
00258
00259 FinalCombinerInputNVFunc FinalCombinerInputNV =
00260 (FinalCombinerInputNVFunc) win->getFunction(_funcFinalCombinerInputNV);
00261
00262
00263
00264
00265 FinalCombinerInputNV(GL_VARIABLE_A_NV,
00266 GL_TEXTURE0_ARB,
00267 GL_UNSIGNED_IDENTITY_NV,
00268 GL_RGB);
00269
00270 FinalCombinerInputNV(GL_VARIABLE_B_NV,
00271 GL_PRIMARY_COLOR_NV,
00272 GL_UNSIGNED_IDENTITY_NV,
00273 GL_RGB);
00274
00275 FinalCombinerInputNV(GL_VARIABLE_C_NV,
00276 GL_ZERO,
00277 GL_UNSIGNED_IDENTITY_NV,
00278 GL_RGB);
00279
00280 FinalCombinerInputNV(GL_VARIABLE_E_NV,
00281 GL_TEXTURE1_ARB,
00282 GL_UNSIGNED_IDENTITY_NV,
00283 GL_RGB);
00284
00285 FinalCombinerInputNV(GL_VARIABLE_F_NV,
00286 GL_SECONDARY_COLOR_NV,
00287 GL_UNSIGNED_IDENTITY_NV,
00288 GL_RGB);
00289
00290 FinalCombinerInputNV(GL_VARIABLE_D_NV,
00291 GL_E_TIMES_F_NV,
00292 GL_UNSIGNED_IDENTITY_NV,
00293 GL_RGB);
00294
00295
00296
00297 FinalCombinerInputNV(GL_VARIABLE_G_NV,
00298 GL_SPARE0_NV,
00299 GL_UNSIGNED_IDENTITY_NV,
00300 GL_ALPHA);
00301 }
00302
00303 void DVRIsoShader::initCombiners_DiffuseMultiCombiners(DrawActionBase *action)
00304 {
00305
00306 Window *win = action->getWindow();
00307
00308 CombinerInputNVFunc CombinerInputNV =
00309 (CombinerInputNVFunc) win->getFunction (_funcCombinerInputNV );
00310
00311 CombinerOutputNVFunc CombinerOutputNV =
00312 (CombinerOutputNVFunc) win->getFunction (_funcCombinerOutputNV );
00313
00314 FinalCombinerInputNVFunc FinalCombinerInputNV =
00315 (FinalCombinerInputNVFunc) win->getFunction(_funcFinalCombinerInputNV);
00316
00317
00318
00319
00320
00321
00322 CombinerInputNV(GL_COMBINER2_NV,
00323 GL_RGB,
00324 GL_VARIABLE_A_NV,
00325 GL_TEXTURE0_ARB,
00326 GL_UNSIGNED_IDENTITY_NV,
00327 GL_RGB);
00328
00329 CombinerInputNV(GL_COMBINER2_NV,
00330 GL_RGB,
00331 GL_VARIABLE_B_NV,
00332 GL_CONSTANT_COLOR0_NV,
00333 GL_UNSIGNED_IDENTITY_NV,
00334 GL_RGB);
00335
00336 CombinerInputNV(GL_COMBINER2_NV,
00337 GL_RGB,
00338 GL_VARIABLE_C_NV,
00339 GL_TEXTURE1_ARB,
00340 GL_UNSIGNED_IDENTITY_NV,
00341 GL_RGB);
00342
00343 CombinerInputNV(GL_COMBINER2_NV,
00344 GL_RGB,
00345 GL_VARIABLE_D_NV,
00346 GL_CONSTANT_COLOR1_NV,
00347 GL_UNSIGNED_IDENTITY_NV,
00348 GL_RGB);
00349
00350 CombinerOutputNV(GL_COMBINER2_NV,
00351 GL_RGB,
00352 GL_DISCARD_NV,
00353 GL_DISCARD_NV,
00354 GL_SPARE1_NV,
00355 GL_NONE,
00356 GL_NONE,
00357 GL_FALSE,
00358 GL_FALSE,
00359 GL_FALSE);
00360
00361 CombinerOutputNV(GL_COMBINER2_NV,
00362 GL_ALPHA,
00363 GL_DISCARD_NV,
00364 GL_DISCARD_NV,
00365 GL_DISCARD_NV,
00366 GL_NONE,
00367 GL_NONE,
00368 GL_FALSE,
00369 GL_FALSE,
00370 GL_FALSE);
00371
00372 Int32 i;
00373
00374 for(i = 0; i < (m_maxCombiners - 5) / 3; i++)
00375 {
00376
00377
00378 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3),
00379 GL_RGB,
00380 GL_VARIABLE_A_NV,
00381 GL_SPARE0_NV,
00382 GL_SIGNED_IDENTITY_NV,
00383 GL_RGB);
00384
00385 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3),
00386 GL_RGB,
00387 GL_VARIABLE_B_NV,
00388 GL_CONSTANT_COLOR0_NV,
00389 GL_EXPAND_NORMAL_NV,
00390 GL_RGB);
00391
00392 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3),
00393 GL_RGB,
00394 GL_VARIABLE_C_NV,
00395 GL_SPARE0_NV,
00396 GL_SIGNED_IDENTITY_NV,
00397 GL_RGB);
00398
00399 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3),
00400 GL_RGB,
00401 GL_VARIABLE_D_NV,
00402 GL_CONSTANT_COLOR1_NV,
00403 GL_EXPAND_NORMAL_NV,
00404 GL_RGB);
00405
00406 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i * 3),
00407 GL_RGB,
00408 GL_TEXTURE0_ARB,
00409 GL_TEXTURE1_ARB,
00410 GL_DISCARD_NV,
00411 GL_NONE,
00412 GL_NONE,
00413 GL_TRUE,
00414 GL_TRUE,
00415 GL_FALSE);
00416
00417 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i * 3),
00418 GL_ALPHA,
00419 GL_DISCARD_NV,
00420 GL_DISCARD_NV,
00421 GL_DISCARD_NV,
00422 GL_NONE,
00423 GL_NONE,
00424 GL_FALSE,
00425 GL_FALSE,
00426 GL_FALSE);
00427
00428
00429
00430 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 +1),
00431 GL_RGB,
00432 GL_VARIABLE_A_NV,
00433 GL_TEXTURE0_ARB,
00434 GL_UNSIGNED_IDENTITY_NV,
00435 GL_RGB);
00436
00437 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00438 GL_RGB,
00439 GL_VARIABLE_B_NV,
00440 GL_CONSTANT_COLOR0_NV,
00441 GL_UNSIGNED_IDENTITY_NV,
00442 GL_RGB);
00443
00444 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00445 GL_RGB,
00446 GL_VARIABLE_C_NV,
00447 GL_TEXTURE1_ARB,
00448 GL_UNSIGNED_IDENTITY_NV,
00449 GL_RGB);
00450
00451 CombinerInputNV(
00452 GLenum(GL_COMBINER3_NV+i*3+1),
00453 GL_RGB,
00454 GL_VARIABLE_D_NV,
00455 GL_CONSTANT_COLOR1_NV,
00456 GL_UNSIGNED_IDENTITY_NV,
00457 GL_RGB);
00458
00459 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00460 GL_RGB,
00461 GL_DISCARD_NV,
00462 GL_DISCARD_NV,
00463 GL_TEXTURE0_ARB,
00464 GL_NONE,
00465 GL_NONE,
00466 GL_FALSE,
00467 GL_FALSE,
00468 GL_FALSE);
00469
00470 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00471 GL_ALPHA,
00472 GL_DISCARD_NV,
00473 GL_DISCARD_NV,
00474 GL_DISCARD_NV,
00475 GL_NONE,
00476 GL_NONE,
00477 GL_FALSE,
00478 GL_FALSE,
00479 GL_FALSE);
00480
00481
00482
00483 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 2),
00484 GL_RGB,
00485 GL_VARIABLE_A_NV,
00486 GL_SPARE1_NV,
00487 GL_UNSIGNED_IDENTITY_NV,
00488 GL_RGB);
00489
00490 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 2),
00491 GL_RGB,
00492 GL_VARIABLE_B_NV,
00493 GL_ZERO,
00494 GL_UNSIGNED_INVERT_NV,
00495 GL_RGB);
00496
00497 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 2),
00498 GL_RGB,
00499 GL_VARIABLE_C_NV,
00500 GL_TEXTURE0_ARB,
00501 GL_UNSIGNED_IDENTITY_NV,
00502 GL_RGB);
00503
00504 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 2),
00505 GL_RGB,
00506 GL_VARIABLE_D_NV,
00507 GL_ZERO,
00508 GL_UNSIGNED_INVERT_NV,
00509 GL_RGB);
00510
00511 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i * 3 + 2),
00512 GL_RGB,
00513 GL_DISCARD_NV,
00514 GL_DISCARD_NV,
00515 GL_SPARE1_NV,
00516 GL_NONE,
00517 GL_NONE,
00518 GL_FALSE,
00519 GL_FALSE,
00520 GL_FALSE);
00521
00522 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i *3 + 2),
00523 GL_ALPHA,
00524 GL_DISCARD_NV,
00525 GL_DISCARD_NV,
00526 GL_DISCARD_NV,
00527 GL_NONE,
00528 GL_NONE,
00529 GL_FALSE,
00530 GL_FALSE,
00531 GL_FALSE);
00532
00533 }
00534
00535
00536
00537
00538
00539
00540 CombinerInputNV(GLenum(GL_COMBINER3_NV+i*3),
00541 GL_RGB,
00542 GL_VARIABLE_A_NV,
00543 GL_SPARE0_NV,
00544 GL_SIGNED_IDENTITY_NV,
00545 GL_RGB);
00546
00547 CombinerInputNV(GLenum(GL_COMBINER3_NV+i*3),
00548 GL_RGB,
00549 GL_VARIABLE_B_NV,
00550 GL_CONSTANT_COLOR0_NV,
00551 GL_EXPAND_NORMAL_NV,
00552 GL_RGB);
00553
00554 CombinerInputNV(GLenum(GL_COMBINER3_NV+i*3),
00555 GL_RGB,
00556 GL_VARIABLE_C_NV,
00557 GL_SPARE0_NV,
00558 GL_SIGNED_IDENTITY_NV,
00559 GL_RGB);
00560
00561 CombinerInputNV(GLenum(GL_COMBINER3_NV+i*3),
00562 GL_RGB,
00563 GL_VARIABLE_D_NV,
00564 GL_CONSTANT_COLOR1_NV,
00565 GL_EXPAND_NORMAL_NV,
00566 GL_RGB);
00567
00568 CombinerOutputNV(GLenum(GL_COMBINER3_NV+i*3),
00569 GL_RGB,
00570 GL_TEXTURE0_ARB,
00571 GL_TEXTURE1_ARB,
00572 GL_DISCARD_NV,
00573 GL_NONE,
00574 GL_NONE,
00575 GL_TRUE,
00576 GL_TRUE,
00577 GL_FALSE);
00578
00579 CombinerOutputNV(GLenum(GL_COMBINER3_NV+i*3),
00580 GL_ALPHA,
00581 GL_DISCARD_NV,
00582 GL_DISCARD_NV,
00583 GL_DISCARD_NV,
00584 GL_NONE,
00585 GL_NONE,
00586 GL_FALSE,
00587 GL_FALSE,
00588 GL_FALSE);
00589
00590
00591
00592 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00593 GL_RGB,
00594 GL_VARIABLE_A_NV,
00595 GL_TEXTURE0_ARB,
00596 GL_UNSIGNED_IDENTITY_NV,
00597 GL_RGB);
00598
00599 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00600 GL_RGB,
00601 GL_VARIABLE_B_NV,
00602 GL_CONSTANT_COLOR0_NV,
00603 GL_UNSIGNED_IDENTITY_NV,
00604 GL_RGB);
00605
00606 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00607 GL_RGB,
00608 GL_VARIABLE_C_NV,
00609 GL_TEXTURE1_ARB,
00610 GL_UNSIGNED_IDENTITY_NV,
00611 GL_RGB);
00612
00613 CombinerInputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00614 GL_RGB,
00615 GL_VARIABLE_D_NV,
00616 GL_CONSTANT_COLOR1_NV,
00617 GL_UNSIGNED_IDENTITY_NV,
00618 GL_RGB);
00619
00620 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00621 GL_RGB,
00622 GL_DISCARD_NV,
00623 GL_DISCARD_NV,
00624 GL_SPARE0_NV,
00625 GL_NONE,
00626 GL_NONE,
00627 GL_FALSE,
00628 GL_FALSE,
00629 GL_FALSE);
00630
00631 CombinerOutputNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
00632 GL_ALPHA,
00633 GL_DISCARD_NV,
00634 GL_DISCARD_NV,
00635 GL_DISCARD_NV,
00636 GL_NONE,
00637 GL_NONE,
00638 GL_FALSE,
00639 GL_FALSE,
00640 GL_FALSE);
00641
00642
00643
00644
00645 FinalCombinerInputNV(GL_VARIABLE_A_NV,
00646 GL_ZERO,
00647 GL_UNSIGNED_INVERT_NV,
00648 GL_RGB);
00649
00650 FinalCombinerInputNV(GL_VARIABLE_B_NV,
00651 GL_SPARE1_NV,
00652 GL_UNSIGNED_IDENTITY_NV,
00653 GL_RGB);
00654
00655 FinalCombinerInputNV(GL_VARIABLE_C_NV,
00656 GL_ZERO,
00657 GL_UNSIGNED_IDENTITY_NV,
00658 GL_RGB);
00659
00660 FinalCombinerInputNV(GL_VARIABLE_D_NV,
00661 GL_SPARE0_PLUS_SECONDARY_COLOR_NV,
00662 GL_UNSIGNED_IDENTITY_NV,
00663 GL_RGB);
00664
00665
00666
00667 FinalCombinerInputNV(GL_VARIABLE_G_NV,
00668 GL_SPARE0_NV,
00669 GL_UNSIGNED_IDENTITY_NV,
00670 GL_ALPHA);
00671 }
00672
00673
00674
00675 void DVRIsoShader::initCombiners_IsoSurfaceSpecular(DrawActionBase *action)
00676 {
00677 Window *win = action->getWindow();
00678
00679 CombinerParameteriNVFunc CombinerParameteriNV =
00680 (CombinerParameteriNVFunc) win->getFunction(_funcCombinerParameteriNV);
00681
00682 CombinerInputNVFunc CombinerInputNV =
00683 (CombinerInputNVFunc) win->getFunction (_funcCombinerInputNV );
00684
00685 CombinerOutputNVFunc CombinerOutputNV =
00686 (CombinerOutputNVFunc) win->getFunction (_funcCombinerOutputNV );
00687
00688 if(m_hasPerStageConstants && m_maxCombiners >= 8)
00689 {
00690 CombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 8);
00691 }
00692 else
00693 {
00694 CombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 2);
00695 }
00696
00697
00698
00699
00700
00701
00702
00703
00704 CombinerInputNV(GL_COMBINER0_NV,
00705 GL_RGB,
00706 GL_VARIABLE_A_NV,
00707 GL_CONSTANT_COLOR0_NV,
00708 GL_UNSIGNED_INVERT_NV,
00709 GL_ALPHA);
00710
00711
00712 CombinerInputNV(GL_COMBINER0_NV,
00713 GL_RGB,
00714 GL_VARIABLE_B_NV,
00715 GL_TEXTURE0_ARB,
00716 GL_EXPAND_NORMAL_NV,
00717 GL_RGB);
00718
00719
00720 CombinerInputNV(GL_COMBINER0_NV,
00721 GL_RGB,
00722 GL_VARIABLE_C_NV,
00723 GL_CONSTANT_COLOR0_NV,
00724 GL_UNSIGNED_IDENTITY_NV,
00725 GL_ALPHA);
00726
00727
00728 CombinerInputNV(GL_COMBINER0_NV,
00729 GL_RGB,
00730 GL_VARIABLE_D_NV,
00731 GL_TEXTURE1_ARB,
00732 GL_EXPAND_NORMAL_NV,
00733 GL_RGB);
00734
00735
00736
00737
00738
00739
00740 CombinerInputNV(GL_COMBINER0_NV,
00741 GL_ALPHA,
00742 GL_VARIABLE_A_NV,
00743 GL_CONSTANT_COLOR0_NV,
00744 GL_UNSIGNED_INVERT_NV,
00745 GL_ALPHA);
00746
00747
00748 CombinerInputNV(GL_COMBINER0_NV,
00749 GL_ALPHA,
00750 GL_VARIABLE_B_NV,
00751 GL_TEXTURE0_ARB,
00752 GL_UNSIGNED_IDENTITY_NV,
00753 GL_ALPHA);
00754
00755
00756 CombinerInputNV(GL_COMBINER0_NV,
00757 GL_ALPHA,
00758 GL_VARIABLE_C_NV,
00759 GL_CONSTANT_COLOR0_NV,
00760 GL_UNSIGNED_IDENTITY_NV,
00761 GL_ALPHA);
00762
00763
00764 CombinerInputNV(GL_COMBINER0_NV,
00765 GL_ALPHA,
00766 GL_VARIABLE_D_NV,
00767 GL_TEXTURE1_ARB,
00768 GL_UNSIGNED_IDENTITY_NV,
00769 GL_ALPHA);
00770
00771
00772
00773
00774
00775
00776 CombinerOutputNV(GL_COMBINER0_NV,
00777 GL_RGB,
00778 GL_DISCARD_NV,
00779 GL_DISCARD_NV,
00780 GL_TEXTURE0_ARB,
00781 GL_NONE,
00782 GL_NONE,
00783 GL_FALSE,
00784 GL_FALSE,
00785 GL_FALSE);
00786
00787
00788
00789
00790
00791 CombinerOutputNV(GL_COMBINER0_NV,
00792 GL_ALPHA,
00793 GL_DISCARD_NV,
00794 GL_DISCARD_NV,
00795 GL_TEXTURE0_ARB,
00796 GL_NONE,
00797 GL_NONE,
00798 GL_FALSE,
00799 GL_FALSE,
00800 GL_FALSE);
00801
00802
00803
00804
00805
00806
00807
00808
00809 CombinerInputNV(GL_COMBINER1_NV,
00810 GL_RGB,
00811 GL_VARIABLE_A_NV,
00812 GL_TEXTURE0_ARB,
00813 GL_SIGNED_IDENTITY_NV,
00814 GL_RGB);
00815
00816
00817 CombinerInputNV(GL_COMBINER1_NV,
00818 GL_RGB,
00819 GL_VARIABLE_B_NV,
00820 GL_PRIMARY_COLOR_NV,
00821 GL_EXPAND_NORMAL_NV,
00822 GL_RGB);
00823
00824
00825 CombinerInputNV(GL_COMBINER1_NV,
00826 GL_RGB,
00827 GL_VARIABLE_C_NV,
00828 GL_TEXTURE0_ARB,
00829 GL_SIGNED_IDENTITY_NV,
00830 GL_RGB);
00831
00832
00833 CombinerInputNV(GL_COMBINER1_NV,
00834 GL_RGB,
00835 GL_VARIABLE_D_NV,
00836 GL_CONSTANT_COLOR1_NV,
00837 GL_EXPAND_NORMAL_NV,
00838 GL_RGB);
00839
00840
00841
00842
00843
00844
00845 CombinerOutputNV(GL_COMBINER1_NV,
00846 GL_RGB,
00847 GL_SPARE0_NV,
00848 GL_SPARE1_NV,
00849 GL_DISCARD_NV,
00850 GL_NONE,
00851 GL_NONE,
00852 GL_TRUE,
00853 GL_TRUE,
00854 GL_FALSE);
00855
00856
00857 CombinerOutputNV(GL_COMBINER1_NV,
00858 GL_ALPHA,
00859 GL_DISCARD_NV,
00860 GL_DISCARD_NV,
00861 GL_DISCARD_NV,
00862 GL_NONE,
00863 GL_NONE,
00864 GL_FALSE,
00865 GL_FALSE,
00866 GL_FALSE);
00867
00868
00869 if((m_maxCombiners > 2) && m_hasPerStageConstants)
00870 {
00871 initCombiners_SpecularMultiCombiners(action);
00872 }
00873 else
00874 {
00875 initCombiners_Specular2Combiners(action);
00876 }
00877 }
00878
00879 void DVRIsoShader::initCombiners_Specular2Combiners(DrawActionBase *action)
00880 {
00881 Window *win = action->getWindow();
00882
00883 FinalCombinerInputNVFunc FinalCombinerInputNV =
00884 (FinalCombinerInputNVFunc) win->getFunction(_funcFinalCombinerInputNV);
00885
00886
00887
00888
00889 FinalCombinerInputNV(GL_VARIABLE_E_NV,
00890 GL_SPARE1_NV,
00891 GL_UNSIGNED_IDENTITY_NV,
00892 GL_RGB);
00893
00894
00895 FinalCombinerInputNV(GL_VARIABLE_F_NV,
00896 GL_SPARE1_NV,
00897 GL_UNSIGNED_IDENTITY_NV,
00898 GL_RGB);
00899
00900
00901 FinalCombinerInputNV(GL_VARIABLE_A_NV,
00902 GL_E_TIMES_F_NV,
00903 GL_UNSIGNED_IDENTITY_NV,
00904 GL_RGB);
00905
00906
00907 FinalCombinerInputNV(GL_VARIABLE_B_NV,
00908 GL_E_TIMES_F_NV,
00909 GL_UNSIGNED_IDENTITY_NV,
00910 GL_RGB);
00911
00912
00913 FinalCombinerInputNV(GL_VARIABLE_C_NV,
00914 GL_ZERO,
00915 GL_UNSIGNED_IDENTITY_NV,
00916 GL_RGB);
00917
00918
00919 FinalCombinerInputNV(GL_VARIABLE_D_NV,
00920 GL_SPARE0_PLUS_SECONDARY_COLOR_NV,
00921 GL_UNSIGNED_IDENTITY_NV,
00922 GL_RGB);
00923
00924
00925 FinalCombinerInputNV(GL_VARIABLE_G_NV,
00926 GL_TEXTURE0_ARB,
00927 GL_UNSIGNED_IDENTITY_NV,
00928 GL_ALPHA);
00929
00930 }
00931
00932 void DVRIsoShader::initCombiners_SpecularMultiCombiners(DrawActionBase *action)
00933 {
00934 Window *win = action->getWindow();
00935
00936 CombinerInputNVFunc CombinerInputNV =
00937 (CombinerInputNVFunc) win->getFunction (_funcCombinerInputNV );
00938
00939 CombinerOutputNVFunc CombinerOutputNV =
00940 (CombinerOutputNVFunc) win->getFunction (_funcCombinerOutputNV );
00941
00942 FinalCombinerInputNVFunc FinalCombinerInputNV =
00943 (FinalCombinerInputNVFunc) win->getFunction(_funcFinalCombinerInputNV);
00944
00945
00946
00947
00948
00949
00950
00951
00952 CombinerInputNV(GL_COMBINER2_NV,
00953 GL_RGB,
00954 GL_VARIABLE_A_NV,
00955 GL_TEXTURE0_ARB,
00956 GL_SIGNED_IDENTITY_NV,
00957 GL_RGB);
00958
00959
00960 CombinerInputNV(GL_COMBINER2_NV,
00961 GL_RGB,
00962 GL_VARIABLE_B_NV,
00963 GL_CONSTANT_COLOR0_NV,
00964 GL_EXPAND_NORMAL_NV,
00965 GL_RGB);
00966
00967
00968 CombinerInputNV(GL_COMBINER2_NV,
00969 GL_RGB,
00970 GL_VARIABLE_C_NV,
00971 GL_TEXTURE0_ARB,
00972 GL_SIGNED_IDENTITY_NV,
00973 GL_RGB);
00974
00975
00976 CombinerInputNV(GL_COMBINER2_NV,
00977 GL_RGB,
00978 GL_VARIABLE_D_NV,
00979 GL_CONSTANT_COLOR1_NV,
00980 GL_EXPAND_NORMAL_NV,
00981 GL_RGB);
00982
00983
00984
00985
00986 CombinerInputNV(GL_COMBINER2_NV,
00987 GL_ALPHA,
00988 GL_VARIABLE_A_NV,
00989 GL_SPARE1_NV,
00990 GL_UNSIGNED_IDENTITY_NV,
00991 GL_BLUE);
00992
00993
00994 CombinerInputNV(GL_COMBINER2_NV,
00995 GL_ALPHA,
00996 GL_VARIABLE_B_NV,
00997 GL_SPARE1_NV,
00998 GL_UNSIGNED_IDENTITY_NV,
00999 GL_BLUE);
01000
01001
01002
01003
01004 CombinerOutputNV(GL_COMBINER2_NV,
01005 GL_RGB,
01006 GL_TEXTURE1_ARB,
01007 GL_SPARE1_NV,
01008 GL_DISCARD_NV,
01009 GL_NONE,
01010 GL_NONE,
01011 GL_TRUE,
01012 GL_TRUE,
01013 GL_FALSE);
01014
01015
01016 CombinerOutputNV(GL_COMBINER2_NV,
01017 GL_ALPHA,
01018 GL_SPARE0_NV,
01019 GL_DISCARD_NV,
01020 GL_DISCARD_NV,
01021 GL_NONE,
01022 GL_NONE,
01023 GL_FALSE,
01024 GL_FALSE,
01025 GL_FALSE);
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035 CombinerInputNV(GL_COMBINER3_NV,
01036 GL_RGB,
01037 GL_VARIABLE_A_NV,
01038 GL_TEXTURE0_ARB,
01039 GL_SIGNED_IDENTITY_NV,
01040 GL_RGB);
01041
01042
01043 CombinerInputNV(GL_COMBINER3_NV,
01044 GL_RGB,
01045 GL_VARIABLE_B_NV,
01046 GL_CONSTANT_COLOR0_NV,
01047 GL_EXPAND_NORMAL_NV,
01048 GL_RGB);
01049
01050
01051 CombinerInputNV(GL_COMBINER3_NV,
01052 GL_RGB,
01053 GL_VARIABLE_C_NV,
01054 GL_TEXTURE0_ARB,
01055 GL_SIGNED_IDENTITY_NV,
01056 GL_RGB);
01057
01058
01059 CombinerInputNV(GL_COMBINER3_NV,
01060 GL_RGB,
01061 GL_VARIABLE_D_NV,
01062 GL_CONSTANT_COLOR1_NV,
01063 GL_EXPAND_NORMAL_NV,
01064 GL_RGB);
01065
01066
01067
01068
01069 CombinerInputNV(GL_COMBINER3_NV,
01070 GL_ALPHA,
01071 GL_VARIABLE_A_NV,
01072 GL_TEXTURE1_ARB,
01073 GL_UNSIGNED_IDENTITY_NV,
01074 GL_BLUE);
01075
01076
01077 CombinerInputNV(GL_COMBINER3_NV,
01078 GL_ALPHA,
01079 GL_VARIABLE_B_NV,
01080 GL_TEXTURE1_ARB,
01081 GL_UNSIGNED_IDENTITY_NV,
01082 GL_BLUE);
01083
01084
01085 CombinerInputNV(GL_COMBINER3_NV,
01086 GL_ALPHA,
01087 GL_VARIABLE_B_NV,
01088 GL_SPARE1_NV,
01089 GL_UNSIGNED_IDENTITY_NV,
01090 GL_BLUE);
01091
01092
01093 CombinerInputNV(GL_COMBINER3_NV,
01094 GL_ALPHA,
01095 GL_VARIABLE_D_NV,
01096 GL_SPARE1_NV,
01097 GL_UNSIGNED_IDENTITY_NV,
01098 GL_BLUE);
01099
01100
01101
01102
01103 CombinerOutputNV(GL_COMBINER3_NV,
01104 GL_RGB,
01105 GL_TEXTURE1_ARB,
01106 GL_SPARE1_NV,
01107 GL_DISCARD_NV,
01108 GL_NONE,
01109 GL_NONE,
01110 GL_TRUE,
01111 GL_TRUE,
01112 GL_FALSE);
01113
01114
01115 CombinerOutputNV(GL_COMBINER3_NV,
01116 GL_ALPHA,
01117 GL_TEXTURE1_ARB,
01118 GL_SPARE1_NV,
01119 GL_DISCARD_NV,
01120 GL_NONE,
01121 GL_NONE,
01122 GL_FALSE,
01123 GL_FALSE,
01124 GL_FALSE);
01125
01126
01127
01128
01129
01130
01131
01132
01133 CombinerInputNV(GL_COMBINER4_NV,
01134 GL_RGB,
01135 GL_VARIABLE_A_NV,
01136 GL_TEXTURE1_ARB,
01137 GL_UNSIGNED_IDENTITY_NV,
01138 GL_RGB);
01139
01140
01141 CombinerInputNV(GL_COMBINER4_NV,
01142 GL_RGB,
01143 GL_VARIABLE_B_NV,
01144 GL_CONSTANT_COLOR0_NV,
01145 GL_UNSIGNED_IDENTITY_NV,
01146 GL_RGB);
01147
01148
01149 CombinerInputNV(GL_COMBINER4_NV,
01150 GL_RGB,
01151 GL_VARIABLE_C_NV,
01152 GL_SPARE1_NV,
01153 GL_UNSIGNED_IDENTITY_NV,
01154 GL_RGB);
01155
01156
01157 CombinerInputNV(GL_COMBINER4_NV,
01158 GL_RGB,
01159 GL_VARIABLE_D_NV,
01160 GL_CONSTANT_COLOR1_NV,
01161 GL_UNSIGNED_IDENTITY_NV,
01162 GL_RGB);
01163
01164
01165
01166
01167 CombinerInputNV(GL_COMBINER4_NV,
01168 GL_ALPHA,
01169 GL_VARIABLE_A_NV,
01170 GL_TEXTURE1_ARB,
01171 GL_UNSIGNED_IDENTITY_NV,
01172 GL_ALPHA);
01173
01174
01175 CombinerInputNV(GL_COMBINER4_NV,
01176 GL_ALPHA,
01177 GL_VARIABLE_B_NV,
01178 GL_TEXTURE1_ARB,
01179 GL_UNSIGNED_IDENTITY_NV,
01180 GL_ALPHA);
01181
01182
01183 CombinerInputNV(GL_COMBINER4_NV,
01184 GL_ALPHA,
01185 GL_VARIABLE_B_NV,
01186 GL_SPARE1_NV,
01187 GL_UNSIGNED_IDENTITY_NV,
01188 GL_ALPHA);
01189
01190
01191 CombinerInputNV(GL_COMBINER4_NV,
01192 GL_ALPHA,
01193 GL_VARIABLE_D_NV,
01194 GL_SPARE1_NV,
01195 GL_UNSIGNED_IDENTITY_NV,
01196 GL_ALPHA);
01197
01198
01199
01200
01201 CombinerOutputNV(GL_COMBINER4_NV,
01202 GL_RGB,
01203 GL_DISCARD_NV,
01204 GL_DISCARD_NV,
01205 GL_SPARE1_NV,
01206 GL_NONE,
01207 GL_NONE,
01208 GL_FALSE,
01209 GL_FALSE,
01210 GL_FALSE);
01211
01212
01213 CombinerOutputNV(GL_COMBINER4_NV,
01214 GL_ALPHA,
01215 GL_TEXTURE1_ARB,
01216 GL_SPARE1_NV,
01217 GL_DISCARD_NV,
01218 GL_NONE,
01219 GL_NONE,
01220 GL_FALSE,
01221 GL_FALSE,
01222 GL_FALSE);
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232 CombinerInputNV(GL_COMBINER5_NV,
01233 GL_RGB,
01234 GL_VARIABLE_A_NV,
01235 GL_TEXTURE1_ARB,
01236 GL_UNSIGNED_IDENTITY_NV,
01237 GL_ALPHA);
01238
01239
01240 CombinerInputNV(GL_COMBINER5_NV,
01241 GL_RGB,
01242 GL_VARIABLE_B_NV,
01243 GL_CONSTANT_COLOR0_NV,
01244 GL_UNSIGNED_IDENTITY_NV,
01245 GL_RGB);
01246
01247
01248 CombinerInputNV(GL_COMBINER5_NV,
01249 GL_RGB,
01250 GL_VARIABLE_C_NV,
01251 GL_SPARE1_NV,
01252 GL_UNSIGNED_IDENTITY_NV,
01253 GL_ALPHA);
01254
01255
01256 CombinerInputNV(GL_COMBINER5_NV,
01257 GL_RGB,
01258 GL_VARIABLE_D_NV,
01259 GL_CONSTANT_COLOR1_NV,
01260 GL_UNSIGNED_IDENTITY_NV,
01261 GL_RGB);
01262
01263
01264
01265
01266 CombinerInputNV(GL_COMBINER5_NV,
01267 GL_ALPHA,
01268 GL_VARIABLE_A_NV,
01269 GL_SPARE0_NV,
01270 GL_UNSIGNED_IDENTITY_NV,
01271 GL_ALPHA);
01272
01273
01274 CombinerInputNV(GL_COMBINER5_NV,
01275 GL_ALPHA,
01276 GL_VARIABLE_B_NV,
01277 GL_SPARE0_NV,
01278 GL_UNSIGNED_IDENTITY_NV,
01279 GL_ALPHA);
01280
01281
01282
01283
01284 CombinerOutputNV(GL_COMBINER5_NV,
01285 GL_RGB,
01286 GL_DISCARD_NV,
01287 GL_DISCARD_NV,
01288 GL_TEXTURE1_ARB,
01289 GL_NONE,
01290 GL_NONE,
01291 GL_FALSE,
01292 GL_FALSE,
01293 GL_FALSE);
01294
01295
01296 CombinerOutputNV(GL_COMBINER5_NV,
01297 GL_ALPHA,
01298 GL_SPARE0_NV,
01299 GL_DISCARD_NV,
01300 GL_DISCARD_NV,
01301 GL_NONE,
01302 GL_NONE,
01303 GL_FALSE,
01304 GL_FALSE,
01305 GL_FALSE);
01306
01307
01308
01309
01310
01311
01312
01313
01314 CombinerInputNV(GL_COMBINER6_NV,
01315 GL_RGB,
01316 GL_VARIABLE_A_NV,
01317 GL_SPARE1_NV,
01318 GL_UNSIGNED_IDENTITY_NV,
01319 GL_RGB);
01320
01321
01322 CombinerInputNV(GL_COMBINER6_NV,
01323 GL_RGB,
01324 GL_VARIABLE_B_NV,
01325 GL_ZERO,
01326 GL_UNSIGNED_INVERT_NV,
01327 GL_RGB);
01328
01329
01330 CombinerInputNV(GL_COMBINER6_NV,
01331 GL_RGB,
01332 GL_VARIABLE_C_NV,
01333 GL_TEXTURE1_ARB,
01334 GL_UNSIGNED_IDENTITY_NV,
01335 GL_RGB);
01336
01337
01338 CombinerInputNV(GL_COMBINER6_NV,
01339 GL_RGB,
01340 GL_VARIABLE_D_NV,
01341 GL_ZERO,
01342 GL_UNSIGNED_INVERT_NV,
01343 GL_RGB);
01344
01345
01346
01347
01348 CombinerOutputNV(GL_COMBINER6_NV,
01349 GL_RGB,
01350 GL_DISCARD_NV,
01351 GL_DISCARD_NV,
01352 GL_SPARE1_NV,
01353 GL_NONE,
01354 GL_NONE,
01355 GL_FALSE,
01356 GL_FALSE,
01357 GL_FALSE);
01358
01359
01360 CombinerOutputNV(GL_COMBINER6_NV,
01361 GL_ALPHA,
01362 GL_DISCARD_NV,
01363 GL_DISCARD_NV,
01364 GL_DISCARD_NV,
01365 GL_NONE,
01366 GL_NONE,
01367 GL_FALSE,
01368 GL_FALSE,
01369 GL_FALSE);
01370
01371
01372
01373
01374
01375
01376
01377 CombinerInputNV(GL_COMBINER7_NV,
01378 GL_RGB,
01379 GL_VARIABLE_A_NV,
01380 GL_SPARE0_NV,
01381 GL_UNSIGNED_IDENTITY_NV,
01382 GL_ALPHA);
01383
01384
01385 CombinerInputNV(GL_COMBINER7_NV,
01386 GL_RGB,
01387 GL_VARIABLE_B_NV,
01388 GL_CONSTANT_COLOR0_NV,
01389 GL_UNSIGNED_IDENTITY_NV,
01390 GL_RGB);
01391
01392
01393 CombinerInputNV(GL_COMBINER7_NV,
01394 GL_RGB,
01395 GL_VARIABLE_C_NV,
01396 GL_SPARE0_NV,
01397 GL_UNSIGNED_IDENTITY_NV,
01398 GL_RGB);
01399
01400
01401 CombinerInputNV(GL_COMBINER7_NV,
01402 GL_RGB,
01403 GL_VARIABLE_D_NV,
01404 GL_CONSTANT_COLOR1_NV,
01405 GL_UNSIGNED_IDENTITY_NV,
01406 GL_RGB);
01407
01408
01409
01410
01411 CombinerOutputNV(GL_COMBINER7_NV,
01412 GL_RGB,
01413 GL_DISCARD_NV,
01414 GL_DISCARD_NV,
01415 GL_SPARE0_NV,
01416 GL_NONE,
01417 GL_NONE,
01418 GL_FALSE,
01419 GL_FALSE,
01420 GL_FALSE);
01421
01422
01423 CombinerOutputNV(GL_COMBINER7_NV,
01424 GL_ALPHA,
01425 GL_DISCARD_NV,
01426 GL_DISCARD_NV,
01427 GL_DISCARD_NV,
01428 GL_NONE,
01429 GL_NONE,
01430 GL_FALSE,
01431 GL_FALSE,
01432 GL_FALSE);
01433
01434
01435
01436
01437
01438
01439 FinalCombinerInputNV(GL_VARIABLE_A_NV,
01440 GL_SPARE1_NV,
01441 GL_UNSIGNED_IDENTITY_NV,
01442 GL_RGB);
01443
01444
01445 FinalCombinerInputNV(GL_VARIABLE_B_NV,
01446 GL_ZERO,
01447 GL_UNSIGNED_INVERT_NV,
01448 GL_RGB);
01449
01450
01451 FinalCombinerInputNV(GL_VARIABLE_C_NV,
01452 GL_ZERO,
01453 GL_UNSIGNED_IDENTITY_NV,
01454 GL_RGB);
01455
01456
01457 FinalCombinerInputNV(GL_VARIABLE_D_NV,
01458 GL_SPARE0_PLUS_SECONDARY_COLOR_NV,
01459 GL_UNSIGNED_IDENTITY_NV,
01460 GL_RGB);
01461
01462
01463 FinalCombinerInputNV(GL_VARIABLE_G_NV,
01464 GL_TEXTURE0_ARB,
01465 GL_UNSIGNED_IDENTITY_NV,
01466 GL_ALPHA);
01467 }
01468
01469 void DVRIsoShader::setupCombinerParametersDiffuse(DVRVolume *volume,
01470 DrawActionBase *action)
01471 {
01472
01473 Window *win = action->getWindow();
01474
01475 CombinerParameterfvNVFunc CombinerParameterfvNV =
01476 (CombinerParameterfvNVFunc) win->getFunction(
01477 _funcCombinerParameterfvNV);
01478
01479 SecondaryColor3fvEXTFunc SecondaryColor3fvEXT =
01480 (SecondaryColor3fvEXTFunc) win->getFunction(_funcSecondaryColor3fvEXT);
01481
01482 CombinerStageParameterfvNVFunc CombinerStageParameterfvNV =
01483 (CombinerStageParameterfvNVFunc) win->getFunction(
01484 _funcCombinerStageParameterfvNV);
01485
01486
01487 DirLightList diffuseLights;
01488 DirLightList specularLights;
01489 Color4f ambientLight;
01490
01491 getLightSources(diffuseLights, specularLights, ambientLight);
01492
01493
01494 unsigned int maxDiffuseLights = 2;
01495
01496 if((m_maxCombiners > 5) && m_hasPerStageConstants)
01497 {
01498 maxDiffuseLights = 4 + 2 * ((m_maxCombiners - 5) / 3);
01499 }
01500
01501
01502 Color4f *diffuseColor = new Color4f[maxDiffuseLights];
01503 Vec4f *diffuseDir = new Vec4f[maxDiffuseLights];
01504
01505 unsigned int i;
01506
01507 DirLightList::iterator l = diffuseLights.begin();
01508
01509 for(i = 0; i < maxDiffuseLights && l != diffuseLights.end(); i++)
01510 {
01511 Vec3f tmp;
01512
01513 diffuseColor[i] = l->color;
01514
01515 Slicer::rotateToLocal(action,l->dir,tmp);
01516
01517 tmp.normalize();
01518
01519 diffuseDir[i].setValues(0.5f + 0.5f * tmp[0],
01520 0.5f + 0.5f * tmp[1],
01521 0.5f + 0.5f * tmp[2],
01522 0.0f );
01523 l++;
01524 }
01525
01526 while(i < maxDiffuseLights)
01527 {
01528 diffuseColor[i] = Color4f(0.0f, 0.0f, 0.0f, 1.0f);
01529
01530 i++;
01531 }
01532
01533 if((m_maxCombiners > 5) && m_hasPerStageConstants)
01534 {
01535
01536
01537 glEnable(GL_PER_STAGE_CONSTANTS_NV);
01538
01539
01540 CombinerStageParameterfvNV(GL_COMBINER0_NV,
01541 GL_CONSTANT_COLOR0_NV,
01542 diffuseDir[0].getValues());
01543
01544
01545 CombinerStageParameterfvNV(GL_COMBINER1_NV,
01546 GL_CONSTANT_COLOR0_NV,
01547 diffuseDir[0].getValues());
01548
01549 CombinerStageParameterfvNV(GL_COMBINER1_NV,
01550 GL_CONSTANT_COLOR1_NV,
01551 diffuseDir[1].getValues());
01552
01553
01554 CombinerStageParameterfvNV(GL_COMBINER2_NV,
01555 GL_CONSTANT_COLOR0_NV,
01556 diffuseColor[0].getValuesRGBA());
01557
01558 CombinerStageParameterfvNV(GL_COMBINER2_NV,
01559 GL_CONSTANT_COLOR1_NV,
01560 diffuseColor[1].getValuesRGBA());
01561
01562 Int32 i;
01563
01564
01565
01566
01567 for(i = 0; i < (m_maxCombiners-5)/3; i++)
01568 {
01569
01570 CombinerStageParameterfvNV(GLenum(GL_COMBINER3_NV + i * 3),
01571 GL_CONSTANT_COLOR0_NV,
01572 diffuseDir[2 + 2 * i].getValues());
01573
01574 CombinerStageParameterfvNV(GLenum(GL_COMBINER3_NV + i * 3),
01575 GL_CONSTANT_COLOR1_NV,
01576 diffuseDir[3 + 2 * i].getValues());
01577
01578
01579 CombinerStageParameterfvNV(
01580 GLenum(GL_COMBINER3_NV + i * 3 + 1),
01581 GL_CONSTANT_COLOR0_NV,
01582 diffuseColor[2 + 2 * i].getValuesRGBA());
01583
01584 CombinerStageParameterfvNV(
01585 GLenum(GL_COMBINER3_NV + i * 3 + 1),
01586 GL_CONSTANT_COLOR1_NV,
01587 diffuseColor[3 + 2 * i].getValuesRGBA());
01588 }
01589
01590
01591 CombinerStageParameterfvNV(GLenum(GL_COMBINER3_NV + i * 3),
01592 GL_CONSTANT_COLOR0_NV,
01593 diffuseDir[2 + 2 * i].getValues());
01594
01595 CombinerStageParameterfvNV(GLenum(GL_COMBINER3_NV + i * 3),
01596 GL_CONSTANT_COLOR1_NV,
01597 diffuseDir[3 + 2 * i].getValues());
01598
01599
01600 CombinerStageParameterfvNV(GLenum(GL_COMBINER3_NV + i * 3 +1),
01601 GL_CONSTANT_COLOR0_NV,
01602 diffuseColor[2 + 2 * i].getValuesRGBA());
01603
01604 CombinerStageParameterfvNV(GLenum(GL_COMBINER3_NV + i * 3 + 1),
01605 GL_CONSTANT_COLOR1_NV,
01606 diffuseColor[3 + 2 * i].getValuesRGBA());
01607
01608
01609 SecondaryColor3fvEXT(ambientLight.getValuesRGBA());
01610 }
01611 else
01612 {
01613
01614
01615
01616 glColor3fv(diffuseColor[0].getValuesRGBA());
01617
01618
01619 CombinerParameterfvNV(GL_CONSTANT_COLOR0_NV,
01620 diffuseDir[0].getValues());
01621
01622
01623 SecondaryColor3fvEXT(diffuseColor[1].getValuesRGBA());
01624
01625
01626 CombinerParameterfvNV(GL_CONSTANT_COLOR1_NV,
01627 diffuseDir[1].getValues());
01628 }
01629
01630 delete [] diffuseColor;
01631 delete [] diffuseDir;
01632
01633 }
01634
01635 void DVRIsoShader::setupCombinerParametersSpecular(DVRVolume *volume,
01636 DrawActionBase *action)
01637 {
01638
01639 Window *win = action->getWindow();
01640
01641 CombinerParameterfvNVFunc CombinerParameterfvNV =
01642 (CombinerParameterfvNVFunc) win->getFunction(
01643 _funcCombinerParameterfvNV);
01644
01645 SecondaryColor3fvEXTFunc SecondaryColor3fvEXT =
01646 (SecondaryColor3fvEXTFunc) win->getFunction(_funcSecondaryColor3fvEXT);
01647
01648 CombinerStageParameterfvNVFunc CombinerStageParameterfvNV =
01649 (CombinerStageParameterfvNVFunc) win->getFunction(
01650 _funcCombinerStageParameterfvNV);
01651
01652 DirLightList diffuseLights;
01653 DirLightList specularLights;
01654 Color4f ambientLight;
01655
01656 getLightSources(diffuseLights, specularLights, ambientLight);
01657
01658
01659 Vec4f diffuseDir [3];
01660 Vec4f halfway [3];
01661 Color4f diffuseColor [3];
01662 Color4f specularColor[3];
01663
01664 unsigned int i;
01665
01666
01667 DirLightList::iterator ld = diffuseLights.begin();
01668
01669 for(i = 0; i < 3 && ld != diffuseLights.end(); i++)
01670 {
01671 Vec3f tmp;
01672
01673 diffuseColor[i] = ld->color;
01674
01675 Slicer::rotateToLocal(action,ld->dir,tmp);
01676
01677 tmp.normalize();
01678
01679 diffuseDir[i].setValues(0.5f + 0.5f * tmp[0],
01680 0.5f + 0.5f * tmp[1],
01681 0.5f + 0.5f * tmp[2],
01682 0.0f);
01683 ld++;
01684 }
01685
01686 while(i < 3)
01687 {
01688 diffuseColor[i] = Color4f(0.0f, 0.0f, 0.0f, 1.0f);
01689 diffuseDir [i] = Vec4f (0.0f, 0.0f, 0.0f, 0.0f);
01690
01691 i++;
01692 }
01693
01694
01695 Vec3f viewDir;
01696
01697 Slicer::getSlicingDirection(action, &viewDir);
01698
01699 viewDir.normalize();
01700
01701
01702 DirLightList::iterator ls = specularLights.begin();
01703
01704 for(i = 0; i < 3 && ls != specularLights.end(); i++)
01705 {
01706 Vec3f tmp;
01707
01708 specularColor[i] = ls->color;
01709
01710 Slicer::rotateToLocal(action,ls->dir,tmp);
01711
01712 tmp.normalize();
01713
01714
01715 tmp += viewDir;
01716 tmp.normalize();
01717
01718 halfway[i].setValues(0.5f + 0.5f * tmp[0],
01719 0.5f + 0.5f * tmp[1],
01720 0.5f + 0.5f * tmp[2],
01721 0.0f);
01722
01723 ls++;
01724 }
01725
01726 while(i < 3)
01727 {
01728 specularColor[i] = Color4f(0.0f, 0.0f, 0.0f, 1.0f);
01729 halfway[i] = Vec4f (0.0f, 0.0f, 0.0f, 0.0f);
01730
01731 i++;
01732 }
01733
01734 if((m_maxCombiners >= 8) && m_hasPerStageConstants)
01735 {
01736
01737
01738 glEnable(GL_PER_STAGE_CONSTANTS_NV);
01739
01740
01741 CombinerStageParameterfvNV(GL_COMBINER1_NV,
01742 GL_CONSTANT_COLOR1_NV,
01743 halfway[0].getValues());
01744
01745
01746 glColor4fv(diffuseDir[0].getValues());
01747
01748
01749 CombinerStageParameterfvNV(GL_COMBINER2_NV,
01750 GL_CONSTANT_COLOR0_NV,
01751 halfway[1].getValues());
01752
01753
01754 CombinerStageParameterfvNV(GL_COMBINER2_NV,
01755 GL_CONSTANT_COLOR1_NV,
01756 halfway[2].getValues());
01757
01758
01759 CombinerStageParameterfvNV(GL_COMBINER3_NV,
01760 GL_CONSTANT_COLOR0_NV,
01761 diffuseDir[1].getValues());
01762
01763
01764 CombinerStageParameterfvNV(GL_COMBINER3_NV,
01765 GL_CONSTANT_COLOR1_NV,
01766 diffuseDir[2].getValues());
01767
01768
01769 CombinerStageParameterfvNV(GL_COMBINER4_NV,
01770 GL_CONSTANT_COLOR0_NV,
01771 diffuseColor[1].getValuesRGBA());
01772
01773
01774 CombinerStageParameterfvNV(GL_COMBINER4_NV,
01775 GL_CONSTANT_COLOR1_NV,
01776 diffuseColor[2].getValuesRGBA());
01777
01778
01779 CombinerStageParameterfvNV(GL_COMBINER5_NV,
01780 GL_CONSTANT_COLOR0_NV,
01781 specularColor[1].getValuesRGBA());
01782
01783
01784 CombinerStageParameterfvNV(GL_COMBINER5_NV,
01785 GL_CONSTANT_COLOR1_NV,
01786 specularColor[2].getValuesRGBA());
01787
01788
01789 CombinerStageParameterfvNV(GL_COMBINER7_NV,
01790 GL_CONSTANT_COLOR0_NV,
01791 specularColor[0].getValuesRGBA());
01792
01793
01794 CombinerStageParameterfvNV(GL_COMBINER7_NV,
01795 GL_CONSTANT_COLOR1_NV,
01796 diffuseColor[0].getValuesRGBA());
01797 }
01798 else
01799 {
01800
01801
01802
01803
01804 diffuseDir[0] *= diffuseColor [0][0];
01805 halfway [0] *= specularColor[0][0];
01806
01807
01808 CombinerParameterfvNV(GL_CONSTANT_COLOR1_NV, halfway[0].getValues());
01809
01810
01811 glColor3f(0.5f + 0.5f * diffuseDir[0][0],
01812 0.5f + 0.5f * diffuseDir[0][1],
01813 0.5f + 0.5f * diffuseDir[0][2]);
01814 }
01815
01816
01817 SecondaryColor3fvEXT(ambientLight.getValuesRGBA());
01818 }
01819
01820 void DVRIsoShader::activate_NVRegisterCombinerShading(DVRVolume *volume,
01821 DrawActionBase *action)
01822 {
01823 if(volume->getDoTextures())
01824 {
01825 Window *win = action->getWindow();
01826
01827 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &m_maxCombiners);
01828 FINFO(("DVRIsoShader - found %d general register combiners\n",
01829 m_maxCombiners));
01830
01831 if(win->hasExtension(_NV_register_combiners2))
01832 {
01833 FINFO(("DVRIsoShader - found per (register combiner) "
01834 "stage constants\n"));
01835
01836 m_hasPerStageConstants = true;
01837 }
01838 else
01839 {
01840 FINFO(("DVRIsoShader - no per (register combiner) "
01841 "stage constants available\n"));
01842
01843 m_hasPerStageConstants = false;
01844 }
01845
01846 ActiveTextureARBFunc ActiveTextureARB =
01847 (ActiveTextureARBFunc) win->getFunction(_funcActiveTextureARB);
01848
01849
01850 Real32 isoValue;
01851 UInt32 alphaMode;
01852 bool doSpecular;
01853 DVRIsoSurfacePtr isoParam = DVRVOLUME_PARAMETER(volume,
01854 DVRIsoSurface);
01855 if(isoParam != NullFC)
01856 {
01857 isoValue = isoParam->getIsoValue ();
01858 alphaMode = isoParam->getAlphaMode ();
01859 doSpecular = isoParam->getSpecularLighting();
01860 }
01861 else
01862 {
01863 isoValue = 1.0;
01864 alphaMode = GL_GREATER;
01865 doSpecular = false;
01866 }
01867
01868
01869 glPushAttrib(GL_ENABLE_BIT |
01870 GL_COLOR_BUFFER_BIT |
01871 GL_DEPTH_BUFFER_BIT |
01872 GL_POLYGON_BIT |
01873 GL_TEXTURE_BIT );
01874
01875
01876 glEnable(GL_REGISTER_COMBINERS_NV);
01877
01878
01879 if(m_shadingMode == SM_REGISTER_COMBINERS_MULTI2D)
01880 {
01881 ActiveTextureARB(GL_TEXTURE0_ARB);
01882 ActiveTextureARB(GL_TEXTURE1_ARB);
01883 }
01884
01885
01886
01887 glDisable(GL_BLEND);
01888 glDisable(GL_LIGHTING);
01889
01890
01891
01892 glEnable (GL_ALPHA_TEST );
01893 glAlphaFunc(alphaMode, isoValue);
01894
01895
01896 if(doSpecular)
01897 {
01898 setupCombinerParametersSpecular (volume,
01899 action);
01900 initCombiners_IsoSurfaceSpecular(action);
01901 }
01902 else
01903 {
01904 setupCombinerParametersDiffuse (volume,
01905 action);
01906 initCombiners_IsoSurfaceDiffuse(action);
01907 }
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921 }
01922 }
01923
01924 void DVRIsoShader::renderSlice_NVRegisterCombinerShading(
01925 DVRVolume *volume,
01926 DrawActionBase *action,
01927 Real32 *data,
01928 UInt32 vertices,
01929 UInt32 values)
01930 {
01931 if(values < 6)
01932 {
01933 SWARNING << "DVRIsoShader::renderSlice - insufficient values"
01934 << std::endl;
01935 return;
01936 }
01937
01938 Window *win = action->getWindow();
01939
01940
01941 CombinerParameterfvNVFunc CombinerParameterfvNV =
01942 (CombinerParameterfvNVFunc) win->getFunction(
01943 _funcCombinerParameterfvNV);
01944
01945 MultiTexCoord2dARBFunc MultiTexCoord2dARB =
01946 (MultiTexCoord2dARBFunc) win->getFunction(_funcMultiTexCoord2dARB);
01947
01948
01949
01950 bool doSpecular;
01951
01952 DVRIsoSurfacePtr isoParam = DVRVOLUME_PARAMETER(volume, DVRIsoSurface);
01953
01954 if(isoParam != NullFC)
01955 {
01956 doSpecular = isoParam->getSpecularLighting();
01957 }
01958 else
01959 {
01960 doSpecular = false;
01961 }
01962
01963 if( ((doSpecular && (m_maxCombiners > 2)) || (m_maxCombiners > 5)) &&
01964 m_hasPerStageConstants )
01965 {
01966 CombinerStageParameterfvNVFunc CombinerStageParameterfvNV =
01967 (CombinerStageParameterfvNVFunc) win->getFunction(
01968 _funcCombinerStageParameterfvNV);
01969
01970 GLfloat col[4] =
01971 {
01972 0.0f, 0.0f, 0.0f, data[5]
01973 };
01974
01975 CombinerStageParameterfvNV(GL_COMBINER0_NV,
01976 GL_CONSTANT_COLOR0_NV,
01977 col);
01978 }
01979 else
01980 {
01981 GLfloat col[4];
01982
01983 glGetFloatv(GL_CONSTANT_COLOR0_NV,col);
01984
01985 col[3] = data[5];
01986
01987 CombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, col);
01988 }
01989
01990 if(volume->getDoTextures())
01991 {
01992 glBegin(GL_TRIANGLE_FAN);
01993 }
01994 else
01995 {
01996 glColor4f(1.0, 1.0, 1.0, 1.0);
01997 glBegin (GL_LINE_LOOP);
01998 }
01999
02000
02001 for(UInt32 i = 0; i < vertices; i++)
02002 {
02003 Real32 * vert = data + i * values;
02004
02005 MultiTexCoord2dARB(GL_TEXTURE0_ARB, vert[3], vert[4]);
02006 MultiTexCoord2dARB(GL_TEXTURE1_ARB, vert[3], vert[4]);
02007
02008 glVertex3f(vert[0], vert[1], vert[2]);
02009 }
02010 glEnd();
02011 }
02012
02013
02014 void DVRIsoShader::renderSlice_NVRegisterCombinerShading(
02015 DVRVolume *volume,
02016 DrawActionBase *action,
02017 DVRRenderSlice *clippedSlice)
02018 {
02019 Window *win = action->getWindow();
02020
02021
02022 CombinerParameterfvNVFunc CombinerParameterfvNV =
02023 (CombinerParameterfvNVFunc) win->getFunction(
02024 _funcCombinerParameterfvNV);
02025
02026 MultiTexCoord2dARBFunc MultiTexCoord2dARB =
02027 (MultiTexCoord2dARBFunc) win->getFunction(_funcMultiTexCoord2dARB);
02028
02029
02030 bool doSpecular;
02031 DVRIsoSurfacePtr isoParam = DVRVOLUME_PARAMETER(volume, DVRIsoSurface);
02032
02033 if(isoParam != NullFC)
02034 {
02035 doSpecular = isoParam->getSpecularLighting();
02036 }
02037 else
02038 {
02039 doSpecular = false;
02040 }
02041
02042 GLfloat intFactor = 0;
02043
02044 switch(clippedSlice->orientation)
02045 {
02046 case DVRRenderSlice::XY:
02047 intFactor =
02048 Real32((*(*clippedSlice->begin())->vertices.begin())[5]);
02049 break;
02050
02051 case DVRRenderSlice::XZ:
02052 intFactor =
02053 Real32((*(*clippedSlice->begin())->vertices.begin())[4]);
02054 break;
02055
02056 case DVRRenderSlice::YZ:
02057 intFactor =
02058 Real32((*(*clippedSlice->begin())->vertices.begin())[3]);
02059 break;
02060
02061 default:
02062 break;
02063 }
02064
02065 if( ((doSpecular && (m_maxCombiners > 2)) || (m_maxCombiners > 5)) &&
02066 m_hasPerStageConstants )
02067 {
02068 CombinerStageParameterfvNVFunc CombinerStageParameterfvNV =
02069 (CombinerStageParameterfvNVFunc) win->getFunction(
02070 _funcCombinerStageParameterfvNV);
02071
02072 GLfloat col[4] =
02073 {
02074 0.0f, 0.0f, 0.0f, intFactor
02075 };
02076
02077 CombinerStageParameterfvNV(GL_COMBINER0_NV,
02078 GL_CONSTANT_COLOR0_NV,
02079 col);
02080 }
02081 else
02082 {
02083 GLfloat col[4];
02084
02085 glGetFloatv(GL_CONSTANT_COLOR0_NV,col);
02086
02087 col[3] = intFactor;
02088
02089 CombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, col);
02090 }
02091
02092 switch(clippedSlice->orientation)
02093 {
02094 case DVRRenderSlice::XY:
02095
02096 for(std::vector<DVRRenderSlicePrimitive*>::const_iterator prim =
02097 clippedSlice->begin();
02098
02099 prim != clippedSlice->end();
02100 ++prim)
02101 {
02102 glBegin((*prim)->type);
02103
02104 std::vector<GLdouble*>::const_iterator vert =
02105 (*prim)->vertices.begin();
02106
02107 for(; vert != (*prim)->vertices.end(); vert++)
02108 {
02109 MultiTexCoord2dARB(GL_TEXTURE0_ARB,
02110 (*vert)[3],
02111 (*vert)[4]);
02112
02113 MultiTexCoord2dARB(GL_TEXTURE1_ARB,
02114 (*vert)[3],
02115 (*vert)[4]);
02116
02117 glVertex3dv(*vert);
02118 }
02119 glEnd();
02120 }
02121 break;
02122
02123 case DVRRenderSlice::XZ:
02124
02125 for(std::vector<DVRRenderSlicePrimitive*>::const_iterator prim =
02126 clippedSlice->begin();
02127
02128 prim != clippedSlice->end();
02129 ++prim)
02130 {
02131 glBegin((*prim)->type);
02132
02133 std::vector<GLdouble*>::const_iterator vert =
02134 (*prim)->vertices.begin();
02135
02136 for(; vert != (*prim)->vertices.end(); vert++)
02137 {
02138 MultiTexCoord2dARB(GL_TEXTURE0_ARB,
02139 (*vert)[3],
02140 (*vert)[5]);
02141
02142 MultiTexCoord2dARB(GL_TEXTURE1_ARB,
02143 (*vert)[3],
02144 (*vert)[5]);
02145
02146 glVertex3dv(*vert);
02147 }
02148 glEnd();
02149 }
02150 break;
02151
02152 case DVRRenderSlice::YZ:
02153
02154 for(std::vector<DVRRenderSlicePrimitive*>::const_iterator prim =
02155 clippedSlice->begin();
02156
02157 prim != clippedSlice->end();
02158 ++prim)
02159 {
02160 glBegin((*prim)->type);
02161
02162 std::vector<GLdouble*>::const_iterator vert =
02163 (*prim)->vertices.begin();
02164
02165 for(; vert != (*prim)->vertices.end(); vert++)
02166 {
02167 MultiTexCoord2dARB(GL_TEXTURE0_ARB,
02168 (*vert)[4],
02169 (*vert)[5]);
02170
02171 MultiTexCoord2dARB(GL_TEXTURE1_ARB,
02172 (*vert)[4],
02173 (*vert)[5]);
02174
02175 glVertex3dv(*vert);
02176 }
02177 glEnd();
02178 }
02179 break;
02180
02181 default:
02182 break;
02183 }
02184 }
02185
02186 void DVRIsoShader::deactivate_NVRegisterCombinerShading(DVRVolume *volume,
02187 DrawActionBase *action)
02188 {
02189 if(volume->getDoTextures())
02190 {
02191 glDisable(GL_REGISTER_COMBINERS_NV);
02192
02193 if((m_maxCombiners > 2) && m_hasPerStageConstants)
02194 glDisable(GL_PER_STAGE_CONSTANTS_NV);
02195
02196 glDisable(GL_ALPHA_TEST);
02197
02198 glPopAttrib();
02199 }
02200 }