Refactored mathematics module

Added AABBs
Added code examples
Added experimental support for texture arrays (1D/2D)
Added initialisers (new way of initialising modules)
Added global headers (Plus a global header generator script)
Added pattern support for directory
Added support for spinlocks critical section on Windows
Added NzRenderWindow::SetFramerateLimit
Core project now includes Mathematics files
Fixed color implementation using double
Fixed declaration needing renderer include
Fixed MLT not clearing nextFree(File/Line) after Free
Fixed move operators not being noexcept
Fixed thread-safety (Now working correctly - If I'm lucky)
Moved Resource to core
New interface for modules
New interface for the renderer
Put some global functions to anonymous namespace
Removed empty modules
Renamed ThreadCondition to ConditionVariable
Replaced redirect to cerr log option by duplicate to cout
Setting mouse position relative to a window will make this window ignore
the event
Shaders sending methods no longer takes the uniform variable name (it's
using ID instead)
Using new OpenGL 4.3 header
This commit is contained in:
Lynix
2012-08-08 04:44:17 +02:00
parent 06eda4eba9
commit b442ab0bd2
142 changed files with 6861 additions and 2326 deletions

View File

@@ -8,9 +8,9 @@
#define NAZARA_ANIMATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <list>
#include <map>

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2011 Jérôme Leclercq
// This file is part of the "Ungine".
// For conditions of distribution and use, see copyright notice in Core.h
#ifndef NAZARA_AXISALIGNEDBOX_HPP
#define NAZARA_AXISALIGNEDBOX_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
class NAZARA_API NzAxisAlignedBox
{
public:
NzAxisAlignedBox();
NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2);
NzAxisAlignedBox(nzExtend extend);
bool Contains(const NzAxisAlignedBox& box);
void ExtendTo(const NzAxisAlignedBox& box);
void ExtendTo(const NzVector3f& vector);
nzExtend GetExtend() const;
NzVector3f GetMaximum() const;
NzVector3f GetMinimum() const;
bool IsFinite() const;
bool IsInfinite() const;
bool IsNull() const;
void SetInfinite();
void SetExtends(const NzVector3f& vec1, const NzVector3f& vec2);
void SetNull();
NzString ToString() const;
static const NzAxisAlignedBox Infinite;
static const NzAxisAlignedBox Null;
private:
nzExtend m_extend;
NzCubef m_cube;
};
NAZARA_API std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb);
#endif // NAZARA_AXISALIGNEDBOX_HPP

View File

@@ -9,8 +9,8 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
class NzBufferImpl;
class NzRenderer;

View File

@@ -29,6 +29,9 @@
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire)
#define NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_UTILITY_MEMORYLEAKTRACKER 0
@@ -38,12 +41,11 @@
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7
// Protège le module des accès concurrentiels
// Protège les classes des accès concurrentiels
#define NAZARA_UTILITY_THREADSAFE 1
#if NAZARA_UTILITY_THREADSAFE
#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW)
#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW)
#endif
// Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW)
#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW)
#endif // NAZARA_CONFIG_UTILITY_HPP

View File

@@ -24,6 +24,7 @@ enum nzBufferAccess
enum nzBufferStorage
{
//nzBufferStorage_Both,
nzBufferStorage_Hardware,
nzBufferStorage_Software,
@@ -44,8 +45,8 @@ enum nzBufferUsage
enum nzCubemapFace
{
// L'ordre est X, -X, Y, -Y, Z, -Z
// Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap
// L'ordre est X, -X, Y, -Y, Z, -Z
nzCubemapFace_PositiveX = 0,
nzCubemapFace_PositiveY = 2,
nzCubemapFace_PositiveZ = 4,
@@ -86,10 +87,38 @@ enum nzElementUsage
nzElementUsage_Max = nzElementUsage_TexCoord
};
enum nzEventType
{
nzEventType_GainedFocus,
nzEventType_LostFocus,
nzEventType_KeyPressed,
nzEventType_KeyReleased,
nzEventType_MouseButtonDoubleClicked,
nzEventType_MouseButtonPressed,
nzEventType_MouseButtonReleased,
nzEventType_MouseEntered,
nzEventType_MouseLeft,
nzEventType_MouseMoved,
nzEventType_MouseWheelMoved,
nzEventType_Moved,
nzEventType_Quit,
nzEventType_Resized,
nzEventType_TextEntered
};
enum nzExtend
{
nzExtend_Finite,
nzExtend_Infinite,
nzExtend_Null
};
enum nzImageType
{
nzImageType_1D,
nzImageType_1D_Array,
nzImageType_2D,
nzImageType_2D_Array,
nzImageType_3D,
nzImageType_Cubemap,

View File

@@ -14,15 +14,22 @@
struct NzEvent
{
// Utilisé par:
// -nzEventType_KeyPressed
// -nzEventType_KeyReleased
struct KeyEvent
{
NzKeyboard::Key code;
bool alt;
bool control;
bool repeated;
bool shift;
bool system;
};
// Utilisé par:
// -nzEventType_MouseButtonDoubleClicked
// -nzEventType_MouseButtonPressed
struct MouseButtonEvent
{
NzMouse::Button button;
@@ -30,63 +37,79 @@ struct NzEvent
unsigned int y;
};
// Utilisé par:
// -nzEventType_MouseMoved
struct MouseMoveEvent
{
int x;
int y;
int deltaX;
int deltaY;
unsigned int x;
unsigned int y;
};
// Utilisé par:
// -nzEventType_MouseWheelMoved
struct MouseWheelEvent
{
float delta;
};
// Utilisé par:
// -nzEventType_Moved
struct PositionEvent
{
int x;
int y;
};
// Utilisé par:
// -nzEventType_Resized
struct SizeEvent
{
unsigned int height;
unsigned int width;
};
// Utilisé par:
// -nzEventType_TextEntered
struct TextEvent
{
bool repeated;
char32_t character;
};
enum Type
{
GainedFocus,
LostFocus,
KeyPressed,
KeyReleased,
MouseButtonDoubleClicked,
MouseButtonPressed,
MouseButtonReleased,
MouseEntered,
MouseLeft,
MouseMoved,
MouseWheelMoved,
Moved,
Quit,
Resized,
TextEntered
};
Type type;
nzEventType type;
union
{
// Utilisé par:
// -nzEventType_KeyPressed
// -nzEventType_KeyReleased
KeyEvent key;
// Utilisé par:
// -nzEventType_MouseButtonDoubleClicked
// -nzEventType_MouseButtonPressed
MouseButtonEvent mouseButton;
// Utilisé par:
// -nzEventType_MouseMoved
MouseMoveEvent mouseMove;
// Utilisé par:
// -nzEventType_MouseWheelMoved
MouseWheelEvent mouseWheel;
// Utilisé par:
// -nzEventType_Moved
PositionEvent position;
// Utilisé par:
// -nzEventType_Resized
SizeEvent size;
// Utilisé par:
// -nzEventType_TextEntered
TextEvent text;
};
};

View File

@@ -10,17 +10,17 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <list>
#include <map>
#if NAZARA_THREADSAFETY_IMAGE
#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_IMAGE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@@ -49,7 +49,7 @@ class NAZARA_API NzImage : public NzResource
NzImage();
NzImage(const NzImage& image);
NzImage(NzImage&& image);
NzImage(NzImage&& image) noexcept;
NzImage(SharedImage* sharedImage);
~NzImage();
@@ -68,14 +68,14 @@ class NAZARA_API NzImage : public NzResource
bool FlipVertically();
nzUInt8 GetBPP() const;
const nzUInt8* GetConstPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0) const;
const nzUInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0) const;
unsigned int GetDepth(nzUInt8 level = 0) const;
nzPixelFormat GetFormat() const;
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);
nzUInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0);
unsigned int GetSize() const;
unsigned int GetSize(nzUInt8 level) const;
nzImageType GetType() const;
@@ -97,7 +97,7 @@ class NAZARA_API NzImage : public NzResource
bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
NzImage& operator=(const NzImage& image);
NzImage& operator=(NzImage&& image);
NzImage& operator=(NzImage&& image) noexcept;
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);

View File

@@ -8,8 +8,8 @@
#define NAZARA_INDEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzIndexBuffer : public NzResource
{

View File

@@ -9,21 +9,22 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <list>
#include <map>
class NzSubMesh;
class NzVertexDeclaration;
struct NzMeshParams
{
NzAnimationParams animation;
//const NzVertexDeclaration* declaration = nullptr;
bool forceSoftware = false;
nzBufferStorage storage = nzBufferStorage_Hardware;
bool loadAnimations = true;
bool IsValid() const;
@@ -52,6 +53,7 @@ class NAZARA_API NzMesh : public NzResource
bool Create(nzAnimationType type);
void Destroy();
const NzAxisAlignedBox& GetAABB() const;
const NzAnimation* GetAnimation() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
@@ -69,6 +71,8 @@ class NAZARA_API NzMesh : public NzResource
bool HasSubMesh(const NzString& identifier) const;
bool HasSubMesh(nzUInt8 index = 0) const;
void InvalidateAABB() const;
bool IsAnimable() const;
bool IsValid() const;

View File

@@ -25,7 +25,7 @@ class NAZARA_API NzMouse
XButton1,
XButton2,
Count
Max = XButton2
};
static NzVector2i GetPosition();

View File

@@ -361,7 +361,7 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format)
return "RGBA8";
case nzPixelFormat_Undefined:
break;
return "Undefined";
}
NazaraError("Invalid pixel format");

View File

@@ -1,30 +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_RESOURCE_HPP
#define NAZARA_RESOURCE_HPP
#include <Nazara/Prerequesites.hpp>
class NAZARA_API NzResource
{
public:
NzResource(bool persistent = true);
NzResource(const NzResource& resource);
virtual ~NzResource();
void AddResourceReference() const;
bool IsPersistent() const;
void RemoveResourceReference() const;
void SetPersistent(bool persistent = true);
private:
// Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms
mutable bool m_resourcePersistent;
mutable unsigned int m_resourceReferenceCount;
};
#endif // NAZARA_RESOURCE_HPP

View File

@@ -14,12 +14,15 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
{
public:
NzStaticMesh(const NzMesh* parent);
NzStaticMesh(const NzMesh* parent, const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr);
virtual ~NzStaticMesh();
bool Create(const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr);
void Destroy();
bool GenerateAABB();
const NzAxisAlignedBox& GetAABB() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
const NzIndexBuffer* GetIndexBuffer() const;
@@ -30,14 +33,16 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
bool IsAnimated() const;
bool IsValid() const;
void SetAABB(const NzAxisAlignedBox& aabb);
void SetPrimitiveType(nzPrimitiveType primitiveType);
private:
void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation);
nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList;
const NzIndexBuffer* m_indexBuffer = nullptr;
const NzVertexBuffer* m_vertexBuffer = nullptr;
NzAxisAlignedBox m_aabb;
NzIndexBuffer* m_indexBuffer = nullptr;
NzVertexBuffer* m_vertexBuffer = nullptr;
const NzVertexDeclaration* m_vertexDeclaration = nullptr;
};

View File

@@ -8,9 +8,10 @@
#define NAZARA_SUBMESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
@@ -26,6 +27,7 @@ class NAZARA_API NzSubMesh : public NzResource
void Animate(unsigned int frameA, unsigned int frameB, float interpolation);
virtual const NzAxisAlignedBox& GetAABB() const = 0;
virtual const NzIndexBuffer* GetIndexBuffer() const = 0;
const NzMesh* GetParent() const;
virtual nzPrimitiveType GetPrimitiveType() const = 0;

View File

@@ -8,20 +8,22 @@
#define NAZARA_UTILITY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzUtility
{
public:
NzUtility();
~NzUtility();
NzUtility() = delete;
~NzUtility() = delete;
bool Initialize();
void Uninitialize();
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_UTILITY_HPP

View File

@@ -8,8 +8,8 @@
#define NAZARA_VERTEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzVertexBuffer : public NzResource
{

View File

@@ -6,8 +6,8 @@
#define NAZARA_VERTEXDECLARATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
struct NzVertexElement
{
@@ -26,7 +26,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource
NzVertexDeclaration() = default;
NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount);
NzVertexDeclaration(const NzVertexDeclaration& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept;
~NzVertexDeclaration();
bool Create(const NzVertexElement* elements, unsigned int elementCount);
@@ -44,7 +44,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource
bool IsValid() const;
NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept;
private:
NzVertexDeclarationImpl* m_sharedImpl = nullptr;

View File

@@ -28,11 +28,13 @@
class NzCursor;
class NzImage;
class NzIcon;
class NzMouse;
class NzUtility;
class NzWindowImpl;
class NAZARA_API NzWindow : NzNonCopyable
{
friend class NzMouse;
friend class NzUtility;
friend class NzWindowImpl;
@@ -42,11 +44,11 @@ class NAZARA_API NzWindow : NzNonCopyable
NzWindow(NzWindowHandle handle);
virtual ~NzWindow();
void Close();
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default);
bool Create(NzWindowHandle handle);
void Destroy();
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
@@ -78,20 +80,20 @@ class NAZARA_API NzWindow : NzNonCopyable
void SetPosition(int x, int y);
void SetSize(const NzVector2i& size);
void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop);
void SetTitle(const NzString& title);
void SetVisible(bool visible);
void StayOnTop(bool stayOnTop);
bool WaitEvent(NzEvent* event);
protected:
virtual void OnClose();
virtual bool OnCreate();
virtual void OnWindowDestroying();
virtual bool OnWindowCreated();
NzWindowImpl* m_impl;
private:
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
void PushEvent(const NzEvent& event);
static bool Initialize();
@@ -99,9 +101,9 @@ class NAZARA_API NzWindow : NzNonCopyable
std::queue<NzEvent> m_events;
#if NAZARA_UTILITY_THREADED_WINDOW
NzConditionVariable m_eventCondition;
NzMutex m_eventMutex;
NzMutex m_eventConditionMutex;
NzThreadCondition m_eventCondition;
bool m_eventListener;
bool m_waitForEvent;
#endif