ShaderNode: Add automatic variables
This commit is contained in:
@@ -40,6 +40,12 @@ namespace Nz
|
||||
VertexPosition, // gl_Position
|
||||
};
|
||||
|
||||
enum class ExpressionCategory
|
||||
{
|
||||
LValue,
|
||||
RValue
|
||||
};
|
||||
|
||||
enum class ExpressionType
|
||||
{
|
||||
Boolean, // bool
|
||||
@@ -104,6 +110,7 @@ namespace Nz
|
||||
class NAZARA_RENDERER_API Expression : public Node
|
||||
{
|
||||
public:
|
||||
virtual ExpressionCategory GetExpressionCategory() const;
|
||||
virtual ExpressionType GetExpressionType() const = 0;
|
||||
};
|
||||
|
||||
@@ -152,6 +159,7 @@ namespace Nz
|
||||
public:
|
||||
inline Variable(VariableType varKind, ExpressionType varType);
|
||||
|
||||
ExpressionCategory GetExpressionCategory() const override;
|
||||
ExpressionType GetExpressionType() const override;
|
||||
|
||||
ExpressionType type;
|
||||
@@ -191,14 +199,14 @@ namespace Nz
|
||||
class NAZARA_RENDERER_API AssignOp : public Expression
|
||||
{
|
||||
public:
|
||||
inline AssignOp(AssignType Op, VariablePtr Var, ExpressionPtr Right);
|
||||
inline AssignOp(AssignType Op, ExpressionPtr Left, ExpressionPtr Right);
|
||||
|
||||
ExpressionType GetExpressionType() const override;
|
||||
void Register(ShaderWriter& visitor) override;
|
||||
void Visit(ShaderWriter& visitor) override;
|
||||
|
||||
AssignType op;
|
||||
VariablePtr variable;
|
||||
ExpressionPtr left;
|
||||
ExpressionPtr right;
|
||||
};
|
||||
|
||||
@@ -277,6 +285,7 @@ namespace Nz
|
||||
public:
|
||||
inline SwizzleOp(ExpressionPtr expressionPtr, std::initializer_list<SwizzleComponent> swizzleComponents);
|
||||
|
||||
ExpressionCategory GetExpressionCategory() const override;
|
||||
ExpressionType GetExpressionType() const override;
|
||||
void Register(ShaderWriter& visitor) override;
|
||||
void Visit(ShaderWriter& visitor) override;
|
||||
|
||||
@@ -82,11 +82,14 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
inline AssignOp::AssignOp(AssignType Op, VariablePtr Var, ExpressionPtr Right) :
|
||||
inline AssignOp::AssignOp(AssignType Op, ExpressionPtr Left, ExpressionPtr Right) :
|
||||
op(Op),
|
||||
variable(std::move(Var)),
|
||||
left(std::move(Left)),
|
||||
right(std::move(Right))
|
||||
{
|
||||
if (left->GetExpressionCategory() != ExpressionCategory::LValue)
|
||||
//TODO: AstParseError
|
||||
throw std::runtime_error("Assignation is only possible with lvalues");
|
||||
}
|
||||
|
||||
inline BinaryOp::BinaryOp(BinaryType Op, ExpressionPtr Left, ExpressionPtr Right) :
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Nz { namespace ShaderBuilder
|
||||
{
|
||||
constexpr AssignOpBuilder() {}
|
||||
|
||||
std::shared_ptr<ShaderAst::AssignOp> operator()(const ShaderAst::VariablePtr& left, const ShaderAst::ExpressionPtr& right) const;
|
||||
std::shared_ptr<ShaderAst::AssignOp> operator()(const ShaderAst::ExpressionPtr& left, const ShaderAst::ExpressionPtr& right) const;
|
||||
};
|
||||
|
||||
template<ShaderAst::BinaryType op>
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Nz { namespace ShaderBuilder
|
||||
}
|
||||
|
||||
template<ShaderAst::AssignType op>
|
||||
std::shared_ptr<ShaderAst::AssignOp> AssignOpBuilder<op>::operator()(const ShaderAst::VariablePtr& left, const ShaderAst::ExpressionPtr& right) const
|
||||
std::shared_ptr<ShaderAst::AssignOp> AssignOpBuilder<op>::operator()(const ShaderAst::ExpressionPtr& left, const ShaderAst::ExpressionPtr& right) const
|
||||
{
|
||||
return std::make_shared<ShaderAst::AssignOp>(op, left, right);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user