Graphics: Add frustum culling

Former-commit-id: 2741c465f9acb4a190de0a29db4a3853700461fd [formerly be67ee144fe577767a11be40f79f3f2e85d030c0] [formerly 302a6d2c8a3222401890d217f01c24a03db9ebc8 [formerly 762367a1144c340b84b61eee9d7577dcdaf717c6]]
Former-commit-id: 6504b78e4ce04d8eea0c10e7ce27bdda4b95f2dc [formerly 8d0fba6c2dde5dcc43cbea0e6e5fd2980af4b801]
Former-commit-id: 75d1deaf21035eb1b630705017462b9e059149a9
This commit is contained in:
Lynix
2016-09-06 13:30:05 +02:00
parent 4345d540bb
commit 01330dcfdf
11 changed files with 732 additions and 78 deletions

View File

@@ -0,0 +1,174 @@
// 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_CULLINGLIST_HPP
#define NAZARA_CULLINGLIST_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <vector>
namespace Nz
{
template<typename T>
class CullingList
{
public:
template<CullTest T> class Entry;
class NoTestEntry;
class SphereEntry;
class VolumeEntry;
template<CullTest T> friend class Entry;
friend NoTestEntry;
friend SphereEntry;
friend VolumeEntry;
using ResultContainer = std::vector<const T*>;
CullingList() = default;
CullingList(const CullingList& renderable) = delete;
CullingList(CullingList&& renderable) = delete;
~CullingList();
std::size_t Cull(const Frustumf& frustum);
NoTestEntry RegisterNoTest(const T* renderable);
SphereEntry RegisterSphereTest(const T* renderable);
VolumeEntry RegisterVolumeTest(const T* renderable);
CullingList& operator=(const CullingList& renderable) = delete;
CullingList& operator=(CullingList&& renderable) = delete;
// STL API
typename ResultContainer::iterator begin();
typename ResultContainer::const_iterator begin() const;
typename ResultContainer::const_iterator cbegin() const;
typename ResultContainer::const_iterator cend() const;
typename ResultContainer::const_reverse_iterator crbegin() const;
typename ResultContainer::const_reverse_iterator crend() const;
bool empty() const;
typename ResultContainer::iterator end();
typename ResultContainer::const_iterator end() const;
typename ResultContainer::reverse_iterator rbegin();
typename ResultContainer::const_reverse_iterator rbegin() const;
typename ResultContainer::reverse_iterator rend();
typename ResultContainer::const_reverse_iterator rend() const;
typename ResultContainer::size_type size() const;
NazaraSignal(OnCullingListRelease, CullingList* /*cullingList*/);
private:
inline void NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr);
inline void NotifyRelease(CullTest type, std::size_t index);
inline void NotifySphereUpdate(std::size_t index, const Spheref& sphere);
inline void NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume);
struct NoTestVisibilityEntry
{
NoTestEntry* entry;
const T* renderable;
};
struct SphereVisibilityEntry
{
Spheref sphere;
SphereEntry* entry;
const T* renderable;
};
struct VolumeVisibilityEntry
{
BoundingVolumef volume;
VolumeEntry* entry;
const T* renderable;
};
std::vector<NoTestVisibilityEntry> m_noTestList;
std::vector<SphereVisibilityEntry> m_sphereTestList;
std::vector<VolumeVisibilityEntry> m_volumeTestList;
ResultContainer m_results;
};
template<typename T>
template<typename CullTest Type>
class CullingList<T>::Entry
{
public:
Entry();
Entry(const Entry&) = delete;
Entry(Entry&& entry);
~Entry();
CullingList* GetParent() const;
void UpdateIndex(std::size_t index);
Entry& operator=(const Entry&) = delete;
Entry& operator=(Entry&& entry);
protected:
Entry(CullingList* parent, std::size_t index);
std::size_t m_index;
CullingList* m_parent;
};
template<typename T>
class CullingList<T>::NoTestEntry : public CullingList::Entry<CullTest::NoTest>
{
friend CullingList;
public:
NoTestEntry();
private:
NoTestEntry(CullingList* parent, std::size_t index);
};
template<typename T>
class CullingList<T>::SphereEntry : public CullingList::Entry<CullTest::Sphere>
{
friend CullingList;
public:
SphereEntry();
void UpdateSphere(const Spheref& sphere);
private:
SphereEntry(CullingList* parent, std::size_t index);
};
template<typename T>
class CullingList<T>::VolumeEntry : public CullingList::Entry<CullTest::Volume>
{
friend CullingList;
public:
VolumeEntry();
void UpdateVolume(const BoundingVolumef& sphere);
private:
VolumeEntry(CullingList* parent, std::size_t index);
};
}
#include <Nazara/Graphics/CullingList.inl>
#endif // NAZARA_CULLINGLIST_HPP