From 8b899253b14cfc083b7e1cf377e62dc41234f807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 1 Dec 2021 18:57:50 +0100 Subject: [PATCH] Graphics/InstancedRenderable: Add support for render layer --- include/Nazara/Graphics/InstancedRenderable.hpp | 4 ++++ include/Nazara/Graphics/InstancedRenderable.inl | 14 +++++++++++++- src/Nazara/Graphics/Model.cpp | 2 +- src/Nazara/Graphics/SlicedSprite.cpp | 2 +- src/Nazara/Graphics/Sprite.cpp | 2 +- src/Nazara/Graphics/TextSprite.cpp | 2 +- 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/Nazara/Graphics/InstancedRenderable.hpp b/include/Nazara/Graphics/InstancedRenderable.hpp index ab9ff80d1..745cb3182 100644 --- a/include/Nazara/Graphics/InstancedRenderable.hpp +++ b/include/Nazara/Graphics/InstancedRenderable.hpp @@ -33,6 +33,9 @@ namespace Nz inline const Boxf& GetAABB() const; virtual const std::shared_ptr& GetMaterial(std::size_t i) const = 0; virtual std::size_t GetMaterialCount() const = 0; + inline int GetRenderLayer() const; + + inline void UpdateRenderLayer(int renderLayer); InstancedRenderable& operator=(const InstancedRenderable&) = delete; InstancedRenderable& operator=(InstancedRenderable&&) noexcept = default; @@ -46,6 +49,7 @@ namespace Nz private: Boxf m_aabb; + int m_renderLayer; }; } diff --git a/include/Nazara/Graphics/InstancedRenderable.inl b/include/Nazara/Graphics/InstancedRenderable.inl index c430d8364..e1760966b 100644 --- a/include/Nazara/Graphics/InstancedRenderable.inl +++ b/include/Nazara/Graphics/InstancedRenderable.inl @@ -8,7 +8,8 @@ namespace Nz { inline InstancedRenderable::InstancedRenderable() : - m_aabb(Boxf::Zero()) + m_aabb(Boxf::Zero()), + m_renderLayer(0) { } @@ -17,6 +18,17 @@ namespace Nz return m_aabb; } + inline int InstancedRenderable::GetRenderLayer() const + { + return m_renderLayer; + } + + inline void InstancedRenderable::UpdateRenderLayer(int renderLayer) + { + m_renderLayer = renderLayer; + OnElementInvalidated(this); + } + inline void InstancedRenderable::UpdateAABB(Boxf aabb) { OnAABBUpdate(this, aabb); diff --git a/src/Nazara/Graphics/Model.cpp b/src/Nazara/Graphics/Model.cpp index c33e893cf..6450a8b67 100644 --- a/src/Nazara/Graphics/Model.cpp +++ b/src/Nazara/Graphics/Model.cpp @@ -46,7 +46,7 @@ namespace Nz const auto& vertexBuffer = m_graphicalMesh->GetVertexBuffer(i); const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(submeshData.vertexBufferData); - elements.emplace_back(std::make_unique(0, materialPass, renderPipeline, worldInstance, m_graphicalMesh->GetIndexCount(i), indexBuffer, vertexBuffer)); + elements.emplace_back(std::make_unique(GetRenderLayer(), materialPass, renderPipeline, worldInstance, m_graphicalMesh->GetIndexCount(i), indexBuffer, vertexBuffer)); } } diff --git a/src/Nazara/Graphics/SlicedSprite.cpp b/src/Nazara/Graphics/SlicedSprite.cpp index b96d19838..126e90cda 100644 --- a/src/Nazara/Graphics/SlicedSprite.cpp +++ b/src/Nazara/Graphics/SlicedSprite.cpp @@ -39,7 +39,7 @@ namespace Nz const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; - elements.emplace_back(std::make_unique(0, materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data())); + elements.emplace_back(std::make_unique(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data())); } const std::shared_ptr& SlicedSprite::GetMaterial(std::size_t i) const diff --git a/src/Nazara/Graphics/Sprite.cpp b/src/Nazara/Graphics/Sprite.cpp index 1b7f56020..f3aad6782 100644 --- a/src/Nazara/Graphics/Sprite.cpp +++ b/src/Nazara/Graphics/Sprite.cpp @@ -42,7 +42,7 @@ namespace Nz const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)]; - elements.emplace_back(std::make_unique(0, materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data())); + elements.emplace_back(std::make_unique(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data())); } const std::shared_ptr& Sprite::GetMaterial(std::size_t i) const diff --git a/src/Nazara/Graphics/TextSprite.cpp b/src/Nazara/Graphics/TextSprite.cpp index 952aeaa2f..6593b4333 100644 --- a/src/Nazara/Graphics/TextSprite.cpp +++ b/src/Nazara/Graphics/TextSprite.cpp @@ -42,7 +42,7 @@ namespace Nz RenderIndices& indices = pair.second; if (indices.count > 0) - elements.emplace_back(std::make_unique(0, materialPass, renderPipeline, worldInstance, vertexDeclaration, key.texture->shared_from_this(), indices.count, &m_vertices[indices.first * 4])); + elements.emplace_back(std::make_unique(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, key.texture->shared_from_this(), indices.count, &m_vertices[indices.first * 4])); } }