Graphics: Move scissor box from InstancedRenderable to GraphicsComponent
This commit is contained in:
parent
29c798a683
commit
cc0fc53bd3
|
|
@ -33,6 +33,7 @@ namespace Nz
|
||||||
inline void DetachRenderable(const std::shared_ptr<InstancedRenderable>& renderable);
|
inline void DetachRenderable(const std::shared_ptr<InstancedRenderable>& renderable);
|
||||||
|
|
||||||
inline const std::vector<Renderable>& GetRenderables() const;
|
inline const std::vector<Renderable>& GetRenderables() const;
|
||||||
|
inline const Recti& GetScissorBox() const;
|
||||||
inline const WorldInstancePtr& GetWorldInstance() const;
|
inline const WorldInstancePtr& GetWorldInstance() const;
|
||||||
|
|
||||||
inline void Hide();
|
inline void Hide();
|
||||||
|
|
@ -41,6 +42,8 @@ namespace Nz
|
||||||
|
|
||||||
inline void Show(bool show = true);
|
inline void Show(bool show = true);
|
||||||
|
|
||||||
|
inline void UpdateScissorBox(const Recti& scissorBox);
|
||||||
|
|
||||||
GraphicsComponent& operator=(const GraphicsComponent&) = default;
|
GraphicsComponent& operator=(const GraphicsComponent&) = default;
|
||||||
GraphicsComponent& operator=(GraphicsComponent&&) = default;
|
GraphicsComponent& operator=(GraphicsComponent&&) = default;
|
||||||
|
|
||||||
|
|
@ -56,6 +59,7 @@ namespace Nz
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Renderable> m_renderables;
|
std::vector<Renderable> m_renderables;
|
||||||
|
Recti m_scissorBox;
|
||||||
WorldInstancePtr m_worldInstance;
|
WorldInstancePtr m_worldInstance;
|
||||||
bool m_isVisible;
|
bool m_isVisible;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline GraphicsComponent::GraphicsComponent(bool initialyVisible) :
|
inline GraphicsComponent::GraphicsComponent(bool initialyVisible) :
|
||||||
|
m_scissorBox(-1, -1, -1, -1),
|
||||||
m_isVisible(initialyVisible)
|
m_isVisible(initialyVisible)
|
||||||
{
|
{
|
||||||
m_worldInstance = std::make_shared<WorldInstance>(); //< FIXME: Use pools
|
m_worldInstance = std::make_shared<WorldInstance>(); //< FIXME: Use pools
|
||||||
|
|
@ -46,6 +47,11 @@ namespace Nz
|
||||||
return m_renderables;
|
return m_renderables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const Recti& GraphicsComponent::GetScissorBox() const
|
||||||
|
{
|
||||||
|
return m_scissorBox;
|
||||||
|
}
|
||||||
|
|
||||||
inline const WorldInstancePtr& GraphicsComponent::GetWorldInstance() const
|
inline const WorldInstancePtr& GraphicsComponent::GetWorldInstance() const
|
||||||
{
|
{
|
||||||
return m_worldInstance;
|
return m_worldInstance;
|
||||||
|
|
@ -69,6 +75,15 @@ namespace Nz
|
||||||
m_isVisible = show;
|
m_isVisible = show;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void GraphicsComponent::UpdateScissorBox(const Recti& scissorBox)
|
||||||
|
{
|
||||||
|
if (m_scissorBox != scissorBox)
|
||||||
|
{
|
||||||
|
OnScissorBoxUpdate(this, scissorBox);
|
||||||
|
m_scissorBox = scissorBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Graphics/DebugOff.hpp>
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequisites.hpp>
|
#include <Nazara/Prerequisites.hpp>
|
||||||
#include <Nazara/Graphics/Config.hpp>
|
#include <Nazara/Graphics/Config.hpp>
|
||||||
|
#include <Nazara/Math/Rect.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +31,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
const InstancedRenderable* instancedRenderable;
|
const InstancedRenderable* instancedRenderable;
|
||||||
const WorldInstance* worldInstance;
|
const WorldInstance* worldInstance;
|
||||||
|
Recti scissorBox;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,16 +28,14 @@ namespace Nz
|
||||||
InstancedRenderable(InstancedRenderable&&) noexcept = default;
|
InstancedRenderable(InstancedRenderable&&) noexcept = default;
|
||||||
~InstancedRenderable();
|
~InstancedRenderable();
|
||||||
|
|
||||||
virtual void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const = 0;
|
virtual void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const = 0;
|
||||||
|
|
||||||
inline const Boxf& GetAABB() const;
|
inline const Boxf& GetAABB() const;
|
||||||
virtual const std::shared_ptr<Material>& GetMaterial(std::size_t i) const = 0;
|
virtual const std::shared_ptr<Material>& GetMaterial(std::size_t i) const = 0;
|
||||||
virtual std::size_t GetMaterialCount() const = 0;
|
virtual std::size_t GetMaterialCount() const = 0;
|
||||||
inline int GetRenderLayer() const;
|
inline int GetRenderLayer() const;
|
||||||
inline const Recti& GetScissorBox() const;
|
|
||||||
|
|
||||||
inline void UpdateRenderLayer(int renderLayer);
|
inline void UpdateRenderLayer(int renderLayer);
|
||||||
inline void UpdateScissorBox(const Recti& scissorBox);
|
|
||||||
|
|
||||||
InstancedRenderable& operator=(const InstancedRenderable&) = delete;
|
InstancedRenderable& operator=(const InstancedRenderable&) = delete;
|
||||||
InstancedRenderable& operator=(InstancedRenderable&&) noexcept = default;
|
InstancedRenderable& operator=(InstancedRenderable&&) noexcept = default;
|
||||||
|
|
@ -51,7 +49,6 @@ namespace Nz
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Boxf m_aabb;
|
Boxf m_aabb;
|
||||||
Recti m_scissorBox;
|
|
||||||
int m_renderLayer;
|
int m_renderLayer;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ namespace Nz
|
||||||
{
|
{
|
||||||
inline InstancedRenderable::InstancedRenderable() :
|
inline InstancedRenderable::InstancedRenderable() :
|
||||||
m_aabb(Boxf::Zero()),
|
m_aabb(Boxf::Zero()),
|
||||||
m_scissorBox(-1, -1, -1, -1),
|
|
||||||
m_renderLayer(0)
|
m_renderLayer(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -24,11 +23,6 @@ namespace Nz
|
||||||
return m_renderLayer;
|
return m_renderLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Recti& InstancedRenderable::GetScissorBox() const
|
|
||||||
{
|
|
||||||
return m_scissorBox;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void InstancedRenderable::UpdateRenderLayer(int renderLayer)
|
inline void InstancedRenderable::UpdateRenderLayer(int renderLayer)
|
||||||
{
|
{
|
||||||
if (m_renderLayer != renderLayer)
|
if (m_renderLayer != renderLayer)
|
||||||
|
|
@ -38,15 +32,6 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void InstancedRenderable::UpdateScissorBox(const Recti& scissorBox)
|
|
||||||
{
|
|
||||||
if (m_scissorBox != scissorBox)
|
|
||||||
{
|
|
||||||
m_scissorBox = scissorBox;
|
|
||||||
OnElementInvalidated(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void InstancedRenderable::UpdateAABB(Boxf aabb)
|
inline void InstancedRenderable::UpdateAABB(Boxf aabb)
|
||||||
{
|
{
|
||||||
OnAABBUpdate(this, aabb);
|
OnAABBUpdate(this, aabb);
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
||||||
Model(Model&&) noexcept = default;
|
Model(Model&&) noexcept = default;
|
||||||
~Model() = default;
|
~Model() = default;
|
||||||
|
|
||||||
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const override;
|
||||||
|
|
||||||
const std::shared_ptr<RenderBuffer>& GetIndexBuffer(std::size_t subMeshIndex) const;
|
const std::shared_ptr<RenderBuffer>& GetIndexBuffer(std::size_t subMeshIndex) const;
|
||||||
std::size_t GetIndexCount(std::size_t subMeshIndex) const;
|
std::size_t GetIndexCount(std::size_t subMeshIndex) const;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
||||||
SlicedSprite(SlicedSprite&&) noexcept = default;
|
SlicedSprite(SlicedSprite&&) noexcept = default;
|
||||||
~SlicedSprite() = default;
|
~SlicedSprite() = default;
|
||||||
|
|
||||||
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const override;
|
||||||
|
|
||||||
inline const Color& GetColor() const;
|
inline const Color& GetColor() const;
|
||||||
inline const Corner& GetBottomRightCorner() const;
|
inline const Corner& GetBottomRightCorner() const;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
||||||
Sprite(Sprite&&) noexcept = default;
|
Sprite(Sprite&&) noexcept = default;
|
||||||
~Sprite() = default;
|
~Sprite() = default;
|
||||||
|
|
||||||
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const override;
|
||||||
|
|
||||||
inline const Color& GetColor() const;
|
inline const Color& GetColor() const;
|
||||||
inline const Color& GetCornerColor(RectCorner corner) const;
|
inline const Color& GetCornerColor(RectCorner corner) const;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
||||||
TextSprite(TextSprite&&) noexcept = default;
|
TextSprite(TextSprite&&) noexcept = default;
|
||||||
~TextSprite() = default;
|
~TextSprite() = default;
|
||||||
|
|
||||||
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const override;
|
void BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const override;
|
||||||
|
|
||||||
inline void Clear();
|
inline void Clear();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Nz
|
||||||
m_renderElements.clear();
|
m_renderElements.clear();
|
||||||
|
|
||||||
for (const auto& renderableData : visibleRenderables)
|
for (const auto& renderableData : visibleRenderables)
|
||||||
renderableData.instancedRenderable->BuildElement(m_depthPassIndex, *renderableData.worldInstance, m_renderElements);
|
renderableData.instancedRenderable->BuildElement(m_depthPassIndex, *renderableData.worldInstance, m_renderElements, renderableData.scissorBox);
|
||||||
|
|
||||||
m_renderQueueRegistry.Clear();
|
m_renderQueueRegistry.Clear();
|
||||||
m_renderQueue.Clear();
|
m_renderQueue.Clear();
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ namespace Nz
|
||||||
lightUboView = it->second;
|
lightUboView = it->second;
|
||||||
|
|
||||||
std::size_t previousCount = m_renderElements.size();
|
std::size_t previousCount = m_renderElements.size();
|
||||||
renderableData.instancedRenderable->BuildElement(m_forwardPassIndex, *renderableData.worldInstance, m_renderElements);
|
renderableData.instancedRenderable->BuildElement(m_forwardPassIndex, *renderableData.worldInstance, m_renderElements, renderableData.scissorBox);
|
||||||
for (std::size_t i = previousCount; i < m_renderElements.size(); ++i)
|
for (std::size_t i = previousCount; i < m_renderElements.size(); ++i)
|
||||||
{
|
{
|
||||||
const RenderElement* element = m_renderElements[i].get();
|
const RenderElement* element = m_renderElements[i].get();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Nz
|
||||||
UpdateAABB(aabb);
|
UpdateAABB(aabb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const
|
void Model::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < m_submeshes.size(); ++i)
|
for (std::size_t i = 0; i < m_submeshes.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Nz
|
||||||
const auto& vertexBuffer = m_graphicalMesh->GetVertexBuffer(i);
|
const auto& vertexBuffer = m_graphicalMesh->GetVertexBuffer(i);
|
||||||
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(submeshData.vertexBufferData);
|
const auto& renderPipeline = materialPass->GetPipeline()->GetRenderPipeline(submeshData.vertexBufferData);
|
||||||
|
|
||||||
elements.emplace_back(std::make_unique<RenderSubmesh>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, m_graphicalMesh->GetIndexCount(i), indexBuffer, vertexBuffer, GetScissorBox()));
|
elements.emplace_back(std::make_unique<RenderSubmesh>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, m_graphicalMesh->GetIndexCount(i), indexBuffer, vertexBuffer, scissorBox));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Nz
|
||||||
UpdateVertices();
|
UpdateVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlicedSprite::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const
|
void SlicedSprite::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const
|
||||||
{
|
{
|
||||||
const auto& materialPass = m_material->GetPass(passIndex);
|
const auto& materialPass = m_material->GetPass(passIndex);
|
||||||
if (!materialPass)
|
if (!materialPass)
|
||||||
|
|
@ -39,7 +39,7 @@ namespace Nz
|
||||||
|
|
||||||
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)];
|
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)];
|
||||||
|
|
||||||
elements.emplace_back(std::make_unique<RenderSpriteChain>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), GetScissorBox()));
|
elements.emplace_back(std::make_unique<RenderSpriteChain>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, m_spriteCount, m_vertices.data(), scissorBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<Material>& SlicedSprite::GetMaterial(std::size_t i) const
|
const std::shared_ptr<Material>& SlicedSprite::GetMaterial(std::size_t i) const
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
||||||
UpdateVertices();
|
UpdateVertices();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const
|
void Sprite::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const
|
||||||
{
|
{
|
||||||
const auto& materialPass = m_material->GetPass(passIndex);
|
const auto& materialPass = m_material->GetPass(passIndex);
|
||||||
if (!materialPass)
|
if (!materialPass)
|
||||||
|
|
@ -43,7 +43,7 @@ namespace Nz
|
||||||
|
|
||||||
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)];
|
const auto& whiteTexture = Graphics::Instance()->GetDefaultTextures().whiteTextures[UnderlyingCast(ImageType::E2D)];
|
||||||
|
|
||||||
elements.emplace_back(std::make_unique<RenderSpriteChain>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data(), GetScissorBox()));
|
elements.emplace_back(std::make_unique<RenderSpriteChain>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, whiteTexture, 1, m_vertices.data(), scissorBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<Material>& Sprite::GetMaterial(std::size_t i) const
|
const std::shared_ptr<Material>& Sprite::GetMaterial(std::size_t i) const
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextSprite::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements) const
|
void TextSprite::BuildElement(std::size_t passIndex, const WorldInstance& worldInstance, std::vector<std::unique_ptr<RenderElement>>& elements, const Recti& scissorBox) const
|
||||||
{
|
{
|
||||||
const auto& materialPass = m_material->GetPass(passIndex);
|
const auto& materialPass = m_material->GetPass(passIndex);
|
||||||
if (!materialPass)
|
if (!materialPass)
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Nz
|
||||||
RenderIndices& indices = pair.second;
|
RenderIndices& indices = pair.second;
|
||||||
|
|
||||||
if (indices.count > 0)
|
if (indices.count > 0)
|
||||||
elements.emplace_back(std::make_unique<RenderSpriteChain>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, key.texture->shared_from_this(), indices.count, &m_vertices[indices.first * 4], GetScissorBox()));
|
elements.emplace_back(std::make_unique<RenderSpriteChain>(GetRenderLayer(), materialPass, renderPipeline, worldInstance, vertexDeclaration, key.texture->shared_from_this(), indices.count, &m_vertices[indices.first * 4], scissorBox));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseWidget::OnKeyPressed(const WindowEvent::KeyEvent& key)
|
bool BaseWidget::OnKeyPressed(const WindowEvent::KeyEvent& /*key*/)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -390,10 +390,7 @@ namespace Nz
|
||||||
for (WidgetEntity& widgetEntity : m_entities)
|
for (WidgetEntity& widgetEntity : m_entities)
|
||||||
{
|
{
|
||||||
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(widgetEntity.handle))
|
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(widgetEntity.handle))
|
||||||
{
|
gfx->UpdateScissorBox(fullBounds);
|
||||||
for (const auto& renderable : gfx->GetRenderables())
|
|
||||||
renderable.renderable->UpdateScissorBox(fullBounds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue