NzImage now handles mipmaps

Added NzRenderer::SetClearColor(const Color&)
Added describe comment for pixel formats
Fixed NzPixelFormat conversion for RGBA4 and RGB5A1 types
Fixed NzRenderer::Clear prototype
Renamed NzLock to NzLockGuard
ResourceLoader's loaders are now tested from newest to oldest
This commit is contained in:
Lynix
2012-05-30 18:10:17 +02:00
parent f39e2f7d36
commit b220e00c88
17 changed files with 591 additions and 221 deletions

View File

@@ -40,10 +40,10 @@ class NzColor
static NzColor FromXYZ(float x, float y, float z);
static void ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow);
static void ToCMYK(const NzColor& color, float* cyan, float* magenta, float* yellow, float* black);
static void ToXYZ(const NzColor& color, NzVector3f* vec);
static void ToXYZ(const NzColor& color, float* x, float* y, float* z);
static void ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturation, nzUInt8* lightness);
static void ToHSV(const NzColor& color, nzUInt8* hue, nzUInt8* saturation, float* value);
static void ToXYZ(const NzColor& color, NzVector3f* vec);
static void ToXYZ(const NzColor& color, float* x, float* y, float* z);
nzUInt8 r, g, b, a;

View File

@@ -4,21 +4,21 @@
#pragma once
#ifndef NAZARA_LOCK_HPP
#define NAZARA_LOCK_HPP
#ifndef NAZARA_LOCKGUARD_HPP
#define NAZARA_LOCKGUARD_HPP
#include <Nazara/Prerequesites.hpp>
class NzMutex;
class NAZARA_API NzLock
class NAZARA_API NzLockGuard
{
public:
NzLock(NzMutex& mutex);
~NzLock();
NzLockGuard(NzMutex& mutex);
~NzLockGuard();
private:
NzMutex& m_mutex;
};
#endif // NAZARA_LOCK_HPP
#endif // NAZARA_LOCKGUARD_HPP

View File

@@ -24,10 +24,10 @@
(NAZARA_THREADSAFETY_STRING && defined(NAZARA_CLASS_STRING)) || \
(NAZARA_THREADSAFETY_STRINGSTREAM && defined(NAZARA_CLASS_STRINGSTREAM)))
#include <Nazara/Core/Lock.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Mutex.hpp>
#define NazaraLock(mutex) NzLock lock_mutex(mutex);
#define NazaraLock(mutex) NzLockGuard lock_mutex(mutex);
#define NazaraMutex(name) NzMutex name;
#define NazaraMutexAttrib(name, attribute) attribute NzMutex name;
#define NazaraMutexLock(mutex) mutex.Lock();

View File

@@ -44,6 +44,7 @@ enum nzRendererClear
nzRendererClear_Stencil = 0x04
};
class NzColor;
class NzIndexBuffer;
class NzRenderTarget;
class NzShader;
@@ -57,7 +58,7 @@ class NAZARA_API NzRenderer
NzRenderer();
~NzRenderer();
void Clear(nzRendererClear flags);
void Clear(unsigned long flags = nzRendererClear_Color | nzRendererClear_Depth);
void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount);
void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount);
@@ -69,6 +70,7 @@ class NAZARA_API NzRenderer
bool HasCapability(nzRendererCap capability) const;
bool Initialize();
void SetClearColor(const NzColor& color);
void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255);
void SetClearDepth(double depth);
void SetClearStencil(unsigned int value);

View File

@@ -50,9 +50,7 @@ struct NzImageParams
}
};
///TODO: Animations ?
///TODO: Filtres
///TODO: Mipmaps
class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, NzImageParams>
{
@@ -70,20 +68,23 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
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);
bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1);
void Destroy();
nzUInt8 GetBPP() const;
const nzUInt8* GetConstPixels() const;
unsigned int GetDepth() const;
const nzUInt8* GetConstPixels(nzUInt8 level = 0) const;
unsigned int GetDepth(nzUInt8 level = 0) const;
nzPixelFormat GetFormat() const;
unsigned int GetHeight() const;
unsigned int GetHeight(nzUInt8 level = 0) const;
nzUInt8 GetLevelCount() const;
nzUInt8 GetMaxLevel() const;
NzColor GetPixel(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
NzColor GetPixelFace(nzCubemapFace face, unsigned int x, unsigned int y) const;
nzUInt8* GetPixels();
nzUInt8* GetPixels(nzUInt8 level = 0);
unsigned int GetSize() const;
unsigned int GetSize(nzUInt8 level) const;
nzImageType GetType() const;
unsigned int GetWidth() const;
unsigned int GetWidth(nzUInt8 level = 0) const;
bool IsCompressed() const;
bool IsCubemap() const;
@@ -93,18 +94,20 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams());
bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams());
bool SetLevelCount(nzUInt8 levelCount);
bool SetPixel(const NzColor& color, unsigned int x, unsigned int y = 0, unsigned int z = 0);
bool SetPixelFace(const NzColor& color, nzCubemapFace face, unsigned int x, unsigned int y);
bool SetPixelFace(nzCubemapFace face, const NzColor& color, unsigned int x, unsigned int y);
bool Update(const nzUInt8* pixels);
bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0);
//bool Update(const nzUInt8* pixels, const NzCubeui& cube);
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels);
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect);
bool Update(const nzUInt8* pixels, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0);
//bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level = 0);
NzImage& operator=(const NzImage& image);
NzImage& operator=(NzImage&& image);
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
static void RegisterFileLoader(const NzString& extensions, LoadFileFunction loadFile);
static void RegisterMemoryLoader(IsMemoryLoadingSupportedFunction isLoadingSupported, LoadMemoryFunction loadMemory);
static void RegisterStreamLoader(IsStreamLoadingSupportedFunction isLoadingSupported, LoadStreamFunction loadStream);
@@ -119,9 +122,10 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
{
}
SharedImage(unsigned short RefCount, nzImageType Type, nzPixelFormat Format, nzUInt8* Pixels, unsigned int Width, unsigned int Height = 1, unsigned int Depth = 1) :
SharedImage(unsigned short RefCount, nzImageType Type, nzPixelFormat Format, nzInt8 LevelCount = 1, nzUInt8** Pixels = nullptr, unsigned int Width = 1, unsigned int Height = 1, unsigned int Depth = 1) :
type(Type),
format(Format),
levelCount(LevelCount),
pixels(Pixels),
depth(Depth),
height(Height),
@@ -132,7 +136,8 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
nzImageType type;
nzPixelFormat format;
nzUInt8* pixels;
nzUInt8 levelCount;
nzUInt8** pixels;
unsigned int depth;
unsigned int height;
unsigned int width;

View File

@@ -14,29 +14,27 @@ enum nzPixelFormat
{
nzPixelFormat_Undefined,
nzPixelFormat_BGR8,
nzPixelFormat_BGRA8,
nzPixelFormat_BGR8, // 3*nzUInt8
nzPixelFormat_BGRA8, // 4*nzUInt8
nzPixelFormat_DXT1,
nzPixelFormat_DXT3,
nzPixelFormat_DXT5,
nzPixelFormat_L8,
nzPixelFormat_LA8,
nzPixelFormat_L8, // 1*nzUInt8
nzPixelFormat_LA8, // 2*nzUInt8
/*
nzPixelFormat_RGB16F,
nzPixelFormat_RGB16I,
nzPixelFormat_RGB16I, // 4*nzUInt16
nzPixelFormat_RGB32F,
nzPixelFormat_RGB32I,
*/
nzPixelFormat_RGB32I, // 4*nzUInt32
nzPixelFormat_RGBA16F,
nzPixelFormat_RGBA16I,
/*
nzPixelFormat_RGBA16I, // 4*nzUInt16
nzPixelFormat_RGBA32F,
nzPixelFormat_RGBA32I,
nzPixelFormat_RGBA32I, // 4*nzUInt32
*/
nzPixelFormat_RGBA4,
nzPixelFormat_RGB5A1,
nzPixelFormat_RGB8,
nzPixelFormat_RGBA8,
nzPixelFormat_RGBA4, // 1*nzUInt16
nzPixelFormat_RGB5A1, // 1*nzUInt16
nzPixelFormat_RGB8, // 3*nzUInt8
nzPixelFormat_RGBA8, // 4*nzUInt8
nzPixelFormat_Count
};
@@ -56,6 +54,7 @@ class NzPixelFormat
static nzUInt8 GetBPP(nzPixelFormat format);
static bool IsCompressed(nzPixelFormat format);
static bool IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat);
static bool IsValid(nzPixelFormat format);
static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction);

View File

@@ -31,11 +31,15 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
if (!func)
{
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " not supported");
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported");
return false;
}
func(static_cast<const nzUInt8*>(src), static_cast<const nzUInt8*>(src) + GetBPP(srcFormat), static_cast<nzUInt8*>(dst));
if (!func(static_cast<const nzUInt8*>(src), static_cast<const nzUInt8*>(src) + GetBPP(srcFormat), static_cast<nzUInt8*>(dst)))
{
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed");
return false;
}
return true;
}
@@ -51,11 +55,15 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
if (!func)
{
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " not supported");
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported");
return false;
}
func(static_cast<const nzUInt8*>(start), static_cast<const nzUInt8*>(end), static_cast<nzUInt8*>(dst));
if (!func(static_cast<const nzUInt8*>(start), static_cast<const nzUInt8*>(end), static_cast<nzUInt8*>(dst)))
{
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed");
return false;
}
return true;
}
@@ -100,13 +108,13 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
case nzPixelFormat_RGB32I:
return 12;
*/
case nzPixelFormat_RGBA16F:
return 8;
case nzPixelFormat_RGBA16I:
return 8;
/*
case nzPixelFormat_RGBA32F:
return 16;
@@ -145,6 +153,14 @@ inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
}
}
inline bool NzPixelFormat::IsConversionSupported(nzPixelFormat srcFormat, nzPixelFormat dstFormat)
{
if (srcFormat == dstFormat)
return true;
return s_convertFunctions[srcFormat][dstFormat] != nullptr;
}
inline bool NzPixelFormat::IsValid(nzPixelFormat format)
{
switch (format)
@@ -199,13 +215,13 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format)
case nzPixelFormat_RGB32I:
return "RGB32I";
*/
case nzPixelFormat_RGBA16F:
return "RGBA16F";
case nzPixelFormat_RGBA16I:
return "RGBA16I";
/*
case nzPixelFormat_RGBA32F:
return "RGBA32F";

View File

@@ -35,14 +35,20 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromFile(Type* resource, co
return false;
}
for (auto it = range.first; it != range.second; ++it)
// range.second est un itérateur vers l'élément après le dernier élémént du range
auto it = range.second;
do
{
it--;
// Chargement de la ressource
if (it->second(resource, filePath, parameters))
return true;
NazaraWarning("Loader failed");
}
while (it != range.first);
NazaraError("Failed to load file: all loaders failed");
@@ -66,7 +72,7 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromMemory(Type* resource,
}
#endif
for (auto loader = s_memoryLoaders.begin(); loader != s_memoryLoaders.end(); ++loader)
for (auto loader = s_memoryLoaders.rbegin(); loader != s_memoryLoaders.rend(); ++loader)
{
// Le loader supporte-t-il les données ?
if (!loader->first(data, size, parameters))
@@ -101,7 +107,7 @@ bool NzResourceLoader<Type, Parameters>::LoadResourceFromStream(Type* resource,
#endif
nzUInt64 streamPos = stream.GetCursorPos();
for (auto loader = s_streamLoaders.begin(); loader != s_streamLoaders.end(); ++loader)
for (auto loader = s_streamLoaders.rbegin(); loader != s_streamLoaders.rend(); ++loader)
{
stream.SetCursorPos(streamPos);
@@ -164,7 +170,6 @@ void NzResourceLoader<Type, Parameters>::UnregisterResourceFileLoader(const NzSt
}
}
}
//s_fileLoaders.erase(std::make_pair(ext, loadFile));
}
template<typename Type, typename Parameters>