SHMaterialInstance::GetProperty() will now retrieve a property from the base material if it was not overriden

This commit is contained in:
Kah Wei 2022-11-16 15:29:11 +08:00
parent ec215b944e
commit 3a6f1f852b
2 changed files with 18 additions and 5 deletions

View File

@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited.
// Project Includes // Project Includes
#include "Resource/SHHandle.h" #include "Resource/SHHandle.h"
#include "SHCommonTypes.h" #include "SHCommonTypes.h"
#include "SH_API.h"
namespace SHADE namespace SHADE
{ {
@ -35,7 +36,7 @@ namespace SHADE
Describes a Pipeline along with it's associated properties for this instance. Describes a Pipeline along with it's associated properties for this instance.
*/ */
/***********************************************************************************/ /***********************************************************************************/
class SHMaterial class SH_API SHMaterial
{ {
public: public:
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/

View File

@ -11,6 +11,7 @@ of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/ *//*************************************************************************************/
#pragma once #pragma once
#include "SHMaterialInstance.h" #include "SHMaterialInstance.h"
#include "SHMaterial.h"
namespace SHADE namespace SHADE
{ {
@ -70,11 +71,22 @@ namespace SHADE
// Search Override Data for the property // Search Override Data for the property
uint32_t PROP_IDX = SHADER_INFO->GetVariableIndex(key); uint32_t PROP_IDX = SHADER_INFO->GetVariableIndex(key);
auto prop = std::find_if(overrideData.begin(), overrideData.end(), [&](const OverrideData& data) 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()) if (prop == overrideData.end())
throw std::invalid_argument("Attempted to get an property that was not set previously!"); {
if (baseMaterial)
{
return baseMaterial->GetProperty<T>(key);
}
else
{
throw std::invalid_argument("Attempted to get an property that was not set previously!");
}
}
// Get offset and return the memory directly // Get offset and return the memory directly
T* dataPtr = reinterpret_cast<T*>(dataStore.get() + prop->StoredDataOffset); T* dataPtr = reinterpret_cast<T*>(dataStore.get() + prop->StoredDataOffset);