@@ -5075,11 +5075,10 @@ void LLViewerObject::setNumTEs(const U8 num_tes)
5075
5075
if (base_material && override_material)
5076
5076
{
5077
5077
tep->setGLTFMaterialOverride (new LLGLTFMaterial (*override_material));
5078
-
5079
- LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial ();
5080
- *render_material = *base_material;
5081
- render_material->applyOverride (*override_material);
5082
- tep->setGLTFRenderMaterial (render_material);
5078
+ }
5079
+ if (base_material)
5080
+ {
5081
+ initRenderMaterial (i);
5083
5082
}
5084
5083
}
5085
5084
}
@@ -5254,6 +5253,9 @@ void LLViewerObject::updateTEMaterialTextures(U8 te)
5254
5253
});
5255
5254
}
5256
5255
getTE (te)->setGLTFMaterial (mat);
5256
+ initRenderMaterial (te);
5257
+ mat = (LLFetchedGLTFMaterial*) getTE (te)->getGLTFRenderMaterial ();
5258
+ llassert (mat == nullptr || dynamic_cast <LLFetchedGLTFMaterial*>(getTE (te)->getGLTFRenderMaterial ()) != nullptr );
5257
5259
}
5258
5260
else if (mat_id.isNull () && mat != nullptr )
5259
5261
{
@@ -5643,6 +5645,42 @@ S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMateri
5643
5645
return retval;
5644
5646
}
5645
5647
5648
+ // Set render material if there are overrides or if the base material is has a
5649
+ // baked texture. Otherwise, set it to null.
5650
+ // If you are setting the material override and not sending an update message,
5651
+ // you should probably call this function.
5652
+ S32 LLViewerObject::initRenderMaterial (U8 te)
5653
+ {
5654
+ LL_PROFILE_ZONE_SCOPED;
5655
+
5656
+ LLTextureEntry* tep = getTE (te);
5657
+ if (!tep) { return 0 ; }
5658
+ const LLFetchedGLTFMaterial* base_material = static_cast <LLFetchedGLTFMaterial*>(tep->getGLTFMaterial ());
5659
+ llassert (base_material);
5660
+ if (!base_material) { return 0 ; }
5661
+ const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride ();
5662
+ LLFetchedGLTFMaterial* render_material = nullptr ;
5663
+ bool need_render_material = override_material;
5664
+ if (!need_render_material)
5665
+ {
5666
+ for (const LLUUID& texture_id : base_material->mTextureId )
5667
+ {
5668
+ if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId (texture_id))
5669
+ {
5670
+ need_render_material = true ;
5671
+ break ;
5672
+ }
5673
+ }
5674
+ }
5675
+ if (need_render_material)
5676
+ {
5677
+ render_material = new LLFetchedGLTFMaterial (*base_material);
5678
+ if (override_material) { render_material->applyOverride (*override_material); }
5679
+ render_material->clearFetchedTextures ();
5680
+ }
5681
+ return tep->setGLTFRenderMaterial (render_material);
5682
+ }
5683
+
5646
5684
S32 LLViewerObject::setTEGLTFMaterialOverride (U8 te, LLGLTFMaterial* override_mat)
5647
5685
{
5648
5686
LL_PROFILE_ZONE_SCOPED;
@@ -5676,22 +5714,13 @@ S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* override_ma
5676
5714
5677
5715
if (retval)
5678
5716
{
5717
+ retval = initRenderMaterial (te) | retval;
5679
5718
if (override_mat)
5680
5719
{
5681
- LLFetchedGLTFMaterial* render_mat = new LLFetchedGLTFMaterial (*src_mat);
5682
- render_mat->applyOverride (*override_mat);
5683
- tep->setGLTFRenderMaterial (render_mat);
5684
- retval = TEM_CHANGE_TEXTURE;
5685
-
5686
5720
for (LLGLTFMaterial::local_tex_map_t ::value_type &val : override_mat->mTrackingIdToLocalTexture )
5687
5721
{
5688
5722
LLLocalBitmapMgr::getInstance ()->associateGLTFMaterial (val.first , override_mat);
5689
5723
}
5690
-
5691
- }
5692
- else if (tep->setGLTFRenderMaterial (nullptr ))
5693
- {
5694
- retval = TEM_CHANGE_TEXTURE;
5695
5724
}
5696
5725
}
5697
5726
@@ -7561,25 +7590,15 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
7561
7590
// the overrides have not changed due to being only texture
7562
7591
// transforms. Re-apply the overrides to the render material here,
7563
7592
// if present.
7564
- const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride ();
7565
- if (override_material)
7593
+ // Also, sometimes, the material has baked textures, which requires
7594
+ // a copy unique to this object.
7595
+ // Currently, we do not deduplicate render materials.
7596
+ new_material->onMaterialComplete ([obj_id = getID (), te]()
7566
7597
{
7567
- new_material->onMaterialComplete ([obj_id = getID (), te]()
7568
- {
7569
- LLViewerObject* obj = gObjectList .findObject (obj_id);
7570
- if (!obj) { return ; }
7571
- LLTextureEntry* tep = obj->getTE (te);
7572
- if (!tep) { return ; }
7573
- const LLGLTFMaterial* new_material = tep->getGLTFMaterial ();
7574
- if (!new_material) { return ; }
7575
- const LLGLTFMaterial* override_material = tep->getGLTFMaterialOverride ();
7576
- if (!override_material) { return ; }
7577
- LLGLTFMaterial* render_material = new LLFetchedGLTFMaterial ();
7578
- *render_material = *new_material;
7579
- render_material->applyOverride (*override_material);
7580
- tep->setGLTFRenderMaterial (render_material);
7581
- });
7582
- }
7598
+ LLViewerObject* obj = gObjectList .findObject (obj_id);
7599
+ if (!obj) { return ; }
7600
+ obj->initRenderMaterial (te);
7601
+ });
7583
7602
}
7584
7603
}
7585
7604
0 commit comments