Added ResourceListenerWrapper
This class wraps the call to Resource::AddResourceListener/RemoveResourceListener using RAII and help a lot with some of the dependencies. Thanks to this, the render queues now handle their resources listening properly. Former-commit-id: 7f215ffa4ccadcc4f44f777656970e92ce01087a
This commit is contained in:
parent
a6183fae69
commit
8f9ea9db17
|
|
@ -12,6 +12,7 @@
|
||||||
#include <Nazara/Core/InputStream.hpp>
|
#include <Nazara/Core/InputStream.hpp>
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
|
|
||||||
|
|
@ -25,7 +26,9 @@ struct NzSoundBufferParams
|
||||||
class NzSound;
|
class NzSound;
|
||||||
class NzSoundBuffer;
|
class NzSoundBuffer;
|
||||||
|
|
||||||
|
using NzSoundBufferConstListener = NzResourceListenerWrapper<const NzSoundBuffer>;
|
||||||
using NzSoundBufferConstRef = NzResourceRef<const NzSoundBuffer>;
|
using NzSoundBufferConstRef = NzResourceRef<const NzSoundBuffer>;
|
||||||
|
using NzSoundBufferListener = NzResourceListenerWrapper<NzSoundBuffer>;
|
||||||
using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>;
|
using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>;
|
||||||
using NzSoundBufferRef = NzResourceRef<NzSoundBuffer>;
|
using NzSoundBufferRef = NzResourceRef<NzSoundBuffer>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_RESOURCELISTENERWRAPPER_HPP
|
||||||
|
#define NAZARA_RESOURCELISTENERWRAPPER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListener.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class NzResourceListenerWrapper
|
||||||
|
{
|
||||||
|
static_assert(std::is_base_of<NzResource, T>::value, "ResourceRef should only be used with resource type");
|
||||||
|
|
||||||
|
public:
|
||||||
|
NzResourceListenerWrapper(NzResourceListener* listener, int index = 0, T* resource = nullptr);
|
||||||
|
NzResourceListenerWrapper(const NzResourceListenerWrapper& listener);
|
||||||
|
NzResourceListenerWrapper(NzResourceListenerWrapper&& listener);
|
||||||
|
~NzResourceListenerWrapper();
|
||||||
|
|
||||||
|
bool IsValid() const;
|
||||||
|
void Reset(T* resource = nullptr);
|
||||||
|
|
||||||
|
operator bool() const;
|
||||||
|
operator T*() const;
|
||||||
|
T* operator->() const;
|
||||||
|
|
||||||
|
NzResourceListenerWrapper& operator=(T* resource);
|
||||||
|
NzResourceListenerWrapper& operator=(const NzResourceListenerWrapper& listener);
|
||||||
|
NzResourceListenerWrapper& operator=(NzResourceListenerWrapper&& listener);
|
||||||
|
|
||||||
|
private:
|
||||||
|
T* m_resource;
|
||||||
|
NzResourceListener* m_listener;
|
||||||
|
int m_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_RESOURCELISTENERWRAPPER_HPP
|
||||||
|
|
@ -0,0 +1,108 @@
|
||||||
|
// Copyright (C) 2015 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>::NzResourceListenerWrapper(NzResourceListener* listener, int index, T* resource) :
|
||||||
|
m_resource(nullptr),
|
||||||
|
m_listener(listener),
|
||||||
|
m_index(index)
|
||||||
|
{
|
||||||
|
Reset(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>::NzResourceListenerWrapper(const NzResourceListenerWrapper& listener) :
|
||||||
|
m_resource(nullptr),
|
||||||
|
m_listener(listener.m_listener),
|
||||||
|
m_index(listener.m_index)
|
||||||
|
{
|
||||||
|
Reset(listener.m_resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>::NzResourceListenerWrapper(NzResourceListenerWrapper&& listener) :
|
||||||
|
m_resource(listener.m_resource),
|
||||||
|
m_listener(listener.m_listener),
|
||||||
|
m_index(listener.m_index)
|
||||||
|
{
|
||||||
|
listener.m_resource = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>::~NzResourceListenerWrapper()
|
||||||
|
{
|
||||||
|
Reset(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool NzResourceListenerWrapper<T>::IsValid() const
|
||||||
|
{
|
||||||
|
return m_resource != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void NzResourceListenerWrapper<T>::Reset(T* resource)
|
||||||
|
{
|
||||||
|
if (resource)
|
||||||
|
resource->AddResourceListener(m_listener, m_index);
|
||||||
|
|
||||||
|
if (m_resource)
|
||||||
|
m_resource->RemoveResourceListener(m_listener);
|
||||||
|
|
||||||
|
m_resource = resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>::operator bool() const
|
||||||
|
{
|
||||||
|
return IsValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>::operator T*() const
|
||||||
|
{
|
||||||
|
return m_resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* NzResourceListenerWrapper<T>::operator->() const
|
||||||
|
{
|
||||||
|
return m_resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>& NzResourceListenerWrapper<T>::operator=(T* resource)
|
||||||
|
{
|
||||||
|
Reset(resource);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>& NzResourceListenerWrapper<T>::operator=(const NzResourceListenerWrapper& listener)
|
||||||
|
{
|
||||||
|
m_index = listener.m_index;
|
||||||
|
m_listener = listener.m_listener;
|
||||||
|
Reset(listener.m_resource);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
NzResourceListenerWrapper<T>& NzResourceListenerWrapper<T>::operator=(NzResourceListenerWrapper&& listener)
|
||||||
|
{
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
m_index = listener.m_index;
|
||||||
|
m_listener = listener.m_listener;
|
||||||
|
m_resource = listener.m_resource;
|
||||||
|
|
||||||
|
listener.m_resource = nullptr;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
@ -11,22 +11,22 @@
|
||||||
#include <Nazara/Core/Color.hpp>
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Core/ResourceListener.hpp>
|
#include <Nazara/Core/ResourceListener.hpp>
|
||||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Math/Box.hpp>
|
#include <Nazara/Math/Box.hpp>
|
||||||
#include <Nazara/Math/Matrix4.hpp>
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||||
#include <Nazara/Utility/MeshData.hpp>
|
#include <Nazara/Utility/MeshData.hpp>
|
||||||
|
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
class NzForwardRenderQueue;
|
class NzForwardRenderQueue;
|
||||||
class NzMaterial;
|
|
||||||
class NzSkeletalMesh;
|
|
||||||
class NzStaticMesh;
|
|
||||||
|
|
||||||
class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourceListener
|
class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourceListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue);
|
NzDeferredRenderQueue(NzForwardRenderQueue* forwardQueue);
|
||||||
~NzDeferredRenderQueue();
|
~NzDeferredRenderQueue() = default;
|
||||||
|
|
||||||
void AddDrawable(const NzDrawable* drawable) override;
|
void AddDrawable(const NzDrawable* drawable) override;
|
||||||
void AddLight(const NzLight* light) override;
|
void AddLight(const NzLight* light) override;
|
||||||
|
|
@ -35,28 +35,48 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
|
||||||
|
|
||||||
void Clear(bool fully);
|
void Clear(bool fully);
|
||||||
|
|
||||||
struct BatchedModelMaterialComparator
|
|
||||||
{
|
|
||||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BatchedSpriteMaterialComparator
|
|
||||||
{
|
|
||||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MeshDataComparator
|
struct MeshDataComparator
|
||||||
{
|
{
|
||||||
bool operator()(const NzMeshData& data1, const NzMeshData& data2);
|
bool operator()(const NzMeshData& data1, const NzMeshData& data2);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<NzMeshData, std::vector<NzMatrix4f>, MeshDataComparator> MeshInstanceContainer;
|
struct MeshInstanceEntry
|
||||||
typedef std::map<const NzMaterial*, std::tuple<bool, bool, MeshInstanceContainer>, BatchedModelMaterialComparator> ModelBatches;
|
{
|
||||||
typedef std::map<const NzMaterial*, std::vector<const NzSprite*>> BatchedSpriteContainer;
|
MeshInstanceEntry(NzDeferredRenderQueue* listener, int indexBufferValue, int vertexBufferValue) :
|
||||||
|
indexBufferListener(listener, indexBufferValue),
|
||||||
|
vertexBufferListener(listener, vertexBufferValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<NzMatrix4f> instances;
|
||||||
|
NzIndexBufferConstListener indexBufferListener;
|
||||||
|
NzVertexBufferConstListener vertexBufferListener;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<NzMeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
|
||||||
|
|
||||||
|
struct BatchedModelMaterialComparator
|
||||||
|
{
|
||||||
|
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BatchedModelEntry
|
||||||
|
{
|
||||||
|
BatchedModelEntry(NzDeferredRenderQueue* listener, int materialValue) :
|
||||||
|
materialListener(listener, materialValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NzMaterialConstListener materialListener;
|
||||||
|
MeshInstanceContainer meshMap;
|
||||||
|
bool enabled = false;
|
||||||
|
bool instancingEnabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<const NzMaterial*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
|
||||||
typedef std::vector<const NzLight*> LightContainer;
|
typedef std::vector<const NzLight*> LightContainer;
|
||||||
|
|
||||||
ModelBatches opaqueModels;
|
ModelBatches opaqueModels;
|
||||||
BatchedSpriteContainer sprites;
|
|
||||||
LightContainer directionalLights;
|
LightContainer directionalLights;
|
||||||
LightContainer pointLights;
|
LightContainer pointLights;
|
||||||
LightContainer spotLights;
|
LightContainer spotLights;
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,16 @@
|
||||||
#include <Nazara/Core/Color.hpp>
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Core/ResourceListener.hpp>
|
#include <Nazara/Core/ResourceListener.hpp>
|
||||||
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
#include <Nazara/Graphics/AbstractRenderQueue.hpp>
|
||||||
|
#include <Nazara/Graphics/Material.hpp>
|
||||||
#include <Nazara/Math/Box.hpp>
|
#include <Nazara/Math/Box.hpp>
|
||||||
#include <Nazara/Math/Matrix4.hpp>
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||||
#include <Nazara/Utility/MeshData.hpp>
|
#include <Nazara/Utility/MeshData.hpp>
|
||||||
|
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
class NzAbstractViewer;
|
class NzAbstractViewer;
|
||||||
class NzMaterial;
|
|
||||||
class NzSkeletalMesh;
|
|
||||||
class NzStaticMesh;
|
|
||||||
|
|
||||||
class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResourceListener
|
class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResourceListener
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +28,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NzForwardRenderQueue() = default;
|
NzForwardRenderQueue() = default;
|
||||||
~NzForwardRenderQueue();
|
~NzForwardRenderQueue() = default;
|
||||||
|
|
||||||
void AddDrawable(const NzDrawable* drawable) override;
|
void AddDrawable(const NzDrawable* drawable) override;
|
||||||
void AddLight(const NzLight* light) override;
|
void AddLight(const NzLight* light) override;
|
||||||
|
|
@ -49,17 +49,15 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||||
unsigned int spriteCount;
|
unsigned int spriteCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TransparentModelData
|
struct BatchedSpriteEntry
|
||||||
{
|
{
|
||||||
NzMatrix4f transformMatrix;
|
BatchedSpriteEntry(NzForwardRenderQueue* listener, int textureValue) :
|
||||||
NzMeshData meshData;
|
textureListener(listener, textureValue)
|
||||||
NzSpheref boundingSphere;
|
{
|
||||||
const NzMaterial* material;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
struct BatchedModelMaterialComparator
|
std::vector<SpriteChain_XYZ_Color_UV> spriteChains;
|
||||||
{
|
NzTextureConstListener textureListener;
|
||||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BatchedSpriteMaterialComparator
|
struct BatchedSpriteMaterialComparator
|
||||||
|
|
@ -67,15 +65,71 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
|
||||||
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::map<const NzTexture*, BatchedSpriteEntry> BasicSpriteOverlayContainer;
|
||||||
|
|
||||||
|
struct BatchedBasicSpriteEntry
|
||||||
|
{
|
||||||
|
BatchedBasicSpriteEntry(NzForwardRenderQueue* listener, int materialValue) :
|
||||||
|
materialListener(listener, materialValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NzMaterialConstListener materialListener;
|
||||||
|
BasicSpriteOverlayContainer overlayMap;
|
||||||
|
bool enabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<const NzMaterial*, BatchedBasicSpriteEntry> BasicSpriteBatches;
|
||||||
|
|
||||||
struct MeshDataComparator
|
struct MeshDataComparator
|
||||||
{
|
{
|
||||||
bool operator()(const NzMeshData& data1, const NzMeshData& data2);
|
bool operator()(const NzMeshData& data1, const NzMeshData& data2);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<NzMeshData, std::pair<NzSpheref, std::vector<NzMatrix4f>>, MeshDataComparator> MeshInstanceContainer;
|
struct MeshInstanceEntry
|
||||||
typedef std::map<const NzMaterial*, std::tuple<bool, bool, MeshInstanceContainer>, BatchedModelMaterialComparator> ModelBatches;
|
{
|
||||||
typedef std::map<const NzTexture*, std::vector<SpriteChain_XYZ_Color_UV>> BasicSpriteOverlayContainer;
|
MeshInstanceEntry(NzForwardRenderQueue* listener, int indexBufferValue, int vertexBufferValue) :
|
||||||
typedef std::map<const NzMaterial*, BasicSpriteOverlayContainer> BasicSpriteBatches;
|
indexBufferListener(listener, indexBufferValue),
|
||||||
|
vertexBufferListener(listener, vertexBufferValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<NzMatrix4f> instances;
|
||||||
|
NzIndexBufferConstListener indexBufferListener;
|
||||||
|
NzSpheref squaredBoundingSphere;
|
||||||
|
NzVertexBufferConstListener vertexBufferListener;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<NzMeshData, MeshInstanceEntry, MeshDataComparator> MeshInstanceContainer;
|
||||||
|
|
||||||
|
struct BatchedModelMaterialComparator
|
||||||
|
{
|
||||||
|
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BatchedModelEntry
|
||||||
|
{
|
||||||
|
BatchedModelEntry(NzForwardRenderQueue* listener, int materialValue) :
|
||||||
|
materialListener(listener, materialValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NzMaterialConstListener materialListener;
|
||||||
|
MeshInstanceContainer meshMap;
|
||||||
|
bool enabled = false;
|
||||||
|
bool instancingEnabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<const NzMaterial*, BatchedModelEntry, BatchedModelMaterialComparator> ModelBatches;
|
||||||
|
|
||||||
|
struct TransparentModelData
|
||||||
|
{
|
||||||
|
NzMatrix4f transformMatrix;
|
||||||
|
NzMeshData meshData;
|
||||||
|
NzSpheref squaredBoundingSphere;
|
||||||
|
const NzMaterial* material;
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::vector<const NzLight*> LightContainer;
|
typedef std::vector<const NzLight*> LightContainer;
|
||||||
typedef std::vector<unsigned int> TransparentModelContainer;
|
typedef std::vector<unsigned int> TransparentModelContainer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Color.hpp>
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
|
|
@ -34,7 +35,9 @@ struct NAZARA_API NzMaterialParams
|
||||||
|
|
||||||
class NzMaterial;
|
class NzMaterial;
|
||||||
|
|
||||||
|
using NzMaterialConstListener = NzResourceListenerWrapper<const NzMaterial>;
|
||||||
using NzMaterialConstRef = NzResourceRef<const NzMaterial>;
|
using NzMaterialConstRef = NzResourceRef<const NzMaterial>;
|
||||||
|
using NzMaterialListener = NzResourceListenerWrapper<NzMaterial>;
|
||||||
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
|
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
|
||||||
using NzMaterialRef = NzResourceRef<NzMaterial>;
|
using NzMaterialRef = NzResourceRef<NzMaterial>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -16,7 +17,9 @@
|
||||||
|
|
||||||
class NzContext;
|
class NzContext;
|
||||||
|
|
||||||
|
using NzContextConstListener = NzResourceListenerWrapper<const NzContext>;
|
||||||
using NzContextConstRef = NzResourceRef<const NzContext>;
|
using NzContextConstRef = NzResourceRef<const NzContext>;
|
||||||
|
using NzContextListener = NzResourceListenerWrapper<NzContext>;
|
||||||
using NzContextRef = NzResourceRef<NzContext>;
|
using NzContextRef = NzResourceRef<NzContext>;
|
||||||
|
|
||||||
class NzContextImpl;
|
class NzContextImpl;
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,15 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
|
||||||
class NzRenderBuffer;
|
class NzRenderBuffer;
|
||||||
|
|
||||||
|
using NzRenderBufferConstListener = NzResourceListenerWrapper<const NzRenderBuffer>;
|
||||||
using NzRenderBufferConstRef = NzResourceRef<const NzRenderBuffer>;
|
using NzRenderBufferConstRef = NzResourceRef<const NzRenderBuffer>;
|
||||||
|
using NzRenderBufferListener = NzResourceListenerWrapper<NzRenderBuffer>;
|
||||||
using NzRenderBufferRef = NzResourceRef<NzRenderBuffer>;
|
using NzRenderBufferRef = NzResourceRef<NzRenderBuffer>;
|
||||||
|
|
||||||
class NAZARA_API NzRenderBuffer : public NzResource, NzNonCopyable
|
class NAZARA_API NzRenderBuffer : public NzResource, NzNonCopyable
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include <Nazara/Core/Color.hpp>
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <Nazara/Math/Matrix4.hpp>
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
|
|
@ -23,7 +24,9 @@
|
||||||
class NzShader;
|
class NzShader;
|
||||||
class NzShaderStage;
|
class NzShaderStage;
|
||||||
|
|
||||||
|
using NzShaderConstListener = NzResourceListenerWrapper<const NzShader>;
|
||||||
using NzShaderConstRef = NzResourceRef<const NzShader>;
|
using NzShaderConstRef = NzResourceRef<const NzShader>;
|
||||||
|
using NzShaderListener = NzResourceListenerWrapper<NzShader>;
|
||||||
using NzShaderRef = NzResourceRef<NzShader>;
|
using NzShaderRef = NzResourceRef<NzShader>;
|
||||||
|
|
||||||
class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Renderer/Enums.hpp>
|
#include <Nazara/Renderer/Enums.hpp>
|
||||||
#include <Nazara/Utility/AbstractImage.hpp>
|
#include <Nazara/Utility/AbstractImage.hpp>
|
||||||
|
|
@ -18,7 +19,9 @@
|
||||||
|
|
||||||
class NzTexture;
|
class NzTexture;
|
||||||
|
|
||||||
|
using NzTextureConstListener = NzResourceListenerWrapper<const NzTexture>;
|
||||||
using NzTextureConstRef = NzResourceRef<const NzTexture>;
|
using NzTextureConstRef = NzResourceRef<const NzTexture>;
|
||||||
|
using NzTextureListener = NzResourceListenerWrapper<NzTexture>;
|
||||||
using NzTextureRef = NzResourceRef<NzTexture>;
|
using NzTextureRef = NzResourceRef<NzTexture>;
|
||||||
|
|
||||||
struct NzTextureImpl;
|
struct NzTextureImpl;
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,16 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/ParameterList.hpp>
|
#include <Nazara/Core/ParameterList.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
class NzUberShader;
|
class NzUberShader;
|
||||||
|
|
||||||
|
using NzUberShaderConstListener = NzResourceListenerWrapper<const NzUberShader>;
|
||||||
using NzUberShaderConstRef = NzResourceRef<const NzUberShader>;
|
using NzUberShaderConstRef = NzResourceRef<const NzUberShader>;
|
||||||
|
using NzUberShaderListener = NzResourceListenerWrapper<NzUberShader>;
|
||||||
using NzUberShaderRef = NzResourceRef<NzUberShader>;
|
using NzUberShaderRef = NzResourceRef<NzUberShader>;
|
||||||
|
|
||||||
class NAZARA_API NzUberShader : public NzResource
|
class NAZARA_API NzUberShader : public NzResource
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,18 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
#include <Nazara/Utility/Sequence.hpp>
|
#include <Nazara/Utility/Sequence.hpp>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
struct NAZARA_API NzAnimationParams
|
struct NAZARA_API NzAnimationParams
|
||||||
{
|
{
|
||||||
// La frame de fin à charger
|
// La frame de fin à charger
|
||||||
unsigned int endFrame = static_cast<unsigned int>(-1);
|
unsigned int endFrame = std::numeric_limits<unsigned int>::max();
|
||||||
// La frame de début à charger
|
// La frame de début à charger
|
||||||
unsigned int startFrame = 0;
|
unsigned int startFrame = 0;
|
||||||
|
|
||||||
|
|
@ -28,7 +30,9 @@ struct NAZARA_API NzAnimationParams
|
||||||
class NzAnimation;
|
class NzAnimation;
|
||||||
class NzSkeleton;
|
class NzSkeleton;
|
||||||
|
|
||||||
|
using NzAnimationConstListener = NzResourceListenerWrapper<const NzAnimation>;
|
||||||
using NzAnimationConstRef = NzResourceRef<const NzAnimation>;
|
using NzAnimationConstRef = NzResourceRef<const NzAnimation>;
|
||||||
|
using NzAnimationListener = NzResourceListenerWrapper<NzAnimation>;
|
||||||
using NzAnimationLoader = NzResourceLoader<NzAnimation, NzAnimationParams>;
|
using NzAnimationLoader = NzResourceLoader<NzAnimation, NzAnimationParams>;
|
||||||
using NzAnimationRef = NzResourceRef<NzAnimation>;
|
using NzAnimationRef = NzResourceRef<NzAnimation>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,15 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
|
||||||
class NzBuffer;
|
class NzBuffer;
|
||||||
|
|
||||||
|
using NzBufferConstListener = NzResourceListenerWrapper<const NzBuffer>;
|
||||||
using NzBufferConstRef = NzResourceRef<const NzBuffer>;
|
using NzBufferConstRef = NzResourceRef<const NzBuffer>;
|
||||||
|
using NzBufferListener = NzResourceListenerWrapper<NzBuffer>;
|
||||||
using NzBufferRef = NzResourceRef<NzBuffer>;
|
using NzBufferRef = NzResourceRef<NzBuffer>;
|
||||||
|
|
||||||
class NzAbstractBuffer;
|
class NzAbstractBuffer;
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/NonCopyable.hpp>
|
#include <Nazara/Core/NonCopyable.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/AbstractAtlas.hpp>
|
#include <Nazara/Utility/AbstractAtlas.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
@ -25,7 +26,9 @@ class NzFontData;
|
||||||
|
|
||||||
struct NzFontGlyph;
|
struct NzFontGlyph;
|
||||||
|
|
||||||
|
using NzFontConstListener = NzResourceListenerWrapper<const NzFont>;
|
||||||
using NzFontConstRef = NzResourceRef<const NzFont>;
|
using NzFontConstRef = NzResourceRef<const NzFont>;
|
||||||
|
using NzFontListener = NzResourceListenerWrapper<NzFont>;
|
||||||
using NzFontLoader = NzResourceLoader<NzFont, NzFontParams>;
|
using NzFontLoader = NzResourceLoader<NzFont, NzFontParams>;
|
||||||
using NzFontRef = NzResourceRef<NzFont>;
|
using NzFontRef = NzResourceRef<NzFont>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <Nazara/Core/Color.hpp>
|
#include <Nazara/Core/Color.hpp>
|
||||||
#include <Nazara/Core/InputStream.hpp>
|
#include <Nazara/Core/InputStream.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/AbstractImage.hpp>
|
#include <Nazara/Utility/AbstractImage.hpp>
|
||||||
|
|
@ -32,7 +33,9 @@ struct NAZARA_API NzImageParams
|
||||||
|
|
||||||
class NzImage;
|
class NzImage;
|
||||||
|
|
||||||
|
using NzImageConstListener = NzResourceListenerWrapper<const NzImage>;
|
||||||
using NzImageConstRef = NzResourceRef<const NzImage>;
|
using NzImageConstRef = NzResourceRef<const NzImage>;
|
||||||
|
using NzImageListener = NzResourceListenerWrapper<NzImage>;
|
||||||
using NzImageLoader = NzResourceLoader<NzImage, NzImageParams>;
|
using NzImageLoader = NzResourceLoader<NzImage, NzImageParams>;
|
||||||
using NzImageRef = NzResourceRef<NzImage>;
|
using NzImageRef = NzResourceRef<NzImage>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,15 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/Buffer.hpp>
|
#include <Nazara/Utility/Buffer.hpp>
|
||||||
|
|
||||||
class NzIndexBuffer;
|
class NzIndexBuffer;
|
||||||
|
|
||||||
|
using NzIndexBufferConstListener = NzResourceListenerWrapper<const NzIndexBuffer>;
|
||||||
using NzIndexBufferConstRef = NzResourceRef<const NzIndexBuffer>;
|
using NzIndexBufferConstRef = NzResourceRef<const NzIndexBuffer>;
|
||||||
|
using NzIndexBufferListener = NzResourceListenerWrapper<NzIndexBuffer>;
|
||||||
using NzIndexBufferRef = NzResourceRef<NzIndexBuffer>;
|
using NzIndexBufferRef = NzResourceRef<NzIndexBuffer>;
|
||||||
|
|
||||||
class NAZARA_API NzIndexBuffer : public NzResource
|
class NAZARA_API NzIndexBuffer : public NzResource
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <Nazara/Core/InputStream.hpp>
|
#include <Nazara/Core/InputStream.hpp>
|
||||||
#include <Nazara/Core/Primitive.hpp>
|
#include <Nazara/Core/Primitive.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
#include <Nazara/Core/ResourceListener.hpp>
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceLoader.hpp>
|
#include <Nazara/Core/ResourceLoader.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
|
|
@ -52,13 +52,15 @@ class NzPrimitiveList;
|
||||||
typedef NzVertexStruct_XYZ_Normal_UV_Tangent NzMeshVertex;
|
typedef NzVertexStruct_XYZ_Normal_UV_Tangent NzMeshVertex;
|
||||||
typedef NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning NzSkeletalMeshVertex;
|
typedef NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning NzSkeletalMeshVertex;
|
||||||
|
|
||||||
|
using NzMeshConstListener = NzResourceListenerWrapper<const NzMesh>;
|
||||||
using NzMeshConstRef = NzResourceRef<const NzMesh>;
|
using NzMeshConstRef = NzResourceRef<const NzMesh>;
|
||||||
|
using NzMeshListener = NzResourceListenerWrapper<NzMesh>;
|
||||||
using NzMeshLoader = NzResourceLoader<NzMesh, NzMeshParams>;
|
using NzMeshLoader = NzResourceLoader<NzMesh, NzMeshParams>;
|
||||||
using NzMeshRef = NzResourceRef<NzMesh>;
|
using NzMeshRef = NzResourceRef<NzMesh>;
|
||||||
|
|
||||||
struct NzMeshImpl;
|
struct NzMeshImpl;
|
||||||
|
|
||||||
class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
class NAZARA_API NzMesh : public NzResource
|
||||||
{
|
{
|
||||||
friend NzMeshLoader;
|
friend NzMeshLoader;
|
||||||
|
|
||||||
|
|
@ -121,8 +123,6 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
|
||||||
void Transform(const NzMatrix4f& matrix);
|
void Transform(const NzMatrix4f& matrix);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnResourceReleased(const NzResource* resource, int index) override;
|
|
||||||
|
|
||||||
NzMeshImpl* m_impl = nullptr;
|
NzMeshImpl* m_impl = nullptr;
|
||||||
|
|
||||||
static NzMeshLoader::LoaderList s_loaders;
|
static NzMeshLoader::LoaderList s_loaders;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class NAZARA_API NzSimpleTextDrawer : public NzAbstractTextDrawer, NzResourceLis
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NzSimpleTextDrawer();
|
NzSimpleTextDrawer();
|
||||||
virtual ~NzSimpleTextDrawer();
|
virtual ~NzSimpleTextDrawer() = default;
|
||||||
|
|
||||||
const NzRectui& GetBounds() const;
|
const NzRectui& GetBounds() const;
|
||||||
unsigned int GetCharacterSize() const;
|
unsigned int GetCharacterSize() const;
|
||||||
|
|
@ -49,6 +49,7 @@ class NAZARA_API NzSimpleTextDrawer : public NzAbstractTextDrawer, NzResourceLis
|
||||||
mutable std::vector<Glyph> m_glyphs;
|
mutable std::vector<Glyph> m_glyphs;
|
||||||
NzColor m_color;
|
NzColor m_color;
|
||||||
NzFontRef m_font;
|
NzFontRef m_font;
|
||||||
|
NzFontListener m_fontListener; // Doit se situer après le FontRef (pour être libéré avant)
|
||||||
mutable NzRectui m_bounds;
|
mutable NzRectui m_bounds;
|
||||||
NzString m_text;
|
NzString m_text;
|
||||||
nzUInt32 m_style;
|
nzUInt32 m_style;
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,16 @@
|
||||||
#define NAZARA_SKELETALMESH_HPP
|
#define NAZARA_SKELETALMESH_HPP
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/Mesh.hpp>
|
#include <Nazara/Utility/Mesh.hpp>
|
||||||
#include <Nazara/Utility/SubMesh.hpp>
|
#include <Nazara/Utility/SubMesh.hpp>
|
||||||
|
|
||||||
class NzSkeletalMesh;
|
class NzSkeletalMesh;
|
||||||
|
|
||||||
|
using NzSkeletalMeshConstListener = NzResourceListenerWrapper<const NzSkeletalMesh>;
|
||||||
using NzSkeletalMeshConstRef = NzResourceRef<const NzSkeletalMesh>;
|
using NzSkeletalMeshConstRef = NzResourceRef<const NzSkeletalMesh>;
|
||||||
|
using NzSkeletalMeshListener = NzResourceListenerWrapper<NzSkeletalMesh>;
|
||||||
using NzSkeletalMeshRef = NzResourceRef<NzSkeletalMesh>;
|
using NzSkeletalMeshRef = NzResourceRef<NzSkeletalMesh>;
|
||||||
|
|
||||||
class NAZARA_API NzSkeletalMesh final : public NzSubMesh
|
class NAZARA_API NzSkeletalMesh final : public NzSubMesh
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Math/Box.hpp>
|
#include <Nazara/Math/Box.hpp>
|
||||||
#include <Nazara/Utility/Joint.hpp>
|
#include <Nazara/Utility/Joint.hpp>
|
||||||
|
|
@ -16,7 +17,9 @@
|
||||||
|
|
||||||
class NzSkeleton;
|
class NzSkeleton;
|
||||||
|
|
||||||
|
using NzSkeletonConstListener = NzResourceListenerWrapper<const NzSkeleton>;
|
||||||
using NzSkeletonConstRef = NzResourceRef<const NzSkeleton>;
|
using NzSkeletonConstRef = NzResourceRef<const NzSkeleton>;
|
||||||
|
using NzSkeletonListener = NzResourceListenerWrapper<NzSkeleton>;
|
||||||
using NzSkeletonRef = NzResourceRef<NzSkeleton>;
|
using NzSkeletonRef = NzResourceRef<NzSkeleton>;
|
||||||
|
|
||||||
struct NzSkeletonImpl;
|
struct NzSkeletonImpl;
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,14 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/ResourceListener.hpp>
|
#include <Nazara/Core/ResourceListener.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Utility/SubMesh.hpp>
|
#include <Nazara/Utility/SubMesh.hpp>
|
||||||
|
|
||||||
class NzStaticMesh;
|
class NzStaticMesh;
|
||||||
|
|
||||||
|
using NzStaticMeshConstListener = NzResourceListenerWrapper<const NzStaticMesh>;
|
||||||
using NzStaticMeshConstRef = NzResourceRef<const NzStaticMesh>;
|
using NzStaticMeshConstRef = NzResourceRef<const NzStaticMesh>;
|
||||||
|
using NzStaticMeshListener = NzResourceListenerWrapper<NzStaticMesh>;
|
||||||
using NzStaticMeshRef = NzResourceRef<NzStaticMesh>;
|
using NzStaticMeshRef = NzResourceRef<NzStaticMesh>;
|
||||||
|
|
||||||
class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener
|
class NAZARA_API NzStaticMesh final : public NzSubMesh, NzResourceListener
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Math/Box.hpp>
|
#include <Nazara/Math/Box.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
|
@ -19,7 +20,9 @@
|
||||||
class NzMesh;
|
class NzMesh;
|
||||||
class NzSubMesh;
|
class NzSubMesh;
|
||||||
|
|
||||||
|
using NzSubMeshConstListener = NzResourceListenerWrapper<const NzSubMesh>;
|
||||||
using NzSubMeshConstRef = NzResourceRef<const NzSubMesh>;
|
using NzSubMeshConstRef = NzResourceRef<const NzSubMesh>;
|
||||||
|
using NzSubMeshListener = NzResourceListenerWrapper<NzSubMesh>;
|
||||||
using NzSubMeshRef = NzResourceRef<NzSubMesh>;
|
using NzSubMeshRef = NzResourceRef<NzSubMesh>;
|
||||||
|
|
||||||
class NAZARA_API NzSubMesh : public NzResource
|
class NAZARA_API NzSubMesh : public NzResource
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,16 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/Buffer.hpp>
|
#include <Nazara/Utility/Buffer.hpp>
|
||||||
#include <Nazara/Utility/VertexDeclaration.hpp>
|
#include <Nazara/Utility/VertexDeclaration.hpp>
|
||||||
|
|
||||||
class NzVertexBuffer;
|
class NzVertexBuffer;
|
||||||
|
|
||||||
|
using NzVertexBufferConstListener = NzResourceListenerWrapper<const NzVertexBuffer>;
|
||||||
using NzVertexBufferConstRef = NzResourceRef<NzVertexBuffer>;
|
using NzVertexBufferConstRef = NzResourceRef<NzVertexBuffer>;
|
||||||
|
using NzVertexBufferListener = NzResourceListenerWrapper<NzVertexBuffer>;
|
||||||
using NzVertexBufferRef = NzResourceRef<NzVertexBuffer>;
|
using NzVertexBufferRef = NzResourceRef<NzVertexBuffer>;
|
||||||
|
|
||||||
class NAZARA_API NzVertexBuffer : public NzResource
|
class NAZARA_API NzVertexBuffer : public NzResource
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,15 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Resource.hpp>
|
#include <Nazara/Core/Resource.hpp>
|
||||||
|
#include <Nazara/Core/ResourceListenerWrapper.hpp>
|
||||||
#include <Nazara/Core/ResourceRef.hpp>
|
#include <Nazara/Core/ResourceRef.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
|
||||||
class NzVertexDeclaration;
|
class NzVertexDeclaration;
|
||||||
|
|
||||||
|
using NzVertexDeclarationConstListener = NzResourceListenerWrapper<const NzVertexDeclaration>;
|
||||||
using NzVertexDeclarationConstRef = NzResourceRef<const NzVertexDeclaration>;
|
using NzVertexDeclarationConstRef = NzResourceRef<const NzVertexDeclaration>;
|
||||||
|
using NzVertexDeclarationListener = NzResourceListenerWrapper<NzVertexDeclaration>;
|
||||||
using NzVertexDeclarationRef = NzResourceRef<NzVertexDeclaration>;
|
using NzVertexDeclarationRef = NzResourceRef<NzVertexDeclaration>;
|
||||||
|
|
||||||
class NAZARA_API NzVertexDeclaration : public NzResource
|
class NAZARA_API NzVertexDeclaration : public NzResource
|
||||||
|
|
|
||||||
|
|
@ -54,17 +54,17 @@ bool NzDeferredGeometryPass::Process(const NzScene* scene, unsigned int firstWor
|
||||||
|
|
||||||
for (auto& matIt : m_renderQueue->opaqueModels)
|
for (auto& matIt : m_renderQueue->opaqueModels)
|
||||||
{
|
{
|
||||||
bool& used = std::get<0>(matIt.second);
|
auto& matEntry = matIt.second;
|
||||||
if (used)
|
|
||||||
|
if (matEntry.enabled)
|
||||||
{
|
{
|
||||||
bool& renderQueueInstancing = std::get<1>(matIt.second);
|
NzDeferredRenderQueue::MeshInstanceContainer& meshInstances = matEntry.meshMap;
|
||||||
NzDeferredRenderQueue::MeshInstanceContainer& meshInstances = std::get<2>(matIt.second);
|
|
||||||
|
|
||||||
if (!meshInstances.empty())
|
if (!meshInstances.empty())
|
||||||
{
|
{
|
||||||
const NzMaterial* material = matIt.first;
|
const NzMaterial* material = matIt.first;
|
||||||
|
|
||||||
bool useInstancing = instancingEnabled && renderQueueInstancing;
|
bool useInstancing = instancingEnabled && matEntry.instancingEnabled;
|
||||||
|
|
||||||
// On commence par récupérer le programme du matériau
|
// On commence par récupérer le programme du matériau
|
||||||
nzUInt32 flags = nzShaderFlags_Deferred;
|
nzUInt32 flags = nzShaderFlags_Deferred;
|
||||||
|
|
@ -88,8 +88,9 @@ bool NzDeferredGeometryPass::Process(const NzScene* scene, unsigned int firstWor
|
||||||
for (auto& meshIt : meshInstances)
|
for (auto& meshIt : meshInstances)
|
||||||
{
|
{
|
||||||
const NzMeshData& meshData = meshIt.first;
|
const NzMeshData& meshData = meshIt.first;
|
||||||
std::vector<NzMatrix4f>& instances = meshIt.second;
|
auto& meshEntry = meshIt.second;
|
||||||
|
|
||||||
|
std::vector<NzMatrix4f>& instances = meshEntry.instances;
|
||||||
if (!instances.empty())
|
if (!instances.empty())
|
||||||
{
|
{
|
||||||
const NzIndexBuffer* indexBuffer = meshData.indexBuffer;
|
const NzIndexBuffer* indexBuffer = meshData.indexBuffer;
|
||||||
|
|
@ -158,8 +159,8 @@ bool NzDeferredGeometryPass::Process(const NzScene* scene, unsigned int firstWor
|
||||||
}
|
}
|
||||||
|
|
||||||
// Et on remet à zéro les données
|
// Et on remet à zéro les données
|
||||||
renderQueueInstancing = false;
|
matEntry.enabled = false;
|
||||||
used = false;
|
matEntry.instancingEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,9 @@
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
|
#include <Nazara/Graphics/DeferredRenderQueue.hpp>
|
||||||
#include <Nazara/Graphics/Camera.hpp>
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
#include <Nazara/Graphics/Material.hpp>
|
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
@ -26,11 +23,6 @@ m_forwardQueue(forwardQueue)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NzDeferredRenderQueue::~NzDeferredRenderQueue()
|
|
||||||
{
|
|
||||||
Clear(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzDeferredRenderQueue::AddDrawable(const NzDrawable* drawable)
|
void NzDeferredRenderQueue::AddDrawable(const NzDrawable* drawable)
|
||||||
{
|
{
|
||||||
m_forwardQueue->AddDrawable(drawable);
|
m_forwardQueue->AddDrawable(drawable);
|
||||||
|
|
@ -46,6 +38,7 @@ void NzDeferredRenderQueue::AddLight(const NzLight* light)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// On trie la lumière (elles sont traitées différement selon leur type)
|
||||||
switch (light->GetLightType())
|
switch (light->GetLightType())
|
||||||
{
|
{
|
||||||
case nzLightType_Directional:
|
case nzLightType_Directional:
|
||||||
|
|
@ -61,56 +54,53 @@ void NzDeferredRenderQueue::AddLight(const NzLight* light)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On envoie également la lumière au forward-shading
|
||||||
|
///TODO: Possibilité pour une lumière de se réserver au Deferred Shading
|
||||||
m_forwardQueue->AddLight(light);
|
m_forwardQueue->AddLight(light);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzDeferredRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix)
|
void NzDeferredRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix)
|
||||||
{
|
{
|
||||||
if (material->IsEnabled(nzRendererParameter_Blend))
|
if (material->IsEnabled(nzRendererParameter_Blend))
|
||||||
|
// Un matériau transparent ? J'aime pas, va voir dans la forward queue si j'y suis
|
||||||
m_forwardQueue->AddMesh(material, meshData, meshAABB, transformMatrix);
|
m_forwardQueue->AddMesh(material, meshData, meshAABB, transformMatrix);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ModelBatches::iterator it = opaqueModels.find(material);
|
auto it = opaqueModels.find(material);
|
||||||
if (it == opaqueModels.end())
|
if (it == opaqueModels.end())
|
||||||
{
|
{
|
||||||
it = opaqueModels.insert(std::make_pair(material, ModelBatches::mapped_type())).first;
|
BatchedModelEntry entry(this, ResourceType_Material);
|
||||||
material->AddResourceListener(this, ResourceType_Material);
|
entry.materialListener = material;
|
||||||
|
|
||||||
|
it = opaqueModels.insert(std::make_pair(material, std::move(entry))).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool& used = std::get<0>(it->second);
|
BatchedModelEntry& entry = it->second;
|
||||||
bool& enableInstancing = std::get<1>(it->second);
|
entry.enabled = true;
|
||||||
MeshInstanceContainer& meshMap = std::get<2>(it->second);
|
|
||||||
|
|
||||||
used = true;
|
auto& meshMap = entry.meshMap;
|
||||||
|
|
||||||
MeshInstanceContainer::iterator it2 = meshMap.find(meshData);
|
auto it2 = meshMap.find(meshData);
|
||||||
if (it2 == meshMap.end())
|
if (it2 == meshMap.end())
|
||||||
{
|
{
|
||||||
it2 = meshMap.insert(std::make_pair(meshData, MeshInstanceContainer::mapped_type())).first;
|
MeshInstanceEntry instanceEntry(this, ResourceType_IndexBuffer, ResourceType_VertexBuffer);
|
||||||
|
instanceEntry.indexBufferListener = meshData.indexBuffer;
|
||||||
|
instanceEntry.vertexBufferListener = meshData.vertexBuffer;
|
||||||
|
|
||||||
if (meshData.indexBuffer)
|
it2 = meshMap.insert(std::make_pair(meshData, std::move(instanceEntry))).first;
|
||||||
meshData.indexBuffer->AddResourceListener(this, ResourceType_IndexBuffer);
|
|
||||||
|
|
||||||
meshData.vertexBuffer->AddResourceListener(this, ResourceType_VertexBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<NzMatrix4f>& instances = it2->second;
|
std::vector<NzMatrix4f>& instances = it2->second.instances;
|
||||||
instances.push_back(transformMatrix);
|
instances.push_back(transformMatrix);
|
||||||
|
|
||||||
// Avons-nous suffisamment d'instances pour que le coût d'utilisation de l'instancing soit payé ?
|
// Avons-nous suffisamment d'instances pour que le coût d'utilisation de l'instancing soit payé ?
|
||||||
if (instances.size() >= NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT)
|
if (instances.size() >= NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT)
|
||||||
enableInstancing = true; // Apparemment oui, activons l'instancing avec ce matériau
|
entry.instancingEnabled = true; // Apparemment oui, activons l'instancing avec ce matériau
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzDeferredRenderQueue::AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay)
|
void NzDeferredRenderQueue::AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay)
|
||||||
{
|
{
|
||||||
/*NzMaterial* material = sprite->GetMaterial();
|
|
||||||
if (!material->IsLightingEnabled() || material->IsEnabled(nzRendererParameter_Blend))
|
|
||||||
m_forwardQueue->AddSprite(sprite);
|
|
||||||
else
|
|
||||||
sprites[material].push_back(sprite);*/
|
|
||||||
|
|
||||||
m_forwardQueue->AddSprites(material, vertices, spriteCount, overlay);
|
m_forwardQueue->AddSprites(material, vertices, spriteCount, overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,27 +111,7 @@ void NzDeferredRenderQueue::Clear(bool fully)
|
||||||
spotLights.clear();
|
spotLights.clear();
|
||||||
|
|
||||||
if (fully)
|
if (fully)
|
||||||
{
|
|
||||||
for (auto& matIt : opaqueModels)
|
|
||||||
{
|
|
||||||
const NzMaterial* material = matIt.first;
|
|
||||||
material->RemoveResourceListener(this);
|
|
||||||
|
|
||||||
MeshInstanceContainer& instances = std::get<2>(matIt.second);
|
|
||||||
for (auto& instanceIt : instances)
|
|
||||||
{
|
|
||||||
const NzMeshData& renderData = instanceIt.first;
|
|
||||||
|
|
||||||
if (renderData.indexBuffer)
|
|
||||||
renderData.indexBuffer->RemoveResourceListener(this);
|
|
||||||
|
|
||||||
renderData.vertexBuffer->RemoveResourceListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
opaqueModels.clear();
|
opaqueModels.clear();
|
||||||
sprites.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_forwardQueue->Clear(fully);
|
m_forwardQueue->Clear(fully);
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +124,7 @@ bool NzDeferredRenderQueue::OnResourceDestroy(const NzResource* resource, int in
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
@ -168,14 +138,18 @@ bool NzDeferredRenderQueue::OnResourceDestroy(const NzResource* resource, int in
|
||||||
}
|
}
|
||||||
|
|
||||||
case ResourceType_Material:
|
case ResourceType_Material:
|
||||||
opaqueModels.erase(static_cast<const NzMaterial*>(resource));
|
{
|
||||||
|
const NzMaterial* material = static_cast<const NzMaterial*>(resource);
|
||||||
|
|
||||||
|
opaqueModels.erase(material);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ResourceType_VertexBuffer:
|
case ResourceType_VertexBuffer:
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
@ -203,7 +177,7 @@ void NzDeferredRenderQueue::OnResourceReleased(const NzResource* resource, int i
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
@ -233,7 +207,7 @@ void NzDeferredRenderQueue::OnResourceReleased(const NzResource* resource, int i
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
@ -268,26 +242,6 @@ bool NzDeferredRenderQueue::BatchedModelMaterialComparator::operator()(const NzM
|
||||||
return mat1 < mat2;
|
return mat1 < mat2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzDeferredRenderQueue::BatchedSpriteMaterialComparator::operator()(const NzMaterial* mat1, const NzMaterial* mat2)
|
|
||||||
{
|
|
||||||
const NzUberShader* uberShader1 = mat1->GetShader();
|
|
||||||
const NzUberShader* uberShader2 = mat2->GetShader();
|
|
||||||
if (uberShader1 != uberShader2)
|
|
||||||
return uberShader1 < uberShader2;
|
|
||||||
|
|
||||||
const NzShader* shader1 = mat1->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
|
||||||
const NzShader* shader2 = mat2->GetShaderInstance(nzShaderFlags_Deferred)->GetShader();
|
|
||||||
if (shader1 != shader2)
|
|
||||||
return shader1 < shader2;
|
|
||||||
|
|
||||||
const NzTexture* diffuseMap1 = mat1->GetDiffuseMap();
|
|
||||||
const NzTexture* diffuseMap2 = mat2->GetDiffuseMap();
|
|
||||||
if (diffuseMap1 != diffuseMap2)
|
|
||||||
return diffuseMap1 < diffuseMap2;
|
|
||||||
|
|
||||||
return mat1 < mat2;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NzDeferredRenderQueue::MeshDataComparator::operator()(const NzMeshData& data1, const NzMeshData& data2)
|
bool NzDeferredRenderQueue::MeshDataComparator::operator()(const NzMeshData& data1, const NzMeshData& data2)
|
||||||
{
|
{
|
||||||
const NzBuffer* buffer1;
|
const NzBuffer* buffer1;
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,8 @@
|
||||||
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
#include <Nazara/Graphics/ForwardRenderQueue.hpp>
|
||||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||||
#include <Nazara/Graphics/Light.hpp>
|
#include <Nazara/Graphics/Light.hpp>
|
||||||
#include <Nazara/Graphics/Material.hpp>
|
|
||||||
#include <Nazara/Graphics/Model.hpp>
|
|
||||||
#include <Nazara/Graphics/Sprite.hpp>
|
|
||||||
#include <Nazara/Utility/SkeletalMesh.hpp>
|
|
||||||
#include <Nazara/Utility/StaticMesh.hpp>
|
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
///FIXME: Régler ce problème de dépendance aux ressources
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
enum ResourceType
|
enum ResourceType
|
||||||
|
|
@ -25,11 +18,6 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
NzForwardRenderQueue::~NzForwardRenderQueue()
|
|
||||||
{
|
|
||||||
Clear(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzForwardRenderQueue::AddDrawable(const NzDrawable* drawable)
|
void NzForwardRenderQueue::AddDrawable(const NzDrawable* drawable)
|
||||||
{
|
{
|
||||||
#if NAZARA_GRAPHICS_SAFE
|
#if NAZARA_GRAPHICS_SAFE
|
||||||
|
|
@ -79,9 +67,9 @@ void NzForwardRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData&
|
||||||
transparentModelData.resize(index+1);
|
transparentModelData.resize(index+1);
|
||||||
|
|
||||||
TransparentModelData& data = transparentModelData.back();
|
TransparentModelData& data = transparentModelData.back();
|
||||||
data.boundingSphere = NzSpheref(transformMatrix.GetTranslation() + meshAABB.GetCenter(), meshAABB.GetSquaredRadius());
|
|
||||||
data.material = material;
|
data.material = material;
|
||||||
data.meshData = meshData;
|
data.meshData = meshData;
|
||||||
|
data.squaredBoundingSphere = NzSpheref(transformMatrix.GetTranslation() + meshAABB.GetCenter(), meshAABB.GetSquaredRadius());
|
||||||
data.transformMatrix = transformMatrix;
|
data.transformMatrix = transformMatrix;
|
||||||
|
|
||||||
transparentModels.push_back(index);
|
transparentModels.push_back(index);
|
||||||
|
|
@ -91,36 +79,34 @@ void NzForwardRenderQueue::AddMesh(const NzMaterial* material, const NzMeshData&
|
||||||
ModelBatches::iterator it = opaqueModels.find(material);
|
ModelBatches::iterator it = opaqueModels.find(material);
|
||||||
if (it == opaqueModels.end())
|
if (it == opaqueModels.end())
|
||||||
{
|
{
|
||||||
it = opaqueModels.insert(std::make_pair(material, ModelBatches::mapped_type())).first;
|
BatchedModelEntry entry(this, ResourceType_Material);
|
||||||
material->AddResourceListener(this, ResourceType_Material);
|
entry.materialListener = material;
|
||||||
|
|
||||||
|
it = opaqueModels.insert(std::make_pair(material, std::move(entry))).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool& used = std::get<0>(it->second);
|
BatchedModelEntry& entry = it->second;
|
||||||
bool& enableInstancing = std::get<1>(it->second);
|
entry.enabled = true;
|
||||||
MeshInstanceContainer& meshMap = std::get<2>(it->second);
|
|
||||||
|
|
||||||
used = true;
|
auto& meshMap = entry.meshMap;
|
||||||
|
|
||||||
MeshInstanceContainer::iterator it2 = meshMap.find(meshData);
|
auto it2 = meshMap.find(meshData);
|
||||||
if (it2 == meshMap.end())
|
if (it2 == meshMap.end())
|
||||||
{
|
{
|
||||||
it2 = meshMap.insert(std::make_pair(meshData, MeshInstanceContainer::mapped_type())).first;
|
MeshInstanceEntry instanceEntry(this, ResourceType_IndexBuffer, ResourceType_VertexBuffer);
|
||||||
|
instanceEntry.indexBufferListener = meshData.indexBuffer;
|
||||||
|
instanceEntry.squaredBoundingSphere = meshAABB.GetSquaredBoundingSphere();
|
||||||
|
instanceEntry.vertexBufferListener = meshData.vertexBuffer;
|
||||||
|
|
||||||
NzSpheref& squaredBoundingSphere = it2->second.first;
|
it2 = meshMap.insert(std::make_pair(meshData, std::move(instanceEntry))).first;
|
||||||
squaredBoundingSphere.Set(meshAABB.GetSquaredBoundingSphere());
|
|
||||||
|
|
||||||
if (meshData.indexBuffer)
|
|
||||||
meshData.indexBuffer->AddResourceListener(this, ResourceType_IndexBuffer);
|
|
||||||
|
|
||||||
meshData.vertexBuffer->AddResourceListener(this, ResourceType_VertexBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<NzMatrix4f>& instances = it2->second.second;
|
std::vector<NzMatrix4f>& instances = it2->second.instances;
|
||||||
instances.push_back(transformMatrix);
|
instances.push_back(transformMatrix);
|
||||||
|
|
||||||
// Avons-nous suffisamment d'instances pour que le coût d'utilisation de l'instancing soit payé ?
|
// Avons-nous suffisamment d'instances pour que le coût d'utilisation de l'instancing soit payé ?
|
||||||
if (instances.size() >= NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT)
|
if (instances.size() >= NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT)
|
||||||
enableInstancing = true; // Apparemment oui, activons l'instancing avec ce matériau
|
entry.instancingEnabled = true; // Apparemment oui, activons l'instancing avec ce matériau
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,20 +115,27 @@ void NzForwardRenderQueue::AddSprites(const NzMaterial* material, const NzVertex
|
||||||
auto matIt = basicSprites.find(material);
|
auto matIt = basicSprites.find(material);
|
||||||
if (matIt == basicSprites.end())
|
if (matIt == basicSprites.end())
|
||||||
{
|
{
|
||||||
matIt = basicSprites.insert(std::make_pair(material, BasicSpriteBatches::mapped_type())).first;
|
BatchedBasicSpriteEntry entry(this, ResourceType_Material);
|
||||||
material->AddResourceListener(this, ResourceType_Material);
|
entry.materialListener = material;
|
||||||
|
|
||||||
|
matIt = basicSprites.insert(std::make_pair(material, std::move(entry))).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& overlayMap = matIt->second;
|
BatchedBasicSpriteEntry& entry = matIt->second;
|
||||||
|
entry.enabled = true;
|
||||||
|
|
||||||
|
auto& overlayMap = entry.overlayMap;
|
||||||
|
|
||||||
auto overlayIt = overlayMap.find(overlay);
|
auto overlayIt = overlayMap.find(overlay);
|
||||||
if (overlayIt == overlayMap.end())
|
if (overlayIt == overlayMap.end())
|
||||||
{
|
{
|
||||||
overlayIt = overlayMap.insert(std::make_pair(overlay, BasicSpriteOverlayContainer::mapped_type())).first;
|
BatchedSpriteEntry overlayEntry(this, ResourceType_Texture);
|
||||||
if (overlay)
|
overlayEntry.textureListener = overlay;
|
||||||
overlay->AddResourceListener(this, ResourceType_Texture);
|
|
||||||
|
overlayIt = overlayMap.insert(std::make_pair(overlay, std::move(overlayEntry))).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& spriteVector = overlayIt->second;
|
auto& spriteVector = overlayIt->second.spriteChains;
|
||||||
spriteVector.push_back(SpriteChain_XYZ_Color_UV({vertices, spriteCount}));
|
spriteVector.push_back(SpriteChain_XYZ_Color_UV({vertices, spriteCount}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,37 +149,7 @@ void NzForwardRenderQueue::Clear(bool fully)
|
||||||
|
|
||||||
if (fully)
|
if (fully)
|
||||||
{
|
{
|
||||||
for (auto& matPair : basicSprites)
|
|
||||||
{
|
|
||||||
const NzMaterial* material = matPair.first;
|
|
||||||
material->RemoveResourceListener(this);
|
|
||||||
|
|
||||||
auto& overlayMap = matPair.second;
|
|
||||||
for (auto& overlayPair : overlayMap)
|
|
||||||
{
|
|
||||||
const NzTexture* overlay = overlayPair.first;
|
|
||||||
if (overlay)
|
|
||||||
overlay->RemoveResourceListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
basicSprites.clear();
|
basicSprites.clear();
|
||||||
|
|
||||||
for (auto& matPair : opaqueModels)
|
|
||||||
{
|
|
||||||
const NzMaterial* material = matPair.first;
|
|
||||||
material->RemoveResourceListener(this);
|
|
||||||
|
|
||||||
MeshInstanceContainer& instances = std::get<2>(matPair.second);
|
|
||||||
for (auto& instanceIt : instances)
|
|
||||||
{
|
|
||||||
const NzMeshData& renderData = instanceIt.first;
|
|
||||||
|
|
||||||
if (renderData.indexBuffer)
|
|
||||||
renderData.indexBuffer->RemoveResourceListener(this);
|
|
||||||
|
|
||||||
renderData.vertexBuffer->RemoveResourceListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
opaqueModels.clear();
|
opaqueModels.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -198,8 +161,8 @@ void NzForwardRenderQueue::Sort(const NzAbstractViewer* viewer)
|
||||||
|
|
||||||
std::sort(transparentModels.begin(), transparentModels.end(), [this, &nearPlane, &viewerNormal](unsigned int index1, unsigned int index2)
|
std::sort(transparentModels.begin(), transparentModels.end(), [this, &nearPlane, &viewerNormal](unsigned int index1, unsigned int index2)
|
||||||
{
|
{
|
||||||
const NzSpheref& sphere1 = transparentModelData[index1].boundingSphere;
|
const NzSpheref& sphere1 = transparentModelData[index1].squaredBoundingSphere;
|
||||||
const NzSpheref& sphere2 = transparentModelData[index2].boundingSphere;
|
const NzSpheref& sphere2 = transparentModelData[index2].squaredBoundingSphere;
|
||||||
|
|
||||||
NzVector3f position1 = sphere1.GetNegativeVertex(viewerNormal);
|
NzVector3f position1 = sphere1.GetNegativeVertex(viewerNormal);
|
||||||
NzVector3f position2 = sphere2.GetNegativeVertex(viewerNormal);
|
NzVector3f position2 = sphere2.GetNegativeVertex(viewerNormal);
|
||||||
|
|
@ -216,7 +179,7 @@ bool NzForwardRenderQueue::OnResourceDestroy(const NzResource* resource, int ind
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
@ -230,15 +193,19 @@ bool NzForwardRenderQueue::OnResourceDestroy(const NzResource* resource, int ind
|
||||||
}
|
}
|
||||||
|
|
||||||
case ResourceType_Material:
|
case ResourceType_Material:
|
||||||
basicSprites.erase(static_cast<const NzMaterial*>(resource));
|
{
|
||||||
opaqueModels.erase(static_cast<const NzMaterial*>(resource));
|
const NzMaterial* material = static_cast<const NzMaterial*>(resource);
|
||||||
|
|
||||||
|
basicSprites.erase(material);
|
||||||
|
opaqueModels.erase(material);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ResourceType_VertexBuffer:
|
case ResourceType_VertexBuffer:
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
@ -266,7 +233,7 @@ void NzForwardRenderQueue::OnResourceReleased(const NzResource* resource, int in
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
@ -306,7 +273,7 @@ void NzForwardRenderQueue::OnResourceReleased(const NzResource* resource, int in
|
||||||
{
|
{
|
||||||
for (auto matIt = basicSprites.begin(); matIt != basicSprites.end(); ++matIt)
|
for (auto matIt = basicSprites.begin(); matIt != basicSprites.end(); ++matIt)
|
||||||
{
|
{
|
||||||
auto& overlayMap = matIt->second;
|
auto& overlayMap = matIt->second.overlayMap;
|
||||||
for (auto overlayIt = overlayMap.begin(); overlayIt != overlayMap.end(); ++overlayIt)
|
for (auto overlayIt = overlayMap.begin(); overlayIt != overlayMap.end(); ++overlayIt)
|
||||||
{
|
{
|
||||||
if (overlayIt->first == resource)
|
if (overlayIt->first == resource)
|
||||||
|
|
@ -324,7 +291,7 @@ void NzForwardRenderQueue::OnResourceReleased(const NzResource* resource, int in
|
||||||
{
|
{
|
||||||
for (auto& modelPair : opaqueModels)
|
for (auto& modelPair : opaqueModels)
|
||||||
{
|
{
|
||||||
MeshInstanceContainer& meshes = std::get<2>(modelPair.second);
|
MeshInstanceContainer& meshes = modelPair.second.meshMap;
|
||||||
for (auto it = meshes.begin(); it != meshes.end();)
|
for (auto it = meshes.begin(); it != meshes.end();)
|
||||||
{
|
{
|
||||||
const NzMeshData& renderData = it->first;
|
const NzMeshData& renderData = it->first;
|
||||||
|
|
|
||||||
|
|
@ -175,86 +175,93 @@ void NzForwardRenderTechnique::DrawBasicSprites(const NzScene* scene) const
|
||||||
for (auto& matIt : m_renderQueue.basicSprites)
|
for (auto& matIt : m_renderQueue.basicSprites)
|
||||||
{
|
{
|
||||||
const NzMaterial* material = matIt.first;
|
const NzMaterial* material = matIt.first;
|
||||||
auto& overlayMap = matIt.second;
|
auto& matEntry = matIt.second;
|
||||||
|
|
||||||
for (auto& overlayIt : overlayMap)
|
if (matEntry.enabled)
|
||||||
{
|
{
|
||||||
const NzTexture* overlay = overlayIt.first;
|
auto& overlayMap = matEntry.overlayMap;
|
||||||
auto& spriteChainVector = overlayIt.second;
|
for (auto& overlayIt : overlayMap)
|
||||||
|
|
||||||
unsigned int spriteChainCount = spriteChainVector.size();
|
|
||||||
if (spriteChainCount > 0)
|
|
||||||
{
|
{
|
||||||
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
const NzTexture* overlay = overlayIt.first;
|
||||||
nzUInt32 flags = nzShaderFlags_VertexColor;
|
auto& spriteChainVector = overlayIt.second.spriteChains;
|
||||||
if (overlay)
|
|
||||||
flags |= nzShaderFlags_TextureOverlay;
|
|
||||||
|
|
||||||
nzUInt8 overlayUnit;
|
unsigned int spriteChainCount = spriteChainVector.size();
|
||||||
const NzShader* shader = material->Apply(flags, 0, &overlayUnit);
|
if (spriteChainCount > 0)
|
||||||
|
|
||||||
if (overlay)
|
|
||||||
{
|
{
|
||||||
overlayUnit++;
|
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||||
NzRenderer::SetTexture(overlayUnit, overlay);
|
nzUInt32 flags = nzShaderFlags_VertexColor;
|
||||||
NzRenderer::SetTextureSampler(overlayUnit, material->GetDiffuseSampler());
|
if (overlay)
|
||||||
}
|
flags |= nzShaderFlags_TextureOverlay;
|
||||||
|
|
||||||
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
nzUInt8 overlayUnit;
|
||||||
if (shader != lastShader)
|
const NzShader* shader = material->Apply(flags, 0, &overlayUnit);
|
||||||
{
|
|
||||||
// Index des uniformes dans le shader
|
|
||||||
shaderUniforms = GetShaderUniforms(shader);
|
|
||||||
|
|
||||||
// Couleur ambiante de la scène
|
if (overlay)
|
||||||
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
{
|
||||||
// Overlay
|
overlayUnit++;
|
||||||
shader->SendInteger(shaderUniforms->textureOverlay, overlayUnit);
|
NzRenderer::SetTexture(overlayUnit, overlay);
|
||||||
// Position de la caméra
|
NzRenderer::SetTextureSampler(overlayUnit, material->GetDiffuseSampler());
|
||||||
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
}
|
||||||
|
|
||||||
lastShader = shader;
|
// Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas
|
||||||
}
|
if (shader != lastShader)
|
||||||
|
{
|
||||||
|
// Index des uniformes dans le shader
|
||||||
|
shaderUniforms = GetShaderUniforms(shader);
|
||||||
|
|
||||||
unsigned int spriteChain = 0; // Quelle chaîne de sprite traitons-nous
|
// Couleur ambiante de la scène
|
||||||
unsigned int spriteChainOffset = 0; // À quel offset dans la dernière chaîne nous sommes-nous arrêtés
|
shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor());
|
||||||
|
// Overlay
|
||||||
|
shader->SendInteger(shaderUniforms->textureOverlay, overlayUnit);
|
||||||
|
// Position de la caméra
|
||||||
|
shader->SendVector(shader->GetUniformLocation(nzShaderUniform_EyePosition), viewer->GetEyePosition());
|
||||||
|
|
||||||
do
|
lastShader = shader;
|
||||||
{
|
}
|
||||||
// On ouvre le buffer en écriture
|
|
||||||
NzBufferMapper<NzVertexBuffer> vertexMapper(m_spriteBuffer, nzBufferAccess_DiscardAndWrite);
|
|
||||||
NzVertexStruct_XYZ_Color_UV* vertices = reinterpret_cast<NzVertexStruct_XYZ_Color_UV*>(vertexMapper.GetPointer());
|
|
||||||
|
|
||||||
unsigned int spriteCount = 0;
|
unsigned int spriteChain = 0; // Quelle chaîne de sprite traitons-nous
|
||||||
|
unsigned int spriteChainOffset = 0; // À quel offset dans la dernière chaîne nous sommes-nous arrêtés
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
NzForwardRenderQueue::SpriteChain_XYZ_Color_UV& currentChain = spriteChainVector[spriteChain];
|
// On ouvre le buffer en écriture
|
||||||
unsigned int count = std::min(s_maxSprites - spriteCount, currentChain.spriteCount - spriteChainOffset);
|
NzBufferMapper<NzVertexBuffer> vertexMapper(m_spriteBuffer, nzBufferAccess_DiscardAndWrite);
|
||||||
|
NzVertexStruct_XYZ_Color_UV* vertices = reinterpret_cast<NzVertexStruct_XYZ_Color_UV*>(vertexMapper.GetPointer());
|
||||||
|
|
||||||
std::memcpy(vertices, currentChain.vertices + spriteChainOffset*4, 4*count*sizeof(NzVertexStruct_XYZ_Color_UV));
|
unsigned int spriteCount = 0;
|
||||||
vertices += count*4;
|
|
||||||
|
|
||||||
spriteCount += count;
|
do
|
||||||
spriteChainOffset += count;
|
|
||||||
|
|
||||||
// Avons-nous traité la chaîne entière ?
|
|
||||||
if (spriteChainOffset == currentChain.spriteCount)
|
|
||||||
{
|
{
|
||||||
spriteChain++;
|
NzForwardRenderQueue::SpriteChain_XYZ_Color_UV& currentChain = spriteChainVector[spriteChain];
|
||||||
spriteChainOffset = 0;
|
unsigned int count = std::min(s_maxSprites - spriteCount, currentChain.spriteCount - spriteChainOffset);
|
||||||
|
|
||||||
|
std::memcpy(vertices, currentChain.vertices + spriteChainOffset*4, 4*count*sizeof(NzVertexStruct_XYZ_Color_UV));
|
||||||
|
vertices += count*4;
|
||||||
|
|
||||||
|
spriteCount += count;
|
||||||
|
spriteChainOffset += count;
|
||||||
|
|
||||||
|
// Avons-nous traité la chaîne entière ?
|
||||||
|
if (spriteChainOffset == currentChain.spriteCount)
|
||||||
|
{
|
||||||
|
spriteChain++;
|
||||||
|
spriteChainOffset = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (spriteCount < s_maxSprites && spriteChain < spriteChainCount);
|
||||||
|
|
||||||
|
vertexMapper.Unmap();
|
||||||
|
|
||||||
|
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, spriteCount*6);
|
||||||
}
|
}
|
||||||
while (spriteCount < s_maxSprites && spriteChain < spriteChainCount);
|
while (spriteChain < spriteChainCount);
|
||||||
|
|
||||||
vertexMapper.Unmap();
|
spriteChainVector.clear();
|
||||||
|
|
||||||
NzRenderer::DrawIndexedPrimitives(nzPrimitiveMode_TriangleList, 0, spriteCount*6);
|
|
||||||
}
|
}
|
||||||
while (spriteChain < spriteChainCount);
|
|
||||||
|
|
||||||
spriteChainVector.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On remet à zéro
|
||||||
|
matEntry.enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -267,11 +274,11 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
|
|
||||||
for (auto& matIt : m_renderQueue.opaqueModels)
|
for (auto& matIt : m_renderQueue.opaqueModels)
|
||||||
{
|
{
|
||||||
bool& used = std::get<0>(matIt.second);
|
auto& matEntry = matIt.second;
|
||||||
if (used)
|
|
||||||
|
if (matEntry.enabled)
|
||||||
{
|
{
|
||||||
bool& renderQueueInstancing = std::get<1>(matIt.second);
|
NzForwardRenderQueue::MeshInstanceContainer& meshInstances = matEntry.meshMap;
|
||||||
NzForwardRenderQueue::MeshInstanceContainer& meshInstances = std::get<2>(matIt.second);
|
|
||||||
|
|
||||||
if (!meshInstances.empty())
|
if (!meshInstances.empty())
|
||||||
{
|
{
|
||||||
|
|
@ -280,7 +287,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
// Nous utilisons de l'instancing que lorsqu'aucune lumière (autre que directionnelle) n'est active
|
// Nous utilisons de l'instancing que lorsqu'aucune lumière (autre que directionnelle) n'est active
|
||||||
// Ceci car l'instancing n'est pas compatible avec la recherche des lumières les plus proches
|
// Ceci car l'instancing n'est pas compatible avec la recherche des lumières les plus proches
|
||||||
// (Le deferred shading n'a pas ce problème)
|
// (Le deferred shading n'a pas ce problème)
|
||||||
bool instancing = m_instancingEnabled && (!material->IsLightingEnabled() || m_lights.IsEmpty()) && renderQueueInstancing;
|
bool instancing = m_instancingEnabled && (!material->IsLightingEnabled() || m_lights.IsEmpty()) && matEntry.instancingEnabled;
|
||||||
|
|
||||||
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
// On commence par appliquer du matériau (et récupérer le shader ainsi activé)
|
||||||
const NzShader* shader = material->Apply((instancing) ? nzShaderFlags_Instancing : 0);
|
const NzShader* shader = material->Apply((instancing) ? nzShaderFlags_Instancing : 0);
|
||||||
|
|
@ -300,11 +307,13 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meshes
|
// Meshes
|
||||||
for (auto& subMeshIt : meshInstances)
|
for (auto& meshIt : meshInstances)
|
||||||
{
|
{
|
||||||
const NzMeshData& meshData = subMeshIt.first;
|
const NzMeshData& meshData = meshIt.first;
|
||||||
const NzSpheref& boundingSphere = subMeshIt.second.first;
|
auto& meshEntry = meshIt.second;
|
||||||
std::vector<NzMatrix4f>& instances = subMeshIt.second.second;
|
|
||||||
|
const NzSpheref& squaredBoundingSphere = meshEntry.squaredBoundingSphere;
|
||||||
|
std::vector<NzMatrix4f>& instances = meshEntry.instances;
|
||||||
|
|
||||||
if (!instances.empty())
|
if (!instances.empty())
|
||||||
{
|
{
|
||||||
|
|
@ -400,7 +409,7 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
for (const NzMatrix4f& matrix : instances)
|
for (const NzMatrix4f& matrix : instances)
|
||||||
{
|
{
|
||||||
unsigned int directionalLightCount = m_directionalLights.GetLightCount();
|
unsigned int directionalLightCount = m_directionalLights.GetLightCount();
|
||||||
unsigned int otherLightCount = m_lights.ComputeClosestLights(matrix.GetTranslation() + boundingSphere.GetPosition(), boundingSphere.radius, m_maxLightPassPerObject*NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS - directionalLightCount);
|
unsigned int otherLightCount = m_lights.ComputeClosestLights(matrix.GetTranslation() + squaredBoundingSphere.GetPosition(), squaredBoundingSphere.radius, m_maxLightPassPerObject*NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS - directionalLightCount);
|
||||||
unsigned int lightCount = directionalLightCount + otherLightCount;
|
unsigned int lightCount = directionalLightCount + otherLightCount;
|
||||||
|
|
||||||
NzRenderer::SetMatrix(nzMatrixType_World, matrix);
|
NzRenderer::SetMatrix(nzMatrixType_World, matrix);
|
||||||
|
|
@ -464,8 +473,8 @@ void NzForwardRenderTechnique::DrawOpaqueModels(const NzScene* scene) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Et on remet à zéro les données
|
// Et on remet à zéro les données
|
||||||
used = false;
|
matEntry.enabled = false;
|
||||||
renderQueueInstancing = false;
|
matEntry.instancingEnabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -534,7 +543,11 @@ void NzForwardRenderTechnique::DrawTransparentModels(const NzScene* scene) const
|
||||||
// Calcul des lumières les plus proches
|
// Calcul des lumières les plus proches
|
||||||
if (lightCount < NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS && !m_lights.IsEmpty())
|
if (lightCount < NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS && !m_lights.IsEmpty())
|
||||||
{
|
{
|
||||||
unsigned int count = std::min(NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS - lightCount, m_lights.ComputeClosestLights(matrix.GetTranslation() + modelData.boundingSphere.GetPosition(), modelData.boundingSphere.radius, NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS));
|
NzVector3f position = matrix.GetTranslation() + modelData.squaredBoundingSphere.GetPosition();
|
||||||
|
float radius = modelData.squaredBoundingSphere.radius;
|
||||||
|
unsigned int closestLightCount = m_lights.ComputeClosestLights(position, radius, NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS);
|
||||||
|
|
||||||
|
unsigned int count = std::min(NAZARA_GRAPHICS_MAX_LIGHT_PER_PASS - lightCount, closestLightCount);
|
||||||
for (unsigned int i = 0; i < count; ++i)
|
for (unsigned int i = 0; i < count; ++i)
|
||||||
m_lights.GetResult(i)->Enable(shader, shaderUniforms->lightUniforms, shaderUniforms->lightOffset*(lightCount++));
|
m_lights.GetResult(i)->Enable(shader, shaderUniforms->lightUniforms, shaderUniforms->lightOffset*(lightCount++));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ namespace
|
||||||
NzVertexBuffer* buffer;
|
NzVertexBuffer* buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
using MeshMap = std::unordered_map<const NzSkeletalMesh*, BufferData>;
|
using MeshMap = std::unordered_map<const NzSkeletalMesh*, std::pair<NzSkeletalMeshConstListener, BufferData>>;
|
||||||
using SkeletonMap = std::unordered_map<const NzSkeleton*, MeshMap>;
|
using SkeletonMap = std::unordered_map<const NzSkeleton*, std::pair<NzSkeletonConstListener, MeshMap>>;
|
||||||
SkeletonMap s_cache;
|
SkeletonMap s_cache;
|
||||||
std::vector<SkinningData> s_skinningQueue;
|
std::vector<SkinningData> s_skinningQueue;
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace
|
||||||
{
|
{
|
||||||
for (auto& pair : s_cache)
|
for (auto& pair : s_cache)
|
||||||
{
|
{
|
||||||
MeshMap& meshMap = pair.second;
|
MeshMap& meshMap = pair.second.second;
|
||||||
meshMap.erase(static_cast<const NzSkeletalMesh*>(resource));
|
meshMap.erase(static_cast<const NzSkeletalMesh*>(resource));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -75,17 +75,19 @@ namespace
|
||||||
{
|
{
|
||||||
for (auto& pair : s_cache)
|
for (auto& pair : s_cache)
|
||||||
{
|
{
|
||||||
MeshMap& meshMap = pair.second;
|
MeshMap& meshMap = pair.second.second;
|
||||||
for (auto& pair2 : meshMap)
|
for (auto& pair2 : meshMap)
|
||||||
pair2.second.updated = false;
|
pair2.second.second.updated = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ResourceType_Skeleton:
|
case ResourceType_Skeleton:
|
||||||
{
|
{
|
||||||
for (auto& pair : s_cache.at(static_cast<const NzSkeleton*>(resource)))
|
const NzSkeleton* skeleton = static_cast<const NzSkeleton*>(resource);
|
||||||
pair.second.updated = false;
|
for (auto& pair : s_cache.at(skeleton).second)
|
||||||
|
pair.second.second.updated = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -161,14 +163,11 @@ NzVertexBuffer* NzSkinningManager::GetBuffer(const NzSkeletalMesh* mesh, const N
|
||||||
|
|
||||||
SkeletonMap::iterator it = s_cache.find(skeleton);
|
SkeletonMap::iterator it = s_cache.find(skeleton);
|
||||||
if (it == s_cache.end())
|
if (it == s_cache.end())
|
||||||
{
|
it = s_cache.insert(std::make_pair(skeleton, std::make_pair(NzSkeletonConstListener(&listener, ResourceType_Skeleton, skeleton), MeshMap{}))).first;
|
||||||
it = s_cache.insert(std::make_pair(skeleton, SkeletonMap::mapped_type())).first;
|
|
||||||
skeleton->AddResourceListener(&listener, ResourceType_Skeleton);
|
|
||||||
}
|
|
||||||
|
|
||||||
NzVertexBuffer* buffer;
|
NzVertexBuffer* buffer;
|
||||||
|
|
||||||
MeshMap& meshMap = it->second;
|
MeshMap& meshMap = it->second.second;
|
||||||
MeshMap::iterator it2 = meshMap.find(mesh);
|
MeshMap::iterator it2 = meshMap.find(mesh);
|
||||||
if (it2 == meshMap.end())
|
if (it2 == meshMap.end())
|
||||||
{
|
{
|
||||||
|
|
@ -177,9 +176,7 @@ NzVertexBuffer* NzSkinningManager::GetBuffer(const NzSkeletalMesh* mesh, const N
|
||||||
vertexBuffer->Reset(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), mesh->GetVertexCount(), nzDataStorage_Hardware, nzBufferUsage_Dynamic);
|
vertexBuffer->Reset(NzVertexDeclaration::Get(nzVertexLayout_XYZ_Normal_UV_Tangent), mesh->GetVertexCount(), nzDataStorage_Hardware, nzBufferUsage_Dynamic);
|
||||||
|
|
||||||
BufferData data({vertexBuffer.get(), true});
|
BufferData data({vertexBuffer.get(), true});
|
||||||
meshMap.insert(std::make_pair(mesh, data));
|
meshMap.insert(std::make_pair(mesh, std::make_pair(NzSkeletalMeshConstListener(&listener, ResourceType_SkeletalMesh, mesh), data)));
|
||||||
|
|
||||||
mesh->AddResourceListener(&listener, ResourceType_SkeletalMesh);
|
|
||||||
|
|
||||||
s_skinningQueue.push_back(SkinningData{mesh, skeleton, vertexBuffer.get()});
|
s_skinningQueue.push_back(SkinningData{mesh, skeleton, vertexBuffer.get()});
|
||||||
|
|
||||||
|
|
@ -187,7 +184,7 @@ NzVertexBuffer* NzSkinningManager::GetBuffer(const NzSkeletalMesh* mesh, const N
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BufferData& data = it2->second;
|
BufferData& data = it2->second.second;
|
||||||
if (!data.updated)
|
if (!data.updated)
|
||||||
{
|
{
|
||||||
s_skinningQueue.push_back(SkinningData{mesh, skeleton, data.buffer});
|
s_skinningQueue.push_back(SkinningData{mesh, skeleton, data.buffer});
|
||||||
|
|
@ -221,13 +218,6 @@ bool NzSkinningManager::Initialize()
|
||||||
|
|
||||||
void NzSkinningManager::Uninitialize()
|
void NzSkinningManager::Uninitialize()
|
||||||
{
|
{
|
||||||
for (auto& pair : s_cache)
|
|
||||||
{
|
|
||||||
pair.first->RemoveResourceListener(&listener);
|
|
||||||
MeshMap& meshMap = pair.second;
|
|
||||||
for (auto& pair2 : meshMap)
|
|
||||||
pair2.first->RemoveResourceListener(&listener);
|
|
||||||
}
|
|
||||||
s_cache.clear();
|
s_cache.clear();
|
||||||
s_skinningQueue.clear();
|
s_skinningQueue.clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,17 @@ namespace
|
||||||
{
|
{
|
||||||
struct Attachment
|
struct Attachment
|
||||||
{
|
{
|
||||||
|
Attachment(NzResourceListener* listener, int bufferIndex = 0, int textureIndex = 0) :
|
||||||
|
bufferListener(listener, bufferIndex),
|
||||||
|
textureListener(listener, textureIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
NzRenderBufferRef buffer;
|
NzRenderBufferRef buffer;
|
||||||
NzTextureRef texture;
|
NzTextureRef texture;
|
||||||
|
// Les listeners doivent se trouver après les références (pour être libérés avant elles)
|
||||||
|
NzRenderBufferListener bufferListener;
|
||||||
|
NzTextureListener textureListener;
|
||||||
|
|
||||||
nzAttachmentPoint attachmentPoint;
|
nzAttachmentPoint attachmentPoint;
|
||||||
bool isBuffer;
|
bool isBuffer;
|
||||||
|
|
@ -51,11 +60,16 @@ namespace
|
||||||
|
|
||||||
struct NzRenderTextureImpl
|
struct NzRenderTextureImpl
|
||||||
{
|
{
|
||||||
|
NzRenderTextureImpl(NzResourceListener* listener, int contextIndex = 0) :
|
||||||
|
context(listener, contextIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
GLuint fbo;
|
GLuint fbo;
|
||||||
std::vector<Attachment> attachments;
|
std::vector<Attachment> attachments;
|
||||||
std::vector<nzUInt8> colorTargets;
|
std::vector<nzUInt8> colorTargets;
|
||||||
mutable std::vector<GLenum> drawBuffers;
|
mutable std::vector<GLenum> drawBuffers;
|
||||||
const NzContext* context;
|
NzContextConstListener context;
|
||||||
bool checked = false;
|
bool checked = false;
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
bool userDefinedTargets = false;
|
bool userDefinedTargets = false;
|
||||||
|
|
@ -139,20 +153,23 @@ bool NzRenderTexture::AttachBuffer(nzAttachmentPoint attachmentPoint, nzUInt8 in
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
unsigned int attachIndex = attachmentIndex[attachmentPoint]+index;
|
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
|
||||||
if (m_impl->attachments.size() <= attachIndex)
|
// On créé les attachements si ça n'a pas déjà été fait
|
||||||
m_impl->attachments.resize(attachIndex+1);
|
for (unsigned int i = m_impl->attachments.size(); i <= attachIndex; ++i)
|
||||||
|
{
|
||||||
|
Attachment attachment(this, attachIndex, attachIndex);
|
||||||
|
m_impl->attachments.emplace_back(std::move(attachment));
|
||||||
|
}
|
||||||
|
|
||||||
Attachment& attachment = m_impl->attachments[attachIndex];
|
Attachment& attachment = m_impl->attachments[attachIndex];
|
||||||
attachment.attachmentPoint = attachmentPoint;
|
attachment.attachmentPoint = attachmentPoint;
|
||||||
attachment.buffer = buffer;
|
attachment.buffer = buffer;
|
||||||
|
attachment.bufferListener = buffer;
|
||||||
attachment.isBuffer = true;
|
attachment.isBuffer = true;
|
||||||
attachment.isUsed = true;
|
attachment.isUsed = true;
|
||||||
attachment.height = buffer->GetHeight();
|
attachment.height = buffer->GetHeight();
|
||||||
attachment.width = buffer->GetWidth();
|
attachment.width = buffer->GetWidth();
|
||||||
|
|
||||||
buffer->AddResourceListener(this, attachIndex);
|
|
||||||
|
|
||||||
m_impl->checked = false;
|
m_impl->checked = false;
|
||||||
|
|
||||||
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
||||||
|
|
@ -283,9 +300,14 @@ bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 i
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
unsigned int attachIndex = attachmentIndex[attachmentPoint]+index;
|
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
|
||||||
if (m_impl->attachments.size() <= attachIndex)
|
|
||||||
m_impl->attachments.resize(attachIndex+1);
|
// On créé les attachements si ça n'a pas déjà été fait
|
||||||
|
for (unsigned int i = m_impl->attachments.size(); i <= attachIndex; ++i)
|
||||||
|
{
|
||||||
|
Attachment attachment(this, attachIndex, attachIndex);
|
||||||
|
m_impl->attachments.emplace_back(std::move(attachment));
|
||||||
|
}
|
||||||
|
|
||||||
Attachment& attachment = m_impl->attachments[attachIndex];
|
Attachment& attachment = m_impl->attachments[attachIndex];
|
||||||
attachment.attachmentPoint = attachmentPoint;
|
attachment.attachmentPoint = attachmentPoint;
|
||||||
|
|
@ -293,10 +315,9 @@ bool NzRenderTexture::AttachTexture(nzAttachmentPoint attachmentPoint, nzUInt8 i
|
||||||
attachment.isUsed = true;
|
attachment.isUsed = true;
|
||||||
attachment.height = texture->GetHeight();
|
attachment.height = texture->GetHeight();
|
||||||
attachment.texture = texture;
|
attachment.texture = texture;
|
||||||
|
attachment.textureListener = texture;
|
||||||
attachment.width = texture->GetWidth();
|
attachment.width = texture->GetWidth();
|
||||||
|
|
||||||
texture->AddResourceListener(this, attachIndex);
|
|
||||||
|
|
||||||
m_impl->checked = false;
|
m_impl->checked = false;
|
||||||
|
|
||||||
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
if (attachmentPoint == nzAttachmentPoint_Color && !m_impl->userDefinedTargets)
|
||||||
|
|
@ -327,7 +348,7 @@ bool NzRenderTexture::Create(bool lock)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::unique_ptr<NzRenderTextureImpl> impl(new NzRenderTextureImpl);
|
std::unique_ptr<NzRenderTextureImpl> impl(new NzRenderTextureImpl(this));
|
||||||
|
|
||||||
impl->fbo = 0;
|
impl->fbo = 0;
|
||||||
glGenFramebuffers(1, &impl->fbo);
|
glGenFramebuffers(1, &impl->fbo);
|
||||||
|
|
@ -340,7 +361,6 @@ bool NzRenderTexture::Create(bool lock)
|
||||||
|
|
||||||
m_impl = impl.release();
|
m_impl = impl.release();
|
||||||
m_impl->context = NzContext::GetCurrent();
|
m_impl->context = NzContext::GetCurrent();
|
||||||
m_impl->context->AddResourceListener(this);
|
|
||||||
|
|
||||||
if (lock)
|
if (lock)
|
||||||
{
|
{
|
||||||
|
|
@ -372,19 +392,6 @@ void NzRenderTexture::Destroy()
|
||||||
if (IsActive())
|
if (IsActive())
|
||||||
NzRenderer::SetTarget(nullptr);
|
NzRenderer::SetTarget(nullptr);
|
||||||
|
|
||||||
m_impl->context->RemoveResourceListener(this);
|
|
||||||
|
|
||||||
for (const Attachment& attachment : m_impl->attachments)
|
|
||||||
{
|
|
||||||
if (attachment.isUsed)
|
|
||||||
{
|
|
||||||
if (attachment.isBuffer)
|
|
||||||
attachment.buffer->RemoveResourceListener(this);
|
|
||||||
else
|
|
||||||
attachment.texture->RemoveResourceListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Le FBO devant être supprimé dans son contexte d'origine, nous déléguons sa suppression à la classe OpenGL
|
// Le FBO devant être supprimé dans son contexte d'origine, nous déléguons sa suppression à la classe OpenGL
|
||||||
// Celle-ci va libérer le FBO dès que possible (la prochaine fois que son contexte d'origine sera actif)
|
// Celle-ci va libérer le FBO dès que possible (la prochaine fois que son contexte d'origine sera actif)
|
||||||
NzOpenGL::DeleteFrameBuffer(m_impl->context, m_impl->fbo);
|
NzOpenGL::DeleteFrameBuffer(m_impl->context, m_impl->fbo);
|
||||||
|
|
@ -410,7 +417,7 @@ void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned int attachIndex = attachmentIndex[attachmentPoint]+index;
|
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
|
||||||
if (attachIndex >= m_impl->attachments.size())
|
if (attachIndex >= m_impl->attachments.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -430,7 +437,7 @@ void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index)
|
||||||
{
|
{
|
||||||
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, 0);
|
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, GL_RENDERBUFFER, 0);
|
||||||
|
|
||||||
attachement.buffer->RemoveResourceListener(this);
|
attachement.bufferListener = nullptr;
|
||||||
attachement.buffer = nullptr;
|
attachement.buffer = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -440,7 +447,7 @@ void NzRenderTexture::Detach(nzAttachmentPoint attachmentPoint, nzUInt8 index)
|
||||||
else
|
else
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0, 0);
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, NzOpenGL::Attachment[attachmentPoint]+index, 0, 0, 0);
|
||||||
|
|
||||||
attachement.texture->RemoveResourceListener(this);
|
attachement.textureListener = nullptr;
|
||||||
attachement.texture = nullptr;
|
attachement.texture = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,38 @@ namespace
|
||||||
bool samplerUpdated = false;
|
bool samplerUpdated = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
using VAO_Key = std::tuple<const NzIndexBuffer*, const NzVertexBuffer*, const NzVertexDeclaration*, const NzVertexDeclaration*>;
|
struct VAO_Entry
|
||||||
using VAO_Map = std::map<VAO_Key, GLuint>;
|
{
|
||||||
|
VAO_Entry(NzResourceListener* listener, int indexBufferIndex, int vertexBufferIndex, int vertexDeclarationIndex, int instancingDeclarationIndex) :
|
||||||
|
indexBufferListener(listener, indexBufferIndex),
|
||||||
|
vertexBufferListener(listener, vertexBufferIndex),
|
||||||
|
instancingDeclarationListener(listener, instancingDeclarationIndex),
|
||||||
|
vertexDeclarationListener(listener, vertexDeclarationIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
using Context_Map = std::unordered_map<const NzContext*, VAO_Map>;
|
GLuint vao;
|
||||||
|
NzIndexBufferConstListener indexBufferListener;
|
||||||
|
NzVertexBufferConstListener vertexBufferListener;
|
||||||
|
NzVertexDeclarationConstListener instancingDeclarationListener;
|
||||||
|
NzVertexDeclarationConstListener vertexDeclarationListener;
|
||||||
|
};
|
||||||
|
|
||||||
|
using VAO_Key = std::tuple<const NzIndexBuffer*, const NzVertexBuffer*, const NzVertexDeclaration*, const NzVertexDeclaration*>;
|
||||||
|
using VAO_Map = std::map<VAO_Key, VAO_Entry>;
|
||||||
|
|
||||||
|
struct Context_Entry
|
||||||
|
{
|
||||||
|
Context_Entry(NzResourceListener* listener, int index) :
|
||||||
|
contextListener(listener, index)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NzContextConstListener contextListener;
|
||||||
|
VAO_Map vaoMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
using Context_Map = std::unordered_map<const NzContext*, Context_Entry>;
|
||||||
|
|
||||||
Context_Map s_vaos;
|
Context_Map s_vaos;
|
||||||
std::vector<unsigned int> s_dirtyTextureUnits;
|
std::vector<unsigned int> s_dirtyTextureUnits;
|
||||||
|
|
@ -116,7 +144,7 @@ namespace
|
||||||
for (auto& pair : s_vaos)
|
for (auto& pair : s_vaos)
|
||||||
{
|
{
|
||||||
const NzContext* context = pair.first;
|
const NzContext* context = pair.first;
|
||||||
VAO_Map& vaos = pair.second;
|
VAO_Map& vaos = pair.second.vaoMap;
|
||||||
|
|
||||||
auto it = vaos.begin();
|
auto it = vaos.begin();
|
||||||
while (it != vaos.end())
|
while (it != vaos.end())
|
||||||
|
|
@ -131,7 +159,7 @@ namespace
|
||||||
// son contexte d'origine est actif, sinon il faudra le mettre en file d'attente
|
// son contexte d'origine est actif, sinon il faudra le mettre en file d'attente
|
||||||
// Ceci est géré par la méthode OpenGL::DeleteVertexArray
|
// Ceci est géré par la méthode OpenGL::DeleteVertexArray
|
||||||
|
|
||||||
NzOpenGL::DeleteVertexArray(context, it->second);
|
NzOpenGL::DeleteVertexArray(context, it->second.vao);
|
||||||
vaos.erase(it++);
|
vaos.erase(it++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -147,7 +175,7 @@ namespace
|
||||||
for (auto& pair : s_vaos)
|
for (auto& pair : s_vaos)
|
||||||
{
|
{
|
||||||
const NzContext* context = pair.first;
|
const NzContext* context = pair.first;
|
||||||
VAO_Map& vaos = pair.second;
|
VAO_Map& vaos = pair.second.vaoMap;
|
||||||
|
|
||||||
auto it = vaos.begin();
|
auto it = vaos.begin();
|
||||||
while (it != vaos.end())
|
while (it != vaos.end())
|
||||||
|
|
@ -162,7 +190,7 @@ namespace
|
||||||
// son contexte d'origine est actif, sinon il faudra le mettre en file d'attente
|
// son contexte d'origine est actif, sinon il faudra le mettre en file d'attente
|
||||||
// Ceci est géré par la méthode OpenGL::DeleteVertexArray
|
// Ceci est géré par la méthode OpenGL::DeleteVertexArray
|
||||||
|
|
||||||
NzOpenGL::DeleteVertexArray(context, it->second);
|
NzOpenGL::DeleteVertexArray(context, it->second.vao);
|
||||||
vaos.erase(it++);
|
vaos.erase(it++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -178,7 +206,7 @@ namespace
|
||||||
for (auto& pair : s_vaos)
|
for (auto& pair : s_vaos)
|
||||||
{
|
{
|
||||||
const NzContext* context = pair.first;
|
const NzContext* context = pair.first;
|
||||||
VAO_Map& vaos = pair.second;
|
VAO_Map& vaos = pair.second.vaoMap;
|
||||||
|
|
||||||
auto it = vaos.begin();
|
auto it = vaos.begin();
|
||||||
while (it != vaos.end())
|
while (it != vaos.end())
|
||||||
|
|
@ -194,7 +222,7 @@ namespace
|
||||||
// son contexte d'origine est actif, sinon il faudra le mettre en file d'attente
|
// son contexte d'origine est actif, sinon il faudra le mettre en file d'attente
|
||||||
// Ceci est géré par la méthode OpenGL::DeleteVertexArray
|
// Ceci est géré par la méthode OpenGL::DeleteVertexArray
|
||||||
|
|
||||||
NzOpenGL::DeleteVertexArray(context, it->second);
|
NzOpenGL::DeleteVertexArray(context, it->second.vao);
|
||||||
vaos.erase(it++);
|
vaos.erase(it++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -1533,28 +1561,14 @@ void NzRenderer::Uninitialize()
|
||||||
for (auto& pair : s_vaos)
|
for (auto& pair : s_vaos)
|
||||||
{
|
{
|
||||||
const NzContext* context = pair.first;
|
const NzContext* context = pair.first;
|
||||||
|
const Context_Entry& contextEntry = pair.second;
|
||||||
|
|
||||||
for (auto& pair2 : pair.second)
|
for (auto& pair2 : contextEntry.vaoMap)
|
||||||
{
|
{
|
||||||
const VAO_Key& key = pair2.first;
|
const VAO_Entry& entry = pair2.second;
|
||||||
const NzIndexBuffer* indexBuffer = std::get<0>(key);
|
NzOpenGL::DeleteVertexArray(context, entry.vao);
|
||||||
const NzVertexBuffer* vertexBuffer = std::get<1>(key);
|
|
||||||
const NzVertexDeclaration* vertexDeclaration = std::get<2>(key);
|
|
||||||
const NzVertexDeclaration* instancingDeclaration = std::get<3>(key);
|
|
||||||
|
|
||||||
if (indexBuffer)
|
|
||||||
indexBuffer->RemoveResourceListener(&s_listener);
|
|
||||||
|
|
||||||
vertexBuffer->RemoveResourceListener(&s_listener);
|
|
||||||
vertexDeclaration->RemoveResourceListener(&s_listener);
|
|
||||||
|
|
||||||
if (instancingDeclaration)
|
|
||||||
instancingDeclaration->RemoveResourceListener(&s_listener);
|
|
||||||
|
|
||||||
NzOpenGL::DeleteVertexArray(context, pair2.second);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s_vaos.clear();
|
s_vaos.clear();
|
||||||
|
|
||||||
NzOpenGL::Uninitialize();
|
NzOpenGL::Uninitialize();
|
||||||
|
|
@ -1719,16 +1733,16 @@ bool NzRenderer::EnsureStateUpdate()
|
||||||
// Note: Les VAOs ne sont pas partagés entre les contextes, nous avons donc un tableau de VAOs par contexte
|
// Note: Les VAOs ne sont pas partagés entre les contextes, nous avons donc un tableau de VAOs par contexte
|
||||||
const NzContext* context = NzContext::GetCurrent();
|
const NzContext* context = NzContext::GetCurrent();
|
||||||
|
|
||||||
VAO_Map* vaos;
|
|
||||||
auto it = s_vaos.find(context);
|
auto it = s_vaos.find(context);
|
||||||
if (it == s_vaos.end())
|
if (it == s_vaos.end())
|
||||||
{
|
{
|
||||||
context->AddResourceListener(&s_listener, ResourceType_Context);
|
Context_Entry entry(&s_listener, ResourceType_Context);
|
||||||
auto pair = s_vaos.insert(std::make_pair(context, Context_Map::mapped_type()));
|
entry.contextListener = context;
|
||||||
vaos = &pair.first->second;
|
|
||||||
|
it = s_vaos.insert(std::make_pair(context, std::move(entry))).first;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
vaos = &it->second;
|
VAO_Map& vaoMap = it->second.vaoMap;
|
||||||
|
|
||||||
// Notre clé est composée de ce qui définit un VAO
|
// Notre clé est composée de ce qui définit un VAO
|
||||||
const NzVertexDeclaration* vertexDeclaration = s_vertexBuffer->GetVertexDeclaration();
|
const NzVertexDeclaration* vertexDeclaration = s_vertexBuffer->GetVertexDeclaration();
|
||||||
|
|
@ -1736,23 +1750,22 @@ bool NzRenderer::EnsureStateUpdate()
|
||||||
VAO_Key key(s_indexBuffer, s_vertexBuffer, vertexDeclaration, instancingDeclaration);
|
VAO_Key key(s_indexBuffer, s_vertexBuffer, vertexDeclaration, instancingDeclaration);
|
||||||
|
|
||||||
// On recherche un VAO existant avec notre configuration
|
// On recherche un VAO existant avec notre configuration
|
||||||
vaoIt = vaos->find(key);
|
vaoIt = vaoMap.find(key);
|
||||||
if (vaoIt == vaos->end())
|
if (vaoIt == vaoMap.end())
|
||||||
{
|
{
|
||||||
// On créé notre VAO
|
// On créé notre VAO
|
||||||
glGenVertexArrays(1, &s_currentVAO);
|
glGenVertexArrays(1, &s_currentVAO);
|
||||||
glBindVertexArray(s_currentVAO);
|
glBindVertexArray(s_currentVAO);
|
||||||
|
|
||||||
// On l'ajoute à notre liste
|
// On l'ajoute à notre liste
|
||||||
vaoIt = vaos->insert(std::make_pair(key, s_currentVAO)).first;
|
VAO_Entry entry(&s_listener, ResourceType_IndexBuffer, ResourceType_VertexBuffer, ResourceType_VertexDeclaration, ResourceType_VertexDeclaration);
|
||||||
if (s_indexBuffer)
|
entry.indexBufferListener = std::get<0>(key);
|
||||||
s_indexBuffer->AddResourceListener(&s_listener, ResourceType_IndexBuffer);
|
entry.instancingDeclarationListener = std::get<3>(key);
|
||||||
|
entry.vertexBufferListener = std::get<1>(key);
|
||||||
|
entry.vertexDeclarationListener = std::get<2>(key);
|
||||||
|
entry.vao = s_currentVAO;
|
||||||
|
|
||||||
s_vertexBuffer->AddResourceListener(&s_listener, ResourceType_VertexBuffer);
|
vaoIt = vaoMap.insert(std::make_pair(key, std::move(entry))).first;
|
||||||
vertexDeclaration->AddResourceListener(&s_listener, ResourceType_VertexDeclaration);
|
|
||||||
|
|
||||||
if (instancingDeclaration)
|
|
||||||
instancingDeclaration->AddResourceListener(&s_listener, ResourceType_VertexDeclaration);
|
|
||||||
|
|
||||||
// Et on indique qu'on veut le programmer
|
// Et on indique qu'on veut le programmer
|
||||||
update = true;
|
update = true;
|
||||||
|
|
@ -1760,7 +1773,7 @@ bool NzRenderer::EnsureStateUpdate()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Notre VAO existe déjà, il est donc inutile de le reprogrammer
|
// Notre VAO existe déjà, il est donc inutile de le reprogrammer
|
||||||
s_currentVAO = vaoIt->second;
|
s_currentVAO = vaoIt->second.vao;
|
||||||
|
|
||||||
update = false;
|
update = false;
|
||||||
}
|
}
|
||||||
|
|
@ -1911,8 +1924,8 @@ bool NzRenderer::EnsureStateUpdate()
|
||||||
if (updateFailed)
|
if (updateFailed)
|
||||||
{
|
{
|
||||||
// La création de notre VAO a échoué, libérons-le et marquons-le comme problématique
|
// La création de notre VAO a échoué, libérons-le et marquons-le comme problématique
|
||||||
glDeleteVertexArrays(1, &vaoIt->second);
|
glDeleteVertexArrays(1, &vaoIt->second.vao);
|
||||||
vaoIt->second = 0;
|
vaoIt->second.vao = 0;
|
||||||
s_currentVAO = 0;
|
s_currentVAO = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ struct NzMeshImpl
|
||||||
|
|
||||||
std::unordered_map<NzString, unsigned int> subMeshMap;
|
std::unordered_map<NzString, unsigned int> subMeshMap;
|
||||||
std::vector<NzString> materials;
|
std::vector<NzString> materials;
|
||||||
std::vector<NzSubMesh*> subMeshes;
|
std::vector<NzSubMeshRef> subMeshes;
|
||||||
nzAnimationType animationType;
|
nzAnimationType animationType;
|
||||||
NzBoxf aabb;
|
NzBoxf aabb;
|
||||||
NzSkeleton skeleton; // Uniquement pour les meshs squelettiques
|
NzSkeleton skeleton; // Uniquement pour les meshs squelettiques
|
||||||
|
|
@ -91,9 +91,6 @@ void NzMesh::AddSubMesh(NzSubMesh* subMesh)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
subMesh->AddResourceListener(this, m_impl->subMeshes.size());
|
|
||||||
subMesh->AddResourceReference();
|
|
||||||
|
|
||||||
m_impl->aabbUpdated = false; // On invalide l'AABB
|
m_impl->aabbUpdated = false; // On invalide l'AABB
|
||||||
m_impl->subMeshes.push_back(subMesh);
|
m_impl->subMeshes.push_back(subMesh);
|
||||||
}
|
}
|
||||||
|
|
@ -135,9 +132,6 @@ void NzMesh::AddSubMesh(const NzString& identifier, NzSubMesh* subMesh)
|
||||||
|
|
||||||
int index = m_impl->subMeshes.size();
|
int index = m_impl->subMeshes.size();
|
||||||
|
|
||||||
subMesh->AddResourceListener(this, index);
|
|
||||||
subMesh->AddResourceReference();
|
|
||||||
|
|
||||||
m_impl->aabbUpdated = false; // On invalide l'AABB
|
m_impl->aabbUpdated = false; // On invalide l'AABB
|
||||||
m_impl->subMeshes.push_back(subMesh);
|
m_impl->subMeshes.push_back(subMesh);
|
||||||
m_impl->subMeshMap[identifier] = index;
|
m_impl->subMeshMap[identifier] = index;
|
||||||
|
|
@ -371,12 +365,6 @@ void NzMesh::Destroy()
|
||||||
{
|
{
|
||||||
NotifyDestroy();
|
NotifyDestroy();
|
||||||
|
|
||||||
for (NzSubMesh* subMesh : m_impl->subMeshes)
|
|
||||||
{
|
|
||||||
subMesh->RemoveResourceListener(this);
|
|
||||||
subMesh->RemoveResourceReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete m_impl;
|
delete m_impl;
|
||||||
m_impl = nullptr;
|
m_impl = nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -864,11 +852,6 @@ void NzMesh::RemoveSubMesh(const NzString& identifier)
|
||||||
auto it2 = m_impl->subMeshes.begin();
|
auto it2 = m_impl->subMeshes.begin();
|
||||||
std::advance(it2, index);
|
std::advance(it2, index);
|
||||||
|
|
||||||
// On libère la ressource
|
|
||||||
NzSubMesh* subMesh = *it2;
|
|
||||||
subMesh->RemoveResourceListener(this);
|
|
||||||
subMesh->RemoveResourceReference();
|
|
||||||
|
|
||||||
m_impl->subMeshes.erase(it2);
|
m_impl->subMeshes.erase(it2);
|
||||||
|
|
||||||
m_impl->aabbUpdated = false; // On invalide l'AABB
|
m_impl->aabbUpdated = false; // On invalide l'AABB
|
||||||
|
|
@ -894,11 +877,6 @@ void NzMesh::RemoveSubMesh(unsigned int index)
|
||||||
auto it = m_impl->subMeshes.begin();
|
auto it = m_impl->subMeshes.begin();
|
||||||
std::advance(it, index);
|
std::advance(it, index);
|
||||||
|
|
||||||
// On libère la ressource
|
|
||||||
NzSubMesh* subMesh = *it;
|
|
||||||
subMesh->RemoveResourceListener(this);
|
|
||||||
subMesh->RemoveResourceReference();
|
|
||||||
|
|
||||||
m_impl->subMeshes.erase(it);
|
m_impl->subMeshes.erase(it);
|
||||||
|
|
||||||
m_impl->aabbUpdated = false; // On invalide l'AABB
|
m_impl->aabbUpdated = false; // On invalide l'AABB
|
||||||
|
|
@ -1011,11 +989,4 @@ void NzMesh::Transform(const NzMatrix4f& matrix)
|
||||||
m_impl->aabbUpdated = false;
|
m_impl->aabbUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzMesh::OnResourceReleased(const NzResource* resource, int index)
|
|
||||||
{
|
|
||||||
NazaraUnused(resource);
|
|
||||||
|
|
||||||
RemoveSubMesh(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
NzMeshLoader::LoaderList NzMesh::s_loaders;
|
NzMeshLoader::LoaderList NzMesh::s_loaders;
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,12 @@
|
||||||
|
|
||||||
NzSimpleTextDrawer::NzSimpleTextDrawer() :
|
NzSimpleTextDrawer::NzSimpleTextDrawer() :
|
||||||
m_color(NzColor::White),
|
m_color(NzColor::White),
|
||||||
|
m_fontListener(this),
|
||||||
m_style(nzTextStyle_Regular)
|
m_style(nzTextStyle_Regular)
|
||||||
{
|
{
|
||||||
SetFont(NzFont::GetDefault());
|
SetFont(NzFont::GetDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
NzSimpleTextDrawer::~NzSimpleTextDrawer()
|
|
||||||
{
|
|
||||||
if (m_font)
|
|
||||||
m_font->RemoveResourceListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
const NzRectui& NzSimpleTextDrawer::GetBounds() const
|
const NzRectui& NzSimpleTextDrawer::GetBounds() const
|
||||||
{
|
{
|
||||||
if (!m_glyphUpdated)
|
if (!m_glyphUpdated)
|
||||||
|
|
@ -63,12 +58,8 @@ void NzSimpleTextDrawer::SetColor(const NzColor& color)
|
||||||
|
|
||||||
void NzSimpleTextDrawer::SetFont(NzFont* font)
|
void NzSimpleTextDrawer::SetFont(NzFont* font)
|
||||||
{
|
{
|
||||||
if (m_font)
|
|
||||||
m_font->RemoveResourceListener(this);
|
|
||||||
|
|
||||||
m_font = font;
|
m_font = font;
|
||||||
if (m_font)
|
m_fontListener = font;
|
||||||
m_font->AddResourceListener(this);
|
|
||||||
|
|
||||||
m_glyphUpdated = false;
|
m_glyphUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue