Added resource managers
Former-commit-id: 9c071230c1e325ec672c9dfe30ee7e498baa1d08
This commit is contained in:
parent
6324d21c67
commit
7a73314ef5
|
|
@ -17,6 +17,7 @@
|
|||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
|
||||
struct NzSoundBufferParams
|
||||
{
|
||||
|
|
@ -33,6 +34,7 @@ using NzSoundBufferConstRef = NzObjectRef<const NzSoundBuffer>;
|
|||
using NzSoundBufferLibrary = NzObjectLibrary<NzSoundBuffer>;
|
||||
using NzSoundBufferListener = NzObjectListenerWrapper<NzSoundBuffer>;
|
||||
using NzSoundBufferLoader = NzResourceLoader<NzSoundBuffer, NzSoundBufferParams>;
|
||||
using NzSoundBufferManager = NzResourceManager<NzSoundBuffer, NzSoundBufferParams>;
|
||||
using NzSoundBufferRef = NzObjectRef<NzSoundBuffer>;
|
||||
|
||||
struct NzSoundBufferImpl;
|
||||
|
|
@ -42,6 +44,7 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
|
|||
friend NzSound;
|
||||
friend NzSoundBufferLibrary;
|
||||
friend NzSoundBufferLoader;
|
||||
friend NzSoundBufferManager;
|
||||
friend class NzAudio;
|
||||
|
||||
public:
|
||||
|
|
@ -77,6 +80,8 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
|
|||
|
||||
static NzSoundBufferLibrary::LibraryMap s_library;
|
||||
static NzSoundBufferLoader::LoaderList s_loaders;
|
||||
static NzSoundBufferManager::ManagerMap s_managerMap;
|
||||
static NzSoundBufferManager::ManagerParams s_managerParameters;
|
||||
};
|
||||
|
||||
#include <Nazara/Audio/SoundBuffer.inl>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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>
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
|
|
@ -42,12 +43,14 @@ using NzMaterialConstRef = NzObjectRef<const NzMaterial>;
|
|||
using NzMaterialLibrary = NzObjectLibrary<NzMaterial>;
|
||||
using NzMaterialListener = NzObjectListenerWrapper<NzMaterial>;
|
||||
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
|
||||
using NzMaterialManager = NzResourceManager<NzMaterial, NzMaterialParams>;
|
||||
using NzMaterialRef = NzObjectRef<NzMaterial>;
|
||||
|
||||
class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
|
||||
{
|
||||
friend NzMaterialLibrary;
|
||||
friend NzMaterialLoader;
|
||||
friend NzMaterialManager;
|
||||
friend class NzGraphics;
|
||||
|
||||
public:
|
||||
|
|
@ -106,37 +109,37 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
|
|||
|
||||
void Reset();
|
||||
|
||||
bool SetAlphaMap(const NzString& texturePath);
|
||||
bool SetAlphaMap(const NzString& name);
|
||||
void SetAlphaMap(NzTexture* map);
|
||||
void SetAlphaThreshold(float alphaThreshold);
|
||||
void SetAmbientColor(const NzColor& ambient);
|
||||
void SetDepthFunc(nzRendererComparison depthFunc);
|
||||
void SetDiffuseColor(const NzColor& diffuse);
|
||||
bool SetDiffuseMap(const NzString& texturePath);
|
||||
bool SetDiffuseMap(const NzString& name);
|
||||
void SetDiffuseMap(NzTexture* map);
|
||||
void SetDiffuseSampler(const NzTextureSampler& sampler);
|
||||
void SetDstBlend(nzBlendFunc func);
|
||||
bool SetEmissiveMap(const NzString& texturePath);
|
||||
bool SetEmissiveMap(const NzString& name);
|
||||
void SetEmissiveMap(NzTexture* map);
|
||||
void SetFaceCulling(nzFaceSide faceSide);
|
||||
void SetFaceFilling(nzFaceFilling filling);
|
||||
bool SetHeightMap(const NzString& texturePath);
|
||||
bool SetHeightMap(const NzString& name);
|
||||
void SetHeightMap(NzTexture* map);
|
||||
bool SetNormalMap(const NzString& texturePath);
|
||||
bool SetNormalMap(const NzString& name);
|
||||
void SetNormalMap(NzTexture* map);
|
||||
void SetRenderStates(const NzRenderStates& states);
|
||||
void SetShader(const NzUberShader* uberShader);
|
||||
bool SetShader(const NzString& uberShaderName);
|
||||
void SetShininess(float shininess);
|
||||
void SetSpecularColor(const NzColor& specular);
|
||||
bool SetSpecularMap(const NzString& texturePath);
|
||||
bool SetSpecularMap(const NzString& name);
|
||||
void SetSpecularMap(NzTexture* map);
|
||||
void SetSpecularSampler(const NzTextureSampler& sampler);
|
||||
void SetSrcBlend(nzBlendFunc func);
|
||||
|
||||
NzMaterial& operator=(const NzMaterial& material);
|
||||
|
||||
static NzMaterial* GetDefault();
|
||||
static NzMaterialRef GetDefault();
|
||||
template<typename... Args> static NzMaterialRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
|
|
@ -177,6 +180,8 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
|
|||
|
||||
static NzMaterialLibrary::LibraryMap s_library;
|
||||
static NzMaterialLoader::LoaderList s_loaders;
|
||||
static NzMaterialManager::ManagerMap s_managerMap;
|
||||
static NzMaterialManager::ManagerParams s_managerParameters;
|
||||
static NzMaterialRef s_defaultMaterial;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/CubemapParams.hpp>
|
||||
|
|
@ -25,6 +26,7 @@ using NzTextureConstListener = NzObjectListenerWrapper<const NzTexture>;
|
|||
using NzTextureConstRef = NzObjectRef<const NzTexture>;
|
||||
using NzTextureLibrary = NzObjectLibrary<NzTexture>;
|
||||
using NzTextureListener = NzObjectListenerWrapper<NzTexture>;
|
||||
using NzTextureManager = NzResourceManager<NzTexture, NzImageParams>;
|
||||
using NzTextureRef = NzObjectRef<NzTexture>;
|
||||
|
||||
struct NzTextureImpl;
|
||||
|
|
@ -32,6 +34,7 @@ struct NzTextureImpl;
|
|||
class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public NzResource, NzNonCopyable
|
||||
{
|
||||
friend NzTextureLibrary;
|
||||
friend NzTextureManager;
|
||||
friend class NzRenderer;
|
||||
|
||||
public:
|
||||
|
|
@ -115,6 +118,8 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public
|
|||
NzTextureImpl* m_impl = nullptr;
|
||||
|
||||
static NzTextureLibrary::LibraryMap s_library;
|
||||
static NzTextureManager::ManagerMap s_managerMap;
|
||||
static NzTextureManager::ManagerParams s_managerParameters;
|
||||
};
|
||||
|
||||
#include <Nazara/Renderer/Texture.inl>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/Sequence.hpp>
|
||||
|
|
@ -37,6 +38,7 @@ using NzAnimationConstRef = NzObjectRef<const NzAnimation>;
|
|||
using NzAnimationLibrary = NzObjectLibrary<NzAnimation>;
|
||||
using NzAnimationListener = NzObjectListenerWrapper<NzAnimation>;
|
||||
using NzAnimationLoader = NzResourceLoader<NzAnimation, NzAnimationParams>;
|
||||
using NzAnimationManager = NzResourceManager<NzAnimation, NzAnimationParams>;
|
||||
using NzAnimationRef = NzObjectRef<NzAnimation>;
|
||||
|
||||
struct NzAnimationImpl;
|
||||
|
|
@ -45,6 +47,7 @@ class NAZARA_API NzAnimation : public NzRefCounted, public NzResource
|
|||
{
|
||||
friend NzAnimationLibrary;
|
||||
friend NzAnimationLoader;
|
||||
friend NzAnimationManager;
|
||||
friend class NzUtility;
|
||||
|
||||
public:
|
||||
|
|
@ -94,6 +97,8 @@ class NAZARA_API NzAnimation : public NzRefCounted, public NzResource
|
|||
|
||||
static NzAnimationLibrary::LibraryMap s_library;
|
||||
static NzAnimationLoader::LoaderList s_loaders;
|
||||
static NzAnimationManager::ManagerMap s_managerMap;
|
||||
static NzAnimationManager::ManagerParams s_managerParameters;
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/Animation.inl>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
///TODO: FontManager ?
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FONT_HPP
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/CubemapParams.hpp>
|
||||
#include <atomic>
|
||||
|
|
@ -40,12 +41,14 @@ using NzImageConstRef = NzObjectRef<const NzImage>;
|
|||
using NzImageLibrary = NzObjectLibrary<NzImage>;
|
||||
using NzImageListener = NzObjectListenerWrapper<NzImage>;
|
||||
using NzImageLoader = NzResourceLoader<NzImage, NzImageParams>;
|
||||
using NzImageManager = NzResourceManager<NzImage, NzImageParams>;
|
||||
using NzImageRef = NzObjectRef<NzImage>;
|
||||
|
||||
class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public NzResource
|
||||
{
|
||||
friend NzImageLibrary;
|
||||
friend NzImageLoader;
|
||||
friend NzImageManager;
|
||||
friend class NzUtility;
|
||||
|
||||
public:
|
||||
|
|
@ -156,6 +159,8 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public N
|
|||
|
||||
static NzImageLibrary::LibraryMap s_library;
|
||||
static NzImageLoader::LoaderList s_loaders;
|
||||
static NzImageManager::ManagerMap s_managerMap;
|
||||
static NzImageManager::ManagerParams s_managerParameters;
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/Image.inl>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Utility/Skeleton.hpp>
|
||||
|
|
@ -59,6 +60,7 @@ using NzMeshConstRef = NzObjectRef<const NzMesh>;
|
|||
using NzMeshLibrary = NzObjectLibrary<NzMesh>;
|
||||
using NzMeshListener = NzObjectListenerWrapper<NzMesh>;
|
||||
using NzMeshLoader = NzResourceLoader<NzMesh, NzMeshParams>;
|
||||
using NzMeshManager = NzResourceManager<NzMesh, NzMeshParams>;
|
||||
using NzMeshRef = NzObjectRef<NzMesh>;
|
||||
|
||||
struct NzMeshImpl;
|
||||
|
|
@ -67,6 +69,7 @@ class NAZARA_API NzMesh : public NzRefCounted, public NzResource
|
|||
{
|
||||
friend NzMeshLibrary;
|
||||
friend NzMeshLoader;
|
||||
friend NzMeshManager;
|
||||
friend class NzUtility;
|
||||
|
||||
public:
|
||||
|
|
@ -137,6 +140,8 @@ class NAZARA_API NzMesh : public NzRefCounted, public NzResource
|
|||
|
||||
static NzMeshLibrary::LibraryMap s_library;
|
||||
static NzMeshLoader::LoaderList s_loaders;
|
||||
static NzMeshManager::ManagerMap s_managerMap;
|
||||
static NzMeshManager::ManagerParams s_managerParameters;
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/Mesh.inl>
|
||||
|
|
|
|||
|
|
@ -234,13 +234,22 @@ bool NzSoundBuffer::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!NzSoundBufferManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise manager");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzSoundBuffer::Uninitialize()
|
||||
{
|
||||
NzSoundBufferManager::Uninitialize();
|
||||
NzSoundBufferLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzSoundBufferLibrary::LibraryMap NzSoundBuffer::s_library;
|
||||
NzSoundBufferLoader::LoaderList NzSoundBuffer::s_loaders;
|
||||
NzSoundBufferManager::ManagerMap NzSoundBuffer::s_managerMap;
|
||||
NzSoundBufferManager::ManagerParams NzSoundBuffer::s_managerParameters;
|
||||
|
|
|
|||
|
|
@ -225,31 +225,21 @@ namespace
|
|||
bool hasAlphaMap = false;;
|
||||
if (parameters.material.loadAlphaMap && !mtlMat->alphaMap.IsEmpty())
|
||||
{
|
||||
NzTextureRef alphaMap = NzTexture::New();
|
||||
if (alphaMap->LoadFromFile(baseDir + mtlMat->alphaMap))
|
||||
{
|
||||
if (material->SetAlphaMap(baseDir + mtlMat->alphaMap))
|
||||
hasAlphaMap = true;
|
||||
material->SetAlphaMap(alphaMap);
|
||||
}
|
||||
else
|
||||
NazaraWarning("Failed to load alpha map (" + mtlMat->alphaMap + ')');
|
||||
}
|
||||
|
||||
if (parameters.material.loadDiffuseMap && !mtlMat->diffuseMap.IsEmpty())
|
||||
{
|
||||
NzTextureRef diffuseMap = NzTexture::New();
|
||||
if (diffuseMap->LoadFromFile(baseDir + mtlMat->diffuseMap))
|
||||
material->SetDiffuseMap(diffuseMap);
|
||||
else
|
||||
if (!material->SetDiffuseMap(baseDir + mtlMat->diffuseMap))
|
||||
NazaraWarning("Failed to load diffuse map (" + mtlMat->diffuseMap + ')');
|
||||
}
|
||||
|
||||
if (parameters.material.loadSpecularMap && !mtlMat->specularMap.IsEmpty())
|
||||
{
|
||||
NzTextureRef specularMap = NzTexture::New();
|
||||
if (specularMap->LoadFromFile(baseDir + mtlMat->specularMap))
|
||||
material->SetSpecularMap(specularMap);
|
||||
else
|
||||
if (!material->SetSpecularMap(baseDir + mtlMat->specularMap))
|
||||
NazaraWarning("Failed to load specular map (" + mtlMat->specularMap + ')');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -406,13 +406,14 @@ void NzMaterial::Reset()
|
|||
SetShader("Basic");
|
||||
}
|
||||
|
||||
bool NzMaterial::SetAlphaMap(const NzString& texturePath)
|
||||
bool NzMaterial::SetAlphaMap(const NzString& name)
|
||||
{
|
||||
NzTextureRef texture = NzTexture::New();
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
NzTextureRef texture = NzTextureLibrary::Query(name);
|
||||
if (!texture)
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
texture = NzTextureManager::Get(name);
|
||||
if (!texture)
|
||||
return false;
|
||||
}
|
||||
|
||||
SetAlphaMap(texture);
|
||||
|
|
@ -446,13 +447,14 @@ void NzMaterial::SetDiffuseColor(const NzColor& diffuse)
|
|||
m_diffuseColor = diffuse;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetDiffuseMap(const NzString& texturePath)
|
||||
bool NzMaterial::SetDiffuseMap(const NzString& name)
|
||||
{
|
||||
NzTextureRef texture = NzTexture::New();
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
NzTextureRef texture = NzTextureLibrary::Query(name);
|
||||
if (!texture)
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
texture = NzTextureManager::Get(name);
|
||||
if (!texture)
|
||||
return false;
|
||||
}
|
||||
|
||||
SetDiffuseMap(texture);
|
||||
|
|
@ -476,13 +478,14 @@ void NzMaterial::SetDstBlend(nzBlendFunc func)
|
|||
m_states.dstBlend = func;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetEmissiveMap(const NzString& texturePath)
|
||||
bool NzMaterial::SetEmissiveMap(const NzString& name)
|
||||
{
|
||||
NzTextureRef texture = NzTexture::New();
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
NzTextureRef texture = NzTextureLibrary::Query(name);
|
||||
if (!texture)
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
texture = NzTextureManager::Get(name);
|
||||
if (!texture)
|
||||
return false;
|
||||
}
|
||||
|
||||
SetEmissiveMap(texture);
|
||||
|
|
@ -506,13 +509,14 @@ void NzMaterial::SetFaceFilling(nzFaceFilling filling)
|
|||
m_states.faceFilling = filling;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetHeightMap(const NzString& texturePath)
|
||||
bool NzMaterial::SetHeightMap(const NzString& name)
|
||||
{
|
||||
NzTextureRef texture = NzTexture::New();
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
NzTextureRef texture = NzTextureLibrary::Query(name);
|
||||
if (!texture)
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
texture = NzTextureManager::Get(name);
|
||||
if (!texture)
|
||||
return false;
|
||||
}
|
||||
|
||||
SetHeightMap(texture);
|
||||
|
|
@ -526,13 +530,14 @@ void NzMaterial::SetHeightMap(NzTexture* map)
|
|||
InvalidateShaders();
|
||||
}
|
||||
|
||||
bool NzMaterial::SetNormalMap(const NzString& texturePath)
|
||||
bool NzMaterial::SetNormalMap(const NzString& name)
|
||||
{
|
||||
NzTextureRef texture = NzTexture::New();
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
NzTextureRef texture = NzTextureLibrary::Query(name);
|
||||
if (!texture)
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
texture = NzTextureManager::Get(name);
|
||||
if (!texture)
|
||||
return false;
|
||||
}
|
||||
|
||||
SetNormalMap(texture);
|
||||
|
|
@ -578,13 +583,14 @@ void NzMaterial::SetSpecularColor(const NzColor& specular)
|
|||
m_specularColor = specular;
|
||||
}
|
||||
|
||||
bool NzMaterial::SetSpecularMap(const NzString& texturePath)
|
||||
bool NzMaterial::SetSpecularMap(const NzString& name)
|
||||
{
|
||||
NzTextureRef texture = NzTexture::New();
|
||||
if (!texture->LoadFromFile(texturePath))
|
||||
NzTextureRef texture = NzTextureLibrary::Query(name);
|
||||
if (!texture)
|
||||
{
|
||||
NazaraError("Failed to load texture from \"" + texturePath + '"');
|
||||
return false;
|
||||
texture = NzTextureManager::Get(name);
|
||||
if (!texture)
|
||||
return false;
|
||||
}
|
||||
|
||||
SetSpecularMap(texture);
|
||||
|
|
@ -613,11 +619,10 @@ NzMaterial& NzMaterial::operator=(const NzMaterial& material)
|
|||
NzResource::operator=(material);
|
||||
|
||||
Copy(material);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzMaterial* NzMaterial::GetDefault()
|
||||
NzMaterialRef NzMaterial::GetDefault()
|
||||
{
|
||||
return s_defaultMaterial;
|
||||
}
|
||||
|
|
@ -711,10 +716,11 @@ bool NzMaterial::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
s_defaultMaterial = NzMaterial::New();
|
||||
s_defaultMaterial->Enable(nzRendererParameter_FaceCulling, false);
|
||||
s_defaultMaterial->SetFaceFilling(nzFaceFilling_Line);
|
||||
NzMaterialLibrary::Register("Default", s_defaultMaterial);
|
||||
if (!NzMaterialManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise manager");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool glsl140 = (NzOpenGL::GetGLSLVersion() >= 140);
|
||||
|
||||
|
|
@ -780,6 +786,12 @@ bool NzMaterial::Initialize()
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
@ -788,9 +800,12 @@ void NzMaterial::Uninitialize()
|
|||
s_defaultMaterial.Reset();
|
||||
NzUberShaderLibrary::Unregister("PhongLighting");
|
||||
NzUberShaderLibrary::Unregister("Basic");
|
||||
NzMaterialManager::Uninitialize();
|
||||
NzMaterialLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzMaterialLibrary::LibraryMap NzMaterial::s_library;
|
||||
NzMaterialLoader::LoaderList NzMaterial::s_loaders;
|
||||
NzMaterialManager::ManagerMap NzMaterial::s_managerMap;
|
||||
NzMaterialManager::ManagerParams NzMaterial::s_managerParameters;
|
||||
NzMaterialRef NzMaterial::s_defaultMaterial = nullptr;
|
||||
|
|
|
|||
|
|
@ -1283,12 +1283,21 @@ bool NzTexture::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!NzTextureManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise manager");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzTexture::Uninitialize()
|
||||
{
|
||||
NzTextureManager::Uninitialize();
|
||||
NzTextureLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzTextureLibrary::LibraryMap NzTexture::s_library;
|
||||
NzTextureManager::ManagerMap NzTexture::s_managerMap;
|
||||
NzTextureManager::ManagerParams NzTexture::s_managerParameters;
|
||||
|
|
|
|||
|
|
@ -519,13 +519,22 @@ bool NzAnimation::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!NzAnimationManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise manager");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzAnimation::Uninitialize()
|
||||
{
|
||||
NzAnimationManager::Uninitialize();
|
||||
NzAnimationLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzAnimationLibrary::LibraryMap NzAnimation::s_library;
|
||||
NzAnimationLoader::LoaderList NzAnimation::s_loaders;
|
||||
NzAnimationManager::ManagerMap NzAnimation::s_managerMap;
|
||||
NzAnimationManager::ManagerParams NzAnimation::s_managerParameters;
|
||||
|
|
|
|||
|
|
@ -1400,14 +1400,23 @@ bool NzImage::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!NzImageManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise manager");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzImage::Uninitialize()
|
||||
{
|
||||
NzImageManager::Uninitialize();
|
||||
NzImageLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_Undefined, 1, nullptr, 0, 0, 0);
|
||||
NzImageLibrary::LibraryMap NzImage::s_library;
|
||||
NzImageLoader::LoaderList NzImage::s_loaders;
|
||||
NzImageManager::ManagerMap NzImage::s_managerMap;
|
||||
NzImageManager::ManagerParams NzImage::s_managerParameters;
|
||||
|
|
|
|||
|
|
@ -1010,13 +1010,23 @@ bool NzMesh::Initialize()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!NzMeshManager::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialise manager");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzMesh::Uninitialize()
|
||||
{
|
||||
NzMeshManager::Uninitialize();
|
||||
NzMeshLibrary::Uninitialize();
|
||||
}
|
||||
|
||||
NzMeshLibrary::LibraryMap NzMesh::s_library;
|
||||
NzMeshLoader::LoaderList NzMesh::s_loaders;
|
||||
NzMeshManager::ManagerMap NzMesh::s_managerMap;
|
||||
NzMeshManager::ManagerParams NzMesh::s_managerParameters;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue