Graphics: Add RenderSystem and frame pipeline

This commit is contained in:
Jérôme Leclercq
2021-07-06 11:04:22 +02:00
parent 428a706fbe
commit 4ac5fe7cba
37 changed files with 1202 additions and 141 deletions

View File

@@ -13,6 +13,7 @@
namespace Nz
{
class CameraComponent;
class GraphicsComponent;
class NodeComponent;
class RigidBody3DComponent;

View File

@@ -8,6 +8,19 @@
namespace Nz
{
namespace Detail
{
template<typename T>
struct RegisterComponent
{
void operator()(entt::id_type& expectedId)
{
if (entt::type_seq<T>() != expectedId++)
throw std::runtime_error(std::string(entt::type_name<T>::value()) + " has wrong index, please initialize Nazara ECS before instancing your own components");
}
};
}
/*!
* \ingroup core
* \class Nz::ECS
@@ -21,14 +34,8 @@ namespace Nz
inline void ECS::RegisterComponents()
{
if (entt::type_seq<NodeComponent>() != 0)
throw std::runtime_error("NodeComponent has wrong index, please initialize Nazara ECS before instancing your own components");
if (entt::type_seq<GraphicsComponent>() != 1)
throw std::runtime_error("GraphicsComponent has wrong index, please initialize Nazara ECS before instancing your own components");
if (entt::type_seq<RigidBody3DComponent>() != 2)
throw std::runtime_error("GraphicsComponent has wrong index, please initialize Nazara ECS before instancing your own components");
entt::id_type expectedId = 0;
TypeListApply<TypeList<NodeComponent, CameraComponent, GraphicsComponent, RigidBody3DComponent>, Detail::RegisterComponent>(expectedId);
}
}

View File

@@ -29,14 +29,17 @@
#ifndef NAZARA_GLOBAL_GRAPHICS_HPP
#define NAZARA_GLOBAL_GRAPHICS_HPP
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/BakedFrameGraph.hpp>
#include <Nazara/Graphics/BasicMaterial.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/ForwardFramePipeline.hpp>
#include <Nazara/Graphics/FrameGraph.hpp>
#include <Nazara/Graphics/FramePass.hpp>
#include <Nazara/Graphics/FramePassAttachment.hpp>
#include <Nazara/Graphics/FramePipeline.hpp>
#include <Nazara/Graphics/GraphicalMesh.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ABSTRACTVIEWER_HPP
#define NAZARA_ABSTRACTVIEWER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
namespace Nz
{
class RenderTarget;
class ViewerInstance;
class NAZARA_GRAPHICS_API AbstractViewer
{
public:
AbstractViewer() = default;
~AbstractViewer() = default;
virtual const RenderTarget& GetRenderTarget() = 0;
virtual ViewerInstance& GetViewerInstance() = 0;
virtual const ViewerInstance& GetViewerInstance() const = 0;
};
}
#include <Nazara/Graphics/AbstractViewer.inl>
#endif

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -29,6 +29,7 @@
#ifndef NAZARA_GLOBAL_GRAPHICS_COMPONENTS_HPP
#define NAZARA_GLOBAL_GRAPHICS_COMPONENTS_HPP
#include <Nazara/Graphics/Components/CameraComponent.hpp>
#include <Nazara/Graphics/Components/GraphicsComponent.hpp>
#endif // NAZARA_GLOBAL_GRAPHICS_COMPONENTS_HPP

View File

@@ -0,0 +1,48 @@
// Copyright (C) 2021 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CAMERACOMPONENT_HPP
#define NAZARA_CAMERACOMPONENT_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/AbstractViewer.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Graphics/ViewerInstance.hpp>
#include <memory>
#include <vector>
namespace Nz
{
class NAZARA_GRAPHICS_API CameraComponent : public AbstractViewer
{
public:
inline CameraComponent(const RenderTarget* renderTarget, ProjectionType projectionType = ProjectionType::Perspective);
CameraComponent(const CameraComponent&) = default;
CameraComponent(CameraComponent&&) = default;
~CameraComponent() = default;
const RenderTarget& GetRenderTarget() override;
ViewerInstance& GetViewerInstance() override;
const ViewerInstance& GetViewerInstance() const override;
inline void UpdateTarget(const RenderTarget* framebuffer);
inline void UpdateProjectionType(ProjectionType projectionType);
CameraComponent& operator=(const CameraComponent&) = default;
CameraComponent& operator=(CameraComponent&&) = default;
private:
inline void UpdateProjectionMatrix();
const RenderTarget* m_renderTarget;
ProjectionType m_projectionType;
ViewerInstance m_viewerInstance;
};
}
#include <Nazara/Graphics/Components/CameraComponent.inl>
#endif

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2021 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Graphics/Components/CameraComponent.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline CameraComponent::CameraComponent(const RenderTarget* renderTarget, ProjectionType projectionType) :
m_projectionType(projectionType),
m_renderTarget(renderTarget)
{
UpdateProjectionMatrix();
}
inline void CameraComponent::UpdateTarget(const RenderTarget* renderTarget)
{
m_renderTarget = renderTarget;
}
inline void CameraComponent::UpdateProjectionType(ProjectionType projectionType)
{
m_projectionType = projectionType;
UpdateProjectionMatrix();
}
inline void CameraComponent::UpdateProjectionMatrix()
{
//FIXME
switch (m_projectionType)
{
case ProjectionType::Orthographic:
m_viewerInstance.UpdateProjectionMatrix(Nz::Matrix4f::Ortho(0.f, 1920.f, 0.f, 1080.f));
break;
case ProjectionType::Perspective:
m_viewerInstance.UpdateProjectionMatrix(Nz::Matrix4f::Perspective(Nz::DegreeAnglef(70.f), 16.f / 9.f, 1.f, 1000.f));
break;
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Nz
class NAZARA_GRAPHICS_API GraphicsComponent
{
public:
GraphicsComponent() = default;
GraphicsComponent();
GraphicsComponent(const GraphicsComponent&) = default;
GraphicsComponent(GraphicsComponent&&) = default;
~GraphicsComponent() = default;
@@ -34,9 +34,12 @@ namespace Nz
GraphicsComponent& operator=(const GraphicsComponent&) = default;
GraphicsComponent& operator=(GraphicsComponent&&) = default;
NazaraSignal(OnRenderableAttached, GraphicsComponent* /*graphicsComponent*/, const std::shared_ptr<InstancedRenderable>& /*renderable*/);
NazaraSignal(OnRenderableDetach, GraphicsComponent* /*graphicsComponent*/, const std::shared_ptr<InstancedRenderable>& /*renderable*/);
private:
std::vector<std::shared_ptr<InstancedRenderable>> m_renderables;
WorldInstance m_worldInstance;
std::unique_ptr<WorldInstance> m_worldInstance;
};
}

View File

@@ -2,22 +2,32 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Utility/Components/NodeComponent.hpp>
#include <Nazara/Utility/Debug.hpp>
#include "GraphicsComponent.hpp"
#include <Nazara/Graphics/Components/GraphicsComponent.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline GraphicsComponent::GraphicsComponent()
{
m_worldInstance = std::make_unique<WorldInstance>(); //< FIXME
}
inline void GraphicsComponent::AttachRenderable(std::shared_ptr<InstancedRenderable> renderable)
{
m_renderables.push_back(std::move(renderable));
OnRenderableAttached(this, m_renderables.back());
}
inline void GraphicsComponent::DetachRenderable(const std::shared_ptr<InstancedRenderable>& renderable)
{
auto it = std::find(m_renderables.begin(), m_renderables.end(), renderable);
if (it != m_renderables.end())
{
OnRenderableDetach(this, renderable);
m_renderables.erase(it);
}
}
inline const std::vector<std::shared_ptr<InstancedRenderable>>& GraphicsComponent::GetRenderables() const
@@ -27,11 +37,11 @@ namespace Nz
inline WorldInstance& GraphicsComponent::GetWorldInstance()
{
return m_worldInstance;
return *m_worldInstance;
}
inline const WorldInstance& GraphicsComponent::GetWorldInstance() const
{
return m_worldInstance;
return *m_worldInstance;
}
}

View File

@@ -16,6 +16,12 @@ namespace Nz
Sphere,
Volume
};
enum class ProjectionType
{
Orthographic,
Perspective
};
}
#endif // NAZARA_ENUMS_GRAPHICS_HPP

View File

@@ -0,0 +1,84 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FORWARDFRAMEPIPELINE_HPP
#define NAZARA_FORWARDFRAMEPIPELINE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/BakedFrameGraph.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FramePipeline.hpp>
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Renderer/ShaderBinding.hpp>
#include <optional>
#include <unordered_map>
#include <unordered_set>
namespace Nz
{
class NAZARA_GRAPHICS_API ForwardFramePipeline : public FramePipeline
{
public:
ForwardFramePipeline();
ForwardFramePipeline(const ForwardFramePipeline&) = delete;
ForwardFramePipeline(ForwardFramePipeline&&) = delete;
~ForwardFramePipeline() = default;
void InvalidateViewer(AbstractViewer* viewerInstance) override;
void InvalidateWorldInstance(WorldInstance* worldInstance) override;
void RegisterInstancedDrawable(WorldInstance* worldInstance, const InstancedRenderable* instancedRenderable) override;
void RegisterViewer(AbstractViewer* viewerInstance) override;
void Render(RenderFrame& renderFrame) override;
void UnregisterInstancedDrawable(WorldInstance* worldInstance, const InstancedRenderable* instancedRenderable) override;
void UnregisterViewer(AbstractViewer* viewerInstance) override;
ForwardFramePipeline& operator=(const ForwardFramePipeline&) = delete;
ForwardFramePipeline& operator=(ForwardFramePipeline&&) = delete;
private:
BakedFrameGraph BuildFrameGraph();
void RegisterMaterial(Material* material);
void UnregisterMaterial(Material* material);
struct MaterialData
{
std::size_t usedCount = 0;
NazaraSlot(Material, OnMaterialInvalidated, onMaterialInvalided);
};
struct RenderableData
{
NazaraSlot(InstancedRenderable, OnMaterialInvalidated, onMaterialInvalidated);
};
struct ViewerData
{
std::size_t colorAttachment;
std::size_t depthStencilAttachment;
ShaderBindingPtr blitShaderBinding;
};
std::size_t m_forwardPass;
std::unordered_map<AbstractViewer*, ViewerData> m_viewers;
std::unordered_map<Material*, MaterialData> m_materials;
std::unordered_map<WorldInstance*, std::unordered_map<const InstancedRenderable*, RenderableData>> m_renderables;
std::unordered_set<AbstractViewer*> m_invalidatedViewerInstances;
std::unordered_set<Material*> m_invalidatedMaterials;
std::unordered_set<WorldInstance*> m_invalidatedWorldInstances;
BakedFrameGraph m_bakedFrameGraph;
bool m_rebuildFrameGraph;
bool m_rebuildForwardPass;
};
}
#include <Nazara/Graphics/ForwardFramePipeline.inl>
#endif

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/ForwardFramePipeline.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -9,8 +9,10 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/FramePassAttachment.hpp>
#include <functional>
#include <limits>
#include <optional>
#include <string>
@@ -30,7 +32,7 @@ namespace Nz
class NAZARA_GRAPHICS_API FramePass
{
public:
using CommandCallback = std::function<void(CommandBufferBuilder& builder)>;
using CommandCallback = std::function<void(CommandBufferBuilder& builder, const Recti& renderRect)>;
using ExecutionCallback = std::function<FramePassExecution()>;
struct DepthStencilClear;
struct Input;

View File

@@ -0,0 +1,46 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FRAMEPIPELINE_HPP
#define NAZARA_FRAMEPIPELINE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/Config.hpp>
namespace Nz
{
class AbstractViewer;
class InstancedRenderable;
class RenderFrame;
class WorldInstance;
class NAZARA_GRAPHICS_API FramePipeline
{
public:
FramePipeline() = default;
FramePipeline(const FramePipeline&) = delete;
FramePipeline(FramePipeline&&) noexcept = default;
virtual ~FramePipeline();
virtual void InvalidateViewer(AbstractViewer* viewerInstance) = 0;
virtual void InvalidateWorldInstance(WorldInstance* worldInstance) = 0;
virtual void RegisterInstancedDrawable(WorldInstance* worldInstance, const InstancedRenderable* instancedRenderable) = 0;
virtual void RegisterViewer(AbstractViewer* viewerInstance) = 0;
virtual void Render(RenderFrame& renderFrame) = 0;
virtual void UnregisterInstancedDrawable(WorldInstance* worldInstance, const InstancedRenderable* instancedRenderable) = 0;
virtual void UnregisterViewer(AbstractViewer* viewerInstance) = 0;
FramePipeline& operator=(const FramePipeline&) = delete;
FramePipeline& operator=(FramePipeline&&) noexcept = default;
};
}
#include <Nazara/Graphics/FramePipeline.inl>
#endif

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/FramePipeline.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -31,6 +31,11 @@ namespace Nz
Graphics(Config config);
~Graphics();
inline const std::shared_ptr<RenderPipeline>& GetBlitPipeline() const;
inline const std::shared_ptr<RenderPipelineLayout>& GetBlitPipelineLayout() const;
inline const std::shared_ptr<AbstractBuffer>& GetFullscreenVertexBuffer() const;
inline const std::shared_ptr<VertexDeclaration>& GetFullscreenVertexDeclaration() const;
inline PixelFormat GetPreferredDepthStencilFormat() const;
inline const std::shared_ptr<RenderPipelineLayout>& GetReferencePipelineLayout() const;
inline const std::shared_ptr<RenderDevice>& GetRenderDevice() const;
inline TextureSamplerCache& GetSamplerCache();
@@ -48,9 +53,18 @@ namespace Nz
static void FillWorldPipelineLayout(RenderPipelineLayoutInfo& layoutInfo, UInt32 set = WorldBindingSet);
private:
void BuildBlitPipeline();
void BuildFullscreenVertexBuffer();
void SelectDepthStencilFormats();
std::optional<TextureSamplerCache> m_samplerCache;
std::shared_ptr<AbstractBuffer> m_fullscreenVertexBuffer;
std::shared_ptr<RenderDevice> m_renderDevice;
std::shared_ptr<RenderPipeline> m_blitPipeline;
std::shared_ptr<RenderPipelineLayout> m_blitPipelineLayout;
std::shared_ptr<RenderPipelineLayout> m_referencePipelineLayout;
std::shared_ptr<VertexDeclaration> m_fullscreenVertexDeclaration;
PixelFormat m_preferredDepthStencilFormat;
static Graphics* s_instance;
};

View File

@@ -7,6 +7,31 @@
namespace Nz
{
inline const std::shared_ptr<RenderPipeline>& Graphics::GetBlitPipeline() const
{
return m_blitPipeline;
}
inline const std::shared_ptr<RenderPipelineLayout>& Graphics::GetBlitPipelineLayout() const
{
return m_blitPipelineLayout;
}
inline const std::shared_ptr<AbstractBuffer>& Graphics::GetFullscreenVertexBuffer() const
{
return m_fullscreenVertexBuffer;
}
inline const std::shared_ptr<VertexDeclaration>& Graphics::GetFullscreenVertexDeclaration() const
{
return m_fullscreenVertexDeclaration;
}
inline PixelFormat Graphics::GetPreferredDepthStencilFormat() const
{
return m_preferredDepthStencilFormat;
}
inline const std::shared_ptr<RenderPipelineLayout>& Graphics::GetReferencePipelineLayout() const
{
return m_referencePipelineLayout;

View File

@@ -8,11 +8,14 @@
#define NAZARA_INSTANCEDRENDERABLE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <memory>
namespace Nz
{
class CommandBufferBuilder;
class Material;
class WorldInstance;
class NAZARA_GRAPHICS_API InstancedRenderable
@@ -23,10 +26,15 @@ namespace Nz
InstancedRenderable(InstancedRenderable&&) noexcept = default;
~InstancedRenderable();
virtual void Draw(CommandBufferBuilder& commandBuffer, const WorldInstance& instance) const = 0;
virtual void Draw(CommandBufferBuilder& commandBuffer) const = 0;
virtual const std::shared_ptr<Material>& GetMaterial(std::size_t i) const = 0;
virtual std::size_t GetMaterialCount() const = 0;
InstancedRenderable& operator=(const InstancedRenderable&) = delete;
InstancedRenderable& operator=(InstancedRenderable&&) noexcept = default;
NazaraSignal(OnMaterialInvalidated, InstancedRenderable* /*instancedRenderable*/, std::size_t /*materialIndex*/, const std::shared_ptr<Material>& /*newMaterial*/);
};
}

View File

@@ -75,8 +75,8 @@ namespace Nz
inline const std::shared_ptr<Texture>& GetTexture(std::size_t textureIndex) const;
inline const TextureSamplerInfo& GetTextureSampler(std::size_t textureIndex) const;
inline const std::shared_ptr<AbstractBuffer>& GetUniformBuffer(std::size_t bufferIndex) const;
inline std::vector<UInt8>& GetUniformBufferData(std::size_t bufferIndex);
inline const std::vector<UInt8>& GetUniformBufferConstData(std::size_t bufferIndex);
inline std::vector<UInt8>& GetUniformBufferData(std::size_t bufferIndex);
inline bool HasTexture(std::size_t textureIndex) const;
inline bool HasVertexColor() const;
@@ -109,12 +109,14 @@ namespace Nz
bool Update(RenderFrame& renderFrame, CommandBufferBuilder& builder);
// Signals:
NazaraSignal(OnMaterialInvalidated, const Material* /*material*/);
NazaraSignal(OnMaterialRelease, const Material* /*material*/);
private:
inline void InvalidatePipeline();
inline void InvalidateShaderBinding();
inline void InvalidateTextureSampler(std::size_t textureIndex);
inline void InvalidateUniformData(std::size_t uniformBufferIndex);
inline void UpdatePipeline() const;
void UpdateShaderBinding();

View File

@@ -468,20 +468,21 @@ namespace Nz
return m_uniformBuffers[bufferIndex].buffer;
}
inline std::vector<UInt8>& Material::GetUniformBufferData(std::size_t bufferIndex)
{
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
UniformBuffer& uboEntry = m_uniformBuffers[bufferIndex];
uboEntry.dataInvalidated = true;
return uboEntry.data;
}
inline const std::vector<UInt8>& Material::GetUniformBufferConstData(std::size_t bufferIndex)
{
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
return m_uniformBuffers[bufferIndex].data;
}
inline std::vector<UInt8>& Material::GetUniformBufferData(std::size_t bufferIndex)
{
NazaraAssert(bufferIndex < m_uniformBuffers.size(), "Invalid uniform buffer index");
UniformBuffer& uboEntry = m_uniformBuffers[bufferIndex];
InvalidateUniformData(bufferIndex);
return uboEntry.data;
}
inline bool Material::HasTexture(std::size_t textureIndex) const
{
return GetTexture(textureIndex) != nullptr;
@@ -740,11 +741,13 @@ namespace Nz
inline void Material::InvalidatePipeline()
{
m_pipelineUpdated = false;
OnMaterialInvalidated(this);
}
inline void Material::InvalidateShaderBinding()
{
m_shaderBindingUpdated = false;
OnMaterialInvalidated(this);
}
inline void Material::InvalidateTextureSampler(std::size_t textureIndex)
@@ -755,6 +758,15 @@ namespace Nz
InvalidateShaderBinding();
}
inline void Material::InvalidateUniformData(std::size_t uniformBufferIndex)
{
assert(uniformBufferIndex < m_uniformBuffers.size());
UniformBuffer& uboEntry = m_uniformBuffers[uniformBufferIndex];
uboEntry.dataInvalidated = true;
OnMaterialInvalidated(this);
}
inline void Material::UpdatePipeline() const
{
for (auto& shader : m_pipelineInfo.shaders)

View File

@@ -28,11 +28,12 @@ namespace Nz
Model(Model&&) noexcept = default;
~Model() = default;
void Draw(CommandBufferBuilder& commandBuffer, const WorldInstance& instance) const override;
void Draw(CommandBufferBuilder& commandBuffer) const override;
const std::shared_ptr<AbstractBuffer>& GetIndexBuffer(std::size_t subMeshIndex) const;
std::size_t GetIndexCount(std::size_t subMeshIndex) const;
const std::shared_ptr<Material>& GetMaterial(std::size_t subMeshIndex) const;
const std::shared_ptr<Material>& GetMaterial(std::size_t subMeshIndex) const override;
std::size_t GetMaterialCount() const override;
const std::shared_ptr<RenderPipeline>& GetRenderPipeline(std::size_t subMeshIndex) const;
const std::shared_ptr<AbstractBuffer>& GetVertexBuffer(std::size_t subMeshIndex) const;
inline std::size_t GetSubMeshCount() const;

View File

@@ -16,6 +16,8 @@ namespace Nz
inline void Model::SetMaterial(std::size_t subMeshIndex, std::shared_ptr<Material> material)
{
assert(subMeshIndex < m_subMeshes.size());
OnMaterialInvalidated(this, subMeshIndex, material);
m_subMeshes[subMeshIndex].material = std::move(material);
}
}

View File

@@ -0,0 +1,34 @@
// This file was automatically generated
/*
Nazara Engine - Graphics module
Copyright (C) 2020 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_GLOBAL_GRAPHICS_SYSTEMS_HPP
#define NAZARA_GLOBAL_GRAPHICS_SYSTEMS_HPP
#include <Nazara/Graphics/Systems/RenderSystem.hpp>
#endif // NAZARA_GLOBAL_GRAPHICS_SYSTEMS_HPP

View File

@@ -0,0 +1,72 @@
// Copyright (C) 2021 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RENDERSYSTEM_HPP
#define NAZARA_RENDERSYSTEM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ECS.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Graphics/Components/GraphicsComponent.hpp>
#include <Nazara/Utility/Node.hpp>
#include <memory>
#include <set>
#include <unordered_map>
namespace Nz
{
class CommandBufferBuilder;
class FramePipeline;
class RenderFrame;
class UploadPool;
class NAZARA_GRAPHICS_API RenderSystem
{
public:
RenderSystem(entt::registry& registry);
RenderSystem(const RenderSystem&) = delete;
RenderSystem(RenderSystem&&) = delete;
~RenderSystem();
void Render(entt::registry& registry, RenderFrame& renderFrame);
RenderSystem& operator=(const RenderSystem&) = delete;
RenderSystem& operator=(RenderSystem&&) = delete;
private:
void OnCameraDestroy(entt::registry& registry, entt::entity entity);
void OnGraphicsDestroy(entt::registry& registry, entt::entity entity);
void OnNodeDestroy(entt::registry& registry, entt::entity entity);
void UpdateInstances(entt::registry& registry);
struct CameraEntity
{
NazaraSlot(Node, OnNodeInvalidation, onNodeInvalidation);
};
struct GraphicsEntity
{
NazaraSlot(GraphicsComponent, OnRenderableAttached, onRenderableAttached);
NazaraSlot(GraphicsComponent, OnRenderableDetach, onRenderableDetach);
NazaraSlot(Node, OnNodeInvalidation, onNodeInvalidation);
};
entt::connection m_cameraDestroyConnection;
entt::connection m_graphicsDestroyConnection;
entt::connection m_nodeDestroyConnection;
entt::observer m_cameraConstructObserver;
entt::observer m_graphicsConstructObserver;
std::set<entt::entity> m_invalidatedCameraNode;
std::set<entt::entity> m_invalidatedWorldNode;
std::unique_ptr<FramePipeline> m_pipeline;
std::unordered_map<entt::entity, CameraEntity> m_cameraEntities;
std::unordered_map<entt::entity, GraphicsEntity> m_graphicsEntities;
};
}
#include <Nazara/Graphics/Systems/RenderSystem.inl>
#endif

View File

@@ -0,0 +1,12 @@
// Copyright (C) 2021 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
#include <Nazara/Graphics/Systems/RenderSystem.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -103,7 +103,7 @@ namespace std
NazaraRenderStateEnum(faceFilling);
if (pipelineInfo.blending) //< Remember, at this time we know lhs.blending == rhs.blending
if (pipelineInfo.blending) //< we don't care about blending state if blending isn't enabled
{
NazaraRenderStateEnum(blend.dstAlpha);
NazaraRenderStateEnum(blend.dstColor);
@@ -119,7 +119,7 @@ namespace std
if (pipelineInfo.faceCulling)
NazaraRenderStateEnum(cullingSide);
if (pipelineInfo.stencilTest)
if (pipelineInfo.stencilTest) //< we don't care about stencil state if stencil isn't enabled
{
NazaraRenderStateEnum(stencilBack.compare);
NazaraRenderStateUInt32(stencilBack.compareMask);