aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldrawpoolwater.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/lldrawpoolwater.cpp')
-rw-r--r--linden/indra/newview/lldrawpoolwater.cpp152
1 files changed, 45 insertions, 107 deletions
diff --git a/linden/indra/newview/lldrawpoolwater.cpp b/linden/indra/newview/lldrawpoolwater.cpp
index cd2a615..343f14c 100644
--- a/linden/indra/newview/lldrawpoolwater.cpp
+++ b/linden/indra/newview/lldrawpoolwater.cpp
@@ -4,6 +4,7 @@
4 * 4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc. 5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 * 6 *
7 * Second Life Viewer Source Code
7 * The source code in this file ("Source Code") is provided by Linden Lab 8 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0 9 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement 10 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -47,21 +48,12 @@
47#include "llworld.h" 48#include "llworld.h"
48#include "pipeline.h" 49#include "pipeline.h"
49#include "viewer.h" // gSunTextureID, gMoonTextureID 50#include "viewer.h" // gSunTextureID, gMoonTextureID
51#include "llglslshader.h"
50 52
51const LLUUID WATER_TEST("2bfd3884-7e27-69b9-ba3a-3e673f680004"); 53const LLUUID WATER_TEST("2bfd3884-7e27-69b9-ba3a-3e673f680004");
52 54
53static float sTime; 55static float sTime;
54 56
55int nhpo2(int v)
56{
57 int r = 1;
58 while (r < v) {
59 r *= 2;
60 }
61 return r;
62}
63
64static GLuint sScreenTex = 0;
65BOOL LLDrawPoolWater::sSkipScreenCopy = FALSE; 57BOOL LLDrawPoolWater::sSkipScreenCopy = FALSE;
66 58
67LLDrawPoolWater::LLDrawPoolWater() : 59LLDrawPoolWater::LLDrawPoolWater() :
@@ -88,30 +80,9 @@ LLDrawPoolWater::~LLDrawPoolWater()
88//static 80//static
89void LLDrawPoolWater::restoreGL() 81void LLDrawPoolWater::restoreGL()
90{ 82{
91 if (gPipeline.getVertexShaderLevel(LLPipeline::SHADER_ENVIRONMENT) >= SHADER_LEVEL_RIPPLE) 83
92 {
93 //build screen texture
94 glClientActiveTextureARB(GL_TEXTURE0_ARB);
95 glActiveTextureARB(GL_TEXTURE0_ARB);
96 glGenTextures(1, &sScreenTex);
97 LLGLEnable gl_texture_2d(GL_TEXTURE_2D);
98 glBindTexture(GL_TEXTURE_2D, sScreenTex);
99 GLint viewport[4];
100 glGetIntegerv(GL_VIEWPORT, viewport);
101 GLuint resX = nhpo2(viewport[2]);
102 GLuint resY = nhpo2(viewport[3]);
103
104 gImageList.updateMaxResidentTexMem(-1, resX*resY*3);
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, resX, resY, 0, GL_RGB, GL_FLOAT, NULL);
106
107 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
108 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
109 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
110 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
111 }
112} 84}
113 85
114
115LLDrawPool *LLDrawPoolWater::instancePool() 86LLDrawPool *LLDrawPoolWater::instancePool()
116{ 87{
117 llerrs << "Should never be calling instancePool on a water pool!" << llendl; 88 llerrs << "Should never be calling instancePool on a water pool!" << llendl;
@@ -121,12 +92,9 @@ LLDrawPool *LLDrawPoolWater::instancePool()
121 92
122void LLDrawPoolWater::prerender() 93void LLDrawPoolWater::prerender()
123{ 94{
124#if 1 // 1.9.1
125 mVertexShaderLevel = gSavedSettings.getBOOL("RenderRippleWater") ? 95 mVertexShaderLevel = gSavedSettings.getBOOL("RenderRippleWater") ?
126 gPipeline.getVertexShaderLevel(LLPipeline::SHADER_ENVIRONMENT) : 0; 96 LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_ENVIRONMENT) : 0;
127#else 97
128 mVertexShaderLevel = gPipeline.getVertexShaderLevel(LLPipeline::SHADER_ENVIRONMENT);
129#endif
130} 98}
131 99
132extern LLColor4U MAX_WATER_COLOR; 100extern LLColor4U MAX_WATER_COLOR;
@@ -149,7 +117,7 @@ void LLDrawPoolWater::render(S32 pass)
149 117
150 std::sort(mDrawFace.begin(), mDrawFace.end(), LLFace::CompareDistanceGreater()); 118 std::sort(mDrawFace.begin(), mDrawFace.end(), LLFace::CompareDistanceGreater());
151 119
152 LLGLSPipelineAlpha alphaState; 120 LLGLEnable blend(GL_BLEND);
153 121
154 if ((mVertexShaderLevel >= SHADER_LEVEL_RIPPLE)) 122 if ((mVertexShaderLevel >= SHADER_LEVEL_RIPPLE))
155 { 123 {
@@ -343,7 +311,6 @@ void LLDrawPoolWater::render(S32 pass)
343 glDisableClientState(GL_NORMAL_ARRAY); 311 glDisableClientState(GL_NORMAL_ARRAY);
344 312
345 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 313 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
346
347} 314}
348 315
349 316
@@ -370,7 +337,7 @@ void LLDrawPoolWater::renderShaderSimple()
370 glEnableClientState(GL_NORMAL_ARRAY); 337 glEnableClientState(GL_NORMAL_ARRAY);
371 338
372 // Set up second pass first 339 // Set up second pass first
373 S32 bumpTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_BUMP_MAP); 340 S32 bumpTex = gWaterProgram.enableTexture(LLShaderMgr::BUMP_MAP);
374 mWaterImagep->addTextureStats(1024.f*1024.f); 341 mWaterImagep->addTextureStats(1024.f*1024.f);
375 mWaterImagep->bind(bumpTex); 342 mWaterImagep->bind(bumpTex);
376 343
@@ -419,7 +386,7 @@ void LLDrawPoolWater::renderShaderSimple()
419 386
420 if (gSky.mVOSkyp->getCubeMap()) 387 if (gSky.mVOSkyp->getCubeMap())
421 { 388 {
422 envTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); 389 envTex = gWaterProgram.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB);
423 gSky.mVOSkyp->getCubeMap()->bind(); 390 gSky.mVOSkyp->getCubeMap()->bind();
424 391
425 glMatrixMode(GL_TEXTURE); 392 glMatrixMode(GL_TEXTURE);
@@ -433,9 +400,9 @@ void LLDrawPoolWater::renderShaderSimple()
433 glMatrixMode(GL_MODELVIEW); 400 glMatrixMode(GL_MODELVIEW);
434 } 401 }
435 402
436 S32 diffTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_DIFFUSE_MAP); 403 S32 diffTex = gWaterProgram.enableTexture(LLShaderMgr::DIFFUSE_MAP);
437 404
438 gPipeline.mWaterProgram.bind(); 405 gWaterProgram.bind();
439 406
440 for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); 407 for (std::vector<LLFace*>::iterator iter = mDrawFace.begin();
441 iter != mDrawFace.end(); iter++) 408 iter != mDrawFace.end(); iter++)
@@ -452,21 +419,21 @@ void LLDrawPoolWater::renderShaderSimple()
452 419
453 if (gSky.mVOSkyp->getCubeMap()) 420 if (gSky.mVOSkyp->getCubeMap())
454 { 421 {
455 gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); 422 gWaterProgram.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB);
456 glMatrixMode(GL_TEXTURE); 423 glMatrixMode(GL_TEXTURE);
457 glLoadIdentity(); 424 glLoadIdentity();
458 glMatrixMode(GL_MODELVIEW); 425 glMatrixMode(GL_MODELVIEW);
459 } 426 }
460 427
461 // Now, disable texture coord generation on texture state 1 428 // Now, disable texture coord generation on texture state 1
462 gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_BUMP_MAP); 429 gWaterProgram.disableTexture(LLShaderMgr::BUMP_MAP);
463 LLImageGL::unbindTexture(bumpTex, GL_TEXTURE_2D); 430 LLImageGL::unbindTexture(bumpTex, GL_TEXTURE_2D);
464 431
465 glActiveTextureARB(GL_TEXTURE1_ARB); 432 glActiveTextureARB(GL_TEXTURE1_ARB);
466 glDisable(GL_TEXTURE_GEN_S); //texture unit 1 433 glDisable(GL_TEXTURE_GEN_S); //texture unit 1
467 glDisable(GL_TEXTURE_GEN_T); //texture unit 1 434 glDisable(GL_TEXTURE_GEN_T); //texture unit 1
468 435
469 gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_DIFFUSE_MAP); 436 gWaterProgram.disableTexture(LLShaderMgr::DIFFUSE_MAP);
470 437
471 // Disable texture coordinate and color arrays 438 // Disable texture coordinate and color arrays
472 LLImageGL::unbindTexture(diffTex, GL_TEXTURE_2D); 439 LLImageGL::unbindTexture(diffTex, GL_TEXTURE_2D);
@@ -527,50 +494,10 @@ void LLDrawPoolWater::renderReflection(LLFace* face)
527 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 494 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
528} 495}
529 496
530void bindScreenToTexture()
531{
532 if (LLDrawPoolWater::sSkipScreenCopy)
533 {
534 glBindTexture(GL_TEXTURE_2D, 0);
535 }
536 else
537 {
538
539 GLint viewport[4];
540 glGetIntegerv(GL_VIEWPORT, viewport);
541 GLuint resX = nhpo2(viewport[2]);
542 GLuint resY = nhpo2(viewport[3]);
543
544 glBindTexture(GL_TEXTURE_2D, sScreenTex);
545 GLint cResX;
546 GLint cResY;
547 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &cResX);
548 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &cResY);
549
550 if (cResX != (GLint)resX || cResY != (GLint)resY)
551 {
552 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, resX, resY, 0, GL_RGB, GL_FLOAT, NULL);
553 gImageList.updateMaxResidentTexMem(-1, resX*resY*3);
554 }
555
556 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, viewport[0], viewport[1], 0, 0, viewport[2], viewport[3]);
557
558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
562
563 float scale[2];
564 scale[0] = (float) viewport[2]/resX;
565 scale[1] = (float) viewport[3]/resY;
566 glUniform2fvARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_FBSCALE], 1, scale);
567
568 LLImageGL::sBoundTextureMemory += resX * resY * 3;
569 }
570}
571
572void LLDrawPoolWater::shade() 497void LLDrawPoolWater::shade()
573{ 498{
499 glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
500
574 static LLVector2 d1( 0.5f, -0.17f ); 501 static LLVector2 d1( 0.5f, -0.17f );
575 static LLVector2 d2( 0.58f, -0.67f ); 502 static LLVector2 d2( 0.58f, -0.67f );
576 static LLVector2 d3( 0.5f, 0.25f ); 503 static LLVector2 d3( 0.5f, 0.25f );
@@ -637,31 +564,41 @@ void LLDrawPoolWater::shade()
637 564
638 LLCubeMap* skyMap = gSky.mVOSkyp->getCubeMap(); 565 LLCubeMap* skyMap = gSky.mVOSkyp->getCubeMap();
639 566
640 gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); 567 gWaterProgram.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB);
641 skyMap->bind(); 568 skyMap->bind();
642 569
643 //bind normal map 570 //bind normal map
644 S32 bumpTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_BUMP_MAP); 571 S32 bumpTex = gWaterProgram.enableTexture(LLShaderMgr::BUMP_MAP);
645 mWaterNormp->addTextureStats(1024.f*1024.f); 572 mWaterNormp->addTextureStats(1024.f*1024.f);
646 mWaterNormp->bind(bumpTex); 573 mWaterNormp->bind(bumpTex);
647 574
648 gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_WATER_SCREENTEX); 575 gWaterProgram.enableTexture(LLShaderMgr::WATER_SCREENTEX);
649 576
650 gPipeline.mWaterProgram.bind(); 577 gWaterProgram.bind();
651 578
652 bindScreenToTexture(); 579 if (!sSkipScreenCopy)
580 {
581 gPipeline.bindScreenToTexture();
582 }
583 else
584 {
585 glBindTexture(GL_TEXTURE_2D, 0);
586 }
653 587
654 S32 diffTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_DIFFUSE_MAP); 588 glUniform2fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_FBSCALE], 1,
589 gPipeline.mScreenScale.mV);
590
591 S32 diffTex = gWaterProgram.enableTexture(LLShaderMgr::DIFFUSE_MAP);
655 592
656 LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); 593 LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
657 594
658 glUniform1fARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_TIME], sTime); 595 glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_TIME], sTime);
659 glUniform3fvARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_SPECULAR], 1, light_diffuse.mV); 596 glUniform3fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_SPECULAR], 1, light_diffuse.mV);
660 glUniform1fARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_SPECULAR_EXP], light_exp); 597 glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_SPECULAR_EXP], light_exp);
661 glUniform3fvARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_EYEVEC], 1, gCamera->getOrigin().mV); 598 glUniform3fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_EYEVEC], 1, gCamera->getOrigin().mV);
662 glUniform2fvARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_WAVE_DIR1], 1, d1.mV); 599 glUniform2fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_WAVE_DIR1], 1, d1.mV);
663 glUniform2fvARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_WAVE_DIR2], 1, d2.mV); 600 glUniform2fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_WAVE_DIR2], 1, d2.mV);
664 glUniform3fvARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_LIGHT_DIR], 1, light_dir.mV); 601 glUniform3fvARB(gWaterProgram.mUniform[LLShaderMgr::WATER_LIGHT_DIR], 1, light_dir.mV);
665 602
666 LLColor4 water_color; 603 LLColor4 water_color;
667 LLVector3 camera_up = gCamera->getUpAxis(); 604 LLVector3 camera_up = gCamera->getUpAxis();
@@ -669,12 +606,12 @@ void LLDrawPoolWater::shade()
669 if (gCamera->cameraUnderWater()) 606 if (gCamera->cameraUnderWater())
670 { 607 {
671 water_color.setVec(1.f, 1.f, 1.f, 0.4f); 608 water_color.setVec(1.f, 1.f, 1.f, 0.4f);
672 glUniform1fARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_REFSCALE], 0.25f); 609 glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_REFSCALE], 0.25f);
673 } 610 }
674 else 611 else
675 { 612 {
676 water_color.setVec(1.f, 1.f, 1.f, 0.5f*(1.f + up_dot)); 613 water_color.setVec(1.f, 1.f, 1.f, 0.5f*(1.f + up_dot));
677 glUniform1fARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_REFSCALE], 0.01f); 614 glUniform1fARB(gWaterProgram.mUniform[LLShaderMgr::WATER_REFSCALE], 0.01f);
678 } 615 }
679 if (water_color.mV[3] > 0.9f) 616 if (water_color.mV[3] > 0.9f)
680 { 617 {
@@ -701,10 +638,10 @@ void LLDrawPoolWater::shade()
701 } 638 }
702 } 639 }
703 640
704 gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); 641 gWaterProgram.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB);
705 gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_WATER_SCREENTEX); 642 gWaterProgram.disableTexture(LLShaderMgr::WATER_SCREENTEX);
706 gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_BUMP_MAP); 643 gWaterProgram.disableTexture(LLShaderMgr::BUMP_MAP);
707 gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_DIFFUSE_MAP); 644 gWaterProgram.disableTexture(LLShaderMgr::DIFFUSE_MAP);
708 645
709 glActiveTextureARB(GL_TEXTURE0_ARB); 646 glActiveTextureARB(GL_TEXTURE0_ARB);
710 glEnable(GL_TEXTURE_2D); 647 glEnable(GL_TEXTURE_2D);
@@ -712,6 +649,7 @@ void LLDrawPoolWater::shade()
712 649
713 glClientActiveTextureARB(GL_TEXTURE0_ARB); 650 glClientActiveTextureARB(GL_TEXTURE0_ARB);
714 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 651 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
652 glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_FALSE);
715} 653}
716 654
717void LLDrawPoolWater::renderForSelect() 655void LLDrawPoolWater::renderForSelect()