Renderer/ShaderAst: Add support for expression type
This commit is contained in:
parent
12321bc59a
commit
a84391cf08
|
|
@ -43,13 +43,14 @@ namespace Nz
|
|||
|
||||
enum class ExpressionType
|
||||
{
|
||||
Float1, // float
|
||||
Float2, // vec2
|
||||
Float3, // vec3
|
||||
Float4, // vec4
|
||||
Mat4x4, // mat4
|
||||
Boolean, // bool
|
||||
Float1, // float
|
||||
Float2, // vec2
|
||||
Float3, // vec3
|
||||
Float4, // vec4
|
||||
Mat4x4, // mat4
|
||||
|
||||
None // void
|
||||
None // void
|
||||
};
|
||||
|
||||
enum class VariableType
|
||||
|
|
@ -91,6 +92,8 @@ namespace Nz
|
|||
|
||||
class NAZARA_RENDERER_API Expression : public Node
|
||||
{
|
||||
public:
|
||||
virtual ExpressionType GetExpressionType() const = 0;
|
||||
};
|
||||
|
||||
class NAZARA_RENDERER_API ExpressionStatement : public Statement
|
||||
|
|
@ -126,6 +129,8 @@ namespace Nz
|
|||
public:
|
||||
inline Variable(VariableType varKind, ExpressionType varType);
|
||||
|
||||
ExpressionType GetExpressionType() const override;
|
||||
|
||||
ExpressionType type;
|
||||
VariableType kind;
|
||||
};
|
||||
|
|
@ -163,6 +168,7 @@ namespace Nz
|
|||
public:
|
||||
inline AssignOp(AssignType Op, VariablePtr Var, ExpressionPtr Right);
|
||||
|
||||
ExpressionType GetExpressionType() const override;
|
||||
void Register(ShaderWriter& visitor) override;
|
||||
void Visit(ShaderWriter& visitor) override;
|
||||
|
||||
|
|
@ -176,6 +182,7 @@ namespace Nz
|
|||
public:
|
||||
inline BinaryOp(BinaryType Op, ExpressionPtr Left, ExpressionPtr Right);
|
||||
|
||||
ExpressionType GetExpressionType() const override;
|
||||
void Register(ShaderWriter& visitor) override;
|
||||
void Visit(ShaderWriter& visitor) override;
|
||||
|
||||
|
|
@ -207,6 +214,7 @@ namespace Nz
|
|||
public:
|
||||
inline explicit Constant(float value);
|
||||
|
||||
ExpressionType GetExpressionType() const override;
|
||||
void Register(ShaderWriter& visitor) override;
|
||||
void Visit(ShaderWriter& visitor) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/ShaderAst.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -50,6 +51,9 @@ namespace Nz
|
|||
left(std::move(Left)),
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ namespace Nz { namespace ShaderAst
|
|||
}
|
||||
|
||||
|
||||
ExpressionType Variable::GetExpressionType() const
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
void NamedVariable::Register(ShaderWriter& visitor)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
left->Register(visitor);
|
||||
|
|
@ -94,6 +126,11 @@ namespace Nz { namespace ShaderAst
|
|||
}
|
||||
|
||||
|
||||
ExpressionType Constant::GetExpressionType() const
|
||||
{
|
||||
return exprType;
|
||||
}
|
||||
|
||||
void Constant::Register(ShaderWriter&)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue