Refactor the way resources are loaded (#191)
* WIP * WIP * Font works * WIP: Only Music remains * Looks like it's working * Fix oopsie * Core/ObjectRef: Add cast functions * Update ChangeLog.md * Audio/SoundStream: Make sound stream thread-safe
This commit is contained in:
@@ -10,31 +10,15 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Audio/Enums.hpp>
|
||||
#include <Nazara/Audio/SoundEmitter.hpp>
|
||||
#include <Nazara/Audio/SoundStream.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct MusicParams : ResourceParameters
|
||||
{
|
||||
bool forceMono = false;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class Music;
|
||||
class SoundStream;
|
||||
|
||||
using MusicLoader = ResourceLoader<Music, MusicParams>;
|
||||
|
||||
struct MusicImpl;
|
||||
|
||||
class NAZARA_AUDIO_API Music : public Resource, public SoundEmitter
|
||||
{
|
||||
friend MusicLoader;
|
||||
|
||||
public:
|
||||
Music() = default;
|
||||
Music(const Music&) = delete;
|
||||
@@ -55,9 +39,9 @@ namespace Nz
|
||||
|
||||
bool IsLooping() const override;
|
||||
|
||||
bool OpenFromFile(const String& filePath, const MusicParams& params = MusicParams());
|
||||
bool OpenFromMemory(const void* data, std::size_t size, const MusicParams& params = MusicParams());
|
||||
bool OpenFromStream(Stream& stream, const MusicParams& params = MusicParams());
|
||||
bool OpenFromFile(const String& filePath, const SoundStreamParams& params = SoundStreamParams());
|
||||
bool OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams());
|
||||
bool OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams());
|
||||
|
||||
void Pause() override;
|
||||
void Play() override;
|
||||
@@ -75,8 +59,6 @@ namespace Nz
|
||||
bool FillAndQueueBuffer(unsigned int buffer);
|
||||
void MusicThread();
|
||||
void StopThread();
|
||||
|
||||
static MusicLoader::LoaderList s_loaders;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -66,16 +66,17 @@ namespace Nz
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
|
||||
bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
|
||||
|
||||
static bool IsFormatSupported(AudioFormat format);
|
||||
template<typename... Args> static SoundBufferRef New(Args&&... args);
|
||||
|
||||
SoundBuffer& operator=(const SoundBuffer&) = delete;
|
||||
SoundBuffer& operator=(SoundBuffer&&) = delete;
|
||||
|
||||
static bool IsFormatSupported(AudioFormat format);
|
||||
|
||||
static SoundBufferRef LoadFromFile(const String& filePath, const SoundBufferParams& params = SoundBufferParams());
|
||||
static SoundBufferRef LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
|
||||
static SoundBufferRef LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
|
||||
|
||||
template<typename... Args> static SoundBufferRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnSoundBufferDestroy, const SoundBuffer* /*soundBuffer*/);
|
||||
NazaraSignal(OnSoundBufferRelease, const SoundBuffer* /*soundBuffer*/);
|
||||
|
||||
@@ -10,22 +10,50 @@
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Audio/Config.hpp>
|
||||
#include <Nazara/Audio/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_AUDIO_API SoundStream
|
||||
struct SoundStreamParams : public ResourceParameters
|
||||
{
|
||||
bool forceMono = false;
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class Mutex;
|
||||
class SoundStream;
|
||||
|
||||
using SoundStreamLoader = ResourceLoader<SoundStream, SoundStreamParams>;
|
||||
using SoundStreamRef = Nz::ObjectRef<SoundStream>;
|
||||
|
||||
class NAZARA_AUDIO_API SoundStream : public RefCounted, public Resource
|
||||
{
|
||||
friend SoundStreamLoader;
|
||||
|
||||
public:
|
||||
SoundStream() = default;
|
||||
virtual ~SoundStream();
|
||||
|
||||
virtual UInt32 GetDuration() const = 0;
|
||||
virtual AudioFormat GetFormat() const = 0;
|
||||
virtual Mutex& GetMutex() = 0;
|
||||
virtual UInt64 GetSampleCount() const = 0;
|
||||
virtual UInt32 GetSampleRate() const = 0;
|
||||
|
||||
virtual UInt64 Read(void* buffer, UInt64 sampleCount) = 0;
|
||||
virtual void Seek(UInt64 offset) = 0;
|
||||
virtual UInt64 Tell() = 0;
|
||||
|
||||
static SoundStreamRef OpenFromFile(const String& filePath, const SoundStreamParams& params = SoundStreamParams());
|
||||
static SoundStreamRef OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams());
|
||||
static SoundStreamRef OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams());
|
||||
|
||||
private:
|
||||
static SoundStreamLoader::LoaderList s_loaders;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,10 @@ namespace Nz
|
||||
template<typename T> bool operator>=(const T& lhs, const ObjectRef<T>& rhs);
|
||||
template<typename T> bool operator>=(const ObjectRef<T>& lhs, const T& rhs);
|
||||
|
||||
template<typename T, typename U> ObjectRef<T> ConstRefCast(const ObjectRef<U>& ref);
|
||||
template<typename T, typename U> ObjectRef<T> DynamicRefCast(const ObjectRef<U>& ref);
|
||||
template<typename T, typename U> ObjectRef<T> ReinterpretRefCast(const ObjectRef<U>& ref);
|
||||
template<typename T, typename U> ObjectRef<T> StaticRefCast(const ObjectRef<U>& ref);
|
||||
|
||||
template<typename T> struct PointedType<ObjectRef<T>> { using type = T; };
|
||||
template<typename T> struct PointedType<ObjectRef<T> const> { using type = T; };
|
||||
|
||||
@@ -480,6 +480,60 @@ namespace Nz
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Casts an ObjectRef from one type to another using static_cast
|
||||
* \return Reference to the casted object
|
||||
*
|
||||
* \param ref The reference to convert
|
||||
*
|
||||
* \remark It is an undefined behavior to cast between incompatible types
|
||||
*/
|
||||
template<typename T, typename U>
|
||||
ObjectRef<T> ConstRefCast(const ObjectRef<U>& ref)
|
||||
{
|
||||
return ObjectRef<T>(const_cast<T*>(ref.Get()));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Casts an ObjectRef from one type to another using static_cast
|
||||
* \return Reference to the casted object
|
||||
*
|
||||
* \param ref The reference to convert
|
||||
*/
|
||||
template<typename T, typename U>
|
||||
ObjectRef<T> DynamicRefCast(const ObjectRef<U>& ref)
|
||||
{
|
||||
return ObjectRef<T>(dynamic_cast<T*>(ref.Get()));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Casts an ObjectRef from one type to another using static_cast
|
||||
* \return Reference to the casted object
|
||||
*
|
||||
* \param ref The reference to convert
|
||||
*
|
||||
* \remark It is an undefined behavior to cast between incompatible types
|
||||
*/
|
||||
template<typename T, typename U>
|
||||
ObjectRef<T> ReinterpretRefCast(const ObjectRef<U>& ref)
|
||||
{
|
||||
return ObjectRef<T>(static_cast<T*>(ref.Get()));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Casts an ObjectRef from one type to another using static_cast
|
||||
* \return Reference to the casted object
|
||||
*
|
||||
* \param ref The reference to convert
|
||||
*
|
||||
* \remark It is an undefined behavior to cast between incompatible types
|
||||
*/
|
||||
template<typename T, typename U>
|
||||
ObjectRef<T> StaticRefCast(const ObjectRef<U>& ref)
|
||||
{
|
||||
return ObjectRef<T>(static_cast<T*>(ref.Get()));
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
@@ -504,3 +558,4 @@ namespace std
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
#include "ObjectRef.hpp"
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define NAZARA_RESOURCELOADER_HPP
|
||||
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
@@ -28,19 +30,19 @@ namespace Nz
|
||||
|
||||
public:
|
||||
using ExtensionGetter = bool (*)(const String& extension);
|
||||
using FileLoader = bool (*)(Type* resource, const String& filePath, const Parameters& parameters);
|
||||
using MemoryLoader = bool (*)(Type* resource, const void* data, std::size_t size, const Parameters& parameters);
|
||||
using FileLoader = ObjectRef<Type> (*)(const String& filePath, const Parameters& parameters);
|
||||
using MemoryLoader = ObjectRef<Type> (*)(const void* data, std::size_t size, const Parameters& parameters);
|
||||
using StreamChecker = Ternary (*)(Stream& stream, const Parameters& parameters);
|
||||
using StreamLoader = bool (*)(Type* resource, Stream& stream, const Parameters& parameters);
|
||||
using StreamLoader = ObjectRef<Type> (*)(Stream& stream, const Parameters& parameters);
|
||||
|
||||
ResourceLoader() = delete;
|
||||
~ResourceLoader() = delete;
|
||||
|
||||
static bool IsExtensionSupported(const String& extension);
|
||||
|
||||
static bool LoadFromFile(Type* resource, const String& filePath, const Parameters& parameters = Parameters());
|
||||
static bool LoadFromMemory(Type* resource, const void* data, std::size_t size, const Parameters& parameters = Parameters());
|
||||
static bool LoadFromStream(Type* resource, Stream& stream, const Parameters& parameters = Parameters());
|
||||
static ObjectRef<Type> LoadFromFile(const String& filePath, const Parameters& parameters = Parameters());
|
||||
static ObjectRef<Type> LoadFromMemory(const void* data, std::size_t size, const Parameters& parameters = Parameters());
|
||||
static ObjectRef<Type> LoadFromStream(Stream& stream, const Parameters& parameters = Parameters());
|
||||
|
||||
static void RegisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader = nullptr, MemoryLoader memoryLoader = nullptr);
|
||||
static void UnregisterLoader(ExtensionGetter extensionGetter, StreamChecker checkFunc, StreamLoader streamLoader, FileLoader fileLoader = nullptr, MemoryLoader memoryLoader = nullptr);
|
||||
|
||||
@@ -53,9 +53,8 @@ namespace Nz
|
||||
* \remark Produces a NazaraError if all loaders failed or no loader was found
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const String& filePath, const Parameters& parameters)
|
||||
ObjectRef<Type> ResourceLoader<Type, Parameters>::LoadFromFile(const String& filePath, const Parameters& parameters)
|
||||
{
|
||||
NazaraAssert(resource, "Invalid resource");
|
||||
NazaraAssert(parameters.IsValid(), "Invalid parameters");
|
||||
|
||||
String path = File::NormalizePath(filePath);
|
||||
@@ -63,7 +62,7 @@ namespace Nz
|
||||
if (ext.IsEmpty())
|
||||
{
|
||||
NazaraError("Failed to get file extension from \"" + filePath + '"');
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
File file(path); // Open only if needed
|
||||
@@ -84,7 +83,7 @@ namespace Nz
|
||||
if (!file.Open(OpenMode_ReadOnly))
|
||||
{
|
||||
NazaraError("Failed to load file: unable to open \"" + filePath + '"');
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,10 +106,11 @@ namespace Nz
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (fileLoader(resource, filePath, parameters))
|
||||
ObjectRef<Type> resource = fileLoader(filePath, parameters);
|
||||
if (resource)
|
||||
{
|
||||
resource->SetFilePath(filePath);
|
||||
return true;
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -125,10 +125,11 @@ namespace Nz
|
||||
|
||||
file.SetCursorPos(0);
|
||||
|
||||
if (streamLoader(resource, file, parameters))
|
||||
ObjectRef<Type> resource = streamLoader(file, parameters);
|
||||
if (resource)
|
||||
{
|
||||
resource->SetFilePath(filePath);
|
||||
return true;
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +142,7 @@ namespace Nz
|
||||
else
|
||||
NazaraError("Failed to load file: no loader found for extension \"" + ext + '"');
|
||||
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -160,9 +161,8 @@ namespace Nz
|
||||
* \remark Produces a NazaraError if all loaders failed or no loader was found
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::LoadFromMemory(Type* resource, const void* data, std::size_t size, const Parameters& parameters)
|
||||
ObjectRef<Type> ResourceLoader<Type, Parameters>::LoadFromMemory(const void* data, std::size_t size, const Parameters& parameters)
|
||||
{
|
||||
NazaraAssert(resource, "Invalid resource");
|
||||
NazaraAssert(data, "Invalid data pointer");
|
||||
NazaraAssert(size, "No data to load");
|
||||
NazaraAssert(parameters.IsValid(), "Invalid parameters");
|
||||
@@ -195,8 +195,9 @@ namespace Nz
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (memoryLoader(resource, data, size, parameters))
|
||||
return true;
|
||||
ObjectRef<Type> resource = memoryLoader(data, size, parameters);
|
||||
if (resource)
|
||||
return resource;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -210,8 +211,9 @@ namespace Nz
|
||||
|
||||
stream.SetCursorPos(0);
|
||||
|
||||
if (streamLoader(resource, stream, parameters))
|
||||
return true;
|
||||
ObjectRef<Type> resource = streamLoader(stream, parameters);
|
||||
if (resource)
|
||||
return resource;
|
||||
}
|
||||
|
||||
if (recognized == Ternary_True)
|
||||
@@ -223,7 +225,7 @@ namespace Nz
|
||||
else
|
||||
NazaraError("Failed to load file: no loader found");
|
||||
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -241,9 +243,8 @@ namespace Nz
|
||||
* \remark Produces a NazaraError if all loaders failed or no loader was found
|
||||
*/
|
||||
template<typename Type, typename Parameters>
|
||||
bool ResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, Stream& stream, const Parameters& parameters)
|
||||
ObjectRef<Type> ResourceLoader<Type, Parameters>::LoadFromStream(Stream& stream, const Parameters& parameters)
|
||||
{
|
||||
NazaraAssert(resource, "Invalid resource");
|
||||
NazaraAssert(stream.GetCursorPos() < stream.GetSize(), "No data to load");
|
||||
NazaraAssert(parameters.IsValid(), "Invalid parameters");
|
||||
|
||||
@@ -267,8 +268,9 @@ namespace Nz
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Load of the resource
|
||||
if (streamLoader(resource, stream, parameters))
|
||||
return true;
|
||||
ObjectRef<Type> resource = streamLoader(stream, parameters);
|
||||
if (resource)
|
||||
return resource;
|
||||
|
||||
if (recognized == Ternary_True)
|
||||
NazaraWarning("Loader failed");
|
||||
@@ -279,7 +281,7 @@ namespace Nz
|
||||
else
|
||||
NazaraError("Failed to load file: no loader found");
|
||||
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -37,14 +37,8 @@ namespace Nz
|
||||
auto it = Type::s_managerMap.find(absolutePath);
|
||||
if (it == Type::s_managerMap.end())
|
||||
{
|
||||
ObjectRef<Type> resource = Type::New();
|
||||
ObjectRef<Type> resource = Type::LoadFromFile(absolutePath, GetDefaultParameters());
|
||||
if (!resource)
|
||||
{
|
||||
NazaraError("Failed to create resource");
|
||||
return ObjectRef<Type>();
|
||||
}
|
||||
|
||||
if (!resource->LoadFromFile(absolutePath, GetDefaultParameters()))
|
||||
{
|
||||
NazaraError("Failed to load resource from file: " + absolutePath);
|
||||
return ObjectRef<Type>();
|
||||
|
||||
@@ -137,10 +137,6 @@ namespace Nz
|
||||
inline bool IsShadowCastingEnabled() const;
|
||||
inline bool IsShadowReceiveEnabled() const;
|
||||
|
||||
inline bool LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
|
||||
inline bool LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
|
||||
inline bool LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());
|
||||
|
||||
void Reset();
|
||||
|
||||
void SaveToParameters(ParameterList* matData);
|
||||
@@ -180,6 +176,11 @@ namespace Nz
|
||||
|
||||
inline static MaterialRef GetDefault();
|
||||
inline static int GetTextureUnit(TextureMap textureMap);
|
||||
|
||||
static inline MaterialRef LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
|
||||
static inline MaterialRef LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
|
||||
static inline MaterialRef LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());
|
||||
|
||||
template<typename... Args> static MaterialRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
|
||||
@@ -895,43 +895,6 @@ namespace Nz
|
||||
return m_pipelineInfo.shadowReceive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from file
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param filePath Path to the file
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline bool Material::LoadFromFile(const String& filePath, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromFile(this, filePath, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from memory
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param data Raw memory
|
||||
* \param size Size of the memory
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline bool Material::LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromMemory(this, data, size, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from stream
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param stream Stream to the material
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline bool Material::LoadFromStream(Stream& stream, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromStream(this, stream, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the alpha map by name
|
||||
* \return true If successful
|
||||
@@ -1466,6 +1429,43 @@ namespace Nz
|
||||
return s_textureUnits[textureMap];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from file
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param filePath Path to the file
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline MaterialRef Material::LoadFromFile(const String& filePath, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromFile(filePath, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from memory
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param data Raw memory
|
||||
* \param size Size of the memory
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline MaterialRef Material::LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromMemory(data, size, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from stream
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param stream Stream to the material
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline MaterialRef Material::LoadFromStream(Stream& stream, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromStream(stream, params);
|
||||
}
|
||||
|
||||
inline void Material::InvalidatePipeline()
|
||||
{
|
||||
m_pipelineUpdated = false;
|
||||
|
||||
@@ -65,10 +65,6 @@ namespace Nz
|
||||
|
||||
virtual bool IsAnimated() const;
|
||||
|
||||
bool LoadFromFile(const String& filePath, const ModelParameters& params = ModelParameters());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
|
||||
bool LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters());
|
||||
|
||||
using InstancedRenderable::SetMaterial;
|
||||
bool SetMaterial(const String& subMeshName, MaterialRef material);
|
||||
bool SetMaterial(std::size_t skinIndex, const String& subMeshName, MaterialRef material);
|
||||
@@ -78,6 +74,10 @@ namespace Nz
|
||||
Model& operator=(const Model& node) = default;
|
||||
Model& operator=(Model&& node) = delete;
|
||||
|
||||
static ModelRef LoadFromFile(const String& filePath, const ModelParameters& params = ModelParameters());
|
||||
static ModelRef LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
|
||||
static ModelRef LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters());
|
||||
|
||||
template<typename... Args> static ModelRef New(Args&&... args);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -59,7 +59,6 @@ namespace Nz
|
||||
*
|
||||
* \param args Arguments for the model
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
ModelRef Model::New(Args&&... args)
|
||||
{
|
||||
|
||||
@@ -26,12 +26,10 @@ namespace Nz
|
||||
|
||||
class SkeletalModel;
|
||||
|
||||
using SkeletalModelLoader = ResourceLoader<SkeletalModel, SkeletalModelParameters>;
|
||||
using SkeletalModelRef = ObjectRef<SkeletalModel>;
|
||||
|
||||
class NAZARA_GRAPHICS_API SkeletalModel : public Model, Updatable
|
||||
{
|
||||
friend SkeletalModelLoader;
|
||||
|
||||
public:
|
||||
SkeletalModel();
|
||||
SkeletalModel(const SkeletalModel& model) = default;
|
||||
@@ -55,10 +53,6 @@ namespace Nz
|
||||
bool IsAnimated() const override;
|
||||
bool IsAnimationEnabled() const;
|
||||
|
||||
bool LoadFromFile(const String& filePath, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
bool LoadFromStream(Stream& stream, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
|
||||
bool SetAnimation(Animation* animation);
|
||||
void SetMesh(Mesh* mesh) override;
|
||||
bool SetSequence(const String& sequenceName);
|
||||
@@ -67,6 +61,8 @@ namespace Nz
|
||||
SkeletalModel& operator=(const SkeletalModel& node) = default;
|
||||
SkeletalModel& operator=(SkeletalModel&& node) = default;
|
||||
|
||||
template<typename... Args> static SkeletalModelRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
/*void Register() override;
|
||||
@@ -80,9 +76,9 @@ namespace Nz
|
||||
float m_interpolation;
|
||||
unsigned int m_currentFrame;
|
||||
unsigned int m_nextFrame;
|
||||
|
||||
static SkeletalModelLoader::LoaderList s_loaders;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/SkeletalModel.inl>
|
||||
|
||||
#endif // NAZARA_SKELETALMODEL_HPP
|
||||
|
||||
27
include/Nazara/Graphics/SkeletalModel.inl
Normal file
27
include/Nazara/Graphics/SkeletalModel.inl
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/SkeletalModel.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Creates a new SkeletalModel from the arguments
|
||||
* \return A reference to the newly created SkeletalModel
|
||||
*
|
||||
* \param args Arguments for the skeletal model
|
||||
*/
|
||||
template<typename... Args>
|
||||
SkeletalModelRef SkeletalModel::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<SkeletalModel> object(new SkeletalModel(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
@@ -38,7 +38,7 @@ namespace Nz
|
||||
public:
|
||||
Texture() = default;
|
||||
Texture(ImageType type, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||
explicit Texture(const Image& image);
|
||||
explicit Texture(const Image* image);
|
||||
Texture(const Texture&) = delete;
|
||||
Texture(Texture&&) = delete;
|
||||
~Texture();
|
||||
@@ -68,24 +68,6 @@ namespace Nz
|
||||
void InvalidateMipmaps();
|
||||
bool IsValid() const;
|
||||
|
||||
// Load
|
||||
bool LoadFromFile(const String& filePath, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
bool LoadFromImage(const Image& image, bool generateMipmaps = true);
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
|
||||
// LoadArray
|
||||
bool LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromImage(const Image& image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
|
||||
// LoadCubemap
|
||||
bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
bool LoadCubemapFromImage(const Image& image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
|
||||
bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
|
||||
// LoadFace
|
||||
bool LoadFaceFromFile(CubemapFace face, const String& filePath, const ImageParams& params = ImageParams());
|
||||
bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||
@@ -97,9 +79,9 @@ namespace Nz
|
||||
|
||||
bool SetMipmapRange(UInt8 minLevel, UInt8 maxLevel);
|
||||
|
||||
bool Update(const Image& image, UInt8 level = 0);
|
||||
bool Update(const Image& image, const Boxui& box, UInt8 level = 0);
|
||||
bool Update(const Image& image, const Rectui& rect, unsigned int z = 0, UInt8 level = 0);
|
||||
bool Update(const Image* image, UInt8 level = 0);
|
||||
bool Update(const Image* image, const Boxui& box, UInt8 level = 0);
|
||||
bool Update(const Image* image, const Rectui& rect, unsigned int z = 0, UInt8 level = 0);
|
||||
bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
@@ -113,6 +95,25 @@ namespace Nz
|
||||
static bool IsFormatSupported(PixelFormatType format);
|
||||
static bool IsMipmappingSupported();
|
||||
static bool IsTypeSupported(ImageType type);
|
||||
|
||||
// Load
|
||||
static TextureRef LoadFromFile(const String& filePath, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
static TextureRef LoadFromImage(const Image* image, bool generateMipmaps = true);
|
||||
static TextureRef LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
static TextureRef LoadFromStream(Stream& stream, const ImageParams& params = ImageParams(), bool generateMipmaps = true);
|
||||
|
||||
// LoadArray
|
||||
static TextureRef LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static TextureRef LoadArrayFromImage(const Image* image, bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static TextureRef LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static TextureRef LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
|
||||
// LoadCubemap
|
||||
static TextureRef LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
static TextureRef LoadCubemapFromImage(const Image* image, bool generateMipmaps = true, const CubemapParams& params = CubemapParams());
|
||||
static TextureRef LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
static TextureRef LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), bool generateMipmaps = true, const CubemapParams& cubemapParams = CubemapParams());
|
||||
|
||||
template<typename... Args> static TextureRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
|
||||
@@ -83,15 +83,15 @@ namespace Nz
|
||||
bool IsLoopPointInterpolationEnabled() const;
|
||||
bool IsValid() const;
|
||||
|
||||
bool LoadFromFile(const String& filePath, const AnimationParams& params = AnimationParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params = AnimationParams());
|
||||
bool LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams());
|
||||
|
||||
void RemoveSequence(const String& sequenceName);
|
||||
void RemoveSequence(UInt32 index);
|
||||
|
||||
template<typename... Args> static AnimationRef New(Args&&... args);
|
||||
|
||||
static AnimationRef LoadFromFile(const String& filePath, const AnimationParams& params = AnimationParams());
|
||||
static AnimationRef LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params = AnimationParams());
|
||||
static AnimationRef LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams());
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnAnimationDestroy, const Animation* /*animation*/);
|
||||
NazaraSignal(OnAnimationRelease, const Animation* /*animation*/);
|
||||
|
||||
@@ -76,11 +76,6 @@ namespace Nz
|
||||
bool Precache(unsigned int characterSize, UInt32 style, char32_t character) const;
|
||||
bool Precache(unsigned int characterSize, UInt32 style, const String& characterSet) const;
|
||||
|
||||
// Open
|
||||
bool OpenFromFile(const String& filePath, const FontParams& params = FontParams());
|
||||
bool OpenFromMemory(const void* data, std::size_t size, const FontParams& params = FontParams());
|
||||
bool OpenFromStream(Stream& stream, const FontParams& params = FontParams());
|
||||
|
||||
void SetAtlas(const std::shared_ptr<AbstractAtlas>& atlas);
|
||||
void SetGlyphBorder(unsigned int borderSize);
|
||||
void SetMinimumStepSize(unsigned int minimumStepSize);
|
||||
@@ -93,6 +88,10 @@ namespace Nz
|
||||
static unsigned int GetDefaultGlyphBorder();
|
||||
static unsigned int GetDefaultMinimumStepSize();
|
||||
|
||||
static FontRef OpenFromFile(const String& filePath, const FontParams& params = FontParams());
|
||||
static FontRef OpenFromMemory(const void* data, std::size_t size, const FontParams& params = FontParams());
|
||||
static FontRef OpenFromStream(Stream& stream, const FontParams& params = FontParams());
|
||||
|
||||
template<typename... Args> static FontRef New(Args&&... args);
|
||||
|
||||
static void SetDefaultAtlas(const std::shared_ptr<AbstractAtlas>& atlas);
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Nz
|
||||
|
||||
bool Convert(PixelFormatType format);
|
||||
|
||||
void Copy(const Image& source, const Boxui& srcBox, const Vector3ui& dstPos);
|
||||
void Copy(const Image* source, const Boxui& srcBox, const Vector3ui& dstPos);
|
||||
|
||||
bool Create(ImageType type, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||
void Destroy();
|
||||
@@ -93,23 +93,6 @@ namespace Nz
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
// Load
|
||||
bool LoadFromFile(const String& filePath, const ImageParams& params = ImageParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||
bool LoadFromStream(Stream& stream, const ImageParams& params = ImageParams());
|
||||
|
||||
// LoadArray
|
||||
bool LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromImage(const Image& image, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
bool LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
|
||||
// LoadCubemap
|
||||
bool LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
|
||||
bool LoadCubemapFromImage(const Image& image, const CubemapParams& params = CubemapParams());
|
||||
bool LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
|
||||
bool LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
|
||||
|
||||
// LoadFace
|
||||
bool LoadFaceFromFile(CubemapFace face, const String& filePath, const ImageParams& params = ImageParams());
|
||||
bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||
@@ -133,6 +116,24 @@ namespace Nz
|
||||
static void Copy(UInt8* destination, const UInt8* source, PixelFormatType format, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0);
|
||||
static UInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
|
||||
static UInt8 GetMaxLevel(ImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
|
||||
|
||||
// Load
|
||||
static ImageRef LoadFromFile(const String& filePath, const ImageParams& params = ImageParams());
|
||||
static ImageRef LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||
static ImageRef LoadFromStream(Stream& stream, const ImageParams& params = ImageParams());
|
||||
|
||||
// LoadArray
|
||||
static ImageRef LoadArrayFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static ImageRef LoadArrayFromImage(const Image* image, const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static ImageRef LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
static ImageRef LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
|
||||
|
||||
// LoadCubemap
|
||||
static ImageRef LoadCubemapFromFile(const String& filePath, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
|
||||
static ImageRef LoadCubemapFromImage(const Image* image, const CubemapParams& params = CubemapParams());
|
||||
static ImageRef LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
|
||||
static ImageRef LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
|
||||
|
||||
template<typename... Args> static ImageRef New(Args&&... args);
|
||||
|
||||
struct SharedImage
|
||||
|
||||
@@ -128,10 +128,6 @@ namespace Nz
|
||||
bool IsAnimable() const;
|
||||
bool IsValid() const;
|
||||
|
||||
bool LoadFromFile(const String& filePath, const MeshParams& params = MeshParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const MeshParams& params = MeshParams());
|
||||
bool LoadFromStream(Stream& stream, const MeshParams& params = MeshParams());
|
||||
|
||||
void Recenter();
|
||||
|
||||
void RemoveSubMesh(const String& identifier);
|
||||
@@ -149,6 +145,10 @@ namespace Nz
|
||||
Mesh& operator=(const Mesh&) = delete;
|
||||
Mesh& operator=(Mesh&&) = delete;
|
||||
|
||||
static MeshRef LoadFromFile(const String& filePath, const MeshParams& params = MeshParams());
|
||||
static MeshRef LoadFromMemory(const void* data, std::size_t size, const MeshParams& params = MeshParams());
|
||||
static MeshRef LoadFromStream(Stream& stream, const MeshParams& params = MeshParams());
|
||||
|
||||
template<typename... Args> static MeshRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
|
||||
Reference in New Issue
Block a user