Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -1,27 +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_SOUND_HPP
|
||||
#define NAZARA_SOUND_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
|
||||
class NAZARA_API NzSound
|
||||
{
|
||||
public:
|
||||
NzSound();
|
||||
~NzSound();
|
||||
|
||||
bool LoadFromFile(const NzString& filePath);
|
||||
bool LoadFromMemory(const nzUInt8* ptr, std::size_t size);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // NAZARA_SOUND_HPP
|
||||
68
include/Nazara/Core/Color.hpp
Normal file
68
include/Nazara/Core/Color.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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_COLOR_HPP
|
||||
#define NAZARA_COLOR_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
class NzColor
|
||||
{
|
||||
public:
|
||||
NzColor();
|
||||
NzColor(nzUInt8 red, nzUInt8 green, nzUInt8 blue, nzUInt8 alpha = 255);
|
||||
explicit NzColor(nzUInt8 lightness);
|
||||
NzColor(nzUInt8 color[3], nzUInt8 alpha = 255);
|
||||
NzColor(const NzColor& color) = default;
|
||||
~NzColor() = default;
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
NzColor operator+(const NzColor& angles) const;
|
||||
NzColor operator*(const NzColor& angles) const;
|
||||
|
||||
NzColor operator+=(const NzColor& angles);
|
||||
NzColor operator*=(const NzColor& angles);
|
||||
|
||||
bool operator==(const NzColor& angles) const;
|
||||
bool operator!=(const NzColor& angles) const;
|
||||
|
||||
static NzColor FromCMY(float cyan, float magenta, float yellow);
|
||||
static NzColor FromCMYK(float cyan, float magenta, float yellow, float black);
|
||||
static NzColor FromHSL(nzUInt8 hue, nzUInt8 saturation, nzUInt8 lightness);
|
||||
static NzColor FromHSV(nzUInt8 hue, nzUInt8 saturation, float value);
|
||||
static NzColor FromXYZ(const NzVector3f& vec);
|
||||
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 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;
|
||||
|
||||
static NAZARA_API const NzColor Black;
|
||||
static NAZARA_API const NzColor Blue;
|
||||
static NAZARA_API const NzColor Cyan;
|
||||
static NAZARA_API const NzColor Green;
|
||||
static NAZARA_API const NzColor Magenta;
|
||||
static NAZARA_API const NzColor Orange;
|
||||
static NAZARA_API const NzColor Red;
|
||||
static NAZARA_API const NzColor Yellow;
|
||||
static NAZARA_API const NzColor White;
|
||||
|
||||
private:
|
||||
static float Hue2RGB(float v1, float v2, float vH);
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const NzColor& color);
|
||||
|
||||
#include <Nazara/Core/Color.inl>
|
||||
|
||||
#endif // NAZARA_COLOR_HPP
|
||||
410
include/Nazara/Core/Color.inl
Normal file
410
include/Nazara/Core/Color.inl
Normal file
@@ -0,0 +1,410 @@
|
||||
// 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 <cmath>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
inline NzColor::NzColor()
|
||||
{
|
||||
}
|
||||
|
||||
inline NzColor::NzColor(nzUInt8 red, nzUInt8 green, nzUInt8 blue, nzUInt8 alpha) :
|
||||
r(red),
|
||||
g(green),
|
||||
b(blue),
|
||||
a(alpha)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzColor::NzColor(nzUInt8 lightness) :
|
||||
r(lightness),
|
||||
g(lightness),
|
||||
b(lightness),
|
||||
a(255)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzColor::NzColor(nzUInt8 vec[3], nzUInt8 alpha) :
|
||||
r(vec[0]),
|
||||
g(vec[1]),
|
||||
b(vec[2]),
|
||||
a(alpha)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzString NzColor::ToString() const
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << "Color(" << static_cast<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b);
|
||||
|
||||
if (a != 255)
|
||||
ss << ", " << static_cast<int>(a);
|
||||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
inline NzColor NzColor::operator+(const NzColor& color) const
|
||||
{
|
||||
return NzColor(std::min(static_cast<nzUInt16>(r) + color.r, 255),
|
||||
std::min(static_cast<nzUInt16>(r) + color.r, 255),
|
||||
std::min(static_cast<nzUInt16>(r) + color.r, 255),
|
||||
std::min(static_cast<nzUInt16>(r) + color.r, 255));
|
||||
}
|
||||
|
||||
inline NzColor NzColor::operator*(const NzColor& color) const
|
||||
{
|
||||
return NzColor(static_cast<nzUInt16>(r) * color.r/255,
|
||||
static_cast<nzUInt16>(r) * color.r/255,
|
||||
static_cast<nzUInt16>(r) * color.r/255,
|
||||
static_cast<nzUInt16>(r) * color.r/255);
|
||||
}
|
||||
|
||||
inline NzColor NzColor::operator+=(const NzColor& color)
|
||||
{
|
||||
return operator=(operator+(color));
|
||||
}
|
||||
|
||||
inline NzColor NzColor::operator*=(const NzColor& color)
|
||||
{
|
||||
return operator=(operator+(color));
|
||||
}
|
||||
|
||||
inline bool NzColor::operator==(const NzColor& color) const
|
||||
{
|
||||
return r == color.r && g == color.g && b == color.b && a == color.a;
|
||||
}
|
||||
|
||||
inline bool NzColor::operator!=(const NzColor& color) const
|
||||
{
|
||||
return !operator==(color);
|
||||
}
|
||||
|
||||
// Algorithmes venant de http://www.easyrgb.com/index.php?X=MATH
|
||||
|
||||
inline NzColor NzColor::FromCMY(float cyan, float magenta, float yellow)
|
||||
{
|
||||
return NzColor((1.f-cyan)*255.f, (1.f-magenta)*255.f, (1.f-yellow)*255.f);
|
||||
}
|
||||
|
||||
inline NzColor NzColor::FromCMYK(float cyan, float magenta, float yellow, float black)
|
||||
{
|
||||
return FromCMY(cyan * (1.f - black) + black,
|
||||
magenta * (1.f - black) + black,
|
||||
yellow * (1.f - black) + black);
|
||||
}
|
||||
|
||||
inline NzColor NzColor::FromHSL(nzUInt8 hue, nzUInt8 saturation, nzUInt8 lightness)
|
||||
{
|
||||
// Norme Windows
|
||||
float l = lightness/240.f;
|
||||
|
||||
if (saturation == 0)
|
||||
{
|
||||
// RGB results from 0 to 255
|
||||
return NzColor(lightness * 255.f,
|
||||
lightness * 255.f,
|
||||
lightness * 255.f);
|
||||
}
|
||||
else
|
||||
{
|
||||
float h = hue/240.f;
|
||||
float s = saturation/240.f;
|
||||
|
||||
float v2;
|
||||
if (l < 0.5f)
|
||||
v2 = l * (1.f + s);
|
||||
else
|
||||
v2 = (l + s) - (s*l);
|
||||
|
||||
float v1 = 2.f * l - v2;
|
||||
|
||||
return NzColor(255.f * Hue2RGB(v1, v2, h + (1.f/3.f)),
|
||||
255.f * Hue2RGB(v1, v2, h),
|
||||
255.f * Hue2RGB(v1, v2, h - (1.f/3.f)));
|
||||
}
|
||||
}
|
||||
|
||||
inline NzColor NzColor::FromHSV(nzUInt8 hue, nzUInt8 saturation, float value)
|
||||
{
|
||||
if (saturation == 0)
|
||||
return NzColor(static_cast<nzUInt8>(value * 255.f));
|
||||
else
|
||||
{
|
||||
float h = hue/240.f * 6.f;
|
||||
float s = saturation/240.f;
|
||||
|
||||
if (NzNumberEquals(h, 6.f))
|
||||
h = 0; // hue must be < 1
|
||||
|
||||
int i = h;
|
||||
float v1 = value * (1.f - s);
|
||||
float v2 = value * (1.f - s * (h - i));
|
||||
float v3 = value * (1.f - s * (1.f - (h - i)));
|
||||
|
||||
float r, g, b;
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
r = value;
|
||||
g = v3;
|
||||
b = v1;
|
||||
|
||||
case 1:
|
||||
r = v2;
|
||||
g = value;
|
||||
b = v1;
|
||||
|
||||
case 2:
|
||||
r = v1;
|
||||
g = value;
|
||||
b = v3;
|
||||
|
||||
case 3:
|
||||
r = v1;
|
||||
g = v2;
|
||||
b = value;
|
||||
|
||||
case 4:
|
||||
r = v3;
|
||||
g = v1;
|
||||
b = value;
|
||||
|
||||
default:
|
||||
r = value;
|
||||
g = v1;
|
||||
b = v2;
|
||||
}
|
||||
|
||||
// RGB results from 0 to 255
|
||||
return NzColor(r*255.f, g*255.f, b*255.f);
|
||||
}
|
||||
}
|
||||
inline NzColor NzColor::FromXYZ(const NzVector3f& vec)
|
||||
{
|
||||
return FromXYZ(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
inline NzColor NzColor::FromXYZ(float x, float y, float z)
|
||||
{
|
||||
x /= 100; // X from 0 to 95.047
|
||||
y /= 100; // Y from 0 to 100.000
|
||||
z /= 100; // Z from 0 to 108.883
|
||||
|
||||
double r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
||||
double g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
||||
double b = x * 0.0557 + y * -0.2040 + z * 1.0570;
|
||||
|
||||
if (r > 0.0031308)
|
||||
r = 1.055 * (std::pow(r, 1.0/2.4)) - 0.055;
|
||||
else
|
||||
r *= 12.92;
|
||||
|
||||
if (g > 0.0031308)
|
||||
g = 1.055 * (std::pow(g, 1.0/2.4)) - 0.055;
|
||||
else
|
||||
g *= 12.92;
|
||||
|
||||
if (b > 0.0031308)
|
||||
b = 1.055 * (std::pow(b, 1.0/2.4)) - 0.055;
|
||||
else
|
||||
b *= 12.92;
|
||||
|
||||
return NzColor(r * 255.0, g * 255.0, b * 255.0);
|
||||
}
|
||||
|
||||
inline void NzColor::ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow)
|
||||
{
|
||||
*cyan = 1.f - color.r/255.f;
|
||||
*magenta = 1.f - color.g/255.f;
|
||||
*yellow = 1.f - color.b/255.f;
|
||||
}
|
||||
|
||||
inline void NzColor::ToCMYK(const NzColor& color, float* cyan, float* magenta, float* yellow, float* black)
|
||||
{
|
||||
float c, m, y;
|
||||
ToCMY(color, &c, &m, &y);
|
||||
|
||||
float k = std::min(std::min(std::min(1.f, c), m), y);
|
||||
|
||||
if (NzNumberEquals(k, 1.f))
|
||||
{
|
||||
//Black
|
||||
*cyan = 0.f;
|
||||
*magenta = 0.f;
|
||||
*yellow = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
*cyan = (c-k)/(1.f-k);
|
||||
*magenta = (m-k)/(1.f-k);
|
||||
*yellow = (y-k)/(1.f-k);
|
||||
}
|
||||
|
||||
*black = k;
|
||||
}
|
||||
|
||||
inline void NzColor::ToHSL(const NzColor& color, nzUInt8* hue, nzUInt8* saturation, nzUInt8* lightness)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
float g = color.g / 255.f;
|
||||
float b = color.b / 255.f;
|
||||
|
||||
float min = std::min(std::min(r, g), b); // Min. value of RGB
|
||||
float max = std::max(std::max(r, g), b); // Max. value of RGB
|
||||
|
||||
float deltaMax = max - min; //Delta RGB value
|
||||
|
||||
float l = (max + min)/2.f;
|
||||
|
||||
if (NzNumberEquals(deltaMax, 0.f))
|
||||
{
|
||||
//This is a gray, no chroma...
|
||||
*hue = 0; //HSL results from 0 to 1
|
||||
*saturation = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Chromatic data...
|
||||
if (l < 0.5f)
|
||||
*saturation = deltaMax/(max+min)*240.f;
|
||||
else
|
||||
*saturation = deltaMax/(2.f-max-min)*240.f;
|
||||
|
||||
*lightness = l*240.f;
|
||||
|
||||
float deltaR = ((max - r)/6.f + deltaMax/2.f)/deltaMax;
|
||||
float deltaG = ((max - g)/6.f + deltaMax/2.f)/deltaMax;
|
||||
float deltaB = ((max - b)/6.f + deltaMax/2.f)/deltaMax;
|
||||
|
||||
float h;
|
||||
|
||||
if (NzNumberEquals(r, max))
|
||||
h = deltaB - deltaG;
|
||||
else if (NzNumberEquals(g, max))
|
||||
h = (1.f/3.f) + deltaR - deltaB;
|
||||
else if (NzNumberEquals(b, max))
|
||||
h = (2.f/3.f) + deltaG - deltaR;
|
||||
|
||||
if (h < 0.f)
|
||||
h += 1.f;
|
||||
else if (h > 1.f)
|
||||
h -= 1.f;
|
||||
|
||||
*hue = h*240.f;
|
||||
}
|
||||
}
|
||||
|
||||
inline void NzColor::ToHSV(const NzColor& color, nzUInt8* hue, nzUInt8* saturation, float* value)
|
||||
{
|
||||
float r = color.r / 255.f;
|
||||
float g = color.g / 255.f;
|
||||
float b = color.b / 255.f;
|
||||
|
||||
float min = std::min(std::min(r, g), b); //Min. value of RGB
|
||||
float max = std::max(std::max(r, g), b); //Max. value of RGB
|
||||
|
||||
float deltaMax = max - min; //Delta RGB value
|
||||
|
||||
*value = max;
|
||||
|
||||
if (NzNumberEquals(deltaMax, 0.f))
|
||||
{
|
||||
//This is a gray, no chroma...
|
||||
*hue = 0; //HSV results from 0 to 1
|
||||
*saturation = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Chromatic data...
|
||||
*saturation = deltaMax/max*240.f;
|
||||
|
||||
float deltaR = ((max - r)/6.f + deltaMax/2.f)/deltaMax;
|
||||
float deltaG = ((max - g)/6.f + deltaMax/2.f)/deltaMax;
|
||||
float deltaB = ((max - b)/6.f + deltaMax/2.f)/deltaMax;
|
||||
|
||||
float h;
|
||||
|
||||
if (NzNumberEquals(r, max))
|
||||
h = deltaB - deltaG;
|
||||
else if (NzNumberEquals(g, max))
|
||||
h = (1.f/3.f) + deltaR - deltaB;
|
||||
else if (NzNumberEquals(b, max))
|
||||
h = (2.f/3.f) + deltaG - deltaR;
|
||||
|
||||
if (h < 0.f)
|
||||
h += 1.f;
|
||||
else if (h > 1.f)
|
||||
h -= 1.f;
|
||||
|
||||
*hue = h*240.f;
|
||||
}
|
||||
}
|
||||
|
||||
inline void NzColor::ToXYZ(const NzColor& color, NzVector3f* vec)
|
||||
{
|
||||
return ToXYZ(color, &vec->x, &vec->y, &vec->z);
|
||||
}
|
||||
|
||||
inline void NzColor::ToXYZ(const NzColor& color, float* x, float* y, float* z)
|
||||
{
|
||||
double r = color.r/255.0; //R from 0 to 255
|
||||
double g = color.g/255.0; //G from 0 to 255
|
||||
double b = color.b/255.0; //B from 0 to 255
|
||||
|
||||
if (r > 0.04045)
|
||||
r = std::pow((r + 0.055)/1.055, 2.4);
|
||||
else
|
||||
r /= 12.92;
|
||||
|
||||
if (g > 0.04045)
|
||||
g = std::pow((g + 0.055)/1.055, 2.4);
|
||||
else
|
||||
g /= 12.92;
|
||||
|
||||
if (b > 0.04045)
|
||||
b = std::pow((b + 0.055)/1.055, 2.4);
|
||||
else
|
||||
b /= 12.92;
|
||||
|
||||
r *= 100.0;
|
||||
g *= 100.0;
|
||||
b *= 100.0;
|
||||
|
||||
//Observer. = 2°, Illuminant = D65
|
||||
*x = r*0.4124 + g*0.3576 + b*0.1805;
|
||||
*y = r*0.2126 + g*0.7152 + b*0.0722;
|
||||
*z = r*0.0193 + g*0.1192 + b*0.9505;
|
||||
}
|
||||
|
||||
inline float NzColor::Hue2RGB(float v1, float v2, float vH)
|
||||
{
|
||||
if (vH < 0.f)
|
||||
vH += 1;
|
||||
|
||||
if (vH > 1.f)
|
||||
vH -= 1;
|
||||
|
||||
if ((6.f * vH) < 1.f)
|
||||
return v1 + (v2-v1)*6*vH;
|
||||
|
||||
if ((2.f * vH) < 1.f)
|
||||
return v2;
|
||||
|
||||
if ((3.f * vH) < 2.f)
|
||||
return v1 + (v2 - v1)*(2.f/3.f - vH)*6;
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, const NzColor& color)
|
||||
{
|
||||
return out << color.ToString();
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NAZARA_DYNLIB_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
#define NAZARA_CLASS_DYNLIB
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
|
||||
@@ -9,26 +9,18 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
#if defined(NAZARA_ENDIANNESS_BIGENDIAN)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NazaraEndianness nzEndianness_BigEndian
|
||||
#elif defined(NAZARA_ENDIANNESS_LITTLEENDIAN)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NazaraEndianness nzEndianness_LittleEndian
|
||||
#else
|
||||
#if !defined(NAZARA_BIG_ENDIAN) && !defined(NAZARA_LITTLE_ENDIAN)
|
||||
// Détection automatique selon les macros du compilateur
|
||||
#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
|
||||
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NAZARA_ENDIANNESS_BIGENDIAN
|
||||
#define NazaraEndianness nzEndianness_BigEndian
|
||||
#define NAZARA_BIG_ENDIAN
|
||||
#elif defined(__i386__) || defined(__i386) || defined(__X86__) || defined (__x86_64)
|
||||
#define NAZARA_ENDIANNESS_DETECTED 1
|
||||
#define NAZARA_ENDIANNESS_LITTLEENDIAN
|
||||
#define NazaraEndianness nzEndianness_LittleEndian
|
||||
#define NAZARA_LITTLE_ENDIAN
|
||||
#else
|
||||
#define NAZARA_ENDIANNESS_DETECTED 0
|
||||
#define NazaraEndianness NzGetPlatformEndianness()
|
||||
#error Failed to identify endianness, you must define either NAZARA_BIG_ENDIAN or NAZARA_LITTLE_ENDIAN
|
||||
#endif
|
||||
#elif defined(NAZARA_BIG_ENDIAN) && defined(NAZARA_LITTLE_ENDIAN)
|
||||
#error You cannot define both NAZARA_BIG_ENDIAN and NAZARA_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
enum nzEndianness
|
||||
|
||||
@@ -17,27 +17,11 @@ inline void NzByteSwap(void* buffer, unsigned int size)
|
||||
|
||||
inline nzEndianness NzGetPlatformEndianness()
|
||||
{
|
||||
#if NAZARA_ENDIANNESS_DETECTED
|
||||
return NazaraEndianness;
|
||||
#else
|
||||
static nzEndianness endianness = nzEndianness_Unknown;
|
||||
static bool tested = false;
|
||||
if (!tested)
|
||||
{
|
||||
nzUInt32 i = 1;
|
||||
nzUInt8* p = reinterpret_cast<nzUInt8*>(&i);
|
||||
|
||||
// Méthode de récupération de l'endianness au runtime
|
||||
if (p[0] == 1)
|
||||
endianness = nzEndianness_LittleEndian;
|
||||
else if (p[3] == 1)
|
||||
endianness = nzEndianness_BigEndian;
|
||||
|
||||
tested = true;
|
||||
}
|
||||
|
||||
return endianness;
|
||||
#endif
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
return nzEndianness_BigEndian;
|
||||
#elif defined(NAZARA_LITTLE_ENDIAN)
|
||||
return nzEndianness_LittleEndian;
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
#define NAZARA_CLASS_FILE
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef NAZARA_FUNCTOR_HPP
|
||||
#define NAZARA_FUNCTOR_HPP
|
||||
|
||||
#include <Nazara/Utility/Tuple.hpp>
|
||||
#include <Nazara/Core/Tuple.hpp>
|
||||
|
||||
// Inspiré du code de la SFML par Laurent Gomila
|
||||
|
||||
@@ -40,6 +40,6 @@ template<typename F, typename... Args> struct NzFunctorWithArgs : NzFunctor
|
||||
template<typename F> struct NzFunctorWithoutArgs;
|
||||
template<typename F, typename... Args> struct NzFunctorWithArgs;
|
||||
|
||||
#include <Nazara/Utility/Functor.inl>
|
||||
#include <Nazara/Core/Functor.inl>
|
||||
|
||||
#endif // NAZARA_FUNCTOR_HPP
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <Nazara/Core/HashDigest.hpp>
|
||||
#include <Nazara/Core/HashImpl.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NAZARA_API NzHash : NzNonCopyable
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NAZARA_HASHIMPL_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NzHashDigest;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -9,13 +9,14 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
|
||||
#define NAZARA_CLASS_LOG
|
||||
#include <Nazara/Core/ThreadSafety.hpp>
|
||||
|
||||
#define NazaraLog NzLog::Instance()
|
||||
#define NazaraNotice(txt) NazaraLog->Write(txt)
|
||||
|
||||
class NzFile;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NAZARA_MUTEX_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NzMutexImpl;
|
||||
class NzThreadCondition;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NAZARA_SEMAPHORE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NzSemaphoreImpl;
|
||||
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -25,9 +24,11 @@ class NAZARA_API NzString : public NzHashable
|
||||
public:
|
||||
enum Flags
|
||||
{
|
||||
None = 0x00, // Mode par défaut
|
||||
CaseInsensitive = 0x01, // Insensible à la casse
|
||||
HandleUtf8 = 0x02 // Traite les octets comme une suite de caractères UTF-8
|
||||
None = 0x00, // Mode par défaut
|
||||
CaseInsensitive = 0x01, // Insensible à la casse
|
||||
HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8
|
||||
TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne
|
||||
TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne
|
||||
};
|
||||
|
||||
struct SharedString;
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#define NAZARA_THREAD_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/Functor.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Core/Functor.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NzThreadImpl;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
|
||||
template<typename F, typename... ArgsT> void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t);
|
||||
|
||||
#include <Nazara/Utility/Tuple.inl>
|
||||
#include <Nazara/Core/Tuple.inl>
|
||||
|
||||
#endif // NAZARA_TUPLE_HPP
|
||||
60
include/Nazara/Math/Cube.hpp
Normal file
60
include/Nazara/Math/Cube.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// 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_CUBE_HPP
|
||||
#define NAZARA_CUBE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
template<typename T>
|
||||
class NzCube
|
||||
{
|
||||
public:
|
||||
NzCube();
|
||||
NzCube(T X, T Y, T Z, T Width, T Height, T Depth);
|
||||
NzCube(T cube[6]);
|
||||
NzCube(const NzRect<T>& rect);
|
||||
template<typename U> explicit NzCube(const NzCube<U>& rect);
|
||||
NzCube(const NzCube& rect) = default;
|
||||
~NzCube() = default;
|
||||
|
||||
bool Contains(T X, T Y, T Z) const;
|
||||
bool Contains(const NzVector3<T>& point) const;
|
||||
bool Contains(const NzCube& rect) const;
|
||||
|
||||
void ExtendTo(const NzVector3<T>& point);
|
||||
void ExtendTo(const NzCube& rect);
|
||||
|
||||
NzVector3<T> GetCenter() const;
|
||||
|
||||
bool Intersect(const NzCube& rect) const;
|
||||
bool Intersect(const NzCube& rect, NzCube& 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, z, width, height, depth;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const NzCube<T>& vec);
|
||||
|
||||
typedef NzCube<double> NzCubed;
|
||||
typedef NzCube<float> NzCubef;
|
||||
typedef NzCube<int> NzCubei;
|
||||
typedef NzCube<unsigned int> NzCubeui;
|
||||
|
||||
#include <Nazara/Math/Cube.inl>
|
||||
|
||||
#endif // NAZARA_CUBE_HPP
|
||||
194
include/Nazara/Math/Cube.inl
Normal file
194
include/Nazara/Math/Cube.inl
Normal file
@@ -0,0 +1,194 @@
|
||||
// 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>
|
||||
NzCube<T>::NzCube()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) :
|
||||
x(X),
|
||||
y(Y),
|
||||
z(Z),
|
||||
width(Width),
|
||||
height(Height),
|
||||
depth(Depth)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::NzCube(T vec[6]) :
|
||||
x(vec[0]),
|
||||
y(vec[1]),
|
||||
z(vec[2]),
|
||||
width(vec[3]),
|
||||
height(vec[4]),
|
||||
depth(vec[5])
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::NzCube(const NzRect<T>& rect) :
|
||||
x(rect.x),
|
||||
y(rect.y),
|
||||
z(0),
|
||||
width(rect.width),
|
||||
height(rect.height),
|
||||
depth(1)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
NzCube<T>::NzCube(const NzCube<U>& rect) :
|
||||
x(static_cast<T>(rect.x)),
|
||||
y(static_cast<T>(rect.y)),
|
||||
z(static_cast<T>(rect.z)),
|
||||
width(static_cast<T>(rect.width)),
|
||||
height(static_cast<T>(rect.height)),
|
||||
depth(static_cast<T>(rect.depth))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Contains(T X, T Y, T Z) const
|
||||
{
|
||||
return X >= x && X < x+width &&
|
||||
Y >= y && Y < y+height &&
|
||||
Z >= z && Z < z+depth;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Contains(const NzVector3<T>& point) const
|
||||
{
|
||||
return Contains(point.x, point.y, point.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Contains(const NzCube<T>& rect) const
|
||||
{
|
||||
return Contains(rect.x, rect.y, rect.z) &&
|
||||
Contains(rect.x + rect.width, rect.y + rect.height, rect.z + rect.depth);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzCube<T>::ExtendTo(const NzVector3<T>& point)
|
||||
{
|
||||
x = std::min(x, point.x);
|
||||
y = std::min(y, point.y);
|
||||
z = std::min(z, point.z);
|
||||
width = std::max(x+width, point.x)-x;
|
||||
height = std::max(y+height, point.x)-y;
|
||||
depth = std::max(z+depth, point.x)-z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzCube<T>::ExtendTo(const NzCube& rect)
|
||||
{
|
||||
x = std::min(x, rect.x);
|
||||
y = std::min(y, rect.y);
|
||||
z = std::min(y, rect.z);
|
||||
width = std::max(x+width, rect.x+rect.width)-x;
|
||||
height = std::max(x+height, rect.y+rect.height)-y;
|
||||
depth = std::max(x+depth, rect.z+rect.depth)-z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzCube<T>::GetCenter() const
|
||||
{
|
||||
return NzVector3<T>((x+width)/2, (y+height)/2, (z+depth)/2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Intersect(const NzCube& rect) const
|
||||
{
|
||||
NzCube intersection; // Optimisé par le compilateur
|
||||
return Intersect(rect, intersection);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Intersect(const NzCube& rect, NzCube& 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);
|
||||
T up = std::max(z, rect.z);
|
||||
T down = std::min(z+depth, rect.z+rect.depth);
|
||||
|
||||
if (left < right && top < bottom && up < down)
|
||||
{
|
||||
intersection.x = left;
|
||||
intersection.y = top;
|
||||
intersection.z = up;
|
||||
intersection.width = right-left;
|
||||
intersection.height = bottom-top;
|
||||
intersection.depth = down-up;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::IsValid() const
|
||||
{
|
||||
return width > 0 && height > 0 && depth > 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzString NzCube<T>::ToString() const
|
||||
{
|
||||
NzStringStream ss;
|
||||
|
||||
return ss << "Cube(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::operator NzString() const
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& NzCube<T>::operator[](unsigned int i)
|
||||
{
|
||||
if (i >= 6)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzCube<T>::operator[](unsigned int i) const
|
||||
{
|
||||
if (i >= 6)
|
||||
{
|
||||
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 NzCube<T>& rect)
|
||||
{
|
||||
return out << rect.ToString();
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -96,17 +96,12 @@ template<typename T> class NzMatrix4
|
||||
|
||||
struct SharedMatrix
|
||||
{
|
||||
SharedMatrix() : // Vivement GCC 4.7 sur Windows
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
T m11, m12, m13, m14;
|
||||
T m21, m22, m23, m24;
|
||||
T m31, m32, m33, m34;
|
||||
T m41, m42, m43, m44;
|
||||
|
||||
unsigned short refCount;
|
||||
unsigned short refCount = 1;
|
||||
NazaraMutex(mutex)
|
||||
};
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ NzMatrix4<T> NzMatrix4<T>::GetInverse() const
|
||||
NzMatrix4 matrix;
|
||||
T det = GetDeterminant();
|
||||
|
||||
if (det != 0.0)
|
||||
if (!NzNumberEquals(det, static_cast<T>(0.0)))
|
||||
{
|
||||
matrix(0, 0) = (m_sharedMatrix->m22 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m34 * m_sharedMatrix->m43) - m_sharedMatrix->m32 * (m_sharedMatrix->m23 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m24) + m_sharedMatrix->m42 * (m_sharedMatrix->m23 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m24)) / det;
|
||||
matrix(0, 1) = -(m_sharedMatrix->m12 * (m_sharedMatrix->m33 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m34) - m_sharedMatrix->m32 * (m_sharedMatrix->m13 * m_sharedMatrix->m44 - m_sharedMatrix->m43 * m_sharedMatrix->m14) + m_sharedMatrix->m42 * (m_sharedMatrix->m13 * m_sharedMatrix->m34 - m_sharedMatrix->m33 * m_sharedMatrix->m14)) / det;
|
||||
|
||||
@@ -26,11 +26,13 @@ template<typename T> class NzQuaternion
|
||||
NzQuaternion(const NzQuaternion& quat) = default;
|
||||
~NzQuaternion() = default;
|
||||
|
||||
T DotProduct(const NzQuaternion& vec) const;
|
||||
|
||||
NzQuaternion GetConjugate() const;
|
||||
NzQuaternion GetNormalized() const;
|
||||
|
||||
double Magnitude() const;
|
||||
double Normalize();
|
||||
T Magnitude() const;
|
||||
T Normalize();
|
||||
T SquaredMagnitude() const;
|
||||
|
||||
void Set(T W, T X, T Y, T Z);
|
||||
@@ -53,10 +55,10 @@ template<typename T> class NzQuaternion
|
||||
NzQuaternion operator*(T scale) const;
|
||||
NzQuaternion operator/(const NzQuaternion& quat) const;
|
||||
|
||||
NzQuaternion operator+=(const NzQuaternion& quat);
|
||||
NzQuaternion operator*=(const NzQuaternion& quat);
|
||||
NzQuaternion operator*=(T scale);
|
||||
NzQuaternion operator/=(const NzQuaternion& quat);
|
||||
NzQuaternion& operator+=(const NzQuaternion& quat);
|
||||
NzQuaternion& operator*=(const NzQuaternion& quat);
|
||||
NzQuaternion& operator*=(T scale);
|
||||
NzQuaternion& operator/=(const NzQuaternion& quat);
|
||||
|
||||
bool operator==(const NzQuaternion& quat) const;
|
||||
bool operator!=(const NzQuaternion& quat) const;
|
||||
@@ -65,6 +67,8 @@ template<typename T> class NzQuaternion
|
||||
bool operator>(const NzQuaternion& quat) const;
|
||||
bool operator>=(const NzQuaternion& quat) const;
|
||||
|
||||
static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp);
|
||||
|
||||
T w, x, y, z;
|
||||
};
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ NzQuaternion<T>::NzQuaternion(const NzQuaternion<U>& quat)
|
||||
Set(quat);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzQuaternion<T>::DotProduct(const NzQuaternion& vec) const
|
||||
{
|
||||
return w*vec.w + x*vec.x + y*vec.y + z.vec.z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::GetConjugate() const
|
||||
{
|
||||
@@ -68,25 +74,29 @@ NzQuaternion<T> NzQuaternion<T>::GetNormalized() const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzQuaternion<T>::Magnitude() const
|
||||
T NzQuaternion<T>::Magnitude() const
|
||||
{
|
||||
return std::sqrt(SquaredMagnitude());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzQuaternion<T>::Normalize()
|
||||
T NzQuaternion<T>::Normalize()
|
||||
{
|
||||
double length = Magnitude();
|
||||
T squaredLength = SquaredMagnitude();
|
||||
|
||||
if (length != 0.0)
|
||||
if (std::fabs(squaredLength) > 0.00001 && std::fabs(squaredLength - 1.0) > 0.00001)
|
||||
{
|
||||
T length = std::sqrt(squaredLength);
|
||||
|
||||
w /= length;
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
}
|
||||
|
||||
return length;
|
||||
return length;
|
||||
}
|
||||
else
|
||||
return 1.0; // Le quaternion est déjà normalisé
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -167,9 +177,55 @@ void NzQuaternion<T>::SetZero()
|
||||
Set(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp)
|
||||
{
|
||||
if (interp <= 0.0)
|
||||
return quatA;
|
||||
|
||||
if (interp >= 1.0)
|
||||
return quatB;
|
||||
|
||||
NzQuaternion q;
|
||||
|
||||
T cosOmega = quatA.DotProduct(quatB);
|
||||
if (cosOmega < 0.0)
|
||||
{
|
||||
// On inverse tout
|
||||
q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z);
|
||||
cosOmega = -cosOmega;
|
||||
}
|
||||
else
|
||||
q.Set(quatB);
|
||||
|
||||
T k0, k1;
|
||||
if (cosOmega > 0.9999)
|
||||
{
|
||||
// Interpolation linéaire pour éviter une division par zéro
|
||||
k0 = 1.0 - interp;
|
||||
k1 = interp;
|
||||
}
|
||||
else
|
||||
{
|
||||
T sinOmega = std::sqrt(1.0f - (cosOmega * cosOmega));
|
||||
T omega = std::atan2(sinOmega, cosOmega);
|
||||
|
||||
// Pour éviter deux divisions
|
||||
sinOmega = 1/sinOmega;
|
||||
|
||||
k0 = std::sin((1.0 - interp) * omega) * sinOmega;
|
||||
k1 = std::sin(interp * omega) * sinOmega;
|
||||
}
|
||||
|
||||
NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z);
|
||||
return result += q;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzEulerAngles<T> NzQuaternion<T>::ToEulerAngles() const
|
||||
{
|
||||
Normalize();
|
||||
|
||||
T test = x*y + z*w;
|
||||
if (test > 0.499)
|
||||
// singularity at north pole
|
||||
@@ -199,31 +255,31 @@ template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator+(const NzQuaternion& quat) const
|
||||
{
|
||||
return NzQuaternion(w + quat.w,
|
||||
x + quat.x,
|
||||
y + quat.y,
|
||||
z + quat.z);
|
||||
x + quat.x,
|
||||
y + quat.y,
|
||||
z + quat.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator*(const NzQuaternion& quat) const
|
||||
{
|
||||
return NzQuaternion(w * quat.w - x * quat.x - y * quat.y - z * quat.z,
|
||||
w * quat.x + x * quat.w + y * quat.z - z * quat.y,
|
||||
w * quat.y + y * quat.w + z * quat.x - x * quat.z,
|
||||
w * quat.z + z * quat.w + x * quat.y - y * quat.x);
|
||||
w * quat.x + x * quat.w + y * quat.z - z * quat.y,
|
||||
w * quat.y + y * quat.w + z * quat.x - x * quat.z,
|
||||
w * quat.z + z * quat.w + x * quat.y - y * quat.x);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzQuaternion<T>::operator*(const NzVector3<T>& vec) const
|
||||
{
|
||||
NzVector3<T> uv, uuv;
|
||||
NzVector3<T> qvec(x, y, z);
|
||||
uv = qvec.CrossProduct(vec);
|
||||
uuv = qvec.CrossProduct(uv);
|
||||
uv *= 2.0 * w;
|
||||
uuv *= 2.0;
|
||||
NzVector3<T> normal(vec);
|
||||
normal.Normalise();
|
||||
|
||||
NzQuaternion qvec(0.0, normal.x, normal.y, normal.z);
|
||||
NzQuaternion result = operator*(qvec * GetConjugate());
|
||||
|
||||
return NzVector3<T>(result.x, result.y, result.z);
|
||||
|
||||
return vec + uv + uuv;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -242,43 +298,27 @@ NzQuaternion<T> NzQuaternion<T>::operator/(const NzQuaternion& quat) const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator+=(const NzQuaternion& quat)
|
||||
NzQuaternion<T>& NzQuaternion<T>::operator+=(const NzQuaternion& quat)
|
||||
{
|
||||
w += quat.w;
|
||||
x += quat.x;
|
||||
y += quat.y;
|
||||
z += quat.z;
|
||||
|
||||
return *this;
|
||||
return operator=(operator+(quat));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator*=(const NzQuaternion& quat)
|
||||
NzQuaternion<T>& NzQuaternion<T>::operator*=(const NzQuaternion& quat)
|
||||
{
|
||||
NzQuaternion q(*this);
|
||||
operator=(q * quat);
|
||||
|
||||
return *this;
|
||||
return operator=(operator*(quat));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator*=(T scale)
|
||||
NzQuaternion<T>& NzQuaternion<T>::operator*=(T scale)
|
||||
{
|
||||
w *= scale;
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
|
||||
return *this;
|
||||
return operator=(operator*(scale));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator/=(const NzQuaternion& quat)
|
||||
NzQuaternion<T>& NzQuaternion<T>::operator/=(const NzQuaternion& quat)
|
||||
{
|
||||
NzQuaternion q(*this);
|
||||
operator=(q / quat);
|
||||
|
||||
return *this;
|
||||
return operator=(operator/(quat));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -28,6 +28,8 @@ class NzRect
|
||||
void ExtendTo(const NzVector2<T>& point);
|
||||
void ExtendTo(const NzRect& rect);
|
||||
|
||||
NzVector2<T> GetCenter() const;
|
||||
|
||||
bool Intersect(const NzRect& rect) const;
|
||||
bool Intersect(const NzRect& rect, NzRect& intersection) const;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ 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;
|
||||
height = std::max(y+height, point.y)-y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -74,7 +74,13 @@ 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;
|
||||
height = std::max(x+height, rect.y+rect.height)-y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T> NzRect<T>::GetCenter() const
|
||||
{
|
||||
return NzVector2<T>((x+width)/2, (y+height)/2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -97,7 +103,7 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
|
||||
intersection.x = left;
|
||||
intersection.y = top;
|
||||
intersection.width = right-left;
|
||||
intersection.height = top-bottom;
|
||||
intersection.height = bottom-top;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,19 +21,22 @@ template<typename T> class NzVector2
|
||||
~NzVector2() = default;
|
||||
|
||||
T AbsDotProduct(const NzVector2& vec) const;
|
||||
double Distance(const NzVector2& vec) const;
|
||||
T Distance(const NzVector2& vec) const;
|
||||
float Distancef(const NzVector2& vec) const;
|
||||
T DotProduct(const NzVector2& vec) const;
|
||||
NzVector2 GetNormal() const;
|
||||
void MakeCeil(const NzVector2& vec);
|
||||
void MakeFloor(const NzVector2& vec);
|
||||
double Length() const;
|
||||
double Normalize();
|
||||
T Length() const;
|
||||
float Lengthf() const;
|
||||
void Normalize();
|
||||
T SquaredDistance(const NzVector2& vec) const;
|
||||
T SquaredLength() const;
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
|
||||
@@ -49,17 +49,30 @@ T NzVector2<T>::AbsDotProduct(const NzVector2& vec) const
|
||||
return std::fabs(x * vec.x) + std::fabs(y * vec.y);
|
||||
}
|
||||
|
||||
template<> inline int NzVector2<int>::AbsDotProduct(const NzVector2<int>& vec) const
|
||||
template<>
|
||||
inline int NzVector2<int>::AbsDotProduct(const NzVector2<int>& vec) const
|
||||
{
|
||||
return std::labs(x * vec.x) + std::labs(y * vec.y);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline unsigned int NzVector2<unsigned int>::AbsDotProduct(const NzVector2<unsigned int>& vec) const
|
||||
{
|
||||
return std::labs(x * vec.x) + std::labs(y * vec.y);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzVector2<T>::Distance(const NzVector2& vec) const
|
||||
T NzVector2<T>::Distance(const NzVector2& vec) const
|
||||
{
|
||||
return std::sqrt(SquaredDistance(vec));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
float NzVector2<T>::Distancef(const NzVector2& vec) const
|
||||
{
|
||||
return std::sqrt(static_cast<float>(SquaredDistance(vec)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzVector2<T>::DotProduct(const NzVector2& vec) const
|
||||
{
|
||||
@@ -96,23 +109,27 @@ void NzVector2<T>::MakeFloor(const NzVector2& vec)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzVector2<T>::Length() const
|
||||
T NzVector2<T>::Length() const
|
||||
{
|
||||
return std::sqrt(SquaredLength());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzVector2<T>::Normalize()
|
||||
float NzVector2<T>::Lengthf() const
|
||||
{
|
||||
double length = Length();
|
||||
return std::sqrt(static_cast<float>(SquaredLength()));
|
||||
}
|
||||
|
||||
if (length != 0.f)
|
||||
template<typename T>
|
||||
void NzVector2<T>::Normalize()
|
||||
{
|
||||
auto length = Length();
|
||||
|
||||
if (!NzNumberEquals(length, static_cast<T>(0.0)))
|
||||
{
|
||||
x /= length;
|
||||
y /= length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -136,9 +153,15 @@ NzString NzVector2<T>::ToString() const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>::operator NzString() const
|
||||
NzVector2<T>::operator T*()
|
||||
{
|
||||
return ToString();
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>::operator const T*() const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -208,7 +231,7 @@ NzVector2<T> NzVector2<T>::operator*(T scale) const
|
||||
template<typename T>
|
||||
NzVector2<T> NzVector2<T>::operator/(const NzVector2& vec) const
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -222,7 +245,7 @@ NzVector2<T> NzVector2<T>::operator/(const NzVector2& vec) const
|
||||
template<typename T>
|
||||
NzVector2<T> NzVector2<T>::operator/(T scale) const
|
||||
{
|
||||
if (scale == 0.f)
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -272,7 +295,7 @@ NzVector2<T>& NzVector2<T>::operator*=(T scale)
|
||||
template<typename T>
|
||||
NzVector2<T>& NzVector2<T>::operator/=(const NzVector2& vec)
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -289,7 +312,7 @@ NzVector2<T>& NzVector2<T>::operator/=(const NzVector2& vec)
|
||||
template<typename T>
|
||||
NzVector2<T>& NzVector2<T>::operator/=(T scale)
|
||||
{
|
||||
if (scale == 0.f)
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -355,7 +378,7 @@ NzVector2<T> operator*(T scale, const NzVector2<T>& vec)
|
||||
template<typename T>
|
||||
NzVector2<T> operator/(T scale, const NzVector2<T>& vec)
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_VECTOR3_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
template<typename T> class NzVector3
|
||||
{
|
||||
@@ -16,25 +17,29 @@ template<typename T> class NzVector3
|
||||
NzVector3(T X, T Y, T Z);
|
||||
explicit NzVector3(T scale);
|
||||
NzVector3(T vec[3]);
|
||||
NzVector3(const NzVector2<T>& vec);
|
||||
template<typename U> explicit NzVector3(const NzVector3<U>& vec);
|
||||
NzVector3(const NzVector3& vec) = default;
|
||||
~NzVector3() = default;
|
||||
|
||||
T AbsDotProduct(const NzVector3& vec) const;
|
||||
NzVector3 CrossProduct(const NzVector3& vec) const;
|
||||
double Distance(const NzVector3& vec) const;
|
||||
T Distance(const NzVector3& vec) const;
|
||||
float Distancef(const NzVector3& vec) const;
|
||||
T DotProduct(const NzVector3& vec) const;
|
||||
NzVector3 GetNormal() const;
|
||||
void MakeCeil(const NzVector3& vec);
|
||||
void MakeFloor(const NzVector3& vec);
|
||||
double Length() const;
|
||||
double Normalize();
|
||||
T Length() const;
|
||||
float Lengthf() const;
|
||||
void Normalize();
|
||||
T SquaredDistance(const NzVector3& vec) const;
|
||||
T SquaredLength() const;
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
@@ -76,6 +81,7 @@ template<typename T> NzVector3<T> operator/(T scale, const NzVector3<T>& vec);
|
||||
typedef NzVector3<double> NzVector3d;
|
||||
typedef NzVector3<float> NzVector3f;
|
||||
typedef NzVector3<int> NzVector3i;
|
||||
typedef NzVector3<unsigned int> NzVector3ui;
|
||||
|
||||
#include <Nazara/Math/Vector3.inl>
|
||||
|
||||
|
||||
@@ -38,6 +38,14 @@ z(vec[2])
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::NzVector3(const NzVector2<T>& vec) :
|
||||
x(vec.x),
|
||||
y(vec.y),
|
||||
z(0)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
NzVector3<T>::NzVector3(const NzVector3<U>& vec) :
|
||||
@@ -53,7 +61,14 @@ T NzVector3<T>::AbsDotProduct(const NzVector3& vec) const
|
||||
return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z);
|
||||
}
|
||||
|
||||
template<> inline int NzVector3<int>::AbsDotProduct(const NzVector3<int>& vec) const
|
||||
template<>
|
||||
inline int NzVector3<int>::AbsDotProduct(const NzVector3<int>& vec) const
|
||||
{
|
||||
return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline unsigned int NzVector3<unsigned int>::AbsDotProduct(const NzVector3<unsigned int>& vec) const
|
||||
{
|
||||
return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z);
|
||||
}
|
||||
@@ -65,11 +80,17 @@ NzVector3<T> NzVector3<T>::CrossProduct(const NzVector3& vec) const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzVector3<T>::Distance(const NzVector3& vec) const
|
||||
T NzVector3<T>::Distance(const NzVector3& vec) const
|
||||
{
|
||||
return std::sqrt(SquaredDistance(vec));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
float NzVector3<T>::Distancef(const NzVector3& vec) const
|
||||
{
|
||||
return std::sqrt(static_cast<float>(SquaredDistance()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzVector3<T>::DotProduct(const NzVector3& vec) const
|
||||
{
|
||||
@@ -112,24 +133,28 @@ void NzVector3<T>::MakeFloor(const NzVector3& vec)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzVector3<T>::Length() const
|
||||
T NzVector3<T>::Length() const
|
||||
{
|
||||
return std::sqrt(SquaredLength());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double NzVector3<T>::Normalize()
|
||||
float NzVector3<T>::Lengthf() const
|
||||
{
|
||||
double length = Length();
|
||||
return std::sqrt(static_cast<float>(SquaredLength()));
|
||||
}
|
||||
|
||||
if (length != 0.f)
|
||||
template<typename T>
|
||||
void NzVector3<T>::Normalize()
|
||||
{
|
||||
T length = Length();
|
||||
|
||||
if (!NzNumberEquals(length, static_cast<T>(0.0)))
|
||||
{
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -153,9 +178,15 @@ NzString NzVector3<T>::ToString() const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::operator NzString() const
|
||||
NzVector3<T>::operator T*()
|
||||
{
|
||||
return ToString();
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::operator const T*() const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -225,7 +256,7 @@ NzVector3<T> NzVector3<T>::operator*(T scale) const
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -239,7 +270,7 @@ NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
|
||||
template<typename T>
|
||||
NzVector3<T> NzVector3<T>::operator/(T scale) const
|
||||
{
|
||||
if (scale == 0.f)
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -293,7 +324,7 @@ NzVector3<T>& NzVector3<T>::operator*=(T scale)
|
||||
template<typename T>
|
||||
NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -311,7 +342,7 @@ NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
|
||||
template<typename T>
|
||||
NzVector3<T>& NzVector3<T>::operator/=(T scale)
|
||||
{
|
||||
if (scale == 0.f)
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -379,7 +410,7 @@ NzVector3<T> operator*(T scale, const NzVector3<T>& vec)
|
||||
template<typename T>
|
||||
NzVector3<T> operator/(T scale, const NzVector3<T>& vec)
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_VECTOR4_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
template<typename T> class NzVector4
|
||||
{
|
||||
@@ -17,6 +18,7 @@ template<typename T> class NzVector4
|
||||
explicit NzVector4(T scale);
|
||||
NzVector4(T vec[4]);
|
||||
template<typename U> explicit NzVector4(const NzVector4<U>& vec);
|
||||
NzVector4(const NzVector3<T>& vec, T W = 1.0);
|
||||
NzVector4(const NzVector4& vec) = default;
|
||||
~NzVector4() = default;
|
||||
|
||||
@@ -28,7 +30,8 @@ template<typename T> class NzVector4
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
|
||||
@@ -51,13 +51,29 @@ w(static_cast<T>(vec.w))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector4<T>::NzVector4(const NzVector3<T>& vec, T W) :
|
||||
x(vec.x),
|
||||
y(vec.y),
|
||||
z(vec.z),
|
||||
w(W)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzVector4<T>::AbsDotProduct(const NzVector4& vec) const
|
||||
{
|
||||
return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z) + std::fabs(w * vec.w);
|
||||
}
|
||||
|
||||
template<> inline int NzVector4<int>::AbsDotProduct(const NzVector4<int>& vec) const
|
||||
template<>
|
||||
inline int NzVector4<int>::AbsDotProduct(const NzVector4<int>& vec) const
|
||||
{
|
||||
return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline unsigned int NzVector4<unsigned int>::AbsDotProduct(const NzVector4<unsigned int>& vec) const
|
||||
{
|
||||
return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w);
|
||||
}
|
||||
@@ -103,7 +119,7 @@ void NzVector4<T>::MakeFloor(const NzVector4& vec)
|
||||
template<typename T>
|
||||
void NzVector4<T>::Normalize()
|
||||
{
|
||||
if (w != 0.f)
|
||||
if (!NzNumberEquals(w, static_cast<T>(0.0)))
|
||||
{
|
||||
x /= w;
|
||||
y /= w;
|
||||
@@ -116,13 +132,19 @@ NzString NzVector4<T>::ToString() const
|
||||
{
|
||||
NzStringStream ss;
|
||||
|
||||
return ss << "Vector4(" << x << ", " << y << ", " << z <<')';
|
||||
return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector4<T>::operator NzString() const
|
||||
NzVector4<T>::operator T*()
|
||||
{
|
||||
return ToString();
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector4<T>::operator const T*() const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -174,7 +196,7 @@ NzVector4<T> NzVector4<T>::operator+(const NzVector4& vec) const
|
||||
template<typename T>
|
||||
NzVector4<T> NzVector4<T>::operator-(const NzVector4& vec) const
|
||||
{
|
||||
return NzVector4(x - vec.x, y - vec.y, z - vec.z);
|
||||
return NzVector4(x - vec.x, y - vec.y, z - vec.z, w - vec.w);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -192,7 +214,7 @@ NzVector4<T> NzVector4<T>::operator*(T scale) const
|
||||
template<typename T>
|
||||
NzVector4<T> NzVector4<T>::operator/(const NzVector4& vec) const
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f || vec.w == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -206,7 +228,7 @@ NzVector4<T> NzVector4<T>::operator/(const NzVector4& vec) const
|
||||
template<typename T>
|
||||
NzVector4<T> NzVector4<T>::operator/(T scale) const
|
||||
{
|
||||
if (scale == 0.f)
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -264,7 +286,7 @@ NzVector4<T>& NzVector4<T>::operator*=(T scale)
|
||||
template<typename T>
|
||||
NzVector4<T>& NzVector4<T>::operator/=(const NzVector4& vec)
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f || vec.w == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -283,7 +305,7 @@ NzVector4<T>& NzVector4<T>::operator/=(const NzVector4& vec)
|
||||
template<typename T>
|
||||
NzVector4<T>& NzVector4<T>::operator/=(T scale)
|
||||
{
|
||||
if (scale == 0.f)
|
||||
if (NzNumberEquals(scale, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
@@ -353,7 +375,7 @@ NzVector4<T> operator*(T scale, const NzVector4<T>& vec)
|
||||
template<typename T>
|
||||
NzVector4<T> operator/(T scale, const NzVector4<T>& vec)
|
||||
{
|
||||
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f || vec.w == 0.f)
|
||||
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
#ifndef NAZARA_PREREQUESITES_HPP
|
||||
#define NAZARA_PREREQUESITES_HPP
|
||||
|
||||
// (Commenté en attendant GCC 4.7)
|
||||
/*#if __cplusplus < 201103L
|
||||
#if __cplusplus < 201103L
|
||||
#error Nazara requires a C++11 compliant compiler
|
||||
#endif*/
|
||||
#endif
|
||||
|
||||
// Version du moteur
|
||||
#define NAZARA_VERSION_MAJOR 0
|
||||
@@ -17,23 +16,27 @@
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
|
||||
///TODO: Rajouter des tests d'identification de compilateurs
|
||||
// NAZARA_THREADLOCAL n'existe qu'en attendant le support complet de thread_local
|
||||
#if defined(_MSC_VER)
|
||||
#define NAZARA_COMPILER_MSVC
|
||||
#define NAZARA_DEPRECATED(txt) __declspec(deprecated(txt))
|
||||
#define NAZARA_FUNCTION __FUNCSIG__
|
||||
#define NAZARA_THREADLOCAL __declspec(thread)
|
||||
#elif defined(__GNUC__)
|
||||
#define NAZARA_COMPILER_GCC
|
||||
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
|
||||
|
||||
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
|
||||
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
|
||||
#define NAZARA_THREADLOCAL __thread
|
||||
#elif defined(__BORLANDC__)
|
||||
#define NAZARA_COMPILER_BORDLAND
|
||||
#define NAZARA_DEPRECATED(txt)
|
||||
#define NAZARA_FUNCTION __FUNC__
|
||||
#define NAZARA_THREADLOCAL __declspec(thread)
|
||||
#else
|
||||
#define NAZARA_COMPILER_UNKNOWN
|
||||
#define NAZARA_DEPRECATED(txt)
|
||||
#define NAZARA_FUNCTION __func__ // __func__ est standard depuis le C++11
|
||||
#define NAZARA_THREADLOCAL thread_local
|
||||
#error This compiler is not fully supported
|
||||
#endif
|
||||
|
||||
@@ -63,24 +66,18 @@
|
||||
|
||||
#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 0x0600
|
||||
#define NAZARA_WINNT 0x0600
|
||||
#else
|
||||
#define NAZARA_WINNT 0x0501
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32_WINNT)
|
||||
#if _WIN32_WINNT < NAZARA_WINNT
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT NAZARA_WINNT
|
||||
#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
|
||||
#define _WIN32_WINNT NAZARA_WINNT
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(linux) || defined(__linux)
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
#define NAZARA_BUFFER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
|
||||
enum nzBufferLock
|
||||
enum nzBufferAccess
|
||||
{
|
||||
nzBufferLock_DiscardAndWrite,
|
||||
nzBufferLock_ReadOnly,
|
||||
nzBufferLock_ReadWrite,
|
||||
nzBufferLock_WriteOnly
|
||||
nzBufferAccess_DiscardAndWrite,
|
||||
nzBufferAccess_ReadOnly,
|
||||
nzBufferAccess_ReadWrite,
|
||||
nzBufferAccess_WriteOnly
|
||||
};
|
||||
|
||||
enum nzBufferStorage
|
||||
@@ -68,8 +68,8 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
|
||||
|
||||
bool IsHardware() const;
|
||||
|
||||
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unlock();
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unmap();
|
||||
|
||||
static bool IsSupported(nzBufferStorage storage);
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
|
||||
#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0
|
||||
|
||||
// Active le paramère debug des paramètres des contextes par défaut (Perte de performances mais capable de recevoir des messages d'OpenGL)
|
||||
#define NAZARA_RENDERER_OPENGL_DEBUG 0
|
||||
|
||||
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
|
||||
#define NAZARA_RENDERER_SAFE 1
|
||||
|
||||
|
||||
@@ -24,16 +24,18 @@ class NAZARA_API NzContext
|
||||
~NzContext();
|
||||
|
||||
bool Create(const NzContextParameters& parameters = NzContextParameters());
|
||||
void Destroy();
|
||||
const NzContextParameters& GetParameters() const;
|
||||
bool IsActive() const;
|
||||
bool SetActive(bool active);
|
||||
void SwapBuffers();
|
||||
|
||||
static const NzContext* GetCurrent();
|
||||
static bool EnsureContext();
|
||||
static NzContext* GetCurrent();
|
||||
static const NzContext* GetReference();
|
||||
static const NzContext* GetThreadContext();
|
||||
static bool InitializeReference();
|
||||
static void UninitializeReference();
|
||||
static NzContext* GetThreadContext();
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
NzContextParameters m_parameters;
|
||||
|
||||
@@ -25,6 +25,7 @@ struct NAZARA_API NzContextParameters
|
||||
shareContext(defaultShareContext),
|
||||
window(defaultWindow),
|
||||
compatibilityProfile(defaultCompatibilityProfile),
|
||||
debugMode(defaultDebugMode),
|
||||
doubleBuffered(defaultDoubleBuffered),
|
||||
shared(defaultShared)
|
||||
{
|
||||
@@ -39,6 +40,7 @@ struct NAZARA_API NzContextParameters
|
||||
const NzContext* shareContext;
|
||||
NzWindowHandle window;
|
||||
bool compatibilityProfile;
|
||||
bool debugMode;
|
||||
bool doubleBuffered;
|
||||
bool shared;
|
||||
|
||||
@@ -47,6 +49,7 @@ struct NAZARA_API NzContextParameters
|
||||
static const NzContext* defaultShareContext;
|
||||
static NzWindowHandle defaultWindow;
|
||||
static bool defaultCompatibilityProfile;
|
||||
static bool defaultDebugMode;
|
||||
static bool defaultDoubleBuffered;
|
||||
static bool defaultShared;
|
||||
};
|
||||
|
||||
@@ -30,8 +30,8 @@ class NAZARA_API NzIndexBuffer
|
||||
bool IsHardware() const;
|
||||
bool IsSequential() const;
|
||||
|
||||
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unlock();
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unmap();
|
||||
|
||||
private:
|
||||
NzBuffer* m_buffer;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define NAZARA_OCCLUSIONQUERY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NAZARA_API NzOcclusionQuery : NzNonCopyable
|
||||
{
|
||||
|
||||
@@ -34,13 +34,19 @@ class NAZARA_API NzOpenGL
|
||||
enum Extension
|
||||
{
|
||||
AnisotropicFilter,
|
||||
DebugOutput,
|
||||
FP64,
|
||||
Framebuffer_Object,
|
||||
FrameBufferObject,
|
||||
SeparateShaderObjects,
|
||||
Texture3D,
|
||||
TextureCompression_s3tc,
|
||||
TextureStorage,
|
||||
VertexArrayObject,
|
||||
|
||||
Count
|
||||
};
|
||||
|
||||
static NzOpenGLFunc GetEntry(const NzString& entryPoint);
|
||||
static unsigned int GetVersion();
|
||||
static bool Initialize();
|
||||
static bool IsSupported(Extension extension);
|
||||
@@ -56,6 +62,7 @@ NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer;
|
||||
NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
|
||||
NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
|
||||
NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture;
|
||||
NAZARA_API extern PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
|
||||
NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc;
|
||||
NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData;
|
||||
NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData;
|
||||
@@ -69,6 +76,10 @@ NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
|
||||
NAZARA_API extern PFNGLCOLORMASKPROC glColorMask;
|
||||
NAZARA_API extern PFNGLCULLFACEPROC glCullFace;
|
||||
NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader;
|
||||
NAZARA_API extern PFNGLCOPYTEXSUBIMAGE2DPROC glCopyTexSubImage2D;
|
||||
NAZARA_API extern PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControl;
|
||||
NAZARA_API extern PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsert;
|
||||
NAZARA_API extern PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallback;
|
||||
NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers;
|
||||
NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
|
||||
NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram;
|
||||
@@ -76,6 +87,7 @@ NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries;
|
||||
NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
|
||||
NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader;
|
||||
NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures;
|
||||
NAZARA_API extern PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
|
||||
NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc;
|
||||
NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask;
|
||||
NAZARA_API extern PFNGLDISABLEPROC glDisable;
|
||||
@@ -96,7 +108,9 @@ NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
|
||||
NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries;
|
||||
NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
|
||||
NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures;
|
||||
NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
|
||||
NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv;
|
||||
NAZARA_API extern PFNGLGETDEBUGMESSAGELOGARBPROC glGetDebugMessageLog;
|
||||
NAZARA_API extern PFNGLGETERRORPROC glGetError;
|
||||
NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv;
|
||||
NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv;
|
||||
@@ -110,24 +124,44 @@ NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource;
|
||||
NAZARA_API extern PFNGLGETSTRINGPROC glGetString;
|
||||
NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi;
|
||||
NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage;
|
||||
NAZARA_API extern PFNGLGETTEXLEVELPARAMETERFVPROC glGetTexLevelParameterfv;
|
||||
NAZARA_API extern PFNGLGETTEXLEVELPARAMETERIVPROC glGetTexLevelParameteriv;
|
||||
NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv;
|
||||
NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv;
|
||||
NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
|
||||
NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram;
|
||||
NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer;
|
||||
NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange;
|
||||
NAZARA_API extern PFNGLPIXELSTOREIPROC glPixelStorei;
|
||||
NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv;
|
||||
NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels;
|
||||
NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
|
||||
NAZARA_API extern PFNGLSCISSORPROC glScissor;
|
||||
NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource;
|
||||
NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc;
|
||||
NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp;
|
||||
NAZARA_API extern PFNGLTEXIMAGE1DPROC glTexImage1D;
|
||||
NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D;
|
||||
NAZARA_API extern PFNGLTEXIMAGE3DEXTPROC glTexImage3D;
|
||||
NAZARA_API extern PFNGLTEXIMAGE3DPROC glTexImage3D;
|
||||
NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf;
|
||||
NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri;
|
||||
NAZARA_API extern PFNGLTEXSTORAGE1DPROC glTexStorage1D;
|
||||
NAZARA_API extern PFNGLTEXSTORAGE2DPROC glTexStorage2D;
|
||||
NAZARA_API extern PFNGLTEXSTORAGE3DPROC glTexStorage3D;
|
||||
NAZARA_API extern PFNGLTEXSUBIMAGE1DPROC glTexSubImage1D;
|
||||
NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D;
|
||||
NAZARA_API extern PFNGLTEXSUBIMAGE3DEXTPROC glTexSubImage3D;
|
||||
NAZARA_API extern PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D;
|
||||
NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d;
|
||||
NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f;
|
||||
NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i;
|
||||
|
||||
@@ -21,15 +21,16 @@ class NAZARA_API NzRenderTarget
|
||||
NzRenderTarget() = default;
|
||||
virtual ~NzRenderTarget();
|
||||
|
||||
virtual bool CanActivate() const = 0;
|
||||
|
||||
virtual NzRenderTargetParameters GetRenderTargetParameters() const = 0;
|
||||
|
||||
#ifdef NAZARA_RENDERER_OPENGL
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
virtual bool HasContext() const = 0;
|
||||
#endif
|
||||
|
||||
virtual unsigned int GetHeight() const = 0;
|
||||
virtual NzRenderTargetParameters GetParameters() const = 0;
|
||||
virtual unsigned int GetWidth() const = 0;
|
||||
|
||||
bool IsActive() const;
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
bool SetActive(bool active);
|
||||
|
||||
|
||||
@@ -10,15 +10,14 @@
|
||||
#define NAZARA_RENDERWINDOW_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#endif
|
||||
|
||||
class NzContext;
|
||||
class NzImage;
|
||||
class NzTexture;
|
||||
struct NzContextParameters;
|
||||
|
||||
class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
|
||||
@@ -29,7 +28,8 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
|
||||
NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
|
||||
virtual ~NzRenderWindow();
|
||||
|
||||
bool CanActivate() const;
|
||||
bool CopyToImage(NzImage* image); ///TODO: Const
|
||||
bool CopyToTexture(NzTexture* texture); ///TODO: Const
|
||||
|
||||
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = NzWindow::Default, const NzContextParameters& parameters = NzContextParameters());
|
||||
bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
|
||||
@@ -38,14 +38,20 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
|
||||
|
||||
void EnableVerticalSync(bool enabled);
|
||||
|
||||
NzRenderTargetParameters GetRenderTargetParameters() const;
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
NzContextParameters GetContextParameters() const;
|
||||
#endif
|
||||
|
||||
unsigned int GetHeight() const;
|
||||
NzRenderTargetParameters GetParameters() const;
|
||||
unsigned int GetWidth() const;
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
bool HasContext() const;
|
||||
#endif
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
protected:
|
||||
bool Activate();
|
||||
|
||||
|
||||
@@ -8,9 +8,40 @@
|
||||
#define NAZARA_RENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
#define NazaraRenderer NzRenderer::Instance()
|
||||
|
||||
enum nzBlendFunc
|
||||
{
|
||||
nzBlendFunc_DestAlpha,
|
||||
nzBlendFunc_DestColor,
|
||||
nzBlendFunc_SrcAlpha,
|
||||
nzBlendFunc_SrcColor,
|
||||
nzBlendFunc_InvDestAlpha,
|
||||
nzBlendFunc_InvDestColor,
|
||||
nzBlendFunc_InvSrcAlpha,
|
||||
nzBlendFunc_InvSrcColor,
|
||||
nzBlendFunc_One,
|
||||
nzBlendFunc_Zero
|
||||
};
|
||||
|
||||
enum nzFaceCulling
|
||||
{
|
||||
nzFaceCulling_Back,
|
||||
nzFaceCulling_Front,
|
||||
nzFaceCulling_FrontAndBack
|
||||
};
|
||||
|
||||
enum nzFaceFilling
|
||||
{
|
||||
nzFaceFilling_Point,
|
||||
nzFaceFilling_Line,
|
||||
nzFaceFilling_Fill
|
||||
};
|
||||
|
||||
enum nzPrimitiveType
|
||||
{
|
||||
nzPrimitiveType_LineList,
|
||||
@@ -44,6 +75,41 @@ enum nzRendererClear
|
||||
nzRendererClear_Stencil = 0x04
|
||||
};
|
||||
|
||||
enum nzRendererComparison
|
||||
{
|
||||
nzRendererComparison_Always,
|
||||
nzRendererComparison_Equal,
|
||||
nzRendererComparison_Greater,
|
||||
nzRendererComparison_GreaterOrEqual,
|
||||
nzRendererComparison_Less,
|
||||
nzRendererComparison_LessOrEqual,
|
||||
nzRendererComparison_Never
|
||||
};
|
||||
|
||||
enum nzRendererParameter
|
||||
{
|
||||
nzRendererParameter_Blend,
|
||||
nzRendererParameter_ColorWrite,
|
||||
nzRendererParameter_DepthTest,
|
||||
nzRendererParameter_DepthWrite,
|
||||
nzRendererParameter_FaceCulling,
|
||||
nzRendererParameter_Stencil
|
||||
};
|
||||
|
||||
enum nzStencilOperation
|
||||
{
|
||||
nzStencilOperation_Decrement,
|
||||
nzStencilOperation_DecrementToSaturation,
|
||||
nzStencilOperation_Increment,
|
||||
nzStencilOperation_IncrementToSaturation,
|
||||
nzStencilOperation_Invert,
|
||||
nzStencilOperation_Keep,
|
||||
nzStencilOperation_Replace,
|
||||
nzStencilOperation_Zero
|
||||
};
|
||||
|
||||
class NzColor;
|
||||
class NzContext;
|
||||
class NzIndexBuffer;
|
||||
class NzRenderTarget;
|
||||
class NzShader;
|
||||
@@ -57,26 +123,42 @@ 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);
|
||||
|
||||
void Enable(nzRendererParameter parameter, bool enable);
|
||||
|
||||
unsigned int GetMaxAnisotropyLevel() const;
|
||||
unsigned int GetMaxRenderTargets() const;
|
||||
unsigned int GetMaxTextureUnits() const;
|
||||
NzShader* GetShader() const;
|
||||
NzRenderTarget* GetTarget() const;
|
||||
NzRectui GetViewport() const;
|
||||
|
||||
bool HasCapability(nzRendererCap capability) const;
|
||||
bool Initialize();
|
||||
|
||||
void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest);
|
||||
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);
|
||||
void SetFaceCulling(nzFaceCulling cullingMode);
|
||||
void SetFaceFilling(nzFaceFilling fillingMode);
|
||||
bool SetIndexBuffer(const NzIndexBuffer* indexBuffer);
|
||||
bool SetShader(NzShader* shader);
|
||||
void SetStencilCompareFunction(nzRendererComparison compareFunc);
|
||||
void SetStencilFailOperation(nzStencilOperation failOperation);
|
||||
void SetStencilMask(nzUInt32 mask);
|
||||
void SetStencilPassOperation(nzStencilOperation passOperation);
|
||||
void SetStencilReferenceValue(unsigned int refValue);
|
||||
void SetStencilZFailOperation(nzStencilOperation zfailOperation);
|
||||
bool SetTarget(NzRenderTarget* target);
|
||||
bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);
|
||||
bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
|
||||
void SetViewport(const NzRectui& viewport);
|
||||
|
||||
void Uninitialize();
|
||||
|
||||
@@ -84,16 +166,30 @@ class NAZARA_API NzRenderer
|
||||
static bool IsInitialized();
|
||||
|
||||
private:
|
||||
bool UpdateVertexBuffer();
|
||||
bool EnsureStateUpdate();
|
||||
|
||||
typedef std::tuple<const NzContext*, const NzIndexBuffer*, const NzVertexBuffer*, const NzVertexDeclaration*> VAO_Key;
|
||||
|
||||
std::map<VAO_Key, unsigned int> m_vaos;
|
||||
nzRendererComparison m_stencilCompare;
|
||||
nzStencilOperation m_stencilFail;
|
||||
nzStencilOperation m_stencilPass;
|
||||
nzStencilOperation m_stencilZFail;
|
||||
nzUInt32 m_stencilMask;
|
||||
const NzIndexBuffer* m_indexBuffer;
|
||||
NzRenderTarget* m_target;
|
||||
NzShader* m_shader;
|
||||
NzUtility* m_utilityModule;
|
||||
const NzVertexBuffer* m_vertexBuffer;
|
||||
const NzVertexDeclaration* m_vertexDeclaration;
|
||||
bool m_vaoUpdated;
|
||||
bool m_capabilities[nzRendererCap_Count];
|
||||
bool m_vertexBufferUpdated;
|
||||
bool m_stencilFuncUpdated;
|
||||
bool m_stencilOpUpdated;
|
||||
unsigned int m_maxAnisotropyLevel;
|
||||
unsigned int m_maxRenderTarget;
|
||||
unsigned int m_maxTextureUnit;
|
||||
unsigned int m_stencilReference;
|
||||
|
||||
static NzRenderer* s_instance;
|
||||
static bool s_initialized;
|
||||
|
||||
@@ -8,9 +8,12 @@
|
||||
#define NAZARA_SHADER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Utility/NonCopyable.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
|
||||
enum nzShaderLanguage
|
||||
@@ -32,6 +35,7 @@ enum nzShaderType
|
||||
|
||||
class NzRenderer;
|
||||
class NzShaderImpl;
|
||||
class NzTexture;
|
||||
|
||||
class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||
{
|
||||
@@ -65,6 +69,13 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||
bool SendInteger(const NzString& name, int value);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
|
||||
bool SendVector(const NzString& name, const NzVector2d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector2f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4f& vector);
|
||||
bool SendTexture(const NzString& name, NzTexture* texture);
|
||||
|
||||
void Unlock();
|
||||
|
||||
|
||||
103
include/Nazara/Renderer/Texture.hpp
Normal file
103
include/Nazara/Renderer/Texture.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// 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_TEXTURE_HPP
|
||||
#define NAZARA_TEXTURE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
|
||||
enum nzTextureFilter
|
||||
{
|
||||
nzTextureFilter_Bilinear,
|
||||
nzTextureFilter_Nearest,
|
||||
nzTextureFilter_Trilinear,
|
||||
nzTextureFilter_Unknown
|
||||
};
|
||||
|
||||
enum nzTextureWrap
|
||||
{
|
||||
nzTextureWrap_Clamp,
|
||||
nzTextureWrap_Repeat,
|
||||
nzTextureWrap_Unknown
|
||||
};
|
||||
|
||||
class NzShader;
|
||||
struct NzTextureImpl;
|
||||
|
||||
class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||
{
|
||||
friend class NzShader;
|
||||
|
||||
public:
|
||||
NzTexture();
|
||||
explicit NzTexture(const NzImage& image);
|
||||
~NzTexture();
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
bool Bind() const;
|
||||
#endif
|
||||
|
||||
bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1, bool lock = false);
|
||||
void Destroy();
|
||||
|
||||
bool Download(NzImage* image) const;
|
||||
|
||||
bool EnableMipmapping(bool enable);
|
||||
|
||||
unsigned int GetAnisotropyLevel() const;
|
||||
nzUInt8 GetBPP() const;
|
||||
unsigned int GetDepth() const;
|
||||
nzTextureFilter GetFilterMode() const;
|
||||
nzPixelFormat GetFormat() const;
|
||||
unsigned int GetHeight() const;
|
||||
nzImageType GetType() const;
|
||||
unsigned int GetWidth() const;
|
||||
nzTextureWrap GetWrapMode() const;
|
||||
|
||||
bool IsCompressed() const;
|
||||
bool IsCubemap() const;
|
||||
bool IsTarget() const;
|
||||
bool IsValid() const;
|
||||
|
||||
bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams());
|
||||
bool LoadFromImage(const NzImage& image);
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const NzImageParams& params = NzImageParams());
|
||||
bool LoadFromStream(NzInputStream& stream, const NzImageParams& params = NzImageParams());
|
||||
|
||||
bool Lock();
|
||||
|
||||
bool SetAnisotropyLevel(unsigned int anistropyLevel);
|
||||
bool SetFilterMode(nzTextureFilter filter);
|
||||
bool SetMipmapRange(nzUInt8 minLevel, nzUInt8 maxLevel);
|
||||
bool SetWrapMode(nzTextureWrap wrap);
|
||||
|
||||
bool Update(const NzImage& image, nzUInt8 level = 0);
|
||||
bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0);
|
||||
bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0);
|
||||
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 NzImage& image, nzUInt8 level = 0);
|
||||
bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, 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);
|
||||
|
||||
void Unlock();
|
||||
|
||||
static unsigned int GetValidSize(unsigned int size);
|
||||
static bool IsFormatSupported(nzPixelFormat format);
|
||||
static bool IsTypeSupported(nzImageType type);
|
||||
|
||||
private:
|
||||
void SetTarget(bool isTarget);
|
||||
|
||||
NzTextureImpl* m_impl;
|
||||
};
|
||||
|
||||
#endif // NAZARA_TEXTURE_HPP
|
||||
@@ -29,8 +29,8 @@ class NAZARA_API NzVertexBuffer
|
||||
|
||||
bool IsHardware() const;
|
||||
|
||||
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unlock();
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unmap();
|
||||
|
||||
private:
|
||||
NzBuffer* m_buffer;
|
||||
|
||||
@@ -36,6 +36,6 @@
|
||||
#define NAZARA_UTILITY_SAFE 1
|
||||
|
||||
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
|
||||
#define NAZARA_UTILITY_THREADED_WINDOW 1
|
||||
#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7
|
||||
|
||||
#endif // NAZARA_CONFIG_UTILITY_HPP
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
#define NAZARA_IMAGE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/ResourceLoader.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
@@ -17,12 +20,12 @@
|
||||
|
||||
enum nzCubemapFace
|
||||
{
|
||||
nzCubemapFace_PositiveX,
|
||||
nzCubemapFace_NegativeX,
|
||||
nzCubemapFace_PositiveY,
|
||||
nzCubemapFace_NegativeY,
|
||||
nzCubemapFace_PositiveZ,
|
||||
nzCubemapFace_NegativeZ
|
||||
nzCubemapFace_PositiveX = 0,
|
||||
nzCubemapFace_NegativeX = 1,
|
||||
nzCubemapFace_PositiveY = 2,
|
||||
nzCubemapFace_NegativeY = 3,
|
||||
nzCubemapFace_PositiveZ = 4,
|
||||
nzCubemapFace_NegativeZ = 5
|
||||
};
|
||||
|
||||
enum nzImageType
|
||||
@@ -30,19 +33,23 @@ enum nzImageType
|
||||
nzImageType_1D,
|
||||
nzImageType_2D,
|
||||
nzImageType_3D,
|
||||
nzImageType_Cubemap
|
||||
nzImageType_Cubemap,
|
||||
|
||||
nzImageType_Count
|
||||
};
|
||||
|
||||
struct NzImageParams
|
||||
{
|
||||
nzPixelFormat loadFormat = nzPixelFormat_Undefined;
|
||||
nzUInt8 levelCount = 0;
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return true;
|
||||
return loadFormat == nzPixelFormat_Undefined || NzPixelFormat::IsValid(loadFormat);
|
||||
}
|
||||
};
|
||||
|
||||
///TODO: Filtres
|
||||
///TODO: Mipmaps
|
||||
|
||||
class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, NzImageParams>
|
||||
{
|
||||
@@ -55,21 +62,33 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
|
||||
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 Convert(nzPixelFormat format);
|
||||
|
||||
bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height = 1, unsigned int depth = 1);
|
||||
bool Copy(const NzImage& source, const NzCubeui& srcCube, const NzVector3ui& dstPos);
|
||||
|
||||
bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1);
|
||||
void Destroy();
|
||||
|
||||
bool Fill(const NzColor& color);
|
||||
bool Fill(const NzColor& color, const NzRectui& rect, unsigned int z = 0);
|
||||
bool Fill(const NzColor& color, const NzCubeui& cube);
|
||||
|
||||
bool FlipHorizontally();
|
||||
bool FlipVertically();
|
||||
|
||||
nzUInt8 GetBPP() const;
|
||||
const nzUInt8* GetConstPixels() const;
|
||||
unsigned int GetDepth() const;
|
||||
const nzUInt8* GetConstPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0) const;
|
||||
unsigned int GetDepth(nzUInt8 level = 0) const;
|
||||
nzPixelFormat GetFormat() const;
|
||||
unsigned int GetHeight() const;
|
||||
nzUInt8* GetPixels();
|
||||
unsigned int GetHeight(nzUInt8 level = 0) const;
|
||||
nzUInt8 GetLevelCount() const;
|
||||
nzUInt8 GetMaxLevel() const;
|
||||
NzColor GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
|
||||
nzUInt8* GetPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 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;
|
||||
@@ -79,14 +98,17 @@ 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 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);
|
||||
bool SetLevelCount(nzUInt8 levelCount);
|
||||
bool SetPixelColor(const NzColor& color, unsigned int x, unsigned int y = 0, unsigned int z = 0);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
@@ -96,14 +118,10 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
|
||||
|
||||
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) :
|
||||
SharedImage(unsigned short RefCount, nzImageType Type, nzPixelFormat Format, nzUInt8 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),
|
||||
@@ -114,12 +132,13 @@ 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;
|
||||
|
||||
unsigned short refCount;
|
||||
unsigned short refCount = 1;
|
||||
NazaraMutex(mutex)
|
||||
};
|
||||
|
||||
|
||||
@@ -8,31 +8,76 @@
|
||||
#define NAZARA_PIXELFORMAT_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
enum nzPixelFormat
|
||||
{
|
||||
nzPixelFormat_Undefined,
|
||||
|
||||
nzPixelFormat_B8G8R8,
|
||||
nzPixelFormat_B8G8R8A8,
|
||||
nzPixelFormat_BGR8, // 3*nzUInt8
|
||||
nzPixelFormat_BGRA8, // 4*nzUInt8
|
||||
nzPixelFormat_DXT1,
|
||||
nzPixelFormat_DXT3,
|
||||
nzPixelFormat_DXT5,
|
||||
nzPixelFormat_L8,
|
||||
nzPixelFormat_L8A8,
|
||||
nzPixelFormat_R4G4A4A4,
|
||||
nzPixelFormat_R5G5A5A1,
|
||||
nzPixelFormat_R8,
|
||||
nzPixelFormat_R8G8,
|
||||
nzPixelFormat_R8G8B8,
|
||||
nzPixelFormat_R8G8B8A8
|
||||
nzPixelFormat_L8, // 1*nzUInt8
|
||||
nzPixelFormat_LA8, // 2*nzUInt8
|
||||
/*
|
||||
nzPixelFormat_RGB16F,
|
||||
nzPixelFormat_RGB16I, // 4*nzUInt16
|
||||
nzPixelFormat_RGB32F,
|
||||
nzPixelFormat_RGB32I, // 4*nzUInt32
|
||||
nzPixelFormat_RGBA16F,
|
||||
nzPixelFormat_RGBA16I, // 4*nzUInt16
|
||||
nzPixelFormat_RGBA32F,
|
||||
nzPixelFormat_RGBA32I, // 4*nzUInt32
|
||||
*/
|
||||
nzPixelFormat_RGBA4, // 1*nzUInt16
|
||||
nzPixelFormat_RGB5A1, // 1*nzUInt16
|
||||
nzPixelFormat_RGB8, // 3*nzUInt8
|
||||
nzPixelFormat_RGBA8, // 4*nzUInt8
|
||||
/*
|
||||
nzPixelFormat_Depth16,
|
||||
nzPixelFormat_Depth24,
|
||||
nzPixelFormat_Depth24Stencil8,
|
||||
nzPixelFormat_Depth32,
|
||||
nzPixelFormat_Stencil1,
|
||||
nzPixelFormat_Stencil4,
|
||||
nzPixelFormat_Stencil8,
|
||||
nzPixelFormat_Stencil16,
|
||||
*/
|
||||
|
||||
nzPixelFormat_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 HasAlpha(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);
|
||||
|
||||
static NzString ToString(nzPixelFormat format);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static NAZARA_API ConvertFunction s_convertFunctions[nzPixelFormat_Count][nzPixelFormat_Count];
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/PixelFormat.inl>
|
||||
|
||||
@@ -2,19 +2,80 @@
|
||||
// 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) + " is not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!func(reinterpret_cast<const nzUInt8*>(src), reinterpret_cast<const nzUInt8*>(src) + GetBPP(srcFormat), reinterpret_cast<nzUInt8*>(dst)))
|
||||
{
|
||||
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
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, reinterpret_cast<const nzUInt8*>(end)-reinterpret_cast<const nzUInt8*>(start));
|
||||
return true;
|
||||
}
|
||||
|
||||
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
|
||||
if (!func)
|
||||
{
|
||||
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " is not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!func(reinterpret_cast<const nzUInt8*>(start), reinterpret_cast<const nzUInt8*>(end), reinterpret_cast<nzUInt8*>(dst)))
|
||||
{
|
||||
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
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,31 +90,84 @@ 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;
|
||||
|
||||
case nzPixelFormat_Count:
|
||||
case nzPixelFormat_Undefined:
|
||||
NazaraError("Invalid pixel format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
NazaraInternalError("Invalid pixel format");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline bool NzPixelFormat::HasAlpha(nzPixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case nzPixelFormat_BGRA8:
|
||||
case nzPixelFormat_DXT3:
|
||||
case nzPixelFormat_DXT5:
|
||||
case nzPixelFormat_LA8:
|
||||
case nzPixelFormat_RGB5A1:
|
||||
case nzPixelFormat_RGBA4:
|
||||
case nzPixelFormat_RGBA8:
|
||||
return true;
|
||||
|
||||
case nzPixelFormat_BGR8:
|
||||
case nzPixelFormat_DXT1:
|
||||
case nzPixelFormat_L8:
|
||||
case nzPixelFormat_RGB8:
|
||||
return false;
|
||||
|
||||
case nzPixelFormat_Count:
|
||||
case nzPixelFormat_Undefined:
|
||||
break;
|
||||
}
|
||||
|
||||
NazaraError("Invalid pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
@@ -68,4 +182,100 @@ inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
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)
|
||||
{
|
||||
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";
|
||||
|
||||
case nzPixelFormat_Count:
|
||||
case nzPixelFormat_Undefined:
|
||||
break;
|
||||
}
|
||||
|
||||
NazaraError("Invalid pixel format");
|
||||
return "Invalid format";
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
@@ -24,10 +24,12 @@
|
||||
#include <Nazara/Core/ThreadCondition.hpp>
|
||||
#endif
|
||||
|
||||
class NzUtility;
|
||||
class NzWindowImpl;
|
||||
|
||||
class NAZARA_API NzWindow : NzNonCopyable
|
||||
{
|
||||
friend class NzUtility;
|
||||
friend class NzWindowImpl;
|
||||
|
||||
public:
|
||||
@@ -59,7 +61,7 @@ class NAZARA_API NzWindow : NzNonCopyable
|
||||
NzWindowHandle GetHandle() const;
|
||||
unsigned int GetHeight() const;
|
||||
NzVector2i GetPosition() const;
|
||||
NzVector2i GetSize() const;
|
||||
NzVector2ui GetSize() const;
|
||||
NzString GetTitle() const;
|
||||
unsigned int GetWidth() const;
|
||||
|
||||
@@ -99,6 +101,9 @@ class NAZARA_API NzWindow : NzNonCopyable
|
||||
private:
|
||||
void PushEvent(const NzEvent& event);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::queue<NzEvent> m_events;
|
||||
#if NAZARA_UTILITY_THREADED_WINDOW
|
||||
NzMutex m_eventMutex;
|
||||
|
||||
Reference in New Issue
Block a user