Added resource managers

Former-commit-id: 9c071230c1e325ec672c9dfe30ee7e498baa1d08
This commit is contained in:
Lynix 2015-01-28 20:53:40 +01:00
parent 6324d21c67
commit 7a73314ef5
16 changed files with 282 additions and 56 deletions

View File

@ -17,6 +17,7 @@
#include <Nazara/Core/RefCounted.hpp> #include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
struct NzSoundBufferParams struct NzSoundBufferParams
{ {
@ -33,6 +34,7 @@ using NzSoundBufferConstRef = NzObjectRef<const NzSoundBuffer>;
using NzSoundBufferLibrary = NzObjectLibrary<NzSoundBuffer>; using NzSoundBufferLibrary = NzObjectLibrary<NzSoundBuffer>;
using NzSoundBufferListener = NzObjectListenerWrapper<NzSoundBuffer>; using NzSoundBufferListener = NzObjectListenerWrapper<NzSoundBuffer>;
using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>; using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>;
using NzSoundBufferManager = NzResourceManager<NzSoundBuffer, NzSoundBufferParams>;
using NzSoundBufferRef = NzObjectRef<NzSoundBuffer>; using NzSoundBufferRef = NzObjectRef<NzSoundBuffer>;
struct NzSoundBufferImpl; struct NzSoundBufferImpl;
@ -42,6 +44,7 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
friend NzSound; friend NzSound;
friend NzSoundBufferLibrary; friend NzSoundBufferLibrary;
friend NzSoundBufferLoader; friend NzSoundBufferLoader;
friend NzSoundBufferManager;
friend class NzAudio; friend class NzAudio;
public: public:
@ -77,6 +80,8 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
static NzSoundBufferLibrary::LibraryMap s_library; static NzSoundBufferLibrary::LibraryMap s_library;
static NzSoundBufferLoader::LoaderList s_loaders; static NzSoundBufferLoader::LoaderList s_loaders;
static NzSoundBufferManager::ManagerMap s_managerMap;
static NzSoundBufferManager::ManagerParams s_managerParameters;
}; };
#include <Nazara/Audio/SoundBuffer.inl> #include <Nazara/Audio/SoundBuffer.inl>

View File

@ -0,0 +1,43 @@
// 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_RESOURCEMANAGER_HPP
#define NAZARA_RESOURCEMANAGER_HPP
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/String.hpp>
#include <unordered_map>
template<typename Type, typename Parameters>
class NzResourceManager
{
friend Type;
public:
NzResourceManager() = delete;
~NzResourceManager() = delete;
static void Clear();
static NzObjectRef<Type> Get(const NzString& filePath);
static const Parameters& GetDefaultParameters();
static void Purge();
static void Register(const NzString& filePath, NzObjectRef<Type> resource);
static void SetDefaultParameters(const Parameters& params);
static void Unregister(const NzString& filePath);
private:
static bool Initialize();
static void Uninitialize();
using ManagerMap = std::unordered_map<NzString, NzObjectRef<Type>>;
using ManagerParams = Parameters;
};
#include <Nazara/Core/ResourceManager.inl>
#endif // NAZARA_RESOURCEMANAGER_HPP

View File

@ -0,0 +1,100 @@
// 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/File.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/Debug.hpp>
template<typename Type, typename Parameters>
void NzResourceManager<Type, Parameters>::Clear()
{
Type::s_managerMap.clear();
}
template<typename Type, typename Parameters>
NzObjectRef<Type> NzResourceManager<Type, Parameters>::Get(const NzString& filePath)
{
NzObjectRef<Type> ref;
NzString absolutePath = NzFile::AbsolutePath(filePath);
auto it = Type::s_managerMap.find(absolutePath);
if (it == Type::s_managerMap.end())
{
NzObjectRef<Type> resource = Type::New();
if (!resource)
{
NazaraError("Failed to create resource");
return ref;
}
if (!resource->LoadFromFile(absolutePath, GetDefaultParameters()))
{
NazaraError("Failed to load resource from file: " + absolutePath);
return ref;
}
NazaraDebug("Loaded resource from file " + absolutePath);
it = Type::s_managerMap.insert(std::make_pair(absolutePath, resource)).first;
}
return it->second;
}
template<typename Type, typename Parameters>
const Parameters& NzResourceManager<Type, Parameters>::GetDefaultParameters()
{
return Type::s_managerParameters;
}
template<typename Type, typename Parameters>
void NzResourceManager<Type, Parameters>::Purge()
{
auto it = Type::s_managerMap.begin();
while (it != Type::s_managerMap.end())
{
const NzObjectRef<Type>& ref = it->second;
if (ref.GetReferenceCount() == 1) // Sommes-nous les seuls à détenir la ressource ?
Type::s_managerMap.erase(it++); // Alors on la supprime
else
++it;
}
}
template<typename Type, typename Parameters>
void NzResourceManager<Type, Parameters>::Register(const NzString& filePath, NzObjectRef<Type> resource)
{
NzString absolutePath = NzFile::AbsolutePath(filePath);
Type::s_managerMap[absolutePath] = resource;
}
template<typename Type, typename Parameters>
void NzResourceManager<Type, Parameters>::SetDefaultParameters(const Parameters& params)
{
Type::s_managerParameters = params;
}
template<typename Type, typename Parameters>
void NzResourceManager<Type, Parameters>::Unregister(const NzString& filePath)
{
NzString absolutePath = NzFile::AbsolutePath(filePath);
Type::s_managerMap.erase(absolutePath);
}
template<typename Type, typename Parameters>
bool NzResourceManager<Type, Parameters>::Initialize()
{
return true;
}
template<typename Type, typename Parameters>
void NzResourceManager<Type, Parameters>::Uninitialize()
{
Clear();
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -15,6 +15,7 @@
#include <Nazara/Core/RefCounted.hpp> #include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Graphics/Enums.hpp> #include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Renderer/RenderStates.hpp> #include <Nazara/Renderer/RenderStates.hpp>
@ -42,12 +43,14 @@ using NzMaterialConstRef = NzObjectRef<const NzMaterial>;
using NzMaterialLibrary = NzObjectLibrary<NzMaterial>; using NzMaterialLibrary = NzObjectLibrary<NzMaterial>;
using NzMaterialListener = NzObjectListenerWrapper<NzMaterial>; using NzMaterialListener = NzObjectListenerWrapper<NzMaterial>;
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>; using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
using NzMaterialManager = NzResourceManager<NzMaterial, NzMaterialParams>;
using NzMaterialRef = NzObjectRef<NzMaterial>; using NzMaterialRef = NzObjectRef<NzMaterial>;
class NAZARA_API NzMaterial : public NzRefCounted, public NzResource class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
{ {
friend NzMaterialLibrary; friend NzMaterialLibrary;
friend NzMaterialLoader; friend NzMaterialLoader;
friend NzMaterialManager;
friend class NzGraphics; friend class NzGraphics;
public: public:
@ -106,37 +109,37 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
void Reset(); void Reset();
bool SetAlphaMap(const NzString& texturePath); bool SetAlphaMap(const NzString& name);
void SetAlphaMap(NzTexture* map); void SetAlphaMap(NzTexture* map);
void SetAlphaThreshold(float alphaThreshold); void SetAlphaThreshold(float alphaThreshold);
void SetAmbientColor(const NzColor& ambient); void SetAmbientColor(const NzColor& ambient);
void SetDepthFunc(nzRendererComparison depthFunc); void SetDepthFunc(nzRendererComparison depthFunc);
void SetDiffuseColor(const NzColor& diffuse); void SetDiffuseColor(const NzColor& diffuse);
bool SetDiffuseMap(const NzString& texturePath); bool SetDiffuseMap(const NzString& name);
void SetDiffuseMap(NzTexture* map); void SetDiffuseMap(NzTexture* map);
void SetDiffuseSampler(const NzTextureSampler& sampler); void SetDiffuseSampler(const NzTextureSampler& sampler);
void SetDstBlend(nzBlendFunc func); void SetDstBlend(nzBlendFunc func);
bool SetEmissiveMap(const NzString& texturePath); bool SetEmissiveMap(const NzString& name);
void SetEmissiveMap(NzTexture* map); void SetEmissiveMap(NzTexture* map);
void SetFaceCulling(nzFaceSide faceSide); void SetFaceCulling(nzFaceSide faceSide);
void SetFaceFilling(nzFaceFilling filling); void SetFaceFilling(nzFaceFilling filling);
bool SetHeightMap(const NzString& texturePath); bool SetHeightMap(const NzString& name);
void SetHeightMap(NzTexture* map); void SetHeightMap(NzTexture* map);
bool SetNormalMap(const NzString& texturePath); bool SetNormalMap(const NzString& name);
void SetNormalMap(NzTexture* map); void SetNormalMap(NzTexture* map);
void SetRenderStates(const NzRenderStates& states); void SetRenderStates(const NzRenderStates& states);
void SetShader(const NzUberShader* uberShader); void SetShader(const NzUberShader* uberShader);
bool SetShader(const NzString& uberShaderName); bool SetShader(const NzString& uberShaderName);
void SetShininess(float shininess); void SetShininess(float shininess);
void SetSpecularColor(const NzColor& specular); void SetSpecularColor(const NzColor& specular);
bool SetSpecularMap(const NzString& texturePath); bool SetSpecularMap(const NzString& name);
void SetSpecularMap(NzTexture* map); void SetSpecularMap(NzTexture* map);
void SetSpecularSampler(const NzTextureSampler& sampler); void SetSpecularSampler(const NzTextureSampler& sampler);
void SetSrcBlend(nzBlendFunc func); void SetSrcBlend(nzBlendFunc func);
NzMaterial& operator=(const NzMaterial& material); NzMaterial& operator=(const NzMaterial& material);
static NzMaterial* GetDefault(); static NzMaterialRef GetDefault();
template<typename... Args> static NzMaterialRef New(Args&&... args); template<typename... Args> static NzMaterialRef New(Args&&... args);
private: private:
@ -177,6 +180,8 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
static NzMaterialLibrary::LibraryMap s_library; static NzMaterialLibrary::LibraryMap s_library;
static NzMaterialLoader::LoaderList s_loaders; static NzMaterialLoader::LoaderList s_loaders;
static NzMaterialManager::ManagerMap s_managerMap;
static NzMaterialManager::ManagerParams s_managerParameters;
static NzMaterialRef s_defaultMaterial; static NzMaterialRef s_defaultMaterial;
}; };

View File

@ -14,6 +14,7 @@
#include <Nazara/Core/ObjectRef.hpp> #include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp> #include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Renderer/Enums.hpp> #include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/AbstractImage.hpp> #include <Nazara/Utility/AbstractImage.hpp>
#include <Nazara/Utility/CubemapParams.hpp> #include <Nazara/Utility/CubemapParams.hpp>
@ -25,6 +26,7 @@ using NzTextureConstListener = NzObjectListenerWrapper<const NzTexture>;
using NzTextureConstRef = NzObjectRef<const NzTexture>; using NzTextureConstRef = NzObjectRef<const NzTexture>;
using NzTextureLibrary = NzObjectLibrary<NzTexture>; using NzTextureLibrary = NzObjectLibrary<NzTexture>;
using NzTextureListener = NzObjectListenerWrapper<NzTexture>; using NzTextureListener = NzObjectListenerWrapper<NzTexture>;
using NzTextureManager = NzResourceManager<NzTexture, NzImageParams>;
using NzTextureRef = NzObjectRef<NzTexture>; using NzTextureRef = NzObjectRef<NzTexture>;
struct NzTextureImpl; struct NzTextureImpl;
@ -32,6 +34,7 @@ struct NzTextureImpl;
class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public NzResource, NzNonCopyable class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public NzResource, NzNonCopyable
{ {
friend NzTextureLibrary; friend NzTextureLibrary;
friend NzTextureManager;
friend class NzRenderer; friend class NzRenderer;
public: public:
@ -115,6 +118,8 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public
NzTextureImpl* m_impl = nullptr; NzTextureImpl* m_impl = nullptr;
static NzTextureLibrary::LibraryMap s_library; static NzTextureLibrary::LibraryMap s_library;
static NzTextureManager::ManagerMap s_managerMap;
static NzTextureManager::ManagerParams s_managerParameters;
}; };
#include <Nazara/Renderer/Texture.inl> #include <Nazara/Renderer/Texture.inl>

View File

@ -14,6 +14,7 @@
#include <Nazara/Core/RefCounted.hpp> #include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.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>
@ -37,6 +38,7 @@ using NzAnimationConstRef = NzObjectRef<const NzAnimation>;
using NzAnimationLibrary = NzObjectLibrary<NzAnimation>; using NzAnimationLibrary = NzObjectLibrary<NzAnimation>;
using NzAnimationListener = NzObjectListenerWrapper<NzAnimation>; using NzAnimationListener = NzObjectListenerWrapper<NzAnimation>;
using NzAnimationLoader = NzResourceLoader<NzAnimation, NzAnimationParams>; using NzAnimationLoader = NzResourceLoader<NzAnimation, NzAnimationParams>;
using NzAnimationManager = NzResourceManager<NzAnimation, NzAnimationParams>;
using NzAnimationRef = NzObjectRef<NzAnimation>; using NzAnimationRef = NzObjectRef<NzAnimation>;
struct NzAnimationImpl; struct NzAnimationImpl;
@ -45,6 +47,7 @@ class NAZARA_API NzAnimation : public NzRefCounted, public NzResource
{ {
friend NzAnimationLibrary; friend NzAnimationLibrary;
friend NzAnimationLoader; friend NzAnimationLoader;
friend NzAnimationManager;
friend class NzUtility; friend class NzUtility;
public: public:
@ -94,6 +97,8 @@ class NAZARA_API NzAnimation : public NzRefCounted, public NzResource
static NzAnimationLibrary::LibraryMap s_library; static NzAnimationLibrary::LibraryMap s_library;
static NzAnimationLoader::LoaderList s_loaders; static NzAnimationLoader::LoaderList s_loaders;
static NzAnimationManager::ManagerMap s_managerMap;
static NzAnimationManager::ManagerParams s_managerParameters;
}; };
#include <Nazara/Utility/Animation.inl> #include <Nazara/Utility/Animation.inl>

View File

@ -2,6 +2,8 @@
// This file is part of the "Nazara Engine - Utility module" // This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
///TODO: FontManager ?
#pragma once #pragma once
#ifndef NAZARA_FONT_HPP #ifndef NAZARA_FONT_HPP

View File

@ -16,6 +16,7 @@
#include <Nazara/Core/RefCounted.hpp> #include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Utility/AbstractImage.hpp> #include <Nazara/Utility/AbstractImage.hpp>
#include <Nazara/Utility/CubemapParams.hpp> #include <Nazara/Utility/CubemapParams.hpp>
#include <atomic> #include <atomic>
@ -40,12 +41,14 @@ using NzImageConstRef = NzObjectRef<const NzImage>;
using NzImageLibrary = NzObjectLibrary<NzImage>; using NzImageLibrary = NzObjectLibrary<NzImage>;
using NzImageListener = NzObjectListenerWrapper<NzImage>; using NzImageListener = NzObjectListenerWrapper<NzImage>;
using NzImageLoader = NzResourceLoader<NzImage, NzImageParams>; using NzImageLoader = NzResourceLoader<NzImage, NzImageParams>;
using NzImageManager = NzResourceManager<NzImage, NzImageParams>;
using NzImageRef = NzObjectRef<NzImage>; using NzImageRef = NzObjectRef<NzImage>;
class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public NzResource class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public NzResource
{ {
friend NzImageLibrary; friend NzImageLibrary;
friend NzImageLoader; friend NzImageLoader;
friend NzImageManager;
friend class NzUtility; friend class NzUtility;
public: public:
@ -156,6 +159,8 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public N
static NzImageLibrary::LibraryMap s_library; static NzImageLibrary::LibraryMap s_library;
static NzImageLoader::LoaderList s_loaders; static NzImageLoader::LoaderList s_loaders;
static NzImageManager::ManagerMap s_managerMap;
static NzImageManager::ManagerParams s_managerParameters;
}; };
#include <Nazara/Utility/Image.inl> #include <Nazara/Utility/Image.inl>

View File

@ -16,6 +16,7 @@
#include <Nazara/Core/RefCounted.hpp> #include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp> #include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp> #include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Math/Box.hpp> #include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Skeleton.hpp> #include <Nazara/Utility/Skeleton.hpp>
@ -59,6 +60,7 @@ using NzMeshConstRef = NzObjectRef<const NzMesh>;
using NzMeshLibrary = NzObjectLibrary<NzMesh>; using NzMeshLibrary = NzObjectLibrary<NzMesh>;
using NzMeshListener = NzObjectListenerWrapper<NzMesh>; using NzMeshListener = NzObjectListenerWrapper<NzMesh>;
using NzMeshLoader = NzResourceLoader<NzMesh, NzMeshParams>; using NzMeshLoader = NzResourceLoader<NzMesh, NzMeshParams>;
using NzMeshManager = NzResourceManager<NzMesh, NzMeshParams>;
using NzMeshRef = NzObjectRef<NzMesh>; using NzMeshRef = NzObjectRef<NzMesh>;
struct NzMeshImpl; struct NzMeshImpl;
@ -67,6 +69,7 @@ class NAZARA_API NzMesh : public NzRefCounted, public NzResource
{ {
friend NzMeshLibrary; friend NzMeshLibrary;
friend NzMeshLoader; friend NzMeshLoader;
friend NzMeshManager;
friend class NzUtility; friend class NzUtility;
public: public:
@ -137,6 +140,8 @@ class NAZARA_API NzMesh : public NzRefCounted, public NzResource
static NzMeshLibrary::LibraryMap s_library; static NzMeshLibrary::LibraryMap s_library;
static NzMeshLoader::LoaderList s_loaders; static NzMeshLoader::LoaderList s_loaders;
static NzMeshManager::ManagerMap s_managerMap;
static NzMeshManager::ManagerParams s_managerParameters;
}; };
#include <Nazara/Utility/Mesh.inl> #include <Nazara/Utility/Mesh.inl>

View File

@ -234,13 +234,22 @@ bool NzSoundBuffer::Initialize()
return false; return false;
} }
if (!NzSoundBufferManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true; return true;
} }
void NzSoundBuffer::Uninitialize() void NzSoundBuffer::Uninitialize()
{ {
NzSoundBufferManager::Uninitialize();
NzSoundBufferLibrary::Uninitialize(); NzSoundBufferLibrary::Uninitialize();
} }
NzSoundBufferLibrary::LibraryMap NzSoundBuffer::s_library; NzSoundBufferLibrary::LibraryMap NzSoundBuffer::s_library;
NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders; NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders;
NzSoundBufferManager::ManagerMap NzSoundBuffer::s_managerMap;
NzSoundBufferManager::ManagerParams NzSoundBuffer::s_managerParameters;

View File

@ -225,31 +225,21 @@ namespace
bool hasAlphaMap = false;; bool hasAlphaMap = false;;
if (parameters.material.loadAlphaMap && !mtlMat->alphaMap.IsEmpty()) if (parameters.material.loadAlphaMap && !mtlMat->alphaMap.IsEmpty())
{ {
NzTextureRef alphaMap = NzTexture::New(); if (material->SetAlphaMap(baseDir + mtlMat->alphaMap))
if (alphaMap->LoadFromFile(baseDir + mtlMat->alphaMap))
{
hasAlphaMap = true; hasAlphaMap = true;
material->SetAlphaMap(alphaMap);
}
else else
NazaraWarning("Failed to load alpha map (" + mtlMat->alphaMap + ')'); NazaraWarning("Failed to load alpha map (" + mtlMat->alphaMap + ')');
} }
if (parameters.material.loadDiffuseMap && !mtlMat->diffuseMap.IsEmpty()) if (parameters.material.loadDiffuseMap && !mtlMat->diffuseMap.IsEmpty())
{ {
NzTextureRef diffuseMap = NzTexture::New(); if (!material->SetDiffuseMap(baseDir + mtlMat->diffuseMap))
if (diffuseMap->LoadFromFile(baseDir + mtlMat->diffuseMap))
material->SetDiffuseMap(diffuseMap);
else
NazaraWarning("Failed to load diffuse map (" + mtlMat->diffuseMap + ')'); NazaraWarning("Failed to load diffuse map (" + mtlMat->diffuseMap + ')');
} }
if (parameters.material.loadSpecularMap && !mtlMat->specularMap.IsEmpty()) if (parameters.material.loadSpecularMap && !mtlMat->specularMap.IsEmpty())
{ {
NzTextureRef specularMap = NzTexture::New(); if (!material->SetSpecularMap(baseDir + mtlMat->specularMap))
if (specularMap->LoadFromFile(baseDir + mtlMat->specularMap))
material->SetSpecularMap(specularMap);
else
NazaraWarning("Failed to load specular map (" + mtlMat->specularMap + ')'); NazaraWarning("Failed to load specular map (" + mtlMat->specularMap + ')');
} }

View File

@ -406,13 +406,14 @@ void NzMaterial::Reset()
SetShader("Basic"); SetShader("Basic");
} }
bool NzMaterial::SetAlphaMap(const NzString& texturePath) bool NzMaterial::SetAlphaMap(const NzString& name)
{ {
NzTextureRef texture = NzTexture::New(); NzTextureRef texture = NzTextureLibrary::Query(name);
if (!texture->LoadFromFile(texturePath)) if (!texture)
{ {
NazaraError("Failed to load texture from \"" + texturePath + '"'); texture = NzTextureManager::Get(name);
return false; if (!texture)
return false;
} }
SetAlphaMap(texture); SetAlphaMap(texture);
@ -446,13 +447,14 @@ void NzMaterial::SetDiffuseColor(const NzColor& diffuse)
m_diffuseColor = diffuse; m_diffuseColor = diffuse;
} }
bool NzMaterial::SetDiffuseMap(const NzString& texturePath) bool NzMaterial::SetDiffuseMap(const NzString& name)
{ {
NzTextureRef texture = NzTexture::New(); NzTextureRef texture = NzTextureLibrary::Query(name);
if (!texture->LoadFromFile(texturePath)) if (!texture)
{ {
NazaraError("Failed to load texture from \"" + texturePath + '"'); texture = NzTextureManager::Get(name);
return false; if (!texture)
return false;
} }
SetDiffuseMap(texture); SetDiffuseMap(texture);
@ -476,13 +478,14 @@ void NzMaterial::SetDstBlend(nzBlendFunc func)
m_states.dstBlend = func; m_states.dstBlend = func;
} }
bool NzMaterial::SetEmissiveMap(const NzString& texturePath) bool NzMaterial::SetEmissiveMap(const NzString& name)
{ {
NzTextureRef texture = NzTexture::New(); NzTextureRef texture = NzTextureLibrary::Query(name);
if (!texture->LoadFromFile(texturePath)) if (!texture)
{ {
NazaraError("Failed to load texture from \"" + texturePath + '"'); texture = NzTextureManager::Get(name);
return false; if (!texture)
return false;
} }
SetEmissiveMap(texture); SetEmissiveMap(texture);
@ -506,13 +509,14 @@ void NzMaterial::SetFaceFilling(nzFaceFilling filling)
m_states.faceFilling = filling; m_states.faceFilling = filling;
} }
bool NzMaterial::SetHeightMap(const NzString& texturePath) bool NzMaterial::SetHeightMap(const NzString& name)
{ {
NzTextureRef texture = NzTexture::New(); NzTextureRef texture = NzTextureLibrary::Query(name);
if (!texture->LoadFromFile(texturePath)) if (!texture)
{ {
NazaraError("Failed to load texture from \"" + texturePath + '"'); texture = NzTextureManager::Get(name);
return false; if (!texture)
return false;
} }
SetHeightMap(texture); SetHeightMap(texture);
@ -526,13 +530,14 @@ void NzMaterial::SetHeightMap(NzTexture* map)
InvalidateShaders(); InvalidateShaders();
} }
bool NzMaterial::SetNormalMap(const NzString& texturePath) bool NzMaterial::SetNormalMap(const NzString& name)
{ {
NzTextureRef texture = NzTexture::New(); NzTextureRef texture = NzTextureLibrary::Query(name);
if (!texture->LoadFromFile(texturePath)) if (!texture)
{ {
NazaraError("Failed to load texture from \"" + texturePath + '"'); texture = NzTextureManager::Get(name);
return false; if (!texture)
return false;
} }
SetNormalMap(texture); SetNormalMap(texture);
@ -578,13 +583,14 @@ void NzMaterial::SetSpecularColor(const NzColor& specular)
m_specularColor = specular; m_specularColor = specular;
} }
bool NzMaterial::SetSpecularMap(const NzString& texturePath) bool NzMaterial::SetSpecularMap(const NzString& name)
{ {
NzTextureRef texture = NzTexture::New(); NzTextureRef texture = NzTextureLibrary::Query(name);
if (!texture->LoadFromFile(texturePath)) if (!texture)
{ {
NazaraError("Failed to load texture from \"" + texturePath + '"'); texture = NzTextureManager::Get(name);
return false; if (!texture)
return false;
} }
SetSpecularMap(texture); SetSpecularMap(texture);
@ -613,11 +619,10 @@ NzMaterial& NzMaterial::operator=(const NzMaterial& material)
NzResource::operator=(material); NzResource::operator=(material);
Copy(material); Copy(material);
return *this; return *this;
} }
NzMaterial* NzMaterial::GetDefault() NzMaterialRef NzMaterial::GetDefault()
{ {
return s_defaultMaterial; return s_defaultMaterial;
} }
@ -711,10 +716,11 @@ bool NzMaterial::Initialize()
return false; return false;
} }
s_defaultMaterial = NzMaterial::New(); if (!NzMaterialManager::Initialize())
s_defaultMaterial->Enable(nzRendererParameter_FaceCulling, false); {
s_defaultMaterial->SetFaceFilling(nzFaceFilling_Line); NazaraError("Failed to initialise manager");
NzMaterialLibrary::Register("Default", s_defaultMaterial); return false;
}
bool glsl140 = (NzOpenGL::GetGLSLVersion() >= 140); bool glsl140 = (NzOpenGL::GetGLSLVersion() >= 140);
@ -780,6 +786,12 @@ bool NzMaterial::Initialize()
NzUberShaderLibrary::Register("PhongLighting", uberShader); NzUberShaderLibrary::Register("PhongLighting", uberShader);
} }
// Une fois les shaders de base enregistrés, on peut créer le matériau par défaut
s_defaultMaterial = NzMaterial::New();
s_defaultMaterial->Enable(nzRendererParameter_FaceCulling, false);
s_defaultMaterial->SetFaceFilling(nzFaceFilling_Line);
NzMaterialLibrary::Register("Default", s_defaultMaterial);
return true; return true;
} }
@ -788,9 +800,12 @@ void NzMaterial::Uninitialize()
s_defaultMaterial.Reset(); s_defaultMaterial.Reset();
NzUberShaderLibrary::Unregister("PhongLighting"); NzUberShaderLibrary::Unregister("PhongLighting");
NzUberShaderLibrary::Unregister("Basic"); NzUberShaderLibrary::Unregister("Basic");
NzMaterialManager::Uninitialize();
NzMaterialLibrary::Uninitialize(); NzMaterialLibrary::Uninitialize();
} }
NzMaterialLibrary::LibraryMap NzMaterial::s_library; NzMaterialLibrary::LibraryMap NzMaterial::s_library;
NzMaterialLoader::LoaderList NzMaterial::s_loaders; NzMaterialLoader::LoaderList NzMaterial::s_loaders;
NzMaterialManager::ManagerMap NzMaterial::s_managerMap;
NzMaterialManager::ManagerParams NzMaterial::s_managerParameters;
NzMaterialRef NzMaterial::s_defaultMaterial = nullptr; NzMaterialRef NzMaterial::s_defaultMaterial = nullptr;

View File

@ -1283,12 +1283,21 @@ bool NzTexture::Initialize()
return false; return false;
} }
if (!NzTextureManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true; return true;
} }
void NzTexture::Uninitialize() void NzTexture::Uninitialize()
{ {
NzTextureManager::Uninitialize();
NzTextureLibrary::Uninitialize(); NzTextureLibrary::Uninitialize();
} }
NzTextureLibrary::LibraryMap NzTexture::s_library; NzTextureLibrary::LibraryMap NzTexture::s_library;
NzTextureManager::ManagerMap NzTexture::s_managerMap;
NzTextureManager::ManagerParams NzTexture::s_managerParameters;

View File

@ -519,13 +519,22 @@ bool NzAnimation::Initialize()
return false; return false;
} }
if (!NzAnimationManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true; return true;
} }
void NzAnimation::Uninitialize() void NzAnimation::Uninitialize()
{ {
NzAnimationManager::Uninitialize();
NzAnimationLibrary::Uninitialize(); NzAnimationLibrary::Uninitialize();
} }
NzAnimationLibrary::LibraryMap NzAnimation::s_library; NzAnimationLibrary::LibraryMap NzAnimation::s_library;
NzAnimationLoader::LoaderList NzAnimation::s_loaders; NzAnimationLoader::LoaderList NzAnimation::s_loaders;
NzAnimationManager::ManagerMap NzAnimation::s_managerMap;
NzAnimationManager::ManagerParams NzAnimation::s_managerParameters;

View File

@ -1400,14 +1400,23 @@ bool NzImage::Initialize()
return false; return false;
} }
if (!NzImageManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true; return true;
} }
void NzImage::Uninitialize() void NzImage::Uninitialize()
{ {
NzImageManager::Uninitialize();
NzImageLibrary::Uninitialize(); NzImageLibrary::Uninitialize();
} }
NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0); NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0);
NzImageLibrary::LibraryMap NzImage::s_library; NzImageLibrary::LibraryMap NzImage::s_library;
NzImageLoader::LoaderList NzImage::s_loaders; NzImageLoader::LoaderList NzImage::s_loaders;
NzImageManager::ManagerMap NzImage::s_managerMap;
NzImageManager::ManagerParams NzImage::s_managerParameters;

View File

@ -1010,13 +1010,23 @@ bool NzMesh::Initialize()
return false; return false;
} }
if (!NzMeshManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true; return true;
} }
void NzMesh::Uninitialize() void NzMesh::Uninitialize()
{ {
NzMeshManager::Uninitialize();
NzMeshLibrary::Uninitialize(); NzMeshLibrary::Uninitialize();
} }
NzMeshLibrary::LibraryMap NzMesh::s_library; NzMeshLibrary::LibraryMap NzMesh::s_library;
NzMeshLoader::LoaderList NzMesh::s_loaders; NzMeshLoader::LoaderList NzMesh::s_loaders;
NzMeshManager::ManagerMap NzMesh::s_managerMap;
NzMeshManager::ManagerParams NzMesh::s_managerParameters;