diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2024-04-12 03:36:23 +0300 |
---|---|---|
committer | Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> | 2024-04-12 21:53:35 +0300 |
commit | 7df1bc9e65a6dd7532ac4a22ea6960cc8d8c9ee8 (patch) | |
tree | 03ca4b5767343888e81fce2687f299989ef8b7ea /indra | |
parent | 5156347c4dd1798b4fdc173cfa9377e09ec193cb (diff) |
viewer#1081 2K texture apload price arrives as an array #2
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/llagentbenefits.cpp | 80 | ||||
-rw-r--r-- | indra/newview/llagentbenefits.h | 9 | ||||
-rw-r--r-- | indra/newview/llfloaterimagepreview.cpp | 13 | ||||
-rw-r--r-- | indra/newview/llmaterialeditor.cpp | 71 | ||||
-rw-r--r-- | indra/newview/llviewermenufile.cpp | 71 |
5 files changed, 101 insertions, 143 deletions
diff --git a/indra/newview/llagentbenefits.cpp b/indra/newview/llagentbenefits.cpp index 7362082029..29b0a4612f 100644 --- a/indra/newview/llagentbenefits.cpp +++ b/indra/newview/llagentbenefits.cpp @@ -25,6 +25,7 @@ #include "llviewerprecompiledheaders.h" #include "llagentbenefits.h" +#include "llviewertexture.h" LLAgentBenefits::LLAgentBenefits(): m_initalized(false), @@ -34,8 +35,7 @@ LLAgentBenefits::LLAgentBenefits(): m_group_membership_limit(-1), m_picks_limit(-1), m_sound_upload_cost(-1), - m_texture_upload_cost(-1), - m_2k_texture_upload_cost(-1) + m_texture_upload_cost(-1) { } @@ -95,7 +95,26 @@ bool LLAgentBenefits::init(const LLSD& benefits_sd) { return false; } - get_required_S32(benefits_sd, "large_texture_upload_cost", m_2k_texture_upload_cost); + + if (benefits_sd.has("large_texture_upload_cost")) + { + LLSD large_texture_cost = benefits_sd.get("large_texture_upload_cost"); + if (large_texture_cost.isArray()) + { + LLSD::array_const_iterator end = large_texture_cost.endArray(); + LLSD::array_const_iterator it = large_texture_cost.beginArray(); + for (; it != end; ++it) + { + m_2k_texture_upload_cost.push_back(it->asInteger()); + } + std::sort(m_2k_texture_upload_cost.begin(), m_2k_texture_upload_cost.end()); + } + } + + if (m_2k_texture_upload_cost.empty()) + { + m_2k_texture_upload_cost.push_back(m_texture_upload_cost); + } // FIXME PREMIUM - either use this field or get rid of it m_initalized = true; @@ -142,9 +161,60 @@ S32 LLAgentBenefits::getTextureUploadCost() const return m_texture_upload_cost; } -S32 LLAgentBenefits::get2KTextureUploadCost() const +S32 LLAgentBenefits::getTextureUploadCost(const LLViewerTexture* tex) const +{ + if (tex) + { + S32 area = tex->getFullHeight() * tex->getFullWidth(); + if (area >= MIN_2K_TEXTURE_AREA) + { + return get2KTextureUploadCost(area); + } + else + { + return getTextureUploadCost(); + } + } + return getTextureUploadCost(); +} + +S32 LLAgentBenefits::getTextureUploadCost(const LLImageBase* tex) const +{ + if (tex) + { + S32 area = tex->getHeight() * tex->getWidth(); + if (area >= MIN_2K_TEXTURE_AREA) + { + return get2KTextureUploadCost(area); + } + else + { + return getTextureUploadCost(); + } + } + return getTextureUploadCost(); +} + +S32 LLAgentBenefits::get2KTextureUploadCost(S32 area) const { - return m_2k_texture_upload_cost; + if (m_2k_texture_upload_cost.empty()) + { + return m_texture_upload_cost; + } + const S32 TEXTURE_SEGMENTS = 1024; + if (m_2k_texture_upload_cost.size() == TEXTURE_SEGMENTS) + { + S32 index = (S32)llceil(sqrt((F32)area)); + // 1..1024 pixels uses m_texture_upload_cost + // 1025..2048 uses m_2k_texture_upload_cost + // Translate 1025..2048 to 0..1023 of the + // cost array + const S32 PIXELS_TO_2K_ARRAY_TRANLATE = 1025; + index -= PIXELS_TO_2K_ARRAY_TRANLATE; + index = llclamp(index, 0, TEXTURE_SEGMENTS - 1); + return m_2k_texture_upload_cost[index]; + } + return m_2k_texture_upload_cost[0]; } bool LLAgentBenefits::findUploadCost(LLAssetType::EType& asset_type, S32& cost) const diff --git a/indra/newview/llagentbenefits.h b/indra/newview/llagentbenefits.h index e48cedd95c..962d0f9371 100644 --- a/indra/newview/llagentbenefits.h +++ b/indra/newview/llagentbenefits.h @@ -30,6 +30,9 @@ #include "llsd.h" #include "llassettype.h" +class LLViewerTexture; +class LLImageBase; + class LLAgentBenefits { public: @@ -49,7 +52,9 @@ public: S32 getPicksLimit() const; S32 getSoundUploadCost() const; S32 getTextureUploadCost() const; - S32 get2KTextureUploadCost() const; + S32 getTextureUploadCost(const LLViewerTexture* tex) const; + S32 getTextureUploadCost(const LLImageBase* tex) const; + S32 get2KTextureUploadCost(S32 area) const; bool findUploadCost(LLAssetType::EType& asset_type, S32& cost) const; @@ -62,7 +67,7 @@ private: S32 m_picks_limit; S32 m_sound_upload_cost; S32 m_texture_upload_cost; - S32 m_2k_texture_upload_cost; + std::vector<S32> m_2k_texture_upload_cost; bool m_initalized; }; diff --git a/indra/newview/llfloaterimagepreview.cpp b/indra/newview/llfloaterimagepreview.cpp index 87fe0a4dd6..55516fe168 100644 --- a/indra/newview/llfloaterimagepreview.cpp +++ b/indra/newview/llfloaterimagepreview.cpp @@ -151,18 +151,7 @@ BOOL LLFloaterImagePreview::postBuild() //----------------------------------------------------------------------------- S32 LLFloaterImagePreview::getExpectedUploadCost() const { - if (mRawImagep.notNull()) - { - if (mRawImagep->getWidth() * mRawImagep->getHeight() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - return LLAgentBenefitsMgr::current().get2KTextureUploadCost(); - } - else - { - return LLAgentBenefitsMgr::current().getTextureUploadCost(); - } - } - return 0; + return LLAgentBenefitsMgr::current().getTextureUploadCost(mRawImagep); } //----------------------------------------------------------------------------- diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp index 1783621530..84446b626a 100644 --- a/indra/newview/llmaterialeditor.cpp +++ b/indra/newview/llmaterialeditor.cpp @@ -489,20 +489,10 @@ BOOL LLMaterialEditor::postBuild() } else { - S32 upload_cost_base = LLAgentBenefitsMgr::current().getTextureUploadCost(); - S32 upload_cost_2k = LLAgentBenefitsMgr::current().get2KTextureUploadCost(); - - bool large_texture = mBaseColorFetched && (mBaseColorFetched->getFullHeight() * mBaseColorFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA); - getChild<LLUICtrl>("base_color_upload_fee")->setTextArg("[FEE]", llformat("%d", large_texture ? upload_cost_2k : upload_cost_base)); - - large_texture = mMetallicRoughnessFetched && (mMetallicRoughnessFetched->getFullHeight() * mMetallicRoughnessFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA); - getChild<LLUICtrl>("metallic_upload_fee")->setTextArg("[FEE]", llformat("%d", large_texture ? upload_cost_2k : upload_cost_base)); - - large_texture = mEmissiveFetched && (mEmissiveFetched->getFullHeight() * mEmissiveFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA); - getChild<LLUICtrl>("emissive_upload_fee")->setTextArg("[FEE]", llformat("%d", large_texture ? upload_cost_2k : upload_cost_base)); - - large_texture = mNormalFetched && (mNormalFetched->getFullHeight() * mNormalFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA); - getChild<LLUICtrl>("normal_upload_fee")->setTextArg("[FEE]", llformat("%d", large_texture ? upload_cost_2k : upload_cost_base)); + getChild<LLUICtrl>("base_color_upload_fee")->setTextArg("[FEE]", llformat("%d", LLAgentBenefitsMgr::current().getTextureUploadCost(mBaseColorFetched))); + getChild<LLUICtrl>("metallic_upload_fee")->setTextArg("[FEE]", llformat("%d", LLAgentBenefitsMgr::current().getTextureUploadCost(mMetallicRoughnessFetched))); + getChild<LLUICtrl>("emissive_upload_fee")->setTextArg("[FEE]", llformat("%d", LLAgentBenefitsMgr::current().getTextureUploadCost(mEmissiveFetched))); + getChild<LLUICtrl>("normal_upload_fee")->setTextArg("[FEE]", llformat("%d", LLAgentBenefitsMgr::current().getTextureUploadCost(mNormalFetched))); } boost::function<void(LLUICtrl*, void*)> changes_callback = [this](LLUICtrl * ctrl, void* userData) @@ -851,60 +841,24 @@ void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag) setCanSave(false); } - S32 upload_texture_count = 0; - S32 upload_2k_texture_count = 0; + mExpectedUploadCost = 0; if (mBaseColorTextureUploadId.notNull() && mBaseColorTextureUploadId == getBaseColorId() && mBaseColorFetched) { - if (mBaseColorFetched->getFullHeight() * mBaseColorFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - upload_2k_texture_count++; - } - else - { - upload_texture_count++; - } + mExpectedUploadCost += LLAgentBenefitsMgr::current().getTextureUploadCost(mBaseColorFetched); } if (mMetallicTextureUploadId.notNull() && mMetallicTextureUploadId == getMetallicRoughnessId() && mMetallicRoughnessFetched) { - if (mMetallicRoughnessFetched->getFullHeight() * mMetallicRoughnessFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - upload_2k_texture_count++; - } - else - { - upload_texture_count++; - } + mExpectedUploadCost += LLAgentBenefitsMgr::current().getTextureUploadCost(mMetallicRoughnessFetched); } if (mEmissiveTextureUploadId.notNull() && mEmissiveTextureUploadId == getEmissiveId() && mEmissiveFetched) { - if (mEmissiveFetched->getFullHeight() * mEmissiveFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - upload_2k_texture_count++; - } - else - { - upload_texture_count++; - } + mExpectedUploadCost += LLAgentBenefitsMgr::current().getTextureUploadCost(mEmissiveFetched); } if (mNormalTextureUploadId.notNull() && mNormalTextureUploadId == getNormalId() && mNormalFetched) { - if (mNormalFetched->getFullHeight() * mNormalFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - upload_2k_texture_count++; - } - else - { - upload_texture_count++; - } + mExpectedUploadCost += LLAgentBenefitsMgr::current().getTextureUploadCost(mNormalFetched); } - mExpectedUploadCost = upload_texture_count * LLAgentBenefitsMgr::current().getTextureUploadCost(); - S32 cost_2k = LLAgentBenefitsMgr::current().get2KTextureUploadCost(); - if (cost_2k < 0) - { - cost_2k = 0; - } - mExpectedUploadCost += upload_2k_texture_count * cost_2k; getChild<LLUICtrl>("total_upload_fee")->setTextArg("[FEE]", llformat("%d", mExpectedUploadCost)); } @@ -3539,12 +3493,7 @@ void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, con std::string buffer; buffer.assign((const char*) img->getData(), img->getDataSize()); - U32 expected_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(); - if (img->getWidth() * img->getHeight() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - expected_upload_cost = LLAgentBenefitsMgr::current().get2KTextureUploadCost(); - } - + U32 expected_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(img); LLSD key = getKey(); std::function<bool(LLUUID itemId, LLSD response, std::string reason)> failed_upload([key](LLUUID assetId, LLSD response, std::string reason) { diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp index 6fe5ef00ab..240c756411 100644 --- a/indra/newview/llviewermenufile.cpp +++ b/indra/newview/llviewermenufile.cpp @@ -556,19 +556,8 @@ void do_bulk_upload(std::vector<std::string> filenames, const LLSD& notification LLPointer<LLImageFormatted> image_frmted = LLImageFormatted::createFromType(codec); if (gDirUtilp->fileExists(filename) && image_frmted->load(filename)) { - if (image_frmted->getWidth() * image_frmted->getHeight() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - expected_upload_cost = LLAgentBenefitsMgr::current().get2KTextureUploadCost(); - if (expected_upload_cost >= 0) - { - resource_upload = true; - } - } - else - { - expected_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(); - resource_upload = true; - } + expected_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(image_frmted); + resource_upload = true; } } else if (LLAgentBenefitsMgr::current().findUploadCost(asset_type, expected_upload_cost)) @@ -617,8 +606,6 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3 total_cost = 0; file_count = 0; bvh_count = 0; - S32 texture_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost(); - S32 texture_2k_upload_cost = LLAgentBenefitsMgr::current().get2KTextureUploadCost(); for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter) { std::string filename = (*in_iter); @@ -640,19 +627,8 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3 LLPointer<LLImageFormatted> image_frmted = LLImageFormatted::createFromType(codec); if (gDirUtilp->fileExists(filename) && image_frmted->load(filename)) { - if (image_frmted->getWidth() * image_frmted->getHeight() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - if (texture_2k_upload_cost >= 0) - { - total_cost += texture_2k_upload_cost; - file_count++; - } - } - else - { - total_cost += texture_upload_cost; - file_count++; - } + total_cost += LLAgentBenefitsMgr::current().getTextureUploadCost(image_frmted); + file_count++; } } else if (LLAgentBenefitsMgr::current().findUploadCost(asset_type, cost)) @@ -680,53 +656,22 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3 { // Todo: make it account for possibility of same texture in different // materials and even in scope of same material - S32 texture_count = 0; - S32 texture_2k_count = 0; if (material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR].notNull() && material->mBaseColorTexture) { - if (material->mBaseColorTexture->getFullHeight() * material->mBaseColorTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - texture_2k_count++; - } - else - { - texture_count++; - } + total_cost += LLAgentBenefitsMgr::current().getTextureUploadCost(material->mBaseColorTexture); } if (material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS].notNull() && material->mMetallicRoughnessTexture) { - if (material->mMetallicRoughnessTexture->getFullHeight() * material->mMetallicRoughnessTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - texture_2k_count++; - } - else - { - texture_count++; - } + total_cost += LLAgentBenefitsMgr::current().getTextureUploadCost(material->mMetallicRoughnessTexture); } if (material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL].notNull() && material->mNormalTexture) { - if (material->mNormalTexture->getFullHeight() * material->mNormalTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - texture_2k_count++; - } - else - { - texture_count++; - } + total_cost += LLAgentBenefitsMgr::current().getTextureUploadCost(material->mNormalTexture); } if (material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE].notNull() && material->mEmissiveTexture) { - if (material->mEmissiveTexture->getFullHeight() * material->mEmissiveTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA) - { - texture_2k_count++; - } - else - { - texture_count++; - } + total_cost += LLAgentBenefitsMgr::current().getTextureUploadCost(material->mEmissiveTexture); } - total_cost += texture_count * texture_upload_cost + texture_2k_count * texture_2k_upload_cost; file_count++; } } |