SL-19012: Fix new material IDs sometimes not applying when set via LSL
parent
a851aa83e7
commit
2aaa15fef1
|
|
@ -115,3 +115,35 @@ void LLFetchedGLTFMaterial::bind()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
void LLFetchedGLTFMaterial::materialBegin()
|
||||
{
|
||||
llassert(!mFetching);
|
||||
mFetching = true;
|
||||
}
|
||||
|
||||
void LLFetchedGLTFMaterial::onMaterialComplete(std::function<void()> material_complete)
|
||||
{
|
||||
if (!material_complete) { return; }
|
||||
|
||||
if (!mFetching)
|
||||
{
|
||||
material_complete();
|
||||
return;
|
||||
}
|
||||
|
||||
materialCompleteCallbacks.push_back(material_complete);
|
||||
}
|
||||
|
||||
void LLFetchedGLTFMaterial::materialComplete()
|
||||
{
|
||||
llassert(mFetching);
|
||||
mFetching = false;
|
||||
|
||||
for (std::function<void()> material_complete : materialCompleteCallbacks)
|
||||
{
|
||||
material_complete();
|
||||
}
|
||||
materialCompleteCallbacks.clear();
|
||||
materialCompleteCallbacks.shrink_to_fit();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ public:
|
|||
LLFetchedGLTFMaterial();
|
||||
virtual ~LLFetchedGLTFMaterial();
|
||||
|
||||
// If this material is loaded, fire the given function
|
||||
void onMaterialComplete(std::function<void()> material_complete);
|
||||
|
||||
// bind this material for rendering
|
||||
void bind();
|
||||
|
||||
|
|
@ -49,9 +52,14 @@ public:
|
|||
LLPointer<LLViewerFetchedTexture> mEmissiveTexture;
|
||||
|
||||
protected:
|
||||
//Lifetime management
|
||||
// Lifetime management
|
||||
|
||||
void materialBegin();
|
||||
void materialComplete();
|
||||
|
||||
F64 mExpectedFlusTime; // since epoch in seconds
|
||||
bool mActive;
|
||||
bool mFetching;
|
||||
std::vector<std::function<void()>> materialCompleteCallbacks;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp
|
|||
if (status != LL_ERR_NOERR)
|
||||
{
|
||||
LL_WARNS("GLTF") << "Error getting material asset data: " << LLAssetStorage::getErrorString(status) << " (" << status << ")" << LL_ENDL;
|
||||
asset_data->mMaterial->mFetching = false;
|
||||
asset_data->mMaterial->materialComplete();
|
||||
delete asset_data;
|
||||
}
|
||||
else
|
||||
|
|
@ -611,13 +611,15 @@ void LLGLTFMaterialList::onAssetLoadComplete(const LLUUID& id, LLAssetType::ETyp
|
|||
{
|
||||
LL_DEBUGS("GLTF") << "Failed to get material " << id << LL_ENDL;
|
||||
}
|
||||
asset_data->mMaterial->mFetching = false;
|
||||
|
||||
asset_data->mMaterial->materialComplete();
|
||||
|
||||
delete asset_data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id)
|
||||
LLFetchedGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id)
|
||||
{
|
||||
LL_PROFILE_ZONE_SCOPED;
|
||||
uuid_mat_map_t::iterator iter = mList.find(id);
|
||||
|
|
@ -629,7 +631,7 @@ LLGLTFMaterial* LLGLTFMaterialList::getMaterial(const LLUUID& id)
|
|||
|
||||
if (!mat->mFetching)
|
||||
{
|
||||
mat->mFetching = true;
|
||||
mat->materialBegin();
|
||||
|
||||
AssetLoadUserData *user_data = new AssetLoadUserData();
|
||||
user_data->mMaterial = mat;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public:
|
|||
LLGLTFMaterialList() {}
|
||||
|
||||
|
||||
LLGLTFMaterial* getMaterial(const LLUUID& id);
|
||||
LLFetchedGLTFMaterial* getMaterial(const LLUUID& id);
|
||||
|
||||
void addMaterial(const LLUUID& id, LLFetchedGLTFMaterial* material);
|
||||
void removeMaterial(const LLUUID& id);
|
||||
|
|
|
|||
|
|
@ -7160,6 +7160,14 @@ const LLUUID& LLViewerObject::getRenderMaterialID(U8 te) const
|
|||
return LLUUID::null;
|
||||
}
|
||||
|
||||
void LLViewerObject::rebuildMaterial()
|
||||
{
|
||||
llassert(!isDead());
|
||||
|
||||
faceMappingChanged();
|
||||
gPipeline.markTextured(mDrawable);
|
||||
}
|
||||
|
||||
void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool update_server)
|
||||
{
|
||||
// implementation is delicate
|
||||
|
|
@ -7188,17 +7196,16 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
|
|||
}
|
||||
|
||||
|
||||
LLFetchedGLTFMaterial* new_material = nullptr;
|
||||
if (id.notNull())
|
||||
{
|
||||
new_material = gGLTFMaterialList.getMaterial(id);
|
||||
}
|
||||
|
||||
// update local state
|
||||
for (S32 te = start_idx; te < end_idx; ++te)
|
||||
{
|
||||
|
||||
LLGLTFMaterial* new_material = nullptr;
|
||||
LLTextureEntry* tep = getTE(te);
|
||||
|
||||
if (id.notNull())
|
||||
{
|
||||
new_material = gGLTFMaterialList.getMaterial(id);
|
||||
}
|
||||
|
||||
bool material_changed = !param_block || id != param_block->getMaterial(te);
|
||||
|
||||
|
|
@ -7225,8 +7232,19 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
|
|||
}
|
||||
|
||||
// signal to render pipe that render batches must be rebuilt for this object
|
||||
faceMappingChanged();
|
||||
gPipeline.markTextured(mDrawable);
|
||||
if (!new_material)
|
||||
{
|
||||
rebuildMaterial();
|
||||
}
|
||||
else
|
||||
{
|
||||
LLPointer<LLViewerObject> this_ptr = this;
|
||||
new_material->onMaterialComplete([this_ptr]() mutable {
|
||||
if (this_ptr->isDead()) { return; }
|
||||
|
||||
this_ptr->rebuildMaterial();
|
||||
});
|
||||
}
|
||||
|
||||
if (update_server)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -226,6 +226,7 @@ public:
|
|||
private:
|
||||
void resetRotTime();
|
||||
void setRenderMaterialIDs(const LLRenderMaterialParams* material_params, bool local_origin);
|
||||
void rebuildMaterial();
|
||||
public:
|
||||
void resetRot();
|
||||
void applyAngularVelocity(F32 dt);
|
||||
|
|
|
|||
Loading…
Reference in New Issue