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 const std::vector<Renderable>& GetRenderables() const;
|
||||
inline const Recti& GetScissorBox() const;
|
||||
inline const WorldInstancePtr& GetWorldInstance() const;
|
||||
|
||||
inline void Hide();
|
||||
|
|
@ -41,6 +42,8 @@ namespace Nz
|
|||
|
||||
inline void Show(bool show = true);
|
||||
|
||||
inline void UpdateScissorBox(const Recti& scissorBox);
|
||||
|
||||
GraphicsComponent& operator=(const GraphicsComponent&) = default;
|
||||
GraphicsComponent& operator=(GraphicsComponent&&) = default;
|
||||
|
||||
|
|
@ -56,6 +59,7 @@ namespace Nz
|
|||
|
||||
private:
|
||||
std::vector<Renderable> m_renderables;
|
||||
Recti m_scissorBox;
|
||||
WorldInstancePtr m_worldInstance;
|
||||
bool m_isVisible;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
namespace Nz
|
||||
{
|
||||
inline GraphicsComponent::GraphicsComponent(bool initialyVisible) :
|
||||
m_scissorBox(-1, -1, -1, -1),
|
||||
m_isVisible(initialyVisible)
|
||||
{
|
||||
m_worldInstance = std::make_shared<WorldInstance>(); //< FIXME: Use pools
|
||||
|
|
@ -46,6 +47,11 @@ namespace Nz
|
|||
return m_renderables;
|
||||
}
|
||||
|
||||
inline const Recti& GraphicsComponent::GetScissorBox() const
|
||||
{
|
||||
return m_scissorBox;
|
||||
}
|
||||
|
||||
inline const WorldInstancePtr& GraphicsComponent::GetWorldInstance() const
|
||||
{
|
||||
return m_worldInstance;
|
||||
|
|
@ -69,6 +75,15 @@ namespace Nz
|
|||
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>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -30,6 +31,7 @@ namespace Nz
|
|||
{
|
||||
const InstancedRenderable* instancedRenderable;
|
||||
const WorldInstance* worldInstance;
|
||||
Recti scissorBox;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,16 +28,14 @@ namespace Nz
|
|||
InstancedRenderable(InstancedRenderable&&) noexcept = default;
|
||||
~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;
|
||||
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;
|
||||
|
|
@ -51,7 +49,6 @@ namespace Nz
|
|||
|
||||
private:
|
||||
Boxf m_aabb;
|
||||
Recti m_scissorBox;
|
||||
int m_renderLayer;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ namespace Nz
|
|||
{
|
||||
inline InstancedRenderable::InstancedRenderable() :
|
||||
m_aabb(Boxf::Zero()),
|
||||
m_scissorBox(-1, -1, -1, -1),
|
||||
m_renderLayer(0)
|
||||
{
|
||||
}
|
||||
|
|
@ -24,11 +23,6 @@ namespace Nz
|
|||
return m_renderLayer;
|
||||
}
|
||||
|
||||
inline const Recti& InstancedRenderable::GetScissorBox() const
|
||||
{
|
||||
return m_scissorBox;
|
||||
}
|
||||
|
||||
inline void InstancedRenderable::UpdateRenderLayer(int 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)
|
||||
{
|
||||
OnAABBUpdate(this, aabb);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
|||
Model(Model&&) noexcept = 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;
|
||||
std::size_t GetIndexCount(std::size_t subMeshIndex) const;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
|||
SlicedSprite(SlicedSprite&&) noexcept = 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 Corner& GetBottomRightCorner() const;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
Sprite(Sprite&&) noexcept = 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& GetCornerColor(RectCorner corner) const;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
|||
TextSprite(TextSprite&&) noexcept = 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();
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Nz
|
|||
m_renderElements.clear();
|
||||
|
||||
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_renderQueue.Clear();
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ namespace Nz
|
|||
lightUboView = it->second;
|
||||
|
||||
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)
|
||||
{
|
||||
const RenderElement* element = m_renderElements[i].get();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Nz
|
|||
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)
|
||||
{
|
||||
|
|
@ -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<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();
|
||||
}
|
||||
|
||||
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);
|
||||
if (!materialPass)
|
||||
|
|
@ -39,7 +39,7 @@ namespace Nz
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
|||
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);
|
||||
if (!materialPass)
|
||||
|
|
@ -43,7 +43,7 @@ namespace Nz
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
if (!materialPass)
|
||||
|
|
@ -42,7 +42,7 @@ namespace Nz
|
|||
RenderIndices& indices = pair.second;
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
@ -390,10 +390,7 @@ namespace Nz
|
|||
for (WidgetEntity& widgetEntity : m_entities)
|
||||
{
|
||||
if (GraphicsComponent* gfx = registry.try_get<GraphicsComponent>(widgetEntity.handle))
|
||||
{
|
||||
for (const auto& renderable : gfx->GetRenderables())
|
||||
renderable.renderable->UpdateScissorBox(fullBounds);
|
||||
}
|
||||
gfx->UpdateScissorBox(fullBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue