From 70f8dc7a4f4be217fea5439e474fc75e567c23c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20N=C3=A6sbye=20Christensen?= Date: Sat, 10 Feb 2024 22:37:52 +0100 Subject: miscellaneous: BOOL (int) to real bool --- indra/llappearance/lltexlayerparams.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'indra/llappearance/lltexlayerparams.cpp') diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp index 604e0124cb..16369533ca 100644 --- a/indra/llappearance/lltexlayerparams.cpp +++ b/indra/llappearance/lltexlayerparams.cpp @@ -79,7 +79,7 @@ BOOL LLTexLayerParam::setInfo(LLViewerVisualParamInfo *info, BOOL add_to_appeara this->setParamLocation(mAvatarAppearance->isSelf() ? LOC_AV_SELF : LOC_AV_OTHER); } - return TRUE; + return true; } @@ -235,7 +235,7 @@ BOOL LLTexLayerParamAlpha::getSkip() const { if (!mTexLayer) { - return TRUE; + return true; } const LLAvatarAppearance *appearance = mTexLayer->getTexLayerSet()->getAvatarAppearance(); @@ -245,24 +245,24 @@ BOOL LLTexLayerParamAlpha::getSkip() const F32 effective_weight = (appearance->getSex() & getSex()) ? mCurWeight : getDefaultWeight(); if (is_approx_zero(effective_weight)) { - return TRUE; + return true; } } LLWearableType::EType type = (LLWearableType::EType)getWearableType(); if ((type != LLWearableType::WT_INVALID) && !appearance->isWearingWearableType(type)) { - return TRUE; + return true; } - return FALSE; + return false; } BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) { LL_PROFILE_ZONE_SCOPED; - BOOL success = TRUE; + BOOL success = true; if (!mTexLayer) { @@ -300,7 +300,7 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) { LL_WARNS() << "Unable to load static file: " << info->mStaticImageFileName << LL_ENDL; mStaticImageInvalid = TRUE; // don't try again. - return FALSE; + return false; } } @@ -383,12 +383,12 @@ BOOL LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node) llassert(node->hasName("param") && node->getChildByName("param_alpha")); if (!LLViewerVisualParamInfo::parseXml(node)) - return FALSE; + return false; LLXmlTreeNode* param_alpha_node = node->getChildByName("param_alpha"); if (!param_alpha_node) { - return FALSE; + return false; } static LLStdStringHandle tga_file_string = LLXmlTree::addAttributeString("tga_file"); @@ -410,7 +410,7 @@ BOOL LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node) static LLStdStringHandle domain_string = LLXmlTree::addAttributeString("domain"); param_alpha_node->getFastAttributeF32(domain_string, mDomain); - return TRUE; + return true; } @@ -543,12 +543,12 @@ BOOL LLTexLayerParamColorInfo::parseXml(LLXmlTreeNode *node) llassert(node->hasName("param") && node->getChildByName("param_color")); if (!LLViewerVisualParamInfo::parseXml(node)) - return FALSE; + return false; LLXmlTreeNode* param_color_node = node->getChildByName("param_color"); if (!param_color_node) { - return FALSE; + return false; } std::string op_string; @@ -581,14 +581,14 @@ BOOL LLTexLayerParamColorInfo::parseXml(LLXmlTreeNode *node) if (!mNumColors) { LL_WARNS() << " is missing sub-elements" << LL_ENDL; - return FALSE; + return false; } if ((mOperation == LLTexLayerParamColor::OP_BLEND) && (mNumColors != 1)) { LL_WARNS() << " with operation\"blend\" must have exactly one " << LL_ENDL; - return FALSE; + return false; } - return TRUE; + return true; } -- cgit v1.2.3 From 4419bb870986c6900fc096338622d27b999cd771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20N=C3=A6sbye=20Christensen?= Date: Sun, 11 Feb 2024 01:23:28 +0100 Subject: more misc: BOOL (int) to real bool --- indra/llappearance/lltexlayerparams.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llappearance/lltexlayerparams.cpp') diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp index 16369533ca..4cfbdc01c1 100644 --- a/indra/llappearance/lltexlayerparams.cpp +++ b/indra/llappearance/lltexlayerparams.cpp @@ -378,7 +378,7 @@ LLTexLayerParamAlphaInfo::LLTexLayerParamAlphaInfo() : { } -BOOL LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node) +bool LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node) { llassert(node->hasName("param") && node->getChildByName("param_alpha")); @@ -538,7 +538,7 @@ LLTexLayerParamColorInfo::LLTexLayerParamColorInfo() : { } -BOOL LLTexLayerParamColorInfo::parseXml(LLXmlTreeNode *node) +bool LLTexLayerParamColorInfo::parseXml(LLXmlTreeNode *node) { llassert(node->hasName("param") && node->getChildByName("param_color")); -- cgit v1.2.3 From 9e854b697a06abed2a0917fb6120445f176764f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20N=C3=A6sbye=20Christensen?= Date: Fri, 16 Feb 2024 19:29:51 +0100 Subject: misc: BOOL to bool --- indra/llappearance/lltexlayerparams.cpp | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'indra/llappearance/lltexlayerparams.cpp') diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp index 4cfbdc01c1..8ad718a506 100644 --- a/indra/llappearance/lltexlayerparams.cpp +++ b/indra/llappearance/lltexlayerparams.cpp @@ -69,7 +69,7 @@ LLTexLayerParam::LLTexLayerParam(const LLTexLayerParam& pOther) { } -BOOL LLTexLayerParam::setInfo(LLViewerVisualParamInfo *info, BOOL add_to_appearance) +bool LLTexLayerParam::setInfo(LLViewerVisualParamInfo *info, bool add_to_appearance) { LLViewerVisualParam::setInfo(info); @@ -123,8 +123,8 @@ LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLTexLayerInterface* layer) mCachedProcessedTexture(NULL), mStaticImageTGA(), mStaticImageRaw(), - mNeedsCreateTexture(FALSE), - mStaticImageInvalid(FALSE), + mNeedsCreateTexture(false), + mStaticImageInvalid(false), mAvgDistortionVec(1.f, 1.f, 1.f), mCachedEffectiveWeight(0.f) { @@ -136,8 +136,8 @@ LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLAvatarAppearance* appearance) mCachedProcessedTexture(NULL), mStaticImageTGA(), mStaticImageRaw(), - mNeedsCreateTexture(FALSE), - mStaticImageInvalid(FALSE), + mNeedsCreateTexture(false), + mStaticImageInvalid(false), mAvgDistortionVec(1.f, 1.f, 1.f), mCachedEffectiveWeight(0.f) { @@ -173,10 +173,10 @@ void LLTexLayerParamAlpha::deleteCaches() mStaticImageTGA = NULL; // deletes image mCachedProcessedTexture = NULL; mStaticImageRaw = NULL; - mNeedsCreateTexture = FALSE; + mNeedsCreateTexture = false; } -BOOL LLTexLayerParamAlpha::getMultiplyBlend() const +bool LLTexLayerParamAlpha::getMultiplyBlend() const { return ((LLTexLayerParamAlphaInfo *)getInfo())->mMultiplyBlend; } @@ -216,7 +216,7 @@ void LLTexLayerParamAlpha::setAnimationTarget(F32 target_value) mTargetWeight = target_value; setWeight(target_value); - mIsAnimating = TRUE; + mIsAnimating = true; if (mNext) { mNext->setAnimationTarget(target_value); @@ -231,7 +231,7 @@ void LLTexLayerParamAlpha::animate(F32 delta) } } -BOOL LLTexLayerParamAlpha::getSkip() const +bool LLTexLayerParamAlpha::getSkip() const { if (!mTexLayer) { @@ -259,10 +259,10 @@ BOOL LLTexLayerParamAlpha::getSkip() const } -BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) +bool LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) { LL_PROFILE_ZONE_SCOPED; - BOOL success = true; + bool success = true; if (!mTexLayer) { @@ -270,7 +270,7 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) } F32 effective_weight = (mTexLayer->getTexLayerSet()->getAvatarAppearance()->getSex() & getSex()) ? mCurWeight : getDefaultWeight(); - BOOL weight_changed = effective_weight != mCachedEffectiveWeight; + bool weight_changed = effective_weight != mCachedEffectiveWeight; if (getSkip()) { return success; @@ -294,12 +294,12 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) // Don't load the image file until we actually need it the first time. Like now. mStaticImageTGA = LLTexLayerStaticImageList::getInstance()->getImageTGA(info->mStaticImageFileName); // We now have something in one of our caches - LLTexLayerSet::sHasCaches |= mStaticImageTGA.notNull() ? TRUE : FALSE; + LLTexLayerSet::sHasCaches |= mStaticImageTGA.notNull() ? true : false; if (mStaticImageTGA.isNull()) { LL_WARNS() << "Unable to load static file: " << info->mStaticImageFileName << LL_ENDL; - mStaticImageInvalid = TRUE; // don't try again. + mStaticImageInvalid = true; // don't try again. return false; } } @@ -316,10 +316,10 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) if (!mCachedProcessedTexture) { llassert(gTextureManagerBridgep); - mCachedProcessedTexture = gTextureManagerBridgep->getLocalTexture(image_tga_width, image_tga_height, 1, FALSE); + mCachedProcessedTexture = gTextureManagerBridgep->getLocalTexture(image_tga_width, image_tga_height, 1, false); // We now have something in one of our caches - LLTexLayerSet::sHasCaches |= mCachedProcessedTexture ? TRUE : FALSE; + LLTexLayerSet::sHasCaches |= mCachedProcessedTexture ? true : false; mCachedProcessedTexture->setExplicitFormat(GL_ALPHA8, GL_ALPHA); } @@ -328,7 +328,7 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) mStaticImageRaw = NULL; mStaticImageRaw = new LLImageRaw; mStaticImageTGA->decodeAndProcess(mStaticImageRaw, info->mDomain, effective_weight); - mNeedsCreateTexture = TRUE; + mNeedsCreateTexture = true; LL_DEBUGS() << "Built Cached Alpha: " << info->mStaticImageFileName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << "Domain: " << info->mDomain << " Weight: " << effective_weight << LL_ENDL; } @@ -339,7 +339,7 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) if (mNeedsCreateTexture) { mCachedProcessedTexture->createGLTexture(0, mStaticImageRaw); - mNeedsCreateTexture = FALSE; + mNeedsCreateTexture = false; gGL.getTexUnit(0)->bind(mCachedProcessedTexture); mCachedProcessedTexture->setAddressMode(LLTexUnit::TAM_CLAMP); } @@ -372,8 +372,8 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) // LLTexLayerParamAlphaInfo //----------------------------------------------------------------------------- LLTexLayerParamAlphaInfo::LLTexLayerParamAlphaInfo() : - mMultiplyBlend(FALSE), - mSkipIfZeroWeight(FALSE), + mMultiplyBlend(false), + mSkipIfZeroWeight(false), mDomain(0.f) { } @@ -514,7 +514,7 @@ void LLTexLayerParamColor::setAnimationTarget(F32 target_value) // set value first then set interpolating flag to ignore further updates mTargetWeight = target_value; setWeight(target_value); - mIsAnimating = TRUE; + mIsAnimating = true; if (mNext) { mNext->setAnimationTarget(target_value); -- cgit v1.2.3 From f9473e8afcb624cc1b101195bf15943ec372b56f Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Mon, 6 May 2024 16:52:34 +0200 Subject: secondlife/viewer#1333 BOOL to bool conversion leftovers: ternaries --- indra/llappearance/lltexlayerparams.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llappearance/lltexlayerparams.cpp') diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp index 8ad718a506..19eb0c784d 100644 --- a/indra/llappearance/lltexlayerparams.cpp +++ b/indra/llappearance/lltexlayerparams.cpp @@ -294,7 +294,7 @@ bool LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) // Don't load the image file until we actually need it the first time. Like now. mStaticImageTGA = LLTexLayerStaticImageList::getInstance()->getImageTGA(info->mStaticImageFileName); // We now have something in one of our caches - LLTexLayerSet::sHasCaches |= mStaticImageTGA.notNull() ? true : false; + LLTexLayerSet::sHasCaches |= mStaticImageTGA.notNull(); if (mStaticImageTGA.isNull()) { @@ -319,7 +319,7 @@ bool LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) mCachedProcessedTexture = gTextureManagerBridgep->getLocalTexture(image_tga_width, image_tga_height, 1, false); // We now have something in one of our caches - LLTexLayerSet::sHasCaches |= mCachedProcessedTexture ? true : false; + LLTexLayerSet::sHasCaches |= mCachedProcessedTexture.notNull(); mCachedProcessedTexture->setExplicitFormat(GL_ALPHA8, GL_ALPHA); } -- cgit v1.2.3 From e2e37cced861b98de8c1a7c9c0d3a50d2d90e433 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Wed, 22 May 2024 21:25:21 +0200 Subject: Fix line endlings --- indra/llappearance/lltexlayerparams.cpp | 1188 +++++++++++++++---------------- 1 file changed, 594 insertions(+), 594 deletions(-) (limited to 'indra/llappearance/lltexlayerparams.cpp') diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp index b55df16185..7beffbcd19 100644 --- a/indra/llappearance/lltexlayerparams.cpp +++ b/indra/llappearance/lltexlayerparams.cpp @@ -1,594 +1,594 @@ -/** - * @file lltexlayerparams.cpp - * @brief Texture layer parameters - * - * $LicenseInfo:firstyear=2002&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" - -#include "lltexlayerparams.h" - -#include "llavatarappearance.h" -#include "llimagetga.h" -#include "llquantize.h" -#include "lltexlayer.h" -#include "lltexturemanagerbridge.h" -#include "../llui/llui.h" -#include "llwearable.h" -#include "llfasttimer.h" - -//----------------------------------------------------------------------------- -// LLTexLayerParam -//----------------------------------------------------------------------------- -LLTexLayerParam::LLTexLayerParam(LLTexLayerInterface *layer) - : LLViewerVisualParam(), - mTexLayer(layer), - mAvatarAppearance(NULL) -{ - if (mTexLayer != NULL) - { - mAvatarAppearance = mTexLayer->getTexLayerSet()->getAvatarAppearance(); - } - else - { - LL_ERRS() << "LLTexLayerParam constructor passed with NULL reference for layer!" << LL_ENDL; - } -} - -LLTexLayerParam::LLTexLayerParam(LLAvatarAppearance *appearance) - : LLViewerVisualParam(), - mTexLayer(NULL), - mAvatarAppearance(appearance) -{ -} - -LLTexLayerParam::LLTexLayerParam(const LLTexLayerParam& pOther) - : LLViewerVisualParam(pOther), - mTexLayer(pOther.mTexLayer), - mAvatarAppearance(pOther.mAvatarAppearance) -{ -} - -bool LLTexLayerParam::setInfo(LLViewerVisualParamInfo *info, bool add_to_appearance) -{ - LLViewerVisualParam::setInfo(info); - - if (add_to_appearance) - { - mAvatarAppearance->addVisualParam( this); - this->setParamLocation(mAvatarAppearance->isSelf() ? LOC_AV_SELF : LOC_AV_OTHER); - } - - return true; -} - - -//----------------------------------------------------------------------------- -// LLTexLayerParamAlpha -//----------------------------------------------------------------------------- - -// static -LLTexLayerParamAlpha::param_alpha_ptr_list_t LLTexLayerParamAlpha::sInstances; - -// static -void LLTexLayerParamAlpha::dumpCacheByteCount() -{ - S32 gl_bytes = 0; - getCacheByteCount( &gl_bytes); - LL_INFOS() << "Processed Alpha Texture Cache GL:" << (gl_bytes/1024) << "KB" << LL_ENDL; -} - -// static -void LLTexLayerParamAlpha::getCacheByteCount(S32* gl_bytes) -{ - *gl_bytes = 0; - - for (LLTexLayerParamAlpha* instance : sInstances) - { - LLGLTexture* tex = instance->mCachedProcessedTexture; - if (tex) - { - S32 bytes = (S32)tex->getWidth() * tex->getHeight() * tex->getComponents(); - - if (tex->hasGLTexture()) - { - *gl_bytes += bytes; - } - } - } -} - -LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLTexLayerInterface* layer) - : LLTexLayerParam(layer), - mCachedProcessedTexture(NULL), - mStaticImageTGA(), - mStaticImageRaw(), - mNeedsCreateTexture(false), - mStaticImageInvalid(false), - mAvgDistortionVec(1.f, 1.f, 1.f), - mCachedEffectiveWeight(0.f) -{ - sInstances.push_front(this); -} - -LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLAvatarAppearance* appearance) - : LLTexLayerParam(appearance), - mCachedProcessedTexture(NULL), - mStaticImageTGA(), - mStaticImageRaw(), - mNeedsCreateTexture(false), - mStaticImageInvalid(false), - mAvgDistortionVec(1.f, 1.f, 1.f), - mCachedEffectiveWeight(0.f) -{ - sInstances.push_front(this); -} - -LLTexLayerParamAlpha::LLTexLayerParamAlpha(const LLTexLayerParamAlpha& pOther) - : LLTexLayerParam(pOther), - mCachedProcessedTexture(pOther.mCachedProcessedTexture), - mStaticImageTGA(pOther.mStaticImageTGA), - mStaticImageRaw(pOther.mStaticImageRaw), - mNeedsCreateTexture(pOther.mNeedsCreateTexture.load()), - mStaticImageInvalid(pOther.mStaticImageInvalid), - mAvgDistortionVec(pOther.mAvgDistortionVec), - mCachedEffectiveWeight(pOther.mCachedEffectiveWeight) -{ - sInstances.push_front(this); -} - -LLTexLayerParamAlpha::~LLTexLayerParamAlpha() -{ - deleteCaches(); - sInstances.remove(this); -} - -/*virtual*/ LLViewerVisualParam* LLTexLayerParamAlpha::cloneParam(LLWearable* wearable) const -{ - return new LLTexLayerParamAlpha(*this); -} - -void LLTexLayerParamAlpha::deleteCaches() -{ - mStaticImageTGA = NULL; // deletes image - mCachedProcessedTexture = NULL; - mStaticImageRaw = NULL; - mNeedsCreateTexture = false; -} - -bool LLTexLayerParamAlpha::getMultiplyBlend() const -{ - return ((LLTexLayerParamAlphaInfo *)getInfo())->mMultiplyBlend; -} - -void LLTexLayerParamAlpha::setWeight(F32 weight) -{ - if (mIsAnimating || mTexLayer == NULL) - { - return; - } - F32 min_weight = getMinWeight(); - F32 max_weight = getMaxWeight(); - F32 new_weight = llclamp(weight, min_weight, max_weight); - U8 cur_u8 = F32_to_U8(mCurWeight, min_weight, max_weight); - U8 new_u8 = F32_to_U8(new_weight, min_weight, max_weight); - if (cur_u8 != new_u8) - { - mCurWeight = new_weight; - - if ((mAvatarAppearance->getSex() & getSex()) && - (mAvatarAppearance->isSelf() && !mIsDummy)) // only trigger a baked texture update if we're changing a wearable's visual param. - { - mAvatarAppearance->invalidateComposite(mTexLayer->getTexLayerSet()); - mTexLayer->invalidateMorphMasks(); - } - } -} - -void LLTexLayerParamAlpha::setAnimationTarget(F32 target_value) -{ - // do not animate dummy parameters - if (mIsDummy) - { - setWeight(target_value); - return; - } - - mTargetWeight = target_value; - setWeight(target_value); - mIsAnimating = true; - if (mNext) - { - mNext->setAnimationTarget(target_value); - } -} - -void LLTexLayerParamAlpha::animate(F32 delta) -{ - if (mNext) - { - mNext->animate(delta); - } -} - -bool LLTexLayerParamAlpha::getSkip() const -{ - if (!mTexLayer) - { - return true; - } - - const LLAvatarAppearance *appearance = mTexLayer->getTexLayerSet()->getAvatarAppearance(); - - if (((LLTexLayerParamAlphaInfo *)getInfo())->mSkipIfZeroWeight) - { - F32 effective_weight = (appearance->getSex() & getSex()) ? mCurWeight : getDefaultWeight(); - if (is_approx_zero(effective_weight)) - { - return true; - } - } - - LLWearableType::EType type = (LLWearableType::EType)getWearableType(); - if ((type != LLWearableType::WT_INVALID) && !appearance->isWearingWearableType(type)) - { - return true; - } - - return false; -} - - -bool LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) -{ - LL_PROFILE_ZONE_SCOPED; - bool success = true; - - if (!mTexLayer) - { - return success; - } - - F32 effective_weight = (mTexLayer->getTexLayerSet()->getAvatarAppearance()->getSex() & getSex()) ? mCurWeight : getDefaultWeight(); - bool weight_changed = effective_weight != mCachedEffectiveWeight; - if (getSkip()) - { - return success; - } - - LLTexLayerParamAlphaInfo *info = (LLTexLayerParamAlphaInfo *)getInfo(); - gGL.flush(); - if (info->mMultiplyBlend) - { - gGL.blendFunc(LLRender::BF_DEST_ALPHA, LLRender::BF_ZERO); // Multiplication: approximates a min() function - } - else - { - gGL.setSceneBlendType(LLRender::BT_ADD); // Addition: approximates a max() function - } - - if (!info->mStaticImageFileName.empty() && !mStaticImageInvalid) - { - if (mStaticImageTGA.isNull()) - { - // Don't load the image file until we actually need it the first time. Like now. - mStaticImageTGA = LLTexLayerStaticImageList::getInstance()->getImageTGA(info->mStaticImageFileName); - // We now have something in one of our caches - LLTexLayerSet::sHasCaches |= mStaticImageTGA.notNull(); - - if (mStaticImageTGA.isNull()) - { - LL_WARNS() << "Unable to load static file: " << info->mStaticImageFileName << LL_ENDL; - mStaticImageInvalid = true; // don't try again. - return false; - } - } - - const S32 image_tga_width = mStaticImageTGA->getWidth(); - const S32 image_tga_height = mStaticImageTGA->getHeight(); - if (!mCachedProcessedTexture || - (mCachedProcessedTexture->getWidth() != image_tga_width) || - (mCachedProcessedTexture->getHeight() != image_tga_height) || - (weight_changed)) - { - mCachedEffectiveWeight = effective_weight; - - if (!mCachedProcessedTexture) - { - llassert(gTextureManagerBridgep); - mCachedProcessedTexture = gTextureManagerBridgep->getLocalTexture(image_tga_width, image_tga_height, 1, false); - - // We now have something in one of our caches - LLTexLayerSet::sHasCaches |= mCachedProcessedTexture.notNull(); - - mCachedProcessedTexture->setExplicitFormat(GL_ALPHA8, GL_ALPHA); - } - - // Applies domain and effective weight to data as it is decoded. Also resizes the raw image if needed. - mStaticImageRaw = NULL; - mStaticImageRaw = new LLImageRaw; - mStaticImageTGA->decodeAndProcess(mStaticImageRaw, info->mDomain, effective_weight); - mNeedsCreateTexture = true; - LL_DEBUGS() << "Built Cached Alpha: " << info->mStaticImageFileName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << "Domain: " << info->mDomain << " Weight: " << effective_weight << LL_ENDL; - } - - if (mCachedProcessedTexture) - { - { - // Create the GL texture, and then hang onto it for future use. - if (mNeedsCreateTexture) - { - mCachedProcessedTexture->createGLTexture(0, mStaticImageRaw); - mNeedsCreateTexture = false; - gGL.getTexUnit(0)->bind(mCachedProcessedTexture); - mCachedProcessedTexture->setAddressMode(LLTexUnit::TAM_CLAMP); - } - - gGL.getTexUnit(0)->bind(mCachedProcessedTexture); - gl_rect_2d_simple_tex(width, height); - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - stop_glerror(); - } - } - - // Don't keep the cache for other people's avatars - // (It's not really a "cache" in that case, but the logic is the same) - if (!mAvatarAppearance->isSelf()) - { - mCachedProcessedTexture = NULL; - } - } - else - { - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - gGL.color4f(0.f, 0.f, 0.f, effective_weight); - gl_rect_2d_simple(width, height); - } - - return success; -} - -//----------------------------------------------------------------------------- -// LLTexLayerParamAlphaInfo -//----------------------------------------------------------------------------- -LLTexLayerParamAlphaInfo::LLTexLayerParamAlphaInfo() : - mMultiplyBlend(false), - mSkipIfZeroWeight(false), - mDomain(0.f) -{ -} - -bool LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node) -{ - llassert(node->hasName("param") && node->getChildByName("param_alpha")); - - if (!LLViewerVisualParamInfo::parseXml(node)) - return false; - - LLXmlTreeNode* param_alpha_node = node->getChildByName("param_alpha"); - if (!param_alpha_node) - { - return false; - } - - static LLStdStringHandle tga_file_string = LLXmlTree::addAttributeString("tga_file"); - if (param_alpha_node->getFastAttributeString(tga_file_string, mStaticImageFileName)) - { - // Don't load the image file until it's actually needed. - } -// else -// { -// LL_WARNS() << " element is missing tga_file attribute." << LL_ENDL; -// } - - static LLStdStringHandle multiply_blend_string = LLXmlTree::addAttributeString("multiply_blend"); - param_alpha_node->getFastAttributeBOOL(multiply_blend_string, mMultiplyBlend); - - static LLStdStringHandle skip_if_zero_string = LLXmlTree::addAttributeString("skip_if_zero"); - param_alpha_node->getFastAttributeBOOL(skip_if_zero_string, mSkipIfZeroWeight); - - static LLStdStringHandle domain_string = LLXmlTree::addAttributeString("domain"); - param_alpha_node->getFastAttributeF32(domain_string, mDomain); - - return true; -} - - - - -LLTexLayerParamColor::LLTexLayerParamColor(LLTexLayerInterface* layer) - : LLTexLayerParam(layer), - mAvgDistortionVec(1.f, 1.f, 1.f) -{ -} - -LLTexLayerParamColor::LLTexLayerParamColor(LLAvatarAppearance *appearance) - : LLTexLayerParam(appearance), - mAvgDistortionVec(1.f, 1.f, 1.f) -{ -} - -LLTexLayerParamColor::LLTexLayerParamColor(const LLTexLayerParamColor& pOther) - : LLTexLayerParam(pOther), - mAvgDistortionVec(pOther.mAvgDistortionVec) -{ -} - -LLTexLayerParamColor::~LLTexLayerParamColor() -{ -} - -/*virtual*/ LLViewerVisualParam* LLTexLayerParamColor::cloneParam(LLWearable* wearable) const -{ - return new LLTexLayerParamColor(*this); -} - -LLColor4 LLTexLayerParamColor::getNetColor() const -{ - const LLTexLayerParamColorInfo *info = (LLTexLayerParamColorInfo *)getInfo(); - - llassert(info->mNumColors >= 1); - - F32 effective_weight = (mAvatarAppearance && (mAvatarAppearance->getSex() & getSex())) ? mCurWeight : getDefaultWeight(); - - S32 index_last = info->mNumColors - 1; - F32 scaled_weight = effective_weight * index_last; - S32 index_start = (S32) scaled_weight; - S32 index_end = index_start + 1; - if (index_start == index_last) - { - return info->mColors[index_last]; - } - else - { - F32 weight = scaled_weight - index_start; - const LLColor4 *start = &info->mColors[ index_start ]; - const LLColor4 *end = &info->mColors[ index_end ]; - return LLColor4((1.f - weight) * start->mV[VX] + weight * end->mV[VX], - (1.f - weight) * start->mV[VY] + weight * end->mV[VY], - (1.f - weight) * start->mV[VZ] + weight * end->mV[VZ], - (1.f - weight) * start->mV[VW] + weight * end->mV[VW]); - } -} - - -void LLTexLayerParamColor::setWeight(F32 weight) -{ - if (mIsAnimating) - { - return; - } - - F32 min_weight = getMinWeight(); - F32 max_weight = getMaxWeight(); - F32 new_weight = llclamp(weight, min_weight, max_weight); - U8 cur_u8 = F32_to_U8(mCurWeight, min_weight, max_weight); - U8 new_u8 = F32_to_U8(new_weight, min_weight, max_weight); - if (cur_u8 != new_u8) - { - mCurWeight = new_weight; - - const LLTexLayerParamColorInfo *info = (LLTexLayerParamColorInfo *)getInfo(); - - if (info->mNumColors <= 0) - { - // This will happen when we set the default weight the first time. - return; - } - - if ((mAvatarAppearance->getSex() & getSex()) && (mAvatarAppearance->isSelf() && !mIsDummy)) // only trigger a baked texture update if we're changing a wearable's visual param. - { - onGlobalColorChanged(); - if (mTexLayer) - { - mAvatarAppearance->invalidateComposite(mTexLayer->getTexLayerSet()); - } - } - -// LL_INFOS() << "param " << mName << " = " << new_weight << LL_ENDL; - } -} - -void LLTexLayerParamColor::setAnimationTarget(F32 target_value) -{ - // set value first then set interpolating flag to ignore further updates - mTargetWeight = target_value; - setWeight(target_value); - mIsAnimating = true; - if (mNext) - { - mNext->setAnimationTarget(target_value); - } -} - -void LLTexLayerParamColor::animate(F32 delta) -{ - if (mNext) - { - mNext->animate(delta); - } -} - -//----------------------------------------------------------------------------- -// LLTexLayerParamColorInfo -//----------------------------------------------------------------------------- -LLTexLayerParamColorInfo::LLTexLayerParamColorInfo() : - mOperation(LLTexLayerParamColor::OP_ADD), - mNumColors(0) -{ -} - -bool LLTexLayerParamColorInfo::parseXml(LLXmlTreeNode *node) -{ - llassert(node->hasName("param") && node->getChildByName("param_color")); - - if (!LLViewerVisualParamInfo::parseXml(node)) - return false; - - LLXmlTreeNode* param_color_node = node->getChildByName("param_color"); - if (!param_color_node) - { - return false; - } - - std::string op_string; - static LLStdStringHandle operation_string = LLXmlTree::addAttributeString("operation"); - if (param_color_node->getFastAttributeString(operation_string, op_string)) - { - LLStringUtil::toLower(op_string); - if (op_string == "add") mOperation = LLTexLayerParamColor::OP_ADD; - else if (op_string == "multiply") mOperation = LLTexLayerParamColor::OP_MULTIPLY; - else if (op_string == "blend") mOperation = LLTexLayerParamColor::OP_BLEND; - } - - mNumColors = 0; - - LLColor4U color4u; - for (LLXmlTreeNode* child = param_color_node->getChildByName("value"); - child; - child = param_color_node->getNextNamedChild()) - { - if ((mNumColors < MAX_COLOR_VALUES)) - { - static LLStdStringHandle color_string = LLXmlTree::addAttributeString("color"); - if (child->getFastAttributeColor4U(color_string, color4u)) - { - mColors[ mNumColors ].setVec(color4u); - mNumColors++; - } - } - } - if (!mNumColors) - { - LL_WARNS() << " is missing sub-elements" << LL_ENDL; - return false; - } - - if ((mOperation == LLTexLayerParamColor::OP_BLEND) && (mNumColors != 1)) - { - LL_WARNS() << " with operation\"blend\" must have exactly one " << LL_ENDL; - return false; - } - - return true; -} +/** + * @file lltexlayerparams.cpp + * @brief Texture layer parameters + * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "lltexlayerparams.h" + +#include "llavatarappearance.h" +#include "llimagetga.h" +#include "llquantize.h" +#include "lltexlayer.h" +#include "lltexturemanagerbridge.h" +#include "../llui/llui.h" +#include "llwearable.h" +#include "llfasttimer.h" + +//----------------------------------------------------------------------------- +// LLTexLayerParam +//----------------------------------------------------------------------------- +LLTexLayerParam::LLTexLayerParam(LLTexLayerInterface *layer) + : LLViewerVisualParam(), + mTexLayer(layer), + mAvatarAppearance(NULL) +{ + if (mTexLayer != NULL) + { + mAvatarAppearance = mTexLayer->getTexLayerSet()->getAvatarAppearance(); + } + else + { + LL_ERRS() << "LLTexLayerParam constructor passed with NULL reference for layer!" << LL_ENDL; + } +} + +LLTexLayerParam::LLTexLayerParam(LLAvatarAppearance *appearance) + : LLViewerVisualParam(), + mTexLayer(NULL), + mAvatarAppearance(appearance) +{ +} + +LLTexLayerParam::LLTexLayerParam(const LLTexLayerParam& pOther) + : LLViewerVisualParam(pOther), + mTexLayer(pOther.mTexLayer), + mAvatarAppearance(pOther.mAvatarAppearance) +{ +} + +bool LLTexLayerParam::setInfo(LLViewerVisualParamInfo *info, bool add_to_appearance) +{ + LLViewerVisualParam::setInfo(info); + + if (add_to_appearance) + { + mAvatarAppearance->addVisualParam( this); + this->setParamLocation(mAvatarAppearance->isSelf() ? LOC_AV_SELF : LOC_AV_OTHER); + } + + return true; +} + + +//----------------------------------------------------------------------------- +// LLTexLayerParamAlpha +//----------------------------------------------------------------------------- + +// static +LLTexLayerParamAlpha::param_alpha_ptr_list_t LLTexLayerParamAlpha::sInstances; + +// static +void LLTexLayerParamAlpha::dumpCacheByteCount() +{ + S32 gl_bytes = 0; + getCacheByteCount( &gl_bytes); + LL_INFOS() << "Processed Alpha Texture Cache GL:" << (gl_bytes/1024) << "KB" << LL_ENDL; +} + +// static +void LLTexLayerParamAlpha::getCacheByteCount(S32* gl_bytes) +{ + *gl_bytes = 0; + + for (LLTexLayerParamAlpha* instance : sInstances) + { + LLGLTexture* tex = instance->mCachedProcessedTexture; + if (tex) + { + S32 bytes = (S32)tex->getWidth() * tex->getHeight() * tex->getComponents(); + + if (tex->hasGLTexture()) + { + *gl_bytes += bytes; + } + } + } +} + +LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLTexLayerInterface* layer) + : LLTexLayerParam(layer), + mCachedProcessedTexture(NULL), + mStaticImageTGA(), + mStaticImageRaw(), + mNeedsCreateTexture(false), + mStaticImageInvalid(false), + mAvgDistortionVec(1.f, 1.f, 1.f), + mCachedEffectiveWeight(0.f) +{ + sInstances.push_front(this); +} + +LLTexLayerParamAlpha::LLTexLayerParamAlpha(LLAvatarAppearance* appearance) + : LLTexLayerParam(appearance), + mCachedProcessedTexture(NULL), + mStaticImageTGA(), + mStaticImageRaw(), + mNeedsCreateTexture(false), + mStaticImageInvalid(false), + mAvgDistortionVec(1.f, 1.f, 1.f), + mCachedEffectiveWeight(0.f) +{ + sInstances.push_front(this); +} + +LLTexLayerParamAlpha::LLTexLayerParamAlpha(const LLTexLayerParamAlpha& pOther) + : LLTexLayerParam(pOther), + mCachedProcessedTexture(pOther.mCachedProcessedTexture), + mStaticImageTGA(pOther.mStaticImageTGA), + mStaticImageRaw(pOther.mStaticImageRaw), + mNeedsCreateTexture(pOther.mNeedsCreateTexture.load()), + mStaticImageInvalid(pOther.mStaticImageInvalid), + mAvgDistortionVec(pOther.mAvgDistortionVec), + mCachedEffectiveWeight(pOther.mCachedEffectiveWeight) +{ + sInstances.push_front(this); +} + +LLTexLayerParamAlpha::~LLTexLayerParamAlpha() +{ + deleteCaches(); + sInstances.remove(this); +} + +/*virtual*/ LLViewerVisualParam* LLTexLayerParamAlpha::cloneParam(LLWearable* wearable) const +{ + return new LLTexLayerParamAlpha(*this); +} + +void LLTexLayerParamAlpha::deleteCaches() +{ + mStaticImageTGA = NULL; // deletes image + mCachedProcessedTexture = NULL; + mStaticImageRaw = NULL; + mNeedsCreateTexture = false; +} + +bool LLTexLayerParamAlpha::getMultiplyBlend() const +{ + return ((LLTexLayerParamAlphaInfo *)getInfo())->mMultiplyBlend; +} + +void LLTexLayerParamAlpha::setWeight(F32 weight) +{ + if (mIsAnimating || mTexLayer == NULL) + { + return; + } + F32 min_weight = getMinWeight(); + F32 max_weight = getMaxWeight(); + F32 new_weight = llclamp(weight, min_weight, max_weight); + U8 cur_u8 = F32_to_U8(mCurWeight, min_weight, max_weight); + U8 new_u8 = F32_to_U8(new_weight, min_weight, max_weight); + if (cur_u8 != new_u8) + { + mCurWeight = new_weight; + + if ((mAvatarAppearance->getSex() & getSex()) && + (mAvatarAppearance->isSelf() && !mIsDummy)) // only trigger a baked texture update if we're changing a wearable's visual param. + { + mAvatarAppearance->invalidateComposite(mTexLayer->getTexLayerSet()); + mTexLayer->invalidateMorphMasks(); + } + } +} + +void LLTexLayerParamAlpha::setAnimationTarget(F32 target_value) +{ + // do not animate dummy parameters + if (mIsDummy) + { + setWeight(target_value); + return; + } + + mTargetWeight = target_value; + setWeight(target_value); + mIsAnimating = true; + if (mNext) + { + mNext->setAnimationTarget(target_value); + } +} + +void LLTexLayerParamAlpha::animate(F32 delta) +{ + if (mNext) + { + mNext->animate(delta); + } +} + +bool LLTexLayerParamAlpha::getSkip() const +{ + if (!mTexLayer) + { + return true; + } + + const LLAvatarAppearance *appearance = mTexLayer->getTexLayerSet()->getAvatarAppearance(); + + if (((LLTexLayerParamAlphaInfo *)getInfo())->mSkipIfZeroWeight) + { + F32 effective_weight = (appearance->getSex() & getSex()) ? mCurWeight : getDefaultWeight(); + if (is_approx_zero(effective_weight)) + { + return true; + } + } + + LLWearableType::EType type = (LLWearableType::EType)getWearableType(); + if ((type != LLWearableType::WT_INVALID) && !appearance->isWearingWearableType(type)) + { + return true; + } + + return false; +} + + +bool LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) +{ + LL_PROFILE_ZONE_SCOPED; + bool success = true; + + if (!mTexLayer) + { + return success; + } + + F32 effective_weight = (mTexLayer->getTexLayerSet()->getAvatarAppearance()->getSex() & getSex()) ? mCurWeight : getDefaultWeight(); + bool weight_changed = effective_weight != mCachedEffectiveWeight; + if (getSkip()) + { + return success; + } + + LLTexLayerParamAlphaInfo *info = (LLTexLayerParamAlphaInfo *)getInfo(); + gGL.flush(); + if (info->mMultiplyBlend) + { + gGL.blendFunc(LLRender::BF_DEST_ALPHA, LLRender::BF_ZERO); // Multiplication: approximates a min() function + } + else + { + gGL.setSceneBlendType(LLRender::BT_ADD); // Addition: approximates a max() function + } + + if (!info->mStaticImageFileName.empty() && !mStaticImageInvalid) + { + if (mStaticImageTGA.isNull()) + { + // Don't load the image file until we actually need it the first time. Like now. + mStaticImageTGA = LLTexLayerStaticImageList::getInstance()->getImageTGA(info->mStaticImageFileName); + // We now have something in one of our caches + LLTexLayerSet::sHasCaches |= mStaticImageTGA.notNull(); + + if (mStaticImageTGA.isNull()) + { + LL_WARNS() << "Unable to load static file: " << info->mStaticImageFileName << LL_ENDL; + mStaticImageInvalid = true; // don't try again. + return false; + } + } + + const S32 image_tga_width = mStaticImageTGA->getWidth(); + const S32 image_tga_height = mStaticImageTGA->getHeight(); + if (!mCachedProcessedTexture || + (mCachedProcessedTexture->getWidth() != image_tga_width) || + (mCachedProcessedTexture->getHeight() != image_tga_height) || + (weight_changed)) + { + mCachedEffectiveWeight = effective_weight; + + if (!mCachedProcessedTexture) + { + llassert(gTextureManagerBridgep); + mCachedProcessedTexture = gTextureManagerBridgep->getLocalTexture(image_tga_width, image_tga_height, 1, false); + + // We now have something in one of our caches + LLTexLayerSet::sHasCaches |= mCachedProcessedTexture.notNull(); + + mCachedProcessedTexture->setExplicitFormat(GL_ALPHA8, GL_ALPHA); + } + + // Applies domain and effective weight to data as it is decoded. Also resizes the raw image if needed. + mStaticImageRaw = NULL; + mStaticImageRaw = new LLImageRaw; + mStaticImageTGA->decodeAndProcess(mStaticImageRaw, info->mDomain, effective_weight); + mNeedsCreateTexture = true; + LL_DEBUGS() << "Built Cached Alpha: " << info->mStaticImageFileName << ": (" << mStaticImageRaw->getWidth() << ", " << mStaticImageRaw->getHeight() << ") " << "Domain: " << info->mDomain << " Weight: " << effective_weight << LL_ENDL; + } + + if (mCachedProcessedTexture) + { + { + // Create the GL texture, and then hang onto it for future use. + if (mNeedsCreateTexture) + { + mCachedProcessedTexture->createGLTexture(0, mStaticImageRaw); + mNeedsCreateTexture = false; + gGL.getTexUnit(0)->bind(mCachedProcessedTexture); + mCachedProcessedTexture->setAddressMode(LLTexUnit::TAM_CLAMP); + } + + gGL.getTexUnit(0)->bind(mCachedProcessedTexture); + gl_rect_2d_simple_tex(width, height); + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + stop_glerror(); + } + } + + // Don't keep the cache for other people's avatars + // (It's not really a "cache" in that case, but the logic is the same) + if (!mAvatarAppearance->isSelf()) + { + mCachedProcessedTexture = NULL; + } + } + else + { + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + gGL.color4f(0.f, 0.f, 0.f, effective_weight); + gl_rect_2d_simple(width, height); + } + + return success; +} + +//----------------------------------------------------------------------------- +// LLTexLayerParamAlphaInfo +//----------------------------------------------------------------------------- +LLTexLayerParamAlphaInfo::LLTexLayerParamAlphaInfo() : + mMultiplyBlend(false), + mSkipIfZeroWeight(false), + mDomain(0.f) +{ +} + +bool LLTexLayerParamAlphaInfo::parseXml(LLXmlTreeNode* node) +{ + llassert(node->hasName("param") && node->getChildByName("param_alpha")); + + if (!LLViewerVisualParamInfo::parseXml(node)) + return false; + + LLXmlTreeNode* param_alpha_node = node->getChildByName("param_alpha"); + if (!param_alpha_node) + { + return false; + } + + static LLStdStringHandle tga_file_string = LLXmlTree::addAttributeString("tga_file"); + if (param_alpha_node->getFastAttributeString(tga_file_string, mStaticImageFileName)) + { + // Don't load the image file until it's actually needed. + } +// else +// { +// LL_WARNS() << " element is missing tga_file attribute." << LL_ENDL; +// } + + static LLStdStringHandle multiply_blend_string = LLXmlTree::addAttributeString("multiply_blend"); + param_alpha_node->getFastAttributeBOOL(multiply_blend_string, mMultiplyBlend); + + static LLStdStringHandle skip_if_zero_string = LLXmlTree::addAttributeString("skip_if_zero"); + param_alpha_node->getFastAttributeBOOL(skip_if_zero_string, mSkipIfZeroWeight); + + static LLStdStringHandle domain_string = LLXmlTree::addAttributeString("domain"); + param_alpha_node->getFastAttributeF32(domain_string, mDomain); + + return true; +} + + + + +LLTexLayerParamColor::LLTexLayerParamColor(LLTexLayerInterface* layer) + : LLTexLayerParam(layer), + mAvgDistortionVec(1.f, 1.f, 1.f) +{ +} + +LLTexLayerParamColor::LLTexLayerParamColor(LLAvatarAppearance *appearance) + : LLTexLayerParam(appearance), + mAvgDistortionVec(1.f, 1.f, 1.f) +{ +} + +LLTexLayerParamColor::LLTexLayerParamColor(const LLTexLayerParamColor& pOther) + : LLTexLayerParam(pOther), + mAvgDistortionVec(pOther.mAvgDistortionVec) +{ +} + +LLTexLayerParamColor::~LLTexLayerParamColor() +{ +} + +/*virtual*/ LLViewerVisualParam* LLTexLayerParamColor::cloneParam(LLWearable* wearable) const +{ + return new LLTexLayerParamColor(*this); +} + +LLColor4 LLTexLayerParamColor::getNetColor() const +{ + const LLTexLayerParamColorInfo *info = (LLTexLayerParamColorInfo *)getInfo(); + + llassert(info->mNumColors >= 1); + + F32 effective_weight = (mAvatarAppearance && (mAvatarAppearance->getSex() & getSex())) ? mCurWeight : getDefaultWeight(); + + S32 index_last = info->mNumColors - 1; + F32 scaled_weight = effective_weight * index_last; + S32 index_start = (S32) scaled_weight; + S32 index_end = index_start + 1; + if (index_start == index_last) + { + return info->mColors[index_last]; + } + else + { + F32 weight = scaled_weight - index_start; + const LLColor4 *start = &info->mColors[ index_start ]; + const LLColor4 *end = &info->mColors[ index_end ]; + return LLColor4((1.f - weight) * start->mV[VX] + weight * end->mV[VX], + (1.f - weight) * start->mV[VY] + weight * end->mV[VY], + (1.f - weight) * start->mV[VZ] + weight * end->mV[VZ], + (1.f - weight) * start->mV[VW] + weight * end->mV[VW]); + } +} + + +void LLTexLayerParamColor::setWeight(F32 weight) +{ + if (mIsAnimating) + { + return; + } + + F32 min_weight = getMinWeight(); + F32 max_weight = getMaxWeight(); + F32 new_weight = llclamp(weight, min_weight, max_weight); + U8 cur_u8 = F32_to_U8(mCurWeight, min_weight, max_weight); + U8 new_u8 = F32_to_U8(new_weight, min_weight, max_weight); + if (cur_u8 != new_u8) + { + mCurWeight = new_weight; + + const LLTexLayerParamColorInfo *info = (LLTexLayerParamColorInfo *)getInfo(); + + if (info->mNumColors <= 0) + { + // This will happen when we set the default weight the first time. + return; + } + + if ((mAvatarAppearance->getSex() & getSex()) && (mAvatarAppearance->isSelf() && !mIsDummy)) // only trigger a baked texture update if we're changing a wearable's visual param. + { + onGlobalColorChanged(); + if (mTexLayer) + { + mAvatarAppearance->invalidateComposite(mTexLayer->getTexLayerSet()); + } + } + +// LL_INFOS() << "param " << mName << " = " << new_weight << LL_ENDL; + } +} + +void LLTexLayerParamColor::setAnimationTarget(F32 target_value) +{ + // set value first then set interpolating flag to ignore further updates + mTargetWeight = target_value; + setWeight(target_value); + mIsAnimating = true; + if (mNext) + { + mNext->setAnimationTarget(target_value); + } +} + +void LLTexLayerParamColor::animate(F32 delta) +{ + if (mNext) + { + mNext->animate(delta); + } +} + +//----------------------------------------------------------------------------- +// LLTexLayerParamColorInfo +//----------------------------------------------------------------------------- +LLTexLayerParamColorInfo::LLTexLayerParamColorInfo() : + mOperation(LLTexLayerParamColor::OP_ADD), + mNumColors(0) +{ +} + +bool LLTexLayerParamColorInfo::parseXml(LLXmlTreeNode *node) +{ + llassert(node->hasName("param") && node->getChildByName("param_color")); + + if (!LLViewerVisualParamInfo::parseXml(node)) + return false; + + LLXmlTreeNode* param_color_node = node->getChildByName("param_color"); + if (!param_color_node) + { + return false; + } + + std::string op_string; + static LLStdStringHandle operation_string = LLXmlTree::addAttributeString("operation"); + if (param_color_node->getFastAttributeString(operation_string, op_string)) + { + LLStringUtil::toLower(op_string); + if (op_string == "add") mOperation = LLTexLayerParamColor::OP_ADD; + else if (op_string == "multiply") mOperation = LLTexLayerParamColor::OP_MULTIPLY; + else if (op_string == "blend") mOperation = LLTexLayerParamColor::OP_BLEND; + } + + mNumColors = 0; + + LLColor4U color4u; + for (LLXmlTreeNode* child = param_color_node->getChildByName("value"); + child; + child = param_color_node->getNextNamedChild()) + { + if ((mNumColors < MAX_COLOR_VALUES)) + { + static LLStdStringHandle color_string = LLXmlTree::addAttributeString("color"); + if (child->getFastAttributeColor4U(color_string, color4u)) + { + mColors[ mNumColors ].setVec(color4u); + mNumColors++; + } + } + } + if (!mNumColors) + { + LL_WARNS() << " is missing sub-elements" << LL_ENDL; + return false; + } + + if ((mOperation == LLTexLayerParamColor::OP_BLEND) && (mNumColors != 1)) + { + LL_WARNS() << " with operation\"blend\" must have exactly one " << LL_ENDL; + return false; + } + + return true; +} -- cgit v1.2.3 From 4b52dd754b41948efca0087ccac6d813f1fcce3f Mon Sep 17 00:00:00 2001 From: Ansariel Date: Mon, 10 Jun 2024 18:16:13 +0200 Subject: Fix incorrect use of VX/VY/VZ/VW indices when color components are accessed --- indra/llappearance/lltexlayerparams.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llappearance/lltexlayerparams.cpp') diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp index 7beffbcd19..30551c115d 100644 --- a/indra/llappearance/lltexlayerparams.cpp +++ b/indra/llappearance/lltexlayerparams.cpp @@ -464,10 +464,10 @@ LLColor4 LLTexLayerParamColor::getNetColor() const F32 weight = scaled_weight - index_start; const LLColor4 *start = &info->mColors[ index_start ]; const LLColor4 *end = &info->mColors[ index_end ]; - return LLColor4((1.f - weight) * start->mV[VX] + weight * end->mV[VX], - (1.f - weight) * start->mV[VY] + weight * end->mV[VY], - (1.f - weight) * start->mV[VZ] + weight * end->mV[VZ], - (1.f - weight) * start->mV[VW] + weight * end->mV[VW]); + return LLColor4((1.f - weight) * start->mV[VRED] + weight * end->mV[VRED], + (1.f - weight) * start->mV[VGREEN] + weight * end->mV[VGREEN], + (1.f - weight) * start->mV[VBLUE] + weight * end->mV[VBLUE], + (1.f - weight) * start->mV[VALPHA] + weight * end->mV[VALPHA]); } } -- cgit v1.2.3