aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltexlayer.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2009-01-11 16:10:39 -0600
committerJacek Antonelli2009-01-11 16:10:43 -0600
commita87e38229921b48c32187c672a942516722f1b52 (patch)
tree9e1dc0bc2318a9c6fa454bdb6d873a6af0e0ce3c /linden/indra/newview/lltexlayer.cpp
parentSecond Life viewer sources 1.22.4-RC (diff)
downloadmeta-impy-a87e38229921b48c32187c672a942516722f1b52.zip
meta-impy-a87e38229921b48c32187c672a942516722f1b52.tar.gz
meta-impy-a87e38229921b48c32187c672a942516722f1b52.tar.bz2
meta-impy-a87e38229921b48c32187c672a942516722f1b52.tar.xz
Second Life viewer sources 1.22.5-RC
Diffstat (limited to 'linden/indra/newview/lltexlayer.cpp')
-rw-r--r--linden/indra/newview/lltexlayer.cpp87
1 files changed, 57 insertions, 30 deletions
diff --git a/linden/indra/newview/lltexlayer.cpp b/linden/indra/newview/lltexlayer.cpp
index a687344..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
@@ -93,17 +93,59 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h
93 mNeedsUpdate( TRUE ), 93 mNeedsUpdate( TRUE ),
94 mNeedsUpload( FALSE ), 94 mNeedsUpload( FALSE ),
95 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
96 mTexLayerSet( owner ), 96 mTexLayerSet( owner )
97 mBumpTexName(0)
98{ 97{
99 LLTexLayerSetBuffer::sGLByteCount += getSize(); 98 LLTexLayerSetBuffer::sGLByteCount += getSize();
99 mHasBump = has_bump ;
100 mBumpTex = NULL ;
100 101
101 if( has_bump ) 102 createBumpTexture() ;
103}
104
105LLTexLayerSetBuffer::~LLTexLayerSetBuffer()
106{
107 LLTexLayerSetBuffer::sGLByteCount -= getSize();
108
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 )
102 { 139 {
103 LLGLSUIDefault gls_ui; 140 LLGLSUIDefault gls_ui;
104 glGenTextures(1, (GLuint*) &mBumpTexName); 141 mBumpTex = new LLImageGL(FALSE) ;
142 if(!mBumpTex->createGLTexture())
143 {
144 mBumpTex = NULL ;
145 return ;
146 }
105 147
106 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName); 148 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName());
107 stop_glerror(); 149 stop_glerror();
108 150
109 gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); 151 gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
@@ -111,7 +153,7 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h
111 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 153 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
112 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 154 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
113 155
114 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);
115 stop_glerror(); 157 stop_glerror();
116 158
117 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); 159 gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
@@ -121,21 +163,6 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h
121 } 163 }
122} 164}
123 165
124LLTexLayerSetBuffer::~LLTexLayerSetBuffer()
125{
126 LLTexLayerSetBuffer::sGLByteCount -= getSize();
127
128 if( mBumpTexName )
129 {
130 glDeleteTextures(1, (GLuint*) &mBumpTexName);
131 stop_glerror();
132 mBumpTexName = 0;
133
134 LLImageGL::sGlobalTextureMemory -= mWidth * mHeight * 4;
135 LLTexLayerSetBuffer::sGLBumpByteCount -= mWidth * mHeight * 4;
136 }
137}
138
139// static 166// static
140void LLTexLayerSetBuffer::dumpTotalByteCount() 167void LLTexLayerSetBuffer::dumpTotalByteCount()
141{ 168{
@@ -244,7 +271,7 @@ BOOL LLTexLayerSetBuffer::render()
244 BOOL success = TRUE; 271 BOOL success = TRUE;
245 272
246 // Composite bump 273 // Composite bump
247 if( mBumpTexName ) 274 if( mBumpTex.notNull() )
248 { 275 {
249 // Composite the bump data 276 // Composite the bump data
250 success &= mTexLayerSet->renderBump( mOrigin.mX, mOrigin.mY, mWidth, mHeight ); 277 success &= mTexLayerSet->renderBump( mOrigin.mX, mOrigin.mY, mWidth, mHeight );
@@ -255,7 +282,7 @@ BOOL LLTexLayerSetBuffer::render()
255 LLGLSUIDefault gls_ui; 282 LLGLSUIDefault gls_ui;
256 283
257 // 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)
258 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName); 285 gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName());
259 stop_glerror(); 286 stop_glerror();
260 287
261 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);
@@ -295,7 +322,7 @@ BOOL LLTexLayerSetBuffer::render()
295 gGL.setSceneBlendType(LLRender::BT_ALPHA); 322 gGL.setSceneBlendType(LLRender::BT_ALPHA);
296 323
297 // we have valid texture data now 324 // we have valid texture data now
298 mTexture->setInitialized(true); 325 mTexture->setGLTextureCreated(true);
299 mNeedsUpdate = FALSE; 326 mNeedsUpdate = FALSE;
300 327
301 return success; 328 return success;
@@ -303,7 +330,7 @@ BOOL LLTexLayerSetBuffer::render()
303 330
304bool LLTexLayerSetBuffer::isInitialized(void) const 331bool LLTexLayerSetBuffer::isInitialized(void) const
305{ 332{
306 return mTexture->isInitialized(); 333 return mTexture.notNull() && mTexture->isGLTextureCreated();
307} 334}
308 335
309BOOL LLTexLayerSetBuffer::updateImmediate() 336BOOL LLTexLayerSetBuffer::updateImmediate()
@@ -351,11 +378,11 @@ void LLTexLayerSetBuffer::readBackAndUpload(U8* baked_bump_data)
351 // writes into baked_color_data 378 // writes into baked_color_data
352 const char* comment_text = NULL; 379 const char* comment_text = NULL;
353 380
354 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
355 LLPointer<LLImageRaw> baked_image = new LLImageRaw( mWidth, mHeight, baked_image_components ); 382 LLPointer<LLImageRaw> baked_image = new LLImageRaw( mWidth, mHeight, baked_image_components );
356 U8* baked_image_data = baked_image->getData(); 383 U8* baked_image_data = baked_image->getData();
357 384
358 if( mBumpTexName ) 385 if( mBumpTex.notNull() )
359 { 386 {
360 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
361 388
@@ -554,9 +581,9 @@ void LLTexLayerSetBuffer::onTextureUploadComplete(const LLUUID& uuid, void* user
554 581
555void LLTexLayerSetBuffer::bindBumpTexture( U32 stage ) 582void LLTexLayerSetBuffer::bindBumpTexture( U32 stage )
556{ 583{
557 if( mBumpTexName ) 584 if( mBumpTex.notNull() )
558 { 585 {
559 gGL.getTexUnit(stage)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName); 586 gGL.getTexUnit(stage)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName());
560 gGL.getTexUnit(0)->activate(); 587 gGL.getTexUnit(0)->activate();
561 588
562 if( mLastBindTime != LLImageGL::sLastFrameTime ) 589 if( mLastBindTime != LLImageGL::sLastFrameTime )