From a87e38229921b48c32187c672a942516722f1b52 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sun, 11 Jan 2009 16:10:39 -0600 Subject: Second Life viewer sources 1.22.5-RC --- linden/indra/newview/lltexlayer.cpp | 87 ++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 30 deletions(-) (limited to 'linden/indra/newview/lltexlayer.cpp') 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 @@ * * $LicenseInfo:firstyear=2002&license=viewergpl$ * - * Copyright (c) 2002-2008, Linden Research, Inc. + * Copyright (c) 2002-2009, Linden Research, Inc. * * Second Life Viewer Source Code * 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 mNeedsUpdate( TRUE ), mNeedsUpload( FALSE ), mUploadPending( FALSE ), // Not used for any logic here, just to sync sending of updates - mTexLayerSet( owner ), - mBumpTexName(0) + mTexLayerSet( owner ) { LLTexLayerSetBuffer::sGLByteCount += getSize(); + mHasBump = has_bump ; + mBumpTex = NULL ; - if( has_bump ) + createBumpTexture() ; +} + +LLTexLayerSetBuffer::~LLTexLayerSetBuffer() +{ + LLTexLayerSetBuffer::sGLByteCount -= getSize(); + + if( mBumpTex.notNull()) + { + mBumpTex = NULL ; + LLImageGL::sGlobalTextureMemory -= mWidth * mHeight * 4; + LLTexLayerSetBuffer::sGLBumpByteCount -= mWidth * mHeight * 4; + } +} +//virtual +void LLTexLayerSetBuffer::restoreGLTexture() +{ + createBumpTexture() ; + LLDynamicTexture::restoreGLTexture() ; +} + +//virtual +void LLTexLayerSetBuffer::destroyGLTexture() +{ + if( mBumpTex.notNull() ) + { + mBumpTex = NULL ; + LLImageGL::sGlobalTextureMemory -= mWidth * mHeight * 4; + LLTexLayerSetBuffer::sGLBumpByteCount -= mWidth * mHeight * 4; + } + + LLDynamicTexture::destroyGLTexture() ; +} + +void LLTexLayerSetBuffer::createBumpTexture() +{ + if( mHasBump ) { LLGLSUIDefault gls_ui; - glGenTextures(1, (GLuint*) &mBumpTexName); + mBumpTex = new LLImageGL(FALSE) ; + if(!mBumpTex->createGLTexture()) + { + mBumpTex = NULL ; + return ; + } - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName()); stop_glerror(); gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); @@ -111,7 +153,7 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); stop_glerror(); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); @@ -121,21 +163,6 @@ LLTexLayerSetBuffer::LLTexLayerSetBuffer( LLTexLayerSet* owner, S32 width, S32 h } } -LLTexLayerSetBuffer::~LLTexLayerSetBuffer() -{ - LLTexLayerSetBuffer::sGLByteCount -= getSize(); - - if( mBumpTexName ) - { - glDeleteTextures(1, (GLuint*) &mBumpTexName); - stop_glerror(); - mBumpTexName = 0; - - LLImageGL::sGlobalTextureMemory -= mWidth * mHeight * 4; - LLTexLayerSetBuffer::sGLBumpByteCount -= mWidth * mHeight * 4; - } -} - // static void LLTexLayerSetBuffer::dumpTotalByteCount() { @@ -244,7 +271,7 @@ BOOL LLTexLayerSetBuffer::render() BOOL success = TRUE; // Composite bump - if( mBumpTexName ) + if( mBumpTex.notNull() ) { // Composite the bump data success &= mTexLayerSet->renderBump( mOrigin.mX, mOrigin.mY, mWidth, mHeight ); @@ -255,7 +282,7 @@ BOOL LLTexLayerSetBuffer::render() LLGLSUIDefault gls_ui; // read back into texture (this is done externally for the color data) - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName()); stop_glerror(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mOrigin.mX, mOrigin.mY, mWidth, mHeight); @@ -295,7 +322,7 @@ BOOL LLTexLayerSetBuffer::render() gGL.setSceneBlendType(LLRender::BT_ALPHA); // we have valid texture data now - mTexture->setInitialized(true); + mTexture->setGLTextureCreated(true); mNeedsUpdate = FALSE; return success; @@ -303,7 +330,7 @@ BOOL LLTexLayerSetBuffer::render() bool LLTexLayerSetBuffer::isInitialized(void) const { - return mTexture->isInitialized(); + return mTexture.notNull() && mTexture->isGLTextureCreated(); } BOOL LLTexLayerSetBuffer::updateImmediate() @@ -351,11 +378,11 @@ void LLTexLayerSetBuffer::readBackAndUpload(U8* baked_bump_data) // writes into baked_color_data const char* comment_text = NULL; - S32 baked_image_components = mBumpTexName ? 5 : 4; // red green blue [bump] clothing + S32 baked_image_components = mBumpTex.notNull() ? 5 : 4; // red green blue [bump] clothing LLPointer baked_image = new LLImageRaw( mWidth, mHeight, baked_image_components ); U8* baked_image_data = baked_image->getData(); - if( mBumpTexName ) + if( mBumpTex.notNull() ) { comment_text = LINDEN_J2C_COMMENT_PREFIX "RGBHM"; // 5 channels: rgb, heightfield/alpha, mask @@ -554,9 +581,9 @@ void LLTexLayerSetBuffer::onTextureUploadComplete(const LLUUID& uuid, void* user void LLTexLayerSetBuffer::bindBumpTexture( U32 stage ) { - if( mBumpTexName ) + if( mBumpTex.notNull() ) { - gGL.getTexUnit(stage)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTexName); + gGL.getTexUnit(stage)->bindManual(LLTexUnit::TT_TEXTURE, mBumpTex->getTexName()); gGL.getTexUnit(0)->activate(); if( mLastBindTime != LLImageGL::sLastFrameTime ) -- cgit v1.1