Added Meshes and Animations (And many more)

Added NzTexture::IsMipmappingSupported
Color::(FromTo)HSV now takes hue and saturation in degrees
Fixed Context::EnsureContext
Fixed COW thread-safety (String, Image, Matrix4)
Fixed Quatenion<T>::operator*(const Vector3<T>&)
Fixed ResourceLoader
Fixed String::Resize with a size of 0
Fixed Texture mipmapping crash
Fixed per-class thread-safety
IndexBuffer and VertexBuffer are now resources
It is now possible to use more than 8 texcoords per shader
Moved all enumerations into separate files (Core/Enums.hpp,
Utility/Enums.hpp, ..)
Removed NzContextParameters::defaultWindow
VertexDeclaration has been rewritten (New interface/COW)
This commit is contained in:
Lynix
2012-07-13 15:22:14 +02:00
parent 5f95f0b677
commit 06eda4eba9
75 changed files with 3385 additions and 861 deletions

View File

@@ -0,0 +1,81 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ANIMATION_HPP
#define NAZARA_ANIMATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <list>
#include <map>
struct NzAnimationParams
{
unsigned int endFrame = static_cast<unsigned int>(-1);
unsigned int startFrame = 0;
bool IsValid() const;
};
struct NzSequence
{
NzString name;
unsigned int firstFrame;
unsigned int lastFrame;
unsigned int framePerSecond;
};
class NzAnimation;
typedef NzResourceLoader<NzAnimation, NzAnimationParams> NzAnimationLoader;
struct NzAnimationImpl;
class NAZARA_API NzAnimation : public NzResource
{
friend class NzResourceLoader<NzAnimation, NzAnimationParams>;
public:
NzAnimation() = default;
~NzAnimation();
unsigned int AddSequence(const NzSequence& sequence);
bool Create(nzAnimationType type, unsigned int frameCount);
void Destroy();
unsigned int GetFrameCount() const;
NzSequence* GetSequence(const NzString& sequenceName);
NzSequence* GetSequence(unsigned int index);
const NzSequence* GetSequence(const NzString& sequenceName) const;
const NzSequence* GetSequence(unsigned int index) const;
unsigned int GetSequenceCount() const;
nzAnimationType GetType() const;
bool HasSequence(const NzString& sequenceName) const;
bool HasSequence(unsigned int index = 0) const;
bool IsValid() const;
bool LoadFromFile(const NzString& filePath, const NzAnimationParams& params = NzAnimationParams());
bool LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params = NzAnimationParams());
bool LoadFromStream(NzInputStream& stream, const NzAnimationParams& params = NzAnimationParams());
void RemoveSequence(const NzString& sequenceName);
void RemoveSequence(unsigned int index);
private:
NzAnimationImpl* m_impl = nullptr;
static std::list<NzAnimationLoader::MemoryLoader> s_memoryLoaders;
static std::list<NzAnimationLoader::StreamLoader> s_streamLoaders;
static std::multimap<NzString, NzAnimationLoader::LoadFileFunction> s_fileLoaders;
};
#endif // NAZARA_ANIMATION_HPP

View File

@@ -9,36 +9,9 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
enum nzBufferAccess
{
nzBufferAccess_DiscardAndWrite,
nzBufferAccess_ReadOnly,
nzBufferAccess_ReadWrite,
nzBufferAccess_WriteOnly
};
enum nzBufferStorage
{
nzBufferStorage_Hardware,
nzBufferStorage_Software,
nzBufferStorage_Max = nzBufferStorage_Software
};
enum nzBufferType
{
nzBufferType_Index,
nzBufferType_Vertex
};
enum nzBufferUsage
{
nzBufferUsage_Dynamic,
nzBufferUsage_Static
};
class NzBufferImpl;
class NzRenderer;
class NzUtility;

View File

@@ -38,4 +38,12 @@
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7
// Protège le module des accès concurrentiels
#define NAZARA_UTILITY_THREADSAFE 1
#if NAZARA_UTILITY_THREADSAFE
#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW)
#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW)
#endif
#endif // NAZARA_CONFIG_UTILITY_HPP

View File

@@ -0,0 +1,191 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ENUMS_UTILITY_HPP
#define NAZARA_ENUMS_UTILITY_HPP
enum nzAnimationType
{
nzAnimationType_Keyframe,
nzAnimationType_Skeletal,
nzAnimationType_Static
};
enum nzBufferAccess
{
nzBufferAccess_DiscardAndWrite,
nzBufferAccess_ReadOnly,
nzBufferAccess_ReadWrite,
nzBufferAccess_WriteOnly
};
enum nzBufferStorage
{
nzBufferStorage_Hardware,
nzBufferStorage_Software,
nzBufferStorage_Max = nzBufferStorage_Software
};
enum nzBufferType
{
nzBufferType_Index,
nzBufferType_Vertex
};
enum nzBufferUsage
{
nzBufferUsage_Dynamic,
nzBufferUsage_Static
};
enum nzCubemapFace
{
// L'ordre est X, -X, Y, -Y, Z, -Z
// Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap
nzCubemapFace_PositiveX = 0,
nzCubemapFace_PositiveY = 2,
nzCubemapFace_PositiveZ = 4,
nzCubemapFace_NegativeX = 1,
nzCubemapFace_NegativeY = 3,
nzCubemapFace_NegativeZ = 5
};
enum nzElementStream
{
nzElementStream_VertexData,
nzElementStream_InstancedData,
nzElementStream_Max = nzElementStream_InstancedData
};
enum nzElementType
{
nzElementType_Color,
nzElementType_Double1,
nzElementType_Double2,
nzElementType_Double3,
nzElementType_Double4,
nzElementType_Float1,
nzElementType_Float2,
nzElementType_Float3,
nzElementType_Float4
};
enum nzElementUsage
{
nzElementUsage_Diffuse,
nzElementUsage_Normal,
nzElementUsage_Position,
nzElementUsage_Tangent,
nzElementUsage_TexCoord,
nzElementUsage_Max = nzElementUsage_TexCoord
};
enum nzImageType
{
nzImageType_1D,
nzImageType_2D,
nzImageType_3D,
nzImageType_Cubemap,
nzImageType_Max = nzImageType_Cubemap
};
enum nzPixelFormat
{
nzPixelFormat_Undefined,
nzPixelFormat_BGR8, // 3*nzUInt8
nzPixelFormat_BGRA8, // 4*nzUInt8
nzPixelFormat_DXT1,
nzPixelFormat_DXT3,
nzPixelFormat_DXT5,
nzPixelFormat_L8, // 1*nzUInt8
nzPixelFormat_LA8, // 2*nzUInt8
/*
nzPixelFormat_RGB16F,
nzPixelFormat_RGB16I, // 4*nzUInt16
nzPixelFormat_RGB32F,
nzPixelFormat_RGB32I, // 4*nzUInt32
nzPixelFormat_RGBA16F,
nzPixelFormat_RGBA16I, // 4*nzUInt16
nzPixelFormat_RGBA32F,
nzPixelFormat_RGBA32I, // 4*nzUInt32
*/
nzPixelFormat_RGBA4, // 1*nzUInt16
nzPixelFormat_RGB5A1, // 1*nzUInt16
nzPixelFormat_RGB8, // 3*nzUInt8
nzPixelFormat_RGBA8, // 4*nzUInt8
/*
nzPixelFormat_Depth16,
nzPixelFormat_Depth24,
nzPixelFormat_Depth24Stencil8,
nzPixelFormat_Depth32,
nzPixelFormat_Stencil1,
nzPixelFormat_Stencil4,
nzPixelFormat_Stencil8,
nzPixelFormat_Stencil16,
*/
nzPixelFormat_Max = nzPixelFormat_RGBA8
};
enum nzPixelFlipping
{
nzPixelFlipping_Horizontally,
nzPixelFlipping_Vertically,
nzPixelFlipping_Max = nzPixelFlipping_Vertically
};
enum nzPrimitiveType
{
nzPrimitiveType_LineList,
nzPrimitiveType_LineStrip,
nzPrimitiveType_PointList,
nzPrimitiveType_TriangleList,
nzPrimitiveType_TriangleStrip,
nzPrimitiveType_TriangleFan
};
enum nzWindowCursor
{
nzWindowCursor_None,
nzWindowCursor_Default,
nzWindowCursor_Crosshair,
nzWindowCursor_Hand,
nzWindowCursor_Help,
nzWindowCursor_Move,
nzWindowCursor_Pointer,
nzWindowCursor_Progress,
nzWindowCursor_ResizeE,
nzWindowCursor_ResizeN,
nzWindowCursor_ResizeNE,
nzWindowCursor_ResizeNW,
nzWindowCursor_ResizeS,
nzWindowCursor_ResizeSE,
nzWindowCursor_ResizeSW,
nzWindowCursor_ResizeW,
nzWindowCursor_Text,
nzWindowCursor_Wait
};
enum nzWindowStyle
{
nzWindowStyle_None = 0x0,
nzWindowStyle_Fullscreen = 0x1,
nzWindowStyle_Closable = 0x2,
nzWindowStyle_Resizable = 0x4,
nzWindowStyle_Titlebar = 0x4,
nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar
};
#endif // NAZARA_ENUMS_UTILITY_HPP

View File

@@ -13,46 +13,37 @@
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/Resource.hpp>
//#include <Nazara/Utility/ThreadSafety.hpp>
#include <list>
#include <map>
enum nzCubemapFace
{
nzCubemapFace_PositiveX = 0,
nzCubemapFace_NegativeX = 1,
nzCubemapFace_PositiveY = 2,
nzCubemapFace_NegativeY = 3,
nzCubemapFace_PositiveZ = 4,
nzCubemapFace_NegativeZ = 5
};
enum nzImageType
{
nzImageType_1D,
nzImageType_2D,
nzImageType_3D,
nzImageType_Cubemap,
nzImageType_Max = nzImageType_Cubemap
};
#if NAZARA_THREADSAFETY_IMAGE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
struct NzImageParams
{
nzPixelFormat loadFormat = nzPixelFormat_Undefined;
nzUInt8 levelCount = 0;
bool IsValid() const
{
return loadFormat == nzPixelFormat_Undefined || NzPixelFormat::IsValid(loadFormat);
}
bool IsValid() const;
};
///TODO: Filtres
class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, NzImageParams>
class NzImage;
typedef NzResourceLoader<NzImage, NzImageParams> NzImageLoader;
class NAZARA_API NzImage : public NzResource
{
friend class NzResourceLoader<NzImage, NzImageParams>;
public:
struct SharedImage;
@@ -109,12 +100,6 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
NzImage& operator=(NzImage&& image);
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
static void RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile);
static void RegisterMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory);
static void RegisterStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream);
static void UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile);
static void UnregisterMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory);
static void UnregisterStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream);
struct SharedImage
{
@@ -149,6 +134,10 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
void ReleaseImage();
SharedImage* m_sharedImage;
static std::list<NzImageLoader::MemoryLoader> s_memoryLoaders;
static std::list<NzImageLoader::StreamLoader> s_streamLoaders;
static std::multimap<NzString, NzImageLoader::LoadFileFunction> s_fileLoaders;
};
#endif // NAZARA_IMAGE_HPP

View File

@@ -9,8 +9,9 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzIndexBuffer
class NAZARA_API NzIndexBuffer : public NzResource
{
public:
NzIndexBuffer(NzBuffer* buffer, unsigned int startIndex, unsigned int indexCount);

View File

@@ -0,0 +1,23 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_KEYFRAMEMESH_HPP
#define NAZARA_KEYFRAMEMESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/SubMesh.hpp>
class NzMesh;
struct NzAnimation;
class NAZARA_API NzKeyframeMesh : public NzSubMesh
{
public:
NzKeyframeMesh(const NzMesh* parent);
virtual ~NzKeyframeMesh();
};
#endif // NAZARA_KEYFRAMEMESH_HPP

View File

@@ -0,0 +1,93 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MESH_HPP
#define NAZARA_MESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <list>
#include <map>
class NzSubMesh;
class NzVertexDeclaration;
struct NzMeshParams
{
NzAnimationParams animation;
//const NzVertexDeclaration* declaration = nullptr;
bool forceSoftware = false;
bool loadAnimations = true;
bool IsValid() const;
};
class NzMesh;
typedef NzResourceLoader<NzMesh, NzMeshParams> NzMeshLoader;
struct NzMeshImpl;
class NAZARA_API NzMesh : public NzResource
{
friend class NzResourceLoader<NzMesh, NzMeshParams>;
public:
NzMesh() = default;
~NzMesh();
unsigned int AddSkin(const NzString& skin, bool setDefault = false);
nzUInt8 AddSubMesh(NzSubMesh* subMesh);
nzUInt8 AddSubMesh(const NzString& identifier, NzSubMesh* subMesh);
void Animate(unsigned int frameA, unsigned int frameB, float interpolation);
bool Create(nzAnimationType type);
void Destroy();
const NzAnimation* GetAnimation() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
NzString GetSkin(unsigned int index = 0) const;
unsigned int GetSkinCount() const;
NzSubMesh* GetSubMesh(const NzString& identifier);
NzSubMesh* GetSubMesh(nzUInt8 index);
const NzSubMesh* GetSubMesh(const NzString& identifier) const;
const NzSubMesh* GetSubMesh(nzUInt8 index) const;
nzUInt8 GetSubMeshCount() const;
unsigned int GetVertexCount() const;
bool HasAnimation() const;
bool HasSkin(unsigned int index = 0) const;
bool HasSubMesh(const NzString& identifier) const;
bool HasSubMesh(nzUInt8 index = 0) const;
bool IsAnimable() const;
bool IsValid() const;
bool LoadFromFile(const NzString& filePath, const NzMeshParams& params = NzMeshParams());
bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& params = NzMeshParams());
bool LoadFromStream(NzInputStream& stream, const NzMeshParams& params = NzMeshParams());
void RemoveSkin(unsigned int index = 0);
void RemoveSubMesh(const NzString& identifier);
void RemoveSubMesh(nzUInt8 index = 0);
bool SetAnimation(const NzAnimation* animation);
private:
NzMeshImpl* m_impl = nullptr;
static std::list<NzMeshLoader::MemoryLoader> s_memoryLoaders;
static std::list<NzMeshLoader::StreamLoader> s_streamLoaders;
static std::multimap<NzString, NzMeshLoader::LoadFileFunction> s_fileLoaders;
};
#endif // NAZARA_MESH_HPP

View File

@@ -9,55 +9,9 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <map>
enum nzPixelFormat
{
nzPixelFormat_Undefined,
nzPixelFormat_BGR8, // 3*nzUInt8
nzPixelFormat_BGRA8, // 4*nzUInt8
nzPixelFormat_DXT1,
nzPixelFormat_DXT3,
nzPixelFormat_DXT5,
nzPixelFormat_L8, // 1*nzUInt8
nzPixelFormat_LA8, // 2*nzUInt8
/*
nzPixelFormat_RGB16F,
nzPixelFormat_RGB16I, // 4*nzUInt16
nzPixelFormat_RGB32F,
nzPixelFormat_RGB32I, // 4*nzUInt32
nzPixelFormat_RGBA16F,
nzPixelFormat_RGBA16I, // 4*nzUInt16
nzPixelFormat_RGBA32F,
nzPixelFormat_RGBA32I, // 4*nzUInt32
*/
nzPixelFormat_RGBA4, // 1*nzUInt16
nzPixelFormat_RGB5A1, // 1*nzUInt16
nzPixelFormat_RGB8, // 3*nzUInt8
nzPixelFormat_RGBA8, // 4*nzUInt8
/*
nzPixelFormat_Depth16,
nzPixelFormat_Depth24,
nzPixelFormat_Depth24Stencil8,
nzPixelFormat_Depth32,
nzPixelFormat_Stencil1,
nzPixelFormat_Stencil4,
nzPixelFormat_Stencil8,
nzPixelFormat_Stencil16,
*/
nzPixelFormat_Max = nzPixelFormat_RGBA8
};
enum nzPixelFlipping
{
nzPixelFlipping_Horizontally,
nzPixelFlipping_Vertically,
nzPixelFlipping_Max = nzPixelFlipping_Vertically
};
class NzUtility;
class NzPixelFormat

View File

@@ -8,8 +8,6 @@
#define NAZARA_RESOURCELOADER_HPP
#include <Nazara/Core/String.hpp>
#include <list>
#include <map>
#include <utility>
class NzInputStream;
@@ -18,30 +16,26 @@ template<typename Type, typename Parameters>
class NzResourceLoader
{
public:
typedef bool (*IsMemoryLoadingSupportedFunction)(const void* data, unsigned int size, const Parameters& parameters);
typedef bool (*IsStreamLoadingSupportedFunction)(NzInputStream& stream, const Parameters& parameters);
typedef bool (*LoadFileFunction)(Type* resource, const NzString& filePath, const Parameters& parameters);
typedef bool (*LoadMemoryFunction)(Type* resource, const void* data, unsigned int size, const Parameters& parameters);
typedef bool (*LoadStreamFunction)(Type* resource, NzInputStream& stream, const Parameters& parameters);
using IdentifyMemoryFunction = bool (*)(const void* data, unsigned int size, const Parameters& parameters);
using IdentifyStreamFunction = bool (*)(NzInputStream& stream, const Parameters& parameters);
using LoadFileFunction = bool (*)(Type* resource, const NzString& filePath, const Parameters& parameters);
using LoadMemoryFunction = bool (*)(Type* resource, const void* data, unsigned int size, const Parameters& parameters);
using LoadStreamFunction = bool (*)(Type* resource, NzInputStream& stream, const Parameters& parameters);
protected:
static bool LoadResourceFromFile(Type* resource, const NzString& filePath, const Parameters& parameters);
static bool LoadResourceFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters);
static bool LoadResourceFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters);
static void RegisterResourceFileLoader(const NzString& extensions, LoadFileFunction loadFile);
static void RegisterResourceMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory);
static void RegisterResourceStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream);
static void UnregisterResourceFileLoader(const NzString& extensions, LoadFileFunction loadFile);
static void UnregisterResourceMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory);
static void UnregisterResourceStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream);
static bool LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters = Parameters());
static bool LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters = Parameters());
static bool LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters = Parameters());
private:
typedef std::pair<IsMemoryLoadingSupportedFunction, LoadMemoryFunction> MemoryLoader;
typedef std::pair<IsStreamLoadingSupportedFunction, LoadStreamFunction> StreamLoader;
static void RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile);
static void RegisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory);
static void RegisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream);
static std::list<MemoryLoader> s_memoryLoaders;
static std::list<StreamLoader> s_streamLoaders;
static std::multimap<NzString, LoadFileFunction> s_fileLoaders;
static void UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile);
static void UnregisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory);
static void UnregisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream);
typedef std::pair<IdentifyMemoryFunction, LoadMemoryFunction> MemoryLoader;
typedef std::pair<IdentifyStreamFunction, LoadStreamFunction> StreamLoader;
};
#include <Nazara/Utility/ResourceLoader.inl>

View File

@@ -9,7 +9,7 @@
#include <Nazara/Utility/Debug.hpp>
template<typename Type, typename Parameters>
bool NzResourceLoader<Type, Parameters>::LoadResourceFromFile(Type* resource, const NzString& filePath, const Parameters& parameters)
bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzString& filePath, const Parameters& parameters)
{
#if NAZARA_UTILITY_SAFE
if (!parameters.IsValid())
@@ -28,7 +28,7 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromFile(Type* resource, co
}
// Récupération de tous les loaders de cette extension
auto range = s_fileLoaders.equal_range(ext);
auto range = Type::s_fileLoaders.equal_range(ext);
if (range.first == range.second)
{
NazaraError("No loader found for extension \"" + ext + '"');
@@ -56,7 +56,7 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromFile(Type* resource, co
}
template<typename Type, typename Parameters>
bool NzResourceLoader<Type, Parameters>::LoadResourceFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters)
bool NzResourceLoader<Type, Parameters>::LoadFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters)
{
#if NAZARA_UTILITY_SAFE
if (!parameters.IsValid())
@@ -72,7 +72,7 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromMemory(Type* resource,
}
#endif
for (auto loader = s_memoryLoaders.rbegin(); loader != s_memoryLoaders.rend(); ++loader)
for (auto loader = Type::s_memoryLoaders.rbegin(); loader != Type::s_memoryLoaders.rend(); ++loader)
{
// Le loader supporte-t-il les données ?
if (!loader->first(data, size, parameters))
@@ -90,7 +90,7 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromMemory(Type* resource,
}
template<typename Type, typename Parameters>
bool NzResourceLoader<Type, Parameters>::LoadResourceFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters)
bool NzResourceLoader<Type, Parameters>::LoadFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters)
{
#if NAZARA_UTILITY_SAFE
if (!parameters.IsValid())
@@ -107,7 +107,7 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromStream(Type* resource,
#endif
nzUInt64 streamPos = stream.GetCursorPos();
for (auto loader = s_streamLoaders.rbegin(); loader != s_streamLoaders.rend(); ++loader)
for (auto loader = Type::s_streamLoaders.rbegin(); loader != Type::s_streamLoaders.rend(); ++loader)
{
stream.SetCursorPos(streamPos);
@@ -129,29 +129,29 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromStream(Type* resource,
}
template<typename Type, typename Parameters>
void NzResourceLoader<Type, Parameters>::RegisterResourceFileLoader(const NzString& extensions, LoadFileFunction loadFile)
void NzResourceLoader<Type, Parameters>::RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile)
{
std::vector<NzString> exts;
extensions.SplitAny(exts, " /\\*.,;|-_");
for (const NzString& ext : exts)
s_fileLoaders.insert(std::make_pair(ext, loadFile));
Type::s_fileLoaders.insert(std::make_pair(ext, loadFile));
}
template<typename Type, typename Parameters>
void NzResourceLoader<Type, Parameters>::RegisterResourceMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory)
void NzResourceLoader<Type, Parameters>::RegisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory)
{
s_memoryLoaders.push_back(std::make_pair(isLoadingSupported, loadMemory));
Type::s_memoryLoaders.push_back(std::make_pair(identifyMemory, loadMemory));
}
template<typename Type, typename Parameters>
void NzResourceLoader<Type, Parameters>::RegisterResourceStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream)
void NzResourceLoader<Type, Parameters>::RegisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream)
{
s_streamLoaders.push_back(std::make_pair(isLoadingSupported, loadStream));
Type::s_streamLoaders.push_back(std::make_pair(identifyStream, loadStream));
}
template<typename Type, typename Parameters>
void NzResourceLoader<Type, Parameters>::UnregisterResourceFileLoader(const NzString& extensions, LoadFileFunction loadFile)
void NzResourceLoader<Type, Parameters>::UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile)
{
std::vector<NzString> exts;
extensions.SplitAny(exts, " /\\*.,;|-_");
@@ -159,13 +159,13 @@ void NzResourceLoader<Type, Parameters>::UnregisterResourceFileLoader(const NzSt
for (const NzString& ext : exts)
{
// Récupération de tous les loaders de cette extension
auto range = s_fileLoaders.equal_range(ext);
auto range = Type::s_fileLoaders.equal_range(ext);
for (auto it = range.first; it != range.second; ++it)
{
if (it->second == loadFile)
{
s_fileLoaders.erase(it);
Type::s_fileLoaders.erase(it);
break;
}
}
@@ -173,19 +173,15 @@ void NzResourceLoader<Type, Parameters>::UnregisterResourceFileLoader(const NzSt
}
template<typename Type, typename Parameters>
void NzResourceLoader<Type, Parameters>::UnregisterResourceMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory)
void NzResourceLoader<Type, Parameters>::UnregisterMemoryLoader(IdentifyMemoryFunction identifyMemory, LoadMemoryFunction loadMemory)
{
s_memoryLoaders.remove(std::make_pair(isLoadingSupported, loadMemory));
Type::s_memoryLoaders.remove(std::make_pair(identifyMemory, loadMemory));
}
template<typename Type, typename Parameters>
void NzResourceLoader<Type, Parameters>::UnregisterResourceStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream)
void NzResourceLoader<Type, Parameters>::UnregisterStreamLoader(IdentifyStreamFunction identifyStream, LoadStreamFunction loadStream)
{
s_streamLoaders.remove(std::make_pair(isLoadingSupported, loadStream));
Type::s_streamLoaders.remove(std::make_pair(identifyStream, loadStream));
}
template<typename T, typename P> std::list<typename NzResourceLoader<T, P>::MemoryLoader> NzResourceLoader<T, P>::s_memoryLoaders;
template<typename T, typename P> std::list<typename NzResourceLoader<T, P>::StreamLoader> NzResourceLoader<T, P>::s_streamLoaders;
template<typename T, typename P> std::multimap<NzString, typename NzResourceLoader<T, P>::LoadFileFunction> NzResourceLoader<T, P>::s_fileLoaders;
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -0,0 +1,44 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_STATICMESH_HPP
#define NAZARA_STATICMESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/SubMesh.hpp>
class NAZARA_API NzStaticMesh final : public NzSubMesh
{
public:
NzStaticMesh(const NzMesh* parent);
NzStaticMesh(const NzMesh* parent, const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
virtual ~NzStaticMesh();
bool Create(const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
void Destroy();
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
const NzIndexBuffer* GetIndexBuffer() const;
nzPrimitiveType GetPrimitiveType() const;
const NzVertexBuffer* GetVertexBuffer() const;
const NzVertexDeclaration* GetVertexDeclaration() const;
bool IsAnimated() const;
bool IsValid() const;
void SetPrimitiveType(nzPrimitiveType primitiveType);
private:
void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation);
nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList;
const NzIndexBuffer* m_indexBuffer = nullptr;
const NzVertexBuffer* m_vertexBuffer = nullptr;
const NzVertexDeclaration* m_vertexDeclaration = nullptr;
};
#endif // NAZARA_STATICMESH_HPP

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SUBMESH_HPP
#define NAZARA_SUBMESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
class NzMesh;
class NAZARA_API NzSubMesh : public NzResource
{
friend class NzMesh;
public:
NzSubMesh(const NzMesh* parent);
virtual ~NzSubMesh();
void Animate(unsigned int frameA, unsigned int frameB, float interpolation);
virtual const NzIndexBuffer* GetIndexBuffer() const = 0;
const NzMesh* GetParent() const;
virtual nzPrimitiveType GetPrimitiveType() const = 0;
virtual const NzVertexBuffer* GetVertexBuffer() const = 0;
virtual const NzVertexDeclaration* GetVertexDeclaration() const = 0;
unsigned int GetVertexCount() const;
protected:
virtual void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation) = 0;
const NzMesh* m_parent;
};
#endif // NAZARA_SUBMESH_HPP

View File

@@ -9,8 +9,9 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzVertexBuffer
class NAZARA_API NzVertexBuffer : public NzResource
{
public:
NzVertexBuffer(NzBuffer* buffer, unsigned int startVertex, unsigned int vertexCount);

View File

@@ -6,70 +6,48 @@
#define NAZARA_VERTEXDECLARATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <vector>
enum nzElementType
{
nzElementType_Color,
nzElementType_Double1,
nzElementType_Double2,
nzElementType_Double3,
nzElementType_Double4,
nzElementType_Float1,
nzElementType_Float2,
nzElementType_Float3,
nzElementType_Float4
};
enum nzElementUsage
{
nzElementUsage_Diffuse,
nzElementUsage_Normal,
nzElementUsage_Position,
nzElementUsage_Tangent,
nzElementUsage_TexCoord
};
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
struct NzVertexElement
{
NzVertexElement() : stream(0), usageIndex(0) {}
unsigned int offset;
unsigned int stream;
unsigned int usageIndex;
unsigned int usageIndex = 0;
nzElementStream stream = nzElementStream_VertexData;
nzElementType type;
nzElementUsage usage;
};
class NAZARA_API NzVertexDeclaration
struct NzVertexDeclarationImpl;
class NAZARA_API NzVertexDeclaration : public NzResource
{
public:
struct Element
{
unsigned int offset;
unsigned int usageIndex;
nzElementType type;
nzElementUsage usage;
};
NzVertexDeclaration() = default;
~NzVertexDeclaration() = default;
NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount);
NzVertexDeclaration(const NzVertexDeclaration& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration);
~NzVertexDeclaration();
bool Create(const NzVertexElement* elements, unsigned int elementCount);
void Destroy();
const Element* GetElement(unsigned int i, unsigned int stream = 0) const;
unsigned int GetElementCount(unsigned int stream = 0) const;
unsigned int GetStreamCount() const;
unsigned int GetStride(unsigned int stream = 0) const;
const NzVertexElement* GetElement(unsigned int i) const;
const NzVertexElement* GetElement(nzElementStream stream, unsigned int i) const;
const NzVertexElement* GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const;
unsigned int GetElementCount() const;
unsigned int GetElementCount(nzElementStream stream) const;
unsigned int GetStride(nzElementStream stream) const;
bool HasStream(nzElementStream stream) const;
bool IsValid() const;
NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration);
private:
struct Stream
{
std::vector<Element> elements;
unsigned int stride;
};
std::vector<Stream> m_streams;
NzVertexDeclarationImpl* m_sharedImpl = nullptr;
};
#endif // NAZARA_VERTEXDECLARATION_HPP

View File

@@ -14,6 +14,7 @@
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/VideoMode.hpp>
#include <Nazara/Utility/WindowHandle.hpp>
@@ -24,48 +25,12 @@
#include <Nazara/Core/ThreadCondition.hpp>
#endif
class NzCursor;
class NzImage;
class NzIcon;
class NzUtility;
class NzWindowImpl;
enum nzWindowCursor
{
nzWindowCursor_None,
nzWindowCursor_Default,
nzWindowCursor_Crosshair,
nzWindowCursor_Hand,
nzWindowCursor_Help,
nzWindowCursor_Move,
nzWindowCursor_Pointer,
nzWindowCursor_Progress,
nzWindowCursor_ResizeE,
nzWindowCursor_ResizeN,
nzWindowCursor_ResizeNE,
nzWindowCursor_ResizeNW,
nzWindowCursor_ResizeS,
nzWindowCursor_ResizeSE,
nzWindowCursor_ResizeSW,
nzWindowCursor_ResizeW,
nzWindowCursor_Text,
nzWindowCursor_Wait
};
enum nzWindowStyle
{
nzWindowStyle_None = 0x0,
nzWindowStyle_Fullscreen = 0x1,
nzWindowStyle_Closable = 0x2,
nzWindowStyle_Resizable = 0x4,
nzWindowStyle_Titlebar = 0x4,
nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar
};
class NzCursor;
class NzIcon;
class NAZARA_API NzWindow : NzNonCopyable
{
friend class NzUtility;