aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldrawpoolterrain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/lldrawpoolterrain.cpp')
-rw-r--r--linden/indra/newview/lldrawpoolterrain.cpp286
1 files changed, 95 insertions, 191 deletions
diff --git a/linden/indra/newview/lldrawpoolterrain.cpp b/linden/indra/newview/lldrawpoolterrain.cpp
index fdb27f9..2cd2fdb 100644
--- a/linden/indra/newview/lldrawpoolterrain.cpp
+++ b/linden/indra/newview/lldrawpoolterrain.cpp
@@ -52,7 +52,7 @@
52#include "llworld.h" 52#include "llworld.h"
53#include "pipeline.h" 53#include "pipeline.h"
54#include "llglslshader.h" 54#include "llglslshader.h"
55#include "llglimmediate.h" 55#include "llrender.h"
56 56
57const F32 DETAIL_SCALE = 1.f/16.f; 57const F32 DETAIL_SCALE = 1.f/16.f;
58int DebugDetailMap = 0; 58int DebugDetailMap = 0;
@@ -69,14 +69,16 @@ LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerImage *texturep) :
69 sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale"); 69 sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale");
70 sDetailMode = gSavedSettings.getS32("RenderTerrainDetail"); 70 sDetailMode = gSavedSettings.getS32("RenderTerrainDetail");
71 mAlphaRampImagep = gImageList.getImageFromFile("alpha_gradient.tga", 71 mAlphaRampImagep = gImageList.getImageFromFile("alpha_gradient.tga",
72 TRUE, TRUE, GL_ALPHA8, GL_ALPHA, 72 TRUE, TRUE, GL_ALPHA8, GL_ALPHA,
73 LLUUID("e97cf410-8e61-7005-ec06-629eba4cd1fb")); 73 LLUUID("e97cf410-8e61-7005-ec06-629eba4cd1fb"));
74
74 mAlphaRampImagep->bind(0); 75 mAlphaRampImagep->bind(0);
75 mAlphaRampImagep->setClamp(TRUE, TRUE); 76 mAlphaRampImagep->setClamp(TRUE, TRUE);
76 77
77 m2DAlphaRampImagep = gImageList.getImageFromFile("alpha_gradient_2d.j2c", 78 m2DAlphaRampImagep = gImageList.getImageFromFile("alpha_gradient_2d.j2c",
78 TRUE, TRUE, GL_ALPHA8, GL_ALPHA, 79 TRUE, TRUE, GL_ALPHA8, GL_ALPHA,
79 LLUUID("38b86f85-2575-52a9-a531-23108d8da837")); 80 LLUUID("38b86f85-2575-52a9-a531-23108d8da837"));
81
80 m2DAlphaRampImagep->bind(0); 82 m2DAlphaRampImagep->bind(0);
81 m2DAlphaRampImagep->setClamp(TRUE, TRUE); 83 m2DAlphaRampImagep->setClamp(TRUE, TRUE);
82 84
@@ -239,7 +241,7 @@ void LLDrawPoolTerrain::renderFullShader()
239 // 241 //
240 S32 detail0 = sShader->enableTexture(LLShaderMgr::TERRAIN_DETAIL0); 242 S32 detail0 = sShader->enableTexture(LLShaderMgr::TERRAIN_DETAIL0);
241 LLViewerImage::bindTexture(detail_texture0p,detail0); 243 LLViewerImage::bindTexture(detail_texture0p,detail0);
242 glActiveTextureARB(GL_TEXTURE0_ARB); 244 gGL.getTexUnit(0)->activate();
243 245
244 glEnable(GL_TEXTURE_GEN_S); 246 glEnable(GL_TEXTURE_GEN_S);
245 glEnable(GL_TEXTURE_GEN_T); 247 glEnable(GL_TEXTURE_GEN_T);
@@ -259,7 +261,7 @@ void LLDrawPoolTerrain::renderFullShader()
259 LLViewerImage::bindTexture(detail_texture1p,detail1); 261 LLViewerImage::bindTexture(detail_texture1p,detail1);
260 262
261 /// ALPHA TEXTURE COORDS 0: 263 /// ALPHA TEXTURE COORDS 0:
262 glActiveTextureARB(GL_TEXTURE1_ARB); 264 gGL.getTexUnit(1)->activate();
263 glMatrixMode(GL_TEXTURE); 265 glMatrixMode(GL_TEXTURE);
264 glLoadIdentity(); 266 glLoadIdentity();
265 glMatrixMode(GL_MODELVIEW); 267 glMatrixMode(GL_MODELVIEW);
@@ -271,7 +273,7 @@ void LLDrawPoolTerrain::renderFullShader()
271 glEnable(GL_TEXTURE_2D); 273 glEnable(GL_TEXTURE_2D);
272 274
273 /// ALPHA TEXTURE COORDS 1: 275 /// ALPHA TEXTURE COORDS 1:
274 glActiveTextureARB(GL_TEXTURE2_ARB); 276 gGL.getTexUnit(2)->activate();
275 glMatrixMode(GL_TEXTURE); 277 glMatrixMode(GL_TEXTURE);
276 glLoadIdentity(); 278 glLoadIdentity();
277 glTranslatef(-2.f, 0.f, 0.f); 279 glTranslatef(-2.f, 0.f, 0.f);
@@ -284,7 +286,7 @@ void LLDrawPoolTerrain::renderFullShader()
284 LLViewerImage::bindTexture(detail_texture3p,detail3); 286 LLViewerImage::bindTexture(detail_texture3p,detail3);
285 287
286 /// ALPHA TEXTURE COORDS 2: 288 /// ALPHA TEXTURE COORDS 2:
287 glActiveTextureARB(GL_TEXTURE3_ARB); 289 gGL.getTexUnit(3)->activate();
288 glMatrixMode(GL_TEXTURE); 290 glMatrixMode(GL_TEXTURE);
289 glLoadIdentity(); 291 glLoadIdentity();
290 glTranslatef(-1.f, 0.f, 0.f); 292 glTranslatef(-1.f, 0.f, 0.f);
@@ -307,7 +309,7 @@ void LLDrawPoolTerrain::renderFullShader()
307 sShader->disableTexture(LLShaderMgr::TERRAIN_DETAIL3); 309 sShader->disableTexture(LLShaderMgr::TERRAIN_DETAIL3);
308 310
309 LLImageGL::unbindTexture(alpha_ramp, GL_TEXTURE_2D); 311 LLImageGL::unbindTexture(alpha_ramp, GL_TEXTURE_2D);
310 glActiveTextureARB(GL_TEXTURE4_ARB); 312 gGL.getTexUnit(4)->activate();
311 glDisable(GL_TEXTURE_2D); // Texture unit 4 313 glDisable(GL_TEXTURE_2D); // Texture unit 4
312 glDisable(GL_TEXTURE_GEN_S); 314 glDisable(GL_TEXTURE_GEN_S);
313 glDisable(GL_TEXTURE_GEN_T); 315 glDisable(GL_TEXTURE_GEN_T);
@@ -316,7 +318,7 @@ void LLDrawPoolTerrain::renderFullShader()
316 glMatrixMode(GL_MODELVIEW); 318 glMatrixMode(GL_MODELVIEW);
317 319
318 LLImageGL::unbindTexture(detail3, GL_TEXTURE_2D); 320 LLImageGL::unbindTexture(detail3, GL_TEXTURE_2D);
319 glActiveTextureARB(GL_TEXTURE3_ARB); 321 gGL.getTexUnit(3)->activate();
320 glDisable(GL_TEXTURE_2D); 322 glDisable(GL_TEXTURE_2D);
321 glDisable(GL_TEXTURE_GEN_S); 323 glDisable(GL_TEXTURE_GEN_S);
322 glDisable(GL_TEXTURE_GEN_T); 324 glDisable(GL_TEXTURE_GEN_T);
@@ -325,7 +327,7 @@ void LLDrawPoolTerrain::renderFullShader()
325 glMatrixMode(GL_MODELVIEW); 327 glMatrixMode(GL_MODELVIEW);
326 328
327 LLImageGL::unbindTexture(detail2, GL_TEXTURE_2D); 329 LLImageGL::unbindTexture(detail2, GL_TEXTURE_2D);
328 glActiveTextureARB(GL_TEXTURE2_ARB); 330 gGL.getTexUnit(2)->activate();
329 glDisable(GL_TEXTURE_2D); 331 glDisable(GL_TEXTURE_2D);
330 glDisable(GL_TEXTURE_GEN_S); 332 glDisable(GL_TEXTURE_GEN_S);
331 glDisable(GL_TEXTURE_GEN_T); 333 glDisable(GL_TEXTURE_GEN_T);
@@ -334,7 +336,7 @@ void LLDrawPoolTerrain::renderFullShader()
334 glMatrixMode(GL_MODELVIEW); 336 glMatrixMode(GL_MODELVIEW);
335 337
336 LLImageGL::unbindTexture(detail1, GL_TEXTURE_2D); 338 LLImageGL::unbindTexture(detail1, GL_TEXTURE_2D);
337 glActiveTextureARB(GL_TEXTURE1_ARB); 339 gGL.getTexUnit(1)->activate();
338 glDisable(GL_TEXTURE_2D); 340 glDisable(GL_TEXTURE_2D);
339 glDisable(GL_TEXTURE_GEN_S); 341 glDisable(GL_TEXTURE_GEN_S);
340 glDisable(GL_TEXTURE_GEN_T); 342 glDisable(GL_TEXTURE_GEN_T);
@@ -346,7 +348,7 @@ void LLDrawPoolTerrain::renderFullShader()
346 // Restore Texture Unit 0 defaults 348 // Restore Texture Unit 0 defaults
347 349
348 LLImageGL::unbindTexture(detail0, GL_TEXTURE_2D); 350 LLImageGL::unbindTexture(detail0, GL_TEXTURE_2D);
349 glActiveTextureARB(GL_TEXTURE0_ARB); 351 gGL.getTexUnit(0)->activate();
350 glEnable(GL_TEXTURE_2D); 352 glEnable(GL_TEXTURE_2D);
351 glDisable(GL_TEXTURE_GEN_S); 353 glDisable(GL_TEXTURE_GEN_S);
352 glDisable(GL_TEXTURE_GEN_T); 354 glDisable(GL_TEXTURE_GEN_T);
@@ -357,7 +359,7 @@ void LLDrawPoolTerrain::renderFullShader()
357 359
358void LLDrawPoolTerrain::renderFull4TU() 360void LLDrawPoolTerrain::renderFull4TU()
359{ 361{
360 glEnableClientState(GL_VERTEX_ARRAY); 362 glEnableClientState(GL_VERTEX_ARRAY);
361 glEnableClientState(GL_NORMAL_ARRAY); 363 glEnableClientState(GL_NORMAL_ARRAY);
362 364
363 // Hack! Get the region that this draw pool is rendering from! 365 // Hack! Get the region that this draw pool is rendering from!
@@ -377,7 +379,7 @@ void LLDrawPoolTerrain::renderFull4TU()
377 tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x); 379 tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
378 tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y); 380 tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
379 381
380 gGL.blendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); 382 gGL.blendFunc(LLRender::BF_ONE_MINUS_SOURCE_ALPHA, LLRender::BF_SOURCE_ALPHA);
381 383
382 //---------------------------------------------------------------------------- 384 //----------------------------------------------------------------------------
383 // Pass 1/1 385 // Pass 1/1
@@ -385,11 +387,10 @@ void LLDrawPoolTerrain::renderFull4TU()
385 // 387 //
386 // Stage 0: detail texture 0 388 // Stage 0: detail texture 0
387 // 389 //
388 glActiveTextureARB(GL_TEXTURE0_ARB); 390 gGL.getTexUnit(0)->activate();
389 LLViewerImage::bindTexture(detail_texture0p,0); 391 LLViewerImage::bindTexture(detail_texture0p,0);
390 glClientActiveTextureARB(GL_TEXTURE0_ARB); 392 glClientActiveTextureARB(GL_TEXTURE0_ARB);
391 393
392 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
393 glEnable(GL_TEXTURE_GEN_S); 394 glEnable(GL_TEXTURE_GEN_S);
394 glEnable(GL_TEXTURE_GEN_T); 395 glEnable(GL_TEXTURE_GEN_T);
395 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); 396 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
@@ -398,36 +399,27 @@ void LLDrawPoolTerrain::renderFull4TU()
398 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 399 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
399 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 400 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
400 401
401 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 402 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_COLOR);
402 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
403
404 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
405 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
406 403
407 // 404 //
408 // Stage 1: Generate alpha ramp for detail0/detail1 transition 405 // Stage 1: Generate alpha ramp for detail0/detail1 transition
409 // 406 //
407
410 LLViewerImage::bindTexture(m2DAlphaRampImagep,1); 408 LLViewerImage::bindTexture(m2DAlphaRampImagep,1);
411 glActiveTextureARB(GL_TEXTURE1_ARB); 409 gGL.getTexUnit(1)->activate();
412 glEnable(GL_TEXTURE_2D); // Texture unit 1 410 glEnable(GL_TEXTURE_2D); // Texture unit 1
413 glClientActiveTextureARB(GL_TEXTURE1_ARB); 411 glClientActiveTextureARB(GL_TEXTURE1_ARB);
414 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 412 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
415 413
416 // Care about alpha only 414 // Care about alpha only
417 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 415 gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR);
418 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); 416 gGL.getTexUnit(1)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_ALPHA);
419 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
420
421 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
422 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
423 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
424 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
425 417
426 // 418 //
427 // Stage 2: Interpolate detail1 with existing based on ramp 419 // Stage 2: Interpolate detail1 with existing based on ramp
428 // 420 //
429 LLViewerImage::bindTexture(detail_texture1p,2); 421 LLViewerImage::bindTexture(detail_texture1p,2);
430 glActiveTextureARB(GL_TEXTURE2_ARB); 422 gGL.getTexUnit(2)->activate();
431 glEnable(GL_TEXTURE_2D); // Texture unit 2 423 glEnable(GL_TEXTURE_2D); // Texture unit 2
432 glClientActiveTextureARB(GL_TEXTURE2_ARB); 424 glClientActiveTextureARB(GL_TEXTURE2_ARB);
433 425
@@ -439,34 +431,22 @@ void LLDrawPoolTerrain::renderFull4TU()
439 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 431 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
440 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 432 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
441 433
442 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 434 gGL.getTexUnit(2)->setTextureColorBlend(LLTexUnit::TBO_LERP_PREV_ALPHA, LLTexUnit::TBS_PREV_COLOR, LLTexUnit::TBS_TEX_COLOR);
443 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE);
444
445 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
446 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
447 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
448 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
449 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PREVIOUS_ARB);
450 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
451 435
452 // 436 //
453 // Stage 3: Modulate with primary (vertex) color for lighting 437 // Stage 3: Modulate with primary (vertex) color for lighting
454 // 438 //
455 LLViewerImage::bindTexture(detail_texture1p,3); // bind any texture 439 LLViewerImage::bindTexture(detail_texture1p,3); // bind any texture
456 glActiveTextureARB(GL_TEXTURE3_ARB); 440 gGL.getTexUnit(3)->activate();
457 glEnable(GL_TEXTURE_2D); // Texture unit 3 441 glEnable(GL_TEXTURE_2D); // Texture unit 3
458 glClientActiveTextureARB(GL_TEXTURE3_ARB); 442 glClientActiveTextureARB(GL_TEXTURE3_ARB);
459 443
460 // Set alpha texture and do lighting modulation 444 // Set alpha texture and do lighting modulation
461 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 445 gGL.getTexUnit(3)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_PREV_COLOR, LLTexUnit::TBS_VERT_COLOR);
462 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
463 446
464 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS); 447 gGL.getTexUnit(0)->activate();
465 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); 448 glClientActiveTextureARB(GL_TEXTURE0_ARB);
466 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
467 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
468 449
469 glActiveTextureARB(GL_TEXTURE0_ARB);
470 // GL_BLEND disabled by default 450 // GL_BLEND disabled by default
471 drawLoop(); 451 drawLoop();
472 452
@@ -475,7 +455,7 @@ void LLDrawPoolTerrain::renderFull4TU()
475 455
476 // Stage 0: Write detail3 into base 456 // Stage 0: Write detail3 into base
477 // 457 //
478 glActiveTextureARB(GL_TEXTURE0_ARB); 458 gGL.getTexUnit(0)->activate();
479 LLViewerImage::bindTexture(detail_texture3p,0); 459 LLViewerImage::bindTexture(detail_texture3p,0);
480 glClientActiveTextureARB(GL_TEXTURE0_ARB); 460 glClientActiveTextureARB(GL_TEXTURE0_ARB);
481 461
@@ -487,18 +467,13 @@ void LLDrawPoolTerrain::renderFull4TU()
487 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 467 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
488 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 468 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
489 469
490 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 470 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_COLOR);
491 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
492
493 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
494 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
495
496 471
497 // 472 //
498 // Stage 1: Generate alpha ramp for detail2/detail3 transition 473 // Stage 1: Generate alpha ramp for detail2/detail3 transition
499 // 474 //
500 LLViewerImage::bindTexture(m2DAlphaRampImagep,1); 475 LLViewerImage::bindTexture(m2DAlphaRampImagep,1);
501 glActiveTextureARB(GL_TEXTURE1_ARB); 476 gGL.getTexUnit(1)->activate();
502 glEnable(GL_TEXTURE_2D); // Texture unit 1 477 glEnable(GL_TEXTURE_2D); // Texture unit 1
503 glClientActiveTextureARB(GL_TEXTURE1_ARB); 478 glClientActiveTextureARB(GL_TEXTURE1_ARB);
504 479
@@ -510,25 +485,20 @@ void LLDrawPoolTerrain::renderFull4TU()
510 glTranslatef(-2.f, 0.f, 0.f); 485 glTranslatef(-2.f, 0.f, 0.f);
511 486
512 // Care about alpha only 487 // Care about alpha only
513 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 488 gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR);
514 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); 489 gGL.getTexUnit(1)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_ALPHA);
515 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
516
517 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
518 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
519 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
520 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
521 490
522 491
523 // 492 //
524 // Stage 2: Interpolate detail2 with existing based on ramp 493 // Stage 2: Interpolate detail2 with existing based on ramp
525 // 494 //
526 LLViewerImage::bindTexture(detail_texture2p,2); 495 LLViewerImage::bindTexture(detail_texture2p,2);
527 glActiveTextureARB(GL_TEXTURE2_ARB); 496 gGL.getTexUnit(2)->activate();
528 glEnable(GL_TEXTURE_2D); // Texture unit 2 497 glEnable(GL_TEXTURE_2D); // Texture unit 2
529 glClientActiveTextureARB(GL_TEXTURE2_ARB);
530 498
499 glClientActiveTextureARB(GL_TEXTURE2_ARB);
531 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 500 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
501
532 glEnable(GL_TEXTURE_GEN_S); 502 glEnable(GL_TEXTURE_GEN_S);
533 glEnable(GL_TEXTURE_GEN_T); 503 glEnable(GL_TEXTURE_GEN_T);
534 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); 504 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
@@ -536,26 +506,16 @@ void LLDrawPoolTerrain::renderFull4TU()
536 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 506 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
537 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 507 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
538 508
539 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 509 gGL.getTexUnit(2)->setTextureColorBlend(LLTexUnit::TBO_LERP_PREV_ALPHA, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_PREV_COLOR);
540 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE);
541
542 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
543 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
544 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
545 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
546 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PREVIOUS_ARB);
547 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_ONE_MINUS_SRC_ALPHA);
548
549 510
550 // 511 //
551 // Stage 3: Generate alpha ramp for detail1/detail2 transition 512 // Stage 3: Generate alpha ramp for detail1/detail2 transition
552 // 513 //
553 LLViewerImage::bindTexture(m2DAlphaRampImagep,3); 514 LLViewerImage::bindTexture(m2DAlphaRampImagep,3);
554 glActiveTextureARB(GL_TEXTURE3_ARB); 515 gGL.getTexUnit(3)->activate();
555
556 glEnable(GL_TEXTURE_2D); // Texture unit 3 516 glEnable(GL_TEXTURE_2D); // Texture unit 3
557 glClientActiveTextureARB(GL_TEXTURE3_ARB);
558 517
518 glClientActiveTextureARB(GL_TEXTURE3_ARB);
559 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 519 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
560 520
561 // Set the texture matrix 521 // Set the texture matrix
@@ -564,38 +524,34 @@ void LLDrawPoolTerrain::renderFull4TU()
564 glTranslatef(-1.f, 0.f, 0.f); 524 glTranslatef(-1.f, 0.f, 0.f);
565 525
566 // Set alpha texture and do lighting modulation 526 // Set alpha texture and do lighting modulation
567 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 527 gGL.getTexUnit(3)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_PREV_COLOR, LLTexUnit::TBS_VERT_COLOR);
568 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); 528 gGL.getTexUnit(3)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_ALPHA);
569 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); 529
570 530 gGL.getTexUnit(0)->activate();
571 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS); 531 glClientActiveTextureARB(GL_TEXTURE0_ARB);
572 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
573 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
574 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
575 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
576 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
577
578 glActiveTextureARB(GL_TEXTURE0_ARB);
579 { 532 {
580 LLGLEnable blend(GL_BLEND); 533 LLGLEnable blend(GL_BLEND);
581 drawLoop(); 534 drawLoop();
582 } 535 }
583 536
537 LLVertexBuffer::unbind();
584 // Disable multitexture 538 // Disable multitexture
585 LLImageGL::unbindTexture(3, GL_TEXTURE_2D); 539 LLImageGL::unbindTexture(3, GL_TEXTURE_2D);
586 glActiveTextureARB(GL_TEXTURE3_ARB); 540 gGL.getTexUnit(3)->activate();
587 glClientActiveTextureARB(GL_TEXTURE3_ARB); 541 glClientActiveTextureARB(GL_TEXTURE3_ARB);
588 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 542 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
589 glDisable(GL_TEXTURE_2D); // Texture unit 3 543 glDisable(GL_TEXTURE_2D); // Texture unit 3
544
590 glMatrixMode(GL_TEXTURE); 545 glMatrixMode(GL_TEXTURE);
591 glLoadIdentity(); 546 glLoadIdentity();
592 glMatrixMode(GL_MODELVIEW); 547 glMatrixMode(GL_MODELVIEW);
593 548
594 LLImageGL::unbindTexture(2, GL_TEXTURE_2D); 549 LLImageGL::unbindTexture(2, GL_TEXTURE_2D);
595 glActiveTextureARB(GL_TEXTURE2_ARB); 550 gGL.getTexUnit(2)->activate();
596 glClientActiveTextureARB(GL_TEXTURE2_ARB); 551 glClientActiveTextureARB(GL_TEXTURE2_ARB);
597 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 552 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
598 glDisable(GL_TEXTURE_2D); // Texture unit 2 553 glDisable(GL_TEXTURE_2D); // Texture unit 2
554
599 glDisable(GL_TEXTURE_GEN_S); 555 glDisable(GL_TEXTURE_GEN_S);
600 glDisable(GL_TEXTURE_GEN_T); 556 glDisable(GL_TEXTURE_GEN_T);
601 glMatrixMode(GL_TEXTURE); 557 glMatrixMode(GL_TEXTURE);
@@ -603,33 +559,34 @@ void LLDrawPoolTerrain::renderFull4TU()
603 glMatrixMode(GL_MODELVIEW); 559 glMatrixMode(GL_MODELVIEW);
604 560
605 LLImageGL::unbindTexture(1, GL_TEXTURE_2D); 561 LLImageGL::unbindTexture(1, GL_TEXTURE_2D);
606 glActiveTextureARB(GL_TEXTURE1_ARB); 562 gGL.getTexUnit(1)->activate();
607 glClientActiveTextureARB(GL_TEXTURE1_ARB); 563 glClientActiveTextureARB(GL_TEXTURE1_ARB);
608 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 564 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
609 glDisable(GL_TEXTURE_2D); // Texture unit 1 565 glDisable(GL_TEXTURE_2D); // Texture unit 1
566
610 glMatrixMode(GL_TEXTURE); 567 glMatrixMode(GL_TEXTURE);
611 glLoadIdentity(); 568 glLoadIdentity();
612 glMatrixMode(GL_MODELVIEW); 569 glMatrixMode(GL_MODELVIEW);
613 570
614 // Restore blend state 571 // Restore blend state
615 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 572 gGL.setSceneBlendType(LLRender::BT_ALPHA);
616 573
617 //---------------------------------------------------------------------------- 574 //----------------------------------------------------------------------------
618 // Restore Texture Unit 0 defaults 575 // Restore Texture Unit 0 defaults
619 576
620 glActiveTextureARB(GL_TEXTURE0_ARB); 577 gGL.getTexUnit(0)->activate();
621 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 578 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
622 glClientActiveTextureARB(GL_TEXTURE0_ARB); 579 glClientActiveTextureARB(GL_TEXTURE0_ARB);
623 glActiveTextureARB(GL_TEXTURE0_ARB); 580 gGL.getTexUnit(0)->activate();
581 glDisableClientState(GL_NORMAL_ARRAY);
582
624 glDisable(GL_TEXTURE_GEN_S); 583 glDisable(GL_TEXTURE_GEN_S);
625 glDisable(GL_TEXTURE_GEN_T); 584 glDisable(GL_TEXTURE_GEN_T);
626 glMatrixMode(GL_TEXTURE); 585 glMatrixMode(GL_TEXTURE);
627 glLoadIdentity(); 586 glLoadIdentity();
628 glMatrixMode(GL_MODELVIEW); 587 glMatrixMode(GL_MODELVIEW);
629 588
630 // Restore non Texture Unit specific defaults 589 gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
631 glDisableClientState(GL_NORMAL_ARRAY);
632 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
633} 590}
634 591
635void LLDrawPoolTerrain::renderFull2TU() 592void LLDrawPoolTerrain::renderFull2TU()
@@ -651,7 +608,7 @@ void LLDrawPoolTerrain::renderFull2TU()
651 tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x); 608 tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
652 tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y); 609 tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
653 610
654 gGL.blendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); 611 gGL.blendFunc(LLRender::BF_ONE_MINUS_SOURCE_ALPHA, LLRender::BF_SOURCE_ALPHA);
655 612
656 //---------------------------------------------------------------------------- 613 //----------------------------------------------------------------------------
657 // Pass 1/4 614 // Pass 1/4
@@ -668,13 +625,7 @@ void LLDrawPoolTerrain::renderFull2TU()
668 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 625 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
669 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 626 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
670 627
671 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 628 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_VERT_COLOR);
672 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
673
674 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
675 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
676 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
677 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
678 629
679 drawLoop(); 630 drawLoop();
680 631
@@ -690,22 +641,17 @@ void LLDrawPoolTerrain::renderFull2TU()
690 glDisable(GL_TEXTURE_GEN_T); 641 glDisable(GL_TEXTURE_GEN_T);
691 642
692 // Care about alpha only 643 // Care about alpha only
693 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 644 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR);
694 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); 645 gGL.getTexUnit(0)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_ALPHA);
695 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
696
697 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
698 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
699 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
700 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
701 646
702 647
703 // 648 //
704 // Stage 1: Write detail1 649 // Stage 1: Write detail1
705 // 650 //
706 LLViewerImage::bindTexture(detail_texture1p,1); // Texture unit 1 651 LLViewerImage::bindTexture(detail_texture1p,1); // Texture unit 1
707 glActiveTextureARB(GL_TEXTURE1_ARB); 652 gGL.getTexUnit(1)->activate();
708 glEnable(GL_TEXTURE_2D); // Texture unit 1 653 glEnable(GL_TEXTURE_2D); // Texture unit 1
654
709 glEnable(GL_TEXTURE_GEN_S); 655 glEnable(GL_TEXTURE_GEN_S);
710 glEnable(GL_TEXTURE_GEN_T); 656 glEnable(GL_TEXTURE_GEN_T);
711 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); 657 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
@@ -713,18 +659,10 @@ void LLDrawPoolTerrain::renderFull2TU()
713 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 659 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
714 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 660 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
715 661
716 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 662 gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_VERT_COLOR);
717 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); 663 gGL.getTexUnit(1)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_ALPHA);
718 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
719 664
720 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); 665 gGL.getTexUnit(0)->activate();
721 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
722 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
723 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
724 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
725 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
726
727 glActiveTextureARB(GL_TEXTURE0_ARB);
728 { 666 {
729 LLGLEnable blend(GL_BLEND); 667 LLGLEnable blend(GL_BLEND);
730 drawLoop(); 668 drawLoop();
@@ -736,26 +674,21 @@ void LLDrawPoolTerrain::renderFull2TU()
736 // Stage 0: Generate alpha ramp for detail1/detail2 transition 674 // Stage 0: Generate alpha ramp for detail1/detail2 transition
737 // 675 //
738 LLViewerImage::bindTexture(m2DAlphaRampImagep,0); 676 LLViewerImage::bindTexture(m2DAlphaRampImagep,0);
677
739 // Set the texture matrix 678 // Set the texture matrix
740 glMatrixMode(GL_TEXTURE); 679 glMatrixMode(GL_TEXTURE);
741 glLoadIdentity(); 680 glLoadIdentity();
742 glTranslatef(-1.f, 0.f, 0.f); 681 glTranslatef(-1.f, 0.f, 0.f);
743 682
744 // Care about alpha only 683 // Care about alpha only
745 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 684 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR);
746 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); 685 gGL.getTexUnit(0)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_ALPHA);
747 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
748
749 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
750 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
751 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
752 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
753 686
754 // 687 //
755 // Stage 1: Write detail2 688 // Stage 1: Write detail2
756 // 689 //
757
758 LLViewerImage::bindTexture(detail_texture2p,1); 690 LLViewerImage::bindTexture(detail_texture2p,1);
691 gGL.getTexUnit(1)->activate();
759 glEnable(GL_TEXTURE_2D); // Texture unit 1 692 glEnable(GL_TEXTURE_2D); // Texture unit 1
760 693
761 glEnable(GL_TEXTURE_GEN_S); 694 glEnable(GL_TEXTURE_GEN_S);
@@ -765,16 +698,8 @@ void LLDrawPoolTerrain::renderFull2TU()
765 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 698 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
766 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 699 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
767 700
768 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 701 gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_VERT_COLOR);
769 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); 702 gGL.getTexUnit(1)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_ALPHA);
770 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
771
772 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
773 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
774 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
775 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
776 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
777 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
778 703
779 { 704 {
780 LLGLEnable blend(GL_BLEND); 705 LLGLEnable blend(GL_BLEND);
@@ -787,27 +712,22 @@ void LLDrawPoolTerrain::renderFull2TU()
787 // 712 //
788 // Stage 0: Generate alpha ramp for detail2/detail3 transition 713 // Stage 0: Generate alpha ramp for detail2/detail3 transition
789 // 714 //
790 LLViewerImage::bindTexture(m2DAlphaRampImagep,0); 715 gGL.getTexUnit(0)->activate();
716 LLViewerImage::bindTexture(m2DAlphaRampImagep,0);
791 // Set the texture matrix 717 // Set the texture matrix
792 glMatrixMode(GL_TEXTURE); 718 glMatrixMode(GL_TEXTURE);
793 glLoadIdentity(); 719 glLoadIdentity();
794 glTranslatef(-2.f, 0.f, 0.f); 720 glTranslatef(-2.f, 0.f, 0.f);
795 721
796 // Care about alpha only 722 // Care about alpha only
797 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 723 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR);
798 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); 724 gGL.getTexUnit(0)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_TEX_ALPHA);
799 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
800
801 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
802 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
803 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
804 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
805 725
806 // Stage 1: Write detail3 726 // Stage 1: Write detail3
807
808 LLViewerImage::bindTexture(detail_texture3p,1); 727 LLViewerImage::bindTexture(detail_texture3p,1);
809 glActiveTextureARB(GL_TEXTURE1_ARB); 728 gGL.getTexUnit(1)->activate();
810 glEnable(GL_TEXTURE_2D); // Texture unit 1 729 glEnable(GL_TEXTURE_2D); // Texture unit 1
730
811 glEnable(GL_TEXTURE_GEN_S); 731 glEnable(GL_TEXTURE_GEN_S);
812 glEnable(GL_TEXTURE_GEN_T); 732 glEnable(GL_TEXTURE_GEN_T);
813 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); 733 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
@@ -815,30 +735,24 @@ void LLDrawPoolTerrain::renderFull2TU()
815 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 735 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
816 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 736 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
817 737
818 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 738 gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_VERT_COLOR);
819 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE); 739 gGL.getTexUnit(1)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_ALPHA);
820 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
821 740
822 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE); 741 gGL.getTexUnit(0)->activate();
823 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
824 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
825 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
826 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
827 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
828
829 glActiveTextureARB(GL_TEXTURE0_ARB);
830 { 742 {
831 LLGLEnable blend(GL_BLEND); 743 LLGLEnable blend(GL_BLEND);
832 drawLoop(); 744 drawLoop();
833 } 745 }
834 746
835 // Restore blend state 747 // Restore blend state
836 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 748 gGL.setSceneBlendType(LLRender::BT_ALPHA);
837 749
838 // Disable multitexture 750 // Disable multitexture
751
839 LLImageGL::unbindTexture(1, GL_TEXTURE_2D); 752 LLImageGL::unbindTexture(1, GL_TEXTURE_2D);
840 glActiveTextureARB(GL_TEXTURE1_ARB); 753 gGL.getTexUnit(1)->activate();
841 glDisable(GL_TEXTURE_2D); // Texture unit 1 754 glDisable(GL_TEXTURE_2D); // Texture unit 1
755
842 glDisable(GL_TEXTURE_GEN_S); 756 glDisable(GL_TEXTURE_GEN_S);
843 glDisable(GL_TEXTURE_GEN_T); 757 glDisable(GL_TEXTURE_GEN_T);
844 glMatrixMode(GL_TEXTURE); 758 glMatrixMode(GL_TEXTURE);
@@ -848,18 +762,16 @@ void LLDrawPoolTerrain::renderFull2TU()
848 //---------------------------------------------------------------------------- 762 //----------------------------------------------------------------------------
849 // Restore Texture Unit 0 defaults 763 // Restore Texture Unit 0 defaults
850 764
851 glActiveTextureARB(GL_TEXTURE0_ARB); 765 gGL.getTexUnit(0)->activate();
852 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 766 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
853 767
854 glActiveTextureARB(GL_TEXTURE0_ARB); 768 gGL.getTexUnit(0)->activate();
855 glDisable(GL_TEXTURE_GEN_S); 769 glDisable(GL_TEXTURE_GEN_S);
856 glDisable(GL_TEXTURE_GEN_T); 770 glDisable(GL_TEXTURE_GEN_T);
857 glMatrixMode(GL_TEXTURE); 771 glMatrixMode(GL_TEXTURE);
858 glLoadIdentity(); 772 glLoadIdentity();
859 glMatrixMode(GL_MODELVIEW); 773 glMatrixMode(GL_MODELVIEW);
860 774 gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
861 // Restore non Texture Unit specific defaults
862 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
863} 775}
864 776
865 777
@@ -874,7 +786,7 @@ void LLDrawPoolTerrain::renderSimple()
874 mTexturep->addTextureStats(1024.f*1024.f); 786 mTexturep->addTextureStats(1024.f*1024.f);
875 mTexturep->bind(0); 787 mTexturep->bind(0);
876 788
877 glActiveTextureARB(GL_TEXTURE0_ARB); 789 gGL.getTexUnit(0)->activate();
878 glEnable(GL_TEXTURE_2D); // Texture unit 2 790 glEnable(GL_TEXTURE_2D); // Texture unit 2
879 791
880 LLVector3 origin_agent = mDrawFace[0]->getDrawable()->getVObj()->getRegion()->getOriginAgent(); 792 LLVector3 origin_agent = mDrawFace[0]->getDrawable()->getVObj()->getRegion()->getOriginAgent();
@@ -889,13 +801,7 @@ void LLDrawPoolTerrain::renderSimple()
889 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); 801 glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
890 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); 802 glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
891 803
892 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 804 gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_VERT_COLOR);
893 glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
894
895 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
896 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
897 glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
898 glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
899 805
900 drawLoop(); 806 drawLoop();
901 807
@@ -903,15 +809,13 @@ void LLDrawPoolTerrain::renderSimple()
903 // Restore Texture Unit 0 defaults 809 // Restore Texture Unit 0 defaults
904 810
905 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 811 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
906 glActiveTextureARB(GL_TEXTURE0_ARB); 812 gGL.getTexUnit(0)->activate();
907 glDisable(GL_TEXTURE_GEN_S); 813 glDisable(GL_TEXTURE_GEN_S);
908 glDisable(GL_TEXTURE_GEN_T); 814 glDisable(GL_TEXTURE_GEN_T);
909 glMatrixMode(GL_TEXTURE); 815 glMatrixMode(GL_TEXTURE);
910 glLoadIdentity(); 816 glLoadIdentity();
911 glMatrixMode(GL_MODELVIEW); 817 glMatrixMode(GL_MODELVIEW);
912 818 gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
913 // Restore non Texture Unit specific defaults
914 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
915} 819}
916 820
917//============================================================================ 821//============================================================================