Graphics/Widgets: Add support for scissoring

This commit is contained in:
Jérôme Leclercq
2021-12-01 20:26:33 +01:00
parent a483e16e15
commit 61779d1cad
21 changed files with 137 additions and 35 deletions

View File

@@ -231,6 +231,8 @@ namespace Nz
// Convert it back to int
m_viewport.Set(fViewport);
m_viewerInstance.UpdateTargetSize(fViewport.GetLengths());
UpdateProjectionMatrix();
}
}

View File

@@ -34,8 +34,10 @@ namespace Nz
virtual const std::shared_ptr<Material>& 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;
};
}

View File

@@ -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);

View File

@@ -52,6 +52,7 @@ namespace Nz
std::shared_ptr<GraphicalMesh> m_graphicalMesh;
std::vector<SubMeshData> m_submeshes;
Recti m_scissorBox;
};
}

View File

@@ -8,7 +8,6 @@
#define NAZARA_GRAPHICS_RENDERSPRITECHAIN_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/MaterialPass.hpp>
#include <Nazara/Graphics/RenderElement.hpp>
#include <Nazara/Graphics/RenderQueueRegistry.hpp>
#include <Nazara/Graphics/WorldInstance.hpp>
@@ -25,13 +24,14 @@ namespace Nz
class RenderSpriteChain : public RenderElement
{
public:
inline RenderSpriteChain(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> textureOverlay, std::size_t spriteCount, const void* spriteData);
inline RenderSpriteChain(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> 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;
};
}

View File

@@ -4,11 +4,12 @@
#include <Nazara/Graphics/RenderSpriteChain.hpp>
#include <Nazara/Graphics/Algorithm.hpp>
#include <Nazara/Graphics/MaterialPass.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> textureOverlay, std::size_t spriteCount, const void* spriteData) :
inline RenderSpriteChain::RenderSpriteChain(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::shared_ptr<VertexDeclaration> vertexDeclaration, std::shared_ptr<Texture> 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;

View File

@@ -24,7 +24,7 @@ namespace Nz
class RenderSubmesh : public RenderElement
{
public:
inline RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer);
inline RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> 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<RenderPipeline> m_renderPipeline;
std::size_t m_indexCount;
const WorldInstance& m_worldInstance;
Recti m_scissorBox;
int m_renderLayer;
};
}

View File

@@ -9,7 +9,7 @@
namespace Nz
{
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> vertexBuffer) :
inline RenderSubmesh::RenderSubmesh(int renderLayer, std::shared_ptr<MaterialPass> materialPass, std::shared_ptr<RenderPipeline> renderPipeline, const WorldInstance& worldInstance, std::size_t indexCount, std::shared_ptr<AbstractBuffer> indexBuffer, std::shared_ptr<AbstractBuffer> 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();

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/ElementRenderer.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/ShaderBinding.hpp>
#include <Nazara/Renderer/UploadPool.hpp>
#include <memory>
@@ -65,6 +66,7 @@ namespace Nz
const ShaderBinding* shaderBinding;
std::size_t firstIndex;
std::size_t quadCount;
Recti scissorBox;
};
struct DrawCallIndices

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Graphics/ElementRenderer.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/ShaderBinding.hpp>
namespace Nz
@@ -41,6 +42,7 @@ namespace Nz
const RenderPipeline* renderPipeline;
const ShaderBinding* shaderBinding;
std::size_t indexCount;
Recti scissorBox;
};
std::vector<DrawCall> drawCalls;

View File

@@ -95,6 +95,7 @@ namespace Nz
std::shared_ptr<Material> m_material;
std::vector<RenderData> m_data;
std::vector<VertexStruct_XYZ_Color_UV> m_vertices;
Recti m_scissorBox;
};
}

View File

@@ -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<AbstractBuffer>& GetViewerBuffer();

View File

@@ -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;