Files
NazaraEngine/SDK/include/NDK/Components/GraphicsComponent.hpp
Lynix 1d758d370c Graphics/InstancedRenderable: Take a const reference to the matrix instead of a non-const one
Former-commit-id: 148f4367351f79994f51699a656a938c6784af8f [formerly 27ef2f23da51c156f615bb33e6b3138b44f77498] [formerly 120334bc6e2bd3fcff30fde0febc901d83cdeb9b [formerly 9f4d16e134fb009ce021f4720ffc6d410cc5bd3c]]
Former-commit-id: 55595b1a006dfa313e7f088f76ff6880971530c4 [formerly 7e3a37de6c217d1b7734be14df74c174f6e0b4d6]
Former-commit-id: 0ebdab2df6d218a51c5ee425482bff7c660fddd8
2016-08-05 09:09:14 +02:00

109 lines
3.2 KiB
C++

// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_SERVER
#ifndef NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#define NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#include <Nazara/Graphics/InstancedRenderable.hpp>
#include <Nazara/Utility/Node.hpp>
#include <NDK/Component.hpp>
namespace Ndk
{
class GraphicsComponent;
using GraphicsComponentHandle = Nz::ObjectHandle<GraphicsComponent>;
class NDK_API GraphicsComponent : public Component<GraphicsComponent>, public Nz::HandledObject<GraphicsComponent>
{
friend class RenderSystem;
public:
using RenderableList = std::vector<Nz::InstancedRenderableRef>;
GraphicsComponent() = default;
inline GraphicsComponent(const GraphicsComponent& graphicsComponent);
~GraphicsComponent() = default;
inline void AddToRenderQueue(Nz::AbstractRenderQueue* renderQueue) const;
inline void Attach(Nz::InstancedRenderableRef renderable, int renderOrder = 0);
inline void Clear();
inline void Detach(const Nz::InstancedRenderableRef& renderable);
inline void EnsureBoundingVolumeUpdate() const;
inline void EnsureTransformMatrixUpdate() const;
inline void GetAttachedRenderables(RenderableList* renderables) const;
inline std::size_t GetAttachedRenderableCount() const;
inline const Nz::BoundingVolumef& GetBoundingVolume() const;
static ComponentIndex componentIndex;
private:
inline void InvalidateBoundingVolume();
void InvalidateRenderableData(const Nz::InstancedRenderable* renderable, Nz::UInt32 flags, std::size_t index);
inline void InvalidateRenderables();
inline void InvalidateTransformMatrix();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
void OnNodeInvalidated(const Nz::Node* node);
void UpdateBoundingVolume() const;
void UpdateTransformMatrix() const;
NazaraSlot(Nz::Node, OnNodeInvalidation, m_nodeInvalidationSlot);
struct Renderable
{
Renderable(const Nz::Matrix4f& transformMatrix) :
data(transformMatrix),
dataUpdated(false)
{
}
Renderable(Renderable&& renderable) noexcept :
data(std::move(renderable.data)),
renderable(std::move(renderable.renderable)),
dataUpdated(renderable.dataUpdated)
{
}
Renderable& operator=(Renderable&& r) noexcept
{
data = std::move(r.data);
dataUpdated = r.dataUpdated;
renderable = std::move(r.renderable);
return *this;
}
NazaraSlot(Nz::InstancedRenderable, OnInstancedRenderableInvalidateData, renderableInvalidationSlot);
mutable Nz::InstancedRenderable::InstanceData data;
Nz::InstancedRenderableRef renderable;
mutable bool dataUpdated;
};
std::vector<Renderable> m_renderables;
mutable Nz::BoundingVolumef m_boundingVolume;
mutable Nz::Matrix4f m_transformMatrix;
mutable bool m_boundingVolumeUpdated;
mutable bool m_transformMatrixUpdated;
};
}
#include <NDK/Components/GraphicsComponent.inl>
#endif // NDK_COMPONENTS_GRAPHICSCOMPONENT_HPP
#endif // NDK_SERVER