diff options
Diffstat (limited to 'linden/indra/newview/lldrawpoolwater.cpp')
-rw-r--r-- | linden/indra/newview/lldrawpoolwater.cpp | 114 |
1 files changed, 54 insertions, 60 deletions
diff --git a/linden/indra/newview/lldrawpoolwater.cpp b/linden/indra/newview/lldrawpoolwater.cpp index e3802a1..cd2a615 100644 --- a/linden/indra/newview/lldrawpoolwater.cpp +++ b/linden/indra/newview/lldrawpoolwater.cpp | |||
@@ -35,7 +35,6 @@ | |||
35 | #include "m3math.h" | 35 | #include "m3math.h" |
36 | 36 | ||
37 | #include "llagent.h" // for gAgent for getRegion for getWaterHeight | 37 | #include "llagent.h" // for gAgent for getRegion for getWaterHeight |
38 | #include "llagparray.h" | ||
39 | #include "llcubemap.h" | 38 | #include "llcubemap.h" |
40 | #include "lldrawable.h" | 39 | #include "lldrawable.h" |
41 | #include "llface.h" | 40 | #include "llface.h" |
@@ -63,11 +62,11 @@ int nhpo2(int v) | |||
63 | } | 62 | } |
64 | 63 | ||
65 | static GLuint sScreenTex = 0; | 64 | static GLuint sScreenTex = 0; |
65 | BOOL LLDrawPoolWater::sSkipScreenCopy = FALSE; | ||
66 | 66 | ||
67 | LLDrawPoolWater::LLDrawPoolWater() : | 67 | LLDrawPoolWater::LLDrawPoolWater() : |
68 | LLDrawPool(POOL_WATER, DATA_SIMPLE_IL_MASK, DATA_SIMPLE_NIL_MASK) | 68 | LLFacePool(POOL_WATER) |
69 | { | 69 | { |
70 | mCleanupUnused = TRUE; | ||
71 | mHBTex[0] = gImageList.getImage(gSunTextureID, TRUE, TRUE); | 70 | mHBTex[0] = gImageList.getImage(gSunTextureID, TRUE, TRUE); |
72 | mHBTex[0]->bind(); | 71 | mHBTex[0]->bind(); |
73 | mHBTex[0]->setClamp(TRUE, TRUE); | 72 | mHBTex[0]->setClamp(TRUE, TRUE); |
@@ -135,11 +134,21 @@ extern LLColor4U MAX_WATER_COLOR; | |||
135 | void LLDrawPoolWater::render(S32 pass) | 134 | void LLDrawPoolWater::render(S32 pass) |
136 | { | 135 | { |
137 | LLFastTimer ftm(LLFastTimer::FTM_RENDER_WATER); | 136 | LLFastTimer ftm(LLFastTimer::FTM_RENDER_WATER); |
138 | if (mDrawFace.empty()) | 137 | if (mDrawFace.empty() || LLDrawable::getCurrentFrame() <= 1) |
139 | { | 138 | { |
140 | return; | 139 | return; |
141 | } | 140 | } |
142 | 141 | ||
142 | //do a quick 'n dirty depth sort | ||
143 | for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); | ||
144 | iter != mDrawFace.end(); iter++) | ||
145 | { | ||
146 | LLFace* facep = *iter; | ||
147 | facep->mDistance = -facep->mCenterLocal.mV[2]; | ||
148 | } | ||
149 | |||
150 | std::sort(mDrawFace.begin(), mDrawFace.end(), LLFace::CompareDistanceGreater()); | ||
151 | |||
143 | LLGLSPipelineAlpha alphaState; | 152 | LLGLSPipelineAlpha alphaState; |
144 | 153 | ||
145 | if ((mVertexShaderLevel >= SHADER_LEVEL_RIPPLE)) | 154 | if ((mVertexShaderLevel >= SHADER_LEVEL_RIPPLE)) |
@@ -164,7 +173,7 @@ void LLDrawPoolWater::render(S32 pass) | |||
164 | return; | 173 | return; |
165 | } | 174 | } |
166 | 175 | ||
167 | const LLFace* refl_face = voskyp->getReflFace(); | 176 | LLFace* refl_face = voskyp->getReflFace(); |
168 | 177 | ||
169 | gPipeline.disableLights(); | 178 | gPipeline.disableLights(); |
170 | 179 | ||
@@ -176,10 +185,6 @@ void LLDrawPoolWater::render(S32 pass) | |||
176 | glEnableClientState(GL_VERTEX_ARRAY); | 185 | glEnableClientState(GL_VERTEX_ARRAY); |
177 | glEnableClientState(GL_NORMAL_ARRAY); | 186 | glEnableClientState(GL_NORMAL_ARRAY); |
178 | 187 | ||
179 | bindGLVertexPointer(); | ||
180 | bindGLNormalPointer(); | ||
181 | bindGLTexCoordPointer(); | ||
182 | |||
183 | // Set up second pass first | 188 | // Set up second pass first |
184 | glActiveTextureARB(GL_TEXTURE1_ARB); | 189 | glActiveTextureARB(GL_TEXTURE1_ARB); |
185 | mWaterImagep->addTextureStats(1024.f*1024.f); | 190 | mWaterImagep->addTextureStats(1024.f*1024.f); |
@@ -246,7 +251,7 @@ void LLDrawPoolWater::render(S32 pass) | |||
246 | continue; | 251 | continue; |
247 | } | 252 | } |
248 | face->bindTexture(); | 253 | face->bindTexture(); |
249 | face->renderIndexed(getRawIndices()); | 254 | face->renderIndexed(); |
250 | mIndicesDrawn += face->getIndicesCount(); | 255 | mIndicesDrawn += face->getIndicesCount(); |
251 | } | 256 | } |
252 | 257 | ||
@@ -307,7 +312,7 @@ void LLDrawPoolWater::render(S32 pass) | |||
307 | 312 | ||
308 | if (face->getGeomCount() > 0) | 313 | if (face->getGeomCount() > 0) |
309 | { | 314 | { |
310 | face->renderIndexed(getRawIndices()); | 315 | face->renderIndexed(); |
311 | mIndicesDrawn += face->getIndicesCount(); | 316 | mIndicesDrawn += face->getIndicesCount(); |
312 | } | 317 | } |
313 | } | 318 | } |
@@ -354,7 +359,7 @@ void LLDrawPoolWater::renderShaderSimple() | |||
354 | return; | 359 | return; |
355 | } | 360 | } |
356 | 361 | ||
357 | const LLFace* refl_face = voskyp->getReflFace(); | 362 | LLFace* refl_face = voskyp->getReflFace(); |
358 | 363 | ||
359 | LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); | 364 | LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); |
360 | 365 | ||
@@ -364,10 +369,6 @@ void LLDrawPoolWater::renderShaderSimple() | |||
364 | glEnableClientState(GL_VERTEX_ARRAY); | 369 | glEnableClientState(GL_VERTEX_ARRAY); |
365 | glEnableClientState(GL_NORMAL_ARRAY); | 370 | glEnableClientState(GL_NORMAL_ARRAY); |
366 | 371 | ||
367 | bindGLVertexPointer(); | ||
368 | bindGLNormalPointer(); | ||
369 | bindGLTexCoordPointer(); | ||
370 | |||
371 | // Set up second pass first | 372 | // Set up second pass first |
372 | S32 bumpTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_BUMP_MAP); | 373 | S32 bumpTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_BUMP_MAP); |
373 | mWaterImagep->addTextureStats(1024.f*1024.f); | 374 | mWaterImagep->addTextureStats(1024.f*1024.f); |
@@ -432,9 +433,6 @@ void LLDrawPoolWater::renderShaderSimple() | |||
432 | glMatrixMode(GL_MODELVIEW); | 433 | glMatrixMode(GL_MODELVIEW); |
433 | } | 434 | } |
434 | 435 | ||
435 | S32 scatterTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_SCATTER_MAP); | ||
436 | LLViewerImage::bindTexture(gSky.mVOSkyp->getScatterMap(), scatterTex); | ||
437 | |||
438 | S32 diffTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_DIFFUSE_MAP); | 436 | S32 diffTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_DIFFUSE_MAP); |
439 | 437 | ||
440 | gPipeline.mWaterProgram.bind(); | 438 | gPipeline.mWaterProgram.bind(); |
@@ -448,7 +446,7 @@ void LLDrawPoolWater::renderShaderSimple() | |||
448 | continue; | 446 | continue; |
449 | } | 447 | } |
450 | face->bindTexture(diffTex); | 448 | face->bindTexture(diffTex); |
451 | face->renderIndexed(getRawIndices()); | 449 | face->renderIndexed(); |
452 | mIndicesDrawn += face->getIndicesCount(); | 450 | mIndicesDrawn += face->getIndicesCount(); |
453 | } | 451 | } |
454 | 452 | ||
@@ -469,8 +467,7 @@ void LLDrawPoolWater::renderShaderSimple() | |||
469 | glDisable(GL_TEXTURE_GEN_T); //texture unit 1 | 467 | glDisable(GL_TEXTURE_GEN_T); //texture unit 1 |
470 | 468 | ||
471 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_DIFFUSE_MAP); | 469 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_DIFFUSE_MAP); |
472 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_SCATTER_MAP); | 470 | |
473 | |||
474 | // Disable texture coordinate and color arrays | 471 | // Disable texture coordinate and color arrays |
475 | LLImageGL::unbindTexture(diffTex, GL_TEXTURE_2D); | 472 | LLImageGL::unbindTexture(diffTex, GL_TEXTURE_2D); |
476 | 473 | ||
@@ -496,7 +493,7 @@ void LLDrawPoolWater::renderShaderSimple() | |||
496 | glDisableClientState(GL_NORMAL_ARRAY); | 493 | glDisableClientState(GL_NORMAL_ARRAY); |
497 | } | 494 | } |
498 | 495 | ||
499 | void LLDrawPoolWater::renderReflection(const LLFace* face) | 496 | void LLDrawPoolWater::renderReflection(LLFace* face) |
500 | { | 497 | { |
501 | LLVOSky *voskyp = gSky.mVOSkyp; | 498 | LLVOSky *voskyp = gSky.mVOSkyp; |
502 | 499 | ||
@@ -524,7 +521,7 @@ void LLDrawPoolWater::renderReflection(const LLFace* face) | |||
524 | LLViewerImage::bindTexture(mHBTex[dr]); | 521 | LLViewerImage::bindTexture(mHBTex[dr]); |
525 | 522 | ||
526 | LLOverrideFaceColor override(this, face->getFaceColor().mV); | 523 | LLOverrideFaceColor override(this, face->getFaceColor().mV); |
527 | face->renderIndexed(getRawIndices()); | 524 | face->renderIndexed(); |
528 | mIndicesDrawn += face->getIndicesCount(); | 525 | mIndicesDrawn += face->getIndicesCount(); |
529 | 526 | ||
530 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 527 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
@@ -532,36 +529,44 @@ void LLDrawPoolWater::renderReflection(const LLFace* face) | |||
532 | 529 | ||
533 | void bindScreenToTexture() | 530 | void bindScreenToTexture() |
534 | { | 531 | { |
535 | GLint viewport[4]; | 532 | if (LLDrawPoolWater::sSkipScreenCopy) |
536 | glGetIntegerv(GL_VIEWPORT, viewport); | ||
537 | GLuint resX = nhpo2(viewport[2]); | ||
538 | GLuint resY = nhpo2(viewport[3]); | ||
539 | |||
540 | glBindTexture(GL_TEXTURE_2D, sScreenTex); | ||
541 | GLint cResX; | ||
542 | GLint cResY; | ||
543 | glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &cResX); | ||
544 | glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &cResY); | ||
545 | |||
546 | if (cResX != (GLint)resX || cResY != (GLint)resY) | ||
547 | { | 533 | { |
548 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, resX, resY, 0, GL_RGB, GL_FLOAT, NULL); | 534 | glBindTexture(GL_TEXTURE_2D, 0); |
549 | gImageList.updateMaxResidentTexMem(-1, resX*resY*3); | ||
550 | } | 535 | } |
536 | else | ||
537 | { | ||
551 | 538 | ||
552 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, viewport[0], viewport[1], 0, 0, viewport[2], viewport[3]); | 539 | GLint viewport[4]; |
540 | glGetIntegerv(GL_VIEWPORT, viewport); | ||
541 | GLuint resX = nhpo2(viewport[2]); | ||
542 | GLuint resY = nhpo2(viewport[3]); | ||
553 | 543 | ||
554 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 544 | glBindTexture(GL_TEXTURE_2D, sScreenTex); |
555 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 545 | GLint cResX; |
556 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 546 | GLint cResY; |
557 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 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 | } | ||
558 | 555 | ||
559 | float scale[2]; | 556 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, viewport[0], viewport[1], 0, 0, viewport[2], viewport[3]); |
560 | scale[0] = (float) viewport[2]/resX; | ||
561 | scale[1] = (float) viewport[3]/resY; | ||
562 | glUniform2fvARB(gPipeline.mWaterProgram.mUniform[LLPipeline::GLSL_WATER_FBSCALE], 1, scale); | ||
563 | 557 | ||
564 | LLImageGL::sBoundTextureMemory += resX * resY * 3; | 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 | } | ||
565 | } | 570 | } |
566 | 571 | ||
567 | void LLDrawPoolWater::shade() | 572 | void LLDrawPoolWater::shade() |
@@ -596,9 +601,6 @@ void LLDrawPoolWater::shade() | |||
596 | glEnableClientState(GL_VERTEX_ARRAY); | 601 | glEnableClientState(GL_VERTEX_ARRAY); |
597 | glEnableClientState(GL_NORMAL_ARRAY); | 602 | glEnableClientState(GL_NORMAL_ARRAY); |
598 | LLGLDisable blend(GL_BLEND); | 603 | LLGLDisable blend(GL_BLEND); |
599 | bindGLVertexPointer(); | ||
600 | bindGLNormalPointer(); | ||
601 | bindGLTexCoordPointer(); | ||
602 | 604 | ||
603 | LLColor3 light_diffuse(0,0,0); | 605 | LLColor3 light_diffuse(0,0,0); |
604 | F32 light_exp = 0.0f; | 606 | F32 light_exp = 0.0f; |
@@ -649,9 +651,6 @@ void LLDrawPoolWater::shade() | |||
649 | 651 | ||
650 | bindScreenToTexture(); | 652 | bindScreenToTexture(); |
651 | 653 | ||
652 | S32 scatterTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_SCATTER_MAP); | ||
653 | LLViewerImage::bindTexture(gSky.mVOSkyp->getScatterMap(), scatterTex); | ||
654 | |||
655 | S32 diffTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_DIFFUSE_MAP); | 654 | S32 diffTex = gPipeline.mWaterProgram.enableTexture(LLPipeline::GLSL_DIFFUSE_MAP); |
656 | 655 | ||
657 | LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); | 656 | LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); |
@@ -697,7 +696,7 @@ void LLDrawPoolWater::shade() | |||
697 | } | 696 | } |
698 | 697 | ||
699 | face->bindTexture(diffTex); | 698 | face->bindTexture(diffTex); |
700 | face->renderIndexed(getRawIndices()); | 699 | face->renderIndexed(); |
701 | mIndicesDrawn += face->getIndicesCount(); | 700 | mIndicesDrawn += face->getIndicesCount(); |
702 | } | 701 | } |
703 | } | 702 | } |
@@ -705,7 +704,6 @@ void LLDrawPoolWater::shade() | |||
705 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); | 704 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB); |
706 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_WATER_SCREENTEX); | 705 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_WATER_SCREENTEX); |
707 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_BUMP_MAP); | 706 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_BUMP_MAP); |
708 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_SCATTER_MAP); | ||
709 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_DIFFUSE_MAP); | 707 | gPipeline.mWaterProgram.disableTexture(LLPipeline::GLSL_DIFFUSE_MAP); |
710 | 708 | ||
711 | glActiveTextureARB(GL_TEXTURE0_ARB); | 709 | glActiveTextureARB(GL_TEXTURE0_ARB); |
@@ -714,10 +712,6 @@ void LLDrawPoolWater::shade() | |||
714 | 712 | ||
715 | glClientActiveTextureARB(GL_TEXTURE0_ARB); | 713 | glClientActiveTextureARB(GL_TEXTURE0_ARB); |
716 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 714 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
717 | |||
718 | /*glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||
719 | glDisableClientState(GL_VERTEX_ARRAY); | ||
720 | glDisableClientState(GL_NORMAL_ARRAY);*/ | ||
721 | } | 715 | } |
722 | 716 | ||
723 | void LLDrawPoolWater::renderForSelect() | 717 | void LLDrawPoolWater::renderForSelect() |