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.cpp306
1 files changed, 112 insertions, 194 deletions
diff --git a/linden/indra/newview/lltexlayer.cpp b/linden/indra/newview/lltexlayer.cpp
index e331146..0944d4b 100644
--- a/linden/indra/newview/lltexlayer.cpp
+++ b/linden/indra/newview/lltexlayer.cpp
@@ -4,7 +4,7 @@
4 * 4 *
5 * $LicenseInfo:firstyear=2002&license=viewergpl$ 5 * $LicenseInfo:firstyear=2002&license=viewergpl$
6 * 6 *
7 * Copyright (c) 2002-2008, Linden Research, Inc. 7 * Copyright (c) 2002-2009, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code 9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
@@ -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;
@@ -95,51 +93,76 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h
95 mNeedsUpdate( TRUE ), 93 mNeedsUpdate( TRUE ),
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)
101{ 97{
102 LLTexLayerSetBuffer::sGLByteCount += getSize(); 98 LLTexLayerSetBuffer::sGLByteCount += getSize();
99 mHasBump = has_bump ;
100 mBumpTex = NULL ;
101
102 createBumpTexture() ;
103}
104
105LLTexLayerSetBuffer::~LLTexLayerSetBuffer()
106{
107 LLTexLayerSetBuffer::sGLByteCount -= getSize();
103 108
104 if( has_bump ) 109 if( mBumpTex.notNull())
110 {
111 mBumpTex = NULL ;
112 LLImageGL::sGlobalTextureMemory -= mWidth * mHeight * 4;
113 LLTexLayerSetBuffer::sGLBumpByteCount -= mWidth * mHeight * 4;
114 }
115}
116//virtual
117void LLTexLayerSetBuffer::restoreGLTexture()
118{
119 createBumpTexture() ;
120 LLDynamicTexture::restoreGLTexture() ;
121}
122
123//virtual
124void LLTexLayerSetBuffer::destroyGLTexture()
125{
126 if( mBumpTex.notNull() )
127 {
128 mBumpTex = NULL ;
129 LLImageGL::sGlobalTextureMemory -= mWidth * mHeight * 4;
130 LLTexLayerSetBuffer::sGLBumpByteCount -= mWidth * mHeight * 4;
131 }
132
133 LLDynamicTexture::destroyGLTexture() ;
134}
135
136void LLTexLayerSetBuffer::createBumpTexture()
137{
138 if( mHasBump )
105 { 139 {
106 LLGLSUIDefault gls_ui; 140 LLGLSUIDefault gls_ui;
107 glGenTextures(1, (GLuint*) &mBumpTexName); 141 mBumpTex = new LLImageGL(FALSE) ;
142 if(!mBumpTex->createGLTexture())
143 {
144 mBumpTex = NULL ;
145 return ;
146 }
108 147
109 LLImageGL::bindExternalTexture(mBumpTexName, 0, GL_TEXTURE_2D); 148 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName());
110 stop_glerror(); 149 stop_glerror();
111 150
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 151 gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
113 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
114 152
115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
116 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
117 155
118 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 156 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
119 stop_glerror(); 157 stop_glerror();
120 158
121 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 159 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
122 160
123 LLImageGL::sGlobalTextureMemory += mWidth * mHeight * 4; 161 LLImageGL::sGlobalTextureMemory += mWidth * mHeight * 4;
124 LLTexLayerSetBuffer::sGLBumpByteCount += mWidth * mHeight * 4; 162 LLTexLayerSetBuffer::sGLBumpByteCount += mWidth * mHeight * 4;
125 } 163 }
126} 164}
127 165
128LLTexLayerSetBuffer::~LLTexLayerSetBuffer()
129{
130 LLTexLayerSetBuffer::sGLByteCount -= getSize();
131
132 if( mBumpTexName )
133 {
134 glDeleteTextures(1, (GLuint*) &mBumpTexName);
135 stop_glerror();
136 mBumpTexName = 0;
137
138 LLImageGL::sGlobalTextureMemory -= mWidth * mHeight * 4;
139 LLTexLayerSetBuffer::sGLBumpByteCount -= mWidth * mHeight * 4;
140 }
141}
142
143// static 166// static
144void LLTexLayerSetBuffer::dumpTotalByteCount() 167void LLTexLayerSetBuffer::dumpTotalByteCount()
145{ 168{
@@ -248,7 +271,7 @@ BOOL LLTexLayerSetBuffer::render()
248 BOOL success = TRUE; 271 BOOL success = TRUE;
249 272
250 // Composite bump 273 // Composite bump
251 if( mBumpTexName ) 274 if( mBumpTex.notNull() )
252 { 275 {
253 // Composite the bump data 276 // Composite the bump data
254 success &= mTexLayerSet->renderBump( mOrigin.mX, mOrigin.mY, mWidth, mHeight ); 277 success &= mTexLayerSet->renderBump( mOrigin.mX, mOrigin.mY, mWidth, mHeight );
@@ -259,7 +282,7 @@ BOOL LLTexLayerSetBuffer::render()
259 LLGLSUIDefault gls_ui; 282 LLGLSUIDefault gls_ui;
260 283
261 // read back into texture (this is done externally for the color data) 284 // read back into texture (this is done externally for the color data)
262 LLImageGL::bindExternalTexture( mBumpTexName, 0, GL_TEXTURE_2D ); 285 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName());
263 stop_glerror(); 286 stop_glerror();
264 287
265 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mOrigin.mX, mOrigin.mY, mWidth, mHeight); 288 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mOrigin.mX, mOrigin.mY, mWidth, mHeight);
@@ -299,12 +322,17 @@ BOOL LLTexLayerSetBuffer::render()
299 gGL.setSceneBlendType(LLRender::BT_ALPHA); 322 gGL.setSceneBlendType(LLRender::BT_ALPHA);
300 323
301 // we have valid texture data now 324 // we have valid texture data now
302 mInitialized = TRUE; 325 mTexture->setGLTextureCreated(true);
303 mNeedsUpdate = FALSE; 326 mNeedsUpdate = FALSE;
304 327
305 return success; 328 return success;
306} 329}
307 330
331bool LLTexLayerSetBuffer::isInitialized(void) const
332{
333 return mTexture.notNull() && mTexture->isGLTextureCreated();
334}
335
308BOOL LLTexLayerSetBuffer::updateImmediate() 336BOOL LLTexLayerSetBuffer::updateImmediate()
309{ 337{
310 mNeedsUpdate = TRUE; 338 mNeedsUpdate = TRUE;
@@ -350,11 +378,11 @@ void LLTexLayerSetBuffer::readBackAndUpload(U8* baked_bump_data)
350 // writes into baked_color_data 378 // writes into baked_color_data
351 const char* comment_text = NULL; 379 const char* comment_text = NULL;
352 380
353 S32 baked_image_components = mBumpTexName ? 5 : 4; // red green blue [bump] clothing 381 S32 baked_image_components = mBumpTex.notNull() ? 5 : 4; // red green blue [bump] clothing
354 LLPointer<LLImageRaw> baked_image = new LLImageRaw( mWidth, mHeight, baked_image_components ); 382 LLPointer<LLImageRaw> baked_image = new LLImageRaw( mWidth, mHeight, baked_image_components );
355 U8* baked_image_data = baked_image->getData(); 383 U8* baked_image_data = baked_image->getData();
356 384
357 if( mBumpTexName ) 385 if( mBumpTex.notNull() )
358 { 386 {
359 comment_text = LINDEN_J2C_COMMENT_PREFIX "RGBHM"; // 5 channels: rgb, heightfield/alpha, mask 387 comment_text = LINDEN_J2C_COMMENT_PREFIX "RGBHM"; // 5 channels: rgb, heightfield/alpha, mask
360 388
@@ -551,24 +579,12 @@ void LLTexLayerSetBuffer::onTextureUploadComplete(const LLUUID& uuid, void* user
551 delete baked_upload_data; 579 delete baked_upload_data;
552} 580}
553 581
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 ) 582void LLTexLayerSetBuffer::bindBumpTexture( U32 stage )
568{ 583{
569 if( mBumpTexName ) 584 if( mBumpTex.notNull() )
570 { 585 {
571 LLImageGL::bindExternalTexture(mBumpTexName, stage, GL_TEXTURE_2D); 586 gGL.getTexUnit(stage)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName());
587 gGL.getTexUnit(0)->activate();
572 588
573 if( mLastBindTime != LLImageGL::sLastFrameTime ) 589 if( mLastBindTime != LLImageGL::sLastFrameTime )
574 { 590 {
@@ -578,7 +594,8 @@ void LLTexLayerSetBuffer::bindBumpTexture( U32 stage )
578 } 594 }
579 else 595 else
580 { 596 {
581 LLImageGL::unbindTexture(stage, GL_TEXTURE_2D); 597 gGL.getTexUnit(stage)->unbind(LLTexUnit::TT_TEXTURE);
598 gGL.getTexUnit(0)->activate();
582 } 599 }
583} 600}
584 601
@@ -786,7 +803,7 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height )
786 if( image_gl ) 803 if( image_gl )
787 { 804 {
788 LLGLSUIDefault gls_ui; 805 LLGLSUIDefault gls_ui;
789 image_gl->bind(); 806 gGL.getTexUnit(0)->bind(image_gl);
790 gl_rect_2d_simple_tex( width, height ); 807 gl_rect_2d_simple_tex( width, height );
791 } 808 }
792 else 809 else
@@ -794,7 +811,7 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height )
794 success = FALSE; 811 success = FALSE;
795 } 812 }
796 } 813 }
797 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 814 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
798 815
799 gGL.flush(); 816 gGL.flush();
800 gGL.setColorMask(true, true); 817 gGL.setColorMask(true, true);
@@ -804,7 +821,8 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height )
804 if( getInfo()->mClearAlpha ) 821 if( getInfo()->mClearAlpha )
805 { 822 {
806 // Set the alpha channel to one (clean up after previous blending) 823 // Set the alpha channel to one (clean up after previous blending)
807 LLGLSNoTextureNoAlphaTest gls_no_alpha; 824 LLGLDisable no_alpha(GL_ALPHA_TEST);
825 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
808 gGL.color4f( 0.f, 0.f, 0.f, 1.f ); 826 gGL.color4f( 0.f, 0.f, 0.f, 1.f );
809 gGL.flush(); 827 gGL.flush();
810 gGL.setColorMask(false, true); 828 gGL.setColorMask(false, true);
@@ -838,7 +856,8 @@ BOOL LLTexLayerSet::renderBump( S32 x, S32 y, S32 width, S32 height )
838 } 856 }
839 857
840 // Set the alpha channel to one (clean up after previous blending) 858 // Set the alpha channel to one (clean up after previous blending)
841 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha; 859 LLGLDisable no_alpha(GL_ALPHA_TEST);
860 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
842 gGL.color4f( 0.f, 0.f, 0.f, 1.f ); 861 gGL.color4f( 0.f, 0.f, 0.f, 1.f );
843 gGL.setColorMask(false, true); 862 gGL.setColorMask(false, true);
844 863
@@ -1358,13 +1377,13 @@ BOOL LLTexLayer::render( S32 x, S32 y, S32 width, S32 height )
1358 BOOL old_clamps = image_gl->getClampS(); 1377 BOOL old_clamps = image_gl->getClampS();
1359 BOOL old_clampt = image_gl->getClampT(); 1378 BOOL old_clampt = image_gl->getClampT();
1360 1379
1361 image_gl->bind(); 1380 gGL.getTexUnit(0)->bind(image_gl);
1362 image_gl->setClamp(TRUE, TRUE); 1381 image_gl->setClamp(TRUE, TRUE);
1363 1382
1364 gl_rect_2d_simple_tex( width, height ); 1383 gl_rect_2d_simple_tex( width, height );
1365 1384
1366 image_gl->setClamp(old_clamps, old_clampt); 1385 image_gl->setClamp(old_clamps, old_clampt);
1367 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1386 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1368 } 1387 }
1369 } 1388 }
1370 else 1389 else
@@ -1380,9 +1399,9 @@ BOOL LLTexLayer::render( S32 x, S32 y, S32 width, S32 height )
1380 LLImageGL* image_gl = gTexStaticImageList.getImageGL( getInfo()->mStaticImageFileName, getInfo()->mStaticImageIsMask ); 1399 LLImageGL* image_gl = gTexStaticImageList.getImageGL( getInfo()->mStaticImageFileName, getInfo()->mStaticImageIsMask );
1381 if( image_gl ) 1400 if( image_gl )
1382 { 1401 {
1383 image_gl->bind(); 1402 gGL.getTexUnit(0)->bind(image_gl);
1384 gl_rect_2d_simple_tex( width, height ); 1403 gl_rect_2d_simple_tex( width, height );
1385 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1404 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1386 } 1405 }
1387 else 1406 else
1388 { 1407 {
@@ -1396,7 +1415,8 @@ BOOL LLTexLayer::render( S32 x, S32 y, S32 width, S32 height )
1396 getInfo()->mStaticImageFileName.empty() && 1415 getInfo()->mStaticImageFileName.empty() &&
1397 color_specified ) 1416 color_specified )
1398 { 1417 {
1399 LLGLSNoTextureNoAlphaTest gls; 1418 LLGLDisable no_alpha(GL_ALPHA_TEST);
1419 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1400 gGL.color4fv( net_color.mV); 1420 gGL.color4fv( net_color.mV);
1401 gl_rect_2d_simple( width, height ); 1421 gl_rect_2d_simple( width, height );
1402 } 1422 }
@@ -1518,7 +1538,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 1538 // Note: if the first param is a mulitply, multiply against the current buffer's alpha
1519 if( !first_param || !first_param->getMultiplyBlend() ) 1539 if( !first_param || !first_param->getMultiplyBlend() )
1520 { 1540 {
1521 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha_test; 1541 LLGLDisable no_alpha(GL_ALPHA_TEST);
1542 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1522 1543
1523 // Clear the alpha 1544 // Clear the alpha
1524 gGL.flush(); 1545 gGL.flush();
@@ -1555,13 +1576,13 @@ BOOL LLTexLayer::renderAlphaMasks( S32 x, S32 y, S32 width, S32 height, LLColor4
1555 1576
1556 BOOL old_clamps = image_gl->getClampS(); 1577 BOOL old_clamps = image_gl->getClampS();
1557 BOOL old_clampt = image_gl->getClampT(); 1578 BOOL old_clampt = image_gl->getClampT();
1558 image_gl->bind(); 1579 gGL.getTexUnit(0)->bind(image_gl);
1559 image_gl->setClamp(TRUE, TRUE); 1580 image_gl->setClamp(TRUE, TRUE);
1560 1581
1561 gl_rect_2d_simple_tex( width, height ); 1582 gl_rect_2d_simple_tex( width, height );
1562 1583
1563 image_gl->setClamp(old_clamps, old_clampt); 1584 image_gl->setClamp(old_clamps, old_clampt);
1564 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1585 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1565 } 1586 }
1566 } 1587 }
1567 else 1588 else
@@ -1581,9 +1602,9 @@ BOOL LLTexLayer::renderAlphaMasks( S32 x, S32 y, S32 width, S32 height, LLColor4
1581 ( (image_gl->getComponents() == 1) && getInfo()->mStaticImageIsMask ) ) 1602 ( (image_gl->getComponents() == 1) && getInfo()->mStaticImageIsMask ) )
1582 { 1603 {
1583 LLGLSNoAlphaTest gls_no_alpha_test; 1604 LLGLSNoAlphaTest gls_no_alpha_test;
1584 image_gl->bind(); 1605 gGL.getTexUnit(0)->bind(image_gl);
1585 gl_rect_2d_simple_tex( width, height ); 1606 gl_rect_2d_simple_tex( width, height );
1586 image_gl->unbindTexture(0, GL_TEXTURE_2D); 1607 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1587 } 1608 }
1588 } 1609 }
1589 else 1610 else
@@ -1597,7 +1618,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 ); 1618 // Note: we're still using gGL.blendFunc( GL_DST_ALPHA, GL_ZERO );
1598 if( colorp->mV[VW] != 1.f ) 1619 if( colorp->mV[VW] != 1.f )
1599 { 1620 {
1600 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha_test; 1621 LLGLDisable no_alpha(GL_ALPHA_TEST);
1622 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1601 gGL.color4fv( colorp->mV ); 1623 gGL.color4fv( colorp->mV );
1602 gl_rect_2d_simple( width, height ); 1624 gl_rect_2d_simple( width, height );
1603 } 1625 }
@@ -1700,7 +1722,7 @@ BOOL LLTexLayer::renderImageRaw( U8* in_data, S32 in_width, S32 in_height, S32 i
1700 glGenTextures(1, &name ); 1722 glGenTextures(1, &name );
1701 stop_glerror(); 1723 stop_glerror();
1702 1724
1703 LLImageGL::bindExternalTexture( name, 0, GL_TEXTURE_2D ); 1725 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, name);
1704 stop_glerror(); 1726 stop_glerror();
1705 1727
1706 glTexImage2D( 1728 glTexImage2D(
@@ -1712,12 +1734,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); 1734 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1713 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1735 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1714 1736
1715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1737 gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
1716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1717 1738
1718 gl_rect_2d_simple_tex( width, height ); 1739 gl_rect_2d_simple_tex( width, height );
1719 1740
1720 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 1741 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1721 1742
1722 glDeleteTextures(1, &name ); 1743 glDeleteTextures(1, &name );
1723 stop_glerror(); 1744 stop_glerror();
@@ -1736,7 +1757,7 @@ BOOL LLTexLayer::renderImageRaw( U8* in_data, S32 in_width, S32 in_height, S32 i
1736 1757
1737 gl_rect_2d_simple_tex( width, height ); 1758 gl_rect_2d_simple_tex( width, height );
1738 1759
1739 LLImageGL::unbindTexture(0, GL_TEXTURE_2D); 1760 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
1740 } 1761 }
1741 1762
1742 return TRUE; 1763 return TRUE;
@@ -1800,8 +1821,6 @@ BOOL LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node)
1800 static LLStdStringHandle domain_string = LLXmlTree::addAttributeString("domain"); 1821 static LLStdStringHandle domain_string = LLXmlTree::addAttributeString("domain");
1801 param_alpha_node->getFastAttributeF32( domain_string, mDomain ); 1822 param_alpha_node->getFastAttributeF32( domain_string, mDomain );
1802 1823
1803 gGradientPaletteList.initPalette(mDomain);
1804
1805 return TRUE; 1824 return TRUE;
1806} 1825}
1807 1826
@@ -1996,7 +2015,7 @@ BOOL LLTexLayerParamAlpha::render( S32 x, S32 y, S32 width, S32 height )
1996 if( !mCachedProcessedImageGL || 2015 if( !mCachedProcessedImageGL ||
1997 (mCachedProcessedImageGL->getWidth() != image_tga_width) || 2016 (mCachedProcessedImageGL->getWidth() != image_tga_width) ||
1998 (mCachedProcessedImageGL->getHeight() != image_tga_height) || 2017 (mCachedProcessedImageGL->getHeight() != image_tga_height) ||
1999 (weight_changed && !(gGLManager.mHasPalettedTextures && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_PALETTE))) ) 2018 (weight_changed ))
2000 { 2019 {
2001// llinfos << "Building Cached Alpha: " << mName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << effective_weight << llendl; 2020// llinfos << "Building Cached Alpha: " << mName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << effective_weight << llendl;
2002 mCachedEffectiveWeight = effective_weight; 2021 mCachedEffectiveWeight = effective_weight;
@@ -2008,71 +2027,34 @@ BOOL LLTexLayerParamAlpha::render( S32 x, S32 y, S32 width, S32 height )
2008 // We now have something in one of our caches 2027 // We now have something in one of our caches
2009 LLTexLayerSet::sHasCaches |= mCachedProcessedImageGL ? TRUE : FALSE; 2028 LLTexLayerSet::sHasCaches |= mCachedProcessedImageGL ? TRUE : FALSE;
2010 2029
2011 if (gGLManager.mHasPalettedTextures && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_PALETTE)) 2030
2012 { 2031 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 } 2032 }
2021 2033
2022 // Applies domain and effective weight to data as it is decoded. Also resizes the raw image if needed. 2034 // 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)) 2035 mStaticImageRaw = NULL;
2024 { 2036 mStaticImageRaw = new LLImageRaw;
2025 mStaticImageRaw = NULL; 2037 mStaticImageTGA->decodeAndProcess( mStaticImageRaw, getInfo()->mDomain, effective_weight );
2026 mStaticImageRaw = new LLImageRaw; 2038 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 } 2039 }
2038 2040
2039 if( mCachedProcessedImageGL ) 2041 if( mCachedProcessedImageGL )
2040 { 2042 {
2041 { 2043 {
2042 if (gGLManager.mHasPalettedTextures && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_PALETTE)) 2044 // Create the GL texture, and then hang onto it for future use.
2045 if( mNeedsCreateTexture )
2043 { 2046 {
2044 if( mNeedsCreateTexture ) 2047 mCachedProcessedImageGL->createGLTexture(0, mStaticImageRaw);
2045 { 2048 mNeedsCreateTexture = FALSE;
2046 mCachedProcessedImageGL->createGLTexture(0, mStaticImageRaw); 2049
2047 mNeedsCreateTexture = FALSE; 2050 gGL.getTexUnit(0)->bind(mCachedProcessedImageGL);
2048 2051 mCachedProcessedImageGL->setClamp(TRUE, TRUE);
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 {
2061 // Create the GL texture, and then hang onto it for future use.
2062 if( mNeedsCreateTexture )
2063 {
2064 mCachedProcessedImageGL->createGLTexture(0, mStaticImageRaw);
2065 mNeedsCreateTexture = FALSE;
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 } 2052 }
2053
2054 LLGLSNoAlphaTest gls_no_alpha_test;
2055 gGL.getTexUnit(0)->bind(mCachedProcessedImageGL);
2056 gl_rect_2d_simple_tex( width, height );
2057 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
2076 stop_glerror(); 2058 stop_glerror();
2077 } 2059 }
2078 } 2060 }
@@ -2086,7 +2068,8 @@ BOOL LLTexLayerParamAlpha::render( S32 x, S32 y, S32 width, S32 height )
2086 } 2068 }
2087 else 2069 else
2088 { 2070 {
2089 LLGLSNoTextureNoAlphaTest gls_no_texture_no_alpha_test; 2071 LLGLDisable no_alpha(GL_ALPHA_TEST);
2072 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
2090 gGL.color4f( 0.f, 0.f, 0.f, effective_weight ); 2073 gGL.color4f( 0.f, 0.f, 0.f, effective_weight );
2091 gl_rect_2d_simple( width, height ); 2074 gl_rect_2d_simple( width, height );
2092 } 2075 }
@@ -2519,7 +2502,7 @@ LLImageGL* LLTexStaticImageList::getImageGL(const std::string& file_name, BOOL i
2519 } 2502 }
2520 image_gl->createGLTexture(0, image_raw); 2503 image_gl->createGLTexture(0, image_raw);
2521 2504
2522 image_gl->bind(); 2505 gGL.getTexUnit(0)->bind(image_gl);
2523 image_gl->setClamp(TRUE, TRUE); 2506 image_gl->setClamp(TRUE, TRUE);
2524 2507
2525 mStaticImageListGL [ namekey ] = image_gl; 2508 mStaticImageListGL [ namekey ] = image_gl;
@@ -2559,68 +2542,3 @@ LLMaskedMorph::LLMaskedMorph( LLPolyMorphTarget *morph_target, BOOL invert ) : m
2559 morph_target->addPendingMorphMask(); 2542 morph_target->addPendingMorphMask();
2560} 2543}
2561 2544
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}