Former-commit-id: a5e9ceb3f30e79a0d3b96b6866a06441cbc0b463 [formerly 8af071cedec0a6aca00ff9c12d66e8a0817049c6] [formerly cd7e7040fd68dd5a74a0b458a3a305c251257b51 [formerly 0f9382c169a260d5fa34fe9b1ab64c3d19dbd385]] Former-commit-id: 774af2326cb64824f85835c83464bc19884005e1 [formerly 4b676844f6dd56940b4f503c6a943905ea8a54c3] Former-commit-id: 0673e4d4cd88c99d24e0e153a61d2726e2e2c039
103 lines
3.3 KiB
C++
103 lines
3.3 KiB
C++
// Copyright (C) 2015 Jérôme Leclercq
|
|
// This file is part of the "Nazara Engine - Graphics module"
|
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
|
|
|
#pragma once
|
|
|
|
#ifndef NAZARA_INSTANCEDRENDERABLE_HPP
|
|
#define NAZARA_INSTANCEDRENDERABLE_HPP
|
|
|
|
#include <Nazara/Core/PrimitiveList.hpp>
|
|
#include <Nazara/Core/ObjectLibrary.hpp>
|
|
#include <Nazara/Core/ObjectRef.hpp>
|
|
#include <Nazara/Core/RefCounted.hpp>
|
|
#include <Nazara/Core/Signal.hpp>
|
|
#include <Nazara/Graphics/Config.hpp>
|
|
#include <Nazara/Math/BoundingVolume.hpp>
|
|
#include <Nazara/Math/Frustum.hpp>
|
|
#include <Nazara/Math/Matrix4.hpp>
|
|
|
|
namespace Nz
|
|
{
|
|
class AbstractRenderQueue;
|
|
class InstancedRenderable;
|
|
|
|
using InstancedRenderableConstRef = ObjectRef<const InstancedRenderable>;
|
|
using InstancedRenderableLibrary = ObjectLibrary<InstancedRenderable>;
|
|
using InstancedRenderableRef = ObjectRef<InstancedRenderable>;
|
|
|
|
class NAZARA_GRAPHICS_API InstancedRenderable : public RefCounted
|
|
{
|
|
public:
|
|
struct InstanceData;
|
|
|
|
InstancedRenderable() = default;
|
|
inline InstancedRenderable(const InstancedRenderable& renderable);
|
|
InstancedRenderable(InstancedRenderable&& renderable) = delete;
|
|
virtual ~InstancedRenderable();
|
|
|
|
inline void EnsureBoundingVolumeUpdated() const;
|
|
|
|
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
|
|
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
|
|
virtual const BoundingVolumef& GetBoundingVolume() const;
|
|
virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const;
|
|
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
|
|
virtual void UpdateData(InstanceData* instanceData) const;
|
|
|
|
inline InstancedRenderable& operator=(const InstancedRenderable& renderable);
|
|
InstancedRenderable& operator=(InstancedRenderable&& renderable) = delete;
|
|
|
|
// Signals:
|
|
NazaraSignal(OnInstancedRenderableInvalidateData, const InstancedRenderable* /*instancedRenderable*/, UInt32 /*flags*/);
|
|
NazaraSignal(OnInstancedRenderableRelease, const InstancedRenderable* /*instancedRenderable*/);
|
|
|
|
struct InstanceData
|
|
{
|
|
InstanceData(const Matrix4f& transformationMatrix) :
|
|
localMatrix(transformationMatrix),
|
|
flags(0)
|
|
{
|
|
}
|
|
|
|
InstanceData(InstanceData&& instanceData) noexcept = default;
|
|
|
|
InstanceData& operator=(InstanceData&& instanceData) noexcept
|
|
{
|
|
data = std::move(instanceData.data);
|
|
flags = instanceData.flags;
|
|
renderOrder = instanceData.renderOrder;
|
|
localMatrix = instanceData.localMatrix;
|
|
transformMatrix = instanceData.transformMatrix;
|
|
volume = instanceData.volume;
|
|
|
|
return *this;
|
|
}
|
|
|
|
std::vector<UInt8> data;
|
|
BoundingVolumef volume;
|
|
Matrix4f localMatrix;
|
|
mutable Matrix4f transformMatrix;
|
|
UInt32 flags;
|
|
int renderOrder;
|
|
};
|
|
|
|
protected:
|
|
virtual void MakeBoundingVolume() const = 0;
|
|
void InvalidateBoundingVolume();
|
|
inline void InvalidateInstanceData(UInt32 flags);
|
|
inline void UpdateBoundingVolume() const;
|
|
|
|
mutable BoundingVolumef m_boundingVolume;
|
|
|
|
private:
|
|
mutable bool m_boundingVolumeUpdated;
|
|
|
|
static InstancedRenderableLibrary::LibraryMap s_library;
|
|
};
|
|
}
|
|
|
|
#include <Nazara/Graphics/InstancedRenderable.inl>
|
|
|
|
#endif // NAZARA_INSTANCEDRENDERABLE_HPP
|