Fixed material property setting at runtime #214
|
@ -43,9 +43,9 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
struct OverrideData
|
||||
{
|
||||
size_t Index;
|
||||
size_t DataSize;
|
||||
size_t StoredDataOffset;
|
||||
uint32_t Index;
|
||||
uint32_t DataSize;
|
||||
uint32_t StoredDataOffset;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -35,26 +35,39 @@ namespace SHADE
|
|||
dataStore.reset(new char[dataStoreSize]);
|
||||
}
|
||||
|
||||
OverrideData od;
|
||||
od.Index = SHADER_INFO->GetVariableIndex(key);
|
||||
od.DataSize = sizeof(T);
|
||||
if (overrideData.empty())
|
||||
// Check if this was stored before
|
||||
const uint32_t VAR_IDX = SHADER_INFO->GetVariableIndex(key);
|
||||
auto existingOverride = std::find_if(overrideData.begin(), overrideData.end(), [&](const OverrideData& od)
|
||||
{
|
||||
od.StoredDataOffset = 0;
|
||||
}
|
||||
else
|
||||
return od.Index == VAR_IDX;
|
||||
});
|
||||
|
||||
// Otherwise, create it
|
||||
if (existingOverride == overrideData.end())
|
||||
{
|
||||
const OverrideData& lastInsertedData = overrideData.back();
|
||||
od.StoredDataOffset = lastInsertedData.StoredDataOffset + lastInsertedData.DataSize;
|
||||
OverrideData od;
|
||||
od.Index = VAR_IDX;
|
||||
od.DataSize = sizeof(T);
|
||||
|
||||
if (overrideData.empty())
|
||||
{
|
||||
od.StoredDataOffset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const OverrideData& lastInsertedData = overrideData.back();
|
||||
od.StoredDataOffset = lastInsertedData.StoredDataOffset + lastInsertedData.DataSize;
|
||||
}
|
||||
|
||||
// Save the override data information
|
||||
overrideData.emplace_back(std::move(od));
|
||||
existingOverride = overrideData.end() - 1;
|
||||
}
|
||||
|
||||
// Get offset and modify the memory directly
|
||||
T* dataPtr = reinterpret_cast<T*>(dataStore.get() + od.StoredDataOffset);
|
||||
T* dataPtr = reinterpret_cast<T*>(dataStore.get() + existingOverride->StoredDataOffset);
|
||||
*dataPtr = value;
|
||||
|
||||
// Save the override data information
|
||||
overrideData.emplace_back(std::move(od));
|
||||
|
||||
|
||||
// Flag
|
||||
dataWasChanged = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue