Remove Utility module and move its content to Core and TextRenderer modules
This commit is contained in:
committed by
Jérôme Leclercq
parent
965a00182c
commit
e64c2b036e
47
include/Nazara/Core/AbstractAtlas.hpp
Normal file
47
include/Nazara/Core/AbstractAtlas.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_ABSTRACTATLAS_HPP
|
||||
#define NAZARA_CORE_ABSTRACTATLAS_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractImage;
|
||||
class Image;
|
||||
|
||||
class NAZARA_CORE_API AbstractAtlas
|
||||
{
|
||||
public:
|
||||
AbstractAtlas() = default;
|
||||
AbstractAtlas(const AbstractAtlas&) = delete;
|
||||
AbstractAtlas(AbstractAtlas&&) noexcept = default;
|
||||
virtual ~AbstractAtlas();
|
||||
|
||||
virtual void Clear() = 0;
|
||||
virtual void Free(SparsePtr<const Rectui> rects, SparsePtr<std::size_t> layers, std::size_t count) = 0;
|
||||
virtual AbstractImage* GetLayer(std::size_t layerIndex) const = 0;
|
||||
virtual std::size_t GetLayerCount() const = 0;
|
||||
virtual DataStoreFlags GetStorage() const = 0;
|
||||
virtual bool Insert(const Image& image, Rectui* rect, bool* flipped, std::size_t* layerIndex) = 0;
|
||||
|
||||
AbstractAtlas& operator=(const AbstractAtlas&) = delete;
|
||||
AbstractAtlas& operator=(AbstractAtlas&&) noexcept = default;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnAtlasCleared, const AbstractAtlas* /*atlas*/);
|
||||
NazaraSignal(OnAtlasLayerChange, const AbstractAtlas* /*atlas*/, AbstractImage* /*oldLayer*/, AbstractImage* /*newLayer*/);
|
||||
NazaraSignal(OnAtlasRelease, const AbstractAtlas* /*atlas*/);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_ABSTRACTATLAS_HPP
|
||||
49
include/Nazara/Core/AbstractImage.hpp
Normal file
49
include/Nazara/Core/AbstractImage.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_ABSTRACTIMAGE_HPP
|
||||
#define NAZARA_CORE_ABSTRACTIMAGE_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractImage;
|
||||
|
||||
class NAZARA_CORE_API AbstractImage
|
||||
{
|
||||
public:
|
||||
AbstractImage() = default;
|
||||
AbstractImage(const AbstractImage&) = default;
|
||||
AbstractImage(AbstractImage&&) noexcept = default;
|
||||
virtual ~AbstractImage();
|
||||
|
||||
UInt8 GetBytesPerPixel() const;
|
||||
virtual PixelFormat GetFormat() const = 0;
|
||||
virtual UInt8 GetLevelCount() const = 0;
|
||||
virtual Vector3ui GetSize(UInt8 level = 0) const = 0;
|
||||
virtual ImageType GetType() const = 0;
|
||||
|
||||
bool IsCompressed() const;
|
||||
bool IsCubemap() const;
|
||||
|
||||
inline bool Update(const void* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
virtual bool Update(const void* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
|
||||
inline bool Update(const void* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
||||
|
||||
AbstractImage& operator=(const AbstractImage&) = default;
|
||||
AbstractImage& operator=(AbstractImage&&) noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/AbstractImage.inl>
|
||||
|
||||
#endif // NAZARA_CORE_ABSTRACTIMAGE_HPP
|
||||
20
include/Nazara/Core/AbstractImage.inl
Normal file
20
include/Nazara/Core/AbstractImage.inl
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool AbstractImage::Update(const void* pixels, unsigned int srcWidth, unsigned int srcHeight, UInt8 level)
|
||||
{
|
||||
return Update(pixels, Boxui(Vector3ui::Zero(), GetSize(level)), srcWidth, srcHeight, level);
|
||||
}
|
||||
|
||||
inline bool AbstractImage::Update(const void* pixels, const Rectui& rect, unsigned int z, unsigned int srcWidth, unsigned int srcHeight, UInt8 level)
|
||||
{
|
||||
return Update(pixels, Boxui(rect.x, rect.y, z, rect.width, rect.height, 1), srcWidth, srcHeight, level);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -9,9 +9,18 @@
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/SerializationContext.hpp>
|
||||
#include <Nazara/Core/IndexIterator.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <NazaraUtils/Algorithm.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
#include <NazaraUtils/TypeTag.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
@@ -23,28 +32,75 @@ namespace Nz
|
||||
{
|
||||
class ByteArray;
|
||||
|
||||
// Hash
|
||||
template<typename T> ByteArray ComputeHash(HashType hash, T&& v);
|
||||
template<typename T> ByteArray ComputeHash(AbstractHash& hash, T&& v);
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, std::string_view v);
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, T&& value);
|
||||
|
||||
inline bool Serialize(SerializationContext& context, bool value, TypeTag<bool>);
|
||||
inline bool Serialize(SerializationContext& context, const std::string& value, TypeTag<std::string>);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value, TypeTag<T>);
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, T* value);
|
||||
|
||||
inline bool Unserialize(SerializationContext& context, bool* value, TypeTag<bool>);
|
||||
inline bool Unserialize(SerializationContext& context, std::string* value, TypeTag<std::string>);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag<T>);
|
||||
|
||||
// Vertex processing
|
||||
class Joint;
|
||||
struct VertexStruct_XYZ_Normal_UV_Tangent;
|
||||
struct VertexStruct_XYZ_Normal_UV_Tangent_Skinning;
|
||||
|
||||
using MeshVertex = VertexStruct_XYZ_Normal_UV_Tangent;
|
||||
using SkeletalMeshVertex = VertexStruct_XYZ_Normal_UV_Tangent_Skinning;
|
||||
|
||||
struct SkinningData
|
||||
{
|
||||
const Joint* joints;
|
||||
SparsePtr<const Vector3f> inputPositions;
|
||||
SparsePtr<const Vector3f> inputNormals;
|
||||
SparsePtr<const Vector3f> inputTangents;
|
||||
SparsePtr<const Vector4i32> inputJointIndices;
|
||||
SparsePtr<const Vector4f> inputJointWeights;
|
||||
SparsePtr<const Vector2f> inputUv;
|
||||
SparsePtr<Vector3f> outputNormals;
|
||||
SparsePtr<Vector3f> outputPositions;
|
||||
SparsePtr<Vector3f> outputTangents;
|
||||
SparsePtr<Vector2f> outputUv;
|
||||
};
|
||||
|
||||
struct VertexPointers
|
||||
{
|
||||
SparsePtr<Vector3f> normalPtr;
|
||||
SparsePtr<Vector3f> positionPtr;
|
||||
SparsePtr<Vector3f> tangentPtr;
|
||||
SparsePtr<Vector2f> uvPtr;
|
||||
};
|
||||
|
||||
NAZARA_CORE_API Boxf ComputeAABB(SparsePtr<const Vector3f> positionPtr, UInt32 vertexCount);
|
||||
NAZARA_CORE_API void ComputeBoxIndexVertexCount(const Vector3ui& subdivision, UInt32* indexCount, UInt32* vertexCount);
|
||||
NAZARA_CORE_API UInt32 ComputeCacheMissCount(IndexIterator indices, UInt32 indexCount);
|
||||
NAZARA_CORE_API void ComputeConeIndexVertexCount(unsigned int subdivision, UInt32* indexCount, UInt32* vertexCount);
|
||||
NAZARA_CORE_API void ComputeCubicSphereIndexVertexCount(unsigned int subdivision, UInt32* indexCount, UInt32* vertexCount);
|
||||
NAZARA_CORE_API void ComputeIcoSphereIndexVertexCount(unsigned int recursionLevel, UInt32* indexCount, UInt32* vertexCount);
|
||||
NAZARA_CORE_API void ComputePlaneIndexVertexCount(const Vector2ui& subdivision, UInt32* indexCount, UInt32* vertexCount);
|
||||
NAZARA_CORE_API void ComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, UInt32* indexCount, UInt32* vertexCount);
|
||||
|
||||
NAZARA_CORE_API void GenerateBox(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb = nullptr, UInt32 indexOffset = 0);
|
||||
NAZARA_CORE_API void GenerateCone(float length, float radius, unsigned int subdivision, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb = nullptr, UInt32 indexOffset = 0);
|
||||
NAZARA_CORE_API void GenerateCubicSphere(float size, unsigned int subdivision, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb = nullptr, UInt32 indexOffset = 0);
|
||||
NAZARA_CORE_API void GenerateIcoSphere(float size, unsigned int recursionLevel, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb = nullptr, UInt32 indexOffset = 0);
|
||||
NAZARA_CORE_API void GeneratePlane(const Vector2ui& subdivision, const Vector2f& size, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb = nullptr, UInt32 indexOffset = 0);
|
||||
NAZARA_CORE_API void GenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb = nullptr, UInt32 indexOffset = 0);
|
||||
|
||||
NAZARA_CORE_API void OptimizeIndices(IndexIterator indices, UInt32 indexCount);
|
||||
|
||||
NAZARA_CORE_API void SkinLinearBlend(const SkinningData& data, UInt32 startVertex, UInt32 vertexCount);
|
||||
|
||||
inline Vector3f TransformPositionTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& position);
|
||||
inline Vector3f TransformNormalTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& normal);
|
||||
inline Quaternionf TransformRotationTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Quaternionf& rotation);
|
||||
inline Vector3f TransformScaleTRS(const Vector3f& transformScale, const Vector3f& scale);
|
||||
inline void TransformTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, Vector3f& position, Quaternionf& rotation, Vector3f& scale);
|
||||
inline void TransformVertices(VertexPointers vertexPointers, UInt32 vertexCount, const Matrix4f& matrix);
|
||||
|
||||
template<typename T> constexpr ComponentType ComponentTypeId();
|
||||
template<typename T> constexpr ComponentType GetComponentTypeOf();
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Algorithm.inl>
|
||||
|
||||
@@ -63,157 +63,83 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, T&& value)
|
||||
inline Vector3f TransformPositionTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& position)
|
||||
{
|
||||
return Serialize(context, std::forward<T>(value), TypeTag<std::decay_t<T>>());
|
||||
return transformRotation * (transformScale * position) + transformTranslation;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes a boolean
|
||||
* \return true if serialization succeeded
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Boolean to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Serialize(SerializationContext& context, bool value, TypeTag<bool>)
|
||||
Vector3f TransformNormalTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Vector3f& normal)
|
||||
{
|
||||
if (context.writeBitPos == 8)
|
||||
return Quaternionf::Mirror(transformRotation, transformScale) * normal;
|
||||
}
|
||||
|
||||
inline Quaternionf TransformRotationTRS(const Quaternionf& transformRotation, const Vector3f& transformScale, const Quaternionf& rotation)
|
||||
{
|
||||
return Quaternionf::Mirror(transformRotation, transformScale) * rotation;
|
||||
}
|
||||
|
||||
inline Vector3f TransformScaleTRS(const Vector3f& transformScale, const Vector3f& scale)
|
||||
{
|
||||
return transformScale * scale;
|
||||
}
|
||||
|
||||
inline void TransformTRS(const Vector3f& transformTranslation, const Quaternionf& transformRotation, const Vector3f& transformScale, Vector3f& position, Quaternionf& rotation, Vector3f& scale)
|
||||
{
|
||||
position = TransformPositionTRS(transformTranslation, transformRotation, transformScale, position);
|
||||
rotation = TransformRotationTRS(transformRotation, transformScale, rotation);
|
||||
scale = TransformScaleTRS(transformScale, scale);
|
||||
}
|
||||
|
||||
inline void TransformVertices(VertexPointers vertexPointers, UInt32 vertexCount, const Matrix4f& matrix)
|
||||
{
|
||||
if (vertexPointers.positionPtr)
|
||||
{
|
||||
context.writeBitPos = 0;
|
||||
context.writeByte = 0;
|
||||
for (UInt32 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.positionPtr++ = matrix.Transform(*vertexPointers.positionPtr);
|
||||
}
|
||||
|
||||
if (value)
|
||||
context.writeByte |= 1 << context.writeBitPos;
|
||||
|
||||
if (++context.writeBitPos >= 8)
|
||||
return Serialize(context, context.writeByte, TypeTag<UInt8>());
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes a std::string
|
||||
* \return true if successful
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value String to serialize
|
||||
*/
|
||||
bool Serialize(SerializationContext& context, const std::string& value, TypeTag<std::string>)
|
||||
{
|
||||
if (!Serialize(context, SafeCast<UInt32>(value.size()), TypeTag<UInt32>()))
|
||||
return false;
|
||||
|
||||
return context.stream->Write(value.data(), value.size()) == value.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes an arithmetic type
|
||||
* \return true if serialization succeeded
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Arithmetic type to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value, TypeTag<T>)
|
||||
{
|
||||
// Flush bits in case a writing is in progress
|
||||
context.FlushBits();
|
||||
|
||||
if (context.endianness != Endianness::Unknown && context.endianness != PlatformEndianness)
|
||||
value = ByteSwap(value);
|
||||
|
||||
return context.stream->Write(&value, sizeof(T)) == sizeof(T);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, T* value)
|
||||
{
|
||||
return Unserialize(context, value, TypeTag<T>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Unserializes a boolean
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to boolean to unserialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Unserialize(SerializationContext& context, bool* value, TypeTag<bool>)
|
||||
{
|
||||
if (context.readBitPos == 8)
|
||||
if (vertexPointers.normalPtr || vertexPointers.tangentPtr)
|
||||
{
|
||||
if (!Unserialize(context, &context.readByte, TypeTag<UInt8>()))
|
||||
return false;
|
||||
Vector3f scale = matrix.GetScale();
|
||||
|
||||
context.readBitPos = 0;
|
||||
if (vertexPointers.normalPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.normalPtr++ = matrix.Transform(*vertexPointers.normalPtr, 0.f) / scale;
|
||||
}
|
||||
|
||||
if (vertexPointers.tangentPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.tangentPtr++ = matrix.Transform(*vertexPointers.tangentPtr, 0.f) / scale;
|
||||
}
|
||||
}
|
||||
|
||||
if (value)
|
||||
*value = (context.readByte & (1 << context.readBitPos)) != 0;
|
||||
|
||||
context.readBitPos++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unserializes a string
|
||||
* \return true if successful
|
||||
*
|
||||
* \param context Context of unserialization
|
||||
* \param string std::string to unserialize
|
||||
*/
|
||||
bool Unserialize(SerializationContext& context, std::string* string, TypeTag<std::string>)
|
||||
template<typename T> constexpr ComponentType ComponentTypeId()
|
||||
{
|
||||
UInt32 size;
|
||||
if (!Unserialize(context, &size, TypeTag<UInt32>()))
|
||||
return false;
|
||||
|
||||
string->resize(size);
|
||||
return context.stream->Read(&(*string)[0], size) == size;
|
||||
static_assert(AlwaysFalse<T>::value, "This type cannot be used as a component.");
|
||||
return ComponentType{};
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Unserializes an arithmetic type
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to arithmetic type to serialize
|
||||
*
|
||||
* \remark Produce a NazaraAssert if pointer to value is invalid
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<> constexpr ComponentType ComponentTypeId<Color>() { return ComponentType::Color; }
|
||||
template<> constexpr ComponentType ComponentTypeId<double>() { return ComponentType::Double1; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector2d>() { return ComponentType::Double2; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector3d>() { return ComponentType::Double3; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector4d>() { return ComponentType::Double4; }
|
||||
template<> constexpr ComponentType ComponentTypeId<float>() { return ComponentType::Float1; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector2f>() { return ComponentType::Float2; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector3f>() { return ComponentType::Float3; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector4f>() { return ComponentType::Float4; }
|
||||
template<> constexpr ComponentType ComponentTypeId<int>() { return ComponentType::Int1; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector2i>() { return ComponentType::Int2; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector3i>() { return ComponentType::Int3; }
|
||||
template<> constexpr ComponentType ComponentTypeId<Vector4i>() { return ComponentType::Int4; }
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag<T>)
|
||||
constexpr ComponentType GetComponentTypeOf()
|
||||
{
|
||||
NazaraAssert(value, "Invalid data pointer");
|
||||
|
||||
context.ResetReadBitPosition();
|
||||
|
||||
if (context.stream->Read(value, sizeof(T)) == sizeof(T))
|
||||
{
|
||||
if (context.endianness != Endianness::Unknown && context.endianness != PlatformEndianness)
|
||||
*value = ByteSwap(*value);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return ComponentTypeId<std::decay_t<T>>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
110
include/Nazara/Core/Animation.hpp
Normal file
110
include/Nazara/Core/Animation.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_ANIMATION_HPP
|
||||
#define NAZARA_CORE_ANIMATION_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Skeleton;
|
||||
|
||||
struct NAZARA_CORE_API AnimationParams : ResourceParameters
|
||||
{
|
||||
// La frame de fin à charger
|
||||
std::size_t endFrame = 0xFFFFFFFF;
|
||||
// La frame de début à charger
|
||||
std::size_t startFrame = 0;
|
||||
// Reference skeleton
|
||||
const Skeleton* skeleton = nullptr;
|
||||
|
||||
// Transform joints by these transformations
|
||||
Vector3f jointOffset = Vector3f::Zero();
|
||||
|
||||
Quaternionf jointRotation = Quaternionf::Identity();
|
||||
|
||||
Vector3f jointScale = Vector3f::Unit();
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class Animation;
|
||||
struct Sequence;
|
||||
struct SequenceJoint;
|
||||
|
||||
using AnimationLibrary = ObjectLibrary<Animation>;
|
||||
using AnimationLoader = ResourceLoader<Animation, AnimationParams>;
|
||||
using AnimationManager = ResourceManager<Animation, AnimationParams>;
|
||||
|
||||
struct AnimationImpl;
|
||||
|
||||
class NAZARA_CORE_API Animation : public Resource
|
||||
{
|
||||
public:
|
||||
using Params = AnimationParams;
|
||||
|
||||
Animation();
|
||||
Animation(const Animation&) = delete;
|
||||
Animation(Animation&&) noexcept;
|
||||
~Animation();
|
||||
|
||||
bool AddSequence(Sequence sequence);
|
||||
void AnimateSkeleton(Skeleton* targetSkeleton, std::size_t frameA, std::size_t frameB, float interpolation) const;
|
||||
|
||||
bool CreateSkeletal(std::size_t frameCount, std::size_t jointCount);
|
||||
void Destroy();
|
||||
|
||||
void EnableLoopPointInterpolation(bool loopPointInterpolation);
|
||||
|
||||
std::size_t GetFrameCount() const;
|
||||
std::size_t GetJointCount() const;
|
||||
Sequence* GetSequence(std::string_view sequenceName);
|
||||
Sequence* GetSequence(std::size_t index);
|
||||
const Sequence* GetSequence(std::string_view sequenceName) const;
|
||||
const Sequence* GetSequence(std::size_t index) const;
|
||||
std::size_t GetSequenceCount() const;
|
||||
std::size_t GetSequenceIndex(std::string_view sequenceName) const;
|
||||
SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0);
|
||||
const SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0) const;
|
||||
AnimationType GetType() const;
|
||||
|
||||
bool HasSequence(std::string_view sequenceName) const;
|
||||
bool HasSequence(std::size_t index = 0) const;
|
||||
|
||||
bool IsLoopPointInterpolationEnabled() const;
|
||||
bool IsValid() const;
|
||||
|
||||
void RemoveSequence(std::string_view sequenceName);
|
||||
void RemoveSequence(std::size_t index);
|
||||
|
||||
Animation& operator=(const Animation&) = delete;
|
||||
Animation& operator=(Animation&&) noexcept;
|
||||
|
||||
static std::shared_ptr<Animation> LoadFromFile(const std::filesystem::path& filePath, const AnimationParams& params = AnimationParams());
|
||||
static std::shared_ptr<Animation> LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params = AnimationParams());
|
||||
static std::shared_ptr<Animation> LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams());
|
||||
|
||||
private:
|
||||
std::unique_ptr<AnimationImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Animation.inl>
|
||||
|
||||
#endif // NAZARA_CORE_ANIMATION_HPP
|
||||
11
include/Nazara/Core/Animation.inl
Normal file
11
include/Nazara/Core/Animation.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
55
include/Nazara/Core/Buffer.hpp
Normal file
55
include/Nazara/Core/Buffer.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_BUFFER_HPP
|
||||
#define NAZARA_CORE_BUFFER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Buffer;
|
||||
|
||||
using BufferFactory = std::function<std::shared_ptr<Buffer>(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData)>;
|
||||
|
||||
class NAZARA_CORE_API Buffer
|
||||
{
|
||||
public:
|
||||
inline Buffer(DataStorage storage, BufferType type, UInt64 size, BufferUsageFlags usage);
|
||||
Buffer(const Buffer&) = delete;
|
||||
Buffer(Buffer&&) = delete;
|
||||
virtual ~Buffer();
|
||||
|
||||
std::shared_ptr<Buffer> CopyContent(const BufferFactory& bufferFactory);
|
||||
|
||||
virtual bool Fill(const void* data, UInt64 offset, UInt64 size) = 0;
|
||||
|
||||
inline UInt64 GetSize() const;
|
||||
inline DataStorage GetStorage() const;
|
||||
inline BufferType GetType() const;
|
||||
inline BufferUsageFlags GetUsageFlags() const;
|
||||
|
||||
virtual void* Map(UInt64 offset, UInt64 size) = 0;
|
||||
virtual bool Unmap() = 0;
|
||||
|
||||
Buffer& operator=(const Buffer&) = delete;
|
||||
Buffer& operator=(Buffer&&) = delete;
|
||||
|
||||
private:
|
||||
BufferType m_type;
|
||||
BufferUsageFlags m_usage;
|
||||
DataStorage m_storage;
|
||||
UInt64 m_size;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Buffer.inl>
|
||||
|
||||
#endif // NAZARA_CORE_BUFFER_HPP
|
||||
39
include/Nazara/Core/Buffer.inl
Normal file
39
include/Nazara/Core/Buffer.inl
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Buffer::Buffer(DataStorage storage, BufferType type, UInt64 size, BufferUsageFlags usage) :
|
||||
m_type(type),
|
||||
m_usage(usage),
|
||||
m_storage(storage),
|
||||
m_size(size)
|
||||
{
|
||||
}
|
||||
|
||||
inline UInt64 Nz::Buffer::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
inline DataStorage Buffer::GetStorage() const
|
||||
{
|
||||
return m_storage;
|
||||
}
|
||||
|
||||
inline BufferType Buffer::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
inline BufferUsageFlags Buffer::GetUsageFlags() const
|
||||
{
|
||||
return m_usage;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
37
include/Nazara/Core/BufferMapper.hpp
Normal file
37
include/Nazara/Core/BufferMapper.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_BUFFERMAPPER_HPP
|
||||
#define NAZARA_CORE_BUFFERMAPPER_HPP
|
||||
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<class T>
|
||||
class BufferMapper
|
||||
{
|
||||
public:
|
||||
BufferMapper();
|
||||
BufferMapper(T& buffer, UInt64 offset, UInt64 length);
|
||||
~BufferMapper();
|
||||
|
||||
bool Map(T& buffer, UInt64 offset, UInt64 length);
|
||||
|
||||
const T* GetBuffer() const;
|
||||
void* GetPointer() const;
|
||||
|
||||
void Unmap();
|
||||
|
||||
private:
|
||||
T* m_buffer;
|
||||
void* m_ptr;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/BufferMapper.inl>
|
||||
|
||||
#endif // NAZARA_CORE_BUFFERMAPPER_HPP
|
||||
72
include/Nazara/Core/BufferMapper.inl
Normal file
72
include/Nazara/Core/BufferMapper.inl
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Config.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T>
|
||||
BufferMapper<T>::BufferMapper() :
|
||||
m_buffer(nullptr),
|
||||
m_ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
BufferMapper<T>::BufferMapper(T& buffer, UInt64 offset, UInt64 length) :
|
||||
m_buffer(nullptr)
|
||||
{
|
||||
if (!Map(buffer, offset, length))
|
||||
NazaraError("failed to map buffer"); ///TODO: Unexpected
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
BufferMapper<T>::~BufferMapper()
|
||||
{
|
||||
if (m_buffer)
|
||||
m_buffer->Unmap();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T* BufferMapper<T>::GetBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void* BufferMapper<T>::GetPointer() const
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool BufferMapper<T>::Map(T& buffer, UInt64 offset, UInt64 length)
|
||||
{
|
||||
Unmap();
|
||||
|
||||
m_buffer = &buffer;
|
||||
m_ptr = buffer.Map(offset, length);
|
||||
if (!m_ptr)
|
||||
{
|
||||
NazaraError("failed to map buffer"); ///TODO: Unexpected
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void BufferMapper<T>::Unmap()
|
||||
{
|
||||
if (m_buffer)
|
||||
{
|
||||
m_buffer->Unmap();
|
||||
m_buffer = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/SerializationContext.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// 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/Algorithm.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -163,7 +162,6 @@ namespace Nz
|
||||
*
|
||||
* \remark Produces a NazaraError if unserialization failed
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
ByteStream& ByteStream::operator>>(T& value)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Nz
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \class Nz::Clock
|
||||
* \brief Utility class that measure the elapsed time
|
||||
* \brief Core class that measure the elapsed time
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_CORE_COLOR_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
@@ -31,5 +31,10 @@
|
||||
|
||||
#include <Nazara/Core/Components/DisabledComponent.hpp>
|
||||
#include <Nazara/Core/Components/LifetimeComponent.hpp>
|
||||
#include <Nazara/Core/Components/NodeComponent.hpp>
|
||||
#include <Nazara/Core/Components/SharedSkeletonComponent.hpp>
|
||||
#include <Nazara/Core/Components/SkeletonComponent.hpp>
|
||||
#include <Nazara/Core/Components/SkeletonComponentBase.hpp>
|
||||
#include <Nazara/Core/Components/VelocityComponent.hpp>
|
||||
|
||||
#endif // NAZARA_CORE_COMPONENTS_HPP
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NAZARA_CORE_COMPONENTS_DISABLEDCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NAZARA_CORE_COMPONENTS_LIFETIMECOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
36
include/Nazara/Core/Components/NodeComponent.hpp
Normal file
36
include/Nazara/Core/Components/NodeComponent.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_COMPONENTS_NODECOMPONENT_HPP
|
||||
#define NAZARA_CORE_COMPONENTS_NODECOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Node.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API NodeComponent : public Node
|
||||
{
|
||||
public:
|
||||
using Node::Node;
|
||||
NodeComponent(const NodeComponent&) = default;
|
||||
NodeComponent(NodeComponent&&) noexcept = default;
|
||||
~NodeComponent() = default;
|
||||
|
||||
void SetParent(entt::handle entity, bool keepDerived = false);
|
||||
void SetParentJoint(entt::handle entity, std::string_view jointName, bool keepDerived = false);
|
||||
void SetParentJoint(entt::handle entity, std::size_t jointIndex, bool keepDerived = false);
|
||||
using Node::SetParent;
|
||||
|
||||
NodeComponent& operator=(const NodeComponent&) = default;
|
||||
NodeComponent& operator=(NodeComponent&&) noexcept = default;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Components/NodeComponent.inl>
|
||||
|
||||
#endif // NAZARA_CORE_COMPONENTS_NODECOMPONENT_HPP
|
||||
11
include/Nazara/Core/Components/NodeComponent.inl
Normal file
11
include/Nazara/Core/Components/NodeComponent.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
46
include/Nazara/Core/Components/SharedSkeletonComponent.hpp
Normal file
46
include/Nazara/Core/Components/SharedSkeletonComponent.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_COMPONENTS_SHAREDSKELETONCOMPONENT_HPP
|
||||
#define NAZARA_CORE_COMPONENTS_SHAREDSKELETONCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Skeleton.hpp>
|
||||
#include <Nazara/Core/Components/SkeletonComponentBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API SharedSkeletonComponent final : public SkeletonComponentBase
|
||||
{
|
||||
friend class SkeletonSystem;
|
||||
|
||||
public:
|
||||
SharedSkeletonComponent(std::shared_ptr<Skeleton> skeleton);
|
||||
SharedSkeletonComponent(const SharedSkeletonComponent& sharedSkeletalComponent);
|
||||
SharedSkeletonComponent(SharedSkeletonComponent&& sharedSkeletalComponent) noexcept;
|
||||
~SharedSkeletonComponent() = default;
|
||||
|
||||
SharedSkeletonComponent& operator=(const SharedSkeletonComponent& sharedSkeletalComponent);
|
||||
SharedSkeletonComponent& operator=(SharedSkeletonComponent&& sharedSkeletalComponent) noexcept;
|
||||
|
||||
private:
|
||||
const Skeleton& GetAttachedSkeleton() const override;
|
||||
inline bool IsAttachedSkeletonOutdated() const;
|
||||
void OnReferenceJointsInvalidated(const Skeleton* skeleton);
|
||||
void SetSkeletonParent(Node* parent);
|
||||
void SetupSkeleton();
|
||||
void UpdateAttachedSkeletonJoints();
|
||||
|
||||
NazaraSlot(Skeleton, OnSkeletonJointsInvalidated, m_onSkeletonJointsInvalidated);
|
||||
|
||||
Skeleton m_attachedSkeleton;
|
||||
bool m_skeletonJointInvalidated;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Components/SharedSkeletonComponent.inl>
|
||||
|
||||
#endif // NAZARA_CORE_COMPONENTS_SHAREDSKELETONCOMPONENT_HPP
|
||||
15
include/Nazara/Core/Components/SharedSkeletonComponent.inl
Normal file
15
include/Nazara/Core/Components/SharedSkeletonComponent.inl
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool SharedSkeletonComponent::IsAttachedSkeletonOutdated() const
|
||||
{
|
||||
return m_skeletonJointInvalidated;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
38
include/Nazara/Core/Components/SkeletonComponent.hpp
Normal file
38
include/Nazara/Core/Components/SkeletonComponent.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_COMPONENTS_SKELETONCOMPONENT_HPP
|
||||
#define NAZARA_CORE_COMPONENTS_SKELETONCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Skeleton.hpp>
|
||||
#include <Nazara/Core/Components/SkeletonComponentBase.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Node;
|
||||
|
||||
class NAZARA_CORE_API SkeletonComponent final : public SkeletonComponentBase
|
||||
{
|
||||
public:
|
||||
inline SkeletonComponent(std::shared_ptr<Skeleton> skeleton);
|
||||
SkeletonComponent(const SkeletonComponent&) = delete;
|
||||
SkeletonComponent(SkeletonComponent&& skeletalComponent) noexcept = default;
|
||||
~SkeletonComponent() = default;
|
||||
|
||||
inline Node* GetRootNode();
|
||||
|
||||
SkeletonComponent& operator=(const SkeletonComponent&) = delete;
|
||||
SkeletonComponent& operator=(SkeletonComponent&& skeletalComponent) noexcept = default;
|
||||
|
||||
private:
|
||||
inline const Skeleton& GetAttachedSkeleton() const override;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Components/SkeletonComponent.inl>
|
||||
|
||||
#endif // NAZARA_CORE_COMPONENTS_SKELETONCOMPONENT_HPP
|
||||
25
include/Nazara/Core/Components/SkeletonComponent.inl
Normal file
25
include/Nazara/Core/Components/SkeletonComponent.inl
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline SkeletonComponent::SkeletonComponent(std::shared_ptr<Skeleton> skeleton) :
|
||||
SkeletonComponentBase(std::move(skeleton))
|
||||
{
|
||||
}
|
||||
|
||||
inline Node* SkeletonComponent::GetRootNode()
|
||||
{
|
||||
return m_referenceSkeleton->GetRootJoint();
|
||||
}
|
||||
|
||||
inline const Skeleton& SkeletonComponent::GetAttachedSkeleton() const
|
||||
{
|
||||
return *m_referenceSkeleton;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
42
include/Nazara/Core/Components/SkeletonComponentBase.hpp
Normal file
42
include/Nazara/Core/Components/SkeletonComponentBase.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_COMPONENTS_SKELETONCOMPONENTBASE_HPP
|
||||
#define NAZARA_CORE_COMPONENTS_SKELETONCOMPONENTBASE_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Joint.hpp>
|
||||
#include <Nazara/Core/Skeleton.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API SkeletonComponentBase
|
||||
{
|
||||
public:
|
||||
SkeletonComponentBase(const SkeletonComponentBase&) = default;
|
||||
SkeletonComponentBase(SkeletonComponentBase&&) noexcept = default;
|
||||
~SkeletonComponentBase() = default;
|
||||
|
||||
inline std::size_t FindJointByName(std::string_view jointName) const;
|
||||
|
||||
inline const Joint& GetAttachedJoint(std::size_t jointIndex) const;
|
||||
inline const std::shared_ptr<Skeleton>& GetSkeleton() const;
|
||||
|
||||
SkeletonComponentBase& operator=(const SkeletonComponentBase&) = default;
|
||||
SkeletonComponentBase& operator=(SkeletonComponentBase&&) noexcept = default;
|
||||
|
||||
protected:
|
||||
SkeletonComponentBase(std::shared_ptr<Skeleton> skeleton);
|
||||
|
||||
virtual const Skeleton& GetAttachedSkeleton() const = 0;
|
||||
|
||||
std::shared_ptr<Skeleton> m_referenceSkeleton;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Components/SkeletonComponentBase.inl>
|
||||
|
||||
#endif // NAZARA_CORE_COMPONENTS_SKELETONCOMPONENTBASE_HPP
|
||||
30
include/Nazara/Core/Components/SkeletonComponentBase.inl
Normal file
30
include/Nazara/Core/Components/SkeletonComponentBase.inl
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline SkeletonComponentBase::SkeletonComponentBase(std::shared_ptr<Skeleton> skeleton) :
|
||||
m_referenceSkeleton(std::move(skeleton))
|
||||
{
|
||||
}
|
||||
|
||||
inline std::size_t SkeletonComponentBase::FindJointByName(std::string_view jointName) const
|
||||
{
|
||||
return m_referenceSkeleton->GetJointIndex(jointName);
|
||||
}
|
||||
|
||||
inline const Joint& SkeletonComponentBase::GetAttachedJoint(std::size_t jointIndex) const
|
||||
{
|
||||
return *GetAttachedSkeleton().GetJoint(jointIndex);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Skeleton>& SkeletonComponentBase::GetSkeleton() const
|
||||
{
|
||||
return m_referenceSkeleton;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
38
include/Nazara/Core/Components/VelocityComponent.hpp
Normal file
38
include/Nazara/Core/Components/VelocityComponent.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_COMPONENTS_VELOCITYCOMPONENT_HPP
|
||||
#define NAZARA_CORE_COMPONENTS_VELOCITYCOMPONENT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API VelocityComponent
|
||||
{
|
||||
public:
|
||||
inline VelocityComponent(const Vector3f& linearVelocity = Vector3f::Zero());
|
||||
VelocityComponent(const VelocityComponent&) = default;
|
||||
VelocityComponent(VelocityComponent&&) = default;
|
||||
~VelocityComponent() = default;
|
||||
|
||||
inline const Vector3f& GetLinearVelocity() const;
|
||||
|
||||
inline void UpdateLinearVelocity(const Vector3f& linearVelocity);
|
||||
|
||||
VelocityComponent& operator=(const VelocityComponent&) = default;
|
||||
VelocityComponent& operator=(VelocityComponent&&) = default;
|
||||
|
||||
private:
|
||||
Vector3f m_linearVelocity;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Components/VelocityComponent.inl>
|
||||
|
||||
#endif // NAZARA_CORE_COMPONENTS_VELOCITYCOMPONENT_HPP
|
||||
25
include/Nazara/Core/Components/VelocityComponent.inl
Normal file
25
include/Nazara/Core/Components/VelocityComponent.inl
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline VelocityComponent::VelocityComponent(const Vector3f& linearVelocity) :
|
||||
m_linearVelocity(linearVelocity)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Vector3f& VelocityComponent::GetLinearVelocity() const
|
||||
{
|
||||
return m_linearVelocity;
|
||||
}
|
||||
|
||||
inline void VelocityComponent::UpdateLinearVelocity(const Vector3f& linearVelocity)
|
||||
{
|
||||
m_linearVelocity = linearVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -34,9 +34,6 @@
|
||||
|
||||
/// Each modification of a parameter needs a recompilation of the module
|
||||
|
||||
// Precision of reals when transformed into string (Max. numbers after the coma)
|
||||
#define NAZARA_CORE_DECIMAL_DIGITS 6
|
||||
|
||||
// Duplicate the log output on the standard output flux (cout)
|
||||
#define NAZARA_CORE_DUPLICATE_LOG_TO_COUT 0
|
||||
|
||||
@@ -55,6 +52,12 @@
|
||||
// Activate the security tests based on the code (Advised for development)
|
||||
#define NAZARA_CORE_SAFE 1
|
||||
|
||||
// When a resource is being parsed, it triggers a warning if a non-critical error is found in the resource (Slower)
|
||||
#define NAZARA_CORE_STRICT_RESOURCE_PARSING 1
|
||||
|
||||
// The maximal number of weights acting on a vertex (In case of overflow, the surnumerous weights would be ignored and the others renormalized)
|
||||
#define NAZARA_CORE_SKINNING_MAX_WEIGHTS 4
|
||||
|
||||
/// Checking the values and types of certain constants
|
||||
#include <Nazara/Core/ConfigCheck.hpp>
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#include <type_traits>
|
||||
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
|
||||
|
||||
NazaraCheckTypeAndVal(NAZARA_CORE_DECIMAL_DIGITS, integral, >, 0, " shall be a strictly positive integer");
|
||||
NazaraCheckTypeAndVal(NAZARA_CORE_FILE_BUFFERSIZE, integral, >, 0, " shall be a strictly positive integer");
|
||||
NazaraCheckTypeAndVal(NAZARA_CORE_SKINNING_MAX_WEIGHTS, integral, >, 0, " shall be a strictly positive integer");
|
||||
|
||||
#undef NazaraCheckTypeAndVal
|
||||
|
||||
|
||||
@@ -8,7 +8,12 @@
|
||||
#define NAZARA_CORE_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Animation.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/Image.hpp>
|
||||
#include <Nazara/Core/ImageStream.hpp>
|
||||
#include <Nazara/Core/Mesh.hpp>
|
||||
#include <Nazara/Core/ModuleBase.hpp>
|
||||
#include <Nazara/Core/Modules.hpp>
|
||||
#include <NazaraUtils/TypeList.hpp>
|
||||
@@ -28,10 +33,28 @@ namespace Nz
|
||||
Core(Config /*config*/);
|
||||
~Core();
|
||||
|
||||
AnimationLoader& GetAnimationLoader();
|
||||
const AnimationLoader& GetAnimationLoader() const;
|
||||
inline const HardwareInfo& GetHardwareInfo() const;
|
||||
ImageLoader& GetImageLoader();
|
||||
const ImageLoader& GetImageLoader() const;
|
||||
ImageSaver& GetImageSaver();
|
||||
const ImageSaver& GetImageSaver() const;
|
||||
ImageStreamLoader& GetImageStreamLoader();
|
||||
const ImageStreamLoader& GetImageStreamLoader() const;
|
||||
MeshLoader& GetMeshLoader();
|
||||
const MeshLoader& GetMeshLoader() const;
|
||||
MeshSaver& GetMeshSaver();
|
||||
const MeshSaver& GetMeshSaver() const;
|
||||
|
||||
private:
|
||||
std::optional<HardwareInfo> m_hardwareInfo;
|
||||
AnimationLoader m_animationLoader;
|
||||
ImageLoader m_imageLoader;
|
||||
ImageSaver m_imageSaver;
|
||||
ImageStreamLoader m_imageStreamLoader;
|
||||
MeshLoader m_meshLoader;
|
||||
MeshSaver m_meshSaver;
|
||||
|
||||
static Core* s_instance;
|
||||
};
|
||||
|
||||
38
include/Nazara/Core/CubemapParams.hpp
Normal file
38
include/Nazara/Core/CubemapParams.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_CUBEMAPPARAMS_HPP
|
||||
#define NAZARA_CORE_CUBEMAPPARAMS_HPP
|
||||
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct CubemapParams
|
||||
{
|
||||
/*
|
||||
La position de chaque face dans la cubemap
|
||||
Les indices ici seront multipliés à la taille d'une face pour obtenir le coin haut-gauche de la zone.
|
||||
Si la taille d'une face est 0, elle sera calculée via max(width, height)/4.
|
||||
|
||||
Par défaut, cela suit ce layout :
|
||||
U
|
||||
L F R B
|
||||
D
|
||||
|
||||
Si ce n'est pas le cas, à vous de repositionner les faces correctement.
|
||||
*/
|
||||
Vector2ui backPosition = Vector2ui(3, 1);
|
||||
Vector2ui downPosition = Vector2ui(1, 2);
|
||||
Vector2ui forwardPosition = Vector2ui(1, 1);
|
||||
Vector2ui leftPosition = Vector2ui(0, 1);
|
||||
Vector2ui rightPosition = Vector2ui(2, 1);
|
||||
Vector2ui upPosition = Vector2ui(1, 0);
|
||||
unsigned int faceSize = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_CUBEMAPPARAMS_HPP
|
||||
@@ -11,6 +11,103 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum class AnimationType
|
||||
{
|
||||
Skeletal,
|
||||
Static,
|
||||
|
||||
Max = Static
|
||||
};
|
||||
|
||||
enum class BlendEquation
|
||||
{
|
||||
Add,
|
||||
Max,
|
||||
Min,
|
||||
ReverseSubtract,
|
||||
Subtract,
|
||||
};
|
||||
|
||||
enum class BlendFunc
|
||||
{
|
||||
ConstantColor,
|
||||
ConstantAlpha,
|
||||
DstAlpha,
|
||||
DstColor,
|
||||
SrcAlpha,
|
||||
SrcColor,
|
||||
InvConstantColor,
|
||||
InvConstantAlpha,
|
||||
InvDstAlpha,
|
||||
InvDstColor,
|
||||
InvSrcAlpha,
|
||||
InvSrcColor,
|
||||
One,
|
||||
Zero
|
||||
};
|
||||
|
||||
enum class BufferAccess
|
||||
{
|
||||
DiscardAndWrite,
|
||||
ReadOnly,
|
||||
ReadWrite,
|
||||
WriteOnly,
|
||||
|
||||
Max = WriteOnly
|
||||
};
|
||||
|
||||
enum class BufferType
|
||||
{
|
||||
Index,
|
||||
Vertex,
|
||||
Storage,
|
||||
Uniform,
|
||||
Upload,
|
||||
|
||||
Max = Upload
|
||||
};
|
||||
|
||||
enum class BufferUsage
|
||||
{
|
||||
DeviceLocal,
|
||||
DirectMapping,
|
||||
Dynamic,
|
||||
Read,
|
||||
PersistentMapping,
|
||||
Write,
|
||||
|
||||
Max = DirectMapping
|
||||
};
|
||||
|
||||
template<>
|
||||
struct EnumAsFlags<BufferUsage>
|
||||
{
|
||||
static constexpr BufferUsage max = BufferUsage::Max;
|
||||
};
|
||||
|
||||
using BufferUsageFlags = Flags<BufferUsage>;
|
||||
|
||||
enum class ComponentType
|
||||
{
|
||||
Color,
|
||||
Double1,
|
||||
Double2,
|
||||
Double3,
|
||||
Double4,
|
||||
Float1,
|
||||
Float2,
|
||||
Float3,
|
||||
Float4,
|
||||
Int1,
|
||||
Int2,
|
||||
Int3,
|
||||
Int4,
|
||||
|
||||
Max = Int4
|
||||
};
|
||||
|
||||
constexpr std::size_t ComponentTypeCount = static_cast<std::size_t>(ComponentType::Max) + 1;
|
||||
|
||||
enum class CoordSys
|
||||
{
|
||||
Global,
|
||||
@@ -28,6 +125,37 @@ namespace Nz
|
||||
Max = AtEnd
|
||||
};
|
||||
|
||||
enum class CubemapFace
|
||||
{
|
||||
// This enumeration is intended to replace the "z" argument of Image's methods containing cubemap
|
||||
// The order is X, -X, Y, -Y, Z, -Z
|
||||
PositiveX = 0,
|
||||
PositiveY = 2,
|
||||
PositiveZ = 4,
|
||||
NegativeX = 1,
|
||||
NegativeY = 3,
|
||||
NegativeZ = 5,
|
||||
|
||||
Max = NegativeZ
|
||||
};
|
||||
|
||||
enum class DataStorage
|
||||
{
|
||||
Hardware,
|
||||
Software,
|
||||
|
||||
Max = Software
|
||||
};
|
||||
|
||||
template<>
|
||||
struct EnumAsFlags<DataStorage>
|
||||
{
|
||||
static constexpr DataStorage max = DataStorage::Max;
|
||||
};
|
||||
|
||||
using DataStoreFlags = Flags<DataStorage>;
|
||||
constexpr std::size_t DataStorageCount = static_cast<std::size_t>(DataStorage::Max) + 1;
|
||||
|
||||
enum class ErrorMode
|
||||
{
|
||||
Silent,
|
||||
@@ -58,6 +186,34 @@ namespace Nz
|
||||
|
||||
constexpr std::size_t ErrorTypeCount = static_cast<std::size_t>(ErrorType::Max) + 1;
|
||||
|
||||
enum class FaceFilling
|
||||
{
|
||||
Fill,
|
||||
Line,
|
||||
Point,
|
||||
|
||||
Max = Point
|
||||
};
|
||||
|
||||
enum class FaceCulling
|
||||
{
|
||||
None,
|
||||
|
||||
Back,
|
||||
Front,
|
||||
FrontAndBack,
|
||||
|
||||
Max = FrontAndBack
|
||||
};
|
||||
|
||||
enum class FrontFace
|
||||
{
|
||||
Clockwise,
|
||||
CounterClockwise,
|
||||
|
||||
Max = CounterClockwise
|
||||
};
|
||||
|
||||
enum class ImageType
|
||||
{
|
||||
E1D,
|
||||
@@ -72,6 +228,15 @@ namespace Nz
|
||||
|
||||
constexpr std::size_t ImageTypeCount = static_cast<std::size_t>(ImageType::Max) + 1;
|
||||
|
||||
enum class IndexType
|
||||
{
|
||||
U8,
|
||||
U16,
|
||||
U32,
|
||||
|
||||
Max = U32
|
||||
};
|
||||
|
||||
enum class HashType
|
||||
{
|
||||
CRC32,
|
||||
@@ -131,6 +296,120 @@ namespace Nz
|
||||
Max = Userdata
|
||||
};
|
||||
|
||||
enum class PixelFormatContent
|
||||
{
|
||||
Undefined = -1,
|
||||
|
||||
ColorRGBA,
|
||||
Depth,
|
||||
DepthStencil,
|
||||
Stencil,
|
||||
|
||||
Max = Stencil
|
||||
};
|
||||
|
||||
enum class PixelFormat
|
||||
{
|
||||
Undefined = -1,
|
||||
|
||||
A8, // 1*uint8
|
||||
BGR8, // 3*uint8
|
||||
BGR8_SRGB, // 3*uint8
|
||||
BGRA8, // 4*uint8
|
||||
BGRA8_SRGB, // 4*uint8
|
||||
DXT1,
|
||||
DXT3,
|
||||
DXT5,
|
||||
L8, // 1*uint8
|
||||
LA8, // 2*uint8
|
||||
R8, // 1*uint8
|
||||
R8I, // 1*int8
|
||||
R8UI, // 1*uint8
|
||||
R16, // 1*uint16
|
||||
R16F, // 1*half
|
||||
R16I, // 1*int16
|
||||
R16UI, // 1*uint16
|
||||
R32F, // 1*float
|
||||
R32I, // 1*uint16
|
||||
R32UI, // 1*uint32
|
||||
RG8, // 2*int8
|
||||
RG8I, // 2*int8
|
||||
RG8UI, // 2*uint8
|
||||
RG16, // 2*uint16
|
||||
RG16F, // 2*half
|
||||
RG16I, // 2*int16
|
||||
RG16UI, // 2*uint16
|
||||
RG32F, // 2*float
|
||||
RG32I, // 2*uint16
|
||||
RG32UI, // 2*uint32
|
||||
RGB5A1, // 3*uint5 + alpha bit
|
||||
RGB8, // 3*uint8
|
||||
RGB8_SRGB, // 3*uint8
|
||||
RGB16F, // 3*half
|
||||
RGB16I, // 4*int16
|
||||
RGB16UI, // 4*uint16
|
||||
RGB32F, // 3*float
|
||||
RGB32I, // 4*int32
|
||||
RGB32UI, // 4*uint32
|
||||
RGBA4, // 4*uint4
|
||||
RGBA8, // 4*uint8
|
||||
RGBA8_SRGB, // 4*uint8
|
||||
RGBA16F, // 4*half
|
||||
RGBA16I, // 4*int16
|
||||
RGBA16UI, // 4*uint16
|
||||
RGBA32F, // 4*float
|
||||
RGBA32I, // 4*int32
|
||||
RGBA32UI, // 4*uint32
|
||||
Depth16,
|
||||
Depth16Stencil8,
|
||||
Depth24,
|
||||
Depth24Stencil8,
|
||||
Depth32F,
|
||||
Depth32FStencil8,
|
||||
Stencil1,
|
||||
Stencil4,
|
||||
Stencil8,
|
||||
Stencil16,
|
||||
|
||||
Max = Stencil16
|
||||
};
|
||||
|
||||
constexpr std::size_t PixelFormatCount = static_cast<std::size_t>(PixelFormat::Max) + 1;
|
||||
|
||||
enum class PixelFormatSubType
|
||||
{
|
||||
Compressed, // Opaque
|
||||
Double, // F64
|
||||
Float, // F32
|
||||
Half, // F16
|
||||
Int, // Signed integer
|
||||
Unsigned, // Unsigned integer
|
||||
|
||||
Max = Unsigned
|
||||
};
|
||||
|
||||
enum class PixelFlipping
|
||||
{
|
||||
Horizontally,
|
||||
Vertically,
|
||||
|
||||
Max = Vertically
|
||||
};
|
||||
|
||||
constexpr std::size_t PixelFlippingCount = static_cast<std::size_t>(PixelFlipping::Max) + 1;
|
||||
|
||||
enum class PrimitiveMode
|
||||
{
|
||||
LineList,
|
||||
LineStrip,
|
||||
PointList,
|
||||
TriangleList,
|
||||
TriangleStrip,
|
||||
TriangleFan,
|
||||
|
||||
Max = TriangleFan
|
||||
};
|
||||
|
||||
enum class PrimitiveType
|
||||
{
|
||||
Box,
|
||||
@@ -204,6 +483,20 @@ namespace Nz
|
||||
|
||||
constexpr std::size_t ProcessorVendorCount = static_cast<std::size_t>(ProcessorVendor::Max) + 1;
|
||||
|
||||
enum class RendererComparison
|
||||
{
|
||||
Always,
|
||||
Equal,
|
||||
Greater,
|
||||
GreaterOrEqual,
|
||||
Less,
|
||||
LessOrEqual,
|
||||
Never,
|
||||
NotEqual,
|
||||
|
||||
Max = NotEqual
|
||||
};
|
||||
|
||||
enum class ResourceLoadingError
|
||||
{
|
||||
DecodingError,
|
||||
@@ -213,6 +506,31 @@ namespace Nz
|
||||
Unrecognized
|
||||
};
|
||||
|
||||
enum class SamplerFilter
|
||||
{
|
||||
Linear,
|
||||
Nearest,
|
||||
|
||||
Max = Nearest
|
||||
};
|
||||
|
||||
enum class SamplerMipmapMode
|
||||
{
|
||||
Linear,
|
||||
Nearest,
|
||||
|
||||
Max = Nearest
|
||||
};
|
||||
|
||||
enum class SamplerWrap
|
||||
{
|
||||
Clamp,
|
||||
MirroredRepeat,
|
||||
Repeat,
|
||||
|
||||
Max = Repeat
|
||||
};
|
||||
|
||||
enum class SphereType
|
||||
{
|
||||
Cubic,
|
||||
@@ -222,6 +540,20 @@ namespace Nz
|
||||
Max = UV
|
||||
};
|
||||
|
||||
enum class StencilOperation
|
||||
{
|
||||
Decrement,
|
||||
DecrementNoClamp,
|
||||
Increment,
|
||||
IncrementNoClamp,
|
||||
Invert,
|
||||
Keep,
|
||||
Replace,
|
||||
Zero,
|
||||
|
||||
Max = Zero
|
||||
};
|
||||
|
||||
enum class StreamOption
|
||||
{
|
||||
None,
|
||||
@@ -241,6 +573,83 @@ namespace Nz
|
||||
};
|
||||
|
||||
using StreamOptionFlags = Flags<StreamOption>;
|
||||
|
||||
enum class TextAlign
|
||||
{
|
||||
Left,
|
||||
Middle,
|
||||
Right,
|
||||
|
||||
Max = Right
|
||||
};
|
||||
|
||||
enum class TextStyle
|
||||
{
|
||||
Bold,
|
||||
Italic,
|
||||
StrikeThrough,
|
||||
Underlined,
|
||||
|
||||
Max = Underlined
|
||||
};
|
||||
|
||||
template<>
|
||||
struct EnumAsFlags<TextStyle>
|
||||
{
|
||||
static constexpr TextStyle max = TextStyle::Max;
|
||||
};
|
||||
|
||||
using TextStyleFlags = Flags<TextStyle>;
|
||||
|
||||
constexpr TextStyleFlags TextStyle_Regular = TextStyleFlags{};
|
||||
|
||||
enum class VertexComponent
|
||||
{
|
||||
Unused = -1,
|
||||
|
||||
Color,
|
||||
JointIndices,
|
||||
JointWeights,
|
||||
Normal,
|
||||
Position,
|
||||
SizeSinCos,
|
||||
Tangent,
|
||||
TexCoord,
|
||||
Userdata,
|
||||
|
||||
Max = Userdata
|
||||
};
|
||||
|
||||
enum class VertexInputRate
|
||||
{
|
||||
Instance,
|
||||
Vertex
|
||||
};
|
||||
|
||||
enum class VertexLayout
|
||||
{
|
||||
// Predefined declarations for rendering
|
||||
UV_SizeSinCos,
|
||||
XY,
|
||||
XY_Color,
|
||||
XY_UV,
|
||||
XYZ,
|
||||
XYZ_Color,
|
||||
XYZ_Color_UV,
|
||||
XYZ_Normal,
|
||||
XYZ_Normal_UV,
|
||||
XYZ_Normal_UV_Tangent,
|
||||
XYZ_Normal_UV_Tangent_Skinning,
|
||||
UV_SizeSinCos_Color,
|
||||
XYZ_UV,
|
||||
|
||||
// Predefined declarations for instancing
|
||||
Matrix4,
|
||||
|
||||
Max = Matrix4
|
||||
};
|
||||
|
||||
constexpr std::size_t VertexLayoutCount = static_cast<std::size_t>(VertexLayout::Max) + 1;
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_ENUMS_HPP
|
||||
|
||||
83
include/Nazara/Core/Formats/MD5AnimParser.hpp
Normal file
83
include/Nazara/Core/Formats/MD5AnimParser.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_MD5ANIMPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_MD5ANIMPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Stream;
|
||||
|
||||
class NAZARA_CORE_API MD5AnimParser
|
||||
{
|
||||
public:
|
||||
struct FrameJoint
|
||||
{
|
||||
Quaternionf orient;
|
||||
Vector3f pos;
|
||||
};
|
||||
|
||||
struct Frame
|
||||
{
|
||||
std::vector<FrameJoint> joints;
|
||||
Boxf bounds;
|
||||
};
|
||||
|
||||
struct Joint
|
||||
{
|
||||
std::string name;
|
||||
Int32 parent;
|
||||
Quaternionf bindOrient;
|
||||
Vector3f bindPos;
|
||||
UInt32 flags;
|
||||
UInt32 index;
|
||||
};
|
||||
|
||||
MD5AnimParser(Stream& stream);
|
||||
~MD5AnimParser();
|
||||
|
||||
bool Check();
|
||||
|
||||
UInt32 GetAnimatedComponentCount() const;
|
||||
const Frame* GetFrames() const;
|
||||
UInt32 GetFrameCount() const;
|
||||
UInt32 GetFrameRate() const;
|
||||
const Joint* GetJoints() const;
|
||||
UInt32 GetJointCount() const;
|
||||
|
||||
bool Parse();
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
void Error(std::string_view message);
|
||||
bool ParseBaseframe();
|
||||
bool ParseBounds();
|
||||
bool ParseFrame();
|
||||
bool ParseHierarchy();
|
||||
void Warning(std::string_view message);
|
||||
void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<float> m_animatedComponents;
|
||||
std::vector<Frame> m_frames;
|
||||
std::vector<Joint> m_joints;
|
||||
Stream& m_stream;
|
||||
StreamOptionFlags m_streamFlags;
|
||||
std::string m_currentLine;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_frameIndex;
|
||||
unsigned int m_frameRate;
|
||||
unsigned int m_lineCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_MD5ANIMPARSER_HPP
|
||||
88
include/Nazara/Core/Formats/MD5MeshParser.hpp
Normal file
88
include/Nazara/Core/Formats/MD5MeshParser.hpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_MD5MESHPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_MD5MESHPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Stream;
|
||||
|
||||
class NAZARA_CORE_API MD5MeshParser
|
||||
{
|
||||
public:
|
||||
struct Joint
|
||||
{
|
||||
std::string name;
|
||||
Int32 parent;
|
||||
Quaternionf bindOrient;
|
||||
Vector3f bindPos;
|
||||
};
|
||||
|
||||
using Triangle = Vector3ui;
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
Vector2f uv;
|
||||
unsigned int startWeight;
|
||||
unsigned int weightCount;
|
||||
};
|
||||
|
||||
struct Weight
|
||||
{
|
||||
Vector3f pos;
|
||||
float bias;
|
||||
unsigned int joint;
|
||||
};
|
||||
|
||||
struct Mesh
|
||||
{
|
||||
std::vector<Triangle> triangles;
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<Weight> weights;
|
||||
std::string shader;
|
||||
};
|
||||
|
||||
MD5MeshParser(Stream& stream);
|
||||
~MD5MeshParser();
|
||||
|
||||
bool Check();
|
||||
|
||||
const Joint* GetJoints() const;
|
||||
UInt32 GetJointCount() const;
|
||||
const Mesh* GetMeshes() const;
|
||||
UInt32 GetMeshCount() const;
|
||||
|
||||
bool Parse();
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
void Error(std::string_view message);
|
||||
bool ParseJoints();
|
||||
bool ParseMesh();
|
||||
void Warning(std::string_view message);
|
||||
void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<Joint> m_joints;
|
||||
std::vector<Mesh> m_meshes;
|
||||
Stream& m_stream;
|
||||
StreamOptionFlags m_streamFlags;
|
||||
std::string m_currentLine;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
unsigned int m_meshIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_MD5MESHPARSER_HPP
|
||||
80
include/Nazara/Core/Formats/MTLParser.hpp
Normal file
80
include/Nazara/Core/Formats/MTLParser.hpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_MTLPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_MTLPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <NazaraUtils/StringHash.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API MTLParser
|
||||
{
|
||||
public:
|
||||
struct Material;
|
||||
|
||||
MTLParser() = default;
|
||||
~MTLParser() = default;
|
||||
|
||||
inline Material* AddMaterial(std::string matName);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
inline const Material* GetMaterial(std::string_view materialName) const;
|
||||
inline const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>& GetMaterials() const;
|
||||
|
||||
bool Parse(Stream& stream);
|
||||
|
||||
bool Save(Stream& stream) const;
|
||||
|
||||
struct Material
|
||||
{
|
||||
Color ambient = Color::White();
|
||||
Color diffuse = Color::White();
|
||||
Color specular = Color::White();
|
||||
std::string alphaMap;
|
||||
std::string ambientMap;
|
||||
std::string bumpMap;
|
||||
std::string decalMap;
|
||||
std::string diffuseMap;
|
||||
std::string displacementMap;
|
||||
std::string emissiveMap; //< <!> Custom addition: not present in MTL
|
||||
std::string normalMap; //< <!> Custom addition: not present in MTL
|
||||
std::string reflectionMap;
|
||||
std::string shininessMap;
|
||||
std::string specularMap;
|
||||
float alpha = 1.f;
|
||||
float refractionIndex = 1.f;
|
||||
float shininess = 1.f;
|
||||
unsigned int illumModel = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
template<typename T> void Emit(const T& text) const;
|
||||
inline void EmitLine() const;
|
||||
template<typename T> void EmitLine(const T& line) const;
|
||||
inline void Error(std::string_view message);
|
||||
inline void Flush() const;
|
||||
inline void Warning(std::string_view message);
|
||||
inline void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>> m_materials;
|
||||
mutable Stream* m_currentStream;
|
||||
std::string m_currentLine;
|
||||
mutable std::ostringstream m_outputStream;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Formats/MTLParser.inl>
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_MTLPARSER_HPP
|
||||
81
include/Nazara/Core/Formats/MTLParser.inl
Normal file
81
include/Nazara/Core/Formats/MTLParser.inl
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline MTLParser::Material* MTLParser::AddMaterial(std::string matName)
|
||||
{
|
||||
return &m_materials[std::move(matName)];
|
||||
}
|
||||
|
||||
inline void MTLParser::Clear()
|
||||
{
|
||||
m_materials.clear();
|
||||
}
|
||||
|
||||
inline const MTLParser::Material* MTLParser::GetMaterial(std::string_view materialName) const
|
||||
{
|
||||
auto it = m_materials.find(materialName);
|
||||
if (it != m_materials.end())
|
||||
return &it->second;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline auto MTLParser::GetMaterials() const -> const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>&
|
||||
{
|
||||
return m_materials;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void MTLParser::Emit(const T& text) const
|
||||
{
|
||||
m_outputStream << text;
|
||||
if (m_outputStream.rdbuf()->str().size() > 1024 * 1024)
|
||||
Flush();
|
||||
}
|
||||
|
||||
inline void MTLParser::EmitLine() const
|
||||
{
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void MTLParser::EmitLine(const T& line) const
|
||||
{
|
||||
Emit(line);
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
inline void MTLParser::Error(std::string_view message)
|
||||
{
|
||||
NazaraErrorFmt("{0} at line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline void MTLParser::Flush() const
|
||||
{
|
||||
m_currentStream->Write(std::move(m_outputStream).str());
|
||||
m_outputStream.str({});
|
||||
}
|
||||
|
||||
inline void MTLParser::Warning(std::string_view message)
|
||||
{
|
||||
NazaraWarningFmt("{0} at line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline void MTLParser::UnrecognizedLine(bool error)
|
||||
{
|
||||
std::string message = "Unrecognized \"" + m_currentLine + '"';
|
||||
|
||||
if (error)
|
||||
Error(message);
|
||||
else
|
||||
Warning(message);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
108
include/Nazara/Core/Formats/OBJParser.hpp
Normal file
108
include/Nazara/Core/Formats/OBJParser.hpp
Normal file
@@ -0,0 +1,108 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_FORMATS_OBJPARSER_HPP
|
||||
#define NAZARA_CORE_FORMATS_OBJPARSER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Stream;
|
||||
|
||||
class NAZARA_CORE_API OBJParser
|
||||
{
|
||||
public:
|
||||
struct Mesh;
|
||||
|
||||
OBJParser() = default;
|
||||
~OBJParser() = default;
|
||||
|
||||
inline void Clear();
|
||||
|
||||
bool Check(Stream& stream);
|
||||
|
||||
inline std::string* GetMaterials();
|
||||
inline const std::string* GetMaterials() const;
|
||||
inline std::size_t GetMaterialCount() const;
|
||||
inline Mesh* GetMeshes();
|
||||
inline const Mesh* GetMeshes() const;
|
||||
inline std::size_t GetMeshCount() const;
|
||||
inline const std::filesystem::path& GetMtlLib() const;
|
||||
inline Vector3f* GetNormals();
|
||||
inline const Vector3f* GetNormals() const;
|
||||
inline std::size_t GetNormalCount() const;
|
||||
inline Vector4f* GetPositions();
|
||||
inline const Vector4f* GetPositions() const;
|
||||
inline std::size_t GetPositionCount() const;
|
||||
inline Vector3f* GetTexCoords();
|
||||
inline const Vector3f* GetTexCoords() const;
|
||||
inline std::size_t GetTexCoordCount() const;
|
||||
|
||||
bool Parse(Stream& stream, std::size_t reservedVertexCount = 100);
|
||||
|
||||
bool Save(Stream& stream) const;
|
||||
|
||||
inline std::string* SetMaterialCount(std::size_t materialCount);
|
||||
inline Mesh* SetMeshCount(std::size_t meshCount);
|
||||
inline void SetMtlLib(const std::filesystem::path& mtlLib);
|
||||
inline Vector3f* SetNormalCount(std::size_t normalCount);
|
||||
inline Vector4f* SetPositionCount(std::size_t positionCount);
|
||||
inline Vector3f* SetTexCoordCount(std::size_t texCoordCount);
|
||||
|
||||
struct Face
|
||||
{
|
||||
std::size_t firstVertex;
|
||||
std::size_t vertexCount;
|
||||
};
|
||||
|
||||
struct FaceVertex
|
||||
{
|
||||
std::size_t normal;
|
||||
std::size_t position;
|
||||
std::size_t texCoord;
|
||||
};
|
||||
|
||||
struct Mesh
|
||||
{
|
||||
std::vector<Face> faces;
|
||||
std::vector<FaceVertex> vertices;
|
||||
std::string name;
|
||||
std::size_t material;
|
||||
};
|
||||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
template<typename T> void Emit(const T& text) const;
|
||||
inline void EmitLine() const;
|
||||
template<typename T> void EmitLine(const T& line) const;
|
||||
inline void Error(std::string_view message);
|
||||
void Flush() const;
|
||||
inline void Warning(std::string_view message);
|
||||
inline bool UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<Mesh> m_meshes;
|
||||
std::vector<std::string> m_materials;
|
||||
std::vector<Vector3f> m_normals;
|
||||
std::vector<Vector4f> m_positions;
|
||||
std::vector<Vector3f> m_texCoords;
|
||||
mutable Stream* m_currentStream;
|
||||
std::string m_currentLine;
|
||||
std::filesystem::path m_mtlLib;
|
||||
mutable std::ostringstream m_outputStream;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
unsigned int m_errorCount;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Formats/OBJParser.inl>
|
||||
|
||||
#endif // NAZARA_CORE_FORMATS_OBJPARSER_HPP
|
||||
185
include/Nazara/Core/Formats/OBJParser.inl
Normal file
185
include/Nazara/Core/Formats/OBJParser.inl
Normal file
@@ -0,0 +1,185 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void OBJParser::Clear()
|
||||
{
|
||||
m_materials.clear();
|
||||
m_meshes.clear();
|
||||
m_positions.clear();
|
||||
m_normals.clear();
|
||||
m_texCoords.clear();
|
||||
}
|
||||
|
||||
inline std::string* OBJParser::GetMaterials()
|
||||
{
|
||||
return m_materials.data();
|
||||
}
|
||||
|
||||
inline const std::string* OBJParser::GetMaterials() const
|
||||
{
|
||||
return m_materials.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetMaterialCount() const
|
||||
{
|
||||
return m_materials.size();
|
||||
}
|
||||
|
||||
inline OBJParser::Mesh* OBJParser::GetMeshes()
|
||||
{
|
||||
return m_meshes.data();
|
||||
}
|
||||
|
||||
inline const OBJParser::Mesh* OBJParser::GetMeshes() const
|
||||
{
|
||||
return m_meshes.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetMeshCount() const
|
||||
{
|
||||
return m_meshes.size();
|
||||
}
|
||||
|
||||
inline const std::filesystem::path& OBJParser::GetMtlLib() const
|
||||
{
|
||||
return m_mtlLib;
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::GetNormals()
|
||||
{
|
||||
return m_normals.data();
|
||||
}
|
||||
|
||||
inline const Vector3f* OBJParser::GetNormals() const
|
||||
{
|
||||
return m_normals.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetNormalCount() const
|
||||
{
|
||||
return m_normals.size();
|
||||
}
|
||||
|
||||
inline Vector4f* OBJParser::GetPositions()
|
||||
{
|
||||
return m_positions.data();
|
||||
}
|
||||
|
||||
inline const Vector4f* OBJParser::GetPositions() const
|
||||
{
|
||||
return m_positions.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetPositionCount() const
|
||||
{
|
||||
return m_positions.size();
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::GetTexCoords()
|
||||
{
|
||||
return m_texCoords.data();
|
||||
}
|
||||
|
||||
inline const Vector3f* OBJParser::GetTexCoords() const
|
||||
{
|
||||
return m_texCoords.data();
|
||||
}
|
||||
|
||||
inline std::size_t OBJParser::GetTexCoordCount() const
|
||||
{
|
||||
return m_texCoords.size();
|
||||
}
|
||||
|
||||
inline std::string* OBJParser::SetMaterialCount(std::size_t materialCount)
|
||||
{
|
||||
m_materials.resize(materialCount);
|
||||
return m_materials.data();
|
||||
}
|
||||
|
||||
inline OBJParser::Mesh* OBJParser::SetMeshCount(std::size_t meshCount)
|
||||
{
|
||||
m_meshes.resize(meshCount);
|
||||
return m_meshes.data();
|
||||
}
|
||||
|
||||
inline void OBJParser::SetMtlLib(const std::filesystem::path& mtlLib)
|
||||
{
|
||||
m_mtlLib = mtlLib;
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::SetNormalCount(std::size_t normalCount)
|
||||
{
|
||||
m_normals.resize(normalCount);
|
||||
return m_normals.data();
|
||||
}
|
||||
|
||||
inline Vector4f* OBJParser::SetPositionCount(std::size_t positionCount)
|
||||
{
|
||||
m_positions.resize(positionCount);
|
||||
return m_positions.data();
|
||||
}
|
||||
|
||||
inline Vector3f* OBJParser::SetTexCoordCount(std::size_t texCoordCount)
|
||||
{
|
||||
m_texCoords.resize(texCoordCount);
|
||||
return m_texCoords.data();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void OBJParser::Emit(const T& text) const
|
||||
{
|
||||
m_outputStream << text;
|
||||
if (m_outputStream.rdbuf()->str().size() > 1024 * 1024)
|
||||
Flush();
|
||||
}
|
||||
|
||||
inline void OBJParser::EmitLine() const
|
||||
{
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void OBJParser::EmitLine(const T& line) const
|
||||
{
|
||||
Emit(line);
|
||||
Emit('\n');
|
||||
}
|
||||
|
||||
inline void OBJParser::Error(std::string_view message)
|
||||
{
|
||||
NazaraErrorFmt("{0} on line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline void OBJParser::Warning(std::string_view message)
|
||||
{
|
||||
NazaraWarningFmt("{0} on line #{1}", message, m_lineCount);
|
||||
}
|
||||
|
||||
inline bool OBJParser::UnrecognizedLine(bool error)
|
||||
{
|
||||
std::string message = "Unrecognized \"" + m_currentLine + '"';
|
||||
|
||||
if (error)
|
||||
Error(message);
|
||||
else
|
||||
Warning(message);
|
||||
|
||||
m_errorCount++;
|
||||
|
||||
if (m_errorCount > 10 && (m_errorCount * 100 / m_lineCount) > 50)
|
||||
{
|
||||
NazaraError("aborting parsing because of error percentage");
|
||||
return false; //< Abort parsing if error percentage is too high
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -7,7 +7,8 @@
|
||||
#ifndef NAZARA_CORE_FUNCTOR_HPP
|
||||
#define NAZARA_CORE_FUNCTOR_HPP
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
// Inspired from the of code of the SFML by Laurent Gomila
|
||||
|
||||
|
||||
79
include/Nazara/Core/GuillotineImageAtlas.hpp
Normal file
79
include/Nazara/Core/GuillotineImageAtlas.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_GUILLOTINEIMAGEATLAS_HPP
|
||||
#define NAZARA_CORE_GUILLOTINEIMAGEATLAS_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/AbstractAtlas.hpp>
|
||||
#include <Nazara/Core/AbstractImage.hpp>
|
||||
#include <Nazara/Core/GuillotineBinPack.hpp>
|
||||
#include <Nazara/Core/Image.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API GuillotineImageAtlas : public AbstractAtlas
|
||||
{
|
||||
public:
|
||||
GuillotineImageAtlas();
|
||||
GuillotineImageAtlas(const GuillotineImageAtlas&) = delete;
|
||||
GuillotineImageAtlas(GuillotineImageAtlas&&) noexcept = default;
|
||||
~GuillotineImageAtlas() = default;
|
||||
|
||||
void Clear() override;
|
||||
|
||||
void Free(SparsePtr<const Rectui> rects, SparsePtr<std::size_t> layers, std::size_t count) override;
|
||||
|
||||
unsigned int GetMaxLayerSize() const;
|
||||
GuillotineBinPack::FreeRectChoiceHeuristic GetRectChoiceHeuristic() const;
|
||||
GuillotineBinPack::GuillotineSplitHeuristic GetRectSplitHeuristic() const;
|
||||
AbstractImage* GetLayer(std::size_t layerIndex) const override;
|
||||
std::size_t GetLayerCount() const override;
|
||||
DataStoreFlags GetStorage() const override;
|
||||
|
||||
bool Insert(const Image& image, Rectui* rect, bool* flipped, std::size_t* layerIndex) override;
|
||||
|
||||
void SetMaxLayerSize(unsigned int maxLayerSize);
|
||||
void SetRectChoiceHeuristic(GuillotineBinPack::FreeRectChoiceHeuristic heuristic);
|
||||
void SetRectSplitHeuristic(GuillotineBinPack::GuillotineSplitHeuristic heuristic);
|
||||
|
||||
GuillotineImageAtlas& operator=(const GuillotineImageAtlas&) = delete;
|
||||
GuillotineImageAtlas& operator=(GuillotineImageAtlas&&) noexcept = default;
|
||||
|
||||
protected:
|
||||
struct Layer;
|
||||
|
||||
virtual std::shared_ptr<AbstractImage> ResizeImage(const std::shared_ptr<AbstractImage>& oldImage, const Vector2ui& size) const;
|
||||
bool ResizeLayer(Layer& layer, const Vector2ui& size);
|
||||
|
||||
struct QueuedGlyph
|
||||
{
|
||||
Image image;
|
||||
Rectui rect;
|
||||
bool flipped;
|
||||
};
|
||||
|
||||
struct Layer
|
||||
{
|
||||
std::vector<QueuedGlyph> queuedGlyphs;
|
||||
std::shared_ptr<AbstractImage> image;
|
||||
GuillotineBinPack binPack;
|
||||
unsigned int freedRectangles = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
void ProcessGlyphQueue(Layer& layer) const;
|
||||
|
||||
mutable std::vector<Layer> m_layers;
|
||||
GuillotineBinPack::FreeRectChoiceHeuristic m_rectChoiceHeuristic;
|
||||
GuillotineBinPack::GuillotineSplitHeuristic m_rectSplitHeuristic;
|
||||
unsigned int m_maxLayerSize;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_GUILLOTINEIMAGEATLAS_HPP
|
||||
@@ -2,7 +2,6 @@
|
||||
// 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/Algorithm.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
||||
173
include/Nazara/Core/Image.hpp
Normal file
173
include/Nazara/Core/Image.hpp
Normal file
@@ -0,0 +1,173 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_IMAGE_HPP
|
||||
#define NAZARA_CORE_IMAGE_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/AbstractImage.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/CubemapParams.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/ResourceSaver.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <atomic>
|
||||
|
||||
///TODO: Filtres
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct NAZARA_CORE_API ImageParams : ResourceParameters
|
||||
{
|
||||
// Le format dans lequel l'image doit être chargée (Undefined pour le format le plus proche de l'original)
|
||||
PixelFormat loadFormat = PixelFormat::Undefined;
|
||||
|
||||
// Le nombre de niveaux de mipmaps maximum devant être créé
|
||||
UInt8 levelCount = 0;
|
||||
|
||||
bool IsValid() const;
|
||||
void Merge(const ImageParams& params);
|
||||
};
|
||||
|
||||
class Image;
|
||||
|
||||
using ImageLibrary = ObjectLibrary<Image>;
|
||||
using ImageLoader = ResourceLoader<Image, ImageParams>;
|
||||
using ImageManager = ResourceManager<Image, ImageParams>;
|
||||
using ImageSaver = ResourceSaver<Image, ImageParams>;
|
||||
|
||||
class NAZARA_CORE_API Image : public AbstractImage, public Resource
|
||||
{
|
||||
public:
|
||||
using Params = ImageParams;
|
||||
struct SharedImage;
|
||||
|
||||
Image();
|
||||
Image(ImageType type, PixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||
Image(SharedImage* sharedImage);
|
||||
Image(const Image& image);
|
||||
inline Image(Image&& image) noexcept;
|
||||
~Image();
|
||||
|
||||
bool Convert(PixelFormat format);
|
||||
|
||||
void Copy(const Image& source, const Boxui& srcBox, const Vector3ui& dstPos);
|
||||
|
||||
bool Create(ImageType type, PixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, UInt8 levelCount = 1);
|
||||
void Destroy();
|
||||
|
||||
bool Fill(const Color& color);
|
||||
bool Fill(const Color& color, const Boxui& box);
|
||||
bool Fill(const Color& color, const Rectui& rect, unsigned int z = 0);
|
||||
|
||||
bool FlipHorizontally();
|
||||
bool FlipVertically();
|
||||
|
||||
const UInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0) const;
|
||||
unsigned int GetDepth(UInt8 level = 0) const;
|
||||
PixelFormat GetFormat() const override;
|
||||
unsigned int GetHeight(UInt8 level = 0) const;
|
||||
UInt8 GetLevelCount() const override;
|
||||
UInt8 GetMaxLevel() const;
|
||||
std::size_t GetMemoryUsage() const;
|
||||
std::size_t GetMemoryUsage(UInt8 level) const;
|
||||
Color GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
|
||||
UInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0);
|
||||
Vector3ui GetSize(UInt8 level = 0) const override;
|
||||
ImageType GetType() const override;
|
||||
unsigned int GetWidth(UInt8 level = 0) const;
|
||||
|
||||
bool HasAlpha() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
// LoadFace
|
||||
bool LoadFaceFromFile(CubemapFace face, const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
|
||||
bool LoadFaceFromImage(CubemapFace face, const Image& image);
|
||||
bool LoadFaceFromMemory(CubemapFace face, const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||
bool LoadFaceFromStream(CubemapFace face, Stream& stream, const ImageParams& params = ImageParams());
|
||||
|
||||
// Save
|
||||
bool SaveToFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
|
||||
bool SaveToStream(Stream& stream, std::string_view format, const ImageParams& params = ImageParams());
|
||||
|
||||
//TODO: SaveArray, SaveCubemap, SaveFace
|
||||
|
||||
void SetLevelCount(UInt8 levelCount);
|
||||
bool SetPixelColor(const Color& color, unsigned int x, unsigned int y = 0, unsigned int z = 0);
|
||||
|
||||
using AbstractImage::Update;
|
||||
bool Update(const void* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||
|
||||
Image& operator=(const Image& image);
|
||||
inline Image& operator=(Image&& image) noexcept;
|
||||
|
||||
static inline void ArrayToRegion(ImageType type, unsigned int baseLayer, unsigned int layerCount, Boxui& region);
|
||||
static void Copy(UInt8* destination, const UInt8* source, PixelFormat format, 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 UInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
|
||||
static UInt8 GetMaxLevel(ImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
|
||||
static inline Boxui RegionToArray(ImageType type, Boxui region, unsigned int& baseLayer, unsigned int& layerCount);
|
||||
|
||||
// Load
|
||||
static std::shared_ptr<Image> LoadFromFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
|
||||
static std::shared_ptr<Image> LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams());
|
||||
static std::shared_ptr<Image> LoadFromStream(Stream& stream, const ImageParams& params = ImageParams());
|
||||
|
||||
// Load (array)
|
||||
static std::shared_ptr<Image> LoadFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams, const Vector2ui& atlasSize);
|
||||
static std::shared_ptr<Image> LoadFromImage(const Image& image, const Vector2ui& atlasSize);
|
||||
static std::shared_ptr<Image> LoadFromMemory(const void* data, std::size_t size, const ImageParams& imageParams, const Vector2ui& atlasSize);
|
||||
static std::shared_ptr<Image> LoadFromStream(Stream& stream, const ImageParams& imageParams, const Vector2ui& atlasSize);
|
||||
|
||||
// Load (cubemap)
|
||||
static std::shared_ptr<Image> LoadFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams, const CubemapParams& cubemapParams);
|
||||
static std::shared_ptr<Image> LoadFromImage(const Image& image, const CubemapParams& params);
|
||||
static std::shared_ptr<Image> LoadFromMemory(const void* data, std::size_t size, const ImageParams& imageParams, const CubemapParams& cubemapParams);
|
||||
static std::shared_ptr<Image> LoadFromStream(Stream& stream, const ImageParams& imageParams, const CubemapParams& cubemapParams);
|
||||
|
||||
struct SharedImage
|
||||
{
|
||||
using PixelContainer = std::vector<std::unique_ptr<UInt8[]>>;
|
||||
|
||||
SharedImage(unsigned short RefCount, ImageType Type, PixelFormat Format, PixelContainer&& Levels, unsigned int Width, unsigned int Height, unsigned int Depth) :
|
||||
type(Type),
|
||||
format(Format),
|
||||
levels(std::move(Levels)),
|
||||
depth(Depth),
|
||||
height(Height),
|
||||
width(Width),
|
||||
refCount(RefCount)
|
||||
{
|
||||
}
|
||||
|
||||
ImageType type;
|
||||
PixelFormat format;
|
||||
PixelContainer levels;
|
||||
unsigned int depth;
|
||||
unsigned int height;
|
||||
unsigned int width;
|
||||
|
||||
std::atomic_ushort refCount;
|
||||
};
|
||||
|
||||
static SharedImage emptyImage;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
void ReleaseImage();
|
||||
|
||||
SharedImage* m_sharedImage;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Image.inl>
|
||||
|
||||
#endif // NAZARA_CORE_IMAGE_HPP
|
||||
89
include/Nazara/Core/Image.inl
Normal file
89
include/Nazara/Core/Image.inl
Normal file
@@ -0,0 +1,89 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Image::Image(Image&& image) noexcept :
|
||||
m_sharedImage(std::exchange(image.m_sharedImage, &emptyImage))
|
||||
{
|
||||
}
|
||||
|
||||
inline Image& Image::operator=(Image&& image) noexcept
|
||||
{
|
||||
std::swap(m_sharedImage, image.m_sharedImage);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Image::ArrayToRegion(ImageType type, unsigned int baseLayer, unsigned int layerCount, Boxui& region)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ImageType::E1D_Array:
|
||||
region.y = baseLayer;
|
||||
region.height = layerCount;
|
||||
break;
|
||||
|
||||
case ImageType::Cubemap:
|
||||
case ImageType::E2D_Array:
|
||||
region.z = baseLayer;
|
||||
region.depth = layerCount;
|
||||
break;
|
||||
|
||||
case ImageType::E1D:
|
||||
NazaraAssert(baseLayer == 0, "out of bounds");
|
||||
NazaraAssert(layerCount <= 1, "out of bounds");
|
||||
[[fallthrough]];
|
||||
case ImageType::E2D:
|
||||
NazaraAssert(baseLayer == 0, "out of bounds");
|
||||
NazaraAssert(layerCount <= 1, "out of bounds");
|
||||
[[fallthrough]];
|
||||
case ImageType::E3D:
|
||||
region.z = 0;
|
||||
region.depth = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline Boxui Image::RegionToArray(ImageType type, Boxui region, unsigned int& baseLayer, unsigned int& layerCount)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ImageType::E1D_Array:
|
||||
baseLayer = region.y;
|
||||
layerCount = region.height;
|
||||
|
||||
region.y = 0;
|
||||
region.height = 1;
|
||||
break;
|
||||
|
||||
case ImageType::Cubemap:
|
||||
case ImageType::E2D_Array:
|
||||
baseLayer = region.z;
|
||||
layerCount = region.depth;
|
||||
|
||||
region.z = 0;
|
||||
region.depth = 1;
|
||||
break;
|
||||
|
||||
case ImageType::E1D:
|
||||
NazaraAssert(region.y == 0, "out of bounds");
|
||||
NazaraAssert(region.height <= 1, "out of bounds");
|
||||
case ImageType::E2D:
|
||||
NazaraAssert(region.z == 0, "out of bounds");
|
||||
NazaraAssert(region.depth <= 1, "out of bounds");
|
||||
case ImageType::E3D:
|
||||
baseLayer = 0;
|
||||
layerCount = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
57
include/Nazara/Core/ImageStream.hpp
Normal file
57
include/Nazara/Core/ImageStream.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_IMAGESTREAM_HPP
|
||||
#define NAZARA_CORE_IMAGESTREAM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <mutex>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct ImageStreamParams : public ResourceParameters
|
||||
{
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class ImageStream;
|
||||
|
||||
using ImageStreamLoader = ResourceLoader<ImageStream, ImageStreamParams>;
|
||||
|
||||
class NAZARA_CORE_API ImageStream : public Resource
|
||||
{
|
||||
public:
|
||||
using Params = ImageStreamParams;
|
||||
|
||||
ImageStream() = default;
|
||||
virtual ~ImageStream();
|
||||
|
||||
virtual bool DecodeNextFrame(void* frameBuffer, Time* frameTime) = 0;
|
||||
|
||||
virtual UInt64 GetFrameCount() const = 0;
|
||||
virtual PixelFormat GetPixelFormat() const = 0;
|
||||
virtual Vector2ui GetSize() const = 0;
|
||||
|
||||
virtual void Seek(UInt64 frameIndex) = 0;
|
||||
|
||||
virtual UInt64 Tell() = 0;
|
||||
|
||||
static std::shared_ptr<ImageStream> OpenFromFile(const std::filesystem::path& filePath, const ImageStreamParams& params = ImageStreamParams());
|
||||
static std::shared_ptr<ImageStream> OpenFromMemory(const void* data, std::size_t size, const ImageStreamParams& params = ImageStreamParams());
|
||||
static std::shared_ptr<ImageStream> OpenFromStream(Stream& stream, const ImageStreamParams& params = ImageStreamParams());
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ImageStream.inl>
|
||||
|
||||
#endif // NAZARA_CORE_IMAGESTREAM_HPP
|
||||
11
include/Nazara/Core/ImageStream.inl
Normal file
11
include/Nazara/Core/ImageStream.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
63
include/Nazara/Core/IndexBuffer.hpp
Normal file
63
include/Nazara/Core/IndexBuffer.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_INDEXBUFFER_HPP
|
||||
#define NAZARA_CORE_INDEXBUFFER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Buffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API IndexBuffer
|
||||
{
|
||||
public:
|
||||
IndexBuffer() = default;
|
||||
IndexBuffer(IndexType indexType, std::shared_ptr<Buffer> buffer);
|
||||
IndexBuffer(IndexType indexType, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||
IndexBuffer(IndexType indexType, UInt32 indexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||
IndexBuffer(const IndexBuffer&) = default;
|
||||
IndexBuffer(IndexBuffer&&) noexcept = default;
|
||||
~IndexBuffer() = default;
|
||||
|
||||
UInt64 ComputeCacheMissCount();
|
||||
|
||||
bool Fill(const void* data, UInt64 startIndex, UInt64 length);
|
||||
bool FillRaw(const void* data, UInt64 offset, UInt64 size);
|
||||
|
||||
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
||||
inline UInt64 GetEndOffset() const;
|
||||
inline UInt32 GetIndexCount() const;
|
||||
inline IndexType GetIndexType() const;
|
||||
inline UInt64 GetStride() const;
|
||||
inline UInt64 GetStartOffset() const;
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
||||
inline void* Map(UInt64 startIndex, UInt64 length);
|
||||
inline void* Map(UInt64 startIndex, UInt64 length) const;
|
||||
void* MapRaw(UInt64 offset, UInt64 size);
|
||||
void* MapRaw(UInt64 offset, UInt64 size) const;
|
||||
|
||||
void Optimize();
|
||||
|
||||
void Unmap() const;
|
||||
|
||||
IndexBuffer& operator=(const IndexBuffer&) = default;
|
||||
IndexBuffer& operator=(IndexBuffer&&) noexcept = default;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Buffer> m_buffer;
|
||||
IndexType m_indexType;
|
||||
UInt32 m_indexCount;
|
||||
UInt64 m_endOffset;
|
||||
UInt64 m_startOffset;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/IndexBuffer.inl>
|
||||
|
||||
#endif // NAZARA_CORE_INDEXBUFFER_HPP
|
||||
72
include/Nazara/Core/IndexBuffer.inl
Normal file
72
include/Nazara/Core/IndexBuffer.inl
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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 <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const std::shared_ptr<Buffer>& IndexBuffer::GetBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
inline UInt64 IndexBuffer::GetEndOffset() const
|
||||
{
|
||||
return m_endOffset;
|
||||
}
|
||||
|
||||
inline UInt32 IndexBuffer::GetIndexCount() const
|
||||
{
|
||||
return m_indexCount;
|
||||
}
|
||||
|
||||
inline IndexType IndexBuffer::GetIndexType() const
|
||||
{
|
||||
return m_indexType;
|
||||
}
|
||||
|
||||
inline UInt64 IndexBuffer::GetStride() const
|
||||
{
|
||||
switch (m_indexType)
|
||||
{
|
||||
case IndexType::U8:
|
||||
return sizeof(UInt8);
|
||||
|
||||
case IndexType::U16:
|
||||
return sizeof(UInt16);
|
||||
|
||||
case IndexType::U32:
|
||||
return sizeof(UInt32);
|
||||
}
|
||||
|
||||
NazaraError("invalid index size");
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline UInt64 IndexBuffer::GetStartOffset() const
|
||||
{
|
||||
return m_startOffset;
|
||||
}
|
||||
|
||||
inline bool IndexBuffer::IsValid() const
|
||||
{
|
||||
return m_buffer != nullptr;
|
||||
}
|
||||
|
||||
inline void* IndexBuffer::Map(UInt64 startIndex, UInt64 length)
|
||||
{
|
||||
UInt64 stride = GetStride();
|
||||
return MapRaw(startIndex * stride, length * stride);
|
||||
}
|
||||
|
||||
inline void* IndexBuffer::Map(UInt64 startIndex, UInt64 length) const
|
||||
{
|
||||
UInt64 stride = GetStride();
|
||||
return MapRaw(startIndex * stride, length * stride);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
82
include/Nazara/Core/IndexIterator.hpp
Normal file
82
include/Nazara/Core/IndexIterator.hpp
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_INDEXITERATOR_HPP
|
||||
#define NAZARA_CORE_INDEXITERATOR_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class IndexMapper;
|
||||
|
||||
class IndexIterator
|
||||
{
|
||||
friend IndexMapper;
|
||||
|
||||
public:
|
||||
class Reference;
|
||||
|
||||
IndexIterator();
|
||||
IndexIterator(const IndexIterator& iterator);
|
||||
~IndexIterator() = default;
|
||||
|
||||
Reference operator*() const;
|
||||
|
||||
Reference operator[](UInt32 index) const;
|
||||
|
||||
IndexIterator& operator=(const IndexIterator& iterator);
|
||||
|
||||
IndexIterator operator+(UInt32 indexCount) const;
|
||||
IndexIterator operator-(UInt32 indexCount) const;
|
||||
|
||||
IndexIterator& operator+=(UInt32 indexCount);
|
||||
IndexIterator& operator-=(UInt32 indexCount);
|
||||
|
||||
IndexIterator& operator++();
|
||||
IndexIterator operator++(int);
|
||||
|
||||
IndexIterator& operator--();
|
||||
IndexIterator operator--(int);
|
||||
|
||||
friend bool operator==(const IndexIterator& lhs, const IndexIterator& rhs);
|
||||
friend bool operator!=(const IndexIterator& lhs, const IndexIterator& rhs);
|
||||
friend bool operator<(const IndexIterator& lhs, const IndexIterator& rhs);
|
||||
friend bool operator<=(const IndexIterator& lhs, const IndexIterator& rhs);
|
||||
friend bool operator>(const IndexIterator& lhs, const IndexIterator& rhs);
|
||||
friend bool operator>=(const IndexIterator& lhs, const IndexIterator& rhs);
|
||||
|
||||
private:
|
||||
IndexIterator(IndexMapper* mapper, UInt32 index);
|
||||
|
||||
IndexMapper* m_mapper;
|
||||
UInt32 m_index;
|
||||
};
|
||||
|
||||
class IndexIterator::Reference
|
||||
{
|
||||
friend IndexIterator;
|
||||
|
||||
public:
|
||||
Reference(const Reference& reference) = default;
|
||||
~Reference() = default;
|
||||
|
||||
Reference& operator=(UInt32 value);
|
||||
Reference& operator=(const Reference& reference);
|
||||
|
||||
operator UInt32() const;
|
||||
|
||||
private:
|
||||
Reference(IndexMapper* mapper, UInt32 index);
|
||||
|
||||
IndexMapper* m_mapper;
|
||||
UInt32 m_index;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/IndexIterator.inl>
|
||||
|
||||
#endif // NAZARA_CORE_INDEXITERATOR_HPP
|
||||
175
include/Nazara/Core/IndexIterator.inl
Normal file
175
include/Nazara/Core/IndexIterator.inl
Normal file
@@ -0,0 +1,175 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/IndexMapper.hpp>
|
||||
#include <iterator>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline IndexIterator::IndexIterator() :
|
||||
m_mapper(nullptr),
|
||||
m_index(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline IndexIterator::IndexIterator(const IndexIterator& iterator) :
|
||||
m_mapper(iterator.m_mapper),
|
||||
m_index(iterator.m_index)
|
||||
{
|
||||
}
|
||||
|
||||
inline IndexIterator::IndexIterator(IndexMapper* mapper, UInt32 index) :
|
||||
m_mapper(mapper),
|
||||
m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
inline IndexIterator::Reference IndexIterator::operator*() const
|
||||
{
|
||||
return Reference(m_mapper, m_index);
|
||||
}
|
||||
|
||||
inline IndexIterator::Reference IndexIterator::operator[](UInt32 index) const
|
||||
{
|
||||
return Reference(m_mapper, m_index+index);
|
||||
}
|
||||
|
||||
inline IndexIterator& IndexIterator::operator=(const IndexIterator& iterator)
|
||||
{
|
||||
m_mapper = iterator.m_mapper;
|
||||
m_index = iterator.m_index;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IndexIterator IndexIterator::operator+(UInt32 indexCount) const
|
||||
{
|
||||
return IndexIterator(m_mapper, m_index + indexCount);
|
||||
}
|
||||
|
||||
inline IndexIterator IndexIterator::operator-(UInt32 indexCount) const
|
||||
{
|
||||
return IndexIterator(m_mapper, m_index - indexCount);
|
||||
}
|
||||
|
||||
inline IndexIterator& IndexIterator::operator+=(UInt32 indexCount)
|
||||
{
|
||||
m_index += indexCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IndexIterator& IndexIterator::operator-=(UInt32 indexCount)
|
||||
{
|
||||
m_index += indexCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IndexIterator& IndexIterator::operator++()
|
||||
{
|
||||
m_index++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IndexIterator IndexIterator::operator++(int)
|
||||
{
|
||||
IndexIterator iterator(*this);
|
||||
operator++();
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
inline IndexIterator& IndexIterator::operator--()
|
||||
{
|
||||
m_index--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IndexIterator IndexIterator::operator--(int)
|
||||
{
|
||||
IndexIterator iterator(*this);
|
||||
operator--();
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
inline bool operator==(const IndexIterator& lhs, const IndexIterator& rhs)
|
||||
{
|
||||
return lhs.m_mapper == rhs.m_mapper && lhs.m_index == rhs.m_index;
|
||||
}
|
||||
|
||||
inline bool operator!=(const IndexIterator& lhs, const IndexIterator& rhs)
|
||||
{
|
||||
return !operator==(lhs, rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const IndexIterator& lhs, const IndexIterator& rhs)
|
||||
{
|
||||
if (lhs.m_mapper == rhs.m_mapper)
|
||||
return lhs.m_index < rhs.m_index;
|
||||
else
|
||||
return lhs.m_mapper < rhs.m_mapper;
|
||||
}
|
||||
|
||||
inline bool operator<=(const IndexIterator& lhs, const IndexIterator& rhs)
|
||||
{
|
||||
return !operator<(rhs, lhs);
|
||||
}
|
||||
|
||||
inline bool operator>(const IndexIterator& lhs, const IndexIterator& rhs)
|
||||
{
|
||||
return operator<(rhs, lhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const IndexIterator& lhs, const IndexIterator& rhs)
|
||||
{
|
||||
return !operator<(lhs, rhs);
|
||||
}
|
||||
|
||||
/**************************IndexIterator::Reference*************************/
|
||||
|
||||
inline IndexIterator::Reference::Reference(IndexMapper* mapper, UInt32 index) :
|
||||
m_mapper(mapper),
|
||||
m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
inline IndexIterator::Reference& IndexIterator::Reference::operator=(UInt32 value)
|
||||
{
|
||||
m_mapper->Set(m_index, value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IndexIterator::Reference& IndexIterator::Reference::operator=(const IndexIterator::Reference& reference)
|
||||
{
|
||||
m_mapper->Set(m_index, reference); // Implicit conversion to UInt32
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline IndexIterator::Reference::operator UInt32() const
|
||||
{
|
||||
return m_mapper->Get(m_index);
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct iterator_traits<Nz::IndexIterator>
|
||||
{
|
||||
using difference_type = ptrdiff_t;
|
||||
using iterator_category = random_access_iterator_tag;
|
||||
using reference = const Nz::IndexIterator::Reference&;
|
||||
using pointer = const Nz::IndexIterator::Reference*;
|
||||
using value_type = Nz::IndexIterator::Reference;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
52
include/Nazara/Core/IndexMapper.hpp
Normal file
52
include/Nazara/Core/IndexMapper.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_INDEXMAPPER_HPP
|
||||
#define NAZARA_CORE_INDEXMAPPER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/BufferMapper.hpp>
|
||||
#include <Nazara/Core/IndexBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class IndexIterator;
|
||||
class SubMesh;
|
||||
|
||||
class NAZARA_CORE_API IndexMapper
|
||||
{
|
||||
public:
|
||||
IndexMapper(IndexBuffer& indexBuffer, UInt32 indexCount = 0);
|
||||
IndexMapper(SubMesh& subMesh);
|
||||
~IndexMapper() = default;
|
||||
|
||||
UInt32 Get(std::size_t i) const;
|
||||
const IndexBuffer* GetBuffer() const;
|
||||
UInt32 GetIndexCount() const;
|
||||
|
||||
void Set(std::size_t i, UInt32 value);
|
||||
|
||||
void Unmap();
|
||||
|
||||
// Méthodes STD
|
||||
IndexIterator begin();
|
||||
//IndexConstIterator begin() const;
|
||||
IndexIterator end();
|
||||
//IndexIterator end() const;
|
||||
// Méthodes STD
|
||||
|
||||
private:
|
||||
using Getter = UInt32(*)(const void* buffer, std::size_t i);
|
||||
using Setter = void(*)(void* buffer, std::size_t i, UInt32 value);
|
||||
|
||||
BufferMapper<IndexBuffer> m_mapper;
|
||||
Getter m_getter;
|
||||
Setter m_setter;
|
||||
UInt32 m_indexCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_INDEXMAPPER_HPP
|
||||
55
include/Nazara/Core/Joint.hpp
Normal file
55
include/Nazara/Core/Joint.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_JOINT_HPP
|
||||
#define NAZARA_CORE_JOINT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Node.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Skeleton;
|
||||
|
||||
class NAZARA_CORE_API Joint : public Node
|
||||
{
|
||||
public:
|
||||
inline Joint(Skeleton* skeleton);
|
||||
inline Joint(const Joint& joint);
|
||||
inline Joint(Joint&&) noexcept;
|
||||
~Joint() = default;
|
||||
|
||||
void EnsureSkinningMatrixUpdate() const;
|
||||
|
||||
const Matrix4f& GetInverseBindMatrix() const;
|
||||
const std::string& GetName() const;
|
||||
Skeleton* GetSkeleton();
|
||||
const Skeleton* GetSkeleton() const;
|
||||
const Matrix4f& GetSkinningMatrix() const;
|
||||
|
||||
void SetInverseBindMatrix(const Matrix4f& matrix);
|
||||
void SetName(std::string name);
|
||||
|
||||
inline Joint& operator=(const Joint& joint);
|
||||
inline Joint& operator=(Joint&& joint) noexcept;
|
||||
|
||||
private:
|
||||
void InvalidateNode(Invalidation invalidation) override;
|
||||
void UpdateSkinningMatrix() const;
|
||||
|
||||
Matrix4f m_inverseBindMatrix;
|
||||
mutable Matrix4f m_skinningMatrix;
|
||||
std::string m_name;
|
||||
Skeleton* m_skeleton;
|
||||
mutable bool m_skinningMatrixUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Joint.inl>
|
||||
|
||||
#endif // NAZARA_CORE_JOINT_HPP
|
||||
112
include/Nazara/Core/Joint.inl
Normal file
112
include/Nazara/Core/Joint.inl
Normal file
@@ -0,0 +1,112 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Skeleton.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Joint::Joint(Skeleton* skeleton) :
|
||||
m_skeleton(skeleton),
|
||||
m_skinningMatrixUpdated(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline Joint::Joint(const Joint& joint) :
|
||||
Node(joint),
|
||||
m_inverseBindMatrix(joint.m_inverseBindMatrix),
|
||||
m_name(joint.m_name),
|
||||
m_skeleton(joint.m_skeleton),
|
||||
m_skinningMatrixUpdated(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline Joint::Joint(Joint&& joint) noexcept :
|
||||
Node(std::move(joint)),
|
||||
m_inverseBindMatrix(joint.m_inverseBindMatrix),
|
||||
m_name(joint.m_name),
|
||||
m_skeleton(joint.m_skeleton),
|
||||
m_skinningMatrixUpdated(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline void Joint::EnsureSkinningMatrixUpdate() const
|
||||
{
|
||||
if (!m_skinningMatrixUpdated)
|
||||
UpdateSkinningMatrix();
|
||||
}
|
||||
|
||||
inline const Matrix4f& Joint::GetInverseBindMatrix() const
|
||||
{
|
||||
return m_inverseBindMatrix;
|
||||
}
|
||||
|
||||
inline const std::string& Joint::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
inline Skeleton* Joint::GetSkeleton()
|
||||
{
|
||||
return m_skeleton;
|
||||
}
|
||||
|
||||
inline const Skeleton* Joint::GetSkeleton() const
|
||||
{
|
||||
return m_skeleton;
|
||||
}
|
||||
|
||||
inline const Matrix4f& Joint::GetSkinningMatrix() const
|
||||
{
|
||||
EnsureSkinningMatrixUpdate();
|
||||
return m_skinningMatrix;
|
||||
}
|
||||
|
||||
inline void Joint::SetInverseBindMatrix(const Matrix4f& matrix)
|
||||
{
|
||||
m_inverseBindMatrix = matrix;
|
||||
m_skinningMatrixUpdated = false;
|
||||
}
|
||||
|
||||
inline void Joint::SetName(std::string name)
|
||||
{
|
||||
m_name = std::move(name);
|
||||
|
||||
m_skeleton->InvalidateJointMap();
|
||||
}
|
||||
|
||||
inline Joint& Joint::operator=(const Joint& joint)
|
||||
{
|
||||
Node::operator=(joint);
|
||||
|
||||
m_inverseBindMatrix = joint.m_inverseBindMatrix;
|
||||
m_name = joint.m_name;
|
||||
m_skeleton = joint.m_skeleton;
|
||||
m_skinningMatrixUpdated = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Joint& Joint::operator=(Joint&& joint) noexcept
|
||||
{
|
||||
Node::operator=(std::move(joint));
|
||||
|
||||
m_inverseBindMatrix = joint.m_inverseBindMatrix;
|
||||
m_name = joint.m_name;
|
||||
m_skeleton = joint.m_skeleton;
|
||||
m_skinningMatrixUpdated = false;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Joint::UpdateSkinningMatrix() const
|
||||
{
|
||||
EnsureTransformMatrixUpdate();
|
||||
|
||||
m_skinningMatrix = Matrix4f::ConcatenateTransform(m_inverseBindMatrix, m_transformMatrix);
|
||||
m_skinningMatrixUpdated = true;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
84
include/Nazara/Core/MaterialData.hpp
Normal file
84
include/Nazara/Core/MaterialData.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_MATERIALDATA_HPP
|
||||
#define NAZARA_CORE_MATERIALDATA_HPP
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct MaterialData
|
||||
{
|
||||
static constexpr const char* AlphaTest = "MatAlphaTest";
|
||||
static constexpr const char* AlphaTextureFilter = "MatAlphaTextureFilter";
|
||||
static constexpr const char* AlphaTexturePath = "MatAlphaTexturePath";
|
||||
static constexpr const char* AlphaTextureWrap = "MatAlphaWTexturerap";
|
||||
static constexpr const char* AlphaThreshold = "MatAlphaThreshold";
|
||||
static constexpr const char* AmbientColor = "MatAmbientColor";
|
||||
static constexpr const char* BackFaceStencilCompare = "MatBackFaceStencilCompare";
|
||||
static constexpr const char* BackFaceStencilFail = "MatBackFaceStencilFail";
|
||||
static constexpr const char* BackFaceStencilMask = "MatBackFaceStencilMask";
|
||||
static constexpr const char* BackFaceStencilPass = "MatBackFaceStencilPass";
|
||||
static constexpr const char* BackFaceStencilReference = "MatBackFaceStencilReference";
|
||||
static constexpr const char* BackFaceStencilZFail = "MatBackFaceStencilZFail";
|
||||
static constexpr const char* BaseColor = "MatBaseColor";
|
||||
static constexpr const char* BaseColorTextureFilter = "MatBaseColorTextureFilter";
|
||||
static constexpr const char* BaseColorTexturePath = "MatBaseColorTexturePath";
|
||||
static constexpr const char* BaseColorTextureWrap = "MatBaseColorTextureWrap";
|
||||
static constexpr const char* Blending = "MatBlending";
|
||||
static constexpr const char* BlendModeAlpha = "MatBlendModeAlpha";
|
||||
static constexpr const char* BlendModeColor = "MatBlendModeColor";
|
||||
static constexpr const char* BlendDstAlpha = "MatBlendDstAlpha";
|
||||
static constexpr const char* BlendDstColor = "MatBlendDstColor";
|
||||
static constexpr const char* BlendSrcAlpha = "MatBlendSrcAlpha";
|
||||
static constexpr const char* BlendSrcColor = "MatBlendSrcColor";
|
||||
static constexpr const char* CullingSide = "MatCullingSide";
|
||||
static constexpr const char* ColorWrite = "MatColorWrite";
|
||||
static constexpr const char* DepthBuffer = "MatDepthBuffer";
|
||||
static constexpr const char* DepthFunc = "MatDepthfunc";
|
||||
static constexpr const char* DepthSorting = "MatDepthSorting";
|
||||
static constexpr const char* DepthWrite = "MatDepthWrite";
|
||||
static constexpr const char* EmissiveTextureFilter = "MatEmissiveTextureFilter";
|
||||
static constexpr const char* EmissiveTexturePath = "MatEmissiveTexturePath";
|
||||
static constexpr const char* EmissiveTextureWrap = "MatEmissiveTextureWrap";
|
||||
static constexpr const char* FaceCulling = "MatFaceCulling";
|
||||
static constexpr const char* FaceFilling = "MatFaceFilling";
|
||||
static constexpr const char* FilePath = "MatFilePath";
|
||||
static constexpr const char* HeightTextureFilter = "MatHeightTextureFilter";
|
||||
static constexpr const char* HeightTexturePath = "MatHeightTexturePath";
|
||||
static constexpr const char* HeightTextureWrap = "MatHeightTextureWrap";
|
||||
static constexpr const char* LineWidth = "MatLineWidth";
|
||||
static constexpr const char* MetallicTextureFilter = "MatMetallicTextureFilter";
|
||||
static constexpr const char* MetallicTexturePath = "MatMetallicTexturePath";
|
||||
static constexpr const char* MetallicTextureWrap = "MatMetallicTextureWrap";
|
||||
static constexpr const char* Name = "MatName";
|
||||
static constexpr const char* NormalTextureFilter = "MatNormalTextureFilter";
|
||||
static constexpr const char* NormalTexturePath = "MatNormalTexturePath";
|
||||
static constexpr const char* NormalTextureWrap = "MatNormalTextureWrap";
|
||||
static constexpr const char* PointSize = "MatPointSize";
|
||||
static constexpr const char* RoughnessTextureFilter = "MatRoughnessTextureFilter";
|
||||
static constexpr const char* RoughnessTexturePath = "MatRoughnessTexturePath";
|
||||
static constexpr const char* RoughnessTextureWrap = "MatRoughnessTextureWrap";
|
||||
static constexpr const char* ScissorTest = "MatScissorTest";
|
||||
static constexpr const char* Shininess = "MatShininess";
|
||||
static constexpr const char* SpecularAnisotropyLevel = "MatSpecularAnisotropyLevel";
|
||||
static constexpr const char* SpecularColor = "MatSpecularColor";
|
||||
static constexpr const char* SpecularTextureFilter = "MatSpecularTextureFilter";
|
||||
static constexpr const char* SpecularTexturePath = "MatSpecularTexturePath";
|
||||
static constexpr const char* SpecularTextureWrap = "MatSpecularTextureWrap";
|
||||
static constexpr const char* StencilCompare = "MatStencilCompare";
|
||||
static constexpr const char* StencilFail = "MatStencilFail";
|
||||
static constexpr const char* StencilMask = "MatStencilMask";
|
||||
static constexpr const char* StencilPass = "MatStencilPass";
|
||||
static constexpr const char* StencilReference = "MatStencilReference";
|
||||
static constexpr const char* StencilTest = "MatStencilTest";
|
||||
static constexpr const char* StencilZFail = "MatStencilZFail";
|
||||
static constexpr const char* Transform = "MatTransform";
|
||||
static constexpr const char* Type = "MatType";
|
||||
static constexpr const char* VertexColor = "MatVertexColor";
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_MATERIALDATA_HPP
|
||||
192
include/Nazara/Core/Mesh.hpp
Normal file
192
include/Nazara/Core/Mesh.hpp
Normal file
@@ -0,0 +1,192 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_MESH_HPP
|
||||
#define NAZARA_CORE_MESH_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceLoader.hpp>
|
||||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/ResourceSaver.hpp>
|
||||
#include <Nazara/Core/Skeleton.hpp>
|
||||
#include <Nazara/Core/SoftwareBuffer.hpp>
|
||||
#include <Nazara/Core/SubMesh.hpp>
|
||||
#include <Nazara/Core/VertexDeclaration.hpp>
|
||||
#include <Nazara/Core/VertexStruct.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct NAZARA_CORE_API MeshParams : ResourceParameters
|
||||
{
|
||||
// How buffer will be allocated (by default in RAM)
|
||||
BufferFactory bufferFactory = &SoftwareBufferFactory;
|
||||
|
||||
// Buffer usage flags used to build the index buffers
|
||||
BufferUsageFlags indexBufferFlags = BufferUsage::DirectMapping | BufferUsage::Read | BufferUsage::Write;
|
||||
|
||||
// Buffer usage flags used to build the vertex buffers
|
||||
BufferUsageFlags vertexBufferFlags = BufferUsage::DirectMapping | BufferUsage::Read | BufferUsage::Write;
|
||||
|
||||
// Transform vertices and joints by these transformations
|
||||
Vector3f vertexOffset = Vector3f::Zero();
|
||||
|
||||
Quaternionf vertexRotation = Quaternionf::Identity();
|
||||
|
||||
Vector3f vertexScale = Vector3f::Unit();
|
||||
|
||||
// Offset to apply on the texture coordinates (not scaled)
|
||||
Vector2f texCoordOffset = {0.f, 0.f};
|
||||
|
||||
// Scale to apply on the texture coordinates
|
||||
Vector2f texCoordScale = {1.f, 1.f};
|
||||
|
||||
// If true, will load an animated version of the model if possible
|
||||
bool animated = true;
|
||||
|
||||
// If true, will center the mesh vertices around the origin
|
||||
bool center = false;
|
||||
|
||||
// Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
|
||||
#ifndef NAZARA_DEBUG
|
||||
bool optimizeIndexBuffers = true;
|
||||
#else
|
||||
bool optimizeIndexBuffers = false;
|
||||
#endif
|
||||
|
||||
/* The declaration must have a Vector3f position component enabled
|
||||
* If the declaration has a Vector2f UV component enabled, UV are generated
|
||||
* If the declaration has a Vector3f Normals component enabled, Normals are generated.
|
||||
* If the declaration has a Vector3f Tangents component enabled, Tangents are generated.
|
||||
*/
|
||||
std::shared_ptr<VertexDeclaration> vertexDeclaration = VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent);
|
||||
|
||||
bool IsValid() const;
|
||||
};
|
||||
|
||||
class Mesh;
|
||||
struct Primitive;
|
||||
class PrimitiveList;
|
||||
class StaticMesh;
|
||||
class SubMesh;
|
||||
|
||||
using MeshVertex = VertexStruct_XYZ_Normal_UV_Tangent;
|
||||
using SkeletalMeshVertex = VertexStruct_XYZ_Normal_UV_Tangent_Skinning;
|
||||
|
||||
using MeshLibrary = ObjectLibrary<Mesh>;
|
||||
using MeshLoader = ResourceLoader<Mesh, MeshParams>;
|
||||
using MeshManager = ResourceManager<Mesh, MeshParams>;
|
||||
using MeshSaver = ResourceSaver<Mesh, MeshParams>;
|
||||
|
||||
struct MeshImpl;
|
||||
|
||||
class NAZARA_CORE_API Mesh : public Resource
|
||||
{
|
||||
public:
|
||||
using Params = MeshParams;
|
||||
|
||||
inline Mesh();
|
||||
Mesh(const Mesh&) = delete;
|
||||
Mesh(Mesh&&) = delete;
|
||||
~Mesh() = default;
|
||||
|
||||
void AddSubMesh(std::shared_ptr<SubMesh> subMesh);
|
||||
void AddSubMesh(std::string identifier, std::shared_ptr<SubMesh> subMesh);
|
||||
|
||||
std::shared_ptr<SubMesh> BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams());
|
||||
void BuildSubMeshes(const PrimitiveList& primitiveList, const MeshParams& params = MeshParams());
|
||||
|
||||
bool CreateSkeletal(std::size_t jointCount);
|
||||
bool CreateStatic();
|
||||
void Destroy();
|
||||
|
||||
void GenerateNormals();
|
||||
void GenerateNormalsAndTangents();
|
||||
void GenerateTangents();
|
||||
|
||||
const Boxf& GetAABB() const;
|
||||
std::filesystem::path GetAnimation() const;
|
||||
AnimationType GetAnimationType() const;
|
||||
std::size_t GetJointCount() const;
|
||||
ParameterList& GetMaterialData(std::size_t index);
|
||||
const ParameterList& GetMaterialData(std::size_t index) const;
|
||||
std::size_t GetMaterialCount() const;
|
||||
Skeleton* GetSkeleton();
|
||||
const Skeleton* GetSkeleton() const;
|
||||
const std::shared_ptr<SubMesh>& GetSubMesh(std::string_view identifier) const;
|
||||
const std::shared_ptr<SubMesh>& GetSubMesh(std::size_t index) const;
|
||||
std::size_t GetSubMeshCount() const;
|
||||
std::size_t GetSubMeshIndex(std::string_view identifier) const;
|
||||
UInt32 GetTriangleCount() const;
|
||||
UInt32 GetVertexCount() const;
|
||||
|
||||
bool HasSubMesh(std::string_view identifier) const;
|
||||
bool HasSubMesh(std::size_t index = 0) const;
|
||||
|
||||
void InvalidateAABB() const;
|
||||
|
||||
bool IsAnimable() const;
|
||||
bool IsValid() const;
|
||||
|
||||
void Recenter();
|
||||
|
||||
void RemoveSubMesh(std::string_view identifier);
|
||||
void RemoveSubMesh(std::size_t index);
|
||||
|
||||
bool SaveToFile(const std::filesystem::path& filePath, const MeshParams& params = MeshParams());
|
||||
bool SaveToStream(Stream& stream, std::string_view format, const MeshParams& params = MeshParams());
|
||||
|
||||
void SetAnimation(const std::filesystem::path& animationPath);
|
||||
void SetMaterialCount(std::size_t matCount);
|
||||
void SetMaterialData(std::size_t matIndex, ParameterList data);
|
||||
|
||||
void Transform(const Matrix4f& matrix);
|
||||
|
||||
Mesh& operator=(const Mesh&) = delete;
|
||||
Mesh& operator=(Mesh&&) = delete;
|
||||
|
||||
static inline std::shared_ptr<Mesh> Build(std::shared_ptr<StaticMesh> staticMesh);
|
||||
static inline std::shared_ptr<Mesh> Build(const Primitive& primitive, const MeshParams& params = MeshParams());
|
||||
static inline std::shared_ptr<Mesh> Build(const PrimitiveList& primitiveList, const MeshParams& params = MeshParams());
|
||||
|
||||
static std::shared_ptr<Mesh> LoadFromFile(const std::filesystem::path& filePath, const MeshParams& params = MeshParams());
|
||||
static std::shared_ptr<Mesh> LoadFromMemory(const void* data, std::size_t size, const MeshParams& params = MeshParams());
|
||||
static std::shared_ptr<Mesh> LoadFromStream(Stream& stream, const MeshParams& params = MeshParams());
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnMeshInvalidateAABB, const Mesh* /*mesh*/);
|
||||
|
||||
private:
|
||||
struct SubMeshData
|
||||
{
|
||||
std::shared_ptr<SubMesh> subMesh;
|
||||
|
||||
NazaraSlot(SubMesh, OnSubMeshInvalidateAABB, onSubMeshInvalidated);
|
||||
};
|
||||
|
||||
std::size_t m_jointCount; // Only used by skeletal meshes
|
||||
std::unordered_map<std::string, std::size_t, StringHash<>, std::equal_to<>> m_subMeshMap;
|
||||
std::vector<ParameterList> m_materialData;
|
||||
std::vector<SubMeshData> m_subMeshes;
|
||||
AnimationType m_animationType;
|
||||
mutable Boxf m_aabb;
|
||||
Skeleton m_skeleton; // Only used by skeletal meshes
|
||||
std::filesystem::path m_animationPath;
|
||||
mutable bool m_aabbUpdated;
|
||||
bool m_isValid;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Mesh.inl>
|
||||
|
||||
#endif // NAZARA_CORE_MESH_HPP
|
||||
46
include/Nazara/Core/Mesh.inl
Normal file
46
include/Nazara/Core/Mesh.inl
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/StaticMesh.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Mesh::Mesh() :
|
||||
m_materialData(1),
|
||||
m_aabbUpdated(false),
|
||||
m_isValid(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline std::shared_ptr<Mesh> Mesh::Build(std::shared_ptr<StaticMesh> staticMesh)
|
||||
{
|
||||
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
|
||||
mesh->CreateStatic();
|
||||
mesh->AddSubMesh(std::move(staticMesh));
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
inline std::shared_ptr<Mesh> Mesh::Build(const Primitive& primitive, const MeshParams& params)
|
||||
{
|
||||
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
|
||||
mesh->CreateStatic();
|
||||
mesh->BuildSubMesh(primitive, params);
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
inline std::shared_ptr<Mesh> Mesh::Build(const PrimitiveList& primitiveList, const MeshParams& params)
|
||||
{
|
||||
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
|
||||
mesh->CreateStatic();
|
||||
mesh->BuildSubMeshes(primitiveList, params);
|
||||
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
25
include/Nazara/Core/MeshData.hpp
Normal file
25
include/Nazara/Core/MeshData.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_MESHDATA_HPP
|
||||
#define NAZARA_CORE_MESHDATA_HPP
|
||||
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class IndexBuffer;
|
||||
class VertexBuffer;
|
||||
|
||||
struct MeshData
|
||||
{
|
||||
PrimitiveMode primitiveMode;
|
||||
const IndexBuffer* indexBuffer;
|
||||
const VertexBuffer* vertexBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_MESHDATA_HPP
|
||||
146
include/Nazara/Core/Node.hpp
Normal file
146
include/Nazara/Core/Node.hpp
Normal file
@@ -0,0 +1,146 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_NODE_HPP
|
||||
#define NAZARA_CORE_NODE_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API Node
|
||||
{
|
||||
public:
|
||||
enum class Invalidation;
|
||||
|
||||
inline Node(const Vector3f& translation = Vector3f::Zero(), const Quaternionf& rotation = Quaternionf::Identity(), const Vector3f& scale = Vector3f::Unit());
|
||||
inline Node(const Node& node);
|
||||
inline Node(Node&& node) noexcept;
|
||||
virtual ~Node();
|
||||
|
||||
inline void EnsureDerivedUpdate() const;
|
||||
inline void EnsureTransformMatrixUpdate() const;
|
||||
|
||||
inline Vector3f GetBackward() const;
|
||||
inline const std::vector<Node*>& GetChilds() const;
|
||||
inline Vector3f GetDown() const;
|
||||
inline Vector3f GetForward() const;
|
||||
inline bool GetInheritPosition() const;
|
||||
inline bool GetInheritRotation() const;
|
||||
inline bool GetInheritScale() const;
|
||||
inline Vector3f GetInitialPosition() const;
|
||||
inline Quaternionf GetInitialRotation() const;
|
||||
inline Vector3f GetInitialScale() const;
|
||||
inline Vector3f GetLeft() const;
|
||||
inline const Node* GetParent() const;
|
||||
inline Vector3f GetPosition(CoordSys coordSys = CoordSys::Local) const;
|
||||
inline Vector3f GetRight() const;
|
||||
inline Quaternionf GetRotation(CoordSys coordSys = CoordSys::Local) const;
|
||||
inline Vector3f GetScale(CoordSys coordSys = CoordSys::Local) const;
|
||||
inline const Matrix4f& GetTransformMatrix() const;
|
||||
inline Vector3f GetUp() const;
|
||||
|
||||
inline bool HasChilds() const;
|
||||
|
||||
inline void Invalidate(Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
|
||||
Node& Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, CoordSys coordSys = CoordSys::Global, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
|
||||
Node& Move(const Vector3f& movement, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline Node& Move(float movementX, float movementY, float movementZ = 0.f, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
|
||||
Node& Rotate(const Quaternionf& rotation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
|
||||
inline Node& Scale(const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline Node& Scale(float scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline Node& Scale(float scaleX, float scaleY, float scaleZ = 1.f, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
|
||||
inline void SetInheritPosition(bool inheritPosition, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInheritRotation(bool inheritRotation, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInheritScale(bool inheritScale, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInitialPosition(const Vector3f& translation, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInitialPosition(float translationX, float translationXY, float translationZ = 0.f, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInitialRotation(const Quaternionf& quat, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInitialScale(const Vector3f& scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInitialScale(float scale, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetInitialScale(float scaleX, float scaleY, float scaleZ = 1.f, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
void SetParent(const Node* node = nullptr, bool keepDerived = false, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
void SetParent(const Node& node, bool keepDerived = false, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
void SetPosition(const Vector3f& translation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetPosition(float translationX, float translationY, float translationZ = 0.f, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
void SetRotation(const Quaternionf& rotation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetScale(const Vector2f& scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
void SetScale(const Vector3f& scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetScale(float scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetScale(float scaleX, float scaleY, float scaleZ = 1.f, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
void SetTransform(const Vector3f& position, const Quaternionf& rotation, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
void SetTransform(const Vector3f& position, const Quaternionf& rotation, const Vector3f& scale, CoordSys coordSys = CoordSys::Local, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
inline void SetTransformMatrix(const Matrix4f& matrix, Invalidation invalidation = Invalidation::InvalidateRecursively);
|
||||
|
||||
// Local -> global
|
||||
inline Vector3f ToGlobalPosition(const Vector3f& localPosition) const;
|
||||
inline Quaternionf ToGlobalRotation(const Quaternionf& localRotation) const;
|
||||
inline Vector3f ToGlobalScale(const Vector3f& localScale) const;
|
||||
|
||||
// Global -> local
|
||||
inline Vector3f ToLocalPosition(const Vector3f& globalPosition) const;
|
||||
inline Quaternionf ToLocalRotation(const Quaternionf& globalRotation) const;
|
||||
inline Vector3f ToLocalScale(const Vector3f& globalScale) const;
|
||||
|
||||
inline Node& operator=(const Node& node);
|
||||
inline Node& operator=(Node&& node) noexcept;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnNodeInvalidation, const Node* /*node*/);
|
||||
NazaraSignal(OnNodeNewParent, const Node* /*node*/, const Node* /*parent*/);
|
||||
NazaraSignal(OnNodeRelease, const Node* /*node*/);
|
||||
|
||||
enum class Invalidation
|
||||
{
|
||||
InvalidateRecursively,
|
||||
InvalidateNodeOnly,
|
||||
DontInvalidate
|
||||
};
|
||||
|
||||
protected:
|
||||
inline void AddChild(Node* node) const;
|
||||
virtual void InvalidateNode(Invalidation invalidation);
|
||||
virtual void OnParenting(const Node* parent);
|
||||
inline void RemoveChild(Node* node) const;
|
||||
virtual void UpdateDerived() const;
|
||||
virtual void UpdateTransformMatrix() const;
|
||||
|
||||
mutable std::vector<Node*> m_childs;
|
||||
mutable Matrix4f m_transformMatrix;
|
||||
mutable Quaternionf m_derivedRotation;
|
||||
Quaternionf m_initialRotation;
|
||||
Quaternionf m_rotation;
|
||||
mutable Vector3f m_derivedPosition;
|
||||
mutable Vector3f m_derivedScale;
|
||||
Vector3f m_initialPosition;
|
||||
Vector3f m_initialScale;
|
||||
Vector3f m_position;
|
||||
Vector3f m_scale;
|
||||
const Node* m_parent;
|
||||
mutable bool m_derivedUpdated;
|
||||
bool m_inheritPosition;
|
||||
bool m_inheritRotation;
|
||||
bool m_inheritScale;
|
||||
mutable bool m_transformMatrixUpdated;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Node.inl>
|
||||
|
||||
#endif // NAZARA_CORE_NODE_HPP
|
||||
487
include/Nazara/Core/Node.inl
Normal file
487
include/Nazara/Core/Node.inl
Normal file
@@ -0,0 +1,487 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Algorithm.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Node::Node(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) :
|
||||
m_initialRotation(Quaternionf::Identity()),
|
||||
m_rotation(rotation),
|
||||
m_initialPosition(Vector3f::Zero()),
|
||||
m_initialScale(Vector3f(1.f, 1.f, 1.f)),
|
||||
m_position(translation),
|
||||
m_scale(scale),
|
||||
m_parent(nullptr),
|
||||
m_derivedUpdated(false),
|
||||
m_inheritPosition(true),
|
||||
m_inheritRotation(true),
|
||||
m_inheritScale(true),
|
||||
m_transformMatrixUpdated(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline Node::Node(const Node& node) :
|
||||
m_initialRotation(node.m_initialRotation),
|
||||
m_rotation(node.m_rotation),
|
||||
m_initialPosition(node.m_initialPosition),
|
||||
m_initialScale(node.m_initialScale),
|
||||
m_position(node.m_position),
|
||||
m_scale(node.m_scale),
|
||||
m_parent(nullptr),
|
||||
m_derivedUpdated(false),
|
||||
m_inheritPosition(node.m_inheritPosition),
|
||||
m_inheritRotation(node.m_inheritRotation),
|
||||
m_inheritScale(node.m_inheritScale),
|
||||
m_transformMatrixUpdated(false)
|
||||
{
|
||||
SetParent(node.m_parent, false);
|
||||
}
|
||||
|
||||
inline Node::Node(Node&& node) noexcept :
|
||||
OnNodeInvalidation(std::move(node.OnNodeInvalidation)),
|
||||
OnNodeNewParent(std::move(node.OnNodeNewParent)),
|
||||
OnNodeRelease(std::move(node.OnNodeRelease)),
|
||||
m_childs(std::move(node.m_childs)),
|
||||
m_initialRotation(node.m_initialRotation),
|
||||
m_rotation(node.m_rotation),
|
||||
m_initialPosition(node.m_initialPosition),
|
||||
m_initialScale(node.m_initialScale),
|
||||
m_position(node.m_position),
|
||||
m_scale(node.m_scale),
|
||||
m_parent(node.m_parent),
|
||||
m_derivedUpdated(false),
|
||||
m_inheritPosition(node.m_inheritPosition),
|
||||
m_inheritRotation(node.m_inheritRotation),
|
||||
m_inheritScale(node.m_inheritScale),
|
||||
m_transformMatrixUpdated(false)
|
||||
{
|
||||
if (m_parent)
|
||||
{
|
||||
m_parent->RemoveChild(&node);
|
||||
m_parent->AddChild(this);
|
||||
node.m_parent = nullptr;
|
||||
}
|
||||
|
||||
for (Node* child : m_childs)
|
||||
child->m_parent = this;
|
||||
}
|
||||
|
||||
inline void Node::EnsureDerivedUpdate() const
|
||||
{
|
||||
if (!m_derivedUpdated)
|
||||
UpdateDerived();
|
||||
}
|
||||
|
||||
inline void Node::EnsureTransformMatrixUpdate() const
|
||||
{
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetBackward() const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation * Vector3f::Backward();
|
||||
}
|
||||
|
||||
inline const std::vector<Node*>& Node::GetChilds() const
|
||||
{
|
||||
return m_childs;
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetDown() const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation * Vector3f::Down();
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetForward() const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation * Vector3f::Forward();
|
||||
}
|
||||
|
||||
inline bool Node::GetInheritPosition() const
|
||||
{
|
||||
return m_inheritPosition;
|
||||
}
|
||||
|
||||
inline bool Node::GetInheritRotation() const
|
||||
{
|
||||
return m_inheritRotation;
|
||||
}
|
||||
|
||||
inline bool Node::GetInheritScale() const
|
||||
{
|
||||
return m_inheritScale;
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetInitialPosition() const
|
||||
{
|
||||
return m_initialPosition;
|
||||
}
|
||||
|
||||
inline Quaternionf Node::GetInitialRotation() const
|
||||
{
|
||||
return m_initialRotation;
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetInitialScale() const
|
||||
{
|
||||
return m_initialScale;
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetLeft() const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation * Vector3f::Left();
|
||||
}
|
||||
|
||||
inline const Node* Node::GetParent() const
|
||||
{
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetPosition(CoordSys coordSys) const
|
||||
{
|
||||
switch (coordSys)
|
||||
{
|
||||
case CoordSys::Global:
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedPosition;
|
||||
|
||||
case CoordSys::Local:
|
||||
return m_position;
|
||||
}
|
||||
|
||||
NazaraErrorFmt("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
|
||||
return Vector3f();
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetRight() const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation * Vector3f::Right();
|
||||
}
|
||||
|
||||
inline Quaternionf Node::GetRotation(CoordSys coordSys) const
|
||||
{
|
||||
switch (coordSys)
|
||||
{
|
||||
case CoordSys::Global:
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation;
|
||||
|
||||
case CoordSys::Local:
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
NazaraErrorFmt("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
|
||||
return Quaternionf();
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetScale(CoordSys coordSys) const
|
||||
{
|
||||
switch (coordSys)
|
||||
{
|
||||
case CoordSys::Global:
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedScale;
|
||||
|
||||
case CoordSys::Local:
|
||||
return m_scale;
|
||||
}
|
||||
|
||||
NazaraErrorFmt("Coordinate system out of enum ({0:#x})", UnderlyingCast(coordSys));
|
||||
return Vector3f();
|
||||
}
|
||||
|
||||
inline const Matrix4f& Node::GetTransformMatrix() const
|
||||
{
|
||||
EnsureTransformMatrixUpdate();
|
||||
return m_transformMatrix;
|
||||
}
|
||||
|
||||
inline Vector3f Node::GetUp() const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation * Vector3f::Up();
|
||||
}
|
||||
|
||||
inline bool Node::HasChilds() const
|
||||
{
|
||||
return !m_childs.empty();
|
||||
}
|
||||
|
||||
inline void Node::Invalidate(Invalidation invalidation)
|
||||
{
|
||||
if (invalidation != Invalidation::DontInvalidate)
|
||||
InvalidateNode(invalidation);
|
||||
}
|
||||
|
||||
inline Node& Node::Move(float moveX, float moveY, float moveZ, CoordSys coordSys, Invalidation invalidation)
|
||||
{
|
||||
return Move(Vector3f(moveX, moveY, moveZ), coordSys, invalidation);
|
||||
}
|
||||
|
||||
inline Node& Node::Scale(const Vector3f& scale, Invalidation invalidation)
|
||||
{
|
||||
m_scale *= scale;
|
||||
|
||||
Invalidate(invalidation);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Node& Node::Scale(float scale, Invalidation invalidation)
|
||||
{
|
||||
m_scale *= scale;
|
||||
|
||||
Invalidate(invalidation);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Node& Node::Scale(float scaleX, float scaleY, float scaleZ, Invalidation invalidation)
|
||||
{
|
||||
m_scale.x *= scaleX;
|
||||
m_scale.y *= scaleY;
|
||||
m_scale.z *= scaleZ;
|
||||
|
||||
Invalidate(invalidation);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::SetInheritPosition(bool inheritPosition, Invalidation invalidation)
|
||||
{
|
||||
///DOC: Un appel redondant est sans effet
|
||||
if (m_inheritPosition != inheritPosition)
|
||||
{
|
||||
m_inheritPosition = inheritPosition;
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Node::SetInheritRotation(bool inheritRotation, Invalidation invalidation)
|
||||
{
|
||||
///DOC: Un appel redondant est sans effet
|
||||
if (m_inheritRotation != inheritRotation)
|
||||
{
|
||||
m_inheritRotation = inheritRotation;
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Node::SetInheritScale(bool inheritScale, Invalidation invalidation)
|
||||
{
|
||||
///DOC: Un appel redondant est sans effet
|
||||
if (m_inheritScale != inheritScale)
|
||||
{
|
||||
m_inheritScale = inheritScale;
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Node::SetInitialPosition(const Vector3f& position, Invalidation invalidation)
|
||||
{
|
||||
m_initialPosition = position;
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetInitialPosition(float positionX, float positionY, float positionZ, Invalidation invalidation)
|
||||
{
|
||||
m_initialPosition = Vector3f(positionX, positionY, positionZ);
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetInitialRotation(const Quaternionf& rotation, Invalidation invalidation)
|
||||
{
|
||||
m_initialRotation = rotation;
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetInitialScale(const Vector3f& scale, Invalidation invalidation)
|
||||
{
|
||||
m_initialScale = scale;
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetInitialScale(float scale, Invalidation invalidation)
|
||||
{
|
||||
m_initialScale = Vector3f(scale);
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetInitialScale(float scaleX, float scaleY, float scaleZ, Invalidation invalidation)
|
||||
{
|
||||
m_initialScale = Vector3f(scaleX, scaleY, scaleZ);
|
||||
|
||||
Invalidate(invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetParent(const Node& node, bool keepDerived, Invalidation invalidation)
|
||||
{
|
||||
SetParent(&node, keepDerived, invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetPosition(float positionX, float positionY, float positionZ, CoordSys coordSys, Invalidation invalidation)
|
||||
{
|
||||
SetPosition(Vector3f(positionX, positionY, positionZ), coordSys, invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetScale(const Vector2f& scale, CoordSys coordSys, Invalidation invalidation)
|
||||
{
|
||||
// Prevent Z scale at zero (can happen when using SetScale with a Vec2)
|
||||
SetScale(scale.x, scale.y, 1.f, coordSys, invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetScale(float scale, CoordSys coordSys, Invalidation invalidation)
|
||||
{
|
||||
SetScale(Vector3f(scale), coordSys, invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetScale(float scaleX, float scaleY, float scaleZ, CoordSys coordSys, Invalidation invalidation)
|
||||
{
|
||||
SetScale(Vector3f(scaleX, scaleY, scaleZ), coordSys, invalidation);
|
||||
}
|
||||
|
||||
inline void Node::SetTransformMatrix(const Matrix4f& matrix, Invalidation invalidation)
|
||||
{
|
||||
SetPosition(matrix.GetTranslation(), CoordSys::Global, Invalidation::DontInvalidate);
|
||||
SetRotation(matrix.GetRotation(), CoordSys::Global, Invalidation::DontInvalidate);
|
||||
SetScale(matrix.GetScale(), CoordSys::Global, Invalidation::DontInvalidate);
|
||||
|
||||
Invalidate(invalidation);
|
||||
|
||||
m_transformMatrix = matrix;
|
||||
m_transformMatrixUpdated = true;
|
||||
}
|
||||
|
||||
inline Vector3f Node::ToGlobalPosition(const Vector3f& localPosition) const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return TransformPositionTRS(m_derivedPosition, m_derivedRotation, m_derivedScale, localPosition);
|
||||
}
|
||||
|
||||
inline Quaternionf Node::ToGlobalRotation(const Quaternionf& localRotation) const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return TransformRotationTRS(m_derivedRotation, m_derivedScale, localRotation);
|
||||
}
|
||||
|
||||
inline Vector3f Node::ToGlobalScale(const Vector3f& localScale) const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return TransformScaleTRS(m_derivedScale, localScale);
|
||||
}
|
||||
|
||||
inline Vector3f Node::ToLocalPosition(const Vector3f& globalPosition) const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation.GetConjugate() * (globalPosition - m_derivedPosition) / m_derivedScale;
|
||||
}
|
||||
|
||||
inline Quaternionf Node::ToLocalRotation(const Quaternionf& globalRotation) const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return m_derivedRotation.GetConjugate() * globalRotation;
|
||||
}
|
||||
|
||||
inline Vector3f Node::ToLocalScale(const Vector3f& globalScale) const
|
||||
{
|
||||
EnsureDerivedUpdate();
|
||||
return globalScale / m_derivedScale;
|
||||
}
|
||||
|
||||
inline Node& Node::operator=(const Node& node)
|
||||
{
|
||||
SetParent(node.m_parent, false, Invalidation::DontInvalidate);
|
||||
|
||||
m_inheritPosition = node.m_inheritPosition;
|
||||
m_inheritRotation = node.m_inheritRotation;
|
||||
m_inheritScale = node.m_inheritScale;
|
||||
m_initialPosition = node.m_initialPosition;
|
||||
m_initialRotation = node.m_initialRotation;
|
||||
m_initialScale = node.m_initialScale;
|
||||
m_position = node.m_position;
|
||||
m_rotation = node.m_rotation;
|
||||
m_scale = node.m_scale;
|
||||
|
||||
InvalidateNode(Invalidation::InvalidateRecursively);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Node& Node::operator=(Node&& node) noexcept
|
||||
{
|
||||
if (m_parent)
|
||||
SetParent(nullptr);
|
||||
|
||||
m_inheritPosition = node.m_inheritPosition;
|
||||
m_inheritRotation = node.m_inheritRotation;
|
||||
m_inheritScale = node.m_inheritScale;
|
||||
m_initialPosition = node.m_initialPosition;
|
||||
m_initialRotation = node.m_initialRotation;
|
||||
m_initialScale = node.m_initialScale;
|
||||
m_position = node.m_position;
|
||||
m_rotation = node.m_rotation;
|
||||
m_scale = node.m_scale;
|
||||
|
||||
m_childs = std::move(node.m_childs);
|
||||
for (Node* child : m_childs)
|
||||
child->m_parent = this;
|
||||
|
||||
m_parent = node.m_parent;
|
||||
if (m_parent)
|
||||
{
|
||||
m_parent->RemoveChild(&node);
|
||||
m_parent->AddChild(this);
|
||||
node.m_parent = nullptr;
|
||||
}
|
||||
|
||||
OnNodeInvalidation = std::move(node.OnNodeInvalidation);
|
||||
OnNodeNewParent = std::move(node.OnNodeNewParent);
|
||||
OnNodeRelease = std::move(node.OnNodeRelease);
|
||||
|
||||
InvalidateNode(Invalidation::InvalidateRecursively);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void Node::AddChild(Node* node) const
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (std::find(m_childs.begin(), m_childs.end(), node) != m_childs.end())
|
||||
{
|
||||
NazaraWarning("Child node is already a child of parent node");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_childs.push_back(node);
|
||||
}
|
||||
|
||||
inline void Node::RemoveChild(Node* node) const
|
||||
{
|
||||
auto it = std::find(m_childs.begin(), m_childs.end(), node);
|
||||
if (it != m_childs.end())
|
||||
m_childs.erase(it);
|
||||
else
|
||||
NazaraWarning("Child not found");
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -7,8 +7,8 @@
|
||||
#ifndef NAZARA_CORE_OBJECTHANDLE_HPP
|
||||
#define NAZARA_CORE_OBJECTHANDLE_HPP
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <NazaraUtils/TypeTraits.hpp>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
#define NAZARA_CORE_OBJECTREF_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <type_traits>
|
||||
#include <NazaraUtils/TypeTraits.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
101
include/Nazara/Core/PixelFormat.hpp
Normal file
101
include/Nazara/Core/PixelFormat.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_PIXELFORMAT_HPP
|
||||
#define NAZARA_CORE_PIXELFORMAT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NazaraUtils/Bitset.hpp>
|
||||
#include <NazaraUtils/EnumArray.hpp>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
|
||||
///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îtra donc pas) mais ça permettrait au moteur de faire la conversion
|
||||
/// entre n'importe quels formats non-compressés.
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct PixelFormatDescription
|
||||
{
|
||||
inline PixelFormatDescription();
|
||||
inline PixelFormatDescription(PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
inline bool IsCompressed() const;
|
||||
inline bool IsValid() const;
|
||||
|
||||
inline void RecomputeBitsPerPixel();
|
||||
|
||||
inline bool Validate() const;
|
||||
|
||||
std::string_view name;
|
||||
// Warning: Masks bit order is reversed
|
||||
Bitset<> redMask;
|
||||
Bitset<> greenMask;
|
||||
Bitset<> blueMask;
|
||||
Bitset<> alphaMask;
|
||||
PixelFormatContent content;
|
||||
PixelFormatSubType redType;
|
||||
PixelFormatSubType greenType;
|
||||
PixelFormatSubType blueType;
|
||||
PixelFormatSubType alphaType;
|
||||
UInt8 bitsPerPixel;
|
||||
};
|
||||
|
||||
class NAZARA_CORE_API PixelFormatInfo
|
||||
{
|
||||
friend class Core;
|
||||
|
||||
public:
|
||||
using ConvertFunction = std::function<UInt8*(const UInt8* start, const UInt8* end, UInt8* dst)>;
|
||||
using FlipFunction = std::function<void(unsigned int width, unsigned int height, unsigned int depth, const UInt8* src, UInt8* dst)>;
|
||||
|
||||
static inline std::size_t ComputeSize(PixelFormat format, unsigned int width, unsigned int height, unsigned int depth);
|
||||
|
||||
static inline bool Convert(PixelFormat srcFormat, PixelFormat dstFormat, const void* src, void* dst);
|
||||
static inline bool Convert(PixelFormat srcFormat, PixelFormat dstFormat, const void* start, const void* end, void* dst);
|
||||
|
||||
static bool Flip(PixelFlipping flipping, PixelFormat format, unsigned int width, unsigned int height, unsigned int depth, const void* src, void* dst);
|
||||
|
||||
static inline UInt8 GetBitsPerPixel(PixelFormat format);
|
||||
static inline PixelFormatContent GetContent(PixelFormat format);
|
||||
static inline UInt8 GetBytesPerPixel(PixelFormat format);
|
||||
static inline const PixelFormatDescription& GetInfo(PixelFormat format);
|
||||
static inline std::string_view GetName(PixelFormat format);
|
||||
|
||||
static inline bool HasAlpha(PixelFormat format);
|
||||
|
||||
static inline PixelFormat IdentifyFormat(const PixelFormatDescription& info);
|
||||
static inline PixelFormat IdentifyFormat(std::string_view formatName);
|
||||
|
||||
static inline bool IsCompressed(PixelFormat format);
|
||||
static inline bool IsConversionSupported(PixelFormat srcFormat, PixelFormat dstFormat);
|
||||
static inline bool IsValid(PixelFormat format);
|
||||
|
||||
static inline void SetConvertFunction(PixelFormat srcFormat, PixelFormat dstFormat, ConvertFunction func);
|
||||
static inline void SetFlipFunction(PixelFlipping flipping, PixelFormat format, FlipFunction func);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
static EnumArray<PixelFormat, EnumArray<PixelFormat, ConvertFunction>> s_convertFunctions;
|
||||
static EnumArray<PixelFormat, EnumArray<PixelFlipping, FlipFunction>> s_flipFunctions;
|
||||
static EnumArray<PixelFormat, PixelFormatDescription> s_pixelFormatInfos;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/PixelFormat.inl>
|
||||
|
||||
#endif // NAZARA_CORE_PIXELFORMAT_HPP
|
||||
299
include/Nazara/Core/PixelFormat.inl
Normal file
299
include/Nazara/Core/PixelFormat.inl
Normal file
@@ -0,0 +1,299 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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 <NazaraUtils/Algorithm.hpp>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline PixelFormatDescription::PixelFormatDescription() :
|
||||
content(PixelFormatContent::Undefined),
|
||||
bitsPerPixel(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline PixelFormatDescription::PixelFormatDescription(PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) :
|
||||
content(formatContent),
|
||||
redType(subType),
|
||||
greenType(subType),
|
||||
blueType(subType),
|
||||
alphaType(subType),
|
||||
bitsPerPixel(bpp)
|
||||
{
|
||||
}
|
||||
|
||||
inline PixelFormatDescription::PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) :
|
||||
name(formatName),
|
||||
content(formatContent),
|
||||
redType(subType),
|
||||
greenType(subType),
|
||||
blueType(subType),
|
||||
alphaType(subType),
|
||||
bitsPerPixel(bpp)
|
||||
{
|
||||
}
|
||||
|
||||
inline PixelFormatDescription::PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) :
|
||||
PixelFormatDescription(formatName, formatContent, subType, rMask, subType, gMask, subType, bMask, subType, aMask)
|
||||
{
|
||||
}
|
||||
|
||||
inline PixelFormatDescription::PixelFormatDescription(std::string_view formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) :
|
||||
name(formatName),
|
||||
redMask(rMask),
|
||||
greenMask(gMask),
|
||||
blueMask(bMask),
|
||||
alphaMask(aMask),
|
||||
content(formatContent),
|
||||
redType(rType),
|
||||
greenType(gType),
|
||||
blueType(bType),
|
||||
alphaType(aType)
|
||||
{
|
||||
redMask.Reverse();
|
||||
greenMask.Reverse();
|
||||
blueMask.Reverse();
|
||||
alphaMask.Reverse();
|
||||
|
||||
if (bpp == 0)
|
||||
RecomputeBitsPerPixel();
|
||||
}
|
||||
|
||||
inline void PixelFormatDescription::Clear()
|
||||
{
|
||||
bitsPerPixel = 0;
|
||||
alphaMask.Clear();
|
||||
blueMask.Clear();
|
||||
greenMask.Clear();
|
||||
redMask.Clear();
|
||||
name = "";
|
||||
}
|
||||
|
||||
inline bool PixelFormatDescription::IsCompressed() const
|
||||
{
|
||||
return redType == PixelFormatSubType::Compressed ||
|
||||
greenType == PixelFormatSubType::Compressed ||
|
||||
blueType == PixelFormatSubType::Compressed ||
|
||||
alphaType == PixelFormatSubType::Compressed;
|
||||
}
|
||||
|
||||
inline bool PixelFormatDescription::IsValid() const
|
||||
{
|
||||
return bitsPerPixel != 0;
|
||||
}
|
||||
|
||||
inline void PixelFormatDescription::RecomputeBitsPerPixel()
|
||||
{
|
||||
Bitset<> counter;
|
||||
counter |= redMask;
|
||||
counter |= greenMask;
|
||||
counter |= blueMask;
|
||||
counter |= alphaMask;
|
||||
|
||||
bitsPerPixel = SafeCast<UInt8>(counter.Count());
|
||||
}
|
||||
|
||||
inline bool PixelFormatDescription::Validate() const
|
||||
{
|
||||
if (!IsValid())
|
||||
return false;
|
||||
|
||||
if (content <= PixelFormatContent::Undefined || content > PixelFormatContent::Max)
|
||||
return false;
|
||||
|
||||
std::array<const Nz::Bitset<>*, 4> masks = { {&redMask, &greenMask, &blueMask, &alphaMask} };
|
||||
std::array<PixelFormatSubType, 4> types = { {redType, greenType, blueType, alphaType} };
|
||||
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
{
|
||||
UInt8 usedBits = SafeCast<UInt8>(masks[i]->Count());
|
||||
if (usedBits == 0)
|
||||
continue;
|
||||
|
||||
if (usedBits > bitsPerPixel)
|
||||
return false;
|
||||
|
||||
if (usedBits > 64) //< Currently, formats with over 64 bits per component are not supported
|
||||
return false;
|
||||
|
||||
switch (types[i])
|
||||
{
|
||||
case PixelFormatSubType::Half:
|
||||
if (usedBits != 16)
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
case PixelFormatSubType::Float:
|
||||
if (usedBits != 32)
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline std::size_t PixelFormatInfo::ComputeSize(PixelFormat format, unsigned int width, unsigned int height, unsigned int depth)
|
||||
{
|
||||
if (IsCompressed(format))
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case PixelFormat::DXT1:
|
||||
case PixelFormat::DXT3:
|
||||
case PixelFormat::DXT5:
|
||||
return (((width + 3) / 4) * ((height + 3) / 4) * ((format == PixelFormat::DXT1) ? 8 : 16)) * depth;
|
||||
|
||||
default:
|
||||
NazaraError("unsupported format");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
return width * height * depth * GetBytesPerPixel(format);
|
||||
}
|
||||
|
||||
inline bool PixelFormatInfo::Convert(PixelFormat srcFormat, PixelFormat dstFormat, const void* src, void* dst)
|
||||
{
|
||||
if (srcFormat == dstFormat)
|
||||
{
|
||||
std::memcpy(dst, src, GetBytesPerPixel(srcFormat));
|
||||
return true;
|
||||
}
|
||||
|
||||
#if NAZARA_CORE_SAFE
|
||||
if (IsCompressed(srcFormat))
|
||||
{
|
||||
NazaraError("cannot convert single pixel from compressed format");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsCompressed(dstFormat))
|
||||
{
|
||||
NazaraError("cannot convert single pixel to compressed format");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Convert(srcFormat, dstFormat, src, static_cast<const UInt8*>(src) + GetBytesPerPixel(srcFormat), dst);
|
||||
}
|
||||
|
||||
inline bool PixelFormatInfo::Convert(PixelFormat srcFormat, PixelFormat dstFormat, const void* start, const void* end, void* dst)
|
||||
{
|
||||
if (srcFormat == dstFormat)
|
||||
{
|
||||
std::memcpy(dst, start, reinterpret_cast<const UInt8*>(end) - reinterpret_cast<const UInt8*>(start));
|
||||
return true;
|
||||
}
|
||||
|
||||
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
|
||||
if (!func)
|
||||
{
|
||||
NazaraErrorFmt("pixel format conversion from {0} to {1} is not supported", GetName(srcFormat), GetName(dstFormat));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!func(reinterpret_cast<const UInt8*>(start), reinterpret_cast<const UInt8*>(end), reinterpret_cast<UInt8*>(dst)))
|
||||
{
|
||||
NazaraErrorFmt("pixel format conversion from {0} to {1} failed", GetName(srcFormat), GetName(dstFormat));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline UInt8 PixelFormatInfo::GetBitsPerPixel(PixelFormat format)
|
||||
{
|
||||
return s_pixelFormatInfos[format].bitsPerPixel;
|
||||
}
|
||||
|
||||
inline UInt8 PixelFormatInfo::GetBytesPerPixel(PixelFormat format)
|
||||
{
|
||||
return GetBitsPerPixel(format)/8;
|
||||
}
|
||||
|
||||
inline PixelFormatContent PixelFormatInfo::GetContent(PixelFormat format)
|
||||
{
|
||||
return s_pixelFormatInfos[format].content;
|
||||
}
|
||||
|
||||
inline const PixelFormatDescription& PixelFormatInfo::GetInfo(PixelFormat format)
|
||||
{
|
||||
return s_pixelFormatInfos[format];
|
||||
}
|
||||
|
||||
inline std::string_view PixelFormatInfo::GetName(PixelFormat format)
|
||||
{
|
||||
return s_pixelFormatInfos[format].name;
|
||||
}
|
||||
|
||||
inline bool PixelFormatInfo::HasAlpha(PixelFormat format)
|
||||
{
|
||||
return s_pixelFormatInfos[format].alphaMask.TestAny();
|
||||
}
|
||||
|
||||
inline PixelFormat PixelFormatInfo::IdentifyFormat(const PixelFormatDescription& info)
|
||||
{
|
||||
for (auto&& [format, formatDesc] : s_pixelFormatInfos.iter_kv())
|
||||
{
|
||||
if (info.bitsPerPixel == formatDesc.bitsPerPixel && info.content == formatDesc.content &&
|
||||
info.redMask == formatDesc.redMask && info.greenMask == formatDesc.greenMask && info.blueMask == formatDesc.blueMask && info.alphaMask == formatDesc.alphaMask &&
|
||||
info.redType == formatDesc.redType && info.greenType == formatDesc.greenType && info.blueType == formatDesc.blueType && info.alphaType == formatDesc.alphaType)
|
||||
return format;
|
||||
}
|
||||
|
||||
return PixelFormat::Undefined;
|
||||
}
|
||||
|
||||
inline PixelFormat PixelFormatInfo::IdentifyFormat(std::string_view formatName)
|
||||
{
|
||||
for (auto&& [format, formatDesc] : s_pixelFormatInfos.iter_kv())
|
||||
{
|
||||
if (formatDesc.name == formatName)
|
||||
return format;
|
||||
}
|
||||
|
||||
return PixelFormat::Undefined;
|
||||
}
|
||||
|
||||
inline bool PixelFormatInfo::IsCompressed(PixelFormat format)
|
||||
{
|
||||
return s_pixelFormatInfos[format].IsCompressed();
|
||||
}
|
||||
|
||||
inline bool PixelFormatInfo::IsConversionSupported(PixelFormat srcFormat, PixelFormat dstFormat)
|
||||
{
|
||||
if (srcFormat == dstFormat)
|
||||
return true;
|
||||
|
||||
return s_convertFunctions[srcFormat][dstFormat] != nullptr;
|
||||
}
|
||||
|
||||
inline bool PixelFormatInfo::IsValid(PixelFormat format)
|
||||
{
|
||||
return format != PixelFormat::Undefined;
|
||||
}
|
||||
|
||||
inline void PixelFormatInfo::SetConvertFunction(PixelFormat srcFormat, PixelFormat dstFormat, ConvertFunction func)
|
||||
{
|
||||
s_convertFunctions[srcFormat][dstFormat] = func;
|
||||
}
|
||||
|
||||
inline void PixelFormatInfo::SetFlipFunction(PixelFlipping flipping, PixelFormat format, FlipFunction func)
|
||||
{
|
||||
s_flipFunctions[format][flipping] = func;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
46
include/Nazara/Core/Plugins/AssimpPlugin.hpp
Normal file
46
include/Nazara/Core/Plugins/AssimpPlugin.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_PLUGINS_ASSIMPPLUGIN_HPP
|
||||
#define NAZARA_CORE_PLUGINS_ASSIMPPLUGIN_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/PluginInterface.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
// Don't export class due to MinGW bug, export every method instead
|
||||
class AssimpPlugin : public PluginInterface
|
||||
{
|
||||
public:
|
||||
#ifdef NAZARA_DEBUG
|
||||
static constexpr inline std::string_view Filename = NazaraPluginPrefix "PluginAssimp-d";
|
||||
#else
|
||||
static constexpr inline std::string_view Filename = NazaraPluginPrefix "PluginAssimp";
|
||||
#endif
|
||||
|
||||
AssimpPlugin() = default;
|
||||
AssimpPlugin(const AssimpPlugin&) = delete;
|
||||
AssimpPlugin(AssimpPlugin&&) = delete;
|
||||
~AssimpPlugin() = default;
|
||||
|
||||
AssimpPlugin& operator=(const AssimpPlugin&) = delete;
|
||||
AssimpPlugin& operator=(AssimpPlugin&&) = delete;
|
||||
};
|
||||
|
||||
#ifdef NAZARA_PLUGINS_STATIC
|
||||
template<>
|
||||
struct PluginProvider<AssimpPlugin>
|
||||
{
|
||||
static std::unique_ptr<AssimpPlugin> Instantiate();
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Plugins/AssimpPlugin.inl>
|
||||
|
||||
#endif // NAZARA_CORE_PLUGINS_ASSIMPPLUGIN_HPP
|
||||
11
include/Nazara/Core/Plugins/AssimpPlugin.inl
Normal file
11
include/Nazara/Core/Plugins/AssimpPlugin.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
38
include/Nazara/Core/Plugins/FFmpegPlugin.hpp
Normal file
38
include/Nazara/Core/Plugins/FFmpegPlugin.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_PLUGINS_FFMPEGPLUGIN_HPP
|
||||
#define NAZARA_CORE_PLUGINS_FFMPEGPLUGIN_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/PluginInterface.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
// Don't export class due to MinGW bug, export every method instead
|
||||
class FFmpegPlugin : public PluginInterface
|
||||
{
|
||||
public:
|
||||
#ifdef NAZARA_DEBUG
|
||||
static constexpr inline std::string_view Filename = NazaraPluginPrefix "PluginFFmpeg-d";
|
||||
#else
|
||||
static constexpr inline std::string_view Filename = NazaraPluginPrefix "PluginFFmpeg";
|
||||
#endif
|
||||
|
||||
FFmpegPlugin() = default;
|
||||
FFmpegPlugin(const FFmpegPlugin&) = delete;
|
||||
FFmpegPlugin(FFmpegPlugin&&) = delete;
|
||||
~FFmpegPlugin() = default;
|
||||
|
||||
FFmpegPlugin& operator=(const FFmpegPlugin&) = delete;
|
||||
FFmpegPlugin& operator=(FFmpegPlugin&&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Plugins/FFmpegPlugin.inl>
|
||||
|
||||
#endif // NAZARA_CORE_PLUGINS_FFMPEGPLUGIN_HPP
|
||||
11
include/Nazara/Core/Plugins/FFmpegPlugin.inl
Normal file
11
include/Nazara/Core/Plugins/FFmpegPlugin.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
32
include/Nazara/Core/Sequence.hpp
Normal file
32
include/Nazara/Core/Sequence.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SEQUENCE_HPP
|
||||
#define NAZARA_CORE_SEQUENCE_HPP
|
||||
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct Sequence
|
||||
{
|
||||
std::string name;
|
||||
UInt32 firstFrame;
|
||||
UInt32 frameCount;
|
||||
UInt32 frameRate;
|
||||
};
|
||||
|
||||
struct SequenceJoint
|
||||
{
|
||||
Quaternionf rotation = Quaternionf::Identity();
|
||||
Vector3f position = Vector3f::Zero();
|
||||
Vector3f scale = Vector3f::Unit();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_SEQUENCE_HPP
|
||||
55
include/Nazara/Core/Serialization.hpp
Normal file
55
include/Nazara/Core/Serialization.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SERIALIZATION_HPP
|
||||
#define NAZARA_CORE_SERIALIZATION_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <NazaraUtils/Endianness.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <NazaraUtils/TypeTag.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct NAZARA_CORE_API SerializationContext
|
||||
{
|
||||
MovablePtr<Stream> stream;
|
||||
Endianness endianness = Endianness::BigEndian; //< Default to Big Endian encoding
|
||||
UInt8 readBitPos = 8; //< 8 means no bit is currently read
|
||||
UInt8 readByte; //< Undefined value, will be initialized at the first bit read
|
||||
UInt8 writeBitPos = 8; //< 8 means no bit is currently wrote
|
||||
UInt8 writeByte; //< Undefined value, will be initialized at the first bit write
|
||||
|
||||
void FlushBits();
|
||||
inline void ResetReadBitPosition();
|
||||
inline void ResetWriteBitPosition();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, T&& value);
|
||||
|
||||
inline bool Serialize(SerializationContext& context, bool value, TypeTag<bool>);
|
||||
inline bool Serialize(SerializationContext& context, const std::string& value, TypeTag<std::string>);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value, TypeTag<T>);
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, T* value);
|
||||
|
||||
inline bool Unserialize(SerializationContext& context, bool* value, TypeTag<bool>);
|
||||
inline bool Unserialize(SerializationContext& context, std::string* value, TypeTag<std::string>);
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag<T>);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Serialization.inl>
|
||||
|
||||
#endif // NAZARA_CORE_SERIALIZATION_HPP
|
||||
184
include/Nazara/Core/Serialization.inl
Normal file
184
include/Nazara/Core/Serialization.inl
Normal file
@@ -0,0 +1,184 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Reset the current read bit cursor
|
||||
*/
|
||||
inline void SerializationContext::ResetReadBitPosition()
|
||||
{
|
||||
readBitPos = 8;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reset the current read bit cursor
|
||||
|
||||
* \remark This function only reset the cursor position, it doesn't do any writing
|
||||
if you wish to write all bits and reset bit position, call FlushBits
|
||||
|
||||
\see FlushBits
|
||||
*/
|
||||
inline void SerializationContext::ResetWriteBitPosition()
|
||||
{
|
||||
writeBitPos = 8;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool Serialize(SerializationContext& context, T&& value)
|
||||
{
|
||||
return Serialize(context, std::forward<T>(value), TypeTag<std::decay_t<T>>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes a boolean
|
||||
* \return true if serialization succeeded
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Boolean to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Serialize(SerializationContext& context, bool value, TypeTag<bool>)
|
||||
{
|
||||
if (context.writeBitPos == 8)
|
||||
{
|
||||
context.writeBitPos = 0;
|
||||
context.writeByte = 0;
|
||||
}
|
||||
|
||||
if (value)
|
||||
context.writeByte |= 1 << context.writeBitPos;
|
||||
|
||||
if (++context.writeBitPos >= 8)
|
||||
return Serialize(context, context.writeByte, TypeTag<UInt8>());
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes a std::string
|
||||
* \return true if successful
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value String to serialize
|
||||
*/
|
||||
bool Serialize(SerializationContext& context, const std::string& value, TypeTag<std::string>)
|
||||
{
|
||||
if (!Serialize(context, SafeCast<UInt32>(value.size()), TypeTag<UInt32>()))
|
||||
return false;
|
||||
|
||||
return context.stream->Write(value.data(), value.size()) == value.size();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Serializes an arithmetic type
|
||||
* \return true if serialization succeeded
|
||||
*
|
||||
* \param context Context for the serialization
|
||||
* \param value Arithmetic type to serialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Serialize(SerializationContext& context, T value, TypeTag<T>)
|
||||
{
|
||||
// Flush bits in case a writing is in progress
|
||||
context.FlushBits();
|
||||
|
||||
if (context.endianness != Endianness::Unknown && context.endianness != PlatformEndianness)
|
||||
value = ByteSwap(value);
|
||||
|
||||
return context.stream->Write(&value, sizeof(T)) == sizeof(T);
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool Unserialize(SerializationContext& context, T* value)
|
||||
{
|
||||
return Unserialize(context, value, TypeTag<T>());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Unserializes a boolean
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to boolean to unserialize
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
inline bool Unserialize(SerializationContext& context, bool* value, TypeTag<bool>)
|
||||
{
|
||||
if (context.readBitPos == 8)
|
||||
{
|
||||
if (!Unserialize(context, &context.readByte, TypeTag<UInt8>()))
|
||||
return false;
|
||||
|
||||
context.readBitPos = 0;
|
||||
}
|
||||
|
||||
if (value)
|
||||
*value = (context.readByte & (1 << context.readBitPos)) != 0;
|
||||
|
||||
context.readBitPos++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Unserializes a string
|
||||
* \return true if successful
|
||||
*
|
||||
* \param context Context of unserialization
|
||||
* \param string std::string to unserialize
|
||||
*/
|
||||
bool Unserialize(SerializationContext& context, std::string* string, TypeTag<std::string>)
|
||||
{
|
||||
UInt32 size;
|
||||
if (!Unserialize(context, &size, TypeTag<UInt32>()))
|
||||
return false;
|
||||
|
||||
string->resize(size);
|
||||
return context.stream->Read(&(*string)[0], size) == size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Unserializes an arithmetic type
|
||||
* \return true if unserialization succedeed
|
||||
*
|
||||
* \param context Context for the unserialization
|
||||
* \param value Pointer to arithmetic type to serialize
|
||||
*
|
||||
* \remark Produce a NazaraAssert if pointer to value is invalid
|
||||
*
|
||||
* \see Serialize, Unserialize
|
||||
*/
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_arithmetic<T>::value, bool> Unserialize(SerializationContext& context, T* value, TypeTag<T>)
|
||||
{
|
||||
NazaraAssert(value, "Invalid data pointer");
|
||||
|
||||
context.ResetReadBitPosition();
|
||||
|
||||
if (context.stream->Read(value, sizeof(T)) == sizeof(T))
|
||||
{
|
||||
if (context.endianness != Endianness::Unknown && context.endianness != PlatformEndianness)
|
||||
*value = ByteSwap(*value);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SERIALIZATIONCONTEXT_HPP
|
||||
#define NAZARA_CORE_SERIALIZATIONCONTEXT_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <NazaraUtils/Endianness.hpp>
|
||||
#include <NazaraUtils/MovablePtr.hpp>
|
||||
#include <NazaraUtils/TypeTag.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Stream;
|
||||
|
||||
struct NAZARA_CORE_API SerializationContext
|
||||
{
|
||||
MovablePtr<Stream> stream;
|
||||
Endianness endianness = Endianness::BigEndian; //< Default to Big Endian encoding
|
||||
UInt8 readBitPos = 8; //< 8 means no bit is currently read
|
||||
UInt8 readByte; //< Undefined value, will be initialized at the first bit read
|
||||
UInt8 writeBitPos = 8; //< 8 means no bit is currently wrote
|
||||
UInt8 writeByte; //< Undefined value, will be initialized at the first bit write
|
||||
|
||||
void FlushBits();
|
||||
inline void ResetReadBitPosition();
|
||||
inline void ResetWriteBitPosition();
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/SerializationContext.inl>
|
||||
|
||||
#endif // NAZARA_CORE_SERIALIZATIONCONTEXT_HPP
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Reset the current read bit cursor
|
||||
*/
|
||||
inline void SerializationContext::ResetReadBitPosition()
|
||||
{
|
||||
readBitPos = 8;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reset the current read bit cursor
|
||||
|
||||
* \remark This function only reset the cursor position, it doesn't do any writing
|
||||
if you wish to write all bits and reset bit position, call FlushBits
|
||||
|
||||
\see FlushBits
|
||||
*/
|
||||
inline void SerializationContext::ResetWriteBitPosition()
|
||||
{
|
||||
writeBitPos = 8;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
44
include/Nazara/Core/SkeletalMesh.hpp
Normal file
44
include/Nazara/Core/SkeletalMesh.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SKELETALMESH_HPP
|
||||
#define NAZARA_CORE_SKELETALMESH_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/IndexBuffer.hpp>
|
||||
#include <Nazara/Core/SubMesh.hpp>
|
||||
#include <Nazara/Core/VertexBuffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API SkeletalMesh final : public SubMesh
|
||||
{
|
||||
public:
|
||||
SkeletalMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer);
|
||||
~SkeletalMesh() = default;
|
||||
|
||||
const Boxf& GetAABB() const override;
|
||||
AnimationType GetAnimationType() const final;
|
||||
const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const override;
|
||||
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
|
||||
UInt32 GetVertexCount() const override;
|
||||
|
||||
bool IsAnimated() const final;
|
||||
bool IsValid() const;
|
||||
|
||||
void SetAABB(const Boxf& aabb);
|
||||
void SetIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer);
|
||||
|
||||
private:
|
||||
Boxf m_aabb;
|
||||
std::shared_ptr<IndexBuffer> m_indexBuffer;
|
||||
std::shared_ptr<VertexBuffer> m_vertexBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/SkeletalMesh.inl>
|
||||
|
||||
#endif // NAZARA_CORE_SKELETALMESH_HPP
|
||||
12
include/Nazara/Core/SkeletalMesh.inl
Normal file
12
include/Nazara/Core/SkeletalMesh.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
75
include/Nazara/Core/Skeleton.hpp
Normal file
75
include/Nazara/Core/Skeleton.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SKELETON_HPP
|
||||
#define NAZARA_CORE_SKELETON_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Joint;
|
||||
class Skeleton;
|
||||
|
||||
using SkeletonLibrary = ObjectLibrary<Skeleton>;
|
||||
|
||||
struct SkeletonImpl;
|
||||
|
||||
class NAZARA_CORE_API Skeleton
|
||||
{
|
||||
friend Joint;
|
||||
|
||||
public:
|
||||
Skeleton();
|
||||
Skeleton(const Skeleton& skeleton);
|
||||
Skeleton(Skeleton&&) noexcept;
|
||||
~Skeleton();
|
||||
|
||||
bool Create(std::size_t jointCount);
|
||||
void Destroy();
|
||||
|
||||
const Boxf& GetAABB() const;
|
||||
Joint* GetJoint(std::string_view jointName);
|
||||
Joint* GetJoint(std::size_t index);
|
||||
const Joint* GetJoint(std::string_view jointName) const;
|
||||
const Joint* GetJoint(std::size_t index) const;
|
||||
Joint* GetJoints();
|
||||
const Joint* GetJoints() const;
|
||||
std::size_t GetJointCount() const;
|
||||
std::size_t GetJointIndex(std::string_view jointName) const;
|
||||
Joint* GetRootJoint();
|
||||
const Joint* GetRootJoint() const;
|
||||
|
||||
void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation);
|
||||
void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, const std::size_t* indices, std::size_t indiceCount);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
Skeleton& operator=(const Skeleton& skeleton);
|
||||
Skeleton& operator=(Skeleton&&) noexcept;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnSkeletonJointsInvalidated, const Skeleton* /*skeleton*/);
|
||||
|
||||
static constexpr std::size_t InvalidJointIndex = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
private:
|
||||
void InvalidateJoints();
|
||||
void InvalidateJointMap();
|
||||
void UpdateJointMap() const;
|
||||
|
||||
std::unique_ptr<SkeletonImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Skeleton.inl>
|
||||
|
||||
#endif // NAZARA_CORE_SKELETON_HPP
|
||||
12
include/Nazara/Core/Skeleton.inl
Normal file
12
include/Nazara/Core/Skeleton.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
37
include/Nazara/Core/SoftwareBuffer.hpp
Normal file
37
include/Nazara/Core/SoftwareBuffer.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SOFTWAREBUFFER_HPP
|
||||
#define NAZARA_CORE_SOFTWAREBUFFER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Buffer.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API SoftwareBuffer : public Buffer
|
||||
{
|
||||
public:
|
||||
SoftwareBuffer(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData);
|
||||
~SoftwareBuffer() = default;
|
||||
|
||||
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
|
||||
|
||||
const UInt8* GetData() const;
|
||||
|
||||
void* Map(UInt64 offset = 0, UInt64 size = 0) override;
|
||||
bool Unmap() override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<UInt8[]> m_buffer;
|
||||
bool m_mapped;
|
||||
};
|
||||
|
||||
NAZARA_CORE_API std::shared_ptr<Buffer> SoftwareBufferFactory(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData = nullptr);
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_SOFTWAREBUFFER_HPP
|
||||
46
include/Nazara/Core/StaticMesh.hpp
Normal file
46
include/Nazara/Core/StaticMesh.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_STATICMESH_HPP
|
||||
#define NAZARA_CORE_STATICMESH_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/SubMesh.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API StaticMesh final : public SubMesh
|
||||
{
|
||||
public:
|
||||
StaticMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer);
|
||||
~StaticMesh() = default;
|
||||
|
||||
void Center();
|
||||
|
||||
bool GenerateAABB();
|
||||
|
||||
const Boxf& GetAABB() const override;
|
||||
AnimationType GetAnimationType() const final;
|
||||
const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const override;
|
||||
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
|
||||
UInt32 GetVertexCount() const override;
|
||||
|
||||
bool IsAnimated() const final;
|
||||
bool IsValid() const;
|
||||
|
||||
void SetAABB(const Boxf& aabb);
|
||||
void SetIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer);
|
||||
|
||||
private:
|
||||
Boxf m_aabb;
|
||||
std::shared_ptr<IndexBuffer> m_indexBuffer;
|
||||
std::shared_ptr<VertexBuffer> m_vertexBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/StaticMesh.inl>
|
||||
|
||||
#endif // NAZARA_CORE_STATICMESH_HPP
|
||||
12
include/Nazara/Core/StaticMesh.inl
Normal file
12
include/Nazara/Core/StaticMesh.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
61
include/Nazara/Core/SubMesh.hpp
Normal file
61
include/Nazara/Core/SubMesh.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SUBMESH_HPP
|
||||
#define NAZARA_CORE_SUBMESH_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/IndexBuffer.hpp>
|
||||
#include <Nazara/Core/VertexBuffer.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <NazaraUtils/Signal.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Mesh;
|
||||
|
||||
class NAZARA_CORE_API SubMesh
|
||||
{
|
||||
friend Mesh;
|
||||
|
||||
public:
|
||||
SubMesh();
|
||||
SubMesh(const SubMesh&) = delete;
|
||||
SubMesh(SubMesh&&) = delete;
|
||||
virtual ~SubMesh();
|
||||
|
||||
void GenerateNormals();
|
||||
void GenerateNormalsAndTangents();
|
||||
void GenerateTangents();
|
||||
|
||||
virtual const Boxf& GetAABB() const = 0;
|
||||
virtual AnimationType GetAnimationType() const = 0;
|
||||
virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const = 0;
|
||||
std::size_t GetMaterialIndex() const;
|
||||
PrimitiveMode GetPrimitiveMode() const;
|
||||
UInt32 GetTriangleCount() const;
|
||||
virtual UInt32 GetVertexCount() const = 0;
|
||||
|
||||
virtual bool IsAnimated() const = 0;
|
||||
|
||||
void SetMaterialIndex(std::size_t matIndex);
|
||||
void SetPrimitiveMode(PrimitiveMode mode);
|
||||
|
||||
SubMesh& operator=(const SubMesh&) = delete;
|
||||
SubMesh& operator=(SubMesh&&) = delete;
|
||||
|
||||
// Signals:
|
||||
NazaraSignal(OnSubMeshInvalidateAABB, const SubMesh* /*subMesh*/);
|
||||
|
||||
protected:
|
||||
PrimitiveMode m_primitiveMode;
|
||||
std::size_t m_matIndex;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_SUBMESH_HPP
|
||||
@@ -30,5 +30,7 @@
|
||||
#define NAZARA_CORE_SYSTEMS_HPP
|
||||
|
||||
#include <Nazara/Core/Systems/LifetimeSystem.hpp>
|
||||
#include <Nazara/Core/Systems/SkeletonSystem.hpp>
|
||||
#include <Nazara/Core/Systems/VelocitySystem.hpp>
|
||||
|
||||
#endif // NAZARA_CORE_SYSTEMS_HPP
|
||||
|
||||
42
include/Nazara/Core/Systems/SkeletonSystem.hpp
Normal file
42
include/Nazara/Core/Systems/SkeletonSystem.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SYSTEMS_SKELETONSYSTEM_HPP
|
||||
#define NAZARA_CORE_SYSTEMS_SKELETONSYSTEM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API SkeletonSystem
|
||||
{
|
||||
public:
|
||||
static constexpr bool AllowConcurrent = false;
|
||||
static constexpr Int64 ExecutionOrder = -1'000;
|
||||
|
||||
SkeletonSystem(entt::registry& registry);
|
||||
SkeletonSystem(const SkeletonSystem&) = delete;
|
||||
SkeletonSystem(SkeletonSystem&&) = delete;
|
||||
~SkeletonSystem();
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
SkeletonSystem& operator=(const SkeletonSystem&) = delete;
|
||||
SkeletonSystem& operator=(SkeletonSystem&&) = delete;
|
||||
|
||||
private:
|
||||
entt::registry& m_registry;
|
||||
entt::observer m_sharedSkeletonConstructObserver;
|
||||
entt::observer m_skeletonConstructObserver;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Systems/SkeletonSystem.inl>
|
||||
|
||||
#endif // NAZARA_CORE_SYSTEMS_SKELETONSYSTEM_HPP
|
||||
11
include/Nazara/Core/Systems/SkeletonSystem.inl
Normal file
11
include/Nazara/Core/Systems/SkeletonSystem.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
40
include/Nazara/Core/Systems/VelocitySystem.hpp
Normal file
40
include/Nazara/Core/Systems/VelocitySystem.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_SYSTEMS_VELOCITYSYSTEM_HPP
|
||||
#define NAZARA_CORE_SYSTEMS_VELOCITYSYSTEM_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
#include <NazaraUtils/TypeList.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API VelocitySystem
|
||||
{
|
||||
public:
|
||||
using Components = TypeList<class NodeComponent, class VelocityComponent>;
|
||||
|
||||
inline VelocitySystem(entt::registry& registry);
|
||||
VelocitySystem(const VelocitySystem&) = delete;
|
||||
VelocitySystem(VelocitySystem&&) = delete;
|
||||
~VelocitySystem() = default;
|
||||
|
||||
void Update(Time elapsedTime);
|
||||
|
||||
VelocitySystem& operator=(const VelocitySystem&) = delete;
|
||||
VelocitySystem& operator=(VelocitySystem&&) = delete;
|
||||
|
||||
private:
|
||||
entt::registry& m_registry;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/Systems/VelocitySystem.inl>
|
||||
|
||||
#endif // NAZARA_CORE_SYSTEMS_VELOCITYSYSTEM_HPP
|
||||
15
include/Nazara/Core/Systems/VelocitySystem.inl
Normal file
15
include/Nazara/Core/Systems/VelocitySystem.inl
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline VelocitySystem::VelocitySystem(entt::registry& registry) :
|
||||
m_registry(registry)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -8,16 +8,14 @@
|
||||
#define NAZARA_CORE_TIME_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <chrono>
|
||||
#include <iosfwd>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct SerializationContext;
|
||||
|
||||
class Time
|
||||
{
|
||||
public:
|
||||
|
||||
40
include/Nazara/Core/TriangleIterator.hpp
Normal file
40
include/Nazara/Core/TriangleIterator.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_TRIANGLEITERATOR_HPP
|
||||
#define NAZARA_CORE_TRIANGLEITERATOR_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/IndexMapper.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class SubMesh;
|
||||
|
||||
class NAZARA_CORE_API TriangleIterator
|
||||
{
|
||||
public:
|
||||
TriangleIterator(PrimitiveMode primitiveMode, IndexBuffer& indexBuffer);
|
||||
TriangleIterator(SubMesh& subMesh);
|
||||
~TriangleIterator() = default;
|
||||
|
||||
bool Advance();
|
||||
|
||||
UInt32 operator[](std::size_t i) const;
|
||||
|
||||
void Unmap();
|
||||
|
||||
private:
|
||||
PrimitiveMode m_primitiveMode;
|
||||
UInt32 m_triangleIndices[3];
|
||||
IndexMapper m_indexMapper;
|
||||
std::size_t m_currentIndex;
|
||||
std::size_t m_indexCount;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_TRIANGLEITERATOR_HPP
|
||||
48
include/Nazara/Core/UniformBuffer.hpp
Normal file
48
include/Nazara/Core/UniformBuffer.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_UNIFORMBUFFER_HPP
|
||||
#define NAZARA_CORE_UNIFORMBUFFER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Buffer.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API UniformBuffer
|
||||
{
|
||||
public:
|
||||
UniformBuffer(std::shared_ptr<Buffer> buffer);
|
||||
UniformBuffer(std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||
UniformBuffer(UInt64 size, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||
UniformBuffer(const UniformBuffer&) = default;
|
||||
UniformBuffer(UniformBuffer&&) noexcept = default;
|
||||
~UniformBuffer() = default;
|
||||
|
||||
bool Fill(const void* data, UInt64 offset, UInt64 size);
|
||||
|
||||
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
||||
inline UInt64 GetEndOffset() const;
|
||||
inline UInt64 GetStartOffset() const;
|
||||
|
||||
void* Map(UInt64 offset = 0, UInt64 size = 0);
|
||||
void* Map(UInt64 offset = 0, UInt64 size = 0) const;
|
||||
|
||||
void Unmap() const;
|
||||
|
||||
UniformBuffer& operator=(const UniformBuffer&) = default;
|
||||
UniformBuffer& operator=(UniformBuffer&&) noexcept = default;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Buffer> m_buffer;
|
||||
UInt64 m_endOffset;
|
||||
UInt64 m_startOffset;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/UniformBuffer.inl>
|
||||
|
||||
#endif // NAZARA_CORE_UNIFORMBUFFER_HPP
|
||||
26
include/Nazara/Core/UniformBuffer.inl
Normal file
26
include/Nazara/Core/UniformBuffer.inl
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const std::shared_ptr<Buffer>& UniformBuffer::GetBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
inline UInt64 UniformBuffer::GetEndOffset() const
|
||||
{
|
||||
return m_endOffset;
|
||||
}
|
||||
|
||||
inline UInt64 UniformBuffer::GetStartOffset() const
|
||||
{
|
||||
return m_startOffset;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -8,8 +8,8 @@
|
||||
#define NAZARA_CORE_UUID_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Serialization.hpp>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
|
||||
62
include/Nazara/Core/VertexBuffer.hpp
Normal file
62
include/Nazara/Core/VertexBuffer.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_VERTEXBUFFER_HPP
|
||||
#define NAZARA_CORE_VERTEXBUFFER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Buffer.hpp>
|
||||
#include <Nazara/Core/VertexDeclaration.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API VertexBuffer
|
||||
{
|
||||
public:
|
||||
VertexBuffer() = default;
|
||||
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
|
||||
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
|
||||
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, UInt32 vertexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
|
||||
VertexBuffer(const VertexBuffer&) = default;
|
||||
VertexBuffer(VertexBuffer&&) noexcept = default;
|
||||
~VertexBuffer() = default;
|
||||
|
||||
bool Fill(const void* data, UInt64 startVertex, UInt64 length);
|
||||
bool FillRaw(const void* data, UInt64 offset, UInt64 size);
|
||||
|
||||
inline const std::shared_ptr<Buffer>& GetBuffer() const;
|
||||
inline UInt64 GetEndOffset() const;
|
||||
inline UInt64 GetStartOffset() const;
|
||||
inline UInt64 GetStride() const;
|
||||
inline UInt32 GetVertexCount() const;
|
||||
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration() const;
|
||||
|
||||
inline bool IsValid() const;
|
||||
|
||||
void* Map(UInt64 startVertex, UInt64 length);
|
||||
void* Map(UInt64 startVertex, UInt64 length) const;
|
||||
void* MapRaw(UInt64 offset, UInt64 size);
|
||||
void* MapRaw(UInt64 offset, UInt64 size) const;
|
||||
|
||||
void SetVertexDeclaration(std::shared_ptr<const VertexDeclaration> vertexDeclaration);
|
||||
|
||||
void Unmap() const;
|
||||
|
||||
VertexBuffer& operator=(const VertexBuffer&) = default;
|
||||
VertexBuffer& operator=(VertexBuffer&&) noexcept = default;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Buffer> m_buffer;
|
||||
std::shared_ptr<const VertexDeclaration> m_vertexDeclaration;
|
||||
UInt32 m_vertexCount;
|
||||
UInt64 m_endOffset;
|
||||
UInt64 m_startOffset;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/VertexBuffer.inl>
|
||||
|
||||
#endif // NAZARA_CORE_VERTEXBUFFER_HPP
|
||||
46
include/Nazara/Core/VertexBuffer.inl
Normal file
46
include/Nazara/Core/VertexBuffer.inl
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline const std::shared_ptr<Buffer>& VertexBuffer::GetBuffer() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
inline UInt64 VertexBuffer::GetEndOffset() const
|
||||
{
|
||||
return m_endOffset;
|
||||
}
|
||||
|
||||
inline UInt64 VertexBuffer::GetStride() const
|
||||
{
|
||||
return static_cast<UInt64>(m_vertexDeclaration->GetStride());
|
||||
}
|
||||
|
||||
inline UInt64 VertexBuffer::GetStartOffset() const
|
||||
{
|
||||
return m_startOffset;
|
||||
}
|
||||
|
||||
inline UInt32 VertexBuffer::GetVertexCount() const
|
||||
{
|
||||
return m_vertexCount;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<const VertexDeclaration>& VertexBuffer::GetVertexDeclaration() const
|
||||
{
|
||||
return m_vertexDeclaration;
|
||||
}
|
||||
|
||||
inline bool VertexBuffer::IsValid() const
|
||||
{
|
||||
return m_buffer && m_vertexDeclaration;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
87
include/Nazara/Core/VertexDeclaration.hpp
Normal file
87
include/Nazara/Core/VertexDeclaration.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_VERTEXDECLARATION_HPP
|
||||
#define NAZARA_CORE_VERTEXDECLARATION_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/ObjectLibrary.hpp>
|
||||
#include <NazaraUtils/EnumArray.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class VertexDeclaration;
|
||||
|
||||
using VertexDeclarationLibrary = ObjectLibrary<VertexDeclaration>;
|
||||
|
||||
class NAZARA_CORE_API VertexDeclaration
|
||||
{
|
||||
friend VertexDeclarationLibrary;
|
||||
friend class Core;
|
||||
|
||||
public:
|
||||
struct Component;
|
||||
struct ComponentEntry;
|
||||
|
||||
VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components);
|
||||
VertexDeclaration(const VertexDeclaration&) = delete;
|
||||
VertexDeclaration(VertexDeclaration&&) = delete;
|
||||
~VertexDeclaration() = default;
|
||||
|
||||
inline const Component* FindComponent(VertexComponent vertexComponent, std::size_t componentIndex) const;
|
||||
|
||||
template<typename T> const Component* GetComponentByType(VertexComponent vertexComponent, std::size_t componentIndex = 0) const;
|
||||
|
||||
inline const Component& GetComponent(std::size_t componentIndex) const;
|
||||
inline std::size_t GetComponentCount() const;
|
||||
inline const std::vector<Component>& GetComponents() const;
|
||||
inline VertexInputRate GetInputRate() const;
|
||||
inline std::size_t GetStride() const;
|
||||
|
||||
inline bool HasComponent(VertexComponent component, std::size_t componentIndex = 0) const;
|
||||
template<typename T> bool HasComponentOfType(VertexComponent vertexComponent, std::size_t componentIndex = 0) const;
|
||||
|
||||
VertexDeclaration& operator=(const VertexDeclaration&) = delete;
|
||||
VertexDeclaration& operator=(VertexDeclaration&&) = delete;
|
||||
|
||||
static inline const std::shared_ptr<VertexDeclaration>& Get(VertexLayout layout);
|
||||
static bool IsTypeSupported(ComponentType type);
|
||||
|
||||
struct Component
|
||||
{
|
||||
ComponentType type;
|
||||
VertexComponent component;
|
||||
std::size_t componentIndex;
|
||||
std::size_t offset;
|
||||
};
|
||||
|
||||
struct ComponentEntry
|
||||
{
|
||||
VertexComponent component;
|
||||
ComponentType type;
|
||||
std::size_t componentIndex;
|
||||
};
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::vector<Component> m_components;
|
||||
std::size_t m_stride;
|
||||
VertexInputRate m_inputRate;
|
||||
|
||||
static EnumArray<VertexLayout, std::shared_ptr<VertexDeclaration>> s_declarations;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/VertexDeclaration.inl>
|
||||
|
||||
#endif // NAZARA_CORE_VERTEXDECLARATION_HPP
|
||||
81
include/Nazara/Core/VertexDeclaration.inl
Normal file
81
include/Nazara/Core/VertexDeclaration.inl
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/Algorithm.hpp>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline auto VertexDeclaration::FindComponent(VertexComponent vertexComponent, std::size_t componentIndex) const -> const Component*
|
||||
{
|
||||
assert(componentIndex == 0 || vertexComponent == VertexComponent::Userdata);
|
||||
|
||||
for (const Component& component : m_components)
|
||||
{
|
||||
if (component.component == vertexComponent && component.componentIndex == componentIndex)
|
||||
return &component;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline auto VertexDeclaration::GetComponent(std::size_t componentIndex) const -> const Component&
|
||||
{
|
||||
return m_components[componentIndex];
|
||||
}
|
||||
|
||||
inline std::size_t VertexDeclaration::GetComponentCount() const
|
||||
{
|
||||
return m_components.size();
|
||||
}
|
||||
|
||||
inline auto VertexDeclaration::GetComponents() const -> const std::vector<Component>&
|
||||
{
|
||||
return m_components;
|
||||
}
|
||||
|
||||
inline VertexInputRate VertexDeclaration::GetInputRate() const
|
||||
{
|
||||
return m_inputRate;
|
||||
}
|
||||
|
||||
inline std::size_t VertexDeclaration::GetStride() const
|
||||
{
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
inline bool VertexDeclaration::HasComponent(VertexComponent component, std::size_t componentIndex) const
|
||||
{
|
||||
return FindComponent(component, componentIndex) != nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto VertexDeclaration::GetComponentByType(VertexComponent vertexComponent, std::size_t componentIndex) const -> const Component*
|
||||
{
|
||||
NazaraAssert(componentIndex == 0 || vertexComponent == VertexComponent::Userdata, "Only userdata vertex component can have component indexes");
|
||||
if (const Component* component = FindComponent(vertexComponent, componentIndex))
|
||||
{
|
||||
if (GetComponentTypeOf<T>() == component->type)
|
||||
return component;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool VertexDeclaration::HasComponentOfType(VertexComponent vertexComponent, std::size_t componentIndex) const
|
||||
{
|
||||
return GetComponentByType<T>(vertexComponent, componentIndex) != nullptr;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<VertexDeclaration>& VertexDeclaration::Get(VertexLayout layout)
|
||||
{
|
||||
NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum");
|
||||
return s_declarations[layout];
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
42
include/Nazara/Core/VertexMapper.hpp
Normal file
42
include/Nazara/Core/VertexMapper.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_VERTEXMAPPER_HPP
|
||||
#define NAZARA_CORE_VERTEXMAPPER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/BufferMapper.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/VertexBuffer.hpp>
|
||||
#include <NazaraUtils/SparsePtr.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class SubMesh;
|
||||
|
||||
class NAZARA_CORE_API VertexMapper
|
||||
{
|
||||
public:
|
||||
VertexMapper(SubMesh& subMesh);
|
||||
VertexMapper(VertexBuffer& vertexBuffer);
|
||||
~VertexMapper();
|
||||
|
||||
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component, std::size_t componentIndex = 0);
|
||||
inline const VertexBuffer* GetVertexBuffer() const;
|
||||
inline UInt32 GetVertexCount() const;
|
||||
|
||||
template<typename T> bool HasComponentOfType(VertexComponent component) const;
|
||||
|
||||
void Unmap();
|
||||
|
||||
private:
|
||||
BufferMapper<VertexBuffer> m_mapper;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/VertexMapper.inl>
|
||||
|
||||
#endif // NAZARA_CORE_VERTEXMAPPER_HPP
|
||||
39
include/Nazara/Core/VertexMapper.inl
Normal file
39
include/Nazara/Core/VertexMapper.inl
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// 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/VertexDeclaration.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <typename T>
|
||||
SparsePtr<T> VertexMapper::GetComponentPtr(VertexComponent component, std::size_t componentIndex)
|
||||
{
|
||||
// On récupère la déclaration depuis le buffer
|
||||
const std::shared_ptr<const VertexDeclaration>& declaration = m_mapper.GetBuffer()->GetVertexDeclaration();
|
||||
|
||||
if (const auto* componentData = declaration->GetComponentByType<T>(component, componentIndex))
|
||||
return SparsePtr<T>(static_cast<UInt8*>(m_mapper.GetPointer()) + componentData->offset, declaration->GetStride());
|
||||
else
|
||||
return SparsePtr<T>();
|
||||
}
|
||||
|
||||
inline const VertexBuffer* VertexMapper::GetVertexBuffer() const
|
||||
{
|
||||
return m_mapper.GetBuffer();
|
||||
}
|
||||
|
||||
inline UInt32 VertexMapper::GetVertexCount() const
|
||||
{
|
||||
return GetVertexBuffer()->GetVertexCount();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool VertexMapper::HasComponentOfType(VertexComponent component) const
|
||||
{
|
||||
return m_mapper.GetBuffer()->GetVertexDeclaration()->HasComponentOfType<T>(component);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
96
include/Nazara/Core/VertexStruct.hpp
Normal file
96
include/Nazara/Core/VertexStruct.hpp
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_VERTEXSTRUCT_HPP
|
||||
#define NAZARA_CORE_VERTEXSTRUCT_HPP
|
||||
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/******************************* Structures 2D *******************************/
|
||||
|
||||
struct VertexStruct_XY
|
||||
{
|
||||
Vector2f position;
|
||||
};
|
||||
|
||||
struct VertexStruct_XY_Color : VertexStruct_XY
|
||||
{
|
||||
Color color;
|
||||
};
|
||||
|
||||
struct VertexStruct_XY_UV : VertexStruct_XY
|
||||
{
|
||||
Vector2f uv;
|
||||
};
|
||||
|
||||
struct VertexStruct_XY_Color_UV : VertexStruct_XY_Color
|
||||
{
|
||||
Vector2f uv;
|
||||
};
|
||||
|
||||
/******************************* Structures 3D *******************************/
|
||||
|
||||
struct VertexStruct_XYZ
|
||||
{
|
||||
Vector3f position;
|
||||
};
|
||||
|
||||
struct VertexStruct_XYZ_Color : VertexStruct_XYZ
|
||||
{
|
||||
Color color;
|
||||
};
|
||||
|
||||
struct VertexStruct_XYZ_Color_UV : VertexStruct_XYZ_Color
|
||||
{
|
||||
Vector2f uv;
|
||||
};
|
||||
|
||||
struct VertexStruct_XYZ_Normal : VertexStruct_XYZ
|
||||
{
|
||||
Vector3f normal;
|
||||
};
|
||||
|
||||
struct VertexStruct_XYZ_Normal_UV : VertexStruct_XYZ_Normal
|
||||
{
|
||||
Vector2f uv;
|
||||
};
|
||||
|
||||
struct VertexStruct_XYZ_Normal_UV_Tangent : VertexStruct_XYZ_Normal_UV
|
||||
{
|
||||
Vector3f tangent;
|
||||
};
|
||||
|
||||
struct VertexStruct_UV_SizeSinCos
|
||||
{
|
||||
Vector2f uv;
|
||||
Vector4f sizeSinCos; //< width, height, sin, cos
|
||||
};
|
||||
|
||||
struct VertexStruct_UV_SizeSinCos_Color : VertexStruct_UV_SizeSinCos
|
||||
{
|
||||
Color color;
|
||||
};
|
||||
|
||||
struct VertexStruct_XYZ_UV : VertexStruct_XYZ
|
||||
{
|
||||
Vector2f uv;
|
||||
};
|
||||
|
||||
/************************* Structures 3D (+ Skinning) ************************/
|
||||
|
||||
struct VertexStruct_XYZ_Normal_UV_Tangent_Skinning : VertexStruct_XYZ_Normal_UV_Tangent
|
||||
{
|
||||
Vector4f weights;
|
||||
Vector4i32 jointIndexes;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_CORE_VERTEXSTRUCT_HPP
|
||||
Reference in New Issue
Block a user