Merge branch 'Font-Update'

Former-commit-id: d293f78c891a74554c6b990afafdc1eb1cc0a584
This commit is contained in:
Lynix
2015-01-17 00:36:28 +01:00
108 changed files with 4982 additions and 1081 deletions

View File

@@ -19,6 +19,7 @@ class NzCallOnExit : NzNonCopyable
NzCallOnExit(Func func = nullptr);
~NzCallOnExit();
void CallAndReset(Func func = nullptr);
void Reset(Func func = nullptr);
private:

View File

@@ -2,6 +2,7 @@
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Debug.hpp>
inline NzCallOnExit::NzCallOnExit(Func func) :
@@ -15,6 +16,14 @@ inline NzCallOnExit::~NzCallOnExit()
m_func();
}
inline void NzCallOnExit::CallAndReset(Func func)
{
if (m_func)
m_func();
Reset(func);
}
inline void NzCallOnExit::Reset(Func func)
{
m_func = func;

View File

@@ -0,0 +1,85 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// Implémentation originale de Jukka Jylänki (Merci de sa contribution au domaine public)
// http://clb.demon.fi/projects/even-more-rectangle-bin-packing
#pragma once
#ifndef NAZARA_GUILLOTINEBINPACK_HPP
#define NAZARA_GUILLOTINEBINPACK_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Math/Rect.hpp>
#include <vector>
class NAZARA_API NzGuillotineBinPack
{
public:
enum FreeRectChoiceHeuristic
{
RectBestAreaFit,
RectBestLongSideFit,
RectBestShortSideFit,
RectWorstAreaFit,
RectWorstLongSideFit,
RectWorstShortSideFit
};
enum GuillotineSplitHeuristic
{
SplitLongerAxis,
SplitLongerLeftoverAxis,
SplitMaximizeArea,
SplitMinimizeArea,
SplitShorterAxis,
SplitShorterLeftoverAxis
};
NzGuillotineBinPack();
NzGuillotineBinPack(unsigned int width, unsigned int height);
NzGuillotineBinPack(const NzVector2ui& size);
NzGuillotineBinPack(const NzGuillotineBinPack&) = default;
NzGuillotineBinPack(NzGuillotineBinPack&&) = default;
~NzGuillotineBinPack() = default;
void Clear();
void Expand(unsigned int newWidth, unsigned newHeight);
void Expand(const NzVector2ui& newSize);
void FreeRectangle(const NzRectui& rect);
unsigned int GetHeight() const;
float GetOccupancy() const;
NzVector2ui GetSize() const;
unsigned int GetWidth() const;
bool Insert(NzRectui* rects, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod);
bool Insert(NzRectui* rects, bool* flipped, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod);
bool Insert(NzRectui* rects, bool* flipped, bool* inserted, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod);
bool MergeFreeRectangles();
void Reset();
void Reset(unsigned int width, unsigned int height);
void Reset(const NzVector2ui& size);
NzGuillotineBinPack& operator=(const NzGuillotineBinPack&) = default;
NzGuillotineBinPack& operator=(NzGuillotineBinPack&&) = default;
private:
void SplitFreeRectAlongAxis(const NzRectui& freeRect, const NzRectui& placedRect, bool splitHorizontal);
void SplitFreeRectByHeuristic(const NzRectui& freeRect, const NzRectui& placedRect, GuillotineSplitHeuristic method);
static int ScoreByHeuristic(int width, int height, const NzRectui& freeRect, FreeRectChoiceHeuristic rectChoice);
std::vector<NzRectui> m_freeRectangles;
unsigned int m_height;
unsigned int m_usedArea;
unsigned int m_width;
};
#endif // NAZARA_GUILLOTINEBINPACK_HPP

View File

@@ -23,6 +23,8 @@ class NAZARA_API NzResource
{
public:
NzResource(bool persistent = true);
NzResource(const NzResource& resource) = delete;
NzResource(NzResource&& resource) = delete;
virtual ~NzResource();
void AddResourceListener(NzResourceListener* listener, int index = 0) const;
@@ -37,6 +39,9 @@ class NAZARA_API NzResource
bool SetPersistent(bool persistent = true, bool checkReferenceCount = false);
NzResource& operator=(const NzResource& resource) = delete;
NzResource& operator=(NzResource&& resource) = delete;
protected:
void NotifyCreated();
void NotifyDestroy();

View File

@@ -46,7 +46,9 @@ class NzSparsePtr
T& operator[](int index) const;
NzSparsePtr operator+(int count) const;
NzSparsePtr operator+(unsigned int count) const;
NzSparsePtr operator-(int count) const;
NzSparsePtr operator-(unsigned int count) const;
std::ptrdiff_t operator-(const NzSparsePtr& ptr) const;
NzSparsePtr& operator+=(int count);

View File

@@ -127,12 +127,24 @@ NzSparsePtr<T> NzSparsePtr<T>::operator+(int count) const
return NzSparsePtr(m_ptr + count*m_stride, m_stride);
}
template<typename T>
NzSparsePtr<T> NzSparsePtr<T>::operator+(unsigned int count) const
{
return NzSparsePtr(m_ptr + count*m_stride, m_stride);
}
template<typename T>
NzSparsePtr<T> NzSparsePtr<T>::operator-(int count) const
{
return NzSparsePtr(m_ptr - count*m_stride, m_stride);
}
template<typename T>
NzSparsePtr<T> NzSparsePtr<T>::operator-(unsigned int count) const
{
return NzSparsePtr(m_ptr - count*m_stride, m_stride);
}
template<typename T>
std::ptrdiff_t NzSparsePtr<T>::operator-(const NzSparsePtr& ptr) const
{

View File

@@ -12,11 +12,13 @@
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
class NzDrawable;
class NzLight;
class NzMaterial;
class NzSprite;
class NzTexture;
struct NzMeshData;
class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
@@ -28,7 +30,7 @@ class NAZARA_API NzAbstractRenderQueue : NzNonCopyable
virtual void AddDrawable(const NzDrawable* drawable) = 0;
virtual void AddLight(const NzLight* light) = 0;
virtual void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) = 0;
virtual void AddSprite(const NzSprite* sprite) = 0;
virtual void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) = 0;
virtual void Clear(bool fully) = 0;
};

View File

@@ -28,6 +28,9 @@ class NAZARA_API NzAbstractViewer
virtual NzVector3f GetEyePosition() const = 0;
virtual NzVector3f GetForward() const = 0;
virtual const NzFrustumf& GetFrustum() const = 0;
virtual NzVector3f GetGlobalForward() const = 0;
virtual NzVector3f GetGlobalRight() const = 0;
virtual NzVector3f GetGlobalUp() const = 0;
virtual const NzMatrix4f& GetProjectionMatrix() const = 0;
virtual const NzRenderTarget* GetTarget() const = 0;
virtual const NzMatrix4f& GetViewMatrix() const = 0;

View File

@@ -32,6 +32,9 @@ class NAZARA_API NzCamera : public NzAbstractViewer, public NzNode, NzRenderTarg
NzVector3f GetForward() const;
float GetFOV() const;
const NzFrustumf& GetFrustum() const;
NzVector3f GetGlobalForward() const;
NzVector3f GetGlobalRight() const;
NzVector3f GetGlobalUp() const;
const NzMatrix4f& GetProjectionMatrix() const;
const NzRenderTarget* GetTarget() const;
const NzRectf& GetTargetRegion() const;

View File

@@ -31,7 +31,7 @@ class NAZARA_API NzDeferredRenderQueue : public NzAbstractRenderQueue, NzResourc
void AddDrawable(const NzDrawable* drawable) override;
void AddLight(const NzLight* light) override;
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
void AddSprite(const NzSprite* sprite) override;
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override;
void Clear(bool fully);

View File

@@ -71,10 +71,11 @@ enum nzRenderTechniqueType
enum nzSceneNodeType
{
nzSceneNodeType_Light, // NzLight
nzSceneNodeType_Model, // NzModel
nzSceneNodeType_Root, // NzSceneRoot
nzSceneNodeType_Sprite, // NzSprite
nzSceneNodeType_Light, // NzLight
nzSceneNodeType_Model, // NzModel
nzSceneNodeType_Root, // NzSceneRoot
nzSceneNodeType_Sprite, // NzSprite
nzSceneNodeType_TextSprite, // NzTextSprite
nzSceneNodeType_User,
nzSceneNodeType_Max = nzSceneNodeType_User
@@ -85,10 +86,12 @@ enum nzShaderFlags
{
nzShaderFlags_None = 0,
nzShaderFlags_Deferred = 0x1,
nzShaderFlags_Instancing = 0x2,
nzShaderFlags_Deferred = 0x1,
nzShaderFlags_Instancing = 0x2,
nzShaderFlags_TextureOverlay = 0x4,
nzShaderFlags_VertexColor = 0x8,
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
nzShaderFlags_Max = nzShaderFlags_VertexColor*2-1
};
#endif // NAZARA_ENUMS_GRAPHICS_HPP

View File

@@ -33,7 +33,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
void AddDrawable(const NzDrawable* drawable) override;
void AddLight(const NzLight* light) override;
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
void AddSprite(const NzSprite* sprite) override;
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override;
void Clear(bool fully);
@@ -43,6 +43,12 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
bool OnResourceDestroy(const NzResource* resource, int index) override;
void OnResourceReleased(const NzResource* resource, int index) override;
struct SpriteChain_XYZ_Color_UV
{
const NzVertexStruct_XYZ_Color_UV* vertices;
unsigned int spriteCount;
};
struct TransparentModelData
{
NzMatrix4f transformMatrix;
@@ -68,12 +74,13 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
typedef std::map<NzMeshData, std::pair<NzSpheref, std::vector<NzMatrix4f>>, MeshDataComparator> MeshInstanceContainer;
typedef std::map<const NzMaterial*, std::tuple<bool, bool, MeshInstanceContainer>, BatchedModelMaterialComparator> ModelBatches;
typedef std::map<const NzMaterial*, std::vector<const NzSprite*>> BatchedSpriteContainer;
typedef std::map<const NzTexture*, std::vector<SpriteChain_XYZ_Color_UV>> BasicSpriteOverlayContainer;
typedef std::map<const NzMaterial*, BasicSpriteOverlayContainer> BasicSpriteBatches;
typedef std::vector<const NzLight*> LightContainer;
typedef std::vector<unsigned int> TransparentModelContainer;
BasicSpriteBatches basicSprites;
ModelBatches opaqueModels;
BatchedSpriteContainer sprites;
TransparentModelContainer transparentModels;
std::vector<TransparentModelData> transparentModelData;
std::vector<const NzDrawable*> otherDrawables;

View File

@@ -32,23 +32,27 @@ class NAZARA_API NzForwardRenderTechnique : public NzAbstractRenderTechnique, Nz
void SetMaxLightPassPerObject(unsigned int passCount);
private:
struct LightUniforms;
struct ShaderUniforms;
void DrawBasicSprites(const NzScene* scene) const;
void DrawOpaqueModels(const NzScene* scene) const;
void DrawSprites(const NzScene* scene) const;
void DrawTransparentModels(const NzScene* scene) const;
const LightUniforms* GetLightUniforms(const NzShader* shader) const;
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
struct LightUniforms
struct ShaderUniforms
{
NzLightUniforms uniforms;
bool exists;
int offset; // "Distance" entre Lights[0].type et Lights[1].type
NzLightUniforms lightUniforms;
bool hasLightUniforms;
/// Moins coûteux en mémoire que de stocker un NzLightUniforms par index de lumière,
/// à voir si ça fonctionne chez tout le monde
int lightOffset; // "Distance" entre Lights[0].type et Lights[1].type
// Autre uniformes
int textureOverlay;
};
mutable std::unordered_map<const NzShader*, LightUniforms> m_lightUniforms;
mutable std::unordered_map<const NzShader*, ShaderUniforms> m_shaderUniforms;
mutable NzForwardRenderQueue m_renderQueue;
NzIndexBufferRef m_indexBuffer;
mutable NzLightManager m_directionalLights;

View File

@@ -0,0 +1,23 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_GUILLOTINETEXTUREATLAS_HPP
#define NAZARA_GUILLOTINETEXTUREATLAS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/GuillotineImageAtlas.hpp>
class NAZARA_API NzGuillotineTextureAtlas : public NzGuillotineImageAtlas
{
public:
NzGuillotineTextureAtlas() = default;
~NzGuillotineTextureAtlas() = default;
private:
NzAbstractImage* ResizeImage(NzAbstractImage* oldImage, const NzVector2ui& size) const override;
};
#endif // NAZARA_GUILLOTINETEXTUREATLAS_HPP

View File

@@ -46,7 +46,6 @@ class NAZARA_API NzMaterial : public NzResource
public:
NzMaterial();
NzMaterial(const NzMaterial& material);
NzMaterial(NzMaterial&& material);
~NzMaterial();
const NzShader* Apply(nzUInt32 shaderFlags = 0, nzUInt8 textureUnit = 0, nzUInt8* lastUsedUnit = nullptr) const;
@@ -127,7 +126,6 @@ class NAZARA_API NzMaterial : public NzResource
void SetSrcBlend(nzBlendFunc func);
NzMaterial& operator=(const NzMaterial& material);
NzMaterial& operator=(NzMaterial&& material);
static NzMaterial* GetDefault();
@@ -140,6 +138,7 @@ class NAZARA_API NzMaterial : public NzResource
};
void Copy(const NzMaterial& material);
void Move(NzMaterial&& material);
void GenerateShader(nzUInt32 flags) const;
void InvalidateShaders();

View File

@@ -36,7 +36,6 @@ class NAZARA_API NzModel : public NzSceneNode
public:
NzModel();
NzModel(const NzModel& model);
NzModel(NzModel&& model);
virtual ~NzModel();
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
@@ -83,7 +82,6 @@ class NAZARA_API NzModel : public NzSceneNode
void SetSkinCount(unsigned int skinCount);
NzModel& operator=(const NzModel& node);
NzModel& operator=(NzModel&& node);
protected:
void InvalidateNode() override;

View File

@@ -41,9 +41,15 @@ class NAZARA_API NzScene
NzColor GetAmbientColor() const;
NzAbstractBackground* GetBackground() const;
NzVector3f GetBackward() const;
NzVector3f GetDown() const;
NzVector3f GetForward() const;
NzVector3f GetLeft() const;
NzAbstractRenderTechnique* GetRenderTechnique() const;
NzVector3f GetRight() const;
NzSceneNode& GetRoot() const;
NzAbstractViewer* GetViewer() const;
NzVector3f GetUp() const;
float GetUpdateTime() const;
unsigned int GetUpdatePerSecond() const;

View File

@@ -21,23 +21,30 @@ class NAZARA_API NzSceneNode : public NzNode
public:
NzSceneNode();
NzSceneNode(const NzSceneNode& sceneNode);
NzSceneNode(NzSceneNode& sceneNode) = delete;
virtual ~NzSceneNode();
virtual void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const = 0;
void EnableDrawing(bool drawingEnabled);
NzVector3f GetBackward() const;
virtual const NzBoundingVolumef& GetBoundingVolume() const = 0;
NzVector3f GetDown() const;
NzVector3f GetForward() const;
NzVector3f GetLeft() const;
nzNodeType GetNodeType() const final;
NzVector3f GetRight() const;
NzScene* GetScene() const;
virtual nzSceneNodeType GetSceneNodeType() const = 0;
NzVector3f GetUp() const;
virtual bool IsDrawable() const = 0;
bool IsDrawingEnabled() const;
bool IsVisible() const;
NzSceneNode& operator=(const NzSceneNode& sceneNode);
NzSceneNode& operator=(NzSceneNode&& sceneNode);
NzSceneNode& operator=(NzSceneNode&& sceneNode) = delete;
protected:
virtual bool FrustumCull(const NzFrustumf& frustum) const;

View File

@@ -10,6 +10,7 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
class NAZARA_API NzSprite : public NzSceneNode
{
@@ -17,12 +18,12 @@ class NAZARA_API NzSprite : public NzSceneNode
NzSprite();
NzSprite(NzTexture* texture);
NzSprite(const NzSprite& sprite);
NzSprite(NzSprite&& sprite);
~NzSprite();
~NzSprite() = default;
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
const NzBoundingVolumef& GetBoundingVolume() const override;
const NzColor& GetColor() const;
NzMaterial* GetMaterial() const;
nzSceneNodeType GetSceneNodeType() const override;
const NzVector2f& GetSize() const;
@@ -30,6 +31,8 @@ class NAZARA_API NzSprite : public NzSceneNode
bool IsDrawable() const;
void SetColor(const NzColor& color);
void SetDefaultMaterial();
void SetMaterial(NzMaterial* material, bool resizeSprite = true);
void SetSize(const NzVector2f& size);
void SetSize(float sizeX, float sizeY);
@@ -37,17 +40,23 @@ class NAZARA_API NzSprite : public NzSceneNode
void SetTextureCoords(const NzRectf& coords);
void SetTextureRect(const NzRectui& rect);
NzSprite& operator=(const NzSprite& sprite);
private:
void InvalidateNode() override;
void Register() override;
void Unregister() override;
void UpdateBoundingVolume() const;
void UpdateVertices() const;
mutable NzBoundingVolumef m_boundingVolume;
NzColor m_color;
NzMaterialRef m_material;
NzRectf m_textureCoords;
NzVector2f m_size;
mutable NzVertexStruct_XYZ_Color_UV m_vertices[4];
mutable bool m_boundingVolumeUpdated;
mutable bool m_verticesUpdated;
};
#endif // NAZARA_SPRITE_HPP

View File

@@ -0,0 +1,75 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_TEXTSPRITE_HPP
#define NAZARA_TEXTSPRITE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ResourceListener.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Graphics/SceneNode.hpp>
#include <Nazara/Utility/AbstractAtlas.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <memory>
#include <set>
class NAZARA_API NzTextSprite : public NzSceneNode, NzAbstractAtlas::Listener
{
public:
NzTextSprite();
NzTextSprite(const NzTextSprite& sprite);
~NzTextSprite();
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
void Clear();
const NzBoundingVolumef& GetBoundingVolume() const override;
const NzColor& GetColor() const;
NzMaterial* GetMaterial() const;
nzSceneNodeType GetSceneNodeType() const override;
void InvalidateVertices();
bool IsDrawable() const;
void SetColor(const NzColor& color);
void SetDefaultMaterial();
void SetMaterial(NzMaterial* material);
void SetText(const NzAbstractTextDrawer& drawer);
NzTextSprite& operator=(const NzTextSprite& text);
private:
void ClearAtlases();
void InvalidateNode() override;
bool OnAtlasCleared(const NzAbstractAtlas* atlas, void* userdata) override;
bool OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer, void* userdata) override;
void OnAtlasReleased(const NzAbstractAtlas* atlas, void* userdata) override;
void Register() override;
void Unregister() override;
void UpdateBoundingVolume() const;
void UpdateVertices() const;
struct RenderIndices
{
unsigned int first;
unsigned int count;
};
std::set<const NzAbstractAtlas*> m_atlases;
mutable std::unordered_map<NzTexture*, RenderIndices> m_renderInfos;
mutable std::vector<NzVertexStruct_XY_Color> m_localVertices;
mutable std::vector<NzVertexStruct_XYZ_Color_UV> m_vertices;
mutable NzBoundingVolumef m_boundingVolume;
NzColor m_color;
NzMaterialRef m_material;
NzRectui m_localBounds;
mutable bool m_boundingVolumeUpdated;
mutable bool m_verticesUpdated;
};
#endif // NAZARA_TEXTSPRITE_HPP

View File

@@ -32,6 +32,9 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget
NzVector3f GetEyePosition() const;
NzVector3f GetForward() const;
const NzFrustumf& GetFrustum() const;
NzVector3f GetGlobalForward() const;
NzVector3f GetGlobalRight() const;
NzVector3f GetGlobalUp() const;
const NzMatrix4f& GetProjectionMatrix() const;
const NzVector2f& GetSize() const;
const NzRenderTarget* GetTarget() const;
@@ -42,6 +45,7 @@ class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget
float GetZNear() const;
void SetSize(const NzVector2f& size);
void SetSize(float width, float height);
void SetTarget(const NzRenderTarget* renderTarget);
void SetTarget(const NzRenderTarget& renderTarget);
void SetTargetRegion(const NzRectf& region);

View File

@@ -38,7 +38,7 @@ class NzBox
NzBox& ExtendTo(const NzVector3<T>& point);
NzSphere<T> GetBoundingSphere() const;
NzVector3<T> GetCorner(nzCorner corner) const;
NzVector3<T> GetCorner(nzBoxCorner corner) const;
NzVector3<T> GetCenter() const;
NzVector3<T> GetLengths() const;
NzVector3<T> GetMaximum() const;

View File

@@ -117,32 +117,32 @@ NzBox<T>& NzBox<T>::ExtendTo(const NzVector3<T>& point)
}
template<typename T>
NzVector3<T> NzBox<T>::GetCorner(nzCorner corner) const
NzVector3<T> NzBox<T>::GetCorner(nzBoxCorner corner) const
{
switch (corner)
{
case nzCorner_FarLeftBottom:
case nzBoxCorner_FarLeftBottom:
return NzVector3<T>(x, y, z);
case nzCorner_FarLeftTop:
case nzBoxCorner_FarLeftTop:
return NzVector3<T>(x, y + height, z);
case nzCorner_FarRightBottom:
case nzBoxCorner_FarRightBottom:
return NzVector3<T>(x + width, y, z);
case nzCorner_FarRightTop:
case nzBoxCorner_FarRightTop:
return NzVector3<T>(x + width, y + height, z);
case nzCorner_NearLeftBottom:
case nzBoxCorner_NearLeftBottom:
return NzVector3<T>(x, y, z + depth);
case nzCorner_NearLeftTop:
case nzBoxCorner_NearLeftTop:
return NzVector3<T>(x, y + height, z + depth);
case nzCorner_NearRightBottom:
case nzBoxCorner_NearRightBottom:
return NzVector3<T>(x + width, y, z + depth);
case nzCorner_NearRightTop:
case nzBoxCorner_NearRightTop:
return NzVector3<T>(x + width, y + height, z + depth);
}

View File

@@ -7,18 +7,18 @@
#ifndef NAZARA_ENUMS_MATH_HPP
#define NAZARA_ENUMS_MATH_HPP
enum nzCorner
enum nzBoxCorner
{
nzCorner_FarLeftBottom,
nzCorner_FarLeftTop,
nzCorner_FarRightBottom,
nzCorner_FarRightTop,
nzCorner_NearLeftBottom,
nzCorner_NearLeftTop,
nzCorner_NearRightBottom,
nzCorner_NearRightTop,
nzBoxCorner_FarLeftBottom,
nzBoxCorner_FarLeftTop,
nzBoxCorner_FarRightBottom,
nzBoxCorner_FarRightTop,
nzBoxCorner_NearLeftBottom,
nzBoxCorner_NearLeftTop,
nzBoxCorner_NearRightBottom,
nzBoxCorner_NearRightTop,
nzCorner_Max = nzCorner_NearRightTop
nzBoxCorner_Max = nzBoxCorner_NearRightTop
};
enum nzExtend
@@ -51,4 +51,14 @@ enum nzIntersectionSide
nzIntersectionSide_Max = nzIntersectionSide_Outside
};
enum nzRectCorner
{
nzRectCorner_LeftBottom,
nzRectCorner_LeftTop,
nzRectCorner_RightBottom,
nzRectCorner_RightTop,
nzRectCorner_Max = nzRectCorner_RightTop
};
#endif // NAZARA_ENUMS_MATH_HPP

View File

@@ -37,7 +37,7 @@ class NzFrustum
NzFrustum& Extract(const NzMatrix4<T>& clipMatrix);
NzFrustum& Extract(const NzMatrix4<T>& view, const NzMatrix4<T>& projection);
const NzVector3<T>& GetCorner(nzCorner corner) const;
const NzVector3<T>& GetCorner(nzBoxCorner corner) const;
const NzPlane<T>& GetPlane(nzFrustumPlane plane) const;
nzIntersectionSide Intersect(const NzBoundingVolume<T>& volume) const;
@@ -52,7 +52,7 @@ class NzFrustum
NzString ToString() const;
private:
NzVector3<T> m_corners[nzCorner_Max+1];
NzVector3<T> m_corners[nzBoxCorner_Max+1];
NzPlane<T> m_planes[nzFrustumPlane_Max+1];
};

View File

@@ -44,23 +44,23 @@ NzFrustum<T>& NzFrustum<T>::Build(T angle, T ratio, T zNear, T zFar, const NzVec
NzVector3<T> fc = eye + f * zFar;
// Calcul du frustum
m_corners[nzCorner_FarLeftBottom] = fc - u*farH - s*farW;
m_corners[nzCorner_FarLeftTop] = fc + u*farH - s*farW;
m_corners[nzCorner_FarRightTop] = fc + u*farH + s*farW;
m_corners[nzCorner_FarRightBottom] = fc - u*farH + s*farW;
m_corners[nzBoxCorner_FarLeftBottom] = fc - u*farH - s*farW;
m_corners[nzBoxCorner_FarLeftTop] = fc + u*farH - s*farW;
m_corners[nzBoxCorner_FarRightTop] = fc + u*farH + s*farW;
m_corners[nzBoxCorner_FarRightBottom] = fc - u*farH + s*farW;
m_corners[nzCorner_NearLeftBottom] = nc - u*nearH - s*nearW;
m_corners[nzCorner_NearLeftTop] = nc + u*nearH - s*nearW;
m_corners[nzCorner_NearRightTop] = nc + u*nearH + s*nearW;
m_corners[nzCorner_NearRightBottom] = nc - u*nearH + s*nearW;
m_corners[nzBoxCorner_NearLeftBottom] = nc - u*nearH - s*nearW;
m_corners[nzBoxCorner_NearLeftTop] = nc + u*nearH - s*nearW;
m_corners[nzBoxCorner_NearRightTop] = nc + u*nearH + s*nearW;
m_corners[nzBoxCorner_NearRightBottom] = nc - u*nearH + s*nearW;
// Construction des plans du frustum
m_planes[nzFrustumPlane_Bottom].Set(m_corners[nzCorner_NearLeftBottom], m_corners[nzCorner_NearRightBottom], m_corners[nzCorner_FarRightBottom]);
m_planes[nzFrustumPlane_Far].Set(m_corners[nzCorner_FarRightTop], m_corners[nzCorner_FarLeftTop], m_corners[nzCorner_FarLeftBottom]);
m_planes[nzFrustumPlane_Left].Set(m_corners[nzCorner_NearLeftTop], m_corners[nzCorner_NearLeftBottom], m_corners[nzCorner_FarLeftBottom]);
m_planes[nzFrustumPlane_Near].Set(m_corners[nzCorner_NearLeftTop], m_corners[nzCorner_NearRightTop], m_corners[nzCorner_NearRightBottom]);
m_planes[nzFrustumPlane_Right].Set(m_corners[nzCorner_NearRightBottom], m_corners[nzCorner_NearRightTop], m_corners[nzCorner_FarRightBottom]);
m_planes[nzFrustumPlane_Top].Set(m_corners[nzCorner_NearRightTop], m_corners[nzCorner_NearLeftTop], m_corners[nzCorner_FarLeftTop]);
m_planes[nzFrustumPlane_Bottom].Set(m_corners[nzBoxCorner_NearLeftBottom], m_corners[nzBoxCorner_NearRightBottom], m_corners[nzBoxCorner_FarRightBottom]);
m_planes[nzFrustumPlane_Far].Set(m_corners[nzBoxCorner_FarRightTop], m_corners[nzBoxCorner_FarLeftTop], m_corners[nzBoxCorner_FarLeftBottom]);
m_planes[nzFrustumPlane_Left].Set(m_corners[nzBoxCorner_NearLeftTop], m_corners[nzBoxCorner_NearLeftBottom], m_corners[nzBoxCorner_FarLeftBottom]);
m_planes[nzFrustumPlane_Near].Set(m_corners[nzBoxCorner_NearLeftTop], m_corners[nzBoxCorner_NearRightTop], m_corners[nzBoxCorner_NearRightBottom]);
m_planes[nzFrustumPlane_Right].Set(m_corners[nzBoxCorner_NearRightBottom], m_corners[nzBoxCorner_NearRightTop], m_corners[nzBoxCorner_FarRightBottom]);
m_planes[nzFrustumPlane_Top].Set(m_corners[nzBoxCorner_NearRightTop], m_corners[nzBoxCorner_NearLeftTop], m_corners[nzBoxCorner_FarLeftTop]);
return *this;
}
@@ -272,56 +272,56 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_FarLeftBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_FarLeftBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
// FarLeftTop
corner.Set(F(-1.0), F(1.0), F(1.0));
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_FarLeftTop] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_FarLeftTop] = NzVector3<T>(corner.x, corner.y, corner.z);
// FarRightBottom
corner.Set(F(1.0), F(-1.0), F(1.0));
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_FarRightBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_FarRightBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
// FarRightTop
corner.Set(F(1.0), F(1.0), F(1.0));
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_FarRightTop] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_FarRightTop] = NzVector3<T>(corner.x, corner.y, corner.z);
// NearLeftBottom
corner.Set(F(-1.0), F(-1.0), F(0.0));
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_NearLeftBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_NearLeftBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
// NearLeftTop
corner.Set(F(-1.0), F(1.0), F(0.0));
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_NearLeftTop] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_NearLeftTop] = NzVector3<T>(corner.x, corner.y, corner.z);
// NearRightBottom
corner.Set(F(1.0), F(-1.0), F(0.0));
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_NearRightBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_NearRightBottom] = NzVector3<T>(corner.x, corner.y, corner.z);
// NearRightTop
corner.Set(F(1.0), F(1.0), F(0.0));
corner = invClipMatrix.Transform(corner);
corner.Normalize();
m_corners[nzCorner_NearRightTop] = NzVector3<T>(corner.x, corner.y, corner.z);
m_corners[nzBoxCorner_NearRightTop] = NzVector3<T>(corner.x, corner.y, corner.z);
}
else
NazaraWarning("Clip matrix is not invertible, failed to compute frustum corners");
@@ -339,10 +339,10 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& view, const NzMatrix4<T>
}
template<typename T>
const NzVector3<T>& NzFrustum<T>::GetCorner(nzCorner corner) const
const NzVector3<T>& NzFrustum<T>::GetCorner(nzBoxCorner corner) const
{
#ifdef NAZARA_DEBUG
if (corner > nzCorner_Max)
if (corner > nzBoxCorner_Max)
{
NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')');
@@ -481,7 +481,7 @@ template<typename T>
template<typename U>
NzFrustum<T>& NzFrustum<T>::Set(const NzFrustum<U>& frustum)
{
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i)
m_corners[i].Set(frustum.m_corners[i]);
for (unsigned int i = 0; i <= nzFrustumPlane_Max; ++i)

View File

@@ -24,7 +24,7 @@ class NzOrientedBox
NzOrientedBox(const NzOrientedBox& orientedBox) = default;
~NzOrientedBox() = default;
const NzVector3<T>& GetCorner(nzCorner corner) const;
const NzVector3<T>& GetCorner(nzBoxCorner corner) const;
bool IsValid() const;
@@ -59,7 +59,7 @@ class NzOrientedBox
NzBox<T> localBox;
private:
NzVector3<T> m_corners[nzCorner_Max+1]; // Ne peuvent pas être modifiés directement
NzVector3<T> m_corners[nzBoxCorner_Max+1]; // Ne peuvent pas être modifiés directement
};
template<typename T>

View File

@@ -37,10 +37,10 @@ NzOrientedBox<T>::NzOrientedBox(const NzOrientedBox<U>& orientedBox)
}
template<typename T>
const NzVector3<T>& NzOrientedBox<T>::GetCorner(nzCorner corner) const
const NzVector3<T>& NzOrientedBox<T>::GetCorner(nzBoxCorner corner) const
{
#ifdef NAZARA_DEBUG
if (corner > nzCorner_Max)
if (corner > nzBoxCorner_Max)
{
NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')');
@@ -102,7 +102,7 @@ template<typename T>
template<typename U>
NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzOrientedBox<U>& orientedBox)
{
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i)
m_corners[i].Set(orientedBox.m_corners[i]);
localBox = orientedBox.localBox;
@@ -115,21 +115,21 @@ NzString NzOrientedBox<T>::ToString() const
{
NzStringStream ss;
return ss << "OrientedBox(FLB: " << m_corners[nzCorner_FarLeftBottom].ToString() << "\n"
<< " FLT: " << m_corners[nzCorner_FarLeftTop].ToString() << "\n"
<< " FRB: " << m_corners[nzCorner_FarRightBottom].ToString() << "\n"
<< " FRT: " << m_corners[nzCorner_FarRightTop].ToString() << "\n"
<< " NLB: " << m_corners[nzCorner_NearLeftBottom].ToString() << "\n"
<< " NLT: " << m_corners[nzCorner_NearLeftTop].ToString() << "\n"
<< " NRB: " << m_corners[nzCorner_NearRightBottom].ToString() << "\n"
<< " NRT: " << m_corners[nzCorner_NearRightTop].ToString() << ")\n";
return ss << "OrientedBox(FLB: " << m_corners[nzBoxCorner_FarLeftBottom].ToString() << "\n"
<< " FLT: " << m_corners[nzBoxCorner_FarLeftTop].ToString() << "\n"
<< " FRB: " << m_corners[nzBoxCorner_FarRightBottom].ToString() << "\n"
<< " FRT: " << m_corners[nzBoxCorner_FarRightTop].ToString() << "\n"
<< " NLB: " << m_corners[nzBoxCorner_NearLeftBottom].ToString() << "\n"
<< " NLT: " << m_corners[nzBoxCorner_NearLeftTop].ToString() << "\n"
<< " NRB: " << m_corners[nzBoxCorner_NearRightBottom].ToString() << "\n"
<< " NRT: " << m_corners[nzBoxCorner_NearRightTop].ToString() << ")\n";
}
template<typename T>
void NzOrientedBox<T>::Update(const NzMatrix4<T>& transformMatrix)
{
for (unsigned int i = 0; i <= nzCorner_Max; ++i)
m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast<nzCorner>(i)));
for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i)
m_corners[i] = transformMatrix.Transform(localBox.GetCorner(static_cast<nzBoxCorner>(i)));
}
template<typename T>
@@ -148,7 +148,7 @@ template<typename T>
NzVector3<T>& NzOrientedBox<T>::operator()(unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i > nzCorner_Max)
if (i > nzBoxCorner_Max)
{
NzStringStream ss;
ss << "Index out of range: (" << i << " >= 3)";
@@ -165,7 +165,7 @@ template<typename T>
NzVector3<T> NzOrientedBox<T>::operator()(unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i > nzCorner_Max)
if (i > nzBoxCorner_Max)
{
NzStringStream ss;
ss << "Index out of range: (" << i << " >= 3)";

View File

@@ -204,9 +204,9 @@ bool NzRay<T>::Intersect(const NzBox<T>& box, const NzMatrix4<T>& transform, T*
template<typename T>
bool NzRay<T>::Intersect(const NzOrientedBox<T>& orientedBox, T* closestHit, T* farthestHit) const
{
NzVector3<T> width = (orientedBox.GetCorner(nzCorner_NearLeftBottom) - orientedBox.GetCorner(nzCorner_FarLeftBottom)).Normalize();
NzVector3<T> height = (orientedBox.GetCorner(nzCorner_FarLeftTop) - orientedBox.GetCorner(nzCorner_FarLeftBottom)).Normalize();
NzVector3<T> depth = (orientedBox.GetCorner(nzCorner_FarRightBottom) - orientedBox.GetCorner(nzCorner_FarLeftBottom)).Normalize();
NzVector3<T> width = (orientedBox.GetCorner(nzBoxCorner_NearLeftBottom) - orientedBox.GetCorner(nzBoxCorner_FarLeftBottom)).Normalize();
NzVector3<T> height = (orientedBox.GetCorner(nzBoxCorner_FarLeftTop) - orientedBox.GetCorner(nzBoxCorner_FarLeftBottom)).Normalize();
NzVector3<T> depth = (orientedBox.GetCorner(nzBoxCorner_FarRightBottom) - orientedBox.GetCorner(nzBoxCorner_FarLeftBottom)).Normalize();
// Construction de la matrice de transformation de l'OBB
NzMatrix4<T> matrix(width.x, height.x, depth.x, F(0.0),

View File

@@ -8,6 +8,7 @@
#define NAZARA_RECT_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Enums.hpp>
#include <Nazara/Math/Vector2.hpp>
template<typename T>
@@ -33,6 +34,7 @@ class NzRect
NzRect& ExtendTo(const NzRect& rect);
NzVector2<T> GetCenter() const;
NzVector2<T> GetCorner(nzRectCorner corner) const;
NzVector2<T> GetLengths() const;
NzVector2<T> GetMaximum() const;
NzVector2<T> GetMinimum() const;

View File

@@ -109,6 +109,28 @@ NzVector2<T> NzRect<T>::GetCenter() const
return GetPosition() + GetLengths() / F(2.0);
}
template<typename T>
NzVector2<T> NzRect<T>::GetCorner(nzRectCorner corner) const
{
switch (corner)
{
case nzRectCorner_LeftBottom:
return NzVector2<T>(x, y + height);
case nzRectCorner_LeftTop:
return NzVector2<T>(x, y);
case nzRectCorner_RightBottom:
return NzVector2<T>(x + width, y + height);
case nzRectCorner_RightTop:
return NzVector2<T>(x + width, y);
}
NazaraError("Corner not handled (0x" + NzString::Number(corner, 16) + ')');
return NzVector2<T>();
}
template<typename T>
NzVector2<T> NzRect<T>::GetLengths() const
{

View File

@@ -9,6 +9,9 @@
#include <Nazara/Core/String.hpp>
template<typename T> class NzVector3;
template<typename T> class NzVector4;
template<typename T>
class NzVector2
{
@@ -19,6 +22,8 @@ class NzVector2
NzVector2(const T vec[2]);
template<typename U> explicit NzVector2(const NzVector2<U>& vec);
NzVector2(const NzVector2& vec) = default;
explicit NzVector2(const NzVector3<T>& vec);
explicit NzVector2(const NzVector4<T>& vec);
~NzVector2() = default;
T AbsDotProduct(const NzVector2& vec) const;
@@ -48,6 +53,8 @@ class NzVector2
NzVector2& Set(T scale);
NzVector2& Set(const T vec[2]);
NzVector2& Set(const NzVector2& vec);
NzVector2& Set(const NzVector3<T>& vec);
NzVector2& Set(const NzVector4<T>& vec);
template<typename U> NzVector2& Set(const NzVector2<U>& vec);
T SquaredDistance(const NzVector2& vec) const;

View File

@@ -36,6 +36,18 @@ NzVector2<T>::NzVector2(const NzVector2<U>& vec)
Set(vec);
}
template<typename T>
NzVector2<T>::NzVector2(const NzVector3<T>& vec)
{
Set(vec);
}
template<typename T>
NzVector2<T>::NzVector2(const NzVector4<T>& vec)
{
Set(vec);
}
template<typename T>
T NzVector2<T>::AbsDotProduct(const NzVector2& vec) const
{
@@ -208,6 +220,24 @@ NzVector2<T>& NzVector2<T>::Set(const NzVector2<U>& vec)
return *this;
}
template<typename T>
NzVector2<T>& NzVector2<T>::Set(const NzVector3<T>& vec)
{
x = vec.x;
y = vec.y;
return *this;
}
template<typename T>
NzVector2<T>& NzVector2<T>::Set(const NzVector4<T>& vec)
{
x = vec.x;
y = vec.y;
return *this;
}
template<typename T>
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
{

View File

@@ -8,18 +8,23 @@
#define NAZARA_VECTOR3_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
template<typename T> class NzVector3
template<typename T> class NzVector2;
template<typename T> class NzVector4;
template<typename T>
class NzVector3
{
public:
NzVector3() = default;
NzVector3(T X, T Y, T Z);
NzVector3(T X, const NzVector2<T>& vec);
explicit NzVector3(T scale);
NzVector3(const T vec[3]);
NzVector3(const NzVector2<T>& vec, T Z = 0.0);
template<typename U> explicit NzVector3(const NzVector3<U>& vec);
NzVector3(const NzVector3& vec) = default;
explicit NzVector3(const NzVector4<T>& vec);
~NzVector3() = default;
T AbsDotProduct(const NzVector3& vec) const;
@@ -56,11 +61,13 @@ template<typename T> class NzVector3
NzVector3& Normalize(T* length = nullptr);
NzVector3& Set(T X, T Y, T Z);
NzVector3& Set(T X, const NzVector2<T>& vec);
NzVector3& Set(T scale);
NzVector3& Set(const T vec[3]);
NzVector3& Set(const NzVector2<T>& vec, T Z = 0.0);
NzVector3& Set(const NzVector3<T>& vec);
template<typename U> NzVector3& Set(const NzVector3<U>& vec);
NzVector3& Set(const NzVector4<T>& vec);
T SquaredDistance(const NzVector3& vec) const;

View File

@@ -17,6 +17,12 @@ NzVector3<T>::NzVector3(T X, T Y, T Z)
Set(X, Y, Z);
}
template<typename T>
NzVector3<T>::NzVector3(T X, const NzVector2<T>& vec)
{
Set(X, vec);
}
template<typename T>
NzVector3<T>::NzVector3(T scale)
{
@@ -42,6 +48,12 @@ NzVector3<T>::NzVector3(const NzVector3<U>& vec)
Set(vec);
}
template<typename T>
NzVector3<T>::NzVector3(const NzVector4<T>& vec)
{
Set(vec);
}
template<typename T>
T NzVector3<T>::AbsDotProduct(const NzVector3& vec) const
{
@@ -255,6 +267,16 @@ NzVector3<T>& NzVector3<T>::Set(T X, T Y, T Z)
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::Set(T X, const NzVector2<T>& vec)
{
x = X;
y = vec.x;
z = vec.y;
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::Set(T scale)
{
@@ -302,6 +324,16 @@ NzVector3<T>& NzVector3<T>::Set(const NzVector3<U>& vec)
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::Set(const NzVector4<T>& vec)
{
x = vec.x;
y = vec.y;
z = vec.z;
return *this;
}
template<typename T>
T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
{

View File

@@ -8,16 +8,23 @@
#define NAZARA_VECTOR4_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T> class NzVector4
template<typename T> class NzVector2;
template<typename T> class NzVector3;
template<typename T>
class NzVector4
{
public:
NzVector4() = default;
NzVector4(T X, T Y, T Z, T W = 1.0);
NzVector4(T X, T Y, const NzVector2<T>& vec);
NzVector4(T X, const NzVector2<T>& vec, T W);
NzVector4(T X, const NzVector3<T>& vec);
explicit NzVector4(T scale);
NzVector4(const T vec[4]);
NzVector4(const NzVector3<T>& vec, T W = 1.0);
NzVector4(const NzVector2<T>& vec, T Z = 0.0, T W = 1.0);
NzVector4(const NzVector3<T>& vec, T W = 0.0);
template<typename U> explicit NzVector4(const NzVector4<U>& vec);
NzVector4(const NzVector4& vec) = default;
~NzVector4() = default;
@@ -39,8 +46,12 @@ template<typename T> class NzVector4
NzVector4& Normalize(T* length = nullptr);
NzVector4& Set(T X, T Y, T Z, T W = 1.0);
NzVector4& Set(T X, T Y, const NzVector2<T>& vec);
NzVector4& Set(T X, const NzVector2<T>& vec, T W);
NzVector4& Set(T X, const NzVector3<T>& vec);
NzVector4& Set(T scale);
NzVector4& Set(const T vec[4]);
NzVector4& Set(const NzVector2<T>& vec, T Z = 0.0, T W = 1.0);
NzVector4& Set(const NzVector3<T>& vec, T W = 1.0);
NzVector4& Set(const NzVector4<T>& vec);
template<typename U> NzVector4& Set(const NzVector4<U>& vec);

View File

@@ -18,6 +18,24 @@ NzVector4<T>::NzVector4(T X, T Y, T Z, T W)
Set(X, Y, Z, W);
}
template<typename T>
NzVector4<T>::NzVector4(T X, T Y, const NzVector2<T>& vec)
{
Set(X, Y, vec);
}
template<typename T>
NzVector4<T>::NzVector4(T X, const NzVector2<T>& vec, T W)
{
Set(X, vec, W);
}
template<typename T>
NzVector4<T>::NzVector4(T X, const NzVector3<T>& vec)
{
Set(X, vec);
}
template<typename T>
NzVector4<T>::NzVector4(T scale)
{
@@ -30,6 +48,12 @@ NzVector4<T>::NzVector4(const T vec[4])
Set(vec);
}
template<typename T>
NzVector4<T>::NzVector4(const NzVector2<T>& vec, T Z, T W)
{
Set(vec, Z, W);
}
template<typename T>
NzVector4<T>::NzVector4(const NzVector3<T>& vec, T W)
{
@@ -155,10 +179,43 @@ NzVector4<T>& NzVector4<T>::Normalize(T* length)
template<typename T>
NzVector4<T>& NzVector4<T>::Set(T X, T Y, T Z, T W)
{
w = W;
x = X;
y = Y;
z = Z;
w = W;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::Set(T X, T Y, const NzVector2<T>& vec)
{
x = X;
y = Y;
z = vec.x;
w = vec.y;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::Set(T X, const NzVector2<T>& vec, T W)
{
x = X;
y = vec.x;
z = vec.y;
w = W;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::Set(T X, const NzVector3<T>& vec)
{
x = X;
y = vec.x;
z = vec.y;
w = vec.z;
return *this;
}
@@ -166,10 +223,10 @@ NzVector4<T>& NzVector4<T>::Set(T X, T Y, T Z, T W)
template<typename T>
NzVector4<T>& NzVector4<T>::Set(T scale)
{
w = scale;
x = scale;
y = scale;
z = scale;
w = scale;
return *this;
}
@@ -182,6 +239,17 @@ NzVector4<T>& NzVector4<T>::Set(const T vec[4])
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::Set(const NzVector2<T>& vec, T Z, T W)
{
x = vec.x;
y = vec.y;
z = Z;
w = W;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::Set(const NzVector3<T>& vec, T W)
{
@@ -205,10 +273,10 @@ template<typename T>
template<typename U>
NzVector4<T>& NzVector4<T>::Set(const NzVector4<U>& vec)
{
w = F(vec.w);
x = F(vec.x);
y = F(vec.y);
z = F(vec.z);
w = F(vec.w);
return *this;
}

View File

@@ -27,6 +27,7 @@ class NAZARA_API NzDebugDrawer
static void Draw(const NzFrustumf& frustum);
static void Draw(const NzOrientedBoxf& orientedBox);
static void Draw(const NzSkeleton* skeleton);
static void Draw(const NzVector3f& position, float size = 0.1f);
static void DrawBinormals(const NzStaticMesh* subMesh);
static void DrawCone(const NzVector3f& origin, const NzQuaternionf& rotation, float angle, float length);
static void DrawLine(const NzVector3f& p1, const NzVector3f& p2);

View File

@@ -187,6 +187,7 @@ enum nzSamplerWrap
enum nzShaderUniform
{
///FIXME: Virer EyePosition, SceneAmbient et TargetSize de l'énumération (ils n'ont rien à faire dans le module de rendu)
nzShaderUniform_EyePosition,
nzShaderUniform_InvProjMatrix,
nzShaderUniform_InvTargetSize,

View File

@@ -69,6 +69,7 @@ class NAZARA_API NzOpenGL
GLenum dataFormat;
GLenum dataType;
GLint internalFormat;
GLint swizzle[4];
};
NzOpenGL() = delete;

View File

@@ -44,7 +44,7 @@ class NAZARA_API NzRenderTarget
{
public:
Listener() = default;
~Listener();
virtual ~Listener();
virtual bool OnRenderTargetParametersChange(const NzRenderTarget* renderTarget, void* userdata);
virtual void OnRenderTargetReleased(const NzRenderTarget* renderTarget, void* userdata);

View File

@@ -57,6 +57,7 @@ class NAZARA_API NzRenderer
static nzUInt8 GetMaxAnisotropyLevel();
static unsigned int GetMaxColorAttachments();
static unsigned int GetMaxRenderTargets();
static unsigned int GetMaxTextureSize();
static unsigned int GetMaxTextureUnits();
static unsigned int GetMaxVertexAttribs();
static float GetPointSize();

View File

@@ -12,9 +12,9 @@
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/AbstractImage.hpp>
#include <Nazara/Utility/CubemapParams.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
class NzTexture;
@@ -23,13 +23,13 @@ using NzTextureRef = NzResourceRef<NzTexture>;
struct NzTextureImpl;
class NAZARA_API NzTexture : public NzResource, NzNonCopyable
class NAZARA_API NzTexture : public NzAbstractImage, public NzResource, NzNonCopyable
{
friend class NzRenderer;
friend class NzRenderTexture;
public:
NzTexture() = default;
NzTexture(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1);
explicit NzTexture(const NzImage& image);
~NzTexture();
@@ -42,18 +42,20 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
void EnsureMipmapsUpdate() const;
nzUInt8 GetBytesPerPixel() const;
unsigned int GetDepth() const;
unsigned int GetDepth(nzUInt8 level = 0) const;
nzPixelFormat GetFormat() const;
unsigned int GetHeight() const;
NzVector2ui GetSize() const;
unsigned int GetHeight(nzUInt8 level = 0) const;
nzUInt8 GetLevelCount() const;
nzUInt8 GetMaxLevel() const;
unsigned int GetMemoryUsage() const;
unsigned int GetMemoryUsage(nzUInt8 level) const;
NzVector3ui GetSize(nzUInt8 level = 0) const;
nzImageType GetType() const;
unsigned int GetWidth() const;
unsigned int GetWidth(nzUInt8 level = 0) const;
bool HasMipmaps() const;
bool IsCompressed() const;
bool IsCubemap() const;
void InvalidateMipmaps();
bool IsValid() const;
// Load
@@ -87,10 +89,6 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
bool Update(const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, 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, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
// Fonctions OpenGL
unsigned int GetOpenGLID() const;
@@ -101,7 +99,7 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
static bool IsTypeSupported(nzImageType type);
private:
void InvalidateMipmaps();
bool CreateTexture(bool proxy);
NzTextureImpl* m_impl = nullptr;
};

View File

@@ -0,0 +1,56 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ABSTRACTATLAS_HPP
#define NAZARA_ABSTRACTATLAS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Math/Rect.hpp>
#include <unordered_map>
class NzAbstractImage;
class NzImage;
class NAZARA_API NzAbstractAtlas
{
public:
class Listener;
NzAbstractAtlas();
virtual ~NzAbstractAtlas();
void AddListener(Listener* font, void* userdata = nullptr) const;
virtual void Clear() = 0;
virtual void Free(NzSparsePtr<const NzRectui> rects, NzSparsePtr<unsigned int> layers, unsigned int count) = 0;
virtual NzAbstractImage* GetLayer(unsigned int layerIndex) const = 0;
virtual unsigned int GetLayerCount() const = 0;
virtual bool Insert(const NzImage& image, NzRectui* rect, bool* flipped, unsigned int* layerIndex) = 0;
void RemoveListener(Listener* font) const;
class Listener
{
public:
Listener() = default;
virtual ~Listener();
virtual bool OnAtlasCleared(const NzAbstractAtlas* atlas, void* userdata);
virtual bool OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer, void* userdata);
virtual void OnAtlasReleased(const NzAbstractAtlas* atlas, void* userdata);
};
protected:
void NotifyCleared();
void NotifyLayerChange(NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
private:
mutable std::unordered_map<Listener*, void*> m_listeners;
bool m_listenersLocked;
};
#endif // NAZARA_ABSTRACTATLAS_HPP

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ABSTRACTIMAGE_HPP
#define NAZARA_ABSTRACTIMAGE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
class NAZARA_API NzAbstractImage
{
public:
NzAbstractImage() = default;
virtual ~NzAbstractImage();
nzUInt8 GetBytesPerPixel() const;
virtual unsigned int GetDepth(nzUInt8 level = 0) const = 0;
virtual nzPixelFormat GetFormat() const = 0;
virtual unsigned int GetHeight(nzUInt8 level = 0) const = 0;
virtual nzUInt8 GetLevelCount() const = 0;
virtual nzUInt8 GetMaxLevel() const = 0;
virtual unsigned int GetMemoryUsage() const = 0;
virtual unsigned int GetMemoryUsage(nzUInt8 level) const = 0;
virtual NzVector3ui GetSize(nzUInt8 level = 0) const = 0;
virtual nzImageType GetType() const = 0;
virtual unsigned int GetWidth(nzUInt8 level = 0) const = 0;
bool IsCompressed() const;
bool IsCubemap() const;
virtual bool Update(const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0) = 0;
virtual bool Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0) = 0;
virtual bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0) = 0;
};
#endif // NAZARA_IMAGE_HPP

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ABSTRACTTEXTDRAWER_HPP
#define NAZARA_ABSTRACTTEXTDRAWER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp>
class NzAbstractImage;
class NzFont;
class NAZARA_API NzAbstractTextDrawer
{
public:
struct Glyph;
NzAbstractTextDrawer() = default;
virtual ~NzAbstractTextDrawer();
virtual const NzRectui& GetBounds() const = 0;
virtual NzFont* GetFont(unsigned int index) const = 0;
virtual unsigned int GetFontCount() const = 0;
virtual const Glyph& GetGlyph(unsigned int index) const = 0;
virtual unsigned int GetGlyphCount() const = 0;
struct Glyph
{
NzColor color;
NzRectui atlasRect;
NzVector2f corners[4];
NzAbstractImage* atlas;
bool flipped;
};
};
#endif // NAZARA_ABSTRACTTEXTDRAWER_HPP

View File

@@ -25,22 +25,22 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
friend class NzUtility;
public:
using BufferFunction = NzAbstractBuffer* (*)(NzBuffer* parent, nzBufferType type);
using BufferFactory = NzAbstractBuffer* (*)(NzBuffer* parent, nzBufferType type);
NzBuffer(nzBufferType type);
NzBuffer(nzBufferType type, unsigned int size, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzBuffer(nzBufferType type, unsigned int size, nzUInt32 storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
~NzBuffer();
bool CopyContent(const NzBuffer& buffer);
bool Create(unsigned int size, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
bool Create(unsigned int size, nzUInt32 storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Destroy();
bool Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard = false);
NzAbstractBuffer* GetImpl() const;
unsigned int GetSize() const;
nzBufferStorage GetStorage() const;
nzUInt32 GetStorage() const;
nzBufferType GetType() const;
nzBufferUsage GetUsage() const;
@@ -50,24 +50,24 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0);
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) const;
bool SetStorage(nzBufferStorage storage);
bool SetStorage(nzUInt32 storage);
void Unmap() const;
static bool IsSupported(nzBufferStorage storage);
static void SetBufferFunction(nzBufferStorage storage, BufferFunction func);
static bool IsStorageSupported(nzUInt32 storage);
static void SetBufferFactory(nzUInt32 storage, BufferFactory func);
private:
static bool Initialize();
static void Uninitialize();
nzBufferStorage m_storage;
nzBufferType m_type;
nzBufferUsage m_usage;
nzUInt32 m_storage;
NzAbstractBuffer* m_impl;
unsigned int m_size;
static BufferFunction s_bufferFunctions[nzBufferStorage_Max+1];
static BufferFactory s_bufferFactories[nzDataStorage_Max+1];
};
#endif // NAZARA_BUFFER_HPP

View File

@@ -25,15 +25,6 @@ enum nzBufferAccess
nzBufferAccess_Max = nzBufferAccess_WriteOnly
};
enum nzBufferStorage
{
//nzBufferStorage_Both, ///TODO
nzBufferStorage_Hardware,
nzBufferStorage_Software,
nzBufferStorage_Max = nzBufferStorage_Software
};
enum nzBufferType
{
nzBufferType_Index,
@@ -84,6 +75,16 @@ enum nzCubemapFace
nzCubemapFace_Max = nzCubemapFace_NegativeZ
};
enum nzDataStorageFlags
{
nzDataStorage_Hardware = 0x1,
nzDataStorage_Software = 0x2,
nzDataStorage_Both = nzDataStorage_Hardware | nzDataStorage_Software,
nzDataStorage_Max = nzDataStorage_Software*2-1
};
enum nzEventType
{
nzEventType_GainedFocus,
@@ -130,6 +131,7 @@ enum nzPixelFormat
{
nzPixelFormat_Undefined = -1,
nzPixelFormat_A8, // 1*uint8
nzPixelFormat_BGR8, // 3*uint8
nzPixelFormat_BGRA8, // 4*uint8
nzPixelFormat_DXT1,
@@ -217,6 +219,27 @@ enum nzPrimitiveMode
nzPrimitiveMode_Max = nzPrimitiveMode_TriangleFan
};
enum nzTextAlign
{
nzTextAlign_Left,
nzTextAlign_Middle,
nzTextAlign_Right,
nzTextAlign_Max = nzTextAlign_Right
};
enum nzTextStyleFlags
{
nzTextStyle_Regular = 0x0,
nzTextStyle_Bold = 0x1,
nzTextStyle_Italic = 0x2,
nzTextStyle_StrikeThrough = 0x4,
nzTextStyle_Underlined = 0x8,
nzTextStyle_Max = nzTextStyle_Underlined*2-1
};
enum nzVertexComponent
{
nzVertexComponent_Unused = -1,
@@ -251,8 +274,11 @@ enum nzVertexLayout
{
// Déclarations destinées au rendu
nzVertexLayout_XY,
nzVertexLayout_XY_Color,
nzVertexLayout_XY_UV,
nzVertexLayout_XYZ,
nzVertexLayout_XYZ_Color,
nzVertexLayout_XYZ_Color_UV,
nzVertexLayout_XYZ_Normal,
nzVertexLayout_XYZ_Normal_UV,
nzVertexLayout_XYZ_Normal_UV_Tangent,

View File

@@ -0,0 +1,129 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FONT_HPP
#define NAZARA_FONT_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Utility/AbstractAtlas.hpp>
#include <memory>
#include <unordered_map>
struct NAZARA_API NzFontParams
{
bool IsValid() const;
};
class NzFont;
class NzFontData;
struct NzFontGlyph;
using NzFontConstRef = NzResourceRef<const NzFont>;
using NzFontLoader = NzResourceLoader<NzFont, NzFontParams>;
using NzFontRef = NzResourceRef<NzFont>;
class NAZARA_API NzFont : public NzResource, NzAbstractAtlas::Listener, NzNonCopyable
{
friend NzFontLoader;
public:
struct Glyph;
struct SizeInfo;
NzFont();
NzFont(NzFont&& font) = default;
~NzFont();
void ClearGlyphCache();
void ClearKerningCache();
void ClearSizeInfoCache();
bool Create(NzFontData* data);
void Destroy();
bool ExtractGlyph(unsigned int characterSize, char32_t character, nzUInt32 style, NzFontGlyph* glyph) const;
const NzAbstractAtlas* GetAtlas() const;
unsigned int GetCachedGlyphCount(unsigned int characterSize, nzUInt32 style) const;
unsigned int GetCachedGlyphCount() const;
NzString GetFamilyName() const;
int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const;
const Glyph& GetGlyph(unsigned int characterSize, nzUInt32 style, char32_t character) const;
unsigned int GetGlyphBorder() const;
unsigned int GetMinimumStepSize() const;
const SizeInfo& GetSizeInfo(unsigned int characterSize) const;
NzString GetStyleName() const;
bool IsValid() const;
bool Precache(unsigned int characterSize, nzUInt32 style, char32_t character) const;
bool Precache(unsigned int characterSize, nzUInt32 style, const NzString& characterSet) const;
// Open
bool OpenFromFile(const NzString& filePath, const NzFontParams& params = NzFontParams());
bool OpenFromMemory(const void* data, std::size_t size, const NzFontParams& params = NzFontParams());
bool OpenFromStream(NzInputStream& stream, const NzFontParams& params = NzFontParams());
void SetAtlas(std::shared_ptr<NzAbstractAtlas> atlas);
void SetGlyphBorder(unsigned int borderSize);
void SetMinimumStepSize(unsigned int minimumSizeStep);
NzFont& operator=(NzFont&& font) = default;
enum ModicationCode
{
ModificationCode_AtlasChanged,
ModificationCode_AtlasLayerChanged,
ModificationCode_GlyphCacheCleared,
ModificationCode_KerningCacheCleared,
ModificationCode_SizeInfoCacheCleared
};
struct Glyph
{
NzRecti aabb;
NzRectui atlasRect;
bool requireFauxBold;
bool requireFauxItalic;
bool flipped;
bool valid;
int advance;
unsigned int layerIndex;
};
struct SizeInfo
{
int spaceAdvance;
unsigned int lineHeight;
float underlinePosition;
float underlineThickness;
};
private:
using GlyphMap = std::unordered_map<char32_t, Glyph>;
nzUInt64 ComputeKey(unsigned int characterSize, nzUInt32 style) const;
bool OnAtlasCleared(const NzAbstractAtlas* atlas, void* userdata) override;
bool OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer, void* userdata) override;
void OnAtlasReleased(const NzAbstractAtlas* atlas, void* userdata) override;
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, nzUInt32 style, char32_t character) const;
std::shared_ptr<NzAbstractAtlas> m_atlas;
std::unique_ptr<NzFontData> m_data;
mutable std::unordered_map<nzUInt64, std::unordered_map<nzUInt64, int>> m_kerningCache;
mutable std::unordered_map<nzUInt64, GlyphMap> m_glyphes;
mutable std::unordered_map<nzUInt64, SizeInfo> m_sizeInfoCache;
unsigned int m_glyphBorder;
unsigned int m_minimumSizeStep;
static NzFontLoader::LoaderList s_loaders;
};
#endif // NAZARA_FONT_HPP

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FONTDATA_HPP
#define NAZARA_FONTDATA_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
struct NzFontGlyph;
class NAZARA_API NzFontData
{
public:
NzFontData() = default;
virtual ~NzFontData();
virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, nzUInt32 style, NzFontGlyph* dst) = 0;
virtual NzString GetFamilyName() const = 0;
virtual NzString GetStyleName() const = 0;
virtual bool HasKerning() const = 0;
virtual bool IsScalable() const = 0;
virtual int QueryKerning(unsigned int characterSize, char32_t first, char32_t second) const = 0;
virtual unsigned int QueryLineHeight(unsigned int characterSize) const = 0;
virtual float QueryUnderlinePosition(unsigned int characterSize) const = 0;
virtual float QueryUnderlineThickness(unsigned int characterSize) const = 0;
virtual bool SupportsStyle(nzUInt32 style) const = 0;
};
#endif // NAZARA_FONTDATA_HPP

View File

@@ -0,0 +1,19 @@
// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FONTGLYPH_HPP
#define NAZARA_FONTGLYPH_HPP
#include <Nazara/Utility/Image.hpp>
struct NzFontGlyph
{
NzImage image;
NzRecti aabb;
int advance;
};
#endif // NAZARA_FONTGLYPH_HPP

View File

@@ -0,0 +1,66 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_GUILLOTINEIMAGEATLAS_HPP
#define NAZARA_GUILLOTINEIMAGEATLAS_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/GuillotineBinPack.hpp>
#include <Nazara/Utility/AbstractAtlas.hpp>
#include <Nazara/Utility/AbstractImage.hpp>
#include <Nazara/Utility/Image.hpp>
#include <memory>
#include <vector>
class NAZARA_API NzGuillotineImageAtlas : public NzAbstractAtlas
{
public:
NzGuillotineImageAtlas();
virtual ~NzGuillotineImageAtlas();
void Clear();
void Free(NzSparsePtr<const NzRectui> rects, NzSparsePtr<unsigned int> layers, unsigned int count);
NzGuillotineBinPack::FreeRectChoiceHeuristic GetRectChoiceHeuristic() const;
NzGuillotineBinPack::GuillotineSplitHeuristic GetRectSplitHeuristic() const;
NzAbstractImage* GetLayer(unsigned int layerIndex) const;
unsigned int GetLayerCount() const;
bool Insert(const NzImage& image, NzRectui* rect, bool* flipped, unsigned int* layerIndex);
void SetRectChoiceHeuristic(NzGuillotineBinPack::FreeRectChoiceHeuristic heuristic);
void SetRectSplitHeuristic(NzGuillotineBinPack::GuillotineSplitHeuristic heuristic);
protected:
struct Layer;
virtual NzAbstractImage* ResizeImage(NzAbstractImage* oldImage, const NzVector2ui& size) const;
bool ResizeLayer(Layer& layer, const NzVector2ui& size);
struct QueuedGlyph
{
NzImage image;
NzRectui rect;
bool flipped;
};
struct Layer
{
std::vector<QueuedGlyph> queuedGlyphs;
std::unique_ptr<NzAbstractImage> image;
NzGuillotineBinPack binPack;
unsigned int freedRectangles = 0;
};
private:
void ProcessGlyphQueue(Layer& layer) const;
mutable std::vector<Layer> m_layers;
NzGuillotineBinPack::FreeRectChoiceHeuristic m_rectChoiceHeuristic;
NzGuillotineBinPack::GuillotineSplitHeuristic m_rectSplitHeuristic;
};
#endif // NAZARA_GUILLOTINEIMAGEATLAS_HPP

View File

@@ -13,12 +13,8 @@
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/AbstractImage.hpp>
#include <Nazara/Utility/CubemapParams.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <atomic>
///TODO: Filtres
@@ -40,7 +36,7 @@ using NzImageConstRef = NzResourceRef<const NzImage>;
using NzImageLoader = NzResourceLoader<NzImage, NzImageParams>;
using NzImageRef = NzResourceRef<NzImage>;
class NAZARA_API NzImage : public NzResource
class NAZARA_API NzImage : public NzAbstractImage, public NzResource
{
friend NzImageLoader;
@@ -50,7 +46,6 @@ class NAZARA_API NzImage : public NzResource
NzImage();
NzImage(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1);
NzImage(const NzImage& image);
NzImage(NzImage&& image) noexcept;
NzImage(SharedImage* sharedImage);
~NzImage();
@@ -68,22 +63,20 @@ class NAZARA_API NzImage : public NzResource
bool FlipHorizontally();
bool FlipVertically();
nzUInt8 GetBytesPerPixel() 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;
unsigned int GetMemoryUsage() const;
unsigned int GetMemoryUsage(nzUInt8 level) const;
NzColor GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
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;
NzVector3ui GetSize(nzUInt8 level = 0) const;
nzImageType GetType() const;
unsigned int GetWidth(nzUInt8 level = 0) const;
bool IsCompressed() const;
bool IsCubemap() const;
bool IsValid() const;
// Load
@@ -106,12 +99,11 @@ class NAZARA_API NzImage : public NzResource
void SetLevelCount(nzUInt8 levelCount);
bool SetPixelColor(const NzColor& color, unsigned int x, unsigned int y = 0, unsigned int z = 0);
void Update(const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
void Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
void Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, const NzBoxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
NzImage& operator=(const NzImage& image);
NzImage& operator=(NzImage&& image) noexcept;
static void Copy(nzUInt8* destination, const nzUInt8* source, nzUInt8 bpp, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0);
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);

View File

@@ -23,7 +23,7 @@ class NAZARA_API NzIndexBuffer : public NzResource
NzIndexBuffer() = default;
NzIndexBuffer(bool largeIndices, NzBuffer* buffer);
NzIndexBuffer(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
NzIndexBuffer(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzIndexBuffer(bool largeIndices, unsigned int length, nzUInt32 storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzIndexBuffer(const NzIndexBuffer& indexBuffer);
NzIndexBuffer(NzIndexBuffer&& indexBuffer) noexcept;
~NzIndexBuffer();
@@ -54,11 +54,11 @@ class NAZARA_API NzIndexBuffer : public NzResource
void Reset();
void Reset(bool largeIndices, NzBuffer* buffer);
void Reset(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
void Reset(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Reset(bool largeIndices, unsigned int length, nzUInt32 storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Reset(const NzIndexBuffer& indexBuffer);
void Reset(NzIndexBuffer&& indexBuffer) noexcept;
bool SetStorage(nzBufferStorage storage);
bool SetStorage(nzUInt32 storage);
void Unmap() const;

View File

@@ -24,12 +24,12 @@ struct NAZARA_API NzMeshParams
{
NzMeshParams(); // Vérifie que le storage par défaut est supporté (software autrement)
// Si ceci sera le stockage utilisé par les buffers
nzBufferStorage storage = nzBufferStorage_Hardware;
// La mise à l'échelle éventuelle que subira le mesh
NzVector3f scale = NzVector3f::Unit();
// Si ceci sera le stockage utilisé par les buffers
nzUInt32 storage = nzDataStorage_Hardware;
// Charger une version animée du mesh si possible ?
bool animated = true;

View File

@@ -24,26 +24,26 @@ class NAZARA_API NzNode
void EnsureDerivedUpdate() const;
void EnsureTransformMatrixUpdate() const;
NzVector3f GetBackward() const;
virtual NzVector3f GetBackward() const;
const std::vector<NzNode*>& GetChilds() const;
NzVector3f GetDown() const;
NzVector3f GetForward() const;
virtual NzVector3f GetDown() const;
virtual NzVector3f GetForward() const;
bool GetInheritPosition() const;
bool GetInheritRotation() const;
bool GetInheritScale() const;
NzVector3f GetInitialPosition() const;
NzQuaternionf GetInitialRotation() const;
NzVector3f GetInitialScale() const;
NzVector3f GetLeft() const;
virtual NzVector3f GetLeft() const;
const NzString& GetName() const;
virtual nzNodeType GetNodeType() const;
const NzNode* GetParent() const;
NzVector3f GetPosition(nzCoordSys coordSys = nzCoordSys_Global) const;
NzVector3f GetRight() const;
virtual NzVector3f GetRight() const;
NzQuaternionf GetRotation(nzCoordSys coordSys = nzCoordSys_Global) const;
NzVector3f GetScale(nzCoordSys coordSys = nzCoordSys_Global) const;
const NzMatrix4f& GetTransformMatrix() const;
NzVector3f GetUp() const;
virtual NzVector3f GetUp() const;
bool HasChilds() const;
@@ -95,7 +95,7 @@ class NAZARA_API NzNode
virtual void InvalidateNode();
virtual void OnParenting(const NzNode* parent);
void RemoveChild(NzNode* node) const;
void UpdateDerived() const;
virtual void UpdateDerived() const;
virtual void UpdateTransformMatrix() const;
mutable std::vector<NzNode*> m_childs;

View File

@@ -13,6 +13,10 @@
#include <functional>
#include <map>
///TODO: Permettre la conversion automatique entre les formats via des renseignements de bits et de type pour chaque format.
/// Ce serait plus lent que la conversion spécialisée (qui ne disparaît donc pas) mais ça permettrait au moteur de faire la conversion
/// entre n'importe quel formats non-compressés.
class NzPixelFormat
{
friend class NzUtility;

View File

@@ -168,6 +168,9 @@ inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
return 8;
case nzPixelFormat_BGR8:
return 24;
@@ -287,20 +290,14 @@ inline nzUInt8 NzPixelFormat::GetBitsPerPixel(nzPixelFormat format)
inline nzUInt8 NzPixelFormat::GetBytesPerPixel(nzPixelFormat format)
{
nzUInt8 bytesPerPixel = GetBitsPerPixel(format)/8;
#if NAZARA_UTILITY_SAFE
if (bytesPerPixel == 0)
NazaraWarning("This format is either invalid or using less than one byte per pixel");
#endif
return bytesPerPixel;
return GetBitsPerPixel(format)/8;
}
inline nzPixelFormatType NzPixelFormat::GetType(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
case nzPixelFormat_BGR8:
case nzPixelFormat_BGRA8:
case nzPixelFormat_DXT1:
@@ -372,6 +369,7 @@ inline bool NzPixelFormat::HasAlpha(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
case nzPixelFormat_BGRA8:
case nzPixelFormat_DXT3:
case nzPixelFormat_DXT5:
@@ -444,6 +442,7 @@ inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
case nzPixelFormat_DXT5:
return true;
case nzPixelFormat_A8:
case nzPixelFormat_BGR8:
case nzPixelFormat_BGRA8:
case nzPixelFormat_L8:
@@ -529,6 +528,9 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format)
{
switch (format)
{
case nzPixelFormat_A8:
return "A8";
case nzPixelFormat_BGR8:
return "BGR8";

View File

@@ -0,0 +1,59 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SIMPLETEXTDRAWER_HPP
#define NAZARA_SIMPLETEXTDRAWER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ResourceListener.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/AbstractTextDrawer.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Font.hpp>
#include <vector>
class NAZARA_API NzSimpleTextDrawer : public NzAbstractTextDrawer, NzResourceListener
{
public:
NzSimpleTextDrawer();
virtual ~NzSimpleTextDrawer();
const NzRectui& GetBounds() const;
unsigned int GetCharacterSize() const;
const NzColor& GetColor() const;
NzFont* GetFont() const;
nzUInt32 GetStyle() const;
void SetCharacterSize(unsigned int characterSize);
void SetColor(const NzColor& color);
void SetFont(NzFont* font);
void SetStyle(nzUInt32 style);
void SetText(const NzString& str);
static NzSimpleTextDrawer Draw(unsigned int characterSize, const NzString& str, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
static NzSimpleTextDrawer Draw(NzFont* font, unsigned int characterSize, const NzString& str, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
private:
NzFont* GetFont(unsigned int index) const override;
unsigned int GetFontCount() const override;
const Glyph& GetGlyph(unsigned int index) const override;
unsigned int GetGlyphCount() const override;
bool OnResourceModified(const NzResource* resource, int index, unsigned int code) override;
void OnResourceReleased(const NzResource* resource, int index) override;
void UpdateGlyphs() const;
mutable std::vector<Glyph> m_glyphs;
NzColor m_color;
NzFontRef m_font;
mutable NzRectui m_bounds;
NzString m_text;
nzUInt32 m_style;
mutable bool m_glyphUpdated;
unsigned int m_characterSize;
};
#endif // NAZARA_SIMPLETEXTDRAWER_HPP

View File

@@ -24,7 +24,7 @@ class NAZARA_API NzVertexBuffer : public NzResource
NzVertexBuffer() = default;
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer);
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzUInt32 storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzVertexBuffer(const NzVertexBuffer& vertexBuffer);
NzVertexBuffer(NzVertexBuffer&& vertexBuffer) noexcept;
~NzVertexBuffer();
@@ -50,11 +50,11 @@ class NAZARA_API NzVertexBuffer : public NzResource
void Reset();
void Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer);
void Reset(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
void Reset(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Reset(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzUInt32 storage = nzDataStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Reset(const NzVertexBuffer& vertexBuffer);
void Reset(NzVertexBuffer&& vertexBuffer) noexcept;
bool SetStorage(nzBufferStorage storage);
bool SetStorage(nzUInt32 storage);
void SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
void Unmap() const;

View File

@@ -7,6 +7,7 @@
#ifndef NAZARA_VERTEXSTRUCT_HPP
#define NAZARA_VERTEXSTRUCT_HPP
#include <Nazara/Core/Color.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
@@ -17,7 +18,12 @@ struct NzVertexStruct_XY
NzVector2f position;
};
struct NzVertexStruct_XY_UV : public NzVertexStruct_XY
struct NzVertexStruct_XY_Color : NzVertexStruct_XY
{
NzColor color;
};
struct NzVertexStruct_XY_UV : NzVertexStruct_XY
{
NzVector2f uv;
};
@@ -29,29 +35,39 @@ struct NzVertexStruct_XYZ
NzVector3f position;
};
struct NzVertexStruct_XYZ_Normal : public NzVertexStruct_XYZ
struct NzVertexStruct_XYZ_Color : NzVertexStruct_XYZ
{
NzVector3f normal;
NzColor color;
};
struct NzVertexStruct_XYZ_Normal_UV : public NzVertexStruct_XYZ_Normal
struct NzVertexStruct_XYZ_Color_UV : NzVertexStruct_XYZ_Color
{
NzVector2f uv;
};
struct NzVertexStruct_XYZ_Normal_UV_Tangent : public NzVertexStruct_XYZ_Normal_UV
struct NzVertexStruct_XYZ_Normal : NzVertexStruct_XYZ
{
NzVector3f normal;
};
struct NzVertexStruct_XYZ_Normal_UV : NzVertexStruct_XYZ_Normal
{
NzVector2f uv;
};
struct NzVertexStruct_XYZ_Normal_UV_Tangent : NzVertexStruct_XYZ_Normal_UV
{
NzVector3f tangent;
};
struct NzVertexStruct_XYZ_UV : public NzVertexStruct_XYZ
struct NzVertexStruct_XYZ_UV : NzVertexStruct_XYZ
{
NzVector2f uv;
};
/************************* Structures 3D (+ Skinning) ************************/
struct NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning : public NzVertexStruct_XYZ_Normal_UV_Tangent
struct NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning : NzVertexStruct_XYZ_Normal_UV_Tangent
{
nzInt32 weightCount;