diff options
author | RunitaiLinden <davep@lindenlab.com> | 2024-01-19 11:36:56 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-19 11:36:56 -0600 |
commit | 6dd260c3699148b4ddf8e7bff84f4b19f8bbf076 (patch) | |
tree | 6c9144f701ecb2cda859baaeed4e2f4ee6f9a683 /indra/newview/llfetchedgltfmaterial.cpp | |
parent | 45547c7bbadf15804f54bb28fd1c94eb5f080bf5 (diff) | |
parent | 09ee84f675cf08f98cbd49516c5e01c289b42a20 (diff) |
Merge branch 'release/materials_featurette' into DRTVWR-592
Diffstat (limited to 'indra/newview/llfetchedgltfmaterial.cpp')
-rw-r--r-- | indra/newview/llfetchedgltfmaterial.cpp | 135 |
1 files changed, 133 insertions, 2 deletions
diff --git a/indra/newview/llfetchedgltfmaterial.cpp b/indra/newview/llfetchedgltfmaterial.cpp index c870d4778c..a39f196cbf 100644 --- a/indra/newview/llfetchedgltfmaterial.cpp +++ b/indra/newview/llfetchedgltfmaterial.cpp @@ -29,6 +29,8 @@ #include "llviewertexturelist.h" #include "llavatarappearancedefines.h" +#include "llviewerobject.h" +#include "llselectmgr.h" #include "llshadermgr.h" #include "pipeline.h" @@ -81,11 +83,11 @@ void LLFetchedGLTFMaterial::bind(LLViewerTexture* media_tex) if (baseColorTex != nullptr) { - gGL.getTexUnit(0)->bindFast(baseColorTex); + shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, baseColorTex); } else { - gGL.getTexUnit(0)->bindFast(LLViewerFetchedTexture::sWhiteImagep); + shader->bindTexture(LLShaderMgr::DIFFUSE_MAP, LLViewerFetchedTexture::sWhiteImagep); } F32 base_color_packed[8]; @@ -142,6 +144,83 @@ void LLFetchedGLTFMaterial::bind(LLViewerTexture* media_tex) } +LLViewerFetchedTexture* fetch_texture(const LLUUID& id) +{ + LLViewerFetchedTexture* img = nullptr; + if (id.notNull()) + { + img = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE); + img->addTextureStats(64.f * 64.f, TRUE); + } + return img; +}; + +bool LLFetchedGLTFMaterial::replaceLocalTexture(const LLUUID& tracking_id, const LLUUID& old_id, const LLUUID& new_id) +{ + bool res = false; + if (mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR] == old_id) + { + mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR] = new_id; + mBaseColorTexture = fetch_texture(new_id); + res = true; + } + if (mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL] == old_id) + { + mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL] = new_id; + mNormalTexture = fetch_texture(new_id); + res = true; + } + if (mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS] == old_id) + { + mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS] = new_id; + mMetallicRoughnessTexture = fetch_texture(new_id); + res = true; + } + if (mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE] == old_id) + { + mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE] = new_id; + mEmissiveTexture = fetch_texture(new_id); + res = true; + } + + for (int i = 0; i < GLTF_TEXTURE_INFO_COUNT; ++i) + { + if (mTextureId[i] == new_id) + { + res = true; + } + } + + if (res) + { + mTrackingIdToLocalTexture[tracking_id] = new_id; + } + else + { + mTrackingIdToLocalTexture.erase(tracking_id); + } + + return res; +} + +void LLFetchedGLTFMaterial::addTextureEntry(LLTextureEntry* te) +{ + mTextureEntires.insert(te); +} + +void LLFetchedGLTFMaterial::removeTextureEntry(LLTextureEntry* te) +{ + mTextureEntires.erase(te); +} + +void LLFetchedGLTFMaterial::updateTextureTracking() +{ + for (local_tex_map_t::value_type &val : mTrackingIdToLocalTexture) + { + LLLocalBitmapMgr::getInstance()->associateGLTFMaterial(val.first, this); + } +} + void LLFetchedGLTFMaterial::materialBegin() { llassert(!mFetching); @@ -174,3 +253,55 @@ void LLFetchedGLTFMaterial::materialComplete(bool success) materialCompleteCallbacks.clear(); materialCompleteCallbacks.shrink_to_fit(); } + +LLPointer<LLViewerFetchedTexture> LLFetchedGLTFMaterial::getUITexture() +{ + if (mFetching) + { + return nullptr; + } + + auto fetch_texture_for_ui = [](LLPointer<LLViewerFetchedTexture>& img, const LLUUID& id) + { + if (id.notNull()) + { + if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id)) + { + LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject(); + if (obj) + { + LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(id); + img = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL; + } + + } + else + { + img = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE); + } + } + if (img) + { + img->setBoostLevel(LLGLTexture::BOOST_PREVIEW); + img->forceToSaveRawImage(0); + } + }; + + fetch_texture_for_ui(mBaseColorTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR]); + fetch_texture_for_ui(mNormalTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL]); + fetch_texture_for_ui(mMetallicRoughnessTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS]); + fetch_texture_for_ui(mEmissiveTexture, mTextureId[LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE]); + + if ((mBaseColorTexture && (mBaseColorTexture->getRawImageLevel() != 0)) || + (mNormalTexture && (mNormalTexture->getRawImageLevel() != 0)) || + (mMetallicRoughnessTexture && (mMetallicRoughnessTexture->getRawImageLevel() != 0)) || + (mEmissiveTexture && (mEmissiveTexture->getRawImageLevel() != 0))) + { + return nullptr; + } + + // *HACK: Use one of the PBR texture components as the preview texture for now + mPreviewTexture = mBaseColorTexture; + + return mPreviewTexture; +} |