Graphics: Remove CullingList (fixes MinGW compilation)

This commit is contained in:
Lynix 2021-10-30 00:51:54 +02:00
parent 90c738023a
commit 5d849129fd
3 changed files with 0 additions and 714 deletions

View File

@ -35,7 +35,6 @@
#include <Nazara/Graphics/BasicMaterial.hpp>
#include <Nazara/Graphics/Camera.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/DepthMaterial.hpp>
#include <Nazara/Graphics/ElementRenderer.hpp>
#include <Nazara/Graphics/Enums.hpp>

View File

@ -1,215 +0,0 @@
// Copyright (C) 2021 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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_GRAPHICS_CULLINGLIST_HPP
#define NAZARA_GRAPHICS_CULLINGLIST_HPP
#include <Nazara/Prerequisites.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> class Entry;
class BoxEntry;
class NoTestEntry;
class SphereEntry;
class VolumeEntry;
template<CullTest> friend class Entry;
friend BoxEntry;
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, bool* forceInvalidation = nullptr);
std::size_t FillWithAllEntries(bool* forceInvalidation = nullptr);
const ResultContainer& GetFullyVisibleResults() const;
const ResultContainer& GetPartiallyVisibleResults() const;
BoxEntry RegisterBoxTest(const T* renderable);
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;
NazaraSignal(OnCullingListRelease, CullingList* /*cullingList*/);
private:
inline void NotifyBoxUpdate(std::size_t index, const Boxf& boundingVolume);
inline void NotifyForceInvalidation(CullTest type, std::size_t index);
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 BoxVisibilityEntry
{
Boxf box;
BoxEntry* entry;
const T* renderable;
bool forceInvalidation;
};
struct NoTestVisibilityEntry
{
NoTestEntry* entry;
const T* renderable;
bool forceInvalidation;
};
struct SphereVisibilityEntry
{
Spheref sphere;
SphereEntry* entry;
const T* renderable;
bool forceInvalidation;
};
struct VolumeVisibilityEntry
{
BoundingVolumef volume;
VolumeEntry* entry;
const T* renderable;
bool forceInvalidation;
};
std::vector<BoxVisibilityEntry> m_boxTestList;
std::vector<NoTestVisibilityEntry> m_noTestList;
std::vector<SphereVisibilityEntry> m_sphereTestList;
std::vector<VolumeVisibilityEntry> m_volumeTestList;
ResultContainer m_fullyVisibleResults;
ResultContainer m_partiallyVisibleResults;
};
template<typename T>
template<CullTest Type>
class CullingList<T>::Entry
{
public:
Entry();
Entry(const Entry&) = delete;
Entry(Entry&& entry);
~Entry();
void ForceInvalidation();
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>::BoxEntry : public CullingList<T>::template Entry<CullTest::Box>
{
friend CullingList;
using ParentType = Entry<CullTest::Box>;
public:
BoxEntry();
BoxEntry(BoxEntry&&) = default;
~BoxEntry() = default;
void UpdateBox(const Boxf& box);
BoxEntry& operator=(BoxEntry&&) = default;
private:
BoxEntry(CullingList* parent, std::size_t index);
};
template<typename T>
class CullingList<T>::NoTestEntry : public CullingList<T>::template Entry<CullTest::NoTest>
{
friend CullingList;
using ParentType = Entry<CullTest::NoTest>;
public:
NoTestEntry();
NoTestEntry(NoTestEntry&&) = default;
~NoTestEntry() = default;
NoTestEntry& operator=(NoTestEntry&&) = default;
private:
NoTestEntry(CullingList* parent, std::size_t index);
};
template<typename T>
class CullingList<T>::SphereEntry : public CullingList<T>::template Entry<CullTest::Sphere>
{
friend CullingList;
using ParentType = Entry<CullTest::Sphere>;
public:
SphereEntry();
SphereEntry(SphereEntry&&) = default;
~SphereEntry() = default;
void UpdateSphere(const Spheref& sphere);
SphereEntry& operator=(SphereEntry&&) = default;
private:
SphereEntry(CullingList* parent, std::size_t index);
};
template<typename T>
class CullingList<T>::VolumeEntry : public CullingList<T>::template Entry<CullTest::Volume>
{
friend CullingList;
using ParentType = Entry<CullTest::Volume>;
public:
VolumeEntry();
VolumeEntry(VolumeEntry&&) = default;
~VolumeEntry() = default;
void UpdateVolume(const BoundingVolumef& sphere);
VolumeEntry& operator=(VolumeEntry&&) = default;
private:
VolumeEntry(CullingList* parent, std::size_t index);
};
}
#include <Nazara/Graphics/CullingList.inl>
#endif // NAZARA_GRAPHICS_CULLINGLIST_HPP

View File

@ -1,498 +0,0 @@
// Copyright (C) 2021 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// 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/CullingList.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
template<typename T>
CullingList<T>::~CullingList()
{
OnCullingListRelease(this);
}
template<typename T>
std::size_t CullingList<T>::Cull(const Frustumf& frustum, bool* forceInvalidation)
{
m_fullyVisibleResults.clear();
m_partiallyVisibleResults.clear();
bool forcedInvalidation = false;
std::size_t fullyVisibleHash = 5U;
std::size_t partiallyVisibleHash = 5U;
auto CombineHash = [](std::size_t currentHash, std::size_t newHash)
{
return currentHash * 23 + newHash;
};
for (BoxVisibilityEntry& entry : m_boxTestList)
{
switch (frustum.Intersect(entry.box))
{
case IntersectionSide::Inside:
m_fullyVisibleResults.push_back(entry.renderable);
fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
entry.forceInvalidation = false;
break;
case IntersectionSide::Intersecting:
m_partiallyVisibleResults.push_back(entry.renderable);
partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash<const T*>()(entry.renderable));
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
entry.forceInvalidation = false;
break;
case IntersectionSide::Outside:
break;
}
}
for (NoTestVisibilityEntry& entry : m_noTestList)
{
m_fullyVisibleResults.push_back(entry.renderable);
CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
if (entry.forceInvalidation)
{
forcedInvalidation = true;
entry.forceInvalidation = false;
}
}
for (SphereVisibilityEntry& entry : m_sphereTestList)
{
switch (frustum.Intersect(entry.sphere))
{
case IntersectionSide::Inside:
m_fullyVisibleResults.push_back(entry.renderable);
fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
entry.forceInvalidation = false;
break;
case IntersectionSide::Intersecting:
m_partiallyVisibleResults.push_back(entry.renderable);
partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash<const T*>()(entry.renderable));
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
entry.forceInvalidation = false;
break;
case IntersectionSide::Outside:
break;
}
}
for (VolumeVisibilityEntry& entry : m_volumeTestList)
{
switch (frustum.Intersect(entry.volume))
{
case IntersectionSide::Inside:
m_fullyVisibleResults.push_back(entry.renderable);
fullyVisibleHash = CombineHash(fullyVisibleHash, std::hash<const T*>()(entry.renderable));
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
entry.forceInvalidation = false;
break;
case IntersectionSide::Intersecting:
m_partiallyVisibleResults.push_back(entry.renderable);
partiallyVisibleHash = CombineHash(partiallyVisibleHash, std::hash<const T*>()(entry.renderable));
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
entry.forceInvalidation = false;
break;
case IntersectionSide::Outside:
break;
}
}
if (forceInvalidation)
*forceInvalidation = forcedInvalidation;
return 5 + partiallyVisibleHash * 17 + fullyVisibleHash;
}
template<typename T>
std::size_t CullingList<T>::FillWithAllEntries(bool* forceInvalidation)
{
m_fullyVisibleResults.clear();
m_partiallyVisibleResults.clear();
bool forcedInvalidation = false;
std::size_t visibleHash = 5U;
auto FillWithList = [&](auto& testList)
{
for (auto& entry : testList)
{
m_fullyVisibleResults.push_back(entry.renderable);
visibleHash = visibleHash * 23 + std::hash<const T*>()(entry.renderable);
forcedInvalidation = forcedInvalidation | entry.forceInvalidation;
entry.forceInvalidation = false;
}
};
FillWithList(m_boxTestList);
FillWithList(m_noTestList);
FillWithList(m_sphereTestList);
FillWithList(m_volumeTestList);
if (forceInvalidation)
*forceInvalidation = forcedInvalidation;
return visibleHash;
}
template<typename T>
auto CullingList<T>::GetFullyVisibleResults() const -> const ResultContainer&
{
return m_fullyVisibleResults;
}
template<typename T>
auto CullingList<T>::GetPartiallyVisibleResults() const -> const ResultContainer&
{
return m_partiallyVisibleResults;
}
template<typename T>
auto CullingList<T>::RegisterBoxTest(const T* renderable) -> BoxEntry
{
BoxEntry newEntry(this, m_boxTestList.size());
m_boxTestList.emplace_back(BoxVisibilityEntry{ Nz::Boxf(), &newEntry, renderable, false }); //< Address of entry will be updated when moving
return newEntry;
}
template<typename T>
auto CullingList<T>::RegisterNoTest(const T* renderable) -> NoTestEntry
{
NoTestEntry newEntry(this, m_volumeTestList.size());
m_noTestList.emplace_back(NoTestVisibilityEntry{&newEntry, renderable, false}); //< Address of entry will be updated when moving
return newEntry;
}
template<typename T>
auto CullingList<T>::RegisterSphereTest(const T* renderable) -> SphereEntry
{
SphereEntry newEntry(this, m_sphereTestList.size());
m_sphereTestList.emplace_back(SphereVisibilityEntry{Nz::Spheref(), &newEntry, renderable, false}); //< Address of entry will be updated when moving
return newEntry;
}
template<typename T>
auto CullingList<T>::RegisterVolumeTest(const T* renderable) -> VolumeEntry
{
VolumeEntry newEntry(this, m_volumeTestList.size());
m_volumeTestList.emplace_back(VolumeVisibilityEntry{Nz::BoundingVolumef(), &newEntry, renderable, false}); //< Address of entry will be updated when moving
return newEntry;
}
template<typename T>
inline void CullingList<T>::NotifyBoxUpdate(std::size_t index, const Boxf& box)
{
m_boxTestList[index].box = box;
}
template<typename T>
void CullingList<T>::NotifyForceInvalidation(CullTest type, std::size_t index)
{
switch (type)
{
case CullTest::Box:
{
m_boxTestList[index].forceInvalidation = true;
break;
}
case CullTest::NoTest:
{
m_noTestList[index].forceInvalidation = true;
break;
}
case CullTest::Sphere:
{
m_sphereTestList[index].forceInvalidation = true;
break;
}
case CullTest::Volume:
{
m_volumeTestList[index].forceInvalidation = true;
break;
}
default:
NazaraInternalError("Unhandled culltype");
break;
}
}
template<typename T>
void CullingList<T>::NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr)
{
NazaraUnused(oldPtr);
switch (type)
{
case CullTest::Box:
{
BoxVisibilityEntry& entry = m_boxTestList[index];
NazaraAssert(entry.entry == oldPtr, "Invalid box entry");
entry.entry = static_cast<BoxEntry*>(newPtr);
break;
}
case CullTest::NoTest:
{
NoTestVisibilityEntry& entry = m_noTestList[index];
NazaraAssert(entry.entry == oldPtr, "Invalid entry");
entry.entry = static_cast<NoTestEntry*>(newPtr);
break;
}
case CullTest::Sphere:
{
SphereVisibilityEntry& entry = m_sphereTestList[index];
NazaraAssert(entry.entry == oldPtr, "Invalid sphere entry");
entry.entry = static_cast<SphereEntry*>(newPtr);
break;
}
case CullTest::Volume:
{
VolumeVisibilityEntry& entry = m_volumeTestList[index];
NazaraAssert(entry.entry == oldPtr, "Invalid volume entry");
entry.entry = static_cast<VolumeEntry*>(newPtr);
break;
}
default:
NazaraInternalError("Unhandled culltype");
break;
}
}
template<typename T>
void CullingList<T>::NotifyRelease(CullTest type, std::size_t index)
{
switch (type)
{
case CullTest::Box:
{
m_boxTestList[index] = std::move(m_boxTestList.back());
m_boxTestList[index].entry->UpdateIndex(index);
m_boxTestList.pop_back();
break;
}
case CullTest::NoTest:
{
m_noTestList[index] = std::move(m_noTestList.back());
m_noTestList[index].entry->UpdateIndex(index);
m_noTestList.pop_back();
break;
}
case CullTest::Sphere:
{
m_sphereTestList[index] = std::move(m_sphereTestList.back());
m_sphereTestList[index].entry->UpdateIndex(index);
m_sphereTestList.pop_back();
break;
}
case CullTest::Volume:
{
m_volumeTestList[index] = std::move(m_volumeTestList.back());
m_volumeTestList[index].entry->UpdateIndex(index);
m_volumeTestList.pop_back();
break;
}
default:
NazaraInternalError("Unhandled culltype");
break;
}
}
template<typename T>
void CullingList<T>::NotifySphereUpdate(std::size_t index, const Spheref& sphere)
{
m_sphereTestList[index].sphere = sphere;
}
template<typename T>
void CullingList<T>::NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume)
{
m_volumeTestList[index].volume = boundingVolume;
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::Entry() :
m_parent(nullptr)
{
}
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::Entry(CullingList* parent, std::size_t index) :
m_index(index),
m_parent(parent)
{
}
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::Entry(Entry&& entry) :
m_index(entry.m_index),
m_parent(entry.m_parent)
{
if (m_parent)
m_parent->NotifyMovement(Type, m_index, &entry, this);
entry.m_parent = nullptr;
}
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::~Entry()
{
if (m_parent)
m_parent->NotifyRelease(Type, m_index);
}
template<typename T>
template<CullTest Type>
void CullingList<T>::Entry<Type>::ForceInvalidation()
{
m_parent->NotifyForceInvalidation(Type, m_index);
}
template<typename T>
template<CullTest Type>
CullingList<T>* CullingList<T>::Entry<Type>::GetParent() const
{
return m_parent;
}
template<typename T>
template<CullTest Type>
void CullingList<T>::Entry<Type>::UpdateIndex(std::size_t index)
{
m_index = index;
}
template<typename T>
template<CullTest Type>
typename CullingList<T>::template Entry<Type>& CullingList<T>::Entry<Type>::operator=(Entry&& entry)
{
m_index = entry.m_index;
m_parent = entry.m_parent;
if (m_parent)
m_parent->NotifyMovement(Type, m_index, &entry, this);
entry.m_parent = nullptr;
return *this;
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
CullingList<T>::BoxEntry::BoxEntry() :
ParentType()
{
}
template<typename T>
CullingList<T>::BoxEntry::BoxEntry(CullingList* parent, std::size_t index) :
ParentType(parent, index)
{
}
template<typename T>
void CullingList<T>::BoxEntry::UpdateBox(const Boxf& box)
{
this->m_parent->NotifyBoxUpdate(this->m_index, box);
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
CullingList<T>::NoTestEntry::NoTestEntry() :
ParentType()
{
}
template<typename T>
CullingList<T>::NoTestEntry::NoTestEntry(CullingList* parent, std::size_t index) :
ParentType(parent, index)
{
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
CullingList<T>::SphereEntry::SphereEntry() :
ParentType()
{
}
template<typename T>
CullingList<T>::SphereEntry::SphereEntry(CullingList* parent, std::size_t index) :
ParentType(parent, index)
{
}
template<typename T>
void CullingList<T>::SphereEntry::UpdateSphere(const Spheref& sphere)
{
this->m_parent->NotifySphereUpdate(this->m_index, sphere);
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
CullingList<T>::VolumeEntry::VolumeEntry() :
ParentType()
{
}
template<typename T>
CullingList<T>::VolumeEntry::VolumeEntry(CullingList* parent, std::size_t index) :
ParentType(parent, index)
{
}
template<typename T>
void CullingList<T>::VolumeEntry::UpdateVolume(const BoundingVolumef& volume)
{
this->m_parent->NotifyVolumeUpdate(this->m_index, volume);
}
}
#include <Nazara/Graphics/DebugOff.hpp>