Graphics: Add Renderable class
WIP Former-commit-id: b9ea2a443cf2e5f8b90360e1f47466b0c3ce69fa
This commit is contained in:
parent
41afb3a3a1
commit
3ee981867e
|
|
@ -0,0 +1,60 @@
|
||||||
|
// 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_RENDERABLE_HPP
|
||||||
|
#define NAZARA_RENDERABLE_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
|
#include <Nazara/Core/PrimitiveList.hpp>
|
||||||
|
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||||
|
#include <Nazara/Core/ObjectListenerWrapper.hpp>
|
||||||
|
#include <Nazara/Core/ObjectRef.hpp>
|
||||||
|
#include <Nazara/Core/RefCounted.hpp>
|
||||||
|
#include <Nazara/Math/BoundingVolume.hpp>
|
||||||
|
#include <Nazara/Math/Frustum.hpp>
|
||||||
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
|
||||||
|
class NzAbstractRenderQueue;
|
||||||
|
class NzRenderable;
|
||||||
|
|
||||||
|
using NzRenderableConstListener = NzObjectListenerWrapper<const NzRenderable>;
|
||||||
|
using NzRenderableConstRef = NzObjectRef<const NzRenderable>;
|
||||||
|
using NzRenderableLibrary = NzObjectLibrary<NzRenderable>;
|
||||||
|
using NzRenderableListener = NzObjectListenerWrapper<NzRenderable>;
|
||||||
|
using NzRenderableRef = NzObjectRef<NzRenderable>;
|
||||||
|
|
||||||
|
class NAZARA_API NzRenderable : public NzRefCounted
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NzRenderable() = default;
|
||||||
|
NzRenderable(const NzRenderable& renderable) = default;
|
||||||
|
virtual ~NzRenderable();
|
||||||
|
|
||||||
|
void EnsureBoundingVolumeUpdated() const;
|
||||||
|
|
||||||
|
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue, const NzMatrix4f& transformMatrix) const = 0;
|
||||||
|
virtual void Cull(const NzFrustumf& frustum, const NzBoundingVolumef& volume, const NzMatrix4f& transformMatrix) const = 0;
|
||||||
|
virtual const NzBoundingVolumef& GetBoundingVolume() const;
|
||||||
|
virtual void UpdateBoundingVolume(NzBoundingVolumef* boundingVolume, const NzMatrix4f& transformMatrix) const;
|
||||||
|
|
||||||
|
NzRenderable& operator=(const NzRenderable& renderable) = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void MakeBoundingVolume() const = 0;
|
||||||
|
void InvalidateBoundingVolume();
|
||||||
|
void UpdateBoundingVolume() const;
|
||||||
|
|
||||||
|
mutable NzBoundingVolumef m_boundingVolume;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable bool m_boundingVolumeUpdated;
|
||||||
|
|
||||||
|
static NzRenderableLibrary::LibraryMap s_library;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/Renderable.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_RENDERABLE_HPP
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
// 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
|
||||||
|
|
||||||
|
void NzRenderable::EnsureBoundingVolumeUpdated() const
|
||||||
|
{
|
||||||
|
if (!m_boundingVolumeUpdated)
|
||||||
|
UpdateBoundingVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzRenderable::InvalidateBoundingVolume()
|
||||||
|
{
|
||||||
|
m_boundingVolumeUpdated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzRenderable::UpdateBoundingVolume() const
|
||||||
|
{
|
||||||
|
MakeBoundingVolume();
|
||||||
|
m_boundingVolumeUpdated = true;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
// 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
|
||||||
|
|
||||||
|
#include <Nazara/Graphics/Renderable.hpp>
|
||||||
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
|
NzRenderable::~NzRenderable() = default;
|
||||||
|
|
||||||
|
const NzBoundingVolumef& NzRenderable::GetBoundingVolume() const
|
||||||
|
{
|
||||||
|
EnsureBoundingVolumeUpdated();
|
||||||
|
|
||||||
|
return m_boundingVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NzRenderable::UpdateBoundingVolume(NzBoundingVolumef* boundingVolume, const NzMatrix4f& transformMatrix) const
|
||||||
|
{
|
||||||
|
NazaraAssert(boundingVolume, "Invalid bounding volume");
|
||||||
|
|
||||||
|
boundingVolume->Update(transformMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
NzRenderableLibrary::LibraryMap NzRenderable::s_library;
|
||||||
Loading…
Reference in New Issue