diff --git a/include/Nazara/Graphics/Camera.inl b/include/Nazara/Graphics/Camera.inl index 244579843..ab4dcc37a 100644 --- a/include/Nazara/Graphics/Camera.inl +++ b/include/Nazara/Graphics/Camera.inl @@ -231,6 +231,8 @@ namespace Nz // Convert it back to int m_viewport.Set(fViewport); + m_viewerInstance.UpdateTargetSize(fViewport.GetLengths()); + UpdateProjectionMatrix(); } } diff --git a/include/Nazara/Graphics/InstancedRenderable.hpp b/include/Nazara/Graphics/InstancedRenderable.hpp index 745cb3182..5a0b5275c 100644 --- a/include/Nazara/Graphics/InstancedRenderable.hpp +++ b/include/Nazara/Graphics/InstancedRenderable.hpp @@ -34,8 +34,10 @@ namespace Nz virtual const std::shared_ptr& GetMaterial(std::size_t i) const = 0; virtual std::size_t GetMaterialCount() const = 0; inline int GetRenderLayer() const; + inline const Recti& GetScissorBox() const; inline void UpdateRenderLayer(int renderLayer); + inline void UpdateScissorBox(const Recti& scissorBox); InstancedRenderable& operator=(const InstancedRenderable&) = delete; InstancedRenderable& operator=(InstancedRenderable&&) noexcept = default; @@ -49,6 +51,7 @@ namespace Nz private: Boxf m_aabb; + Recti m_scissorBox; int m_renderLayer; }; } diff --git a/include/Nazara/Graphics/InstancedRenderable.inl b/include/Nazara/Graphics/InstancedRenderable.inl index 410451aac..021d89f14 100644 --- a/include/Nazara/Graphics/InstancedRenderable.inl +++ b/include/Nazara/Graphics/InstancedRenderable.inl @@ -23,6 +23,11 @@ namespace Nz return m_renderLayer; } + inline const Recti& InstancedRenderable::GetScissorBox() const + { + return m_scissorBox; + } + inline void InstancedRenderable::UpdateRenderLayer(int renderLayer) { if (m_renderLayer != renderLayer) @@ -32,6 +37,15 @@ namespace Nz } } + inline void InstancedRenderable::UpdateScissorBox(const Recti& scissorBox) + { + if (m_scissorBox != scissorBox) + { + m_scissorBox = scissorBox; + OnElementInvalidated(this); + } + } + inline void InstancedRenderable::UpdateAABB(Boxf aabb) { OnAABBUpdate(this, aabb); diff --git a/include/Nazara/Graphics/Model.hpp b/include/Nazara/Graphics/Model.hpp index 2984c279d..84edcb431 100644 --- a/include/Nazara/Graphics/Model.hpp +++ b/include/Nazara/Graphics/Model.hpp @@ -52,6 +52,7 @@ namespace Nz std::shared_ptr m_graphicalMesh; std::vector m_submeshes; + Recti m_scissorBox; }; } diff --git a/include/Nazara/Graphics/RenderSpriteChain.hpp b/include/Nazara/Graphics/RenderSpriteChain.hpp index a53ac1da7..af960d939 100644 --- a/include/Nazara/Graphics/RenderSpriteChain.hpp +++ b/include/Nazara/Graphics/RenderSpriteChain.hpp @@ -8,7 +8,6 @@ #define NAZARA_GRAPHICS_RENDERSPRITECHAIN_HPP #include -#include #include #include #include @@ -25,13 +24,14 @@ namespace Nz class RenderSpriteChain : public RenderElement { public: - inline RenderSpriteChain(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::shared_ptr vertexDeclaration, std::shared_ptr textureOverlay, std::size_t spriteCount, const void* spriteData); + inline RenderSpriteChain(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::shared_ptr vertexDeclaration, std::shared_ptr textureOverlay, std::size_t spriteCount, const void* spriteData, const Recti& scissorBox); ~RenderSpriteChain() = default; inline UInt64 ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const override; inline const MaterialPass& GetMaterialPass() const; inline const RenderPipeline& GetRenderPipeline() const; + inline const Recti& GetScissorBox() const; inline std::size_t GetSpriteCount() const; inline const void* GetSpriteData() const; inline const Texture* GetTextureOverlay() const; @@ -48,6 +48,7 @@ namespace Nz std::size_t m_spriteCount; const void* m_spriteData; const WorldInstance& m_worldInstance; + Recti m_scissorBox; int m_renderLayer; }; } diff --git a/include/Nazara/Graphics/RenderSpriteChain.inl b/include/Nazara/Graphics/RenderSpriteChain.inl index 63cc3ad52..39ee430c4 100644 --- a/include/Nazara/Graphics/RenderSpriteChain.inl +++ b/include/Nazara/Graphics/RenderSpriteChain.inl @@ -4,11 +4,12 @@ #include #include +#include #include namespace Nz { - inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::shared_ptr vertexDeclaration, std::shared_ptr textureOverlay, std::size_t spriteCount, const void* spriteData) : + inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::shared_ptr vertexDeclaration, std::shared_ptr textureOverlay, std::size_t spriteCount, const void* spriteData, const Recti& scissorBox) : RenderElement(BasicRenderElement::SpriteChain), m_materialPass(std::move(materialPass)), m_renderPipeline(std::move(renderPipeline)), @@ -17,6 +18,7 @@ namespace Nz m_spriteCount(spriteCount), m_spriteData(spriteData), m_worldInstance(worldInstance), + m_scissorBox(scissorBox), m_renderLayer(renderLayer) { } @@ -34,8 +36,9 @@ namespace Nz // Transparent RQ index: // - Layer (8bits) - // - Transparent flag (1bit) - // - Distance to near plane (32bits) + // - Sorted by distance flag (1bit) + // - Distance to near plane (32bits) - could by reduced to 24 or even 16 if required + // - ?? (23bits) return (layerIndex & 0xFF) << 60 | (matFlags) << 52 | @@ -53,7 +56,7 @@ namespace Nz // Opaque RQ index: // - Layer (8bits) - // - Transparent flag (1bit) + // - Sorted by distance flag (1bit) // - Element type (4bits) // - Pipeline (16bits) // - MaterialPass (16bits) @@ -79,6 +82,11 @@ namespace Nz return *m_renderPipeline; } + inline const Recti& RenderSpriteChain::GetScissorBox() const + { + return m_scissorBox; + } + inline std::size_t RenderSpriteChain::GetSpriteCount() const { return m_spriteCount; diff --git a/include/Nazara/Graphics/RenderSubmesh.hpp b/include/Nazara/Graphics/RenderSubmesh.hpp index a78351f75..1a0376791 100644 --- a/include/Nazara/Graphics/RenderSubmesh.hpp +++ b/include/Nazara/Graphics/RenderSubmesh.hpp @@ -24,7 +24,7 @@ namespace Nz class RenderSubmesh : public RenderElement { public: - inline RenderSubmesh(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr indexBuffer, std::shared_ptr vertexBuffer); + inline RenderSubmesh(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr indexBuffer, std::shared_ptr vertexBuffer, const Recti& scissorBox); ~RenderSubmesh() = default; inline UInt64 ComputeSortingScore(const Frustumf& frustum, const RenderQueueRegistry& registry) const override; @@ -33,6 +33,7 @@ namespace Nz inline std::size_t GetIndexCount() const; inline const MaterialPass& GetMaterialPass() const; inline const RenderPipeline* GetRenderPipeline() const; + inline const Recti& GetScissorBox() const; inline const AbstractBuffer* GetVertexBuffer() const; inline const WorldInstance& GetWorldInstance() const; @@ -45,6 +46,7 @@ namespace Nz std::shared_ptr m_renderPipeline; std::size_t m_indexCount; const WorldInstance& m_worldInstance; + Recti m_scissorBox; int m_renderLayer; }; } diff --git a/include/Nazara/Graphics/RenderSubmesh.inl b/include/Nazara/Graphics/RenderSubmesh.inl index 0863c1f7a..e9d6e2be7 100644 --- a/include/Nazara/Graphics/RenderSubmesh.inl +++ b/include/Nazara/Graphics/RenderSubmesh.inl @@ -9,7 +9,7 @@ namespace Nz { - inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr indexBuffer, std::shared_ptr vertexBuffer) : + inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr materialPass, std::shared_ptr renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr indexBuffer, std::shared_ptr vertexBuffer, const Recti& scissorBox) : RenderElement(BasicRenderElement::Submesh), m_indexBuffer(std::move(indexBuffer)), m_vertexBuffer(std::move(vertexBuffer)), @@ -17,6 +17,7 @@ namespace Nz m_renderPipeline(std::move(renderPipeline)), m_indexCount(indexCount), m_worldInstance(worldInstance), + m_scissorBox(scissorBox), m_renderLayer(renderLayer) { } @@ -34,8 +35,9 @@ namespace Nz // Transparent RQ index: // - Layer (8bits) - // - Transparent flag (1bit) - // - Distance to near plane (32bits) + // - Sorted by distance flag (1bit) + // - Distance to near plane (32bits) - could by reduced to 24 or even 16 if required + // - ?? (23bits) return (layerIndex & 0xFF) << 60 | (matFlags) << 52 | @@ -52,7 +54,7 @@ namespace Nz // Opaque RQ index: // - Layer (8bits) - // - Transparent flag (1bit) + // - Sorted by distance flag (1bit) // - Element type (4bits) // - Pipeline (16bits) // - MaterialPass (16bits) @@ -88,6 +90,11 @@ namespace Nz return m_renderPipeline.get(); } + inline const Recti& RenderSubmesh::GetScissorBox() const + { + return m_scissorBox; + } + inline const AbstractBuffer* RenderSubmesh::GetVertexBuffer() const { return m_vertexBuffer.get(); diff --git a/include/Nazara/Graphics/SpriteChainRenderer.hpp b/include/Nazara/Graphics/SpriteChainRenderer.hpp index 7f840d20e..d5dc9bb79 100644 --- a/include/Nazara/Graphics/SpriteChainRenderer.hpp +++ b/include/Nazara/Graphics/SpriteChainRenderer.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -65,6 +66,7 @@ namespace Nz const ShaderBinding* shaderBinding; std::size_t firstIndex; std::size_t quadCount; + Recti scissorBox; }; struct DrawCallIndices diff --git a/include/Nazara/Graphics/SubmeshRenderer.hpp b/include/Nazara/Graphics/SubmeshRenderer.hpp index 7bfe3d033..2f0b4a52f 100644 --- a/include/Nazara/Graphics/SubmeshRenderer.hpp +++ b/include/Nazara/Graphics/SubmeshRenderer.hpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace Nz @@ -41,6 +42,7 @@ namespace Nz const RenderPipeline* renderPipeline; const ShaderBinding* shaderBinding; std::size_t indexCount; + Recti scissorBox; }; std::vector drawCalls; diff --git a/include/Nazara/Graphics/TextSprite.hpp b/include/Nazara/Graphics/TextSprite.hpp index c701eb7dd..8cb1e0a3a 100644 --- a/include/Nazara/Graphics/TextSprite.hpp +++ b/include/Nazara/Graphics/TextSprite.hpp @@ -95,6 +95,7 @@ namespace Nz std::shared_ptr m_material; std::vector m_data; std::vector m_vertices; + Recti m_scissorBox; }; } diff --git a/include/Nazara/Graphics/ViewerInstance.hpp b/include/Nazara/Graphics/ViewerInstance.hpp index 3db198f02..11be0a080 100644 --- a/include/Nazara/Graphics/ViewerInstance.hpp +++ b/include/Nazara/Graphics/ViewerInstance.hpp @@ -32,6 +32,7 @@ namespace Nz inline const Matrix4f& GetInvViewMatrix() const; inline const Matrix4f& GetInvViewProjMatrix() const; inline const Matrix4f& GetProjectionMatrix() const; + inline const Vector2f& GetTargetSize() const; inline const Matrix4f& GetViewMatrix() const; inline const Matrix4f& GetViewProjMatrix() const; inline std::shared_ptr& GetViewerBuffer(); diff --git a/include/Nazara/Graphics/ViewerInstance.inl b/include/Nazara/Graphics/ViewerInstance.inl index 468de8ce2..77c4b768f 100644 --- a/include/Nazara/Graphics/ViewerInstance.inl +++ b/include/Nazara/Graphics/ViewerInstance.inl @@ -28,6 +28,11 @@ namespace Nz return m_projectionMatrix; } + inline const Vector2f& ViewerInstance::GetTargetSize() const + { + return m_targetSize; + } + inline const Matrix4f& ViewerInstance::GetViewMatrix() const { return m_viewMatrix; diff --git a/src/Nazara/Graphics/Model.cpp b/src/Nazara/Graphics/Model.cpp index 6450a8b67..0130ee1ea 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(GetRenderLayer(), 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, GetScissorBox())); } } diff --git a/src/Nazara/Graphics/SlicedSprite.cpp b/src/Nazara/Graphics/SlicedSprite.cpp index 126e90cda..4b48e48a8 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(GetRenderLayer(), 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(), GetScissorBox())); } 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 f3aad6782..11c0644b6 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(GetRenderLayer(), 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(), GetScissorBox())); } const std::shared_ptr& Sprite::GetMaterial(std::size_t i) const diff --git a/src/Nazara/Graphics/SpriteChainRenderer.cpp b/src/Nazara/Graphics/SpriteChainRenderer.cpp index d21db2eda..96be59460 100644 --- a/src/Nazara/Graphics/SpriteChainRenderer.cpp +++ b/src/Nazara/Graphics/SpriteChainRenderer.cpp @@ -59,6 +59,8 @@ namespace Nz auto& data = static_cast(rendererData); + Recti invalidScissorBox(-1, -1, -1, -1); + std::size_t firstQuadIndex = 0; SpriteChainRendererData::DrawCall* currentDrawCall = nullptr; UploadPool::Allocation* currentAllocation = nullptr; @@ -70,6 +72,7 @@ namespace Nz const ShaderBinding* currentShaderBinding = nullptr; const Texture* currentTextureOverlay = nullptr; const WorldInstance* currentWorldInstance = nullptr; + Recti currentScissorBox = invalidScissorBox; auto FlushDrawCall = [&]() { @@ -149,6 +152,14 @@ namespace Nz currentTextureOverlay = textureOverlay; } + const Recti& scissorBox = spriteChain.GetScissorBox(); + const Recti& targetScissorBox = (scissorBox.width >= 0) ? scissorBox : invalidScissorBox; + if (currentScissorBox != targetScissorBox) + { + FlushDrawData(); + currentScissorBox = targetScissorBox; + } + std::size_t remainingQuads = spriteChain.GetSpriteCount(); const UInt8* spriteData = static_cast(spriteChain.GetSpriteData()); @@ -236,6 +247,7 @@ namespace Nz currentShaderBinding, 6 * firstQuadIndex, 0, + currentScissorBox }); currentDrawCall = &data.drawCalls.back(); @@ -287,15 +299,19 @@ namespace Nz } } - void SpriteChainRenderer::Render(const ViewerInstance& /*viewerInstance*/, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer* elements, std::size_t /*elementCount*/) + void SpriteChainRenderer::Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer* elements, std::size_t /*elementCount*/) { auto& data = static_cast(rendererData); commandBuffer.BindIndexBuffer(*m_indexBuffer); + Vector2f targetSize = viewerInstance.GetTargetSize(); + Recti fullscreenScissorBox(0, 0, SafeCast(std::floor(targetSize.x)), SafeCast(std::floor(targetSize.y))); + const AbstractBuffer* currentVertexBuffer = nullptr; const RenderPipeline* currentPipeline = nullptr; const ShaderBinding* currentShaderBinding = nullptr; + Recti currentScissorBox(-1, -1, -1, -1); const RenderSpriteChain* firstSpriteChain = static_cast(elements[0]); auto it = data.drawCallPerElement.find(firstSpriteChain); @@ -305,27 +321,34 @@ namespace Nz for (std::size_t i = 0; i < indices.count; ++i) { - const auto& drawCall = data.drawCalls[indices.start + i]; + const auto& drawData = data.drawCalls[indices.start + i]; - if (currentVertexBuffer != drawCall.vertexBuffer) + if (currentVertexBuffer != drawData.vertexBuffer) { - commandBuffer.BindVertexBuffer(0, *drawCall.vertexBuffer); - currentVertexBuffer = drawCall.vertexBuffer; + commandBuffer.BindVertexBuffer(0, *drawData.vertexBuffer); + currentVertexBuffer = drawData.vertexBuffer; } - if (currentPipeline != drawCall.renderPipeline) + if (currentPipeline != drawData.renderPipeline) { - commandBuffer.BindPipeline(*drawCall.renderPipeline); - currentPipeline = drawCall.renderPipeline; + commandBuffer.BindPipeline(*drawData.renderPipeline); + currentPipeline = drawData.renderPipeline; } - if (currentShaderBinding != drawCall.shaderBinding) + if (currentShaderBinding != drawData.shaderBinding) { - commandBuffer.BindShaderBinding(0, *drawCall.shaderBinding); - currentShaderBinding = drawCall.shaderBinding; + commandBuffer.BindShaderBinding(0, *drawData.shaderBinding); + currentShaderBinding = drawData.shaderBinding; } - commandBuffer.DrawIndexed(drawCall.quadCount * 6, 1U, drawCall.firstIndex); + const Recti& targetScissorBox = (drawData.scissorBox.width >= 0) ? drawData.scissorBox : fullscreenScissorBox; + if (currentScissorBox != targetScissorBox) + { + commandBuffer.SetScissor(targetScissorBox); + currentScissorBox = targetScissorBox; + } + + commandBuffer.DrawIndexed(SafeCast(drawData.quadCount * 6), 1U, SafeCast(drawData.firstIndex)); } } diff --git a/src/Nazara/Graphics/SubmeshRenderer.cpp b/src/Nazara/Graphics/SubmeshRenderer.cpp index 638de6703..a07ff35b7 100644 --- a/src/Nazara/Graphics/SubmeshRenderer.cpp +++ b/src/Nazara/Graphics/SubmeshRenderer.cpp @@ -27,12 +27,15 @@ namespace Nz auto& data = static_cast(rendererData); + Recti invalidScissorBox(-1, -1, -1, -1); + const AbstractBuffer* currentIndexBuffer = nullptr; const AbstractBuffer* currentVertexBuffer = nullptr; const MaterialPass* currentMaterialPass = nullptr; const RenderPipeline* currentPipeline = nullptr; const ShaderBinding* currentShaderBinding = nullptr; const WorldInstance* currentWorldInstance = nullptr; + Recti currentScissorBox = invalidScissorBox; auto FlushDrawCall = [&]() { @@ -86,6 +89,14 @@ namespace Nz currentWorldInstance = worldInstance; } + const Recti& scissorBox = submesh.GetScissorBox(); + const Recti& targetScissorBox = (scissorBox.width >= 0) ? scissorBox : invalidScissorBox; + if (currentScissorBox != targetScissorBox) + { + FlushDrawData(); + currentScissorBox = targetScissorBox; + } + if (!currentShaderBinding) { m_bindingCache.clear(); @@ -140,19 +151,24 @@ namespace Nz drawCall.indexBuffer = currentIndexBuffer; drawCall.indexCount = submesh.GetIndexCount(); drawCall.renderPipeline = currentPipeline; + drawCall.scissorBox = currentScissorBox; drawCall.shaderBinding = currentShaderBinding; drawCall.vertexBuffer = currentVertexBuffer; } } - void SubmeshRenderer::Render(const ViewerInstance& /*viewerInstance*/, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer* /*elements*/, std::size_t /*elementCount*/) + void SubmeshRenderer::Render(const ViewerInstance& viewerInstance, ElementRendererData& rendererData, CommandBufferBuilder& commandBuffer, const Pointer* /*elements*/, std::size_t /*elementCount*/) { auto& data = static_cast(rendererData); + Vector2f targetSize = viewerInstance.GetTargetSize(); + Recti fullscreenScissorBox(0, 0, SafeCast(std::floor(targetSize.x)), SafeCast(std::floor(targetSize.y))); + const AbstractBuffer* currentIndexBuffer = nullptr; const AbstractBuffer* currentVertexBuffer = nullptr; const RenderPipeline* currentPipeline = nullptr; const ShaderBinding* currentShaderBinding = nullptr; + Recti currentScissorBox(-1, -1, -1, -1); for (const auto& drawData : data.drawCalls) { @@ -180,10 +196,17 @@ namespace Nz currentVertexBuffer = drawData.vertexBuffer; } + const Recti& targetScissorBox = (drawData.scissorBox.width >= 0) ? drawData.scissorBox : fullscreenScissorBox; + if (currentScissorBox != targetScissorBox) + { + commandBuffer.SetScissor(targetScissorBox); + currentScissorBox = targetScissorBox; + } + if (currentIndexBuffer) - commandBuffer.DrawIndexed(drawData.indexCount); + commandBuffer.DrawIndexed(SafeCast(drawData.indexCount)); else - commandBuffer.Draw(drawData.indexCount); + commandBuffer.Draw(SafeCast(drawData.indexCount)); } } diff --git a/src/Nazara/Graphics/TextSprite.cpp b/src/Nazara/Graphics/TextSprite.cpp index 6593b4333..a6356153d 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(GetRenderLayer(), 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], GetScissorBox())); } } diff --git a/src/Nazara/Widgets/BaseWidget.cpp b/src/Nazara/Widgets/BaseWidget.cpp index 5a504da10..6dd1425ae 100644 --- a/src/Nazara/Widgets/BaseWidget.cpp +++ b/src/Nazara/Widgets/BaseWidget.cpp @@ -382,12 +382,18 @@ namespace Nz scissorRect = parentScissorRect; } - /*Recti fullBounds(scissorRect); + scissorRect.y = GetCanvas()->GetSize().y - scissorRect.height - scissorRect.y; //< scissor rect is in screen coordinates + + Recti fullBounds(scissorRect); + + auto& registry = GetRegistry(); for (WidgetEntity& widgetEntity : m_entities) { - const Ndk::EntityHandle& entity = widgetEntity.handle; - if (entity->HasComponent()) - entity->GetComponent().SetScissorRect(fullBounds); - }*/ + if (GraphicsComponent* gfx = registry.try_get(widgetEntity.handle)) + { + for (const auto& renderable : gfx->GetRenderables()) + renderable.renderable->UpdateScissorBox(fullBounds); + } + } } } diff --git a/src/Nazara/Widgets/Canvas.cpp b/src/Nazara/Widgets/Canvas.cpp index 913b95e07..0a7e4c3b4 100644 --- a/src/Nazara/Widgets/Canvas.cpp +++ b/src/Nazara/Widgets/Canvas.cpp @@ -19,6 +19,7 @@ namespace Nz m_cursorController(cursorController) { m_canvas = this; + BaseWidget::m_registry = &m_registry; m_widgetParent = nullptr; SetBaseRenderLayer(initialRenderLayer);