Merge branch 'master' into vulkan

This commit is contained in:
Lynix
2017-11-24 20:14:39 +01:00
559 changed files with 10925 additions and 3359 deletions

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEBUGDRAWER_HPP
#define NAZARA_DEBUGDRAWER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/OrientedBox.hpp>
#include <Nazara/Renderer/Config.hpp>
namespace Nz
{
class Skeleton;
class StaticMesh;
class NAZARA_RENDERER_API DebugDrawer
{
public:
static void Draw(const BoundingVolumef& volume);
static void Draw(const Boxf& box);
static void Draw(const Boxi& box);
static void Draw(const Boxui& box);
static void Draw(const Frustumf& frustum);
static void Draw(const OrientedBoxf& orientedBox);
static void Draw(const Skeleton* skeleton);
static void Draw(const Vector3f& position, float size = 0.1f);
static void DrawAxes(const Vector3f& position = Vector3f::Zero(), float size = 1.f);
static void DrawBinormals(const StaticMesh* subMesh);
static void DrawCone(const Vector3f& origin, const Quaternionf& rotation, float angle, float length);
static void DrawLine(const Vector3f& p1, const Vector3f& p2);
static void DrawPoints(const Vector3f* ptr, unsigned int pointCount);
static void DrawNormals(const StaticMesh* subMesh);
static void DrawTangents(const StaticMesh* subMesh);
static void EnableDepthBuffer(bool depthBuffer);
static float GetLineWidth();
static float GetPointSize();
static Color GetPrimaryColor();
static Color GetSecondaryColor();
static bool Initialize();
static bool IsDepthBufferEnabled();
static void SetLineWidth(float width);
static void SetPointSize(float size);
static void SetPrimaryColor(const Color& color);
static void SetSecondaryColor(const Color& color);
static void Uninitialize();
};
}
#endif // NAZARA_DEBUG_DRAWER_HPP

View File

@@ -0,0 +1,88 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_GLSLWRITER_HPP
#define NAZARA_GLSLWRITER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/ShaderWriter.hpp>
#include <set>
#include <unordered_map>
namespace Nz
{
class NAZARA_RENDERER_API GlslWriter : public ShaderWriter
{
public:
GlslWriter();
GlslWriter(const GlslWriter&) = delete;
GlslWriter(GlslWriter&&) = delete;
~GlslWriter() = default;
Nz::String Generate(const ShaderAst::StatementPtr& node) override;
void RegisterFunction(const String& name, ShaderAst::StatementPtr statement, std::initializer_list<ShaderAst::NamedVariablePtr> parameters, ShaderAst::ExpressionType ret) override;
void RegisterVariable(ShaderAst::VariableType kind, const String& name, ShaderAst::ExpressionType type) override;
void SetGlslVersion(unsigned int version);
void Write(const ShaderAst::AssignOp& node) override;
void Write(const ShaderAst::Branch& node) override;
void Write(const ShaderAst::BinaryOp& node) override;
void Write(const ShaderAst::BuiltinVariable& node) override;
void Write(const ShaderAst::Cast& node) override;
void Write(const ShaderAst::Constant& node) override;
void Write(const ShaderAst::ExpressionStatement& node) override;
void Write(const ShaderAst::NamedVariable& node) override;
void Write(const ShaderAst::NodePtr& node) override;
void Write(const ShaderAst::StatementBlock& node) override;
void Write(const ShaderAst::SwizzleOp& node) override;
private:
struct Function;
using VariableContainer = std::set<std::pair<ShaderAst::ExpressionType, String>>;
void Append(ShaderAst::BuiltinEntry builtin);
void Append(ShaderAst::ExpressionType type);
void Append(const String& txt);
void AppendCommentSection(const String& section);
void AppendFunction(Function& func);
void AppendLine(const String& txt = String());
void DeclareVariables(const VariableContainer& variables, const String& keyword = String(), const String& section = String());
void EnterScope();
void LeaveScope();
struct Function
{
VariableContainer variables;
std::vector<ShaderAst::NamedVariablePtr> parameters;
ShaderAst::ExpressionType retType;
ShaderAst::StatementPtr node;
String name;
};
struct State
{
VariableContainer inputs;
VariableContainer outputs;
VariableContainer uniforms;
StringStream stream;
unsigned int indentLevel = 0;
};
std::unordered_map<String, Function> m_functions;
Function* m_currentFunction;
State* m_currentState;
unsigned int m_glslVersion;
};
}
#endif // NAZARA_GLSLWRITER_HPP

View File

@@ -14,7 +14,7 @@
#include <Nazara/Renderer/RenderSurface.hpp>
#include <Nazara/Renderer/RenderWindowImpl.hpp>
#include <Nazara/Renderer/RenderWindowParameters.hpp>
#include <Nazara/Utility/Window.hpp>
#include <Nazara/Platform/Window.hpp>
#include <memory>
namespace Nz

View File

@@ -0,0 +1,134 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_HPP
#define NAZARA_SHADER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp>
namespace Nz
{
class Color;
class Shader;
class ShaderStage;
using ShaderConstRef = ObjectRef<const Shader>;
using ShaderLibrary = ObjectLibrary<Shader>;
using ShaderRef = ObjectRef<Shader>;
class NAZARA_RENDERER_API Shader : public RefCounted
{
friend ShaderLibrary;
friend class Renderer;
public:
Shader();
Shader(const Shader&) = delete;
Shader(Shader&&) = delete;
~Shader();
void AttachStage(ShaderStageType stage, const ShaderStage& shaderStage);
bool AttachStageFromFile(ShaderStageType stage, const String& filePath);
bool AttachStageFromSource(ShaderStageType stage, const char* source, unsigned int length);
bool AttachStageFromSource(ShaderStageType stage, const String& source);
void Bind() const;
bool Create();
void Destroy();
ByteArray GetBinary() const;
String GetLog() const;
String GetSourceCode(ShaderStageType stage) const;
int GetUniformLocation(const String& name) const;
int GetUniformLocation(ShaderUniform shaderUniform) const;
bool HasStage(ShaderStageType stage) const;
bool IsBinaryRetrievable() const;
bool IsLinked() const;
bool IsValid() const;
bool Link();
bool LoadFromBinary(const void* buffer, unsigned int size);
bool LoadFromBinary(const ByteArray& byteArray);
void SendBoolean(int location, bool value) const;
void SendColor(int location, const Color& color) const;
void SendDouble(int location, double value) const;
void SendDoubleArray(int location, const double* values, unsigned int count) const;
void SendFloat(int location, float value) const;
void SendFloatArray(int location, const float* values, unsigned int count) const;
void SendInteger(int location, int value) const;
void SendIntegerArray(int location, const int* values, unsigned int count) const;
void SendMatrix(int location, const Matrix4d& matrix) const;
void SendMatrix(int location, const Matrix4f& matrix) const;
void SendVector(int location, const Vector2d& vector) const;
void SendVector(int location, const Vector2f& vector) const;
void SendVector(int location, const Vector2i& vector) const;
void SendVector(int location, const Vector3d& vector) const;
void SendVector(int location, const Vector3f& vector) const;
void SendVector(int location, const Vector3i& vector) const;
void SendVector(int location, const Vector4d& vector) const;
void SendVector(int location, const Vector4f& vector) const;
void SendVector(int location, const Vector4i& vector) const;
void SendVectorArray(int location, const Vector2d* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector2f* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector2i* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector3d* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector3f* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector3i* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector4d* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector4f* vectors, unsigned int count) const;
void SendVectorArray(int location, const Vector4i* vectors, unsigned int count) const;
bool Validate() const;
// Fonctions OpenGL
unsigned int GetOpenGLID() const;
Shader& operator=(const Shader&) = delete;
Shader& operator=(Shader&&) = delete;
static bool IsStageSupported(ShaderStageType stage);
template<typename... Args> static ShaderRef New(Args&&... args);
// Signals:
NazaraSignal(OnShaderDestroy, const Shader* /*shader*/);
NazaraSignal(OnShaderRelease, const Shader* /*shader*/);
NazaraSignal(OnShaderUniformInvalidated, const Shader* /*shader*/);
private:
bool PostLinkage();
static bool Initialize();
static void Uninitialize();
std::vector<unsigned int> m_attachedShaders[ShaderStageType_Max+1];
bool m_linked;
int m_uniformLocations[ShaderUniform_Max+1];
unsigned int m_program;
static ShaderLibrary::LibraryMap s_library;
};
}
#include <Nazara/Renderer/Shader.inl>
#endif // NAZARA_SHADER_HPP

View File

@@ -0,0 +1,292 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_AST_HPP
#define NAZARA_SHADER_AST_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <array>
namespace Nz
{
class ShaderWriter;
namespace ShaderAst
{
enum class AssignType
{
Simple //< =
};
enum class BinaryType
{
Add, //< +
Substract, //< -
Multiply, //< *
Divide, //< /
Equality //< ==
};
enum class BuiltinEntry
{
VertexPosition, // gl_Position
};
enum class ExpressionType
{
Boolean, // bool
Float1, // float
Float2, // vec2
Float3, // vec3
Float4, // vec4
Mat4x4, // mat4
Void // void
};
enum class SwizzleComponent
{
First,
Second,
Third,
Fourth
};
enum class VariableType
{
Builtin,
Input,
Output,
Parameter,
Uniform,
Variable
};
//////////////////////////////////////////////////////////////////////////
class Node;
using NodePtr = std::shared_ptr<Node>;
class NAZARA_RENDERER_API Node
{
public:
virtual ~Node() = default;
virtual void Register(ShaderWriter& visitor) = 0;
virtual void Visit(ShaderWriter& visitor) = 0;
static inline unsigned int GetComponentCount(ExpressionType type);
static inline ExpressionType GetComponentType(ExpressionType type);
};
class Statement;
using StatementPtr = std::shared_ptr<Statement>;
class NAZARA_RENDERER_API Statement : public Node
{
};
class Expression;
using ExpressionPtr = std::shared_ptr<Expression>;
class NAZARA_RENDERER_API Expression : public Node
{
public:
virtual ExpressionType GetExpressionType() const = 0;
};
class NAZARA_RENDERER_API ExpressionStatement : public Statement
{
public:
inline explicit ExpressionStatement(ExpressionPtr expr);
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
ExpressionPtr expression;
};
//////////////////////////////////////////////////////////////////////////
class NAZARA_RENDERER_API ConditionalStatement : public Statement
{
public:
inline ConditionalStatement(const String& condition, StatementPtr statementPtr);
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
String conditionName;
StatementPtr statement;
};
class NAZARA_RENDERER_API StatementBlock : public Statement
{
public:
template<typename... Args> explicit StatementBlock(Args&&... args);
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
std::vector<StatementPtr> statements;
};
class Variable;
using VariablePtr = std::shared_ptr<Variable>;
class NAZARA_RENDERER_API Variable : public Expression
{
public:
inline Variable(VariableType varKind, ExpressionType varType);
ExpressionType GetExpressionType() const override;
ExpressionType type;
VariableType kind;
};
class NAZARA_RENDERER_API BuiltinVariable : public Variable
{
public:
inline BuiltinVariable(BuiltinEntry variable, ExpressionType varType);
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
BuiltinEntry var;
};
class NamedVariable;
using NamedVariablePtr = std::shared_ptr<NamedVariable>;
class NAZARA_RENDERER_API NamedVariable : public Variable
{
public:
inline NamedVariable(VariableType varKind, const Nz::String& varName, ExpressionType varType);
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
Nz::String name;
};
//////////////////////////////////////////////////////////////////////////
class NAZARA_RENDERER_API AssignOp : public Expression
{
public:
inline AssignOp(AssignType Op, VariablePtr Var, ExpressionPtr Right);
ExpressionType GetExpressionType() const override;
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
AssignType op;
VariablePtr variable;
ExpressionPtr right;
};
class NAZARA_RENDERER_API BinaryOp : public Expression
{
public:
inline BinaryOp(BinaryType Op, ExpressionPtr Left, ExpressionPtr Right);
ExpressionType GetExpressionType() const override;
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
BinaryType op;
ExpressionPtr left;
ExpressionPtr right;
};
class NAZARA_RENDERER_API Branch : public Statement
{
public:
inline Branch(ExpressionPtr condition, StatementPtr trueStatement, StatementPtr falseStatement = nullptr);
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
struct ConditionalStatement
{
ExpressionPtr condition;
StatementPtr statement;
};
std::vector<ConditionalStatement> condStatements;
StatementPtr elseStatement;
};
class NAZARA_RENDERER_API Cast : public Expression
{
public:
inline Cast(ExpressionType castTo, ExpressionPtr first, ExpressionPtr second = nullptr, ExpressionPtr third = nullptr, ExpressionPtr fourth = nullptr);
ExpressionType GetExpressionType() const override;
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
ExpressionType exprType;
std::array<ExpressionPtr, 4> expressions;
};
class NAZARA_RENDERER_API Constant : public Expression
{
public:
inline explicit Constant(bool value);
inline explicit Constant(float value);
inline explicit Constant(const Vector2f& value);
inline explicit Constant(const Vector3f& value);
inline explicit Constant(const Vector4f& value);
ExpressionType GetExpressionType() const override;
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
ExpressionType exprType;
union
{
bool bool1;
float vec1;
Vector2f vec2;
Vector3f vec3;
Vector4f vec4;
} values;
};
class NAZARA_RENDERER_API SwizzleOp : public Expression
{
public:
inline SwizzleOp(ExpressionPtr expressionPtr, std::initializer_list<SwizzleComponent> swizzleComponents);
ExpressionType GetExpressionType() const override;
void Register(ShaderWriter& visitor) override;
void Visit(ShaderWriter& visitor) override;
std::array<SwizzleComponent, 4> components;
std::size_t componentCount;
ExpressionPtr expression;
};
}
}
#include <Nazara/Renderer/ShaderAst.inl>
#endif // NAZARA_SHADER_AST_HPP

View File

@@ -0,0 +1,231 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/Debug.hpp>
namespace Nz
{
namespace ShaderAst
{
inline unsigned int Node::GetComponentCount(ExpressionType type)
{
switch (type)
{
case ExpressionType::Float2:
return 2;
case ExpressionType::Float3:
return 3;
case ExpressionType::Float4:
return 4;
case ExpressionType::Mat4x4:
return 4;
default:
return 1;
}
}
inline ExpressionType Node::GetComponentType(ExpressionType type)
{
switch (type)
{
case ExpressionType::Float2:
case ExpressionType::Float3:
case ExpressionType::Float4:
return ExpressionType::Float1;
case ExpressionType::Mat4x4:
return ExpressionType::Float4;
default:
return type;
}
}
inline ExpressionStatement::ExpressionStatement(ExpressionPtr expr) :
expression(std::move(expr))
{
}
inline ConditionalStatement::ConditionalStatement(const String& condition, StatementPtr statementPtr) :
conditionName(condition),
statement(std::move(statementPtr))
{
}
template<typename... Args>
StatementBlock::StatementBlock(Args&& ...args) :
statements({std::forward<Args>(args)...})
{
}
inline Variable::Variable(VariableType varKind, ExpressionType varType) :
type(varType),
kind(varKind)
{
}
inline BuiltinVariable::BuiltinVariable(BuiltinEntry variable, ExpressionType varType) :
Variable(VariableType::Builtin, varType),
var(variable)
{
}
inline NamedVariable::NamedVariable(VariableType varKind, const Nz::String& varName, ExpressionType varType) :
Variable(varKind, varType),
name(varName)
{
}
inline AssignOp::AssignOp(AssignType Op, VariablePtr Var, ExpressionPtr Right) :
op(Op),
variable(std::move(Var)),
right(std::move(Right))
{
}
inline BinaryOp::BinaryOp(BinaryType Op, ExpressionPtr Left, ExpressionPtr Right) :
op(Op),
left(std::move(Left)),
right(std::move(Right))
{
ExpressionType leftType = left->GetExpressionType();
ExpressionType rightType = right->GetExpressionType();
if (leftType != rightType)
{
switch (op)
{
case BinaryType::Add:
case BinaryType::Equality:
case BinaryType::Substract:
{
//TODO: AstParseError
throw std::runtime_error("Left expression type must match right expression type");
}
case BinaryType::Multiply:
case BinaryType::Divide:
{
switch (leftType)
{
case ExpressionType::Float2:
case ExpressionType::Float3:
case ExpressionType::Float4:
{
if (rightType != ExpressionType::Float1)
throw std::runtime_error("Left expression type is not compatible with right expression type");
break;
}
case ExpressionType::Mat4x4:
{
switch (rightType)
{
case ExpressionType::Float1:
case ExpressionType::Float4:
case ExpressionType::Mat4x4:
break;
//TODO: AstParseError
default:
throw std::runtime_error("Left expression type is not compatible with right expression type");
}
break;
}
default:
//TODO: AstParseError
throw std::runtime_error("Left expression type must match right expression type");
}
}
}
}
}
inline Branch::Branch(ExpressionPtr condition, StatementPtr trueStatement, StatementPtr falseStatement)
{
condStatements.emplace_back(ConditionalStatement{ std::move(condition), std::move(trueStatement) });
elseStatement = std::move(falseStatement);
}
inline Cast::Cast(ExpressionType castTo, ExpressionPtr first, ExpressionPtr second, ExpressionPtr third, ExpressionPtr fourth) :
exprType(castTo),
expressions({ {first, second, third, fourth} })
{
unsigned int componentCount = 0;
unsigned int requiredComponents = GetComponentCount(exprType);
for (const auto& exprPtr : expressions)
{
if (!exprPtr)
break;
componentCount += GetComponentCount(exprPtr->GetExpressionType());
}
//TODO: AstParseError
if (componentCount != requiredComponents)
throw std::runtime_error("Component count doesn't match required component count");
}
inline Constant::Constant(bool value) :
exprType(ExpressionType::Boolean)
{
values.bool1 = value;
}
inline Constant::Constant(float value) :
exprType(ExpressionType::Float1)
{
values.vec1 = value;
}
inline Constant::Constant(const Vector2f& value) :
exprType(ExpressionType::Float2)
{
values.vec2 = value;
}
inline Constant::Constant(const Vector3f& value) :
exprType(ExpressionType::Float3)
{
values.vec3 = value;
}
inline Constant::Constant(const Vector4f& value) :
exprType(ExpressionType::Float4)
{
values.vec4 = value;
}
inline SwizzleOp::SwizzleOp(ExpressionPtr expressionPtr, std::initializer_list<SwizzleComponent> swizzleComponents) :
componentCount(swizzleComponents.size()),
expression(expressionPtr)
{
if (componentCount > 4)
throw std::runtime_error("Cannot swizzle more than four elements");
switch (expressionPtr->GetExpressionType())
{
case ExpressionType::Float1:
case ExpressionType::Float2:
case ExpressionType::Float3:
case ExpressionType::Float4:
break;
default:
throw std::runtime_error("Cannot swizzle this type");
}
std::copy(swizzleComponents.begin(), swizzleComponents.end(), components.begin());
}
}
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -0,0 +1,79 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_BUILDER_HPP
#define NAZARA_SHADER_BUILDER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/ShaderAst.hpp>
#include <memory>
namespace Nz { namespace ShaderBuilder
{
template<ShaderAst::AssignType op>
struct AssignOpBuilder
{
constexpr AssignOpBuilder() {}
std::shared_ptr<ShaderAst::AssignOp> operator()(const ShaderAst::VariablePtr& left, const ShaderAst::ExpressionPtr& right) const;
};
template<ShaderAst::BinaryType op>
struct BinOpBuilder
{
constexpr BinOpBuilder() {}
std::shared_ptr<ShaderAst::BinaryOp> operator()(const ShaderAst::ExpressionPtr& left, const ShaderAst::ExpressionPtr& right) const;
};
struct BuiltinBuilder
{
constexpr BuiltinBuilder() {}
inline std::shared_ptr<ShaderAst::Variable> operator()(ShaderAst::BuiltinEntry builtin) const;
};
template<typename T>
struct GenBuilder
{
constexpr GenBuilder() {}
template<typename... Args> std::shared_ptr<T> operator()(Args&&... args) const;
};
template<ShaderAst::VariableType type>
struct VarBuilder
{
constexpr VarBuilder() {}
template<typename... Args> std::shared_ptr<ShaderAst::Variable> operator()(Args&&... args) const;
};
constexpr BinOpBuilder<ShaderAst::BinaryType::Add> Add;
constexpr AssignOpBuilder<ShaderAst::AssignType::Simple> Assign;
constexpr BuiltinBuilder Builtin;
constexpr GenBuilder<ShaderAst::StatementBlock> Block;
constexpr GenBuilder<ShaderAst::Branch> Branch;
constexpr GenBuilder<ShaderAst::ConditionalStatement> ConditionalStatement;
constexpr GenBuilder<ShaderAst::Constant> Constant;
constexpr BinOpBuilder<ShaderAst::BinaryType::Divide> Divide;
constexpr BinOpBuilder<ShaderAst::BinaryType::Equality> Equal;
constexpr GenBuilder<ShaderAst::ExpressionStatement> ExprStatement;
constexpr VarBuilder<ShaderAst::VariableType::Input> Input;
constexpr BinOpBuilder<ShaderAst::BinaryType::Multiply> Multiply;
constexpr VarBuilder<ShaderAst::VariableType::Output> Output;
constexpr VarBuilder<ShaderAst::VariableType::Parameter> Parameter;
constexpr GenBuilder<ShaderAst::SwizzleOp> Swizzle;
constexpr BinOpBuilder<ShaderAst::BinaryType::Substract> Substract;
constexpr VarBuilder<ShaderAst::VariableType::Uniform> Uniform;
constexpr VarBuilder<ShaderAst::VariableType::Variable> Variable;
template<ShaderAst::ExpressionType Type, typename... Args> std::shared_ptr<ShaderAst::Cast> Cast(Args&&... args);
} }
#include <Nazara/Renderer/ShaderBuilder.inl>
#endif // NAZARA_SHADER_BUILDER_HPP

View File

@@ -0,0 +1,59 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/ShaderBuilder.hpp>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz { namespace ShaderBuilder
{
template<typename T>
template<typename... Args>
std::shared_ptr<T> GenBuilder<T>::operator()(Args&&... args) const
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
template<ShaderAst::AssignType op>
std::shared_ptr<ShaderAst::AssignOp> AssignOpBuilder<op>::operator()(const ShaderAst::VariablePtr& left, const ShaderAst::ExpressionPtr& right) const
{
return std::make_shared<ShaderAst::AssignOp>(op, left, right);
}
template<ShaderAst::BinaryType op>
std::shared_ptr<ShaderAst::BinaryOp> BinOpBuilder<op>::operator()(const ShaderAst::ExpressionPtr& left, const ShaderAst::ExpressionPtr& right) const
{
return std::make_shared<ShaderAst::BinaryOp>(op, left, right);
}
inline std::shared_ptr<ShaderAst::Variable> BuiltinBuilder::operator()(ShaderAst::BuiltinEntry builtin) const
{
ShaderAst::ExpressionType exprType = ShaderAst::ExpressionType::Void;
switch (builtin)
{
case ShaderAst::BuiltinEntry::VertexPosition:
exprType = ShaderAst::ExpressionType::Float4;
break;
}
NazaraAssert(exprType != ShaderAst::ExpressionType::Void, "Unhandled builtin");
return std::make_shared<ShaderAst::BuiltinVariable>(builtin, exprType);
}
template<ShaderAst::VariableType type>
template<typename... Args>
std::shared_ptr<ShaderAst::Variable> VarBuilder<type>::operator()(Args&&... args) const
{
return std::make_shared<ShaderAst::NamedVariable>(type, std::forward<Args>(args)...);
}
template<ShaderAst::ExpressionType Type, typename... Args>
std::shared_ptr<ShaderAst::Cast> Cast(Args&&... args)
{
return std::make_shared<ShaderAst::Cast>(Type, std::forward<Args>(args)...);
}
} }
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -0,0 +1,52 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADERWRITER_HPP
#define NAZARA_SHADERWRITER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/ShaderAst.hpp>
#include <unordered_set>
namespace Nz
{
class NAZARA_RENDERER_API ShaderWriter
{
public:
ShaderWriter() = default;
ShaderWriter(const ShaderWriter&) = delete;
ShaderWriter(ShaderWriter&&) = delete;
virtual ~ShaderWriter();
void EnableCondition(const String& name, bool cond);
bool IsConditionEnabled(const String& name) const;
virtual Nz::String Generate(const ShaderAst::StatementPtr& node) = 0;
virtual void RegisterFunction(const String& name, ShaderAst::StatementPtr node, std::initializer_list<ShaderAst::NamedVariablePtr> parameters, ShaderAst::ExpressionType ret) = 0;
virtual void RegisterVariable(ShaderAst::VariableType kind, const String& name, ShaderAst::ExpressionType type) = 0;
virtual void Write(const ShaderAst::AssignOp& node) = 0;
virtual void Write(const ShaderAst::Branch& node) = 0;
virtual void Write(const ShaderAst::BinaryOp& node) = 0;
virtual void Write(const ShaderAst::BuiltinVariable& node) = 0;
virtual void Write(const ShaderAst::Cast& node) = 0;
virtual void Write(const ShaderAst::Constant& node) = 0;
virtual void Write(const ShaderAst::ExpressionStatement& node) = 0;
virtual void Write(const ShaderAst::NamedVariable& node) = 0;
virtual void Write(const ShaderAst::NodePtr& node) = 0;
virtual void Write(const ShaderAst::StatementBlock& node) = 0;
virtual void Write(const ShaderAst::SwizzleOp& node) = 0;
private:
std::unordered_set<String> m_conditions;
};
}
#endif // NAZARA_SHADERWRITER_HPP

View File

@@ -14,7 +14,6 @@
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/AbstractImage.hpp>
#include <Nazara/Utility/CubemapParams.hpp>
#include <Nazara/Utility/Image.hpp>