Added formats conversion

Functor, NonCopyable, Tuple are now parts of NazaraCore (NazaraCore no
longer needs NazaraUtility)
Added loadFormat image parameter (ask loader to load image in specific
format)
Fixed utility project building
It is now possible to convert, get validity or get name of pixel formats
Changed endianness macros' name
Removed useless NazaraEndianness macro
Removed unused files
This commit is contained in:
Lynix
2012-05-24 18:55:48 +02:00
parent 570e0a8070
commit b243d15c74
40 changed files with 1609 additions and 150 deletions

View File

@@ -1,45 +0,0 @@
// 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_FUNCTOR_HPP
#define NAZARA_FUNCTOR_HPP
#include <Nazara/Utility/Tuple.hpp>
// Inspiré du code de la SFML par Laurent Gomila
struct NzFunctor
{
virtual ~NzFunctor() {}
virtual void Run() = 0;
};
template<typename F> struct NzFunctorWithoutArgs : NzFunctor
{
NzFunctorWithoutArgs(F func);
void Run();
F function;
};
template<typename F, typename... Args> struct NzFunctorWithArgs : NzFunctor
{
NzFunctorWithArgs(F func, Args&... args);
void Run();
F function;
std::tuple<Args...> arguments;
};
template<typename F> struct NzFunctorWithoutArgs;
template<typename F, typename... Args> struct NzFunctorWithArgs;
#include <Nazara/Utility/Functor.inl>
#endif // NAZARA_FUNCTOR_HPP

View File

@@ -1,24 +0,0 @@
// 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
template<typename F> NzFunctorWithoutArgs<F>::NzFunctorWithoutArgs(F func) :
function(func)
{
}
template<typename F> void NzFunctorWithoutArgs<F>::Run()
{
function();
}
template<typename F, typename... Args> NzFunctorWithArgs<F, Args...>::NzFunctorWithArgs(F func, Args&... args) :
function(func),
arguments(args...)
{
}
template<typename F, typename... Args> void NzFunctorWithArgs<F, Args...>::Run()
{
NzUnpackTuple(function, arguments);
}

View File

@@ -35,12 +35,21 @@ enum nzImageType
struct NzImageParams
{
// GCC 4.7 je te veux
NzImageParams() :
loadFormat(nzPixelFormat_Undefined)
{
}
nzPixelFormat loadFormat;
bool IsValid() const
{
return true;
return loadFormat == nzPixelFormat_Undefined || NzPixelFormat::IsValid(loadFormat);
}
};
///TODO: Animations ?
///TODO: Filtres
///TODO: Mipmaps
@@ -55,6 +64,8 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
NzImage(SharedImage* sharedImage);
~NzImage();
bool Convert(nzPixelFormat format);
bool Copy(const NzImage& source, const NzRectui& srcRect, const NzVector2ui& dstPos);
bool CopyToFace(nzCubemapFace face, const NzImage& source, const NzRectui& srcRect, const NzVector2ui& dstPos);

View File

@@ -1,20 +0,0 @@
// 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_NONCOPYABLE_HPP
#define NAZARA_NONCOPYABLE_HPP
#include <Nazara/Prerequesites.hpp>
class NAZARA_API NzNonCopyable
{
protected:
NzNonCopyable() = default;
NzNonCopyable(const NzNonCopyable&) = delete;
NzNonCopyable& operator=(const NzNonCopyable&) = delete;
};
#endif // NAZARA_NONCOPYABLE_HPP

View File

@@ -8,31 +8,65 @@
#define NAZARA_PIXELFORMAT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
enum nzPixelFormat
{
nzPixelFormat_Undefined,
nzPixelFormat_B8G8R8,
nzPixelFormat_B8G8R8A8,
nzPixelFormat_BGR8,
nzPixelFormat_BGRA8,
nzPixelFormat_DXT1,
nzPixelFormat_DXT3,
nzPixelFormat_DXT5,
nzPixelFormat_L8,
nzPixelFormat_L8A8,
nzPixelFormat_R4G4A4A4,
nzPixelFormat_R5G5A5A1,
nzPixelFormat_R8,
nzPixelFormat_R8G8,
nzPixelFormat_R8G8B8,
nzPixelFormat_R8G8B8A8
nzPixelFormat_LA8,
/*
nzPixelFormat_RGB16F,
nzPixelFormat_RGB16I,
nzPixelFormat_RGB32F,
nzPixelFormat_RGB32I,
*/
nzPixelFormat_RGBA16F,
nzPixelFormat_RGBA16I,
/*
nzPixelFormat_RGBA32F,
nzPixelFormat_RGBA32I,
*/
nzPixelFormat_RGBA4,
nzPixelFormat_RGB5A1,
nzPixelFormat_RGB8,
nzPixelFormat_RGBA8,
nzPixelFormat_Count
};
class NzUtility;
class NzPixelFormat
{
friend class NzUtility;
public:
typedef nzUInt8* (*ConvertFunction)(const nzUInt8* start, const nzUInt8* end, nzUInt8* dst);
static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst);
static bool Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst);
static nzUInt8 GetBPP(nzPixelFormat format);
static bool IsCompressed(nzPixelFormat format);
static bool IsValid(nzPixelFormat format);
static void SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction);
static NzString ToString(nzPixelFormat format);
private:
static bool Initialize();
static void Uninitialize();
static ConvertFunction s_convertFunctions[nzPixelFormat_Count][nzPixelFormat_Count];
};
#include <Nazara/Utility/PixelFormat.inl>

View File

@@ -2,19 +2,76 @@
// 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>
#include <Nazara/Core/Error.hpp>
#include <cstring>
#include <Nazara/Utility/Debug.hpp>
inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* src, void* dst)
{
if (srcFormat == dstFormat)
{
std::memcpy(dst, src, GetBPP(srcFormat));
return true;
}
#if NAZARA_UTILITY_SAFE
if (IsCompressed(srcFormat))
{
NazaraError("Cannot convert single pixel from compressed format");
return false;
}
if (IsCompressed(dstFormat))
{
NazaraError("Cannot convert single pixel to compressed format");
return false;
}
#endif
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
if (!func)
{
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " not supported");
return false;
}
func(static_cast<const nzUInt8*>(src), static_cast<const nzUInt8*>(src) + GetBPP(srcFormat), static_cast<nzUInt8*>(dst));
return true;
}
inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFormat, const void* start, const void* end, void* dst)
{
if (srcFormat == dstFormat)
{
std::memcpy(dst, start, static_cast<const nzUInt8*>(end)-static_cast<const nzUInt8*>(start));
return true;
}
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
if (!func)
{
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " not supported");
return false;
}
func(static_cast<const nzUInt8*>(start), static_cast<const nzUInt8*>(end), static_cast<nzUInt8*>(dst));
return true;
}
inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_Count:
case nzPixelFormat_Undefined:
return 0;
case nzPixelFormat_B8G8R8:
case nzPixelFormat_BGR8:
return 3;
case nzPixelFormat_B8G8R8A8:
case nzPixelFormat_BGRA8:
return 4;
case nzPixelFormat_DXT1:
@@ -29,28 +86,48 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
case nzPixelFormat_L8:
return 1;
case nzPixelFormat_L8A8:
case nzPixelFormat_LA8:
return 2;
/*
case nzPixelFormat_RGB16F:
return 6;
case nzPixelFormat_RGB16I:
return 6;
case nzPixelFormat_RGB32F:
return 12;
case nzPixelFormat_RGB32I:
return 12;
*/
case nzPixelFormat_RGBA16F:
return 8;
case nzPixelFormat_RGBA16I:
return 8;
/*
case nzPixelFormat_RGBA32F:
return 16;
case nzPixelFormat_RGBA32I:
return 16;
*/
case nzPixelFormat_RGBA4:
return 2;
case nzPixelFormat_R4G4A4A4:
case nzPixelFormat_RGB5A1:
return 2;
case nzPixelFormat_R5G5A5A1:
return 2;
case nzPixelFormat_R8:
return 1;
case nzPixelFormat_R8G8:
return 2;
case nzPixelFormat_R8G8B8:
case nzPixelFormat_RGB8:
return 3;
case nzPixelFormat_R8G8B8A8:
case nzPixelFormat_RGBA8:
return 4;
}
NazaraInternalError("Invalid pixel format");
return 0;
}
@@ -68,4 +145,92 @@ inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
}
}
#include <Nazara/Core/DebugOff.hpp>
inline bool NzPixelFormat::IsValid(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_Count:
case nzPixelFormat_Undefined:
return false;
default:
return true;
}
}
inline void NzPixelFormat::SetConvertFunction(nzPixelFormat srcFormat, nzPixelFormat dstFormat, ConvertFunction func)
{
s_convertFunctions[srcFormat][dstFormat] = func;
}
inline NzString NzPixelFormat::ToString(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_BGR8:
return "BGR8";
case nzPixelFormat_BGRA8:
return "BGRA8";
case nzPixelFormat_DXT1:
return "DXT1";
case nzPixelFormat_DXT3:
return "DXT3";
case nzPixelFormat_DXT5:
return "DXT5";
case nzPixelFormat_L8:
return "L8";
case nzPixelFormat_LA8:
return "LA8";
/*
case nzPixelFormat_RGB16F:
return "RGB16F";
case nzPixelFormat_RGB16I:
return "RGB16I";
case nzPixelFormat_RGB32F:
return "RGB32F";
case nzPixelFormat_RGB32I:
return "RGB32I";
*/
case nzPixelFormat_RGBA16F:
return "RGBA16F";
case nzPixelFormat_RGBA16I:
return "RGBA16I";
/*
case nzPixelFormat_RGBA32F:
return "RGBA32F";
case nzPixelFormat_RGBA32I:
return "RGBA32I";
*/
case nzPixelFormat_RGBA4:
return "RGBA4";
case nzPixelFormat_RGB5A1:
return "RGB5A1";
case nzPixelFormat_RGB8:
return "RGB8";
case nzPixelFormat_RGBA8:
return "RGBA8";
default:
NazaraInternalError("Invalid pixel format");
case nzPixelFormat_Count:
case nzPixelFormat_Undefined:
return "Invalid format";
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -1,16 +0,0 @@
// 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_TUPLE_HPP
#define NAZARA_TUPLE_HPP
#include <tuple>
template<typename F, typename... ArgsT> void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t);
#include <Nazara/Utility/Tuple.inl>
#endif // NAZARA_TUPLE_HPP

View File

@@ -1,35 +0,0 @@
// 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
// http://stackoverflow.com/questions/687490/c0x-how-do-i-expand-a-tuple-into-variadic-template-function-arguments
// Merci à Ryan "FullMetal Alchemist" Lahfa
// Merci aussi à Freedom de siteduzero.com
#include <Nazara/Utility/Debug.hpp>
template<unsigned int N> struct NzTupleUnpack
{
template <typename F, typename... ArgsT, typename... Args>
void operator()(F func, const std::tuple<ArgsT...>& t, Args&... args)
{
NzTupleUnpack<N-1>()(func, t, std::get<N-1>(t), args...);
}
};
template<> struct NzTupleUnpack<0>
{
template <typename F, typename... ArgsT, typename... Args>
void operator()(F func, const std::tuple<ArgsT...>&, Args&... args)
{
func(args...);
}
};
template<typename F, typename... ArgsT>
void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t )
{
NzTupleUnpack<sizeof...(ArgsT)>()(func, t);
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -10,11 +10,11 @@
#define NAZARA_WINDOW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
#include <Nazara/Utility/VideoMode.hpp>
#include <Nazara/Utility/WindowHandle.hpp>
#include <queue>