aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lldrawpoolbump.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/lldrawpoolbump.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/lldrawpoolbump.cpp')
-rw-r--r--linden/indra/newview/lldrawpoolbump.cpp530
1 files changed, 395 insertions, 135 deletions
diff --git a/linden/indra/newview/lldrawpoolbump.cpp b/linden/indra/newview/lldrawpoolbump.cpp
index 51a7749..987e65e 100644
--- a/linden/indra/newview/lldrawpoolbump.cpp
+++ b/linden/indra/newview/lldrawpoolbump.cpp
@@ -40,17 +40,19 @@
40#include "m3math.h" 40#include "m3math.h"
41#include "m4math.h" 41#include "m4math.h"
42#include "v4math.h" 42#include "v4math.h"
43#include "llglheaders.h"
44#include "llglimmediate.h"
43 45
44#include "llagent.h" 46#include "llagent.h"
45#include "llcubemap.h" 47#include "llcubemap.h"
46#include "lldrawable.h" 48#include "lldrawable.h"
47#include "lldrawpoolsimple.h"
48#include "llface.h" 49#include "llface.h"
49#include "llsky.h" 50#include "llsky.h"
50#include "lltextureentry.h" 51#include "lltextureentry.h"
51#include "llviewercamera.h" 52#include "llviewercamera.h"
52#include "llviewerimagelist.h" 53#include "llviewerimagelist.h"
53#include "pipeline.h" 54#include "pipeline.h"
55#include "llspatialpartition.h"
54#include "llglslshader.h" 56#include "llglslshader.h"
55 57
56//#include "llimagebmp.h" 58//#include "llimagebmp.h"
@@ -73,6 +75,10 @@ const U32 VERTEX_MASK_BUMP = LLVertexBuffer::MAP_VERTEX |LLVertexBuffer::MAP_TEX
73U32 LLDrawPoolBump::sVertexMask = VERTEX_MASK_SHINY; 75U32 LLDrawPoolBump::sVertexMask = VERTEX_MASK_SHINY;
74static LLCubeMap* sCubeMap = NULL; 76static LLCubeMap* sCubeMap = NULL;
75 77
78static LLGLSLShader* shader = NULL;
79static S32 cube_channel = -1;
80static S32 diffuse_channel = -1;
81
76// static 82// static
77void LLStandardBumpmap::init() 83void LLStandardBumpmap::init()
78{ 84{
@@ -158,8 +164,9 @@ void LLStandardBumpmap::destroyGL()
158//////////////////////////////////////////////////////////////// 164////////////////////////////////////////////////////////////////
159 165
160LLDrawPoolBump::LLDrawPoolBump() 166LLDrawPoolBump::LLDrawPoolBump()
161: LLRenderPass(LLDrawPool::POOL_BUMP) 167: LLRenderPass(LLDrawPool::POOL_BUMP)
162{ 168{
169 mShiny = FALSE;
163} 170}
164 171
165 172
@@ -173,7 +180,25 @@ S32 LLDrawPoolBump::numBumpPasses()
173{ 180{
174 if (gSavedSettings.getBOOL("RenderObjectBump")) 181 if (gSavedSettings.getBOOL("RenderObjectBump"))
175 { 182 {
176 return 2; 183 if (mVertexShaderLevel > 1)
184 {
185 if (LLPipeline::sImpostorRender)
186 {
187 return 2;
188 }
189 else
190 {
191 return 3;
192 }
193 }
194 else if (LLPipeline::sImpostorRender)
195 {
196 return 1;
197 }
198 else
199 {
200 return 2;
201 }
177 } 202 }
178 else 203 else
179 { 204 {
@@ -188,12 +213,23 @@ S32 LLDrawPoolBump::getNumPasses()
188 213
189void LLDrawPoolBump::beginRenderPass(S32 pass) 214void LLDrawPoolBump::beginRenderPass(S32 pass)
190{ 215{
216 LLFastTimer t(LLFastTimer::FTM_RENDER_BUMP);
191 switch( pass ) 217 switch( pass )
192 { 218 {
193 case 0: 219 case 0:
194 beginShiny(); 220 beginShiny();
195 break; 221 break;
196 case 1: 222 case 1:
223 if (mVertexShaderLevel > 1)
224 {
225 beginFullbrightShiny();
226 }
227 else
228 {
229 beginBump();
230 }
231 break;
232 case 2:
197 beginBump(); 233 beginBump();
198 break; 234 break;
199 default: 235 default:
@@ -213,32 +249,47 @@ void LLDrawPoolBump::render(S32 pass)
213 249
214 switch( pass ) 250 switch( pass )
215 { 251 {
216 case 0: 252 case 0:
217 { 253 renderShiny();
218 renderShiny(); 254 break;
219 break; 255 case 1:
220 } 256 if (mVertexShaderLevel > 1)
221 case 1: 257 {
222 { 258 renderFullbrightShiny();
223 renderBump(); 259 }
224 break; 260 else
225 } 261 {
226 default: 262 renderBump();
227 { 263 }
228 llassert(0); 264 break;
229 break; 265 case 2:
230 } 266 renderBump();
267 break;
268 default:
269 llassert(0);
270 break;
231 } 271 }
232} 272}
233 273
234void LLDrawPoolBump::endRenderPass(S32 pass) 274void LLDrawPoolBump::endRenderPass(S32 pass)
235{ 275{
276 LLFastTimer t(LLFastTimer::FTM_RENDER_BUMP);
236 switch( pass ) 277 switch( pass )
237 { 278 {
238 case 0: 279 case 0:
239 endShiny(); 280 endShiny();
240 break; 281 break;
241 case 1: 282 case 1:
283 if (mVertexShaderLevel > 1)
284 {
285 endFullbrightShiny();
286 }
287 else
288 {
289 endBump();
290 }
291 break;
292 case 2:
242 endBump(); 293 endBump();
243 break; 294 break;
244 default: 295 default:
@@ -248,36 +299,77 @@ void LLDrawPoolBump::endRenderPass(S32 pass)
248} 299}
249 300
250//static 301//static
251void LLDrawPoolBump::beginShiny() 302void LLDrawPoolBump::beginShiny(bool invisible)
252{ 303{
304 LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
305 if (!invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_SHINY)||
306 invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_INVISI_SHINY))
307 {
308 return;
309 }
310
311 mShiny = TRUE;
253 sVertexMask = VERTEX_MASK_SHINY; 312 sVertexMask = VERTEX_MASK_SHINY;
254 // Second pass: environment map 313 // Second pass: environment map
255 glEnableClientState(GL_VERTEX_ARRAY); 314 glEnableClientState(GL_VERTEX_ARRAY);
256 glEnableClientState(GL_NORMAL_ARRAY); 315 glEnableClientState(GL_NORMAL_ARRAY);
257 glEnableClientState(GL_COLOR_ARRAY); 316 glEnableClientState(GL_COLOR_ARRAY);
317 if (!invisible && mVertexShaderLevel > 1)
318 {
319 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
320 sVertexMask = VERTEX_MASK_SHINY | LLVertexBuffer::MAP_TEXCOORD;
321 }
322
323 if (LLPipeline::sUnderWaterRender)
324 {
325 shader = &gObjectShinyWaterProgram;
326 }
327 else
328 {
329 shader = &gObjectShinyProgram;
330 }
258 331
259 LLCubeMap* cube_map = gSky.mVOSkyp->getCubeMap(); 332 LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
260 if( cube_map ) 333 if( cube_map )
261 { 334 {
262 cube_map->enable(0); 335 if (!invisible && LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_OBJECT) > 0 )
263 cube_map->setMatrix(0);
264 cube_map->bind();
265
266 if (LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_OBJECT) > 0)
267 { 336 {
268 LLMatrix4 mat; 337 LLMatrix4 mat;
269 mat.initRows(LLVector4(gGLModelView+0), 338 mat.initRows(LLVector4(gGLModelView+0),
270 LLVector4(gGLModelView+4), 339 LLVector4(gGLModelView+4),
271 LLVector4(gGLModelView+8), 340 LLVector4(gGLModelView+8),
272 LLVector4(gGLModelView+12)); 341 LLVector4(gGLModelView+12));
273 gObjectShinyProgram.bind(); 342 shader->bind();
274 LLVector3 vec = LLVector3(gShinyOrigin) * mat; 343 LLVector3 vec = LLVector3(gShinyOrigin) * mat;
275 LLVector4 vec4(vec, gShinyOrigin.mV[3]); 344 LLVector4 vec4(vec, gShinyOrigin.mV[3]);
276 glUniform4fvARB(gObjectShinyProgram.mUniform[LLShaderMgr::SHINY_ORIGIN], 1, 345 shader->uniform4fv(LLShaderMgr::SHINY_ORIGIN, 1, vec4.mV);
277 vec4.mV); 346 if (mVertexShaderLevel > 1)
347 {
348 cube_map->setMatrix(1);
349 // Make sure that texture coord generation happens for tex unit 1, as that's the one we use for
350 // the cube map in the one pass shiny shaders
351 cube_channel = shader->enableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB);
352 cube_map->enableTexture(cube_channel);
353 cube_map->enableTextureCoords(1);
354 diffuse_channel = shader->enableTexture(LLShaderMgr::DIFFUSE_MAP);
355 }
356 else
357 {
358 cube_channel = 0;
359 diffuse_channel = -1;
360 cube_map->setMatrix(0);
361 cube_map->enable(shader->enableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB));
362 }
363 cube_map->bind();
278 } 364 }
279 else 365 else
280 { 366 {
367 cube_channel = 0;
368 diffuse_channel = -1;
369 cube_map->enable(0);
370 cube_map->setMatrix(0);
371 cube_map->bind();
372
281 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); 373 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
282 374
283 //use RGB from texture 375 //use RGB from texture
@@ -293,63 +385,188 @@ void LLDrawPoolBump::beginShiny()
293 } 385 }
294} 386}
295 387
296void LLDrawPoolBump::renderShiny() 388void LLDrawPoolBump::renderShiny(bool invisible)
297{ 389{
298 LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY); 390 LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
299 391 if (!invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_SHINY)||
392 invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_INVISI_SHINY))
393 {
394 return;
395 }
396
300 sCubeMap = NULL; 397 sCubeMap = NULL;
301 398
302 if( gSky.mVOSkyp->getCubeMap() ) 399 if( gSky.mVOSkyp->getCubeMap() )
303 { 400 {
304 LLGLEnable blend_enable(GL_BLEND); 401 LLGLEnable blend_enable(GL_BLEND);
305 renderStatic(LLRenderPass::PASS_SHINY, sVertexMask); 402 if (!invisible && mVertexShaderLevel > 1)
306 renderActive(LLRenderPass::PASS_SHINY, sVertexMask); 403 {
404 LLRenderPass::renderTexture(LLRenderPass::PASS_SHINY, sVertexMask);
405 }
406 else if (!invisible)
407 {
408 renderGroups(LLRenderPass::PASS_SHINY, sVertexMask);
409 }
410 else // invisible
411 {
412 renderGroups(LLRenderPass::PASS_INVISI_SHINY, sVertexMask);
413 }
307 } 414 }
308} 415}
309 416
310void LLDrawPoolBump::renderActive(U32 type, U32 mask, BOOL texture) 417void LLDrawPoolBump::endShiny(bool invisible)
311{ 418{
312#if !LL_RELEASE_FOR_DOWNLOAD 419 LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
313 LLGLState::checkClientArrays(mask); 420 if (!invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_SHINY)||
314#endif 421 invisible && !gPipeline.hasRenderBatches(LLRenderPass::PASS_INVISI_SHINY))
422 {
423 return;
424 }
315 425
316 LLSpatialBridge* last_bridge = NULL; 426 LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
317 glPushMatrix(); 427 if( cube_map )
318
319 for (LLSpatialGroup::sg_vector_t::iterator i = gPipeline.mActiveGroups.begin(); i != gPipeline.mActiveGroups.end(); ++i)
320 { 428 {
321 LLSpatialGroup* group = *i; 429 cube_map->disable();
322 if (!group->isDead() && 430 cube_map->restoreMatrix();
323 gPipeline.hasRenderType(group->mSpatialPartition->mDrawableType) && 431
324 group->mDrawMap.find(type) != group->mDrawMap.end()) 432 if (!invisible && mVertexShaderLevel > 1)
325 { 433 {
326 LLSpatialBridge* bridge = (LLSpatialBridge*) group->mSpatialPartition; 434 shader->disableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB);
327 if (bridge != last_bridge) 435
436 if (LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_OBJECT) > 0)
328 { 437 {
329 glPopMatrix(); 438 if (diffuse_channel != 0)
330 glPushMatrix();
331 glMultMatrixf((F32*) bridge->mDrawable->getRenderMatrix().mMatrix);
332 last_bridge = bridge;
333
334 if (LLPipeline::sDynamicReflections)
335 { 439 {
336 LLSpatialPartition* part = gPipeline.getSpatialPartition(LLPipeline::PARTITION_VOLUME); 440 shader->disableTexture(LLShaderMgr::DIFFUSE_MAP);
337 LLSpatialGroup::OctreeNode* node = part->mOctree->getNodeAt(LLVector3d(bridge->mDrawable->getPositionAgent()), 32.0);
338 if (node)
339 {
340 sCubeMap = ((LLSpatialGroup*) node->getListener(0))->mReflectionMap;
341 }
342 } 441 }
343 } 442 }
344 443
345 renderGroup(group,type,mask,texture); 444 shader->unbind();
445 glActiveTextureARB(GL_TEXTURE0_ARB);
446 glEnable(GL_TEXTURE_2D);
346 } 447 }
448
449 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
347 } 450 }
348 451
349 glPopMatrix(); 452 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
453 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
454 glDisableClientState(GL_NORMAL_ARRAY);
455 glDisableClientState(GL_COLOR_ARRAY);
456 if (!invisible && mVertexShaderLevel > 1)
457 {
458 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
459 }
460
461 diffuse_channel = -1;
462 cube_channel = 0;
463 mShiny = FALSE;
350} 464}
351 465
466void LLDrawPoolBump::beginFullbrightShiny()
467{
468 LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
469 if (!gPipeline.hasRenderBatches(LLRenderPass::PASS_FULLBRIGHT_SHINY))
470 {
471 return;
472 }
473
474 sVertexMask = VERTEX_MASK_SHINY | LLVertexBuffer::MAP_TEXCOORD;
475
476 // Second pass: environment map
477 glEnableClientState(GL_VERTEX_ARRAY);
478 glEnableClientState(GL_NORMAL_ARRAY);
479 glEnableClientState(GL_COLOR_ARRAY);
480 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
481
482 if (LLPipeline::sUnderWaterRender)
483 {
484 shader = &gObjectShinyWaterProgram;
485 }
486 else
487 {
488 shader = &gObjectFullbrightShinyProgram;
489 }
352 490
491 LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
492 if( cube_map )
493 {
494 LLMatrix4 mat;
495 mat.initRows(LLVector4(gGLModelView+0),
496 LLVector4(gGLModelView+4),
497 LLVector4(gGLModelView+8),
498 LLVector4(gGLModelView+12));
499 shader->bind();
500 LLVector3 vec = LLVector3(gShinyOrigin) * mat;
501 LLVector4 vec4(vec, gShinyOrigin.mV[3]);
502 shader->uniform4fv(LLShaderMgr::SHINY_ORIGIN, 1, vec4.mV);
503
504 cube_map->setMatrix(1);
505 // Make sure that texture coord generation happens for tex unit 1, as that's the one we use for
506 // the cube map in the one pass shiny shaders
507 cube_channel = shader->enableTexture(LLShaderMgr::ENVIRONMENT_MAP, GL_TEXTURE_CUBE_MAP_ARB);
508 cube_map->enableTexture(cube_channel);
509 cube_map->enableTextureCoords(1);
510 diffuse_channel = shader->enableTexture(LLShaderMgr::DIFFUSE_MAP);
511
512 cube_map->bind();
513 }
514 mShiny = TRUE;
515}
516
517void LLDrawPoolBump::renderFullbrightShiny()
518{
519 LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
520 if (!gPipeline.hasRenderBatches(LLRenderPass::PASS_FULLBRIGHT_SHINY))
521 {
522 return;
523 }
524
525 sCubeMap = NULL;
526
527 if( gSky.mVOSkyp->getCubeMap() )
528 {
529 LLGLEnable blend_enable(GL_BLEND);
530 LLRenderPass::renderTexture(LLRenderPass::PASS_FULLBRIGHT_SHINY, sVertexMask);
531 }
532}
533
534void LLDrawPoolBump::endFullbrightShiny()
535{
536 LLFastTimer t(LLFastTimer::FTM_RENDER_SHINY);
537 if (!gPipeline.hasRenderBatches(LLRenderPass::PASS_FULLBRIGHT_SHINY))
538 {
539 return;
540 }
541
542 LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
543 if( cube_map )
544 {
545 cube_map->disable();
546 cube_map->restoreMatrix();
547
548 if (diffuse_channel != 0)
549 {
550 shader->disableTexture(LLShaderMgr::DIFFUSE_MAP);
551 }
552 glActiveTextureARB(GL_TEXTURE0_ARB);
553 glEnable(GL_TEXTURE_2D);
554
555 shader->unbind();
556
557 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
558 }
559
560 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
561 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
562 glDisableClientState(GL_NORMAL_ARRAY);
563 glDisableClientState(GL_COLOR_ARRAY);
564 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
565
566 diffuse_channel = -1;
567 cube_channel = 0;
568 mShiny = FALSE;
569}
353 570
354void LLDrawPoolBump::renderGroup(LLSpatialGroup* group, U32 type, U32 mask, BOOL texture = TRUE) 571void LLDrawPoolBump::renderGroup(LLSpatialGroup* group, U32 type, U32 mask, BOOL texture = TRUE)
355{ 572{
@@ -366,6 +583,11 @@ void LLDrawPoolBump::renderGroup(LLSpatialGroup* group, U32 type, U32 mask, BOOL
366 } 583 }
367 else 584 else
368 { 585 {
586 if (params.mModelMatrix)
587 {
588 sCubeMap = gPipeline.findReflectionMap(params.mModelMatrix->getTranslation());
589 }
590
369 if (sCubeMap) 591 if (sCubeMap)
370 { 592 {
371 sCubeMap->bind(); 593 sCubeMap->bind();
@@ -377,34 +599,14 @@ void LLDrawPoolBump::renderGroup(LLSpatialGroup* group, U32 type, U32 mask, BOOL
377 } 599 }
378 } 600 }
379 601
602 applyModelMatrix(params);
603
380 params.mVertexBuffer->setBuffer(mask); 604 params.mVertexBuffer->setBuffer(mask);
381 U32* indices_pointer = (U32*) params.mVertexBuffer->getIndicesPointer(); 605 U16* indices_pointer = (U16*) params.mVertexBuffer->getIndicesPointer();
382 glDrawRangeElements(GL_TRIANGLES, params.mStart, params.mEnd, params.mCount, 606 glDrawRangeElements(GL_TRIANGLES, params.mStart, params.mEnd, params.mCount,
383 GL_UNSIGNED_INT, indices_pointer+params.mOffset); 607 GL_UNSIGNED_SHORT, indices_pointer+params.mOffset);
384 gPipeline.mTrianglesDrawn += params.mCount/3; 608 gPipeline.addTrianglesDrawn(params.mCount/3);
385 }
386}
387
388void LLDrawPoolBump::endShiny()
389{
390 LLCubeMap* cube_map = gSky.mVOSkyp->getCubeMap();
391 if( cube_map )
392 {
393 cube_map->disable();
394 cube_map->restoreMatrix();
395
396 if (LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_OBJECT) > 0)
397 {
398 gObjectShinyProgram.unbind();
399 }
400
401 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
402 } 609 }
403
404 LLImageGL::unbindTexture(0, GL_TEXTURE_2D);
405 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
406 glDisableClientState(GL_NORMAL_ARRAY);
407 glDisableClientState(GL_COLOR_ARRAY);
408} 610}
409 611
410 612
@@ -450,6 +652,11 @@ BOOL LLDrawPoolBump::bindBumpMap(LLDrawInfo& params)
450//static 652//static
451void LLDrawPoolBump::beginBump() 653void LLDrawPoolBump::beginBump()
452{ 654{
655 if (!gPipeline.hasRenderBatches(LLRenderPass::PASS_BUMP))
656 {
657 return;
658 }
659
453 sVertexMask = VERTEX_MASK_BUMP; 660 sVertexMask = VERTEX_MASK_BUMP;
454 LLFastTimer t(LLFastTimer::FTM_RENDER_BUMP); 661 LLFastTimer t(LLFastTimer::FTM_RENDER_BUMP);
455 // Optional second pass: emboss bump map 662 // Optional second pass: emboss bump map
@@ -503,28 +710,41 @@ void LLDrawPoolBump::beginBump()
503 // = 2 * ((1 + bump0 - bump1) / 2) * dst [0 - 2 * dst] 710 // = 2 * ((1 + bump0 - bump1) / 2) * dst [0 - 2 * dst]
504 // = (1 + bump0 - bump1) * dst.rgb 711 // = (1 + bump0 - bump1) * dst.rgb
505 // = dst.rgb + dst.rgb * (bump0 - bump1) 712 // = dst.rgb + dst.rgb * (bump0 - bump1)
506 glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR); 713 gGL.blendFunc(GL_DST_COLOR, GL_SRC_COLOR);
507// glBlendFunc(GL_ONE, GL_ZERO); // temp 714// gGL.blendFunc(GL_ONE, GL_ZERO); // temp
508 glActiveTextureARB(GL_TEXTURE0_ARB); 715 glActiveTextureARB(GL_TEXTURE0_ARB);
509 stop_glerror(); 716 stop_glerror();
717
718 LLViewerImage::unbindTexture(1, GL_TEXTURE_2D);
510} 719}
511 720
512//static 721//static
513void LLDrawPoolBump::renderBump() 722void LLDrawPoolBump::renderBump()
514{ 723{
724 if (!gPipeline.hasRenderBatches(LLRenderPass::PASS_BUMP))
725 {
726 return;
727 }
728
515 LLFastTimer ftm(LLFastTimer::FTM_RENDER_BUMP); 729 LLFastTimer ftm(LLFastTimer::FTM_RENDER_BUMP);
516 LLGLDisable fog(GL_FOG); 730 LLGLDisable fog(GL_FOG);
517 LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_EQUAL); 731 LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_LEQUAL);
518 LLGLEnable tex2d(GL_TEXTURE_2D);
519 LLGLEnable blend(GL_BLEND); 732 LLGLEnable blend(GL_BLEND);
520 glColor4f(1,1,1,1); 733 glColor4f(1,1,1,1);
734 /// Get rid of z-fighting with non-bump pass.
735 LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
736 glPolygonOffset(-1.0f, -1.0f);
521 renderBump(LLRenderPass::PASS_BUMP, sVertexMask); 737 renderBump(LLRenderPass::PASS_BUMP, sVertexMask);
522 renderBumpActive(LLRenderPass::PASS_BUMP, sVertexMask);
523} 738}
524 739
525//static 740//static
526void LLDrawPoolBump::endBump() 741void LLDrawPoolBump::endBump()
527{ 742{
743 if (!gPipeline.hasRenderBatches(LLRenderPass::PASS_BUMP))
744 {
745 return;
746 }
747
528 // Disable texture unit 1 748 // Disable texture unit 1
529 glActiveTextureARB(GL_TEXTURE1_ARB); 749 glActiveTextureARB(GL_TEXTURE1_ARB);
530 glClientActiveTextureARB(GL_TEXTURE1_ARB); 750 glClientActiveTextureARB(GL_TEXTURE1_ARB);
@@ -538,7 +758,7 @@ void LLDrawPoolBump::endBump()
538 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 758 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
539 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 759 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
540 760
541 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); 761 gGL.blendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
542} 762}
543 763
544//////////////////////////////////////////////////////////////// 764////////////////////////////////////////////////////////////////
@@ -864,47 +1084,16 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerImage *src_vi, LLIma
864 } 1084 }
865} 1085}
866 1086
867void LLDrawPoolBump::renderBumpActive(U32 type, U32 mask)
868{
869#if !LL_RELEASE_FOR_DOWNLOAD
870 LLGLState::checkClientArrays(mask);
871#endif
872
873 LLSpatialBridge* last_bridge = NULL;
874 glPushMatrix();
875
876 for (LLSpatialGroup::sg_vector_t::iterator i = gPipeline.mActiveGroups.begin(); i != gPipeline.mActiveGroups.end(); ++i)
877 {
878 LLSpatialGroup* group = *i;
879 if (!group->isDead() &&
880 group->mSpatialPartition->mRenderByGroup &&
881 group->mDrawMap.find(type) != group->mDrawMap.end())
882 {
883 LLSpatialBridge* bridge = (LLSpatialBridge*) group->mSpatialPartition;
884 if (bridge != last_bridge)
885 {
886 glPopMatrix();
887 glPushMatrix();
888 glMultMatrixf((F32*) bridge->mDrawable->getRenderMatrix().mMatrix);
889 last_bridge = bridge;
890 }
891
892 renderGroupBump(group,type,mask);
893 }
894 }
895
896 glPopMatrix();
897}
898
899void LLDrawPoolBump::renderBump(U32 type, U32 mask) 1087void LLDrawPoolBump::renderBump(U32 type, U32 mask)
900{ 1088{
901#if !LL_RELEASE_FOR_DOWNLOAD 1089#if !LL_RELEASE_FOR_DOWNLOAD
902 LLGLState::checkClientArrays(mask); 1090 LLGLState::checkClientArrays(mask);
903#endif 1091#endif
904 1092
905 LLSpatialGroup::drawmap_elem_t& draw_info = gPipeline.mRenderMap[type]; 1093 LLCullResult::drawinfo_list_t::iterator begin = gPipeline.beginRenderMap(type);
1094 LLCullResult::drawinfo_list_t::iterator end = gPipeline.endRenderMap(type);
906 1095
907 for (LLSpatialGroup::drawmap_elem_t::iterator i = draw_info.begin(); i != draw_info.end(); ++i) 1096 for (LLCullResult::drawinfo_list_t::iterator i = begin; i != end; ++i)
908 { 1097 {
909 LLDrawInfo& params = **i; 1098 LLDrawInfo& params = **i;
910 1099
@@ -932,25 +1121,96 @@ void LLDrawPoolBump::renderGroupBump(LLSpatialGroup* group, U32 type, U32 mask)
932 1121
933void LLDrawPoolBump::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture) 1122void LLDrawPoolBump::pushBatch(LLDrawInfo& params, U32 mask, BOOL texture)
934{ 1123{
1124 applyModelMatrix(params);
1125
935 if (params.mTextureMatrix) 1126 if (params.mTextureMatrix)
936 { 1127 {
937 glActiveTextureARB(GL_TEXTURE1_ARB); 1128 if (mShiny)
938 glMatrixMode(GL_TEXTURE); 1129 {
939 glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix); 1130 glActiveTextureARB(GL_TEXTURE0_ARB);
940 glActiveTextureARB(GL_TEXTURE0_ARB); 1131 glMatrixMode(GL_TEXTURE);
1132 }
1133 else
1134 {
1135 glActiveTextureARB(GL_TEXTURE1_ARB);
1136 glMatrixMode(GL_TEXTURE);
1137 glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix);
1138 gPipeline.mTextureMatrixOps++;
1139 glActiveTextureARB(GL_TEXTURE0_ARB);
1140 }
1141
941 glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix); 1142 glLoadMatrixf((GLfloat*) params.mTextureMatrix->mMatrix);
1143 gPipeline.mTextureMatrixOps++;
1144 }
1145
1146 if (mShiny && mVertexShaderLevel > 1 && texture)
1147 {
1148 if (params.mTexture.notNull())
1149 {
1150 params.mTexture->bind(diffuse_channel);
1151 params.mTexture->addTextureStats(params.mVSize);
1152 }
1153 else
1154 {
1155 LLImageGL::unbindTexture(0);
1156 }
1157
1158 if (LLPipeline::sDynamicReflections)
1159 {
1160 LLCubeMap* cube_map = params.mReflectionMap;
1161
1162 if (!cube_map && params.mModelMatrix)
1163 {
1164 cube_map = gPipeline.findReflectionMap(params.mModelMatrix->getTranslation());
1165 }
1166
1167 if (cube_map)
1168 {
1169 cube_map->enableTexture(cube_channel);
1170 cube_map->bind();
1171 }
1172 }
942 } 1173 }
1174
943 params.mVertexBuffer->setBuffer(mask); 1175 params.mVertexBuffer->setBuffer(mask);
944 U32* indices_pointer = (U32*) params.mVertexBuffer->getIndicesPointer(); 1176 U16* indices_pointer = (U16*) params.mVertexBuffer->getIndicesPointer();
945 glDrawRangeElements(GL_TRIANGLES, params.mStart, params.mEnd, params.mCount, 1177 glDrawRangeElements(GL_TRIANGLES, params.mStart, params.mEnd, params.mCount,
946 GL_UNSIGNED_INT, indices_pointer+params.mOffset); 1178 GL_UNSIGNED_SHORT, indices_pointer+params.mOffset);
947 gPipeline.mTrianglesDrawn += params.mCount/3; 1179 gPipeline.addTrianglesDrawn(params.mCount/3);
1180
948 if (params.mTextureMatrix) 1181 if (params.mTextureMatrix)
949 { 1182 {
950 glActiveTextureARB(GL_TEXTURE1_ARB); 1183 if (mShiny)
951 glLoadIdentity(); 1184 {
952 glActiveTextureARB(GL_TEXTURE0_ARB); 1185 glActiveTextureARB(GL_TEXTURE0_ARB);
1186 }
1187 else
1188 {
1189 glActiveTextureARB(GL_TEXTURE1_ARB);
1190 glLoadIdentity();
1191 glActiveTextureARB(GL_TEXTURE0_ARB);
1192 }
953 glLoadIdentity(); 1193 glLoadIdentity();
954 glMatrixMode(GL_MODELVIEW); 1194 glMatrixMode(GL_MODELVIEW);
955 } 1195 }
956} 1196}
1197
1198void LLDrawPoolInvisible::render(S32 pass)
1199{ //render invisiprims
1200 LLFastTimer t(LLFastTimer::FTM_RENDER_INVISIBLE);
1201
1202 U32 invisi_mask = LLVertexBuffer::MAP_VERTEX;
1203 glStencilMask(0);
1204 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
1205 pushBatches(LLRenderPass::PASS_INVISIBLE, invisi_mask, FALSE);
1206 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
1207 glStencilMask(0xFFFFFFFF);
1208
1209 if (gPipeline.hasRenderBatches(LLRenderPass::PASS_INVISI_SHINY))
1210 {
1211 beginShiny(true);
1212 renderShiny(true);
1213 endShiny(true);
1214 }
1215}
1216