viewer#1081 Account for 2K texture upload price in bulk upload

master
Andrey Kleshchev 2024-03-29 21:57:58 +02:00 committed by Andrey Kleshchev
parent 18ef2e3b2b
commit e1e0b6fc5b
5 changed files with 98 additions and 43 deletions

View File

@ -33,7 +33,7 @@
class LLAgentBenefits
{
public:
static constexpr S32 MIN_2K_TEXTURE_AREA = 1024 * 1024;
static constexpr S32 MIN_2K_TEXTURE_AREA = 1024 * 1024 + 1;
LLAgentBenefits();
~LLAgentBenefits();

View File

@ -153,7 +153,7 @@ S32 LLFloaterImagePreview::getExpectedUploadCost() const
{
if (mRawImagep.notNull())
{
if (mRawImagep->getWidth() * mRawImagep->getHeight() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (mRawImagep->getWidth() * mRawImagep->getHeight() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
return LLAgentBenefitsMgr::current().get2KTextureUploadCost();
}

View File

@ -48,17 +48,17 @@ protected:
public:
LLImagePreviewSculpted(S32 width, S32 height);
/*virtual*/ S8 getType() const ;
S8 getType() const override;
void setPreviewTarget(LLImageRaw *imagep, F32 distance);
void setTexture(U32 name) { mTextureName = name; }
BOOL render();
BOOL render() override;
void refresh();
void rotate(F32 yaw_radians, F32 pitch_radians);
void zoom(F32 zoom_amt);
void pan(F32 right, F32 up);
virtual BOOL needsRender() { return mNeedsUpdate; }
virtual BOOL needsRender() override { return mNeedsUpdate; }
protected:
BOOL mNeedsUpdate;
@ -87,12 +87,12 @@ public:
void setTexture(U32 name) { mTextureName = name; }
void clearPreviewTexture(const std::string& mesh_name);
BOOL render();
BOOL render() override;
void refresh();
void rotate(F32 yaw_radians, F32 pitch_radians);
void zoom(F32 zoom_amt);
void pan(F32 right, F32 up);
virtual BOOL needsRender() { return mNeedsUpdate; }
virtual BOOL needsRender() override { return mNeedsUpdate; }
protected:
BOOL mNeedsUpdate;

View File

@ -492,16 +492,16 @@ BOOL LLMaterialEditor::postBuild()
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);
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);
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);
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);
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));
}
@ -855,7 +855,7 @@ void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag)
S32 upload_2k_texture_count = 0;
if (mBaseColorTextureUploadId.notNull() && mBaseColorTextureUploadId == getBaseColorId() && mBaseColorFetched)
{
if (mBaseColorFetched->getFullHeight() * mBaseColorFetched->getFullWidth() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (mBaseColorFetched->getFullHeight() * mBaseColorFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
upload_2k_texture_count++;
}
@ -866,7 +866,7 @@ void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag)
}
if (mMetallicTextureUploadId.notNull() && mMetallicTextureUploadId == getMetallicRoughnessId() && mMetallicRoughnessFetched)
{
if (mMetallicRoughnessFetched->getFullHeight() * mMetallicRoughnessFetched->getFullWidth() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (mMetallicRoughnessFetched->getFullHeight() * mMetallicRoughnessFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
upload_2k_texture_count++;
}
@ -877,7 +877,7 @@ void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag)
}
if (mEmissiveTextureUploadId.notNull() && mEmissiveTextureUploadId == getEmissiveId() && mEmissiveFetched)
{
if (mEmissiveFetched->getFullHeight() * mEmissiveFetched->getFullWidth() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (mEmissiveFetched->getFullHeight() * mEmissiveFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
upload_2k_texture_count++;
}
@ -888,7 +888,7 @@ void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag)
}
if (mNormalTextureUploadId.notNull() && mNormalTextureUploadId == getNormalId() && mNormalFetched)
{
if (mNormalFetched->getFullHeight() * mNormalFetched->getFullWidth() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (mNormalFetched->getFullHeight() * mNormalFetched->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
upload_2k_texture_count++;
}
@ -899,7 +899,12 @@ void LLMaterialEditor::markChangesUnsaved(U32 dirty_flag)
}
mExpectedUploadCost = upload_texture_count * LLAgentBenefitsMgr::current().getTextureUploadCost();
mExpectedUploadCost += upload_2k_texture_count * LLAgentBenefitsMgr::current().get2KTextureUploadCost();
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));
}
@ -3535,7 +3540,7 @@ void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, con
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)
if (img->getWidth() * img->getHeight() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
expected_upload_cost = LLAgentBenefitsMgr::current().get2KTextureUploadCost();
}

View File

@ -546,21 +546,50 @@ void do_bulk_upload(std::vector<std::string> filenames, const LLSD& notification
std::string ext = gDirUtilp->getExtension(filename);
LLAssetType::EType asset_type;
U32 codec;
S32 expected_upload_cost;
if (LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(ext, asset_type, codec) &&
LLAgentBenefitsMgr::current().findUploadCost(asset_type, expected_upload_cost))
{
LLResourceUploadInfo::ptr_t uploadInfo(new LLNewFileResourceUploadInfo(
filename,
asset_name,
asset_name, 0,
LLFolderType::FT_NONE, LLInventoryType::IT_NONE,
LLFloaterPerms::getNextOwnerPerms("Uploads"),
LLFloaterPerms::getGroupPerms("Uploads"),
LLFloaterPerms::getEveryonePerms("Uploads"),
expected_upload_cost));
S32 expected_upload_cost = 0;
upload_new_resource(uploadInfo);
if (LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(ext, asset_type, codec))
{
bool resource_upload = false;
if (asset_type == LLAssetType::AT_TEXTURE)
{
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;
}
}
}
else if (LLAgentBenefitsMgr::current().findUploadCost(asset_type, expected_upload_cost))
{
resource_upload = true;
}
if (resource_upload)
{
LLResourceUploadInfo::ptr_t uploadInfo(new LLNewFileResourceUploadInfo(
filename,
asset_name,
asset_name, 0,
LLFolderType::FT_NONE, LLInventoryType::IT_NONE,
LLFloaterPerms::getNextOwnerPerms("Uploads"),
LLFloaterPerms::getGroupPerms("Uploads"),
LLFloaterPerms::getEveryonePerms("Uploads"),
expected_upload_cost));
upload_new_resource(uploadInfo);
}
}
// gltf does not use normal upload procedure
@ -588,6 +617,8 @@ 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);
@ -602,18 +633,37 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3
U32 codec;
S32 cost;
if (LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(ext, asset_type, codec) &&
LLAgentBenefitsMgr::current().findUploadCost(asset_type, cost))
if (LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(ext, asset_type, codec))
{
total_cost += cost;
file_count++;
}
if (asset_type == LLAssetType::AT_TEXTURE)
{
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++;
}
}
}
else if (LLAgentBenefitsMgr::current().findUploadCost(asset_type, cost))
{
total_cost += cost;
file_count++;
}
}
if (ext == "gltf" || ext == "glb")
{
S32 texture_upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost();
S32 texture_2k_upload_cost = LLAgentBenefitsMgr::current().get2KTextureUploadCost();
tinygltf::Model model;
if (LLTinyGLTFHelper::loadModel(filename, model))
@ -634,7 +684,7 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3
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)
if (material->mBaseColorTexture->getFullHeight() * material->mBaseColorTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
texture_2k_count++;
}
@ -645,7 +695,7 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3
}
if (material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS].notNull() && material->mMetallicRoughnessTexture)
{
if (material->mMetallicRoughnessTexture->getFullHeight() * material->mMetallicRoughnessTexture->getFullWidth() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (material->mMetallicRoughnessTexture->getFullHeight() * material->mMetallicRoughnessTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
texture_2k_count++;
}
@ -656,7 +706,7 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3
}
if (material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL].notNull() && material->mNormalTexture)
{
if (material->mNormalTexture->getFullHeight() * material->mNormalTexture->getFullWidth() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (material->mNormalTexture->getFullHeight() * material->mNormalTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
texture_2k_count++;
}
@ -667,7 +717,7 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3
}
if (material->mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE].notNull() && material->mEmissiveTexture)
{
if (material->mEmissiveTexture->getFullHeight() * material->mEmissiveTexture->getFullWidth() > LLAgentBenefits::MIN_2K_TEXTURE_AREA)
if (material->mEmissiveTexture->getFullHeight() * material->mEmissiveTexture->getFullWidth() >= LLAgentBenefits::MIN_2K_TEXTURE_AREA)
{
texture_2k_count++;
}