Renderer/ShaderAst: Add support for expression type
This commit is contained in:
parent
12321bc59a
commit
a84391cf08
|
|
@ -43,6 +43,7 @@ namespace Nz
|
||||||
|
|
||||||
enum class ExpressionType
|
enum class ExpressionType
|
||||||
{
|
{
|
||||||
|
Boolean, // bool
|
||||||
Float1, // float
|
Float1, // float
|
||||||
Float2, // vec2
|
Float2, // vec2
|
||||||
Float3, // vec3
|
Float3, // vec3
|
||||||
|
|
@ -91,6 +92,8 @@ namespace Nz
|
||||||
|
|
||||||
class NAZARA_RENDERER_API Expression : public Node
|
class NAZARA_RENDERER_API Expression : public Node
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
virtual ExpressionType GetExpressionType() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NAZARA_RENDERER_API ExpressionStatement : public Statement
|
class NAZARA_RENDERER_API ExpressionStatement : public Statement
|
||||||
|
|
@ -126,6 +129,8 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
inline Variable(VariableType varKind, ExpressionType varType);
|
inline Variable(VariableType varKind, ExpressionType varType);
|
||||||
|
|
||||||
|
ExpressionType GetExpressionType() const override;
|
||||||
|
|
||||||
ExpressionType type;
|
ExpressionType type;
|
||||||
VariableType kind;
|
VariableType kind;
|
||||||
};
|
};
|
||||||
|
|
@ -163,6 +168,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
inline AssignOp(AssignType Op, VariablePtr Var, ExpressionPtr Right);
|
inline AssignOp(AssignType Op, VariablePtr Var, ExpressionPtr Right);
|
||||||
|
|
||||||
|
ExpressionType GetExpressionType() const override;
|
||||||
void Register(ShaderWriter& visitor) override;
|
void Register(ShaderWriter& visitor) override;
|
||||||
void Visit(ShaderWriter& visitor) override;
|
void Visit(ShaderWriter& visitor) override;
|
||||||
|
|
||||||
|
|
@ -176,6 +182,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
inline BinaryOp(BinaryType Op, ExpressionPtr Left, ExpressionPtr Right);
|
inline BinaryOp(BinaryType Op, ExpressionPtr Left, ExpressionPtr Right);
|
||||||
|
|
||||||
|
ExpressionType GetExpressionType() const override;
|
||||||
void Register(ShaderWriter& visitor) override;
|
void Register(ShaderWriter& visitor) override;
|
||||||
void Visit(ShaderWriter& visitor) override;
|
void Visit(ShaderWriter& visitor) override;
|
||||||
|
|
||||||
|
|
@ -207,6 +214,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
inline explicit Constant(float value);
|
inline explicit Constant(float value);
|
||||||
|
|
||||||
|
ExpressionType GetExpressionType() const override;
|
||||||
void Register(ShaderWriter& visitor) override;
|
void Register(ShaderWriter& visitor) override;
|
||||||
void Visit(ShaderWriter& visitor) override;
|
void Visit(ShaderWriter& visitor) override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||||
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Renderer/Debug.hpp>
|
#include <Nazara/Renderer/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
|
|
@ -50,6 +51,9 @@ namespace Nz
|
||||||
left(std::move(Left)),
|
left(std::move(Left)),
|
||||||
right(std::move(Right))
|
right(std::move(Right))
|
||||||
{
|
{
|
||||||
|
//TODO: AstParseError
|
||||||
|
if (left->GetExpressionType() != right->GetExpressionType())
|
||||||
|
throw std::runtime_error("Left expression type must match right expression type");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Branch::Branch(ExpressionPtr condition, StatementPtr trueStatement, StatementPtr falseStatement)
|
inline Branch::Branch(ExpressionPtr condition, StatementPtr trueStatement, StatementPtr falseStatement)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ namespace Nz { namespace ShaderAst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionType Variable::GetExpressionType() const
|
||||||
|
{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
void NamedVariable::Register(ShaderWriter& visitor)
|
void NamedVariable::Register(ShaderWriter& visitor)
|
||||||
{
|
{
|
||||||
visitor.RegisterVariable(kind, name, type);
|
visitor.RegisterVariable(kind, name, type);
|
||||||
|
|
@ -52,6 +57,11 @@ namespace Nz { namespace ShaderAst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionType AssignOp::GetExpressionType() const
|
||||||
|
{
|
||||||
|
return variable->GetExpressionType();
|
||||||
|
}
|
||||||
|
|
||||||
void AssignOp::Register(ShaderWriter& visitor)
|
void AssignOp::Register(ShaderWriter& visitor)
|
||||||
{
|
{
|
||||||
variable->Register(visitor);
|
variable->Register(visitor);
|
||||||
|
|
@ -64,6 +74,28 @@ namespace Nz { namespace ShaderAst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionType BinaryOp::GetExpressionType() const
|
||||||
|
{
|
||||||
|
ShaderAst::ExpressionType exprType = ShaderAst::ExpressionType::None;
|
||||||
|
|
||||||
|
switch (op)
|
||||||
|
{
|
||||||
|
case ShaderAst::BinaryType::Add:
|
||||||
|
case ShaderAst::BinaryType::Divide:
|
||||||
|
case ShaderAst::BinaryType::Multiply:
|
||||||
|
case ShaderAst::BinaryType::Substract:
|
||||||
|
exprType = left->GetExpressionType();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ShaderAst::BinaryType::Equality:
|
||||||
|
exprType = ExpressionType::Boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
NazaraAssert(exprType != ShaderAst::ExpressionType::None, "Unhandled builtin");
|
||||||
|
|
||||||
|
return exprType;
|
||||||
|
}
|
||||||
|
|
||||||
void BinaryOp::Register(ShaderWriter& visitor)
|
void BinaryOp::Register(ShaderWriter& visitor)
|
||||||
{
|
{
|
||||||
left->Register(visitor);
|
left->Register(visitor);
|
||||||
|
|
@ -94,6 +126,11 @@ namespace Nz { namespace ShaderAst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ExpressionType Constant::GetExpressionType() const
|
||||||
|
{
|
||||||
|
return exprType;
|
||||||
|
}
|
||||||
|
|
||||||
void Constant::Register(ShaderWriter&)
|
void Constant::Register(ShaderWriter&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue