Added Image
Added pixel format support Added MemoryStream Added Rect Added ResourceLoader Added generic loader (bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga) Added PCX loader Added utility module initializer Fixed Config.hpp include Prerequesites.hpp now overwrites _WIN32_WINNT when defined version is less than requiered version Renderer's initialisation will implicitly initialize utility module Removed RENDERER_SINGLETON option Shaders are now resources
This commit is contained in:
parent
47cdbbcdb0
commit
9b3f4e794a
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/ModuleName/ModuleName.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/ModuleName/Config.hpp>
|
||||
#include <Nazara/ModuleName/Debug.hpp>
|
||||
|
||||
NzModuleName::NzModuleName()
|
||||
{
|
||||
|
|
@ -26,6 +27,10 @@ bool NzModuleName::Initialize()
|
|||
}
|
||||
#endif
|
||||
|
||||
// Initialisation du module
|
||||
|
||||
s_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -38,6 +43,10 @@ void NzModuleName::Uninitialize()
|
|||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Libération du module
|
||||
|
||||
s_initialized = false;
|
||||
}
|
||||
|
||||
bool NzModuleName::IsInitialized()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
project "NazaraUtility"
|
||||
|
||||
defines "STBI_NO_STDIO"
|
||||
|
||||
files
|
||||
{
|
||||
"../include/Nazara/Utility/**.hpp",
|
||||
|
|
|
|||
|
|
@ -28,11 +28,13 @@ class NAZARA_API NzByteArray : public NzHashable
|
|||
NzByteArray(SharedArray* sharedArray);
|
||||
~NzByteArray();
|
||||
|
||||
unsigned int Capacity() const;
|
||||
NzByteArray& Append(const NzByteArray& byteArray);
|
||||
|
||||
void Clear();
|
||||
|
||||
const nzUInt8* GetBuffer() const;
|
||||
nzUInt8* GetBuffer();
|
||||
unsigned int GetCapacity() const;
|
||||
const nzUInt8* GetConstBuffer() const;
|
||||
unsigned int GetSize() const;
|
||||
|
||||
NzByteArray& Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength);
|
||||
|
|
@ -42,10 +44,10 @@ class NAZARA_API NzByteArray : public NzHashable
|
|||
|
||||
void Reserve(unsigned int bufferSize);
|
||||
|
||||
NzByteArray& Resize(int size, nzUInt8 byte = '\0');
|
||||
NzByteArray Resized(int size, nzUInt8 byte = '\0') const;
|
||||
NzByteArray& Resize(int size, nzUInt8 byte = 0);
|
||||
NzByteArray Resized(int size, nzUInt8 byte = 0) const;
|
||||
|
||||
NzByteArray SubArray(int startPos, int endPos = -1) const;
|
||||
NzByteArray Subarray(int startPos, int endPos = -1) const;
|
||||
|
||||
void Swap(NzByteArray& byteArray);
|
||||
|
||||
|
|
@ -88,15 +90,15 @@ class NAZARA_API NzByteArray : public NzHashable
|
|||
{
|
||||
}
|
||||
|
||||
SharedArray(unsigned int bufferSize, unsigned int arraySize, unsigned short referenceCount, nzUInt8* ptr) :
|
||||
allocatedSize(bufferSize),
|
||||
SharedArray(unsigned short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) :
|
||||
capacity(bufferSize),
|
||||
size(arraySize),
|
||||
refCount(referenceCount),
|
||||
buffer(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int allocatedSize;
|
||||
unsigned int capacity;
|
||||
unsigned int size;
|
||||
unsigned short refCount;
|
||||
nzUInt8* buffer;
|
||||
|
|
@ -105,6 +107,7 @@ class NAZARA_API NzByteArray : public NzHashable
|
|||
};
|
||||
|
||||
static SharedArray emptyArray;
|
||||
static unsigned int npos;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
|
|
|
|||
|
|
@ -14,8 +14,12 @@ class NzInputStream
|
|||
public:
|
||||
virtual ~NzInputStream();
|
||||
|
||||
virtual bool EndOfFile() const = 0;
|
||||
virtual nzUInt64 GetCursorPos() const = 0;
|
||||
virtual nzUInt64 GetSize() const = 0;
|
||||
|
||||
virtual std::size_t Read(void* buffer, std::size_t size) = 0;
|
||||
|
||||
virtual bool SetCursorPos(nzUInt64 offset) = 0;
|
||||
};
|
||||
|
||||
#endif // NAZARA_INPUTSTREAM_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
// 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_MEMORYSTREAM_HPP
|
||||
#define NAZARA_MEMORYSTREAM_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
|
||||
class NAZARA_API NzMemoryStream : public NzInputStream
|
||||
{
|
||||
public:
|
||||
NzMemoryStream(const void* ptr, nzUInt64 size);
|
||||
~NzMemoryStream();
|
||||
|
||||
bool EndOfStream() const;
|
||||
|
||||
nzUInt64 GetCursorPos() const;
|
||||
nzUInt64 GetSize() const;
|
||||
|
||||
std::size_t Read(void* buffer, std::size_t size);
|
||||
|
||||
bool SetCursorPos(nzUInt64 offset);
|
||||
|
||||
private:
|
||||
const nzUInt8* m_ptr;
|
||||
nzUInt64 m_pos;
|
||||
nzUInt64 m_size;
|
||||
};
|
||||
|
||||
#endif // NAZARA_MEMORYSTREAM_HPP
|
||||
|
|
@ -284,14 +284,14 @@ class NAZARA_API NzString : public NzHashable
|
|||
}
|
||||
|
||||
SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) :
|
||||
allocatedSize(bufferSize),
|
||||
capacity(bufferSize),
|
||||
size(stringSize),
|
||||
string(str),
|
||||
refCount(referenceCount)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int allocatedSize;
|
||||
unsigned int capacity;
|
||||
unsigned int size;
|
||||
char* string;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#define NAZARA_BASIC_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
#ifndef M_PI
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <cmath>
|
||||
|
|
|
|||
|
|
@ -106,8 +106,7 @@ template<typename T> class NzMatrix4
|
|||
T m31, m32, m33, m34;
|
||||
T m41, m42, m43, m44;
|
||||
|
||||
unsigned int refCount;
|
||||
|
||||
unsigned short refCount;
|
||||
NazaraMutex(mutex)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
|
@ -267,10 +268,7 @@ void NzMatrix4<T>::Set(const NzMatrix4& matrix)
|
|||
template<typename T>
|
||||
void NzMatrix4<T>::Set(NzMatrix4&& matrix)
|
||||
{
|
||||
ReleaseMatrix();
|
||||
|
||||
m_sharedMatrix = matrix.m_sharedMatrix;
|
||||
matrix.m_sharedMatrix = nullptr;
|
||||
std::swap(m_sharedMatrix, matrix.m_sharedMatrix);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Basic.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
// 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_RECT_HPP
|
||||
#define NAZARA_RECT_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
template<typename T>
|
||||
class NzRect
|
||||
{
|
||||
public:
|
||||
NzRect();
|
||||
NzRect(T X, T Y, T Width, T Height);
|
||||
NzRect(T rect[4]);
|
||||
template<typename U> explicit NzRect(const NzRect<U>& rect);
|
||||
NzRect(const NzRect& rect) = default;
|
||||
~NzRect() = default;
|
||||
|
||||
bool Contains(T X, T Y) const;
|
||||
bool Contains(const NzVector2<T>& point) const;
|
||||
bool Contains(const NzRect& rect) const;
|
||||
|
||||
void ExtendTo(const NzVector2<T>& point);
|
||||
void ExtendTo(const NzRect& rect);
|
||||
|
||||
bool Intersect(const NzRect& rect) const;
|
||||
bool Intersect(const NzRect& rect, NzRect& intersection) const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
|
||||
T x, y, width, height;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const NzRect<T>& vec);
|
||||
|
||||
typedef NzRect<double> NzRectd;
|
||||
typedef NzRect<float> NzRectf;
|
||||
typedef NzRect<int> NzRecti;
|
||||
typedef NzRect<unsigned int> NzRectui;
|
||||
|
||||
#include <Nazara/Math/Rect.inl>
|
||||
|
||||
#endif // NAZARA_RECT_HPP
|
||||
|
|
@ -0,0 +1,162 @@
|
|||
// 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
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::NzRect()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::NzRect(T X, T Y, T Width, T Height) :
|
||||
x(X),
|
||||
y(Y),
|
||||
width(Width),
|
||||
height(Height)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::NzRect(T vec[4]) :
|
||||
x(vec[0]),
|
||||
y(vec[1]),
|
||||
width(vec[2]),
|
||||
height(vec[3])
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
NzRect<T>::NzRect(const NzRect<U>& rect) :
|
||||
x(static_cast<T>(rect.x)),
|
||||
y(static_cast<T>(rect.y)),
|
||||
width(static_cast<T>(rect.width)),
|
||||
height(static_cast<T>(rect.height))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::Contains(T X, T Y) const
|
||||
{
|
||||
return X >= x && X < x+width &&
|
||||
Y >= y && Y < y+height;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::Contains(const NzVector2<T>& point) const
|
||||
{
|
||||
return Contains(point.x, point.y);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::Contains(const NzRect<T>& rect) const
|
||||
{
|
||||
return Contains(rect.x, rect.y) &&
|
||||
Contains(rect.x + rect.width, rect.y + rect.height);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzRect<T>::ExtendTo(const NzVector2<T>& point)
|
||||
{
|
||||
x = std::min(x, point.x);
|
||||
y = std::min(y, point.y);
|
||||
width = std::max(x+width, point.x)-x;
|
||||
height = std::max(x+width, point.x)-y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzRect<T>::ExtendTo(const NzRect& rect)
|
||||
{
|
||||
x = std::min(x, rect.x);
|
||||
y = std::min(y, rect.y);
|
||||
width = std::max(x+width, rect.x+rect.width)-x;
|
||||
height = std::max(x+width, rect.x+rect.height)-y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::Intersect(const NzRect& rect) const
|
||||
{
|
||||
NzRect intersection; // Optimisé par le compilateur
|
||||
return Intersect(rect, intersection);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
|
||||
{
|
||||
T left = std::max(x, rect.x);
|
||||
T right = std::min(x+width, rect.x+rect.width);
|
||||
T top = std::max(y, rect.y);
|
||||
T bottom = std::min(y+height, rect.y+rect.height);
|
||||
|
||||
if (left < right && top < bottom)
|
||||
{
|
||||
intersection.x = left;
|
||||
intersection.y = top;
|
||||
intersection.width = right-left;
|
||||
intersection.height = top-bottom;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRect<T>::IsValid() const
|
||||
{
|
||||
return width > 0 && height > 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzString NzRect<T>::ToString() const
|
||||
{
|
||||
NzStringStream ss;
|
||||
|
||||
return ss << "Rect(" << x << ", " << y << ", " << width << ", " << height << ')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzRect<T>::operator NzString() const
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& NzRect<T>::operator[](unsigned int i)
|
||||
{
|
||||
if (i >= 4)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzRect<T>::operator[](unsigned int i) const
|
||||
{
|
||||
if (i >= 4)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const NzRect<T>& rect)
|
||||
{
|
||||
return out << rect.ToString();
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -74,6 +74,7 @@ template<typename T> NzVector2<T> operator/(T scale, const NzVector2<T>& vec);
|
|||
typedef NzVector2<double> NzVector2d;
|
||||
typedef NzVector2<float> NzVector2f;
|
||||
typedef NzVector2<int> NzVector2i;
|
||||
typedef NzVector2<unsigned int> NzVector2ui;
|
||||
|
||||
#include <Nazara/Math/Vector2.inl>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,15 +5,17 @@
|
|||
#ifndef NAZARA_PREREQUESITES_HPP
|
||||
#define NAZARA_PREREQUESITES_HPP
|
||||
|
||||
// Version du moteur
|
||||
#define NAZARA_VERSION_MAJOR 0
|
||||
#define NAZARA_VERSION_MINOR 1
|
||||
|
||||
// (Commenté en attendant GCC 4.7)
|
||||
/*#if __cplusplus < 201103L
|
||||
#error Nazara requires a C++11 compliant compiler
|
||||
#endif*/
|
||||
|
||||
// Version du moteur
|
||||
#define NAZARA_VERSION_MAJOR 0
|
||||
#define NAZARA_VERSION_MINOR 1
|
||||
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
|
||||
///TODO: Rajouter des tests d'identification de compilateurs
|
||||
#if defined(_MSC_VER)
|
||||
#define NAZARA_COMPILER_MSVC
|
||||
|
|
@ -59,11 +61,25 @@
|
|||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32_WINNT
|
||||
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
|
||||
#define _WIN32_WINNT 0x0600 // Version de Windows minimale : Vista
|
||||
#if NAZARA_CORE_WINDOWS_VISTA
|
||||
// Version de Windows minimale : Vista
|
||||
#if defined(_WIN32_WINNT)
|
||||
#if _WIN32_WINNT < 0x0600
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#endif
|
||||
#else
|
||||
#define _WIN32_WINNT 0x0501 // Version de Windows minimale : XP
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#endif
|
||||
#else
|
||||
// Version de Windows minimale : XP
|
||||
#if defined(_WIN32_WINNT)
|
||||
#if _WIN32_WINNT < 0x0501
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
#else
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#define NAZARA_BUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
|
||||
enum nzBufferLock
|
||||
|
|
@ -39,7 +40,7 @@ enum nzBufferUsage
|
|||
class NzBufferImpl;
|
||||
class NzRenderer;
|
||||
|
||||
class NAZARA_API NzBuffer : public NzResource
|
||||
class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
|
||||
{
|
||||
friend class NzRenderer;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,4 @@
|
|||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_RENDERER_SAFE 1
|
||||
|
||||
// Fait en sorte que le Renderer soit un singleton plutôt qu'une instance globale
|
||||
#define NAZARA_RENDERER_SINGLETON 0
|
||||
|
||||
#endif // NAZARA_CONFIG_MODULENAME_HPP
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#define NAZARA_RENDERTARGET_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/RenderTargetParameters.hpp>
|
||||
|
||||
class NzRenderer;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
|
|
|
|||
|
|
@ -44,9 +44,10 @@ enum nzRendererClear
|
|||
nzRendererClear_Stencil = 0x04
|
||||
};
|
||||
|
||||
class NzRenderTarget;
|
||||
class NzIndexBuffer;
|
||||
class NzRenderTarget;
|
||||
class NzShader;
|
||||
class NzUtility;
|
||||
class NzVertexBuffer;
|
||||
class NzVertexDeclaration;
|
||||
|
||||
|
|
@ -79,23 +80,23 @@ class NAZARA_API NzRenderer
|
|||
|
||||
void Uninitialize();
|
||||
|
||||
#if NAZARA_RENDERER_SINGLETON
|
||||
static void Destroy();
|
||||
#endif
|
||||
static NzRenderer* Instance();
|
||||
static bool IsInitialized();
|
||||
|
||||
private:
|
||||
bool UpdateVertexBuffer();
|
||||
|
||||
static NzRenderer* s_instance;
|
||||
|
||||
const NzIndexBuffer* m_indexBuffer;
|
||||
NzRenderTarget* m_target;
|
||||
NzShader* m_shader;
|
||||
NzUtility* m_utilityModule;
|
||||
const NzVertexBuffer* m_vertexBuffer;
|
||||
const NzVertexDeclaration* m_vertexDeclaration;
|
||||
bool m_capabilities[nzRendererCap_Count];
|
||||
bool m_vertexBufferUpdated;
|
||||
|
||||
static NzRenderer* s_instance;
|
||||
static bool s_initialized;
|
||||
};
|
||||
|
||||
#endif // NAZARA_RENDERER_HPP
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
|
||||
enum nzShaderLanguage
|
||||
{
|
||||
|
|
@ -31,7 +33,7 @@ enum nzShaderType
|
|||
class NzRenderer;
|
||||
class NzShaderImpl;
|
||||
|
||||
class NAZARA_API NzShader
|
||||
class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||
{
|
||||
friend class NzRenderer;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_UTILITY_SAFE 1
|
||||
|
||||
// Fait tourner chaque fenêtre dans un thread séparé
|
||||
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
|
||||
#define NAZARA_UTILITY_THREADED_WINDOW 1
|
||||
|
||||
#endif // NAZARA_CONFIG_UTILITY_HPP
|
||||
|
|
|
|||
|
|
@ -0,0 +1,135 @@
|
|||
// 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_IMAGE_HPP
|
||||
#define NAZARA_IMAGE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Utility/ResourceLoader.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
//#include <Nazara/Utility/ThreadSafety.hpp>
|
||||
|
||||
enum nzCubemapFace
|
||||
{
|
||||
nzCubemapFace_PositiveX,
|
||||
nzCubemapFace_NegativeX,
|
||||
nzCubemapFace_PositiveY,
|
||||
nzCubemapFace_NegativeY,
|
||||
nzCubemapFace_PositiveZ,
|
||||
nzCubemapFace_NegativeZ
|
||||
};
|
||||
|
||||
enum nzImageType
|
||||
{
|
||||
nzImageType_1D,
|
||||
nzImageType_2D,
|
||||
nzImageType_3D,
|
||||
nzImageType_Cubemap
|
||||
};
|
||||
|
||||
struct NzImageParams
|
||||
{
|
||||
bool IsValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
///TODO: Filtres
|
||||
///TODO: Mipmaps
|
||||
|
||||
class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, NzImageParams>
|
||||
{
|
||||
public:
|
||||
struct SharedImage;
|
||||
|
||||
NzImage();
|
||||
NzImage(const NzImage& image);
|
||||
NzImage(NzImage&& image);
|
||||
NzImage(SharedImage* sharedImage);
|
||||
~NzImage();
|
||||
|
||||
bool Copy(const NzImage& source, const NzRectui& srcRect, const NzVector2ui& dstPos);
|
||||
bool CopyToFace(nzCubemapFace face, const NzImage& source, const NzRectui& srcRect, const NzVector2ui& dstPos);
|
||||
|
||||
bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height = 1, unsigned int depth = 1);
|
||||
void Destroy();
|
||||
|
||||
nzUInt8 GetBPP() const;
|
||||
const nzUInt8* GetConstPixels() const;
|
||||
unsigned int GetDepth() const;
|
||||
nzPixelFormat GetFormat() const;
|
||||
unsigned int GetHeight() const;
|
||||
nzUInt8* GetPixels();
|
||||
unsigned int GetSize() const;
|
||||
nzImageType GetType() const;
|
||||
unsigned int GetWidth() const;
|
||||
|
||||
bool IsCompressed() const;
|
||||
bool IsCubemap() const;
|
||||
bool IsValid() const;
|
||||
|
||||
bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams());
|
||||
bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams());
|
||||
|
||||
bool Update(const nzUInt8* pixels);
|
||||
bool Update(const nzUInt8* pixels, const NzRectui& rect);
|
||||
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels);
|
||||
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect);
|
||||
|
||||
NzImage& operator=(const NzImage& image);
|
||||
NzImage& operator=(NzImage&& image);
|
||||
|
||||
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
|
||||
{
|
||||
SharedImage() : // Vivement GCC 4.7 sur Windows
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
SharedImage(unsigned short RefCount, nzImageType Type, nzPixelFormat Format, nzUInt8* Pixels, unsigned int Width, unsigned int Height = 1, unsigned int Depth = 1) :
|
||||
type(Type),
|
||||
format(Format),
|
||||
pixels(Pixels),
|
||||
depth(Depth),
|
||||
height(Height),
|
||||
width(Width),
|
||||
refCount(RefCount)
|
||||
{
|
||||
}
|
||||
|
||||
nzImageType type;
|
||||
nzPixelFormat format;
|
||||
nzUInt8* pixels;
|
||||
unsigned int depth;
|
||||
unsigned int height;
|
||||
unsigned int width;
|
||||
|
||||
unsigned short refCount;
|
||||
NazaraMutex(mutex)
|
||||
};
|
||||
|
||||
static SharedImage emptyImage;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
void ReleaseImage();
|
||||
|
||||
SharedImage* m_sharedImage;
|
||||
};
|
||||
|
||||
#endif // NAZARA_IMAGE_HPP
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// 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_PIXELFORMAT_HPP
|
||||
#define NAZARA_PIXELFORMAT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
enum nzPixelFormat
|
||||
{
|
||||
nzPixelFormat_Undefined,
|
||||
|
||||
nzPixelFormat_B8G8R8,
|
||||
nzPixelFormat_B8G8R8A8,
|
||||
nzPixelFormat_DXT1,
|
||||
nzPixelFormat_DXT3,
|
||||
nzPixelFormat_DXT5,
|
||||
nzPixelFormat_L8,
|
||||
nzPixelFormat_L8A8,
|
||||
nzPixelFormat_R4G4A4A4,
|
||||
nzPixelFormat_R5G5A5A1,
|
||||
nzPixelFormat_R8,
|
||||
nzPixelFormat_R8G8,
|
||||
nzPixelFormat_R8G8B8,
|
||||
nzPixelFormat_R8G8B8A8
|
||||
};
|
||||
|
||||
class NzPixelFormat
|
||||
{
|
||||
public:
|
||||
static nzUInt8 GetBPP(nzPixelFormat format);
|
||||
static bool IsCompressed(nzPixelFormat format);
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/PixelFormat.inl>
|
||||
|
||||
#endif // NAZARA_PIXELFORMAT_HPP
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
// 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
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case nzPixelFormat_Undefined:
|
||||
return 0;
|
||||
|
||||
case nzPixelFormat_B8G8R8:
|
||||
return 3;
|
||||
|
||||
case nzPixelFormat_B8G8R8A8:
|
||||
return 4;
|
||||
|
||||
case nzPixelFormat_DXT1:
|
||||
return 1;
|
||||
|
||||
case nzPixelFormat_DXT3:
|
||||
return 2;
|
||||
|
||||
case nzPixelFormat_DXT5:
|
||||
return 2;
|
||||
|
||||
case nzPixelFormat_L8:
|
||||
return 1;
|
||||
|
||||
case nzPixelFormat_L8A8:
|
||||
return 2;
|
||||
|
||||
case nzPixelFormat_R4G4A4A4:
|
||||
return 2;
|
||||
|
||||
case nzPixelFormat_R5G5A5A1:
|
||||
return 2;
|
||||
|
||||
case nzPixelFormat_R8:
|
||||
return 1;
|
||||
|
||||
case nzPixelFormat_R8G8:
|
||||
return 2;
|
||||
|
||||
case nzPixelFormat_R8G8B8:
|
||||
return 3;
|
||||
|
||||
case nzPixelFormat_R8G8B8A8:
|
||||
return 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case nzPixelFormat_DXT1:
|
||||
case nzPixelFormat_DXT3:
|
||||
case nzPixelFormat_DXT5:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -8,12 +8,12 @@
|
|||
#define NAZARA_RESOURCE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
class NAZARA_API NzResource : NzNonCopyable
|
||||
class NAZARA_API NzResource
|
||||
{
|
||||
public:
|
||||
NzResource(bool persistent = true);
|
||||
NzResource(const NzResource& resource);
|
||||
virtual ~NzResource();
|
||||
|
||||
void AddResourceReference() const;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
// 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_RESOURCELOADER_HPP
|
||||
#define NAZARA_RESOURCELOADER_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
class NzInputStream;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
typedef std::pair<IsMemoryLoadingSupportedFunction, LoadMemoryFunction> MemoryLoader;
|
||||
typedef std::pair<IsStreamLoadingSupportedFunction, LoadStreamFunction> StreamLoader;
|
||||
|
||||
static std::list<MemoryLoader> s_memoryLoaders;
|
||||
static std::list<StreamLoader> s_streamLoaders;
|
||||
static std::multimap<NzString, LoadFileFunction> s_fileLoaders;
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/ResourceLoader.inl>
|
||||
|
||||
#endif // NAZARA_RESOURCELOADER_HPP
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
// 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
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadResourceFromFile(Type* resource, const NzString& filePath, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid Parameters");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzString path = NzFile::NormalizePath(filePath);
|
||||
NzString ext = path.SubstrFrom('.', -1, true);
|
||||
if (ext.IsEmpty())
|
||||
{
|
||||
NazaraError("Failed to get file extension");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Récupération de tous les loaders de cette extension
|
||||
auto range = s_fileLoaders.equal_range(ext);
|
||||
if (range.first == range.second)
|
||||
{
|
||||
NazaraError("No loader found for extension \"" + ext + '"');
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto it = range.first; it != range.second; ++it)
|
||||
{
|
||||
// Chargement de la ressource
|
||||
if (it->second(resource, filePath, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: all loaders failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadResourceFromMemory(Type* resource, const void* data, unsigned int size, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid Parameters");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data || size == 0)
|
||||
{
|
||||
NazaraError("No data to load");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (auto loader = s_memoryLoaders.begin(); loader != s_memoryLoaders.end(); ++loader)
|
||||
{
|
||||
// Le loader supporte-t-il les données ?
|
||||
if (!loader->first(data, size, parameters))
|
||||
continue;
|
||||
|
||||
// Chargement de la ressource
|
||||
if (loader->second(resource, data, size, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: all loaders failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
bool NzResourceLoader<Type, Parameters>::LoadResourceFromStream(Type* resource, NzInputStream& stream, const Parameters& parameters)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!parameters.IsValid())
|
||||
{
|
||||
NazaraError("Invalid Parameters");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (stream.GetSize() == 0 || stream.GetCursorPos() >= stream.GetSize())
|
||||
{
|
||||
NazaraError("No data to load");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
nzUInt64 streamPos = stream.GetCursorPos();
|
||||
for (auto loader = s_streamLoaders.begin(); loader != s_streamLoaders.end(); ++loader)
|
||||
{
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Le loader supporte-t-il les données ?
|
||||
if (!loader->first(stream, parameters))
|
||||
continue;
|
||||
|
||||
stream.SetCursorPos(streamPos);
|
||||
|
||||
// Chargement de la ressource
|
||||
if (loader->second(resource, stream, parameters))
|
||||
return true;
|
||||
|
||||
NazaraWarning("Loader failed");
|
||||
}
|
||||
|
||||
NazaraError("Failed to load file: all loaders failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::RegisterResourceFileLoader(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));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::RegisterResourceMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory)
|
||||
{
|
||||
s_memoryLoaders.push_back(std::make_pair(isLoadingSupported, loadMemory));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::RegisterResourceStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream)
|
||||
{
|
||||
s_streamLoaders.push_back(std::make_pair(isLoadingSupported, loadStream));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::UnregisterResourceFileLoader(const NzString& extensions, LoadFileFunction loadFile)
|
||||
{
|
||||
std::vector<NzString> exts;
|
||||
extensions.SplitAny(exts, " /\\*.,;|-_");
|
||||
|
||||
for (const NzString& ext : exts)
|
||||
{
|
||||
// Récupération de tous les loaders de cette extension
|
||||
auto range = s_fileLoaders.equal_range(ext);
|
||||
|
||||
for (auto it = range.first; it != range.second; ++it)
|
||||
{
|
||||
if (it->second == loadFile)
|
||||
{
|
||||
s_fileLoaders.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//s_fileLoaders.erase(std::make_pair(ext, loadFile));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::UnregisterResourceMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory)
|
||||
{
|
||||
s_memoryLoaders.remove(std::make_pair(isLoadingSupported, loadMemory));
|
||||
}
|
||||
|
||||
template<typename Type, typename Parameters>
|
||||
void NzResourceLoader<Type, Parameters>::UnregisterResourceStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream)
|
||||
{
|
||||
s_streamLoaders.remove(std::make_pair(isLoadingSupported, 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>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// 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_UTILITY_HPP
|
||||
#define NAZARA_UTILITY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
class NAZARA_API NzUtility
|
||||
{
|
||||
public:
|
||||
NzUtility();
|
||||
~NzUtility();
|
||||
|
||||
bool Initialize();
|
||||
void Uninitialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
private:
|
||||
static bool s_initialized;
|
||||
};
|
||||
|
||||
#endif // NAZARA_UTILITY_HPP
|
||||
|
|
@ -3,6 +3,29 @@
|
|||
#include <cstring>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
inline unsigned int nzPow2(unsigned int n)
|
||||
{
|
||||
unsigned int x = 1;
|
||||
|
||||
while(x <= n)
|
||||
x <<= 1;
|
||||
|
||||
return x;
|
||||
}
|
||||
// Cet algorithme est inspiré de la documentation de Qt
|
||||
inline unsigned int nzGetNewSize(unsigned int newSize)
|
||||
{
|
||||
if (newSize < 20)
|
||||
return newSize+4;
|
||||
else
|
||||
{
|
||||
if (newSize < (1 << 12)-12)
|
||||
return nzPow2(newSize << 1)-12;
|
||||
else
|
||||
return newSize + (1 << 11);
|
||||
}
|
||||
}
|
||||
|
||||
NzByteArray::NzByteArray() :
|
||||
m_sharedArray(&emptyArray)
|
||||
{
|
||||
|
|
@ -13,10 +36,10 @@ NzByteArray::NzByteArray(const nzUInt8* buffer, unsigned int bufferLength)
|
|||
if (bufferLength > 0)
|
||||
{
|
||||
m_sharedArray = new SharedArray;
|
||||
m_sharedArray->allocatedSize = bufferLength;
|
||||
m_sharedArray->buffer = new nzUInt8[bufferLength];
|
||||
m_sharedArray->capacity = bufferLength;
|
||||
m_sharedArray->size = bufferLength;
|
||||
std::memcpy(m_sharedArray->buffer, buffer, bufferLength*sizeof(nzUInt8));
|
||||
std::memcpy(m_sharedArray->buffer, buffer, bufferLength);
|
||||
}
|
||||
else
|
||||
m_sharedArray = &emptyArray;
|
||||
|
|
@ -49,9 +72,38 @@ NzByteArray::~NzByteArray()
|
|||
ReleaseArray();
|
||||
}
|
||||
|
||||
unsigned int NzByteArray::Capacity() const
|
||||
NzByteArray& NzByteArray::Append(const NzByteArray& byteArray)
|
||||
{
|
||||
return m_sharedArray->allocatedSize;
|
||||
if (byteArray.m_sharedArray->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedArray->size == 0 && m_sharedArray->capacity < byteArray.m_sharedArray->size)
|
||||
return operator=(byteArray);
|
||||
|
||||
if (m_sharedArray->capacity >= m_sharedArray->size + byteArray.m_sharedArray->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
std::memcpy(&m_sharedArray->buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size);
|
||||
m_sharedArray->size += byteArray.m_sharedArray->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int newSize = m_sharedArray->size + byteArray.m_sharedArray->size;
|
||||
unsigned int bufferSize = nzGetNewSize(newSize);
|
||||
|
||||
nzUInt8* buffer = new nzUInt8[bufferSize+1];
|
||||
std::memcpy(buffer, m_sharedArray->buffer, m_sharedArray->size);
|
||||
std::memcpy(&buffer[m_sharedArray->size], byteArray.m_sharedArray->buffer, byteArray.m_sharedArray->size);
|
||||
|
||||
ReleaseArray();
|
||||
m_sharedArray = new SharedArray;
|
||||
m_sharedArray->buffer = buffer;
|
||||
m_sharedArray->capacity = bufferSize;
|
||||
m_sharedArray->size = newSize;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void NzByteArray::Clear()
|
||||
|
|
@ -59,7 +111,19 @@ void NzByteArray::Clear()
|
|||
ReleaseArray();
|
||||
}
|
||||
|
||||
const nzUInt8* NzByteArray::GetBuffer() const
|
||||
nzUInt8* NzByteArray::GetBuffer()
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
return m_sharedArray->buffer;
|
||||
}
|
||||
|
||||
unsigned int NzByteArray::GetCapacity() const
|
||||
{
|
||||
return m_sharedArray->capacity;
|
||||
}
|
||||
|
||||
const nzUInt8* NzByteArray::GetConstBuffer() const
|
||||
{
|
||||
return m_sharedArray->buffer;
|
||||
}
|
||||
|
|
@ -83,12 +147,12 @@ NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bu
|
|||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedArray->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedArray->allocatedSize >= m_sharedArray->size + bufferLength)
|
||||
if (m_sharedArray->capacity >= m_sharedArray->size + bufferLength)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size*sizeof(nzUInt8));
|
||||
std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength*sizeof(nzUInt8));
|
||||
std::memmove(&m_sharedArray->buffer[start+bufferLength], &m_sharedArray->buffer[start], m_sharedArray->size);
|
||||
std::memcpy(&m_sharedArray->buffer[start], buffer, bufferLength);
|
||||
|
||||
m_sharedArray->size += bufferLength;
|
||||
}
|
||||
|
|
@ -118,7 +182,55 @@ NzByteArray& NzByteArray::Insert(int pos, const nzUInt8* buffer, unsigned int bu
|
|||
return *this;
|
||||
}
|
||||
|
||||
NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray);
|
||||
NzByteArray& NzByteArray::Insert(int pos, const NzByteArray& byteArray)
|
||||
{
|
||||
if (string.m_sharedArray->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedArray->size == 0 && m_sharedArray->capacity < string.m_sharedArray->size)
|
||||
return operator=(string);
|
||||
|
||||
if (pos < 0)
|
||||
pos = std::max(static_cast<int>(m_sharedArray->size + pos), 0);
|
||||
|
||||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedArray->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedArray->capacity >= m_sharedArray->size + string.m_sharedArray->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
std::memmove(&m_sharedArray->string[start+string.m_sharedArray->size], &m_sharedArray->string[start], m_sharedArray->size*sizeof(char));
|
||||
std::memcpy(&m_sharedArray->string[start], string.m_sharedArray->string, string.m_sharedArray->size*sizeof(char));
|
||||
|
||||
m_sharedArray->size += string.m_sharedArray->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned int newSize = m_sharedArray->size+string.m_sharedArray->size;
|
||||
char* newString = new char[newSize+1];
|
||||
|
||||
char* ptr = newString;
|
||||
const char* s = m_sharedArray->string;
|
||||
|
||||
while (ptr != &newString[start])
|
||||
*ptr++ = *s++;
|
||||
|
||||
const char* p = string.m_sharedArray->string;
|
||||
while (ptr != &newString[start+string.m_sharedArray->size])
|
||||
*ptr++ = *p++;
|
||||
|
||||
std::strcpy(ptr, s);
|
||||
|
||||
ReleaseString();
|
||||
m_sharedArray = new SharedString;
|
||||
m_sharedArray->capacity = newSize;
|
||||
m_sharedArray->size = newSize;
|
||||
m_sharedArray->string = newString;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool NzByteArray::IsEmpty() const
|
||||
{
|
||||
|
|
@ -130,9 +242,9 @@ void NzByteArray::Reserve(unsigned int bufferSize)
|
|||
if (m_sharedArray->allocatedSize >= bufferSize)
|
||||
return;
|
||||
|
||||
char* ptr = new char[bufferSize+1];
|
||||
nzUInt8* ptr = new nzUInt8[bufferSize+1];
|
||||
if (m_sharedArray->size > 0)
|
||||
std::strcpy(ptr, m_sharedArray->buffer);
|
||||
std::memcpy(ptr, m_sharedArray->buffer, m_sharedArray->size);
|
||||
|
||||
unsigned int size = m_sharedArray->size;
|
||||
|
||||
|
|
@ -143,45 +255,6 @@ void NzByteArray::Reserve(unsigned int bufferSize)
|
|||
m_sharedArray->size = size;
|
||||
}
|
||||
|
||||
NzByteArray& NzByteArray::Resize(int size, nzUInt8 byte = '\0');
|
||||
NzByteArray NzByteArray::Resized(int size, nzUInt8 byte = '\0') const;
|
||||
|
||||
NzByteArray SubArray(int startPos, int endPos = -1) const;
|
||||
|
||||
void Swap(NzByteArray& byteArray);
|
||||
|
||||
NzByteArray& Trim(nzUInt8 byte = '\0');
|
||||
NzByteArray Trimmed(nzUInt8 byte = '\0') const;
|
||||
|
||||
// Méthodes compatibles STD
|
||||
nzUInt8* begin();
|
||||
const nzUInt8* begin() const;
|
||||
nzUInt8* end();
|
||||
const nzUInt8* end() const;
|
||||
void push_front(nzUInt8 c);
|
||||
void push_back(nzUInt8 c);
|
||||
|
||||
typedef const nzUInt8& const_reference;
|
||||
typedef nzUInt8* iterator;
|
||||
//typedef nzUInt8* reverse_iterator;
|
||||
typedef nzUInt8 value_type;
|
||||
// Méthodes compatibles STD
|
||||
|
||||
nzUInt8& operator[](unsigned int pos);
|
||||
nzUInt8 operator[](unsigned int pos) const;
|
||||
|
||||
NzByteArray& operator=(const NzByteArray& byteArray);
|
||||
NzByteArray& operator=(NzByteArray&& byteArray);
|
||||
|
||||
NzByteArray operator+(const NzByteArray& byteArray) const;
|
||||
NzByteArray& operator+=(const NzByteArray& byteArray);
|
||||
|
||||
static int Compare(const NzByteArray& first, const NzByteArray& second);
|
||||
|
||||
static SharedArray emptyArray;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
bool FillHash(NzHashImpl* hash) const;
|
||||
void ReleaseArray();
|
||||
NzByteArray::SharedString NzByteArray::emptyArray(0, 0, 0, nullptr);
|
||||
unsigned int NzByteArray::npos(static_cast<unsigned int>(-1));
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
// 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
|
||||
|
||||
#include <Nazara/Core/MemoryStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzMemoryStream::NzMemoryStream(const void* ptr, nzUInt64 size) :
|
||||
m_ptr(static_cast<const nzUInt8*>(ptr)),
|
||||
m_pos(0),
|
||||
m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
NzMemoryStream::~NzMemoryStream()
|
||||
{
|
||||
}
|
||||
|
||||
bool NzMemoryStream::EndOfStream() const
|
||||
{
|
||||
return m_pos == m_size;
|
||||
}
|
||||
|
||||
nzUInt64 NzMemoryStream::GetCursorPos() const
|
||||
{
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
nzUInt64 NzMemoryStream::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
std::size_t NzMemoryStream::Read(void* buffer, std::size_t size)
|
||||
{
|
||||
unsigned int readSize = std::min(static_cast<nzUInt64>(size), m_size-m_pos);
|
||||
std::memcpy(buffer, &m_ptr[m_pos], readSize);
|
||||
m_pos += readSize;
|
||||
|
||||
return readSize;
|
||||
}
|
||||
|
||||
bool NzMemoryStream::SetCursorPos(nzUInt64 offset)
|
||||
{
|
||||
m_pos = std::min(offset, m_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ NzString::NzString(char character)
|
|||
else
|
||||
{
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = 1;
|
||||
m_sharedString->capacity = 1;
|
||||
m_sharedString->size = 1;
|
||||
m_sharedString->string = new char[2];
|
||||
m_sharedString->string[0] = character;
|
||||
|
|
@ -107,7 +107,7 @@ NzString::NzString(const char* string)
|
|||
if (size > 0)
|
||||
{
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = size;
|
||||
m_sharedString->capacity = size;
|
||||
m_sharedString->size = size;
|
||||
m_sharedString->string = new char[size+1];
|
||||
std::strcpy(m_sharedString->string, string);
|
||||
|
|
@ -124,7 +124,7 @@ NzString::NzString(const std::string& string)
|
|||
if (string.size() > 0)
|
||||
{
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = string.capacity();
|
||||
m_sharedString->capacity = string.capacity();
|
||||
m_sharedString->size = string.size();
|
||||
m_sharedString->string = new char[string.capacity()+1];
|
||||
std::strcpy(m_sharedString->string, string.c_str());
|
||||
|
|
@ -165,10 +165,10 @@ NzString& NzString::Append(char character)
|
|||
if (character == '\0')
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize == 0)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity == 0)
|
||||
return operator=(character);
|
||||
|
||||
if (m_sharedString->allocatedSize > m_sharedString->size)
|
||||
if (m_sharedString->capacity > m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ NzString& NzString::Append(char character)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
|
|
@ -205,7 +205,7 @@ NzString& NzString::Append(const char* string)
|
|||
if (length == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + length)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + length)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ NzString& NzString::Append(const char* string)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
|
|
@ -236,10 +236,10 @@ NzString& NzString::Append(const NzString& string)
|
|||
if (string.m_sharedString->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize < string.m_sharedString->size)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size)
|
||||
return operator=(string);
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.m_sharedString->size)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -257,7 +257,7 @@ NzString& NzString::Append(const NzString& string)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
|
|
@ -2231,7 +2231,7 @@ char* NzString::GetBuffer()
|
|||
|
||||
unsigned int NzString::GetCapacity() const
|
||||
{
|
||||
return m_sharedString->allocatedSize;
|
||||
return m_sharedString->capacity;
|
||||
}
|
||||
|
||||
const char* NzString::GetConstBuffer() const
|
||||
|
|
@ -2464,7 +2464,7 @@ NzString& NzString::Insert(int pos, char character)
|
|||
if (character == '\0')
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize == 0)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity == 0)
|
||||
return operator=(character);
|
||||
|
||||
if (pos < 0)
|
||||
|
|
@ -2473,7 +2473,7 @@ NzString& NzString::Insert(int pos, char character)
|
|||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedString->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size+1)
|
||||
if (m_sharedString->capacity >= m_sharedString->size+1)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -2499,7 +2499,7 @@ NzString& NzString::Insert(int pos, char character)
|
|||
ReleaseString();
|
||||
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
|
|
@ -2519,7 +2519,7 @@ NzString& NzString::Insert(int pos, const char* string)
|
|||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
unsigned int len = std::strlen(string);
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size+len)
|
||||
if (m_sharedString->capacity >= m_sharedString->size+len)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -2547,7 +2547,7 @@ NzString& NzString::Insert(int pos, const char* string)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
|
|
@ -2560,7 +2560,7 @@ NzString& NzString::Insert(int pos, const NzString& string)
|
|||
if (string.m_sharedString->size == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->size == 0 && m_sharedString->allocatedSize < string.m_sharedString->size)
|
||||
if (m_sharedString->size == 0 && m_sharedString->capacity < string.m_sharedString->size)
|
||||
return operator=(string);
|
||||
|
||||
if (pos < 0)
|
||||
|
|
@ -2569,7 +2569,7 @@ NzString& NzString::Insert(int pos, const NzString& string)
|
|||
unsigned int start = std::min(static_cast<unsigned int>(pos), m_sharedString->size);
|
||||
|
||||
// Si le buffer est déjà suffisamment grand
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.m_sharedString->size)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -2597,7 +2597,7 @@ NzString& NzString::Insert(int pos, const NzString& string)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
|
|
@ -2870,7 +2870,7 @@ unsigned int NzString::Replace(const char* oldString, const char* replaceString,
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
|
|
@ -2940,7 +2940,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
|
|
@ -3180,7 +3180,7 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact
|
|||
*/
|
||||
void NzString::Reserve(unsigned int bufferSize)
|
||||
{
|
||||
if (m_sharedString->allocatedSize >= bufferSize)
|
||||
if (m_sharedString->capacity >= bufferSize)
|
||||
return;
|
||||
|
||||
char* ptr = new char[bufferSize+1];
|
||||
|
|
@ -3191,7 +3191,7 @@ void NzString::Reserve(unsigned int bufferSize)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = size;
|
||||
m_sharedString->string = ptr;
|
||||
}
|
||||
|
|
@ -3203,7 +3203,7 @@ NzString& NzString::Resize(int size, char character)
|
|||
|
||||
unsigned int newSize = static_cast<unsigned int>(size);
|
||||
|
||||
if (m_sharedString->allocatedSize >= newSize)
|
||||
if (m_sharedString->capacity >= newSize)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -3232,7 +3232,7 @@ NzString& NzString::Resize(int size, char character)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = newSize;
|
||||
m_sharedString->capacity = newSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = newString;
|
||||
}
|
||||
|
|
@ -4103,13 +4103,13 @@ NzString& NzString::operator=(char character)
|
|||
{
|
||||
if (character != '\0')
|
||||
{
|
||||
if (m_sharedString->allocatedSize >= 1)
|
||||
if (m_sharedString->capacity >= 1)
|
||||
EnsureOwnership();
|
||||
else
|
||||
{
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = 1;
|
||||
m_sharedString->capacity = 1;
|
||||
m_sharedString->string = new char[2];
|
||||
}
|
||||
|
||||
|
|
@ -4128,14 +4128,14 @@ NzString& NzString::operator=(const char* string)
|
|||
if (string && string[0] != '\0')
|
||||
{
|
||||
unsigned int size = std::strlen(string);
|
||||
if (m_sharedString->allocatedSize >= size)
|
||||
if (m_sharedString->capacity >= size)
|
||||
EnsureOwnership();
|
||||
else
|
||||
{
|
||||
ReleaseString();
|
||||
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = size;
|
||||
m_sharedString->capacity = size;
|
||||
m_sharedString->string = new char[size+1];
|
||||
}
|
||||
|
||||
|
|
@ -4152,14 +4152,14 @@ NzString& NzString::operator=(const std::string& string)
|
|||
{
|
||||
if (string.size() > 0)
|
||||
{
|
||||
if (m_sharedString->allocatedSize >= string.size())
|
||||
if (m_sharedString->capacity >= string.size())
|
||||
EnsureOwnership();
|
||||
else
|
||||
{
|
||||
ReleaseString();
|
||||
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = string.size();
|
||||
m_sharedString->capacity = string.size();
|
||||
m_sharedString->string = new char[string.size()+1];
|
||||
}
|
||||
|
||||
|
|
@ -4269,7 +4269,7 @@ NzString& NzString::operator+=(char character)
|
|||
if (m_sharedString->size == 0)
|
||||
return operator=(character);
|
||||
|
||||
if (m_sharedString->allocatedSize > m_sharedString->size)
|
||||
if (m_sharedString->capacity > m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -4289,7 +4289,7 @@ NzString& NzString::operator+=(char character)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
|
|
@ -4309,7 +4309,7 @@ NzString& NzString::operator+=(const char* string)
|
|||
if (length == 0)
|
||||
return *this;
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + length)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + length)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -4327,7 +4327,7 @@ NzString& NzString::operator+=(const char* string)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
|
|
@ -4343,7 +4343,7 @@ NzString& NzString::operator+=(const std::string& string)
|
|||
if (m_sharedString->size == 0)
|
||||
return operator=(string);
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.size())
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.size())
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -4361,7 +4361,7 @@ NzString& NzString::operator+=(const std::string& string)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
|
|
@ -4377,7 +4377,7 @@ NzString& NzString::operator+=(const NzString& string)
|
|||
if (m_sharedString->size == 0)
|
||||
return operator=(string);
|
||||
|
||||
if (m_sharedString->allocatedSize >= m_sharedString->size + string.m_sharedString->size)
|
||||
if (m_sharedString->capacity >= m_sharedString->size + string.m_sharedString->size)
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
|
|
@ -4395,7 +4395,7 @@ NzString& NzString::operator+=(const NzString& string)
|
|||
|
||||
ReleaseString();
|
||||
m_sharedString = new SharedString;
|
||||
m_sharedString->allocatedSize = bufferSize;
|
||||
m_sharedString->capacity = bufferSize;
|
||||
m_sharedString->size = newSize;
|
||||
m_sharedString->string = str;
|
||||
}
|
||||
|
|
@ -5037,10 +5037,10 @@ void NzString::EnsureOwnership()
|
|||
{
|
||||
m_sharedString->refCount--;
|
||||
|
||||
char* string = new char[m_sharedString->allocatedSize+1];
|
||||
char* string = new char[m_sharedString->capacity+1];
|
||||
std::strcpy(string, m_sharedString->string);
|
||||
|
||||
m_sharedString = new SharedString(1, m_sharedString->allocatedSize, m_sharedString->size, string);
|
||||
m_sharedString = new SharedString(1, m_sharedString->capacity, m_sharedString->size, string);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include <Nazara/Core/Win32/Time.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
///TODO: Faire en sorte que le EOF corresponde aux autres EOF de Nazara
|
||||
|
||||
NzFileImpl::NzFileImpl(const NzFile* parent) :
|
||||
m_endOfFile(false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/Buffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/HardwareBuffer.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/SoftwareBuffer.hpp>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Nazara/Renderer/IndexBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/OcclusionQuery.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@
|
|||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/BufferImpl.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Context.hpp>
|
||||
#include <Nazara/Renderer/IndexBuffer.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Renderer/ShaderImpl.hpp>
|
||||
#include <Nazara/Renderer/VertexBuffer.hpp>
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
|
|
@ -45,7 +47,8 @@ m_vertexBufferUpdated(false)
|
|||
|
||||
NzRenderer::~NzRenderer()
|
||||
{
|
||||
Uninitialize();
|
||||
if (s_initialized)
|
||||
Uninitialize();
|
||||
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
|
@ -166,6 +169,21 @@ bool NzRenderer::HasCapability(nzRendererCap capability) const
|
|||
|
||||
bool NzRenderer::Initialize()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (s_initialized)
|
||||
{
|
||||
NazaraError("Renderer already initialized");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialisation du module Utility
|
||||
if (!NzUtility::IsInitialized())
|
||||
{
|
||||
m_utilityModule = new NzUtility;
|
||||
m_utilityModule->Initialize();
|
||||
}
|
||||
|
||||
if (NzOpenGL::Initialize())
|
||||
{
|
||||
m_capabilities[nzRendererCap_AnisotropicFilter] = NzOpenGL::IsSupported(NzOpenGL::AnisotropicFilter);
|
||||
|
|
@ -179,6 +197,8 @@ bool NzRenderer::Initialize()
|
|||
m_capabilities[nzRendererCap_TextureMulti] = true; // Natif depuis OpenGL 1.3
|
||||
m_capabilities[nzRendererCap_TextureNPOT] = true; // Natif depuis OpenGL 2.0
|
||||
|
||||
s_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
@ -329,23 +349,28 @@ bool NzRenderer::SetVertexDeclaration(const NzVertexDeclaration* vertexDeclarati
|
|||
|
||||
void NzRenderer::Uninitialize()
|
||||
{
|
||||
NzOpenGL::Uninitialize();
|
||||
}
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
if (!s_initialized)
|
||||
{
|
||||
NazaraError("Renderer not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NAZARA_RENDERER_SINGLETON
|
||||
void NzRenderer::Destroy()
|
||||
{
|
||||
delete s_instance;
|
||||
s_instance = nullptr;
|
||||
NzOpenGL::Uninitialize();
|
||||
|
||||
s_initialized = false;
|
||||
|
||||
if (m_utilityModule)
|
||||
{
|
||||
delete m_utilityModule;
|
||||
m_utilityModule = nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NzRenderer* NzRenderer::Instance()
|
||||
{
|
||||
#if NAZARA_RENDERER_SINGLETON
|
||||
if (!s_instance)
|
||||
s_instance = new NzRenderer;
|
||||
#elif defined(NAZARA_DEBUG)
|
||||
#if defined(NAZARA_DEBUG)
|
||||
if (!s_instance)
|
||||
NazaraError("Renderer not instanced");
|
||||
#endif
|
||||
|
|
@ -353,6 +378,11 @@ NzRenderer* NzRenderer::Instance()
|
|||
return s_instance;
|
||||
}
|
||||
|
||||
bool NzRenderer::IsInitialized()
|
||||
{
|
||||
return s_initialized;
|
||||
}
|
||||
|
||||
bool NzRenderer::UpdateVertexBuffer()
|
||||
{
|
||||
#if NAZARA_RENDERER_SAFE
|
||||
|
|
@ -384,3 +414,4 @@ bool NzRenderer::UpdateVertexBuffer()
|
|||
}
|
||||
|
||||
NzRenderer* NzRenderer::s_instance = nullptr;
|
||||
bool NzRenderer::s_initialized = false;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/GLSLShader.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/ShaderImpl.hpp>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Renderer/OpenGL.hpp>
|
||||
#include <Nazara/Renderer/SoftwareBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Nazara/Renderer/VertexDeclaration.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/Debug.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,475 @@
|
|||
// 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
|
||||
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/ResourceLoader.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzImage::NzImage() :
|
||||
m_sharedImage(&emptyImage)
|
||||
{
|
||||
}
|
||||
|
||||
NzImage::NzImage(const NzImage& image) :
|
||||
NzResource(image),
|
||||
m_sharedImage(image.m_sharedImage)
|
||||
{
|
||||
if (m_sharedImage != &emptyImage)
|
||||
{
|
||||
NazaraMutexLock(m_sharedImage->mutex);
|
||||
m_sharedImage->refCount++;
|
||||
NazaraMutexUnlock(m_sharedImage->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
NzImage::NzImage(NzImage&& image) :
|
||||
m_sharedImage(image.m_sharedImage)
|
||||
{
|
||||
image.m_sharedImage = &emptyImage;
|
||||
}
|
||||
|
||||
NzImage::~NzImage()
|
||||
{
|
||||
ReleaseImage();
|
||||
}
|
||||
|
||||
bool NzImage::Copy(const NzImage& source, const NzRectui& srcRect, const NzVector2ui& dstPos)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!source.IsValid())
|
||||
{
|
||||
NazaraError("Source image must be valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source.GetFormat() != m_sharedImage->format)
|
||||
{
|
||||
NazaraError("Source image format does not match destination image format");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Update(&source.GetConstPixels()[(srcRect.x + srcRect.y * source.GetHeight()) * source.GetBPP()], NzRectui(dstPos.x, dstPos.y, srcRect.width, srcRect.height));
|
||||
}
|
||||
|
||||
bool NzImage::CopyToFace(nzCubemapFace face, const NzImage& source, const NzRectui& srcRect, const NzVector2ui& dstPos)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!source.IsValid())
|
||||
{
|
||||
NazaraError("Source image must be valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source.GetFormat() != m_sharedImage->format)
|
||||
{
|
||||
NazaraError("Source image format does not match destination image format");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return UpdateFace(face, &source.GetConstPixels()[(srcRect.x + srcRect.y * source.GetHeight()) * source.GetBPP()], NzRectui(dstPos.x, dstPos.y, srcRect.width, srcRect.height));
|
||||
}
|
||||
|
||||
bool NzImage::Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth)
|
||||
{
|
||||
ReleaseImage();
|
||||
|
||||
unsigned int size = width*height*depth*NzPixelFormat::GetBPP(format);
|
||||
if (size == 0)
|
||||
return true;
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
switch (type)
|
||||
{
|
||||
case nzImageType_1D:
|
||||
if (height > 1)
|
||||
{
|
||||
NazaraError("1D textures must be 1 height");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (depth > 1)
|
||||
{
|
||||
NazaraError("1D textures must be 1 depth");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_2D:
|
||||
if (depth > 1)
|
||||
{
|
||||
NazaraError("2D textures must be 1 depth");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case nzImageType_Cubemap:
|
||||
if (depth > 1)
|
||||
{
|
||||
NazaraError("Cubemaps must be 1 depth");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (width != height)
|
||||
{
|
||||
NazaraError("Cubemaps must have square dimensions");
|
||||
return false;
|
||||
}
|
||||
|
||||
size *= 6; // Les cubemaps ont six faces
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if (type == nzImageType_Cubemap)
|
||||
size *= 6; // Les cubemaps ont six faces
|
||||
#endif
|
||||
|
||||
m_sharedImage = new SharedImage(1, type, format, new nzUInt8[size], width, height, depth);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzImage::Destroy()
|
||||
{
|
||||
ReleaseImage();
|
||||
}
|
||||
|
||||
nzUInt8 NzImage::GetBPP() const
|
||||
{
|
||||
return NzPixelFormat::GetBPP(m_sharedImage->format);
|
||||
}
|
||||
|
||||
const nzUInt8* NzImage::GetConstPixels() const
|
||||
{
|
||||
return m_sharedImage->pixels;
|
||||
}
|
||||
|
||||
unsigned int NzImage::GetDepth() const
|
||||
{
|
||||
return m_sharedImage->depth;
|
||||
}
|
||||
|
||||
nzPixelFormat NzImage::GetFormat() const
|
||||
{
|
||||
return m_sharedImage->format;
|
||||
}
|
||||
|
||||
unsigned int NzImage::GetHeight() const
|
||||
{
|
||||
return m_sharedImage->height;
|
||||
}
|
||||
|
||||
nzUInt8* NzImage::GetPixels()
|
||||
{
|
||||
EnsureOwnership();
|
||||
|
||||
return m_sharedImage->pixels;
|
||||
}
|
||||
|
||||
unsigned int NzImage::GetSize() const
|
||||
{
|
||||
return m_sharedImage->width * m_sharedImage->height * m_sharedImage->depth * NzPixelFormat::GetBPP(m_sharedImage->format);
|
||||
}
|
||||
|
||||
nzImageType NzImage::GetType() const
|
||||
{
|
||||
return m_sharedImage->type;
|
||||
}
|
||||
|
||||
unsigned int NzImage::GetWidth() const
|
||||
{
|
||||
return m_sharedImage->width;
|
||||
}
|
||||
|
||||
bool NzImage::IsCompressed() const
|
||||
{
|
||||
return NzPixelFormat::IsCompressed(m_sharedImage->format);
|
||||
}
|
||||
|
||||
bool NzImage::IsCubemap() const
|
||||
{
|
||||
return m_sharedImage->type == nzImageType_Cubemap;
|
||||
}
|
||||
|
||||
bool NzImage::IsValid() const
|
||||
{
|
||||
return m_sharedImage != &emptyImage;
|
||||
}
|
||||
|
||||
bool NzImage::LoadFromFile(const NzString& filePath, const NzImageParams& params)
|
||||
{
|
||||
return NzResourceLoader<NzImage, NzImageParams>::LoadResourceFromFile(this, filePath, params);
|
||||
}
|
||||
|
||||
bool NzImage::LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params)
|
||||
{
|
||||
return NzResourceLoader<NzImage, NzImageParams>::LoadResourceFromMemory(this, data, size, params);
|
||||
}
|
||||
|
||||
bool NzImage::LoadFromStream(NzInputStream& stream, const NzImageParams& params)
|
||||
{
|
||||
return NzResourceLoader<NzImage, NzImageParams>::LoadResourceFromStream(this, stream, params);
|
||||
}
|
||||
|
||||
bool NzImage::Update(const nzUInt8* pixels)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
{
|
||||
NazaraError("Image must be valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsCubemap())
|
||||
{
|
||||
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pixels)
|
||||
{
|
||||
NazaraError("Invalid pixel source");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
std::memcpy(m_sharedImage->pixels, pixels, GetSize());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzImage::Update(const nzUInt8* pixels, const NzRectui& rect)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
{
|
||||
NazaraError("Image must be valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsCubemap())
|
||||
{
|
||||
NazaraError("Update is not designed for cubemaps, use UpdateFace instead");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pixels)
|
||||
{
|
||||
NazaraError("Invalid pixel source");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!rect.IsValid())
|
||||
{
|
||||
NazaraError("Invalid rectangle");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rect.width > m_sharedImage->width || rect.height > m_sharedImage->height)
|
||||
{
|
||||
NazaraError("Rectangle dimensions are out of bounds");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format);
|
||||
|
||||
nzUInt8* dstPixels = m_sharedImage->pixels + (rect.x + rect.y * m_sharedImage->width) * bpp;
|
||||
unsigned int srcStride = rect.width * bpp;
|
||||
unsigned int dstStride = m_sharedImage->width * bpp;
|
||||
|
||||
unsigned int blockSize = m_sharedImage->width * bpp;
|
||||
for (unsigned int i = 0; i < rect.height; ++i)
|
||||
{
|
||||
std::memcpy(dstPixels, pixels, blockSize);
|
||||
pixels += srcStride;
|
||||
dstPixels += dstStride;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzImage::UpdateFace(nzCubemapFace face, const nzUInt8* pixels)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
{
|
||||
NazaraError("Image must be valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsCubemap())
|
||||
{
|
||||
NazaraError("Update is only designed for cubemaps, use Update instead");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pixels)
|
||||
{
|
||||
NazaraError("Invalid pixel source");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
unsigned int size = GetSize();
|
||||
std::memcpy(&m_sharedImage->pixels[size*(face-nzCubemapFace_PositiveX)], pixels, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzImage::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!IsValid())
|
||||
{
|
||||
NazaraError("Image must be valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsCubemap())
|
||||
{
|
||||
NazaraError("Update is only designed for cubemaps, use Update instead");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pixels)
|
||||
{
|
||||
NazaraError("Invalid pixel source");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!rect.IsValid())
|
||||
{
|
||||
NazaraError("Invalid rectangle");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rect.width > m_sharedImage->width || rect.height > m_sharedImage->height)
|
||||
{
|
||||
NazaraError("Rectangle dimensions are out of bounds");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
EnsureOwnership();
|
||||
|
||||
nzUInt8 bpp = NzPixelFormat::GetBPP(m_sharedImage->format);
|
||||
|
||||
nzUInt8* dstPixels = m_sharedImage->pixels + (rect.x + rect.y * m_sharedImage->width + (face-nzCubemapFace_PositiveX)*m_sharedImage->width*m_sharedImage->height) * bpp;
|
||||
unsigned int srcStride = rect.width * bpp;
|
||||
unsigned int dstStride = m_sharedImage->width * bpp;
|
||||
|
||||
unsigned int blockSize = m_sharedImage->width * bpp;
|
||||
for (unsigned int i = 0; i < rect.height; ++i)
|
||||
{
|
||||
std::memcpy(dstPixels, pixels, blockSize);
|
||||
pixels += srcStride;
|
||||
dstPixels += dstStride;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NzImage& NzImage::operator=(const NzImage& image)
|
||||
{
|
||||
ReleaseImage();
|
||||
|
||||
m_sharedImage = image.m_sharedImage;
|
||||
if (m_sharedImage != &emptyImage)
|
||||
{
|
||||
NazaraMutexLock(m_sharedImage->mutex);
|
||||
m_sharedImage->refCount++;
|
||||
NazaraMutexUnlock(m_sharedImage->mutex);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzImage& NzImage::operator=(NzImage&& image)
|
||||
{
|
||||
std::swap(m_sharedImage, image.m_sharedImage);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void NzImage::RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile)
|
||||
{
|
||||
return RegisterResourceFileLoader(extensions, loadFile);
|
||||
}
|
||||
|
||||
void NzImage::RegisterMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory)
|
||||
{
|
||||
return RegisterResourceMemoryLoader(isLoadingSupported, loadMemory);
|
||||
}
|
||||
|
||||
void NzImage::RegisterStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream)
|
||||
{
|
||||
return RegisterResourceStreamLoader(isLoadingSupported, loadStream);
|
||||
}
|
||||
|
||||
void NzImage::UnregisterFileLoader(const NzString& extensions, LoadFileFunction loadFile)
|
||||
{
|
||||
UnregisterResourceFileLoader(extensions, loadFile);
|
||||
}
|
||||
|
||||
void NzImage::UnregisterMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory)
|
||||
{
|
||||
UnregisterResourceMemoryLoader(isLoadingSupported, loadMemory);
|
||||
}
|
||||
|
||||
void NzImage::UnregisterStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream)
|
||||
{
|
||||
UnregisterResourceStreamLoader(isLoadingSupported, loadStream);
|
||||
}
|
||||
|
||||
void NzImage::EnsureOwnership()
|
||||
{
|
||||
if (m_sharedImage == &emptyImage)
|
||||
return;
|
||||
|
||||
NazaraLock(m_sharedImage->mutex);
|
||||
if (m_sharedImage->refCount > 1)
|
||||
{
|
||||
m_sharedImage->refCount--;
|
||||
|
||||
unsigned int size = GetSize();
|
||||
|
||||
nzUInt8* pixels = new nzUInt8[size];
|
||||
std::memcpy(pixels, m_sharedImage->pixels, size);
|
||||
|
||||
m_sharedImage = new SharedImage(1, m_sharedImage->type, m_sharedImage->format, pixels, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth);
|
||||
}
|
||||
}
|
||||
|
||||
void NzImage::ReleaseImage()
|
||||
{
|
||||
if (m_sharedImage == &emptyImage)
|
||||
return;
|
||||
|
||||
NazaraMutexLock(m_sharedImage->mutex);
|
||||
m_sharedImage->refCount--;
|
||||
NazaraMutexUnlock(m_sharedImage->mutex);
|
||||
|
||||
if (m_sharedImage->refCount == 0)
|
||||
{
|
||||
delete[] m_sharedImage->pixels;
|
||||
delete m_sharedImage;
|
||||
}
|
||||
|
||||
m_sharedImage = &emptyImage;
|
||||
}
|
||||
|
||||
NzImage::SharedImage NzImage::emptyImage(0, nzImageType_2D, nzPixelFormat_R8G8B8, nullptr, 0, 0, 0);
|
||||
|
|
@ -0,0 +1,365 @@
|
|||
// Copyright (C) 2011 Jérôme Leclercq
|
||||
// This file is part of the "Ungine".
|
||||
// For conditions of distribution and use, see copyright notice in Core.h
|
||||
|
||||
#include <Nazara/Utility/Loaders/PCX.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/MemoryStream.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
// Auteur du loader original : David Henry
|
||||
|
||||
namespace
|
||||
{
|
||||
struct pcx_header
|
||||
{
|
||||
nzUInt8 manufacturer;
|
||||
nzUInt8 version;
|
||||
nzUInt8 encoding;
|
||||
nzUInt8 bitsPerPixel;
|
||||
|
||||
nzUInt16 xmin, ymin;
|
||||
nzUInt16 xmax, ymax;
|
||||
nzUInt16 horzRes, vertRes;
|
||||
|
||||
nzUInt8 palette[48];
|
||||
nzUInt8 reserved;
|
||||
nzUInt8 numColorPlanes;
|
||||
|
||||
nzUInt16 bytesPerScanLine;
|
||||
nzUInt16 paletteType;
|
||||
nzUInt16 horzSize, vertSize;
|
||||
|
||||
nzUInt8 padding[54];
|
||||
};
|
||||
|
||||
bool NzLoader_PCX_LoadStream(NzImage* resource, NzInputStream& stream, const NzImageParams& parameters);
|
||||
|
||||
bool NzLoader_PCX_LoadFile(NzImage* resource, const NzString& filePath, const NzImageParams& parameters)
|
||||
{
|
||||
NzFile file(filePath);
|
||||
if (!file.Open(NzFile::ReadOnly))
|
||||
{
|
||||
NazaraError("Failed to open file");
|
||||
return false;
|
||||
}
|
||||
|
||||
return NzLoader_PCX_LoadStream(resource, file, parameters);
|
||||
}
|
||||
|
||||
bool NzLoader_PCX_LoadMemory(NzImage* resource, const void* data, unsigned int size, const NzImageParams& parameters)
|
||||
{
|
||||
NzMemoryStream stream(data, size);
|
||||
return NzLoader_PCX_LoadStream(resource, stream, parameters);
|
||||
}
|
||||
|
||||
bool NzLoader_PCX_LoadStream(NzImage* resource, NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
pcx_header header;
|
||||
if (stream.Read(&header, sizeof(pcx_header)) != sizeof(pcx_header))
|
||||
{
|
||||
NazaraError("Failed to read header");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (header.manufacturer != 0x0a)
|
||||
{
|
||||
NazaraError("Bad version number (" + NzString::Number(header.manufacturer) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes;
|
||||
unsigned int width = header.xmax - header.xmin+1;
|
||||
unsigned int height = header.ymax - header.ymin+1;
|
||||
|
||||
if (!resource->Create(nzImageType_2D, nzPixelFormat_R8G8B8, width, height))
|
||||
{
|
||||
NazaraError("Failed to create image");
|
||||
return false;
|
||||
}
|
||||
|
||||
nzUInt8* pixels = resource->GetPixels();
|
||||
|
||||
int rle_value = 0;
|
||||
unsigned int rle_count = 0;
|
||||
|
||||
switch (bitCount)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
{
|
||||
nzUInt8* ptr = &pixels[y * width * 3];
|
||||
int bytes = header.bytesPerScanLine;
|
||||
|
||||
/* decode line number y */
|
||||
while (bytes--)
|
||||
{
|
||||
if (rle_count == 0)
|
||||
{
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rle_value < 0xc0)
|
||||
rle_count = 1;
|
||||
else
|
||||
{
|
||||
rle_count = rle_value - 0xc0;
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rle_count--;
|
||||
|
||||
for (int i = 7; i >= 0; --i)
|
||||
{
|
||||
int colorIndex = ((rle_value & (1 << i)) > 0);
|
||||
|
||||
*ptr++ = header.palette[colorIndex * 3 + 0];
|
||||
*ptr++ = header.palette[colorIndex * 3 + 1];
|
||||
*ptr++ = header.palette[colorIndex * 3 + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
nzUInt8* colorIndex = new nzUInt8[width];
|
||||
nzUInt8* line = new nzUInt8[header.bytesPerScanLine];
|
||||
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
{
|
||||
nzUInt8* ptr = &pixels[y * width * 3];
|
||||
|
||||
std::memset(colorIndex, 0, width);
|
||||
|
||||
for (unsigned int c = 0; c < 4; ++c)
|
||||
{
|
||||
nzUInt8* pLine = line;
|
||||
int bytes = header.bytesPerScanLine;
|
||||
|
||||
/* decode line number y */
|
||||
while (bytes--)
|
||||
{
|
||||
if (rle_count == 0)
|
||||
{
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
delete[] colorIndex;
|
||||
delete[] line;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rle_value < 0xc0)
|
||||
rle_count = 1;
|
||||
else
|
||||
{
|
||||
rle_count = rle_value - 0xc0;
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
delete[] colorIndex;
|
||||
delete[] line;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rle_count--;
|
||||
*(pLine++) = rle_value;
|
||||
}
|
||||
|
||||
/* compute line's color indexes */
|
||||
for (unsigned int x = 0; x < width; ++x)
|
||||
{
|
||||
if (line[x / 8] & (128 >> (x % 8)))
|
||||
colorIndex[x] += (1 << c);
|
||||
}
|
||||
}
|
||||
|
||||
/* decode scan line. color index => rgb */
|
||||
for (unsigned int x = 0; x < width; ++x)
|
||||
{
|
||||
*ptr++ = header.palette[colorIndex[x] * 3 + 0];
|
||||
*ptr++ = header.palette[colorIndex[x] * 3 + 1];
|
||||
*ptr++ = header.palette[colorIndex[x] * 3 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
/* release memory */
|
||||
delete[] colorIndex;
|
||||
delete[] line;
|
||||
break;
|
||||
}
|
||||
|
||||
case 8:
|
||||
{
|
||||
nzUInt8 palette[768];
|
||||
|
||||
/* the palette is contained in the last 769 bytes of the file */
|
||||
unsigned int curPos = stream.GetCursorPos();
|
||||
stream.SetCursorPos(stream.GetSize()-769);
|
||||
nzUInt8 magic;
|
||||
if (!stream.Read(&magic, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
/* first byte must be equal to 0x0c (12) */
|
||||
if (magic != 0x0c)
|
||||
{
|
||||
NazaraError("Colormap's first byte must be 0x0c (0x" + NzString::Number(magic, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
/* read palette */
|
||||
if (stream.Read(palette, 768) != 768)
|
||||
{
|
||||
NazaraError("Failed to read palette");
|
||||
return false;
|
||||
}
|
||||
|
||||
stream.SetCursorPos(curPos);
|
||||
|
||||
/* read pixel data */
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
{
|
||||
nzUInt8* ptr = &pixels[y * width * 3];
|
||||
int bytes = header.bytesPerScanLine;
|
||||
|
||||
/* decode line number y */
|
||||
while (bytes--)
|
||||
{
|
||||
if (rle_count == 0)
|
||||
{
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rle_value < 0xc0)
|
||||
rle_count = 1;
|
||||
else
|
||||
{
|
||||
rle_count = rle_value - 0xc0;
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rle_count--;
|
||||
|
||||
*ptr++ = palette[rle_value * 3 + 0];
|
||||
*ptr++ = palette[rle_value * 3 + 1];
|
||||
*ptr++ = palette[rle_value * 3 + 2];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 24:
|
||||
{
|
||||
for (unsigned int y = 0; y < height; ++y)
|
||||
{
|
||||
/* for each color plane */
|
||||
for (int c = 0; c < 3; ++c)
|
||||
{
|
||||
nzUInt8* ptr = &pixels[y * width * 4];
|
||||
int bytes = header.bytesPerScanLine;
|
||||
|
||||
/* decode line number y */
|
||||
while (bytes--)
|
||||
{
|
||||
if (rle_count == 0)
|
||||
{
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rle_value < 0xc0)
|
||||
rle_count = 1;
|
||||
else
|
||||
{
|
||||
rle_count = rle_value - 0xc0;
|
||||
if (!stream.Read(&rle_value, 1))
|
||||
{
|
||||
NazaraError("Failed to read stream (byte " + NzString::Number(stream.GetCursorPos()) + ')');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rle_count--;
|
||||
ptr[c] = static_cast<nzUInt8>(rle_value);
|
||||
ptr += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
NazaraError("Unknown " + NzString::Number(bitCount) + " bitcount pcx files");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzLoader_PCX_IsMemoryLoadingSupported(const void* data, unsigned int size, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
if (size < sizeof(pcx_header))
|
||||
return false;
|
||||
|
||||
return *reinterpret_cast<const nzUInt8*>(data) == 0x0a;
|
||||
}
|
||||
|
||||
bool NzLoader_PCX_IsStreamLoadingSupported(NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
nzUInt8 manufacturer;
|
||||
stream.Read(&manufacturer, 1);
|
||||
|
||||
return manufacturer == 0x0a;
|
||||
}
|
||||
}
|
||||
|
||||
void NzLoaders_PCX_Register()
|
||||
{
|
||||
NzImage::RegisterFileLoader("pcx", NzLoader_PCX_LoadFile);
|
||||
NzImage::RegisterMemoryLoader(NzLoader_PCX_IsMemoryLoadingSupported, NzLoader_PCX_LoadMemory);
|
||||
NzImage::RegisterStreamLoader(NzLoader_PCX_IsStreamLoadingSupported, NzLoader_PCX_LoadStream);
|
||||
}
|
||||
|
||||
void NzLoaders_PCX_Unregister()
|
||||
{
|
||||
///TODO
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// 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_LOADERS_PCX_HPP
|
||||
#define NAZARA_LOADERS_PCX_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
void NzLoaders_PCX_Register();
|
||||
void NzLoaders_PCX_Unregister();
|
||||
|
||||
#endif // NAZARA_LOADERS_PCX_HPP
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
// Copyright (C) 2011 Jérôme Leclercq
|
||||
// This file is part of the "Ungine".
|
||||
// For conditions of distribution and use, see copyright notice in Core.h
|
||||
|
||||
#include <Nazara/Utility/Loaders/STB.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/MemoryStream.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
|
||||
#define STBI_HEADER_FILE_ONLY
|
||||
#include <Nazara/Utility/Loaders/STB/stb_image.c>
|
||||
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
// Auteur du loader original : David Henry
|
||||
|
||||
namespace
|
||||
{
|
||||
int Read(void* userdata, char* data, int size)
|
||||
{
|
||||
NzInputStream* stream = static_cast<NzInputStream*>(userdata);
|
||||
return static_cast<int>(stream->Read(data, size));
|
||||
}
|
||||
|
||||
void Skip(void* userdata, unsigned int size)
|
||||
{
|
||||
NzInputStream* stream = static_cast<NzInputStream*>(userdata);
|
||||
stream->Read(nullptr, size);
|
||||
}
|
||||
|
||||
int Eof(void* userdata)
|
||||
{
|
||||
NzInputStream* stream = static_cast<NzInputStream*>(userdata);
|
||||
return stream->GetCursorPos() >= stream->GetSize();
|
||||
}
|
||||
|
||||
static stbi_io_callbacks callbacks = {Read, Skip, Eof};
|
||||
|
||||
bool NzLoader_STB_LoadStream(NzImage* resource, NzInputStream& stream, const NzImageParams& parameters);
|
||||
|
||||
bool NzLoader_STB_LoadFile(NzImage* resource, const NzString& filePath, const NzImageParams& parameters)
|
||||
{
|
||||
NzFile file(filePath);
|
||||
if (!file.Open(NzFile::ReadOnly))
|
||||
{
|
||||
NazaraError("Failed to open file");
|
||||
return false;
|
||||
}
|
||||
|
||||
return NzLoader_STB_LoadStream(resource, file, parameters);
|
||||
}
|
||||
|
||||
bool NzLoader_STB_LoadMemory(NzImage* resource, const void* data, unsigned int size, const NzImageParams& parameters)
|
||||
{
|
||||
NzMemoryStream stream(data, size);
|
||||
return NzLoader_STB_LoadStream(resource, stream, parameters);
|
||||
}
|
||||
|
||||
bool NzLoader_STB_LoadStream(NzImage* resource, NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
static nzPixelFormat format[4] = {
|
||||
nzPixelFormat_L8,
|
||||
nzPixelFormat_L8A8,
|
||||
nzPixelFormat_R8G8B8,
|
||||
nzPixelFormat_R8G8B8A8
|
||||
};
|
||||
|
||||
int width, height, bpp;
|
||||
nzUInt8* ptr = stbi_load_from_callbacks(&callbacks, &stream, &width, &height, &bpp, STBI_default);
|
||||
|
||||
if (!ptr)
|
||||
{
|
||||
NazaraError("Failed to load image: " + NzString(stbi_failure_reason()));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!resource->Create(nzImageType_2D, format[bpp-1], width, height))
|
||||
{
|
||||
NazaraError("Failed to create image");
|
||||
stbi_image_free(ptr);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
resource->Update(ptr);
|
||||
stbi_image_free(ptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzLoader_STB_IsMemoryLoadingSupported(const void* data, unsigned int size, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
int width, height, bpp;
|
||||
return stbi_info_from_memory(static_cast<const stbi_uc*>(data), size, &width, &height, &bpp);
|
||||
}
|
||||
|
||||
bool NzLoader_STB_IsStreamLoadingSupported(NzInputStream& stream, const NzImageParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
int width, height, bpp;
|
||||
return stbi_info_from_callbacks(&callbacks, &stream, &width, &height, &bpp);
|
||||
}
|
||||
}
|
||||
|
||||
void NzLoaders_STB_Register()
|
||||
{
|
||||
NzImage::RegisterFileLoader("bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga", NzLoader_STB_LoadFile);
|
||||
NzImage::RegisterMemoryLoader(NzLoader_STB_IsMemoryLoadingSupported, NzLoader_STB_LoadMemory);
|
||||
NzImage::RegisterStreamLoader(NzLoader_STB_IsStreamLoadingSupported, NzLoader_STB_LoadStream);
|
||||
}
|
||||
|
||||
void NzLoaders_STB_Unregister()
|
||||
{
|
||||
NzImage::UnregisterStreamLoader(NzLoader_STB_IsStreamLoadingSupported, NzLoader_STB_LoadStream);
|
||||
NzImage::UnregisterMemoryLoader(NzLoader_STB_IsMemoryLoadingSupported, NzLoader_STB_LoadMemory);
|
||||
NzImage::UnregisterFileLoader("bmp, gif, hdr, jpg, jpeg, pic, png, psd, tga", NzLoader_STB_LoadFile);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
// 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_LOADERS_STB_HPP
|
||||
#define NAZARA_LOADERS_STB_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
void NzLoaders_STB_Register();
|
||||
void NzLoaders_STB_Unregister();
|
||||
|
||||
#endif // NAZARA_LOADERS_STB_HPP
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Utility/Resource.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzResource::NzResource(bool persistent) :
|
||||
m_resourcePersistent(persistent),
|
||||
|
|
@ -12,6 +13,12 @@ m_resourceReferenceCount(0)
|
|||
{
|
||||
}
|
||||
|
||||
NzResource::NzResource(const NzResource& resource) :
|
||||
m_resourcePersistent(resource.m_resourcePersistent),
|
||||
m_resourceReferenceCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
NzResource::~NzResource() = default;
|
||||
|
||||
void NzResource::AddResourceReference() const
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
// 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
|
||||
|
||||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Loaders/PCX.hpp>
|
||||
#include <Nazara/Utility/Loaders/STB.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzUtility::NzUtility()
|
||||
{
|
||||
}
|
||||
|
||||
NzUtility::~NzUtility()
|
||||
{
|
||||
if (s_initialized)
|
||||
Uninitialize();
|
||||
}
|
||||
|
||||
bool NzUtility::Initialize()
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (s_initialized)
|
||||
{
|
||||
NazaraError("Renderer already initialized");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Loaders spécialisés
|
||||
NzLoaders_PCX_Register(); // Loader de fichiers .PCX (1, 4, 8, 24)
|
||||
|
||||
// Loaders génériques (En dernier pour donner la priorité aux loaders spécialisés)
|
||||
NzLoaders_STB_Register(); // Loader générique (STB)
|
||||
|
||||
s_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzUtility::Uninitialize()
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!s_initialized)
|
||||
{
|
||||
NazaraError("Utility not initialized");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
NzLoaders_STB_Unregister();
|
||||
NzLoaders_PCX_Unregister();
|
||||
}
|
||||
|
||||
bool NzUtility::IsInitialized()
|
||||
{
|
||||
return s_initialized;
|
||||
}
|
||||
|
||||
bool NzUtility::s_initialized = false;
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Core/ThreadCondition.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <cstdio>
|
||||
#include <windowsx.h>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
|
|
|||
Loading…
Reference in New Issue