Shader: Fix shader serialization
This commit is contained in:
parent
ef737a8ecd
commit
7d2673eabd
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
static_assert(std::is_same_v<std::size_t, UInt32> || std::is_same_v<std::size_t, UInt64>);
|
||||
|
||||
class NAZARA_SHADER_API ShaderAstSerializerBase
|
||||
{
|
||||
public:
|
||||
|
|
@ -70,6 +68,7 @@ namespace Nz
|
|||
virtual void Value(UInt16& val) = 0;
|
||||
virtual void Value(UInt32& val) = 0;
|
||||
virtual void Value(UInt64& val) = 0;
|
||||
inline void SizeT(std::size_t& val);
|
||||
|
||||
virtual void Variable(ShaderNodes::VariablePtr& var) = 0;
|
||||
template<typename T> void Variable(std::shared_ptr<T>& var);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,12 @@ namespace Nz
|
|||
optVal.emplace();
|
||||
|
||||
if (optVal.has_value())
|
||||
Value(optVal.value());
|
||||
{
|
||||
if constexpr (std::is_same_v<T, std::size_t>)
|
||||
SizeT(optVal.value());
|
||||
else
|
||||
Value(optVal.value());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
@ -86,6 +91,20 @@ namespace Nz
|
|||
node = std::static_pointer_cast<T>(value);
|
||||
}
|
||||
|
||||
inline void ShaderAstSerializerBase::SizeT(std::size_t& val)
|
||||
{
|
||||
bool isWriting = IsWriting();
|
||||
|
||||
UInt32 fixedVal;
|
||||
if (isWriting)
|
||||
fixedVal = static_cast<UInt32>(val);
|
||||
|
||||
Value(fixedVal);
|
||||
|
||||
if (!isWriting)
|
||||
val = static_cast<std::size_t>(fixedVal);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ShaderAstSerializerBase::Variable(std::shared_ptr<T>& var)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ namespace Nz
|
|||
|
||||
Container(node.memberIndices);
|
||||
for (std::size_t& index : node.memberIndices)
|
||||
Value(index);
|
||||
SizeT(index);
|
||||
}
|
||||
|
||||
void ShaderAstSerializerBase::Serialize(ShaderNodes::AssignOp& node)
|
||||
|
|
|
|||
Loading…
Reference in New Issue