From 3a6f1f852bac3c58560380d8ec02a9cf391cbd7c Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 16 Nov 2022 15:29:11 +0800 Subject: [PATCH] SHMaterialInstance::GetProperty() will now retrieve a property from the base material if it was not overriden --- .../Graphics/MiddleEnd/Interface/SHMaterial.h | 3 ++- .../Interface/SHMaterialInstance.hpp | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h index 964f9e34..ac793089 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h @@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Resource/SHHandle.h" #include "SHCommonTypes.h" +#include "SH_API.h" namespace SHADE { @@ -35,7 +36,7 @@ namespace SHADE Describes a Pipeline along with it's associated properties for this instance. */ /***********************************************************************************/ - class SHMaterial + class SH_API SHMaterial { public: /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp index e70631ea..3f7013fe 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp @@ -11,6 +11,7 @@ of DigiPen Institute of Technology is prohibited. *//*************************************************************************************/ #pragma once #include "SHMaterialInstance.h" +#include "SHMaterial.h" namespace SHADE { @@ -70,11 +71,22 @@ namespace SHADE // Search Override Data for the property uint32_t PROP_IDX = SHADER_INFO->GetVariableIndex(key); auto prop = std::find_if(overrideData.begin(), overrideData.end(), [&](const OverrideData& data) - { - return PROP_IDX == data.Index; - }); + { + return PROP_IDX == data.Index; + }); + + // No overrides, we get from the base material instead if (prop == overrideData.end()) - throw std::invalid_argument("Attempted to get an property that was not set previously!"); + { + if (baseMaterial) + { + return baseMaterial->GetProperty(key); + } + else + { + throw std::invalid_argument("Attempted to get an property that was not set previously!"); + } + } // Get offset and return the memory directly T* dataPtr = reinterpret_cast(dataStore.get() + prop->StoredDataOffset);