Skip to content

Commit

Permalink
Fix issue where material instance name cannot be set without creating…
Browse files Browse the repository at this point in the history
… a default instance (#8213)
  • Loading branch information
kunyoungparkk authored Oct 22, 2024
1 parent eab8490 commit 13310e4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions filament/src/details/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,9 @@ FMaterialInstance* FEngine::createMaterialInstance(const FMaterial* material,
return p;
}

FMaterialInstance* FEngine::createMaterialInstance(const FMaterial* material) noexcept {
FMaterialInstance* p = mHeapAllocator.make<FMaterialInstance>(*this, material);
FMaterialInstance* FEngine::createMaterialInstance(const FMaterial* material,
const char* name) noexcept {
FMaterialInstance* p = mHeapAllocator.make<FMaterialInstance>(*this, material, name);
if (UTILS_UNLIKELY(p)) { // should never happen
auto pos = mMaterialInstances.emplace(material, "MaterialInstance");
pos.first->second.insert(p);
Expand Down
3 changes: 2 additions & 1 deletion filament/src/details/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ class FEngine : public Engine {
FMaterialInstance* createMaterialInstance(const FMaterial* material,
const FMaterialInstance* other, const char* name) noexcept;

FMaterialInstance* createMaterialInstance(const FMaterial* material) noexcept;
FMaterialInstance* createMaterialInstance(const FMaterial* material,
const char* name) noexcept;

FScene* createScene() noexcept;
FView* createView() noexcept;
Expand Down
4 changes: 2 additions & 2 deletions filament/src/details/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,13 @@ FMaterialInstance* FMaterial::createInstance(const char* name) const noexcept {
return FMaterialInstance::duplicate(mDefaultMaterialInstance, name);
} else {
// but if we don't, just create an instance with all the default parameters
return mEngine.createMaterialInstance(this);
return mEngine.createMaterialInstance(this, name);
}
}

FMaterialInstance* FMaterial::getDefaultInstance() noexcept {
if (UTILS_UNLIKELY(!mDefaultMaterialInstance)) {
mDefaultMaterialInstance = mEngine.createMaterialInstance(this);
mDefaultMaterialInstance = mEngine.createMaterialInstance(this, mName.c_str());
mDefaultMaterialInstance->setDefaultInstance(true);
}
return mDefaultMaterialInstance;
Expand Down
6 changes: 4 additions & 2 deletions filament/src/details/MaterialInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ namespace filament {

using namespace backend;

FMaterialInstance::FMaterialInstance(FEngine& engine, FMaterial const* material) noexcept
FMaterialInstance::FMaterialInstance(FEngine& engine, FMaterial const* material,
const char* name) noexcept
: mMaterial(material),
mDescriptorSet(material->getDescriptorSetLayout()),
mCulling(CullingMode::BACK),
Expand All @@ -66,7 +67,8 @@ FMaterialInstance::FMaterialInstance(FEngine& engine, FMaterial const* material)
mHasScissor(false),
mIsDoubleSided(false),
mIsDefaultInstance(false),
mTransparencyMode(TransparencyMode::DEFAULT) {
mTransparencyMode(TransparencyMode::DEFAULT),
mName(name ? CString(name) : material->getName()) {

FEngine::DriverApi& driver = engine.getDriverApi();

Expand Down
3 changes: 2 additions & 1 deletion filament/src/details/MaterialInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class FTexture;

class FMaterialInstance : public MaterialInstance {
public:
FMaterialInstance(FEngine& engine, FMaterial const* material) noexcept;
FMaterialInstance(FEngine& engine, FMaterial const* material,
const char* name) noexcept;
FMaterialInstance(FEngine& engine, FMaterialInstance const* other, const char* name);
FMaterialInstance(const FMaterialInstance& rhs) = delete;
FMaterialInstance& operator=(const FMaterialInstance& rhs) = delete;
Expand Down

0 comments on commit 13310e4

Please sign in to comment.