Replaced (Uber)ShaderLibrary by template class ObjectLibrary
Former-commit-id: d488cfd4e5e3ff31112fffebce2b7cdb86cc2e55
This commit is contained in:
parent
c2d1773b41
commit
e18e490c59
|
|
@ -0,0 +1,39 @@
|
|||
// 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_OBJECTLIBRARY_HPP
|
||||
#define NAZARA_OBJECTLIBRARY_HPP
|
||||
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
template<typename Type>
|
||||
class NzObjectLibrary
|
||||
{
|
||||
friend Type;
|
||||
|
||||
public:
|
||||
NzObjectLibrary() = delete;
|
||||
~NzObjectLibrary() = delete;
|
||||
|
||||
static NzObjectRef<Type> Get(const NzString& name);
|
||||
static bool Has(const NzString& name);
|
||||
|
||||
static void Register(const NzString& name, NzObjectRef<Type> object);
|
||||
static void Unregister(const NzString& name);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
using LibraryMap = std::unordered_map<NzString, NzObjectRef<Type>>;
|
||||
};
|
||||
|
||||
#include <Nazara/Core/ObjectLibrary.inl>
|
||||
|
||||
#endif // NAZARA_OBJECTLIBRARY_HPP
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// 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/Error.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
template<typename Type>
|
||||
NzObjectRef<Type> NzObjectLibrary<Type>::Get(const NzString& name)
|
||||
{
|
||||
auto it = Type::s_library.find(name);
|
||||
if (it != Type::s_library.end())
|
||||
return it->second;
|
||||
else
|
||||
{
|
||||
NazaraError("Object \"" + name + "\" is not present");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool NzObjectLibrary<Type>::Has(const NzString& name)
|
||||
{
|
||||
return Type::s_library.find(name) != Type::s_library.end();
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void NzObjectLibrary<Type>::Register(const NzString& name, NzObjectRef<Type> object)
|
||||
{
|
||||
Type::s_library.emplace(name, object);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void NzObjectLibrary<Type>::Unregister(const NzString& name)
|
||||
{
|
||||
Type::s_library.erase(name);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool NzObjectLibrary<Type>::Initialize()
|
||||
{
|
||||
return true; // Que faire
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
void NzObjectLibrary<Type>::Uninitialize()
|
||||
{
|
||||
Type::s_library.clear();
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -44,14 +44,12 @@
|
|||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/TextureSampler.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <Nazara/Renderer/UberShaderInstance.hpp>
|
||||
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/UberShaderPreprocessor.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_RENDERER_HPP
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectListenerWrapper.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
|
|
@ -26,11 +27,13 @@ class NzShaderStage;
|
|||
|
||||
using NzShaderConstListener = NzObjectListenerWrapper<const NzShader>;
|
||||
using NzShaderConstRef = NzObjectRef<const NzShader>;
|
||||
using NzShaderLibrary = NzObjectLibrary<NzShader>;
|
||||
using NzShaderListener = NzObjectListenerWrapper<NzShader>;
|
||||
using NzShaderRef = NzObjectRef<NzShader>;
|
||||
|
||||
class NAZARA_API NzShader : public NzRefCounted, NzNonCopyable
|
||||
{
|
||||
friend NzShaderLibrary;
|
||||
friend class NzRenderer;
|
||||
|
||||
public:
|
||||
|
|
@ -102,10 +105,15 @@ class NAZARA_API NzShader : public NzRefCounted, NzNonCopyable
|
|||
private:
|
||||
bool PostLinkage();
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::vector<unsigned int> m_attachedShaders[nzShaderStage_Max+1];
|
||||
bool m_linked;
|
||||
int m_uniformLocations[nzShaderUniform_Max+1];
|
||||
unsigned int m_program;
|
||||
|
||||
static NzShaderLibrary::LibraryMap s_library;
|
||||
};
|
||||
|
||||
#include <Nazara/Renderer/Shader.inl>
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_SHADERLIBRARY_HPP
|
||||
#define NAZARA_SHADERLIBRARY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
class NAZARA_API NzShaderLibrary
|
||||
{
|
||||
friend class NzRenderer;
|
||||
|
||||
public:
|
||||
NzShaderLibrary() = delete;
|
||||
~NzShaderLibrary() = delete;
|
||||
|
||||
static NzShader* Get(const NzString& name);
|
||||
static bool Has(const NzString& name);
|
||||
|
||||
static void Register(const NzString& name, NzShader* shader);
|
||||
static void Unregister(const NzString& name);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static std::unordered_map<NzString, NzShaderRef> s_library;
|
||||
};
|
||||
|
||||
#endif // NAZARA_SHADERLIBRARY_HPP
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/ParameterList.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/ObjectListenerWrapper.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
|
|
@ -19,16 +20,26 @@ class NzUberShader;
|
|||
|
||||
using NzUberShaderConstListener = NzObjectListenerWrapper<const NzUberShader>;
|
||||
using NzUberShaderConstRef = NzObjectRef<const NzUberShader>;
|
||||
using NzUberShaderLibrary = NzObjectLibrary<NzUberShader>;
|
||||
using NzUberShaderListener = NzObjectListenerWrapper<NzUberShader>;
|
||||
using NzUberShaderRef = NzObjectRef<NzUberShader>;
|
||||
|
||||
class NAZARA_API NzUberShader : public NzRefCounted
|
||||
{
|
||||
friend NzUberShaderLibrary;
|
||||
friend class NzRenderer;
|
||||
|
||||
public:
|
||||
NzUberShader() = default;
|
||||
virtual ~NzUberShader();
|
||||
|
||||
virtual NzUberShaderInstance* Get(const NzParameterList& parameters) const = 0;
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static NzUberShaderLibrary::LibraryMap s_library;
|
||||
};
|
||||
|
||||
#endif // NAZARA_UBERSHADER_HPP
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_UBERSHADERLIBRARY_HPP
|
||||
#define NAZARA_UBERSHADERLIBRARY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
class NAZARA_API NzUberShaderLibrary
|
||||
{
|
||||
friend class NzRenderer;
|
||||
|
||||
public:
|
||||
NzUberShaderLibrary() = delete;
|
||||
~NzUberShaderLibrary() = delete;
|
||||
|
||||
static NzUberShader* Get(const NzString& name);
|
||||
static bool Has(const NzString& name);
|
||||
|
||||
static void Register(const NzString& name, NzUberShader* uberShader);
|
||||
static void Unregister(const NzString& name);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static std::unordered_map<NzString, NzUberShaderRef> s_library;
|
||||
};
|
||||
|
||||
#endif // NAZARA_UBERSHADERLIBRARY_HPP
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <Nazara/Graphics/ColorBackGround.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <Nazara/Graphics/DeferredBloomPass.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include <Nazara/Graphics/DeferredFXAAPass.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
#include <Nazara/Utility/VertexStruct.hpp>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <Nazara/Graphics/Scene.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderTexture.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Utility/StaticMesh.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/ShaderStage.hpp>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/UberShaderPreprocessor.hpp>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <Nazara/Graphics/TextureBackground.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
|
|
|
|||
|
|
@ -16,9 +16,8 @@
|
|||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/Texture.hpp>
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Renderer/UberShader.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
|
|
@ -865,9 +864,9 @@ bool NzRenderer::Initialize()
|
|||
}
|
||||
}
|
||||
|
||||
if (!NzShaderLibrary::Initialize())
|
||||
if (!NzShader::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize shader library");
|
||||
NazaraError("Failed to initialize shaders");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -877,9 +876,9 @@ bool NzRenderer::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!NzUberShaderLibrary::Initialize())
|
||||
if (!NzUberShader::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize uber shader library");
|
||||
NazaraError("Failed to initialize uber shaders");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1544,9 +1543,9 @@ void NzRenderer::Uninitialize()
|
|||
|
||||
NzShaderLibrary::Unregister("DebugSimple");
|
||||
|
||||
NzUberShaderLibrary::Uninitialize();
|
||||
NzUberShader::Uninitialize();
|
||||
NzTextureSampler::Uninitialize();
|
||||
NzShaderLibrary::Uninitialize();
|
||||
NzShader::Uninitialize();
|
||||
NzDebugDrawer::Uninitialize();
|
||||
|
||||
s_textureUnits.clear();
|
||||
|
|
|
|||
|
|
@ -787,3 +787,21 @@ bool NzShader::PostLinkage()
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzShader::Initialize()
|
||||
{
|
||||
if (!NzShaderLibrary::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise library");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzShader::Uninitialize()
|
||||
{
|
||||
NzShaderLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzShaderLibrary::LibraryMap NzShader::s_library;
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/ShaderLibrary.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzShader* NzShaderLibrary::Get(const NzString& name)
|
||||
{
|
||||
auto it = s_library.find(name);
|
||||
if (it != s_library.end())
|
||||
return it->second;
|
||||
else
|
||||
{
|
||||
NazaraError("Shader \"" + name + "\" is not present");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzShaderLibrary::Has(const NzString& name)
|
||||
{
|
||||
return s_library.find(name) != s_library.end();
|
||||
}
|
||||
|
||||
void NzShaderLibrary::Register(const NzString& name, NzShader* shader)
|
||||
{
|
||||
s_library.emplace(name, shader);
|
||||
NazaraDebug("Shader \"" + name + "\" registred");
|
||||
}
|
||||
|
||||
void NzShaderLibrary::Unregister(const NzString& name)
|
||||
{
|
||||
s_library.erase(name);
|
||||
NazaraDebug("Shader \"" + name + "\" unregistred");
|
||||
}
|
||||
|
||||
bool NzShaderLibrary::Initialize()
|
||||
{
|
||||
return true; // Que faire
|
||||
}
|
||||
|
||||
void NzShaderLibrary::Uninitialize()
|
||||
{
|
||||
for (auto it : s_library)
|
||||
NazaraWarning("Shader \"" + it.first + "\" has not been unregistred");
|
||||
|
||||
s_library.clear();
|
||||
}
|
||||
|
||||
std::unordered_map<NzString, NzShaderRef> NzShaderLibrary::s_library;
|
||||
|
|
@ -6,3 +6,21 @@
|
|||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzUberShader::~NzUberShader() = default;
|
||||
|
||||
bool NzUberShader::Initialize()
|
||||
{
|
||||
if (!NzUberShaderLibrary::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise library");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzUberShader::Uninitialize()
|
||||
{
|
||||
NzUberShaderLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzUberShaderLibrary::LibraryMap NzUberShader::s_library;
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Renderer module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Renderer/UberShaderLibrary.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
NzUberShader* NzUberShaderLibrary::Get(const NzString& name)
|
||||
{
|
||||
auto it = s_library.find(name);
|
||||
if (it != s_library.end())
|
||||
return it->second;
|
||||
else
|
||||
{
|
||||
NazaraError("UberShader \"" + name + "\" is not present");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NzUberShaderLibrary::Has(const NzString& name)
|
||||
{
|
||||
return s_library.find(name) != s_library.end();
|
||||
}
|
||||
|
||||
void NzUberShaderLibrary::Register(const NzString& name, NzUberShader* uberShader)
|
||||
{
|
||||
s_library.emplace(name, uberShader);
|
||||
NazaraDebug("UberShader \"" + name + "\" registred");
|
||||
}
|
||||
|
||||
void NzUberShaderLibrary::Unregister(const NzString& name)
|
||||
{
|
||||
s_library.erase(name);
|
||||
NazaraDebug("UberShader \"" + name + "\" unregistred");
|
||||
}
|
||||
|
||||
bool NzUberShaderLibrary::Initialize()
|
||||
{
|
||||
return true; // Que faire
|
||||
}
|
||||
|
||||
void NzUberShaderLibrary::Uninitialize()
|
||||
{
|
||||
for (auto it : s_library)
|
||||
NazaraWarning("UberShader \"" + it.first + "\" has not been unregistred");
|
||||
|
||||
s_library.clear();
|
||||
}
|
||||
|
||||
std::unordered_map<NzString, NzUberShaderRef> NzUberShaderLibrary::s_library;
|
||||
Loading…
Reference in New Issue