ShaderNodes: Replace union by std::variant

This commit is contained in:
Jérôme Leclercq
2020-08-04 01:33:31 +02:00
parent 50bd150345
commit 7736312c2f
5 changed files with 66 additions and 96 deletions

View File

@@ -220,22 +220,17 @@ namespace Nz
ShaderExpressionType GetExpressionType() const override;
void Visit(ShaderVisitor& visitor) override;
BasicType exprType;
using Variant = std::variant<
bool,
float,
Vector2f,
Vector3f,
Vector4f
>;
union
{
bool bool1;
float vec1;
Vector2f vec2;
Vector3f vec3;
Vector4f vec4;
} values;
Variant value;
static inline std::shared_ptr<Constant> Build(bool value);
static inline std::shared_ptr<Constant> Build(float value);
static inline std::shared_ptr<Constant> Build(const Vector2f& value);
static inline std::shared_ptr<Constant> Build(const Vector3f& value);
static inline std::shared_ptr<Constant> Build(const Vector4f& value);
template<typename T> static std::shared_ptr<Constant> Build(const T& value);
};
struct NAZARA_RENDERER_API SwizzleOp : public Expression

View File

@@ -239,47 +239,11 @@ namespace Nz::ShaderNodes
{
}
inline std::shared_ptr<Constant> Constant::Build(bool value)
template<typename T>
std::shared_ptr<Constant> Nz::ShaderNodes::Constant::Build(const T& value)
{
auto node = std::make_shared<Constant>();
node->exprType = BasicType::Boolean;
node->values.bool1 = value;
return node;
}
inline std::shared_ptr<Constant> Constant::Build(float value)
{
auto node = std::make_shared<Constant>();
node->exprType = BasicType::Float1;
node->values.vec1 = value;
return node;
}
inline std::shared_ptr<Constant> Constant::Build(const Vector2f& value)
{
auto node = std::make_shared<Constant>();
node->exprType = BasicType::Float2;
node->values.vec2 = value;
return node;
}
inline std::shared_ptr<Constant> Constant::Build(const Vector3f& value)
{
auto node = std::make_shared<Constant>();
node->exprType = BasicType::Float3;
node->values.vec3 = value;
return node;
}
inline std::shared_ptr<Constant> Constant::Build(const Vector4f& value)
{
auto node = std::make_shared<Constant>();
node->exprType = BasicType::Float4;
node->values.vec4 = value;
node->value = value;
return node;
}