Skip to content
Snippets Groups Projects
Unverified Commit 98d2a46b authored by cosmic-linden's avatar cosmic-linden Committed by GitHub
Browse files

Merge pull request #59 from secondlife/SL-19012

SL-19012: Fix new material IDs sometimes not applying when set via LSL
parents 623bb4d5 2aaa15fe
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
......@@ -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 @@ class LLFetchedGLTFMaterial: public LLGLTFMaterial
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 @@ class LLFetchedGLTFMaterial: public LLGLTFMaterial
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 @@ class LLGLTFMaterialList
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 @@ class LLViewerObject
private:
void resetRotTime();
void setRenderMaterialIDs(const LLRenderMaterialParams* material_params, bool local_origin);
void rebuildMaterial();
public:
void resetRot();
void applyAngularVelocity(F32 dt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment