Replaced (Uber)ShaderLibrary by template class ObjectLibrary
Former-commit-id: d488cfd4e5e3ff31112fffebce2b7cdb86cc2e55
This commit is contained in:
39
include/Nazara/Core/ObjectLibrary.hpp
Normal file
39
include/Nazara/Core/ObjectLibrary.hpp
Normal file
@@ -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
|
||||
51
include/Nazara/Core/ObjectLibrary.inl
Normal file
51
include/Nazara/Core/ObjectLibrary.inl
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user