aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltexlayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/lltexlayer.cpp')
-rw-r--r--linden/indra/newview/lltexlayer.cpp229
1 files changed, 60 insertions, 169 deletions
diff --git a/linden/indra/newview/lltexlayer.cpp b/linden/indra/newview/lltexlayer.cpp
index e331146..a687344 100644
--- a/linden/indra/newview/lltexlayer.cpp
+++ b/linden/indra/newview/lltexlayer.cpp
@@ -60,8 +60,6 @@
60// SJB: We really always want to use the GL cache; 60// SJB: We really always want to use the GL cache;
61// let GL page textures in and out of video RAM instead of trying to do so by hand. 61// let GL page textures in and out of video RAM instead of trying to do so by hand.
62 62
63LLGradientPaletteList gGradientPaletteList;
64
65// static 63// static
66S32 LLTexLayerSetBuffer::sGLByteCount = 0; 64S32 LLTexLayerSetBuffer::sGLByteCount = 0;
67S32 LLTexLayerSetBuffer::sGLBumpByteCount = 0; 65S32 LLTexLayerSetBuffer::sGLBumpByteCount = 0;
@@ -96,7 +94,6 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h
96 mNeedsUpload( FALSE ), 94 mNeedsUpload( FALSE ),
97 mUploadPending( FALSE ), // Not used for any logic here, just to sync sending of updates 95 mUploadPending( FALSE ), // Not used for any logic here, just to sync sending of updates
98 mTexLayerSet( owner ), 96 mTexLayerSet( owner ),
99 mInitialized( FALSE ),
100 mBumpTexName(0) 97 mBumpTexName(0)
101{ 98{
102 LLTexLayerSetBuffer::sGLByteCount += getSize(); 99 LLTexLayerSetBuffer::sGLByteCount += getSize();
@@ -106,11 +103,10 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h
106 LLGLSUIDefault gls_ui; 103 LLGLSUIDefault gls_ui;
107 glGenTextures(1, (GLuint*) &mBumpTexName); 104 glGenTextures(1, (GLuint*) &mBumpTexName);
108 105
109 LLImageGL::bindExternalTexture(mBumpTexName, 0, GL_TEXTURE_2D); 106 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName);
110 stop_glerror(); 107 stop_glerror();
111 108
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 109 gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
114 110
115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -118,7 +114,7 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h
118 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 114 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
119 stop_glerror(); 115 stop_glerror();
120 116
121 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 117 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
122 118
123 LLImageGL::sGlobalTextureMemory += mWidth * mHeight * 4; 119 LLImageGL::sGlobalTextureMemory += mWidth * mHeight * 4;
124 LLTexLayerSetBuffer::sGLBumpByteCount += mWidth * mHeight * 4; 120 LLTexLayerSetBuffer::sGLBumpByteCount += mWidth * mHeight * 4;
@@ -259,7 +255,7 @@ BOOL LLTexLayerSetBuffer::render()
259 LLGLSUIDefault gls_ui; 255 LLGLSUIDefault gls_ui;
260 256
261 // read back into texture (this is done externally for the color data) 257 // read back into texture (this is done externally for the color data)
262 LLImageGL::bindExternalTexture( mBumpTexName, 0, GL_TEXTURE_2D ); 258 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName);
263 stop_glerror(); 259 stop_glerror();
264 260
265 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mOrigin.mX, mOrigin.mY, mWidth, mHeight); 261 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mOrigin.mX, mOrigin.mY, mWidth, mHeight);
@@ -299,12 +295,17 @@ BOOL LLTexLayerSetBuffer::render()
299 gGL.setSceneBlendType(LLRender::BT_ALPHA); 295 gGL.setSceneBlendType(LLRender::BT_ALPHA);
300 296
301 // we have valid texture data now 297 // we have valid texture data now
302 mInitialized = TRUE; 298 mTexture->setInitialized(true);
303 mNeedsUpdate = FALSE; 299 mNeedsUpdate = FALSE;
304 300
305 return success; 301 return success;
306} 302}
307 303
304bool LLTexLayerSetBuffer::isInitialized(void) const
305{
306 return mTexture->isInitialized();
307}
308
308BOOL LLTexLayerSetBuffer::updateImmediate() 309BOOL LLTexLayerSetBuffer::updateImmediate()
309{ 310{
310 mNeedsUpdate = TRUE; 311 mNeedsUpdate = TRUE;
@@ -551,24 +552,12 @@ void LLTexLayerSetBuffer::onTextureUploadComplete(const LLUUID& uuid, void* user
551 delete baked_upload_data; 552 delete baked_upload_data;
552} 553}
553 554
554
555void LLTexLayerSetBuffer::bindTexture()
556{
557 if( mInitialized )
558 {
559 LLDynamicTexture::bindTexture();
560 }
561 else
562 {
563 gImageList.getImage(IMG_DEFAULT)->bind();
564 }
565}
566
567void LLTexLayerSetBuffer::bindBumpTexture( U32 stage ) 555void LLTexLayerSetBuffer::bindBumpTexture( U32 stage )
568{ 556{
569 if( mBumpTexName ) 557 if( mBumpTexName )
570 { 558 {
571 LLImageGL::bindExternalTexture(mBumpTexName, stage, GL_TEXTURE_2D); 559 gGL.getTexUnit(stage)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName);
560 gGL.getTexUnit(0)->activate();
572 561
573 if( mLastBindTime != LLImageGL::sLastFrameTime ) 562 if( mLastBindTime != LLImageGL::sLastFrameTime )
574 { 563 {
@@ -578,7 +567,8 @@ void LLTexLayerSetBuffer::bindBumpTexture( U32 stage )
578 } 567 }
579 else 568 else
580 { 569 {
581 LLImageGL::unbindTexture(stage, GL_TEXTURE_2D); 570 gGL.getTexUnit(stage)->unbind(LLTexUnit::TT_TEXTURE);
571 gGL.getTexUnit(0)->activate();
582 } 572 }
583} 573}
584 574
@@ -786,7 +776,7 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height )
786 if( image_gl ) 776 if( image_gl )
787 { 777 {
788 LLGLSUIDefault gls_ui; 778 LLGLSUIDefault gls_ui;
789 image_gl->bind(); 779 gGL.getTexUnit(0)->bind(image_gl);
790 gl_rect_2d_simple_tex( width, height ); 780 gl_rect_2d_simple_tex( width, height );
791 } 781 }
792 else 782 else
@@ -794,7 +784,7 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height )
794 success = FALSE; 784 success = FALSE;
795 } 785 }
796 } 786 }
797 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 787 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
798 788
799 gGL.flush(); 789 gGL.flush();
800 gGL.setColorMask(true, true); 790 gGL.setColorMask(true, true);
@@ -804,7 +794,8 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height )
804 if( getInfo()->mClearAlpha ) 794 if( getInfo()->mClearAlpha )
805 { 795 {
806 // Set the alpha channel to one (clean up after previous blending) 796 // Set the alpha channel to one (clean up after previous blending)
807 LLGLSNoTextureNoAlphaTest gls_no_alpha; 797 LLGLDisable no_alpha(GL_ALPHA_TEST);
798 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
808 gGL.color4f( 0.f, 0.f, 0.f, 1.f ); 799 gGL.color4f( 0.f, 0.f, 0.f, 1.f );
809 gGL.flush(); 800 gGL.flush();
810 gGL.setColorMask(false, true); 801 gGL.setColorMask(false, true);
@@ -838,7 +829,8 @@ BOOL LLTexLayerSet::renderBump( S32 x, S32 y, S32 width, S32 height )
838 } 829 }
839 830
840 // Set the alpha channel to one (clean up after previous blending) 831 // Set the alpha channel to one (clean up after previous blending)
841 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha; 832 LLGLDisable no_alpha(GL_ALPHA_TEST);
833 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
842 gGL.color4f( 0.f, 0.f, 0.f, 1.f ); 834 gGL.color4f( 0.f, 0.f, 0.f, 1.f );
843 gGL.setColorMask(false, true); 835 gGL.setColorMask(false, true);
844 836
@@ -1358,13 +1350,13 @@ BOOL LLTexLayer::render( S32 x, S32 y, S32 width, S32 height )
1358 BOOL old_clamps = image_gl->getClampS(); 1350 BOOL old_clamps = image_gl->getClampS();
1359 BOOL old_clampt = image_gl->getClampT(); 1351 BOOL old_clampt = image_gl->getClampT();
1360 1352
1361 image_gl->bind(); 1353 gGL.getTexUnit(0)->bind(image_gl);
1362 image_gl->setClamp(TRUE, TRUE); 1354 image_gl->setClamp(TRUE, TRUE);
1363 1355
1364 gl_rect_2d_simple_tex( width, height ); 1356 gl_rect_2d_simple_tex( width, height );
1365 1357
1366 image_gl->setClamp(old_clamps, old_clampt); 1358 image_gl->setClamp(old_clamps, old_clampt);
1367 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1359 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1368 } 1360 }
1369 } 1361 }
1370 else 1362 else
@@ -1380,9 +1372,9 @@ BOOL LLTexLayer::render( S32 x, S32 y, S32 width, S32 height )
1380 LLImageGL* image_gl = gTexStaticImageList.getImageGL( getInfo()->mStaticImageFileName, getInfo()->mStaticImageIsMask ); 1372 LLImageGL* image_gl = gTexStaticImageList.getImageGL( getInfo()->mStaticImageFileName, getInfo()->mStaticImageIsMask );
1381 if( image_gl ) 1373 if( image_gl )
1382 { 1374 {
1383 image_gl->bind(); 1375 gGL.getTexUnit(0)->bind(image_gl);
1384 gl_rect_2d_simple_tex( width, height ); 1376 gl_rect_2d_simple_tex( width, height );
1385 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1377 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1386 } 1378 }
1387 else 1379 else
1388 { 1380 {
@@ -1396,7 +1388,8 @@ BOOL LLTexLayer::render( S32 x, S32 y, S32 width, S32 height )
1396 getInfo()->mStaticImageFileName.empty() && 1388 getInfo()->mStaticImageFileName.empty() &&
1397 color_specified ) 1389 color_specified )
1398 { 1390 {
1399 LLGLSNoTextureNoAlphaTest gls; 1391 LLGLDisable no_alpha(GL_ALPHA_TEST);
1392 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1400 gGL.color4fv( net_color.mV); 1393 gGL.color4fv( net_color.mV);
1401 gl_rect_2d_simple( width, height ); 1394 gl_rect_2d_simple( width, height );
1402 } 1395 }
@@ -1518,7 +1511,8 @@ BOOL LLTexLayer::renderAlphaMasks( S32 x, S32 y, S32 width, S32 height, LLColor4
1518 // Note: if the first param is a mulitply, multiply against the current buffer's alpha 1511 // Note: if the first param is a mulitply, multiply against the current buffer's alpha
1519 if( !first_param || !first_param->getMultiplyBlend() ) 1512 if( !first_param || !first_param->getMultiplyBlend() )
1520 { 1513 {
1521 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha_test; 1514 LLGLDisable no_alpha(GL_ALPHA_TEST);
1515 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1522 1516
1523 // Clear the alpha 1517 // Clear the alpha
1524 gGL.flush(); 1518 gGL.flush();
@@ -1555,13 +1549,13 @@ BOOL LLTexLayer::renderAlphaMasks( S32 x, S32 y, S32 width, S32 height, LLColor4
1555 1549
1556 BOOL old_clamps = image_gl->getClampS(); 1550 BOOL old_clamps = image_gl->getClampS();
1557 BOOL old_clampt = image_gl->getClampT(); 1551 BOOL old_clampt = image_gl->getClampT();
1558 image_gl->bind(); 1552 gGL.getTexUnit(0)->bind(image_gl);
1559 image_gl->setClamp(TRUE, TRUE); 1553 image_gl->setClamp(TRUE, TRUE);
1560 1554
1561 gl_rect_2d_simple_tex( width, height ); 1555 gl_rect_2d_simple_tex( width, height );
1562 1556
1563 image_gl->setClamp(old_clamps, old_clampt); 1557 image_gl->setClamp(old_clamps, old_clampt);
1564 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1558 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1565 } 1559 }
1566 } 1560 }
1567 else 1561 else
@@ -1581,9 +1575,9 @@ BOOL LLTexLayer::renderAlphaMasks( S32 x, S32 y, S32 width, S32 height, LLColor4
1581 ( (image_gl->getComponents() == 1) && getInfo()->mStaticImageIsMask ) ) 1575 ( (image_gl->getComponents() == 1) && getInfo()->mStaticImageIsMask ) )
1582 { 1576 {
1583 LLGLSNoAlphaTest gls_no_alpha_test; 1577 LLGLSNoAlphaTest gls_no_alpha_test;
1584 image_gl->bind(); 1578 gGL.getTexUnit(0)->bind(image_gl);
1585 gl_rect_2d_simple_tex( width, height ); 1579 gl_rect_2d_simple_tex( width, height );
1586 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1580 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1587 } 1581 }
1588 } 1582 }
1589 else 1583 else
@@ -1597,7 +1591,8 @@ BOOL LLTexLayer::renderAlphaMasks( S32 x, S32 y, S32 width, S32 height, LLColor4
1597 // Note: we're still using gGL.blendFunc( GL_DST_ALPHA, GL_ZERO ); 1591 // Note: we're still using gGL.blendFunc( GL_DST_ALPHA, GL_ZERO );
1598 if( colorp->mV[VW] != 1.f ) 1592 if( colorp->mV[VW] != 1.f )
1599 { 1593 {
1600 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha_test; 1594 LLGLDisable no_alpha(GL_ALPHA_TEST);
1595 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1601 gGL.color4fv( colorp->mV ); 1596 gGL.color4fv( colorp->mV );
1602 gl_rect_2d_simple( width, height ); 1597 gl_rect_2d_simple( width, height );
1603 } 1598 }
@@ -1700,7 +1695,7 @@ BOOL LLTexLayer::renderImageRaw( U8* in_data, S32 in_width, S32 in_height, S32 i
1700 glGenTextures(1, &name ); 1695 glGenTextures(1, &name );
1701 stop_glerror(); 1696 stop_glerror();
1702 1697
1703 LLImageGL::bindExternalTexture( name, 0, GL_TEXTURE_2D ); 1698 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, name);
1704 stop_glerror(); 1699 stop_glerror();
1705 1700
1706 glTexImage2D( 1701 glTexImage2D(
@@ -1712,12 +1707,11 @@ BOOL LLTexLayer::renderImageRaw( U8* in_data, S32 in_width, S32 in_height, S32 i
1712 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1707 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1708 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1714 1709
1715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1710 gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
1716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1717 1711
1718 gl_rect_2d_simple_tex( width, height ); 1712 gl_rect_2d_simple_tex( width, height );
1719 1713
1720 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 1714 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1721 1715
1722 glDeleteTextures(1, &name ); 1716 glDeleteTextures(1, &name );
1723 stop_glerror(); 1717 stop_glerror();
@@ -1736,7 +1730,7 @@ BOOL LLTexLayer::renderImageRaw( U8* in_data, S32 in_width, S32 in_height, S32 i
1736 1730
1737 gl_rect_2d_simple_tex( width, height ); 1731 gl_rect_2d_simple_tex( width, height );
1738 1732
1739 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 1733 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1740 } 1734 }
1741 1735
1742 return TRUE; 1736 return TRUE;
@@ -1800,8 +1794,6 @@ BOOL LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node)
1800 static LLStdStringHandle domain_string = LLXmlTree::addAttributeString("domain"); 1794 static LLStdStringHandle domain_string = LLXmlTree::addAttributeString("domain");
1801 param_alpha_node->getFastAttributeF32( domain_string, mDomain ); 1795 param_alpha_node->getFastAttributeF32( domain_string, mDomain );
1802 1796
1803 gGradientPaletteList.initPalette(mDomain);
1804
1805 return TRUE; 1797 return TRUE;
1806} 1798}
1807 1799
@@ -1996,7 +1988,7 @@ BOOL LLTexLayerParamAlpha::render( S32 x, S32 y, S32 width, S32 height )
1996 if( !mCachedProcessedImageGL || 1988 if( !mCachedProcessedImageGL ||
1997 (mCachedProcessedImageGL->getWidth() != image_tga_width) || 1989 (mCachedProcessedImageGL->getWidth() != image_tga_width) ||
1998 (mCachedProcessedImageGL->getHeight() != image_tga_height) || 1990 (mCachedProcessedImageGL->getHeight() != image_tga_height) ||
1999 (weight_changed && !(gGLManager.mHasPalettedTextures && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_PALETTE))) ) 1991 (weight_changed ))
2000 { 1992 {
2001// llinfos << "Building Cached Alpha: " << mName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << effective_weight << llendl; 1993// llinfos << "Building Cached Alpha: " << mName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << effective_weight << llendl;
2002 mCachedEffectiveWeight = effective_weight; 1994 mCachedEffectiveWeight = effective_weight;
@@ -2008,71 +2000,34 @@ BOOL LLTexLayerParamAlpha::render( S32 x, S32 y, S32 width, S32 height )
2008 // We now have something in one of our caches 2000 // We now have something in one of our caches
2009 LLTexLayerSet::sHasCaches |= mCachedProcessedImageGL ? TRUE : FALSE; 2001 LLTexLayerSet::sHasCaches |= mCachedProcessedImageGL ? TRUE : FALSE;
2010 2002
2011 if (gGLManager.mHasPalettedTextures && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_PALETTE)) 2003
2012 { 2004 mCachedProcessedImageGL->setExplicitFormat( GL_ALPHA8, GL_ALPHA );
2013 // interpret luminance values as color index table
2014 mCachedProcessedImageGL->setExplicitFormat( GL_COLOR_INDEX8_EXT, GL_COLOR_INDEX );
2015 }
2016 else
2017 {
2018 mCachedProcessedImageGL->setExplicitFormat( GL_ALPHA8, GL_ALPHA );
2019 }
2020 } 2005 }
2021 2006
2022 // Applies domain and effective weight to data as it is decoded. Also resizes the raw image if needed. 2007 // Applies domain and effective weight to data as it is decoded. Also resizes the raw image if needed.
2023 if (gGLManager.mHasPalettedTextures && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_PALETTE)) 2008 mStaticImageRaw = NULL;
2024 { 2009 mStaticImageRaw = new LLImageRaw;
2025 mStaticImageRaw = NULL; 2010 mStaticImageTGA->decodeAndProcess( mStaticImageRaw, getInfo()->mDomain, effective_weight );
2026 mStaticImageRaw = new LLImageRaw; 2011 mNeedsCreateTexture = TRUE;
2027 mStaticImageTGA->decode(mStaticImageRaw);
2028 mNeedsCreateTexture = TRUE;
2029 }
2030 else
2031 {
2032 mStaticImageRaw = NULL;
2033 mStaticImageRaw = new LLImageRaw;
2034 mStaticImageTGA->decodeAndProcess( mStaticImageRaw, getInfo()->mDomain, effective_weight );
2035 mNeedsCreateTexture = TRUE;
2036 }
2037 } 2012 }
2038 2013
2039 if( mCachedProcessedImageGL ) 2014 if( mCachedProcessedImageGL )
2040 { 2015 {
2041 { 2016 {
2042 if (gGLManager.mHasPalettedTextures && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_PALETTE)) 2017 // Create the GL texture, and then hang onto it for future use.
2043 { 2018 if( mNeedsCreateTexture )
2044 if( mNeedsCreateTexture )
2045 {
2046 mCachedProcessedImageGL->createGLTexture(0, mStaticImageRaw);
2047 mNeedsCreateTexture = FALSE;
2048
2049 mCachedProcessedImageGL->bind();
2050 mCachedProcessedImageGL->setClamp(TRUE, TRUE);
2051 }
2052
2053 LLGLSNoAlphaTest gls_no_alpha_test;
2054 mCachedProcessedImageGL->bind();
2055 gGradientPaletteList.setHardwarePalette( getInfo()->mDomain, effective_weight );
2056 gl_rect_2d_simple_tex( width, height );
2057 mCachedProcessedImageGL->unbindTexture(0, GL_TEXTURE_2D);
2058 }
2059 else
2060 { 2019 {
2061 // Create the GL texture, and then hang onto it for future use. 2020 mCachedProcessedImageGL->createGLTexture(0, mStaticImageRaw);
2062 if( mNeedsCreateTexture ) 2021 mNeedsCreateTexture = FALSE;
2063 { 2022
2064 mCachedProcessedImageGL->createGLTexture(0, mStaticImageRaw); 2023 gGL.getTexUnit(0)->bind(mCachedProcessedImageGL);
2065 mNeedsCreateTexture = FALSE; 2024 mCachedProcessedImageGL->setClamp(TRUE, TRUE);
2066
2067 mCachedProcessedImageGL->bind();
2068 mCachedProcessedImageGL->setClamp(TRUE, TRUE);
2069 }
2070
2071 LLGLSNoAlphaTest gls_no_alpha_test;
2072 mCachedProcessedImageGL->bind();
2073 gl_rect_2d_simple_tex( width, height );
2074 mCachedProcessedImageGL->unbindTexture(0, GL_TEXTURE_2D);
2075 } 2025 }
2026
2027 LLGLSNoAlphaTest gls_no_alpha_test;
2028 gGL.getTexUnit(0)->bind(mCachedProcessedImageGL);
2029 gl_rect_2d_simple_tex( width, height );
2030 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
2076 stop_glerror(); 2031 stop_glerror();
2077 } 2032 }
2078 } 2033 }
@@ -2086,7 +2041,8 @@ BOOL LLTexLayerParamAlpha::render( S32 x, S32 y, S32 width, S32 height )
2086 } 2041 }
2087 else 2042 else
2088 { 2043 {
2089 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha_test; 2044 LLGLDisable no_alpha(GL_ALPHA_TEST);
2045 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
2090 gGL.color4f( 0.f, 0.f, 0.f, effective_weight ); 2046 gGL.color4f( 0.f, 0.f, 0.f, effective_weight );
2091 gl_rect_2d_simple( width, height ); 2047 gl_rect_2d_simple( width, height );
2092 } 2048 }
@@ -2519,7 +2475,7 @@ LLImageGL* LLTexStaticImageList::getImageGL(const std::string& file_name, BOOL i
2519 } 2475 }
2520 image_gl->createGLTexture(0, image_raw); 2476 image_gl->createGLTexture(0, image_raw);
2521 2477
2522 image_gl->bind(); 2478 gGL.getTexUnit(0)->bind(image_gl);
2523 image_gl->setClamp(TRUE, TRUE); 2479 image_gl->setClamp(TRUE, TRUE);
2524 2480
2525 mStaticImageListGL [ namekey ] = image_gl; 2481 mStaticImageListGL [ namekey ] = image_gl;
@@ -2559,68 +2515,3 @@ LLMaskedMorph::LLMaskedMorph( LLPolyMorphTarget *morph_target, BOOL invert ) : m
2559 morph_target->addPendingMorphMask(); 2515 morph_target->addPendingMorphMask();
2560} 2516}
2561 2517
2562
2563//-----------------------------------------------------------------------------
2564// LLGradientPaletteList
2565//-----------------------------------------------------------------------------
2566
2567LLGradientPaletteList::~LLGradientPaletteList()
2568{
2569 // Note: can't just call deleteAllData() because the data values are arrays.
2570 for( palette_map_t::iterator iter = mPaletteMap.begin();
2571 iter != mPaletteMap.end(); iter++ )
2572 {
2573 U8* data = iter->second;
2574 delete []data;
2575 }
2576}
2577
2578void LLGradientPaletteList::initPalette(F32 domain)
2579{
2580 palette_map_t::iterator iter = mPaletteMap.find( domain );
2581 if( iter == mPaletteMap.end() )
2582 {
2583 U8 *palette = new U8[512 * 4];
2584 mPaletteMap[domain] = palette;
2585 S32 ramp_start = 255 - llfloor(domain * 255.f);
2586 S32 ramp_end = 255;
2587 F32 ramp_factor = (ramp_end == ramp_start) ? 0.f : (255.f / ((F32)ramp_end - (F32)ramp_start));
2588
2589 // *TODO: move conditionals outside of loop, since this really
2590 // is just a sequential process.
2591 for (S32 i = 0; i < 512; i++)
2592 {
2593 palette[(i * 4) + 1] = 0;
2594 palette[(i * 4) + 2] = 0;
2595 if (i <= ramp_start)
2596 {
2597 palette[(i * 4)] = 0;
2598 palette[(i * 4) + 3] = 0;
2599 }
2600 else if (i < ramp_end)
2601 {
2602 palette[(i * 4)] = llfloor(((F32)i - (F32)ramp_start) * ramp_factor);
2603 palette[(i * 4) + 3] = llfloor(((F32)i - (F32)ramp_start) * ramp_factor);
2604 }
2605 else
2606 {
2607 palette[(i * 4)] = 255;
2608 palette[(i * 4) + 3] = 255;
2609 }
2610 }
2611 }
2612}
2613
2614void LLGradientPaletteList::setHardwarePalette( F32 domain, F32 effective_weight )
2615{
2616 palette_map_t::iterator iter = mPaletteMap.find( domain );
2617 if( iter != mPaletteMap.end() )
2618 {
2619 U8* palette = iter->second;
2620 set_palette( palette + llfloor(effective_weight * (255.f * (1.f - domain))) * 4);
2621 }
2622 else
2623 {
2624 llwarns << "LLGradientPaletteList::setHardwarePalette() missing domain " << domain << llendl;
2625 }
2626}