Upgrade Utility

This commit is contained in:
Jérôme Leclercq
2021-05-24 19:10:53 +02:00
parent b936946154
commit cce32a64d4
120 changed files with 2328 additions and 2971 deletions

View File

@@ -28,25 +28,38 @@ namespace Nz
friend Type;
public:
using ExtensionGetter = bool (*)(const std::string& extension);
using FormatQuerier = bool (*)(const std::string& format);
using FileSaver = bool (*)(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters);
using StreamSaver = bool (*)(const Type& resource, const std::string& format, Stream& stream, const Parameters& parameters);
struct Entry;
using FormatSupport = std::function<bool(const std::string_view& format)>;
using FileSaver = std::function<bool(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters)>;
using StreamSaver = std::function<bool(const Type& resource, const std::string& format, Stream& stream, const Parameters& parameters)>;
ResourceSaver() = delete;
~ResourceSaver() = delete;
ResourceSaver() = default;
ResourceSaver(const ResourceSaver&) = delete;
ResourceSaver(ResourceSaver&&) noexcept = default;
~ResourceSaver() = default;
static bool IsFormatSupported(const std::string& extension);
void Clear();
static bool SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters = Parameters());
static bool SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters = Parameters());
bool IsExtensionSupported(const std::string_view& extension) const;
static void RegisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);
static void UnregisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver = nullptr);
bool SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters = Parameters()) const;
bool SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters = Parameters()) const;
const Entry* RegisterSaver(Entry saver);
void UnregisterSaver(const Entry* saver);
ResourceSaver& operator=(const ResourceSaver&) = delete;
ResourceSaver& operator=(ResourceSaver&&) noexcept = default;
struct Entry
{
FormatSupport formatSupport;
FileSaver fileSaver;
StreamSaver streamSaver;
};
private:
using Saver = std::tuple<FormatQuerier, StreamSaver, FileSaver>;
using SaverList = std::list<Saver>;
std::vector<std::unique_ptr<Entry>> m_savers;
};
}

View File

@@ -18,6 +18,15 @@ namespace Nz
* \brief Core class that represents a list of saver functions for a specific resource type
*/
/*!
* \brief Unregister every saver registered
*/
template<typename Type, typename Parameters>
void ResourceSaver<Type, Parameters>::Clear()
{
m_savers.clear();
}
/*!
* \brief Checks whether the extension of the file is supported
* \return true if supported
@@ -25,13 +34,12 @@ namespace Nz
* \param extension Extension of the file
*/
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::IsFormatSupported(const std::string& extension)
bool ResourceSaver<Type, Parameters>::IsExtensionSupported(const std::string_view& extension) const
{
for (Saver& saver : Type::s_savers)
for (const auto& saverPtr : m_savers)
{
ExtensionGetter isExtensionSupported = std::get<0>(saver);
if (isExtensionSupported && isExtensionSupported(extension))
const Entry& saver = *saverPtr;
if (saver.formatSupport(extension))
return true;
}
@@ -52,45 +60,42 @@ namespace Nz
* \see SaveToStream
*/
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters)
bool ResourceSaver<Type, Parameters>::SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters) const
{
NazaraAssert(parameters.IsValid(), "Invalid parameters");
std::string ext = ToLower(filePath.extension().generic_u8string());
if (ext.empty())
std::string extension = ToLower(filePath.extension().generic_u8string());
if (extension.empty())
{
NazaraError("Failed to get file extension from \"" + filePath.generic_u8string() + '"');
return false;
}
File file(filePath.generic_u8string()); // Opened only is required
bool found = false;
for (Saver& saver : Type::s_savers)
for (const auto& saverPtr : m_savers)
{
FormatQuerier formatQuerier = std::get<0>(saver);
if (!formatQuerier || !formatQuerier(ext))
const Entry& saver = *saverPtr;
if (!saver.formatSupport(extension))
continue;
found = true;
StreamSaver streamSeaver = std::get<1>(saver);
FileSaver fileSaver = std::get<2>(saver);
if (fileSaver)
if (saver.fileSaver)
{
if (fileSaver(resource, filePath, parameters))
if (saver.fileSaver(resource, filePath, parameters))
return true;
}
else
{
File file(filePath.generic_u8string());
if (!file.Open(OpenMode_WriteOnly | OpenMode_Truncate))
{
NazaraError("Failed to save to file: unable to open \"" + filePath.generic_u8string() + "\" in write mode");
return false;
}
if (streamSeaver(resource, ext, file, parameters))
if (saver.streamSaver(resource, extension, file, parameters))
return true;
}
@@ -100,7 +105,7 @@ namespace Nz
if (found)
NazaraError("Failed to save resource: all savers failed");
else
NazaraError("Failed to save resource: no saver found for extension \"" + ext + '"');
NazaraError("Failed to save resource: no saver found for extension \"" + extension + '"');
return false;
}
@@ -117,28 +122,26 @@ namespace Nz
* \see SaveToFile
*/
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters)
bool ResourceSaver<Type, Parameters>::SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters) const
{
NazaraAssert(stream.IsWritable(), "Stream is not writable");
NazaraAssert(parameters.IsValid(), "Invalid parameters");
UInt64 streamPos = stream.GetCursorPos();
bool found = false;
for (Saver& saver : Type::s_savers)
for (const auto& saverPtr : m_savers)
{
FormatQuerier formatQuerier = std::get<0>(saver);
if (!formatQuerier || !formatQuerier(format))
const Entry& saver = *saverPtr;
if (!saver.formatSupport(format))
continue;
found = true;
StreamSaver streamSeaver = std::get<1>(saver);
// We move the stream to its old position
stream.SetCursorPos(streamPos);
// Load of the resource
if (streamSeaver(resource, format, stream, parameters))
if (saver.streamSaver(resource, format, stream, parameters))
return true;
NazaraWarning("Saver failed");
@@ -154,36 +157,35 @@ namespace Nz
/*!
* \brief Registers a saver
* \return A pointer to the registered Entry which can be unsed to unregister it later
*
* \param formatQuerier A function to test whether the format (as a string) is supported by this saver
* \param streamSaver A function which saves the resource to a stream
* \param fileSaver Optional function which saves the resource directly to a file given a file path
* \param loader A collection of saver callbacks that will be registered
*
* \remark The fileSaver argument is only present for compatibility with external savers which cannot be interfaced with streams
* \remark At least one saver is required
* \see UnregisterLoader
*/
template<typename Type, typename Parameters>
void ResourceSaver<Type, Parameters>::RegisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver)
auto ResourceSaver<Type, Parameters>::RegisterSaver(Entry saver) -> const Entry*
{
NazaraAssert(formatQuerier, "A format querier is mandaroty");
NazaraAssert(streamSaver || fileSaver, "A saver function is mandaroty");
NazaraAssert(saver.formatSupport, "A format support callback is mandatory");
NazaraAssert(saver.streamSaver || saver.fileSaver, "A saver function is mandatory");
Type::s_savers.push_front(std::make_tuple(formatQuerier, streamSaver, fileSaver));
auto it = m_savers.emplace(m_savers.begin(), std::make_unique<Entry>(std::move(saver)));
return it->get();
}
/*!
* \brief Unregisters a saver
*
* \param formatQuerier A function to test whether the format (as a string) is supported by this saver
* \param streamSaver A function which saves the resource to a stream
* \param fileSaver A function function which saves the resource directly to a file given a file path
* \param saver A pointer to a loader returned by RegisterSaver
*
* \remark The saver will only be unregistered if the function pointers are exactly the same
* \see RegisterSaver
*/
template<typename Type, typename Parameters>
void ResourceSaver<Type, Parameters>::UnregisterSaver(FormatQuerier formatQuerier, StreamSaver streamSaver, FileSaver fileSaver)
void ResourceSaver<Type, Parameters>::UnregisterSaver(const Entry* saver)
{
Type::s_savers.remove(std::make_tuple(formatQuerier, streamSaver, fileSaver));
auto it = std::find_if(m_savers.begin(), m_savers.end(), [&](const std::unique_ptr<Entry>& saverPtr) { return saverPtr.get() == saver; });
if (it != m_savers.end())
m_savers.erase(it);
}
}

View File

@@ -18,7 +18,7 @@ namespace Nz
class NAZARA_GRAPHICS_API GraphicalMesh
{
public:
GraphicalMesh(const Mesh* mesh);
GraphicalMesh(const Mesh& mesh);
GraphicalMesh(const GraphicalMesh&) = delete;
GraphicalMesh(GraphicalMesh&&) noexcept = default;
~GraphicalMesh() = default;
@@ -26,7 +26,7 @@ namespace Nz
inline const std::shared_ptr<AbstractBuffer>& GetIndexBuffer(std::size_t subMesh) const;
inline std::size_t GetIndexCount(std::size_t subMesh) const;
inline const std::shared_ptr<AbstractBuffer>& GetVertexBuffer(std::size_t subMesh) const;
inline const VertexDeclarationConstRef& GetVertexDeclaration(std::size_t subMesh) const;
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration(std::size_t subMesh) const;
inline std::size_t GetSubMeshCount() const;
GraphicalMesh& operator=(const GraphicalMesh&) = delete;
@@ -38,7 +38,7 @@ namespace Nz
std::shared_ptr<AbstractBuffer> indexBuffer;
std::shared_ptr<AbstractBuffer> vertexBuffer;
std::size_t indexCount;
VertexDeclarationConstRef vertexDeclaration;
std::shared_ptr<const VertexDeclaration> vertexDeclaration;
};
std::vector<GraphicalSubMesh> m_subMeshes;

View File

@@ -26,7 +26,7 @@ namespace Nz
return m_subMeshes[subMesh].vertexBuffer;
}
inline const VertexDeclarationConstRef& GraphicalMesh::GetVertexDeclaration(std::size_t subMesh) const
inline const std::shared_ptr<const VertexDeclaration>& GraphicalMesh::GetVertexDeclaration(std::size_t subMesh) const
{
assert(subMesh < m_subMeshes.size());
return m_subMeshes[subMesh].vertexDeclaration;

View File

@@ -10,8 +10,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
@@ -32,7 +30,7 @@ namespace Nz
class CommandBufferBuilder;
class UploadPool;
class NAZARA_GRAPHICS_API Material : public RefCounted, public Resource
class NAZARA_GRAPHICS_API Material : public Resource
{
public:
Material(std::shared_ptr<const MaterialSettings> settings);

View File

@@ -107,7 +107,7 @@ namespace Nz
*
* This parameter is required for depth writing.
*
* In order to enable depth writing without enabling depth test, set the depth comparison function to RendererComparison_Never
* In order to enable depth writing without enabling depth test, set the depth comparison function to RendererComparison::Never
*
* \param depthBuffer Defines if this material will use depth buffer
*

View File

@@ -17,13 +17,13 @@ namespace Nz
{
switch (imageType)
{
case ImageType_2D: return GL::TextureTarget::Target2D;
case ImageType_2D_Array: return GL::TextureTarget::Target2D_Array;
case ImageType_3D: return GL::TextureTarget::Target3D;
case ImageType_Cubemap: return GL::TextureTarget::Cubemap;
case ImageType::E2D: return GL::TextureTarget::Target2D;
case ImageType::E2D_Array: return GL::TextureTarget::Target2D_Array;
case ImageType::E3D: return GL::TextureTarget::Target3D;
case ImageType::Cubemap: return GL::TextureTarget::Cubemap;
case ImageType_1D:
case ImageType_1D_Array:
case ImageType::E1D:
case ImageType::E1D_Array:
default:
throw std::runtime_error("unsupported texture type");
}

View File

@@ -15,17 +15,17 @@ namespace Nz
// TODO: Fill this switch
switch (pixelFormat)
{
case PixelFormat_A8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
case PixelFormat_BGR8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
case PixelFormat_BGR8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
case PixelFormat_BGRA8: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat_BGRA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat_Depth24Stencil8: return GLTextureFormat{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO };
case PixelFormat_RGB8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
case PixelFormat_RGB8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
case PixelFormat_RGBA8: return GLTextureFormat{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
case PixelFormat_RGBA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
case PixelFormat_RGBA32F: return GLTextureFormat{ GL_RGBA32F, GL_RGBA, GL_FLOAT, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
case PixelFormat::A8: return GLTextureFormat{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, GL_ZERO, GL_ZERO, GL_ZERO, GL_RED };
case PixelFormat::BGR8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
case PixelFormat::BGR8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ONE };
case PixelFormat::BGRA8: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat::BGRA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA };
case PixelFormat::Depth24Stencil8: return GLTextureFormat{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_RED, GL_GREEN, GL_ZERO, GL_ZERO };
case PixelFormat::RGB8: return GLTextureFormat{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
case PixelFormat::RGB8_SRGB: return GLTextureFormat{ GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ONE };
case PixelFormat::RGBA8: return GLTextureFormat{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
case PixelFormat::RGBA8_SRGB: return GLTextureFormat{ GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
case PixelFormat::RGBA32F: return GLTextureFormat{ GL_RGBA32F, GL_RGBA, GL_FLOAT, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
default: break;
}
@@ -76,12 +76,12 @@ namespace Nz
{
switch (filter)
{
case FaceSide_None:
case FaceSide::None:
break;
case FaceSide_Back: return GL_BACK;
case FaceSide_Front: return GL_FRONT;
case FaceSide_FrontAndBack: return GL_FRONT_AND_BACK;
case FaceSide::Back: return GL_BACK;
case FaceSide::Front: return GL_FRONT;
case FaceSide::FrontAndBack: return GL_FRONT_AND_BACK;
}
NazaraError("Unhandled FaceSide 0x" + NumberToString(UnderlyingCast(filter), 16));
@@ -92,12 +92,12 @@ namespace Nz
{
switch (primitiveMode)
{
case PrimitiveMode_LineList: return GL_LINES;
case PrimitiveMode_LineStrip: return GL_LINE_STRIP;
case PrimitiveMode_PointList: return GL_POINTS;
case PrimitiveMode_TriangleList: return GL_TRIANGLES;
case PrimitiveMode_TriangleStrip: return GL_TRIANGLE_STRIP;
case PrimitiveMode_TriangleFan: return GL_TRIANGLE_FAN;
case PrimitiveMode::LineList: return GL_LINES;
case PrimitiveMode::LineStrip: return GL_LINE_STRIP;
case PrimitiveMode::PointList: return GL_POINTS;
case PrimitiveMode::TriangleList: return GL_TRIANGLES;
case PrimitiveMode::TriangleStrip: return GL_TRIANGLE_STRIP;
case PrimitiveMode::TriangleFan: return GL_TRIANGLE_FAN;
}
NazaraError("Unhandled PrimitiveMode 0x" + NumberToString(UnderlyingCast(primitiveMode), 16));
@@ -108,14 +108,14 @@ namespace Nz
{
switch (comparison)
{
case RendererComparison_Always: return GL_ALWAYS;
case RendererComparison_Equal: return GL_EQUAL;
case RendererComparison_Greater: return GL_GREATER;
case RendererComparison_GreaterOrEqual: return GL_GEQUAL;
case RendererComparison_Less: return GL_LESS;
case RendererComparison_LessOrEqual: return GL_LEQUAL;
case RendererComparison_Never: return GL_NEVER;
case RendererComparison_NotEqual: return GL_NOTEQUAL;
case RendererComparison::Always: return GL_ALWAYS;
case RendererComparison::Equal: return GL_EQUAL;
case RendererComparison::Greater: return GL_GREATER;
case RendererComparison::GreaterOrEqual: return GL_GEQUAL;
case RendererComparison::Less: return GL_LESS;
case RendererComparison::LessOrEqual: return GL_LEQUAL;
case RendererComparison::Never: return GL_NEVER;
case RendererComparison::NotEqual: return GL_NOTEQUAL;
}
NazaraError("Unhandled RendererComparison 0x" + NumberToString(UnderlyingCast(comparison), 16));
@@ -126,8 +126,8 @@ namespace Nz
{
switch (filter)
{
case SamplerFilter::SamplerFilter_Linear: return GL_LINEAR;
case SamplerFilter::SamplerFilter_Nearest: return GL_NEAREST;
case SamplerFilter::Linear: return GL_LINEAR;
case SamplerFilter::Nearest: return GL_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(filter), 16));
@@ -138,24 +138,24 @@ namespace Nz
{
switch (minFilter)
{
case SamplerFilter::SamplerFilter_Linear:
case SamplerFilter::Linear:
{
switch (mipmapFilter)
{
case SamplerMipmapMode_Linear: return GL_LINEAR_MIPMAP_LINEAR;
case SamplerMipmapMode_Nearest: return GL_LINEAR_MIPMAP_NEAREST;
case SamplerMipmapMode::Linear: return GL_LINEAR_MIPMAP_LINEAR;
case SamplerMipmapMode::Nearest: return GL_LINEAR_MIPMAP_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16));
return {};
}
case SamplerFilter::SamplerFilter_Nearest:
case SamplerFilter::Nearest:
{
switch (mipmapFilter)
{
case SamplerMipmapMode_Linear: return GL_NEAREST_MIPMAP_LINEAR;
case SamplerMipmapMode_Nearest: return GL_NEAREST_MIPMAP_NEAREST;
case SamplerMipmapMode::Linear: return GL_NEAREST_MIPMAP_LINEAR;
case SamplerMipmapMode::Nearest: return GL_NEAREST_MIPMAP_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16));
@@ -171,9 +171,9 @@ namespace Nz
{
switch (wrapMode)
{
case SamplerWrap::SamplerWrap_Clamp: return GL_CLAMP_TO_EDGE;
case SamplerWrap::SamplerWrap_MirroredRepeat: return GL_MIRRORED_REPEAT;
case SamplerWrap::SamplerWrap_Repeat: return GL_REPEAT;
case SamplerWrap::Clamp: return GL_CLAMP_TO_EDGE;
case SamplerWrap::MirroredRepeat: return GL_MIRRORED_REPEAT;
case SamplerWrap::Repeat: return GL_REPEAT;
}
NazaraError("Unhandled SamplerWrap 0x" + NumberToString(UnderlyingCast(wrapMode), 16));
@@ -196,14 +196,14 @@ namespace Nz
{
switch (stencilOp)
{
case StencilOperation_Decrement: return GL_DECR;
case StencilOperation_DecrementNoClamp: return GL_DECR_WRAP;
case StencilOperation_Increment: return GL_INCR;
case StencilOperation_IncrementNoClamp: return GL_INCR_WRAP;
case StencilOperation_Invert: return GL_INVERT;
case StencilOperation_Keep: return GL_KEEP;
case StencilOperation_Replace: return GL_REPLACE;
case StencilOperation_Zero: return GL_ZERO;
case StencilOperation::Decrement: return GL_DECR;
case StencilOperation::DecrementNoClamp: return GL_DECR_WRAP;
case StencilOperation::Increment: return GL_INCR;
case StencilOperation::IncrementNoClamp: return GL_INCR_WRAP;
case StencilOperation::Invert: return GL_INVERT;
case StencilOperation::Keep: return GL_KEEP;
case StencilOperation::Replace: return GL_REPLACE;
case StencilOperation::Zero: return GL_ZERO;
}
NazaraError("Unhandled StencilOperation 0x" + NumberToString(UnderlyingCast(stencilOp), 16));

View File

@@ -8,7 +8,6 @@
#define NAZARA_ABSTRACTIMAGE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
@@ -19,14 +18,12 @@ namespace Nz
{
class AbstractImage;
using AbstractImageConstRef = ObjectRef<const AbstractImage>;
using AbstractImageRef = ObjectRef<AbstractImage>;
class NAZARA_UTILITY_API AbstractImage : public RefCounted
class NAZARA_UTILITY_API AbstractImage
{
public:
AbstractImage() = default;
inline AbstractImage(const AbstractImage& image);
AbstractImage(const AbstractImage&) = default;
AbstractImage(AbstractImage&&) noexcept = default;
virtual ~AbstractImage();
UInt8 GetBytesPerPixel() const;
@@ -47,6 +44,9 @@ namespace Nz
virtual bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
virtual bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
virtual bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) = 0;
AbstractImage& operator=(const AbstractImage&) = default;
AbstractImage& operator=(AbstractImage&&) noexcept = default;
};
}

View File

@@ -6,10 +6,6 @@
namespace Nz
{
inline AbstractImage::AbstractImage(const AbstractImage&) :
RefCounted()
{
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -12,6 +12,7 @@
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp>
#include <memory>
namespace Nz
{
@@ -30,7 +31,7 @@ namespace Nz
virtual void Clear() = 0;
virtual const Rectf& GetBounds() const = 0;
virtual Font* GetFont(std::size_t index) const = 0;
virtual const std::shared_ptr<Font>& GetFont(std::size_t index) const = 0;
virtual std::size_t GetFontCount() const = 0;
virtual const Glyph& GetGlyph(std::size_t index) const = 0;
virtual std::size_t GetGlyphCount() const = 0;

View File

@@ -14,20 +14,20 @@ namespace Nz
return ComponentType{};
}
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<> constexpr ComponentType ComponentTypeId<Quaternionf>() { return ComponentType_Quaternion; }
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<> constexpr ComponentType ComponentTypeId<Quaternionf>() { return ComponentType::Quaternion; }
template<typename T>
constexpr ComponentType GetComponentTypeOf()

View File

@@ -10,8 +10,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/MovablePtr.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
@@ -38,23 +36,18 @@ namespace Nz
struct SequenceJoint;
class Skeleton;
using AnimationConstRef = ObjectRef<const Animation>;
using AnimationLibrary = ObjectLibrary<Animation>;
using AnimationLoader = ResourceLoader<Animation, AnimationParams>;
using AnimationManager = ResourceManager<Animation, AnimationParams>;
using AnimationRef = ObjectRef<Animation>;
struct AnimationImpl;
class NAZARA_UTILITY_API Animation : public RefCounted, public Resource
class NAZARA_UTILITY_API Animation : public Resource
{
friend AnimationLibrary;
friend AnimationLoader;
friend AnimationManager;
friend class Utility;
public:
Animation() = default;
Animation();
Animation(const Animation&) = delete;
Animation(Animation&&) noexcept;
~Animation();
bool AddSequence(const Sequence& sequence);
@@ -86,26 +79,15 @@ namespace Nz
void RemoveSequence(const std::string& sequenceName);
void RemoveSequence(std::size_t index);
template<typename... Args> static AnimationRef New(Args&&... args);
Animation& operator=(const Animation&) = delete;
Animation& operator=(Animation&&) noexcept;
static AnimationRef LoadFromFile(const std::filesystem::path& filePath, const AnimationParams& params = AnimationParams());
static AnimationRef LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params = AnimationParams());
static AnimationRef LoadFromStream(Stream& stream, const AnimationParams& params = AnimationParams());
// Signals:
NazaraSignal(OnAnimationDestroy, const Animation* /*animation*/);
NazaraSignal(OnAnimationRelease, const Animation* /*animation*/);
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:
static bool Initialize();
static void Uninitialize();
MovablePtr<AnimationImpl> m_impl = nullptr;
static AnimationLibrary::LibraryMap s_library;
static AnimationLoader::LoaderList s_loaders;
static AnimationManager::ManagerMap s_managerMap;
static AnimationManager::ManagerParams s_managerParameters;
std::unique_ptr<AnimationImpl> m_impl;
};
}

View File

@@ -2,19 +2,12 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Animation.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
template<typename... Args>
AnimationRef Animation::New(Args&&... args)
{
std::unique_ptr<Animation> object(new Animation(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -8,37 +8,30 @@
#define NAZARA_BUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Utility/AbstractBuffer.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <array>
#include <functional>
namespace Nz
{
class Buffer;
using BufferConstRef = ObjectRef<const Buffer>;
using BufferRef = ObjectRef<Buffer>;
class NAZARA_UTILITY_API Buffer : public RefCounted
class NAZARA_UTILITY_API Buffer
{
friend class Utility;
public:
using BufferFactory = AbstractBuffer* (*)(Buffer* parent, BufferType type);
using BufferFactory = std::function<std::unique_ptr<AbstractBuffer>(Buffer* parent, BufferType type)>;
Buffer(BufferType type);
Buffer(BufferType type, UInt32 size, DataStorage storage = DataStorage_Software, BufferUsageFlags usage = 0);
Buffer(BufferType type, UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0);
Buffer(const Buffer&) = delete;
Buffer(Buffer&&) = delete;
~Buffer();
~Buffer() = default;
bool CopyContent(const BufferRef& buffer);
bool CopyContent(const Buffer& buffer);
bool Create(UInt32 size, DataStorage storage = DataStorage_Software, BufferUsageFlags usage = 0);
bool Create(UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0);
void Destroy();
bool Fill(const void* data, UInt32 offset, UInt32 size);
@@ -64,13 +57,8 @@ namespace Nz
Buffer& operator=(Buffer&&) = delete;
static bool IsStorageSupported(DataStorage storage);
template<typename... Args> static BufferRef New(Args&&... args);
static void SetBufferFactory(DataStorage storage, BufferFactory func);
// Signals:
NazaraSignal(OnBufferDestroy, const Buffer* /*buffer*/);
NazaraSignal(OnBufferRelease, const Buffer* /*buffer*/);
private:
static bool Initialize();
static void Uninitialize();
@@ -80,7 +68,7 @@ namespace Nz
BufferUsageFlags m_usage;
UInt32 m_size;
static std::array<BufferFactory, DataStorage_Max + 1> s_bufferFactories;
static std::array<BufferFactory, DataStorageCount> s_bufferFactories;
};
}

View File

@@ -41,15 +41,6 @@ namespace Nz
{
return m_impl != nullptr;
}
template<typename... Args>
BufferRef Buffer::New(Args&&... args)
{
std::unique_ptr<Buffer> object(new Buffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -11,12 +11,12 @@
namespace Nz
{
enum AnimationType
enum class AnimationType
{
AnimationType_Skeletal,
AnimationType_Static,
Skeletal,
Static,
AnimationType_Max = AnimationType_Static
Max = Static
};
enum class BlendEquation
@@ -46,286 +46,281 @@ namespace Nz
Zero
};
enum BufferAccess
enum class BufferAccess
{
BufferAccess_DiscardAndWrite,
BufferAccess_ReadOnly,
BufferAccess_ReadWrite,
BufferAccess_WriteOnly,
DiscardAndWrite,
ReadOnly,
ReadWrite,
WriteOnly,
BufferAccess_Max = BufferAccess_WriteOnly
Max = WriteOnly
};
enum BufferType
enum class BufferType
{
BufferType_Index,
BufferType_Vertex,
BufferType_Uniform,
Index,
Vertex,
Uniform,
BufferType_Max = BufferType_Uniform
Max = Uniform
};
enum BufferUsage
enum class BufferUsage
{
BufferUsage_DeviceLocal,
BufferUsage_DirectMapping,
BufferUsage_Dynamic,
BufferUsage_PersistentMapping,
DeviceLocal,
DirectMapping,
Dynamic,
PersistentMapping,
BufferUsage_Max = BufferUsage_DirectMapping
Max = DirectMapping
};
template<>
struct EnumAsFlags<BufferUsage>
{
static constexpr BufferUsage max = BufferUsage_Max;
static constexpr BufferUsage max = BufferUsage::Max;
};
using BufferUsageFlags = Flags<BufferUsage>;
enum ComponentType
enum class ComponentType
{
ComponentType_Color,
ComponentType_Double1,
ComponentType_Double2,
ComponentType_Double3,
ComponentType_Double4,
ComponentType_Float1,
ComponentType_Float2,
ComponentType_Float3,
ComponentType_Float4,
ComponentType_Int1,
ComponentType_Int2,
ComponentType_Int3,
ComponentType_Int4,
ComponentType_Quaternion,
Color,
Double1,
Double2,
Double3,
Double4,
Float1,
Float2,
Float3,
Float4,
Int1,
Int2,
Int3,
Int4,
Quaternion,
ComponentType_Max = ComponentType_Quaternion
Max = Quaternion
};
enum CubemapFace
constexpr std::size_t ComponentTypeCount = static_cast<std::size_t>(ComponentType::Max) + 1;
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
CubemapFace_PositiveX = 0,
CubemapFace_PositiveY = 2,
CubemapFace_PositiveZ = 4,
CubemapFace_NegativeX = 1,
CubemapFace_NegativeY = 3,
CubemapFace_NegativeZ = 5,
PositiveX = 0,
PositiveY = 2,
PositiveZ = 4,
NegativeX = 1,
NegativeY = 3,
NegativeZ = 5,
CubemapFace_Max = CubemapFace_NegativeZ
Max = NegativeZ
};
enum DataStorage
enum class DataStorage
{
DataStorage_Hardware,
DataStorage_Software,
Hardware,
Software,
DataStorage_Max = DataStorage_Software
Max = Software
};
enum FaceFilling
{
FaceFilling_Fill,
FaceFilling_Line,
FaceFilling_Point,
constexpr std::size_t DataStorageCount = static_cast<std::size_t>(DataStorage::Max) + 1;
FaceFilling_Max = FaceFilling_Point
enum class FaceFilling
{
Fill,
Line,
Point,
Max = Point
};
enum FaceSide
enum class FaceSide
{
FaceSide_None,
None,
FaceSide_Back,
FaceSide_Front,
FaceSide_FrontAndBack,
Back,
Front,
FrontAndBack,
FaceSide_Max = FaceSide_FrontAndBack
Max = FrontAndBack
};
enum ImageType
enum class ImageType
{
ImageType_1D,
ImageType_1D_Array,
ImageType_2D,
ImageType_2D_Array,
ImageType_3D,
ImageType_Cubemap,
E1D,
E1D_Array,
E2D,
E2D_Array,
E3D,
Cubemap,
ImageType_Max = ImageType_Cubemap
Max = Cubemap
};
constexpr std::size_t ImageTypeCount = static_cast<std::size_t>(ImageType_Max) + 1;
constexpr std::size_t ImageTypeCount = static_cast<std::size_t>(ImageType::Max) + 1;
enum NodeType
enum class NodeType
{
NodeType_Default, // Node
NodeType_Scene, // SceneNode (Graphics)
NodeType_Skeletal, ///TODO
Default, // Node
Scene, // SceneNode (Graphics)
Skeletal, ///TODO
NodeType_Max = NodeType_Skeletal
Max = Skeletal
};
enum PixelFormatContent
enum class PixelFormatContent
{
PixelFormatContent_Undefined = -1,
Undefined = -1,
PixelFormatContent_ColorRGBA,
PixelFormatContent_Depth,
PixelFormatContent_DepthStencil,
PixelFormatContent_Stencil,
ColorRGBA,
Depth,
DepthStencil,
Stencil,
PixelFormatContent_Max = PixelFormatContent_Stencil
Max = Stencil
};
enum PixelFormat
enum class PixelFormat
{
PixelFormat_Undefined = -1,
Undefined = -1,
PixelFormat_A8, // 1*uint8
PixelFormat_BGR8, // 3*uint8
PixelFormat_BGR8_SRGB, // 3*uint8
PixelFormat_BGRA8, // 4*uint8
PixelFormat_BGRA8_SRGB, // 4*uint8
PixelFormat_DXT1,
PixelFormat_DXT3,
PixelFormat_DXT5,
PixelFormat_L8, // 1*uint8
PixelFormat_LA8, // 2*uint8
PixelFormat_R8, // 1*uint8
PixelFormat_R8I, // 1*int8
PixelFormat_R8UI, // 1*uint8
PixelFormat_R16, // 1*uint16
PixelFormat_R16F, // 1*half
PixelFormat_R16I, // 1*int16
PixelFormat_R16UI, // 1*uint16
PixelFormat_R32F, // 1*float
PixelFormat_R32I, // 1*uint16
PixelFormat_R32UI, // 1*uint32
PixelFormat_RG8, // 2*int8
PixelFormat_RG8I, // 2*int8
PixelFormat_RG8UI, // 2*uint8
PixelFormat_RG16, // 2*uint16
PixelFormat_RG16F, // 2*half
PixelFormat_RG16I, // 2*int16
PixelFormat_RG16UI, // 2*uint16
PixelFormat_RG32F, // 2*float
PixelFormat_RG32I, // 2*uint16
PixelFormat_RG32UI, // 2*uint32
PixelFormat_RGB5A1, // 3*uint5 + alpha bit
PixelFormat_RGB8, // 3*uint8
PixelFormat_RGB8_SRGB, // 3*uint8
PixelFormat_RGB16F, // 3*half
PixelFormat_RGB16I, // 4*int16
PixelFormat_RGB16UI, // 4*uint16
PixelFormat_RGB32F, // 3*float
PixelFormat_RGB32I, // 4*int32
PixelFormat_RGB32UI, // 4*uint32
PixelFormat_RGBA4, // 4*uint4
PixelFormat_RGBA8, // 4*uint8
PixelFormat_RGBA8_SRGB, // 4*uint8
PixelFormat_RGBA16F, // 4*half
PixelFormat_RGBA16I, // 4*int16
PixelFormat_RGBA16UI, // 4*uint16
PixelFormat_RGBA32F, // 4*float
PixelFormat_RGBA32I, // 4*int32
PixelFormat_RGBA32UI, // 4*uint32
PixelFormat_Depth16,
PixelFormat_Depth24,
PixelFormat_Depth24Stencil8,
PixelFormat_Depth32,
PixelFormat_Stencil1,
PixelFormat_Stencil4,
PixelFormat_Stencil8,
PixelFormat_Stencil16,
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,
Depth24,
Depth24Stencil8,
Depth32,
Stencil1,
Stencil4,
Stencil8,
Stencil16,
PixelFormat_Max = PixelFormat_Stencil16
Max = Stencil16
};
enum PixelFormatSubType
{
PixelFormatSubType_Compressed, // Opaque
PixelFormatSubType_Double, // F64
PixelFormatSubType_Float, // F32
PixelFormatSubType_Half, // F16
PixelFormatSubType_Int, // Signed integer
PixelFormatSubType_Unsigned, // Unsigned integer
constexpr std::size_t PixelFormatCount = static_cast<std::size_t>(PixelFormat::Max) + 1;
PixelFormatSubType_Max = PixelFormatSubType_Unsigned
enum class PixelFormatSubType
{
Compressed, // Opaque
Double, // F64
Float, // F32
Half, // F16
Int, // Signed integer
Unsigned, // Unsigned integer
Max = Unsigned
};
enum PixelFlipping
enum class PixelFlipping
{
PixelFlipping_Horizontally,
PixelFlipping_Vertically,
Horizontally,
Vertically,
PixelFlipping_Max = PixelFlipping_Vertically
Max = Vertically
};
enum PrimitiveMode
{
PrimitiveMode_LineList,
PrimitiveMode_LineStrip,
PrimitiveMode_PointList,
PrimitiveMode_TriangleList,
PrimitiveMode_TriangleStrip,
PrimitiveMode_TriangleFan,
constexpr std::size_t PixelFlippingCount = static_cast<std::size_t>(PixelFlipping::Max) + 1;
PrimitiveMode_Max = PrimitiveMode_TriangleFan
enum class PrimitiveMode
{
LineList,
LineStrip,
PointList,
TriangleList,
TriangleStrip,
TriangleFan,
Max = TriangleFan
};
enum RendererComparison
enum class RendererComparison
{
RendererComparison_Always,
RendererComparison_Equal,
RendererComparison_Greater,
RendererComparison_GreaterOrEqual,
RendererComparison_Less,
RendererComparison_LessOrEqual,
RendererComparison_Never,
RendererComparison_NotEqual,
Always,
Equal,
Greater,
GreaterOrEqual,
Less,
LessOrEqual,
Never,
NotEqual,
RendererComparison_Max = RendererComparison_NotEqual
Max = NotEqual
};
enum RendererParameter
enum class SamplerFilter
{
RendererParameter_Blend,
RendererParameter_ColorWrite,
RendererParameter_DepthBuffer,
RendererParameter_DepthWrite,
RendererParameter_FaceCulling,
RendererParameter_ScissorTest,
RendererParameter_StencilTest,
Linear,
Nearest,
RendererParameter_Max = RendererParameter_StencilTest
Max = Nearest
};
enum SamplerFilter
enum class SamplerMipmapMode
{
SamplerFilter_Linear,
SamplerFilter_Nearest,
Linear,
Nearest,
SamplerFilter_Max = SamplerFilter_Nearest
Max = Nearest
};
enum SamplerMipmapMode
enum class SamplerWrap
{
SamplerMipmapMode_Linear,
SamplerMipmapMode_Nearest,
Clamp,
MirroredRepeat,
Repeat,
SamplerMipmapMode_Max = SamplerMipmapMode_Nearest
};
enum SamplerWrap
{
SamplerWrap_Clamp,
SamplerWrap_MirroredRepeat,
SamplerWrap_Repeat,
SamplerWrap_Max = SamplerWrap_Repeat
Max = Repeat
};
enum class ShaderStageType
@@ -348,95 +343,95 @@ namespace Nz
constexpr ShaderStageTypeFlags ShaderStageType_All = ShaderStageType::Fragment | ShaderStageType::Vertex;
enum StructFieldType
enum class StructFieldType
{
StructFieldType_Bool1,
StructFieldType_Bool2,
StructFieldType_Bool3,
StructFieldType_Bool4,
StructFieldType_Float1,
StructFieldType_Float2,
StructFieldType_Float3,
StructFieldType_Float4,
StructFieldType_Double1,
StructFieldType_Double2,
StructFieldType_Double3,
StructFieldType_Double4,
StructFieldType_Int1,
StructFieldType_Int2,
StructFieldType_Int3,
StructFieldType_Int4,
StructFieldType_UInt1,
StructFieldType_UInt2,
StructFieldType_UInt3,
StructFieldType_UInt4,
Bool1,
Bool2,
Bool3,
Bool4,
Float1,
Float2,
Float3,
Float4,
Double1,
Double2,
Double3,
Double4,
Int1,
Int2,
Int3,
Int4,
UInt1,
UInt2,
UInt3,
UInt4,
StructFieldType_Max = StructFieldType_UInt4
Max = UInt4
};
enum StructLayout
enum class StructLayout
{
StructLayout_Packed,
StructLayout_Std140,
Packed,
Std140,
StructLayout_Max = StructLayout_Std140
Max = Std140
};
enum StencilOperation
enum class StencilOperation
{
StencilOperation_Decrement,
StencilOperation_DecrementNoClamp,
StencilOperation_Increment,
StencilOperation_IncrementNoClamp,
StencilOperation_Invert,
StencilOperation_Keep,
StencilOperation_Replace,
StencilOperation_Zero,
Decrement,
DecrementNoClamp,
Increment,
IncrementNoClamp,
Invert,
Keep,
Replace,
Zero,
StencilOperation_Max = StencilOperation_Zero
Max = Zero
};
enum TextAlign
enum class TextAlign
{
TextAlign_Left,
TextAlign_Middle,
TextAlign_Right,
Left,
Middle,
Right,
TextAlign_Max = TextAlign_Right
Max = Right
};
enum TextStyle
enum class TextStyle
{
TextStyle_Bold,
TextStyle_Italic,
TextStyle_StrikeThrough,
TextStyle_Underlined,
Bold,
Italic,
StrikeThrough,
Underlined,
TextStyle_Max = TextStyle_Underlined
Max = Underlined
};
template<>
struct EnumAsFlags<TextStyle>
{
static constexpr TextStyle max = TextStyle_Max;
static constexpr TextStyle max = TextStyle::Max;
};
using TextStyleFlags = Flags<TextStyle>;
constexpr TextStyleFlags TextStyle_Regular = 0;
enum VertexComponent
enum class VertexComponent
{
VertexComponent_Unused = -1,
Unused = -1,
VertexComponent_Color,
VertexComponent_Normal,
VertexComponent_Position,
VertexComponent_Tangent,
VertexComponent_TexCoord,
VertexComponent_Userdata,
Color,
Normal,
Position,
Tangent,
TexCoord,
Userdata,
VertexComponent_Max = VertexComponent_Userdata
Max = Userdata
};
enum class VertexInputRate
@@ -445,26 +440,28 @@ namespace Nz
Vertex
};
enum VertexLayout
enum class VertexLayout
{
// Predefined declarations for rendering
VertexLayout_XY,
VertexLayout_XY_Color,
VertexLayout_XY_UV,
VertexLayout_XYZ,
VertexLayout_XYZ_Color,
VertexLayout_XYZ_Color_UV,
VertexLayout_XYZ_Normal,
VertexLayout_XYZ_Normal_UV,
VertexLayout_XYZ_Normal_UV_Tangent,
VertexLayout_XYZ_Normal_UV_Tangent_Skinning,
VertexLayout_XYZ_UV,
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,
XYZ_UV,
// Predefined declarations for instancing
VertexLayout_Matrix4,
Matrix4,
VertexLayout_Max = VertexLayout_Matrix4
Max = Matrix4
};
constexpr std::size_t VertexLayoutCount = static_cast<std::size_t>(VertexLayout::Max) + 1;
}
#endif // NAZARA_ENUMS_UTILITY_HPP

View File

@@ -25,7 +25,7 @@ namespace Nz
inline std::size_t FieldOffsets::GetAlignedSize() const
{
if (m_layout == StructLayout_Std140)
if (m_layout == StructLayout::Std140)
return Align(m_size, m_largestFieldAlignment);
else
return m_size;
@@ -40,43 +40,43 @@ namespace Nz
{
switch (layout)
{
case StructLayout_Packed:
case StructLayout::Packed:
return 1;
case StructLayout_Std140:
case StructLayout::Std140:
{
switch (fieldType)
{
case StructFieldType_Bool1:
case StructFieldType_Float1:
case StructFieldType_Int1:
case StructFieldType_UInt1:
case StructFieldType::Bool1:
case StructFieldType::Float1:
case StructFieldType::Int1:
case StructFieldType::UInt1:
return 4;
case StructFieldType_Bool2:
case StructFieldType_Float2:
case StructFieldType_Int2:
case StructFieldType_UInt2:
case StructFieldType::Bool2:
case StructFieldType::Float2:
case StructFieldType::Int2:
case StructFieldType::UInt2:
return 2 * 4;
case StructFieldType_Bool3:
case StructFieldType_Float3:
case StructFieldType_Int3:
case StructFieldType_UInt3:
case StructFieldType_Bool4:
case StructFieldType_Float4:
case StructFieldType_Int4:
case StructFieldType_UInt4:
case StructFieldType::Bool3:
case StructFieldType::Float3:
case StructFieldType::Int3:
case StructFieldType::UInt3:
case StructFieldType::Bool4:
case StructFieldType::Float4:
case StructFieldType::Int4:
case StructFieldType::UInt4:
return 4 * 4;
case StructFieldType_Double1:
case StructFieldType::Double1:
return 8;
case StructFieldType_Double2:
case StructFieldType::Double2:
return 2 * 8;
case StructFieldType_Double3:
case StructFieldType_Double4:
case StructFieldType::Double3:
case StructFieldType::Double4:
return 4 * 8;
}
}
@@ -89,32 +89,32 @@ namespace Nz
{
switch (fieldType)
{
case StructFieldType_Bool1:
case StructFieldType_Double1:
case StructFieldType_Float1:
case StructFieldType_Int1:
case StructFieldType_UInt1:
case StructFieldType::Bool1:
case StructFieldType::Double1:
case StructFieldType::Float1:
case StructFieldType::Int1:
case StructFieldType::UInt1:
return 1;
case StructFieldType_Bool2:
case StructFieldType_Double2:
case StructFieldType_Float2:
case StructFieldType_Int2:
case StructFieldType_UInt2:
case StructFieldType::Bool2:
case StructFieldType::Double2:
case StructFieldType::Float2:
case StructFieldType::Int2:
case StructFieldType::UInt2:
return 2;
case StructFieldType_Bool3:
case StructFieldType_Double3:
case StructFieldType_Float3:
case StructFieldType_Int3:
case StructFieldType_UInt3:
case StructFieldType::Bool3:
case StructFieldType::Double3:
case StructFieldType::Float3:
case StructFieldType::Int3:
case StructFieldType::UInt3:
return 3;
case StructFieldType_Bool4:
case StructFieldType_Double4:
case StructFieldType_Float4:
case StructFieldType_Int4:
case StructFieldType_UInt4:
case StructFieldType::Bool4:
case StructFieldType::Double4:
case StructFieldType::Float4:
case StructFieldType::Int4:
case StructFieldType::UInt4:
return 4;
}
@@ -125,40 +125,40 @@ namespace Nz
{
switch (fieldType)
{
case StructFieldType_Bool1:
case StructFieldType_Float1:
case StructFieldType_Int1:
case StructFieldType_UInt1:
case StructFieldType::Bool1:
case StructFieldType::Float1:
case StructFieldType::Int1:
case StructFieldType::UInt1:
return 4;
case StructFieldType_Bool2:
case StructFieldType_Float2:
case StructFieldType_Int2:
case StructFieldType_UInt2:
case StructFieldType::Bool2:
case StructFieldType::Float2:
case StructFieldType::Int2:
case StructFieldType::UInt2:
return 2 * 4;
case StructFieldType_Bool3:
case StructFieldType_Float3:
case StructFieldType_Int3:
case StructFieldType_UInt3:
case StructFieldType::Bool3:
case StructFieldType::Float3:
case StructFieldType::Int3:
case StructFieldType::UInt3:
return 3 * 4;
case StructFieldType_Bool4:
case StructFieldType_Float4:
case StructFieldType_Int4:
case StructFieldType_UInt4:
case StructFieldType::Bool4:
case StructFieldType::Float4:
case StructFieldType::Int4:
case StructFieldType::UInt4:
return 4 * 4;
case StructFieldType_Double1:
case StructFieldType::Double1:
return 8;
case StructFieldType_Double2:
case StructFieldType::Double2:
return 2 * 8;
case StructFieldType_Double3:
case StructFieldType::Double3:
return 3 * 8;
case StructFieldType_Double4:
case StructFieldType::Double4:
return 4 * 8;
}

View File

@@ -11,7 +11,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceParameters.hpp>
@@ -32,12 +31,10 @@ namespace Nz
struct FontGlyph;
using FontConstRef = ObjectRef<const Font>;
using FontLibrary = ObjectLibrary<Font>;
using FontLoader = ResourceLoader<Font, FontParams>;
using FontRef = ObjectRef<Font>;
class NAZARA_UTILITY_API Font : public RefCounted, public Resource
class NAZARA_UTILITY_API Font : public Resource
{
friend FontLibrary;
friend FontLoader;
@@ -85,15 +82,13 @@ namespace Nz
Font& operator=(Font&&) = delete;
static std::shared_ptr<AbstractAtlas> GetDefaultAtlas();
static const FontRef& GetDefault();
static const std::shared_ptr<Font>& GetDefault();
static unsigned int GetDefaultGlyphBorder();
static unsigned int GetDefaultMinimumStepSize();
static FontRef OpenFromFile(const std::filesystem::path& filePath, const FontParams& params = FontParams());
static FontRef OpenFromMemory(const void* data, std::size_t size, const FontParams& params = FontParams());
static FontRef OpenFromStream(Stream& stream, const FontParams& params = FontParams());
template<typename... Args> static FontRef New(Args&&... args);
static std::shared_ptr<Font> OpenFromFile(const std::filesystem::path& filePath, const FontParams& params = FontParams());
static std::shared_ptr<Font> OpenFromMemory(const void* data, std::size_t size, const FontParams& params = FontParams());
static std::shared_ptr<Font> OpenFromStream(Stream& stream, const FontParams& params = FontParams());
static void SetDefaultAtlas(const std::shared_ptr<AbstractAtlas>& atlas);
static void SetDefaultGlyphBorder(unsigned int borderSize);
@@ -154,9 +149,7 @@ namespace Nz
unsigned int m_minimumStepSize;
static std::shared_ptr<AbstractAtlas> s_defaultAtlas;
static FontRef s_defaultFont;
static FontLibrary::LibraryMap s_library;
static FontLoader::LoaderList s_loaders;
static std::shared_ptr<Font> s_defaultFont;
static unsigned int s_defaultGlyphBorder;
static unsigned int s_defaultMinimumStepSize;
};

View File

@@ -2,19 +2,12 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Font.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
template<typename... Args>
FontRef Font::New(Args&&... args)
{
std::unique_ptr<Font> object(new Font(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -27,7 +27,7 @@ namespace Nz
struct NAZARA_UTILITY_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;
PixelFormat loadFormat = PixelFormat::Undefined;
// Le nombre de niveaux de mipmaps maximum devant être créé
UInt8 levelCount = 0;
@@ -37,21 +37,13 @@ namespace Nz
class Image;
using ImageConstRef = ObjectRef<const Image>;
using ImageLibrary = ObjectLibrary<Image>;
using ImageLoader = ResourceLoader<Image, ImageParams>;
using ImageManager = ResourceManager<Image, ImageParams>;
using ImageRef = ObjectRef<Image>;
using ImageSaver = ResourceSaver<Image, ImageParams>;
class NAZARA_UTILITY_API Image : public AbstractImage, public Resource
{
friend ImageLibrary;
friend ImageLoader;
friend ImageManager;
friend ImageSaver;
friend class Utility;
public:
struct SharedImage;
@@ -63,7 +55,7 @@ namespace Nz
bool Convert(PixelFormat format);
void Copy(const Image* source, const Boxui& srcBox, const Vector3ui& dstPos);
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();
@@ -118,23 +110,21 @@ namespace Nz
static UInt8 GetMaxLevel(ImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
// Load
static ImageRef LoadFromFile(const std::filesystem::path& filePath, const ImageParams& params = ImageParams());
static ImageRef LoadFromMemory(const void* data, std::size_t size, const ImageParams& params = ImageParams());
static ImageRef LoadFromStream(Stream& stream, const ImageParams& params = ImageParams());
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());
// LoadArray
static ImageRef LoadArrayFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static ImageRef LoadArrayFromImage(const Image* image, const Vector2ui& atlasSize = Vector2ui(2, 2));
static ImageRef LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static ImageRef LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static std::shared_ptr<Image> LoadArrayFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static std::shared_ptr<Image> LoadArrayFromImage(const Image& image, const Vector2ui& atlasSize = Vector2ui(2, 2));
static std::shared_ptr<Image> LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
static std::shared_ptr<Image> LoadArrayFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const Vector2ui& atlasSize = Vector2ui(2, 2));
// LoadCubemap
static ImageRef LoadCubemapFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
static ImageRef LoadCubemapFromImage(const Image* image, const CubemapParams& params = CubemapParams());
static ImageRef LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
static ImageRef LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
template<typename... Args> static ImageRef New(Args&&... args);
static std::shared_ptr<Image> LoadCubemapFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
static std::shared_ptr<Image> LoadCubemapFromImage(const Image& image, const CubemapParams& params = CubemapParams());
static std::shared_ptr<Image> LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
static std::shared_ptr<Image> LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams = ImageParams(), const CubemapParams& cubemapParams = CubemapParams());
struct SharedImage
{
@@ -163,24 +153,11 @@ namespace Nz
static SharedImage emptyImage;
// Signals:
NazaraSignal(OnImageDestroy, const Image* /*image*/);
NazaraSignal(OnImageRelease, const Image* /*image*/);
private:
void EnsureOwnership();
void ReleaseImage();
static bool Initialize();
static void Uninitialize();
SharedImage* m_sharedImage;
static ImageLibrary::LibraryMap s_library;
static ImageLoader::LoaderList s_loaders;
static ImageManager::ManagerMap s_managerMap;
static ImageManager::ManagerParams s_managerParameters;
static ImageSaver::SaverList s_savers;
};
}

View File

@@ -2,19 +2,12 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Image.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
template<typename... Args>
ImageRef Image::New(Args&&... args)
{
std::unique_ptr<Image> object(new Image(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -8,34 +8,27 @@
#define NAZARA_INDEXBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Utility/Buffer.hpp>
namespace Nz
{
class IndexBuffer;
using IndexBufferConstRef = ObjectRef<const IndexBuffer>;
using IndexBufferRef = ObjectRef<IndexBuffer>;
class NAZARA_UTILITY_API IndexBuffer : public RefCounted
class NAZARA_UTILITY_API IndexBuffer
{
public:
IndexBuffer() = default;
IndexBuffer(bool largeIndices, BufferRef buffer);
IndexBuffer(bool largeIndices, BufferRef buffer, std::size_t offset, std::size_t size);
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer);
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
IndexBuffer(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
IndexBuffer(const IndexBuffer& indexBuffer);
IndexBuffer(IndexBuffer&&) = delete;
~IndexBuffer();
IndexBuffer(const IndexBuffer&) = default;
IndexBuffer(IndexBuffer&&) noexcept = default;
~IndexBuffer() = default;
unsigned int ComputeCacheMissCount() const;
bool Fill(const void* data, std::size_t startIndex, std::size_t length);
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
inline const BufferRef& GetBuffer() const;
inline const std::shared_ptr<Buffer>& GetBuffer() const;
inline std::size_t GetEndOffset() const;
inline std::size_t GetIndexCount() const;
inline std::size_t GetStride() const;
@@ -53,23 +46,18 @@ namespace Nz
void Optimize();
void Reset();
void Reset(bool largeIndices, BufferRef buffer);
void Reset(bool largeIndices, BufferRef buffer, std::size_t offset, std::size_t size);
void Reset(bool largeIndices, std::shared_ptr<Buffer> buffer);
void Reset(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
void Reset(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
void Reset(const IndexBuffer& indexBuffer);
void Unmap() const;
IndexBuffer& operator=(const IndexBuffer& indexBuffer);
IndexBuffer& operator=(IndexBuffer&&) = delete;
template<typename... Args> static IndexBufferRef New(Args&&... args);
// Signals:
NazaraSignal(OnIndexBufferRelease, const IndexBuffer* /*indexBuffer*/);
IndexBuffer& operator=(const IndexBuffer&) = default;
IndexBuffer& operator=(IndexBuffer&&) noexcept = default;
private:
BufferRef m_buffer;
std::shared_ptr<Buffer> m_buffer;
std::size_t m_endOffset;
std::size_t m_indexCount;
std::size_t m_startOffset;

View File

@@ -7,7 +7,7 @@
namespace Nz
{
inline const BufferRef& IndexBuffer::GetBuffer() const
inline const std::shared_ptr<Buffer>& IndexBuffer::GetBuffer() const
{
return m_buffer;
}
@@ -39,7 +39,7 @@ namespace Nz
inline bool IndexBuffer::IsValid() const
{
return m_buffer.IsValid();
return m_buffer != nullptr;
}
inline void* IndexBuffer::Map(BufferAccess access, std::size_t startIndex, std::size_t length)
@@ -53,15 +53,6 @@ namespace Nz
std::size_t stride = GetStride();
return MapRaw(access, startIndex*stride, length*stride);
}
template<typename... Args>
IndexBufferRef IndexBuffer::New(Args&&... args)
{
std::unique_ptr<IndexBuffer> object(new IndexBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -19,10 +19,10 @@ namespace Nz
class NAZARA_UTILITY_API IndexMapper
{
public:
IndexMapper(IndexBuffer* indexBuffer, BufferAccess access = BufferAccess_ReadWrite, std::size_t indexCount = 0);
IndexMapper(SubMesh* subMesh, BufferAccess access = BufferAccess_ReadWrite);
IndexMapper(const IndexBuffer* indexBuffer, BufferAccess access = BufferAccess_ReadOnly, std::size_t indexCount = 0);
IndexMapper(const SubMesh* subMesh, BufferAccess access = BufferAccess_ReadOnly);
IndexMapper(IndexBuffer& indexBuffer, BufferAccess access = BufferAccess::ReadWrite, std::size_t indexCount = 0);
IndexMapper(SubMesh& subMesh, BufferAccess access = BufferAccess::ReadWrite);
IndexMapper(const IndexBuffer& indexBuffer, BufferAccess access = BufferAccess::ReadOnly, std::size_t indexCount = 0);
IndexMapper(const SubMesh& subMesh, BufferAccess access = BufferAccess::ReadOnly);
~IndexMapper() = default;
UInt32 Get(std::size_t i) const;

View File

@@ -9,8 +9,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceManager.hpp>
@@ -35,7 +33,7 @@ namespace Nz
BufferUsageFlags indexBufferFlags = 0; ///< Buffer usage flags used to build the index buffers
BufferUsageFlags vertexBufferFlags = 0; ///< Buffer usage flags used to build the vertex buffers
Matrix4f matrix = Matrix4f::Identity(); ///< A matrix which will transform every vertex position
DataStorage storage = DataStorage_Hardware; ///< The place where the buffers will be allocated
DataStorage storage = DataStorage::Hardware; ///< The place where the buffers will be allocated
Vector2f texCoordOffset = {0.f, 0.f}; ///< Offset to apply on the texture coordinates (not scaled)
Vector2f texCoordScale = {1.f, 1.f}; ///< Scale to apply on the texture coordinates
bool animated = true; ///< If true, will load an animated version of the model if possible
@@ -51,7 +49,7 @@ namespace Nz
* If the declaration has a Vector3f Normals component enabled, Normals are generated.
* If the declaration has a Vector3f Tangents component enabled, Tangents are generated.
*/
VertexDeclaration* vertexDeclaration = VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent);
std::shared_ptr<VertexDeclaration> vertexDeclaration = VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent);
bool IsValid() const;
};
@@ -64,33 +62,25 @@ namespace Nz
using MeshVertex = VertexStruct_XYZ_Normal_UV_Tangent;
using SkeletalMeshVertex = VertexStruct_XYZ_Normal_UV_Tangent_Skinning;
using MeshConstRef = ObjectRef<const Mesh>;
using MeshLibrary = ObjectLibrary<Mesh>;
using MeshLoader = ResourceLoader<Mesh, MeshParams>;
using MeshManager = ResourceManager<Mesh, MeshParams>;
using MeshRef = ObjectRef<Mesh>;
using MeshSaver = ResourceSaver<Mesh, MeshParams>;
struct MeshImpl;
class NAZARA_UTILITY_API Mesh : public RefCounted, public Resource
class NAZARA_UTILITY_API Mesh : public Resource
{
friend MeshLibrary;
friend MeshLoader;
friend MeshManager;
friend MeshSaver;
friend class Utility;
public:
inline Mesh();
Mesh(const Mesh&) = delete;
Mesh(Mesh&&) = delete;
inline ~Mesh();
~Mesh() = default;
void AddSubMesh(SubMesh* subMesh);
void AddSubMesh(const std::string& identifier, SubMesh* subMesh);
void AddSubMesh(std::shared_ptr<SubMesh> subMesh);
void AddSubMesh(const std::string& identifier, std::shared_ptr<SubMesh> subMesh);
SubMesh* BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams());
std::shared_ptr<SubMesh> BuildSubMesh(const Primitive& primitive, const MeshParams& params = MeshParams());
void BuildSubMeshes(const PrimitiveList& list, const MeshParams& params = MeshParams());
bool CreateSkeletal(std::size_t jointCount);
@@ -110,10 +100,8 @@ namespace Nz
std::size_t GetMaterialCount() const;
Skeleton* GetSkeleton();
const Skeleton* GetSkeleton() const;
SubMesh* GetSubMesh(const std::string& identifier);
SubMesh* GetSubMesh(std::size_t index);
const SubMesh* GetSubMesh(const std::string& identifier) const;
const SubMesh* GetSubMesh(std::size_t index) const;
const std::shared_ptr<SubMesh>& GetSubMesh(const std::string& identifier) const;
const std::shared_ptr<SubMesh>& GetSubMesh(std::size_t index) const;
std::size_t GetSubMeshCount() const;
std::size_t GetSubMeshIndex(const std::string& identifier) const;
std::size_t GetTriangleCount() const;
@@ -144,25 +132,22 @@ namespace Nz
Mesh& operator=(const Mesh&) = delete;
Mesh& operator=(Mesh&&) = delete;
static MeshRef LoadFromFile(const std::filesystem::path& filePath, const MeshParams& params = MeshParams());
static MeshRef LoadFromMemory(const void* data, std::size_t size, const MeshParams& params = MeshParams());
static MeshRef LoadFromStream(Stream& stream, const MeshParams& params = MeshParams());
template<typename... Args> static MeshRef New(Args&&... args);
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(OnMeshDestroy, const Mesh* /*mesh*/);
NazaraSignal(OnMeshInvalidateAABB, const Mesh* /*mesh*/);
NazaraSignal(OnMeshRelease, const Mesh* /*mesh*/);
private:
struct SubMeshData
{
SubMeshRef subMesh;
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> m_subMeshMap;
std::vector<ParameterList> m_materialData;
std::vector<SubMeshData> m_subMeshes;
@@ -172,16 +157,6 @@ namespace Nz
std::filesystem::path m_animationPath;
mutable bool m_aabbUpdated;
bool m_isValid;
std::size_t m_jointCount; // Only used by skeletal meshes
static bool Initialize();
static void Uninitialize();
static MeshLibrary::LibraryMap s_library;
static MeshLoader::LoaderList s_loaders;
static MeshManager::ManagerMap s_managerMap;
static MeshManager::ManagerParams s_managerParameters;
static MeshSaver::SaverList s_savers;
};
}

View File

@@ -14,22 +14,6 @@ namespace Nz
m_isValid(false)
{
}
Mesh::~Mesh()
{
OnMeshRelease(this);
Destroy();
}
template<typename... Args>
MeshRef Mesh::New(Args&&... args)
{
std::unique_ptr<Mesh> object(new Mesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -87,9 +87,9 @@ namespace Nz
static bool Initialize();
static void Uninitialize();
static PixelFormatDescription s_pixelFormatInfos[PixelFormat_Max + 1];
static ConvertFunction s_convertFunctions[PixelFormat_Max+1][PixelFormat_Max+1];
static std::map<PixelFormat, FlipFunction> s_flipFunctions[PixelFlipping_Max+1];
static PixelFormatDescription s_pixelFormatInfos[PixelFormatCount];
static ConvertFunction s_convertFunctions[PixelFormatCount][PixelFormatCount];
static std::map<PixelFormat, FlipFunction> s_flipFunctions[PixelFlippingCount];
};
}

View File

@@ -2,7 +2,9 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <array>
#include <cstring>
#include <Nazara/Utility/Debug.hpp>
@@ -10,7 +12,7 @@
namespace Nz
{
inline PixelFormatDescription::PixelFormatDescription() :
content(PixelFormatContent_Undefined),
content(PixelFormatContent::Undefined),
bitsPerPixel(0)
{
}
@@ -74,10 +76,10 @@ namespace Nz
inline bool PixelFormatDescription::IsCompressed() const
{
return redType == PixelFormatSubType_Compressed ||
greenType == PixelFormatSubType_Compressed ||
blueType == PixelFormatSubType_Compressed ||
alphaType == PixelFormatSubType_Compressed;
return redType == PixelFormatSubType::Compressed ||
greenType == PixelFormatSubType::Compressed ||
blueType == PixelFormatSubType::Compressed ||
alphaType == PixelFormatSubType::Compressed;
}
inline bool PixelFormatDescription::IsValid() const
@@ -101,7 +103,7 @@ namespace Nz
if (!IsValid())
return false;
if (content <= PixelFormatContent_Undefined || content > PixelFormatContent_Max)
if (content <= PixelFormatContent::Undefined || content > PixelFormatContent::Max)
return false;
std::array<const Nz::Bitset<>*, 4> masks = { {&redMask, &greenMask, &blueMask, &alphaMask} };
@@ -121,13 +123,13 @@ namespace Nz
switch (types[i])
{
case PixelFormatSubType_Half:
case PixelFormatSubType::Half:
if (usedBits != 16)
return false;
break;
case PixelFormatSubType_Float:
case PixelFormatSubType::Float:
if (usedBits != 32)
return false;
@@ -149,10 +151,10 @@ namespace Nz
{
switch (format)
{
case PixelFormat_DXT1:
case PixelFormat_DXT3:
case PixelFormat_DXT5:
return (((width + 3) / 4) * ((height + 3) / 4) * ((format == PixelFormat_DXT1) ? 8 : 16)) * depth;
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");
@@ -196,7 +198,7 @@ namespace Nz
return true;
}
ConvertFunction func = s_convertFunctions[srcFormat][dstFormat];
ConvertFunction func = s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)];
if (!func)
{
NazaraError("Pixel format conversion from " + GetName(srcFormat) + " to " + GetName(dstFormat) + " is not supported");
@@ -214,7 +216,7 @@ namespace Nz
inline UInt8 PixelFormatInfo::GetBitsPerPixel(PixelFormat format)
{
return s_pixelFormatInfos[format].bitsPerPixel;
return s_pixelFormatInfos[UnderlyingCast(format)].bitsPerPixel;
}
inline UInt8 PixelFormatInfo::GetBytesPerPixel(PixelFormat format)
@@ -224,27 +226,27 @@ namespace Nz
inline PixelFormatContent PixelFormatInfo::GetContent(PixelFormat format)
{
return s_pixelFormatInfos[format].content;
return s_pixelFormatInfos[UnderlyingCast(format)].content;
}
inline const PixelFormatDescription& PixelFormatInfo::GetInfo(PixelFormat format)
{
return s_pixelFormatInfos[format];
return s_pixelFormatInfos[UnderlyingCast(format)];
}
inline const std::string& PixelFormatInfo::GetName(PixelFormat format)
{
return s_pixelFormatInfos[format].name;
return s_pixelFormatInfos[UnderlyingCast(format)].name;
}
inline bool PixelFormatInfo::HasAlpha(PixelFormat format)
{
return s_pixelFormatInfos[format].alphaMask.TestAny();
return s_pixelFormatInfos[UnderlyingCast(format)].alphaMask.TestAny();
}
inline bool PixelFormatInfo::IsCompressed(PixelFormat format)
{
return s_pixelFormatInfos[format].IsCompressed();
return s_pixelFormatInfos[UnderlyingCast(format)].IsCompressed();
}
inline bool PixelFormatInfo::IsConversionSupported(PixelFormat srcFormat, PixelFormat dstFormat)
@@ -252,22 +254,22 @@ namespace Nz
if (srcFormat == dstFormat)
return true;
return s_convertFunctions[srcFormat][dstFormat] != nullptr;
return s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)] != nullptr;
}
inline bool PixelFormatInfo::IsValid(PixelFormat format)
{
return format != PixelFormat_Undefined;
return format != PixelFormat::Undefined;
}
inline void PixelFormatInfo::SetConvertFunction(PixelFormat srcFormat, PixelFormat dstFormat, ConvertFunction func)
{
s_convertFunctions[srcFormat][dstFormat] = func;
s_convertFunctions[UnderlyingCast(srcFormat)][UnderlyingCast(dstFormat)] = func;
}
inline void PixelFormatInfo::SetFlipFunction(PixelFlipping flipping, PixelFormat format, FlipFunction func)
{
s_flipFunctions[flipping][format] = func;
s_flipFunctions[UnderlyingCast(flipping)][format] = func;
}
}

View File

@@ -37,7 +37,7 @@ namespace Nz
inline const Color& GetBlockColor(std::size_t index) const;
inline std::size_t GetBlockCount() const;
inline std::size_t GetBlockFirstGlyphIndex(std::size_t index) const;
inline const FontRef& GetBlockFont(std::size_t index) const;
inline const std::shared_ptr<Font>& GetBlockFont(std::size_t index) const;
inline float GetBlockLineHeight(std::size_t index) const;
inline float GetBlockLineSpacingOffset(std::size_t index) const;
inline const Color& GetBlockOutlineColor(std::size_t index) const;
@@ -50,12 +50,12 @@ namespace Nz
inline unsigned int GetDefaultCharacterSize() const;
inline float GetDefaultCharacterSpacingOffset() const;
inline const Color& GetDefaultColor() const;
inline const FontRef& GetDefaultFont() const;
inline const std::shared_ptr<Font>& GetDefaultFont() const;
inline float GetDefaultLineSpacingOffset() const;
inline const Color& GetDefaultOutlineColor() const;
inline float GetDefaultOutlineThickness() const;
inline TextStyleFlags GetDefaultStyle() const;
Font* GetFont(std::size_t index) const override;
const std::shared_ptr<Font>& GetFont(std::size_t index) const override;
std::size_t GetFontCount() const override;
const Glyph& GetGlyph(std::size_t index) const override;
std::size_t GetGlyphCount() const override;
@@ -72,7 +72,7 @@ namespace Nz
inline void SetBlockCharacterSize(std::size_t index, unsigned int characterSize);
inline void SetBlockCharacterSpacingOffset(std::size_t index, float offset);
inline void SetBlockColor(std::size_t index, const Color& color);
inline void SetBlockFont(std::size_t index, FontRef font);
inline void SetBlockFont(std::size_t index, std::shared_ptr<Font> font);
inline void SetBlockLineSpacingOffset(std::size_t index, float offset);
inline void SetBlockOutlineColor(std::size_t index, const Color& color);
inline void SetBlockOutlineThickness(std::size_t index, float thickness);
@@ -82,7 +82,7 @@ namespace Nz
inline void SetDefaultCharacterSize(unsigned int characterSize);
inline void SetDefaultCharacterSpacingOffset(float offset);
inline void SetDefaultColor(const Color& color);
inline void SetDefaultFont(const FontRef& font);
inline void SetDefaultFont(const std::shared_ptr<Font>& font);
inline void SetDefaultLineSpacingOffset(float offset);
inline void SetDefaultOutlineColor(const Color& color);
inline void SetDefaultOutlineThickness(float thickness);
@@ -98,16 +98,16 @@ namespace Nz
private:
struct Block;
inline void AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset) const;
void AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset, std::size_t glyphIndex, float glyphPosition) const;
inline void AppendNewLine(const Font& font, unsigned int characterSize, float lineSpacingOffset) const;
void AppendNewLine(const Font& font, unsigned int characterSize, float lineSpacingOffset, std::size_t glyphIndex, float glyphPosition) const;
inline void ClearGlyphs() const;
inline void ConnectFontSlots();
inline void DisconnectFontSlots();
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, const Font* font, const Color& color, TextStyleFlags style, float lineSpacingOffset, unsigned int characterSize, int renderOrder, int* advance) const;
void GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const std::string& text) const;
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, const Font& font, const Color& color, TextStyleFlags style, float lineSpacingOffset, unsigned int characterSize, int renderOrder, int* advance) const;
void GenerateGlyphs(const Font& font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const std::string& text) const;
inline float GetLineHeight(const Block& block) const;
inline float GetLineHeight(float lineSpacingOffset, const Font::SizeInfo& sizeInfo) const;
inline std::size_t HandleFontAddition(const FontRef& font);
inline std::size_t HandleFontAddition(const std::shared_ptr<Font>& font);
inline void InvalidateGlyphs();
inline void ReleaseFont(std::size_t fontIndex);
inline bool ShouldLineWrap(float size) const;
@@ -136,7 +136,7 @@ namespace Nz
struct FontData
{
FontRef font;
std::shared_ptr<Font> font;
std::size_t useCount = 0;
NazaraSlot(Font, OnFontAtlasChanged, atlasChangedSlot);
@@ -148,9 +148,9 @@ namespace Nz
Color m_defaultColor;
Color m_defaultOutlineColor;
TextStyleFlags m_defaultStyle;
FontRef m_defaultFont;
std::shared_ptr<Font> m_defaultFont;
mutable std::size_t m_lastSeparatorGlyph;
std::unordered_map<FontRef, std::size_t> m_fontIndexes;
std::unordered_map<std::shared_ptr<Font>, std::size_t> m_fontIndexes;
std::vector<Block> m_blocks;
std::vector<FontData> m_fonts;
mutable std::vector<Glyph> m_glyphs;
@@ -179,7 +179,7 @@ namespace Nz
inline unsigned int GetCharacterSize() const;
inline Color GetColor() const;
inline std::size_t GetFirstGlyphIndex() const;
inline const FontRef& GetFont() const;
inline const std::shared_ptr<Font>& GetFont() const;
inline float GetLineSpacingOffset() const;
inline Color GetOutlineColor() const;
inline float GetOutlineThickness() const;
@@ -189,7 +189,7 @@ namespace Nz
inline void SetCharacterSpacingOffset(float offset);
inline void SetCharacterSize(unsigned int size);
inline void SetColor(Color color);
inline void SetFont(FontRef font);
inline void SetFont(std::shared_ptr<Font> font);
inline void SetLineSpacingOffset(float offset);
inline void SetOutlineColor(Color color);
inline void SetOutlineThickness(float thickness);

View File

@@ -80,7 +80,7 @@ namespace Nz
return m_blocks[index].glyphIndex;
}
inline const FontRef& RichTextDrawer::GetBlockFont(std::size_t index) const
inline const std::shared_ptr<Font>& RichTextDrawer::GetBlockFont(std::size_t index) const
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
std::size_t fontIndex = m_blocks[index].fontIndex;
@@ -139,7 +139,7 @@ namespace Nz
return m_defaultColor;
}
inline const FontRef& RichTextDrawer::GetDefaultFont() const
inline const std::shared_ptr<Font>& RichTextDrawer::GetDefaultFont() const
{
return m_defaultFont;
}
@@ -164,7 +164,7 @@ namespace Nz
return m_defaultStyle;
}
inline void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset) const
inline void RichTextDrawer::AppendNewLine(const Font& font, unsigned int characterSize, float lineSpacingOffset) const
{
AppendNewLine(font, characterSize, lineSpacingOffset, InvalidGlyph, 0);
}
@@ -214,7 +214,7 @@ namespace Nz
return float(sizeInfo.lineHeight) + lineSpacingOffset;
}
inline std::size_t RichTextDrawer::HandleFontAddition(const FontRef& font)
inline std::size_t RichTextDrawer::HandleFontAddition(const std::shared_ptr<Font>& font)
{
auto it = m_fontIndexes.find(font);
if (it == m_fontIndexes.end())
@@ -292,7 +292,7 @@ namespace Nz
InvalidateGlyphs();
}
inline void RichTextDrawer::SetBlockFont(std::size_t index, FontRef font)
inline void RichTextDrawer::SetBlockFont(std::size_t index, std::shared_ptr<Font> font)
{
NazaraAssert(index < m_blocks.size(), "Invalid block index");
std::size_t fontIndex = HandleFontAddition(font);
@@ -375,7 +375,7 @@ namespace Nz
m_defaultColor = color;
}
inline void RichTextDrawer::SetDefaultFont(const FontRef& font)
inline void RichTextDrawer::SetDefaultFont(const std::shared_ptr<Font>& font)
{
m_defaultFont = font;
}
@@ -457,7 +457,7 @@ namespace Nz
*
* \see GetCharacterSize, GetColor, GetStyle, GetText, SetFont
*/
inline const FontRef& RichTextDrawer::BlockRef::GetFont() const
inline const std::shared_ptr<Font>& RichTextDrawer::BlockRef::GetFont() const
{
return m_drawer.GetBlockFont(m_blockIndex);
}
@@ -567,7 +567,7 @@ namespace Nz
*
* \see GetCharacterSize, SetCharacterSize, SetColor, SetStyle, SetText
*/
inline void RichTextDrawer::BlockRef::SetFont(FontRef font)
inline void RichTextDrawer::BlockRef::SetFont(std::shared_ptr<Font> font)
{
m_drawer.SetBlockFont(m_blockIndex, std::move(font));
}

View File

@@ -31,8 +31,8 @@ namespace Nz
inline float GetCharacterSpacingOffset() const;
inline unsigned int GetCharacterSize() const;
inline const Color& GetColor() const;
inline Font* GetFont() const;
Font* GetFont(std::size_t index) const override;
inline const std::shared_ptr<Font>& GetFont() const;
const std::shared_ptr<Font>& GetFont(std::size_t index) const override;
std::size_t GetFontCount() const override;
const Glyph& GetGlyph(std::size_t index) const override;
std::size_t GetGlyphCount() const override;
@@ -49,7 +49,7 @@ namespace Nz
inline void SetCharacterSpacingOffset(float offset);
inline void SetCharacterSize(unsigned int characterSize);
inline void SetColor(const Color& color);
inline void SetFont(Font* font);
inline void SetFont(std::shared_ptr<Font> font);
inline void SetLineSpacingOffset(float offset);
inline void SetMaxLineWidth(float lineWidth) override;
inline void SetOutlineColor(const Color& color);
@@ -62,8 +62,8 @@ namespace Nz
static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
static inline SimpleTextDrawer Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
static inline SimpleTextDrawer Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
static inline SimpleTextDrawer Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
static inline SimpleTextDrawer Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
private:
inline void AppendNewLine() const;
@@ -104,7 +104,7 @@ namespace Nz
std::string m_text;
Color m_color;
Color m_outlineColor;
FontRef m_font;
std::shared_ptr<Font> m_font;
mutable Rectf m_bounds;
TextStyleFlags m_style;
mutable UInt32 m_previousCharacter;

View File

@@ -65,7 +65,7 @@ namespace Nz
return m_color;
}
inline Font* SimpleTextDrawer::GetFont() const
inline const std::shared_ptr<Font>& SimpleTextDrawer::GetFont() const
{
return m_font;
}
@@ -131,11 +131,11 @@ namespace Nz
}
}
inline void SimpleTextDrawer::SetFont(Font* font)
inline void SimpleTextDrawer::SetFont(std::shared_ptr<Font> font)
{
if (m_font != font)
{
m_font = font;
m_font = std::move(font);
if (m_font)
ConnectFontSlots();
@@ -281,7 +281,7 @@ namespace Nz
return drawer;
}
inline SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color)
inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color)
{
SimpleTextDrawer drawer;
drawer.SetCharacterSize(characterSize);
@@ -293,7 +293,7 @@ namespace Nz
return drawer;
}
inline SimpleTextDrawer SimpleTextDrawer::Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor)
inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor)
{
SimpleTextDrawer drawer;
drawer.SetCharacterSize(characterSize);

View File

@@ -8,56 +8,34 @@
#define NAZARA_SKELETALMESH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
namespace Nz
{
class SkeletalMesh;
using SkeletalMeshConstRef = ObjectRef<const SkeletalMesh>;
using SkeletalMeshRef = ObjectRef<SkeletalMesh>;
class NAZARA_UTILITY_API SkeletalMesh final : public SubMesh
{
public:
SkeletalMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer);
NAZARA_DEPRECATED("SkeletalMesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
SkeletalMesh(const Mesh* parent);
~SkeletalMesh();
NAZARA_DEPRECATED("SkeletalMesh create/destroy functions are deprecated, please use constructor")
bool Create(VertexBuffer* vertexBuffer);
void Destroy();
SkeletalMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer);
~SkeletalMesh() = default;
const Boxf& GetAABB() const override;
AnimationType GetAnimationType() const final;
const IndexBuffer* GetIndexBuffer() const override;
VertexBuffer* GetVertexBuffer();
const VertexBuffer* GetVertexBuffer() const;
const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const override;
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
std::size_t GetVertexCount() const override;
bool IsAnimated() const final;
bool IsValid() const;
void SetAABB(const Boxf& aabb);
void SetIndexBuffer(const IndexBuffer* indexBuffer);
template<typename... Args> static SkeletalMeshRef New(Args&&... args);
// Signals:
NazaraSignal(OnSkeletalMeshDestroy, const SkeletalMesh* /*skeletalMesh*/);
NazaraSignal(OnSkeletalMeshRelease, const SkeletalMesh* /*skeletalMesh*/);
void SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer);
private:
Boxf m_aabb;
IndexBufferConstRef m_indexBuffer;
VertexBufferRef m_vertexBuffer;
std::shared_ptr<const IndexBuffer> m_indexBuffer;
std::shared_ptr<VertexBuffer> m_vertexBuffer;
};
}

View File

@@ -2,19 +2,12 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/SkeletalMesh.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
template<typename... Args>
SkeletalMeshRef SkeletalMesh::New(Args&&... args)
{
std::unique_ptr<SkeletalMesh> object(new SkeletalMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -9,8 +9,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Config.hpp>
@@ -21,21 +19,18 @@ namespace Nz
class Joint;
class Skeleton;
using SkeletonConstRef = ObjectRef<const Skeleton>;
using SkeletonLibrary = ObjectLibrary<Skeleton>;
using SkeletonRef = ObjectRef<Skeleton>;
struct SkeletonImpl;
class NAZARA_UTILITY_API Skeleton : public RefCounted
class NAZARA_UTILITY_API Skeleton
{
friend Joint;
friend SkeletonLibrary;
friend class Utility;
public:
Skeleton() = default;
Skeleton();
Skeleton(const Skeleton& skeleton);
Skeleton(Skeleton&&) noexcept;
~Skeleton();
bool Create(std::size_t jointCount);
@@ -49,33 +44,25 @@ namespace Nz
Joint* GetJoints();
const Joint* GetJoints() const;
std::size_t GetJointCount() const;
int GetJointIndex(const std::string& jointName) const;
std::size_t GetJointIndex(const std::string& jointName) const;
void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation);
void Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, std::size_t* indices, std::size_t indiceCount);
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);
template<typename... Args> static SkeletonRef New(Args&&... args);
Skeleton& operator=(Skeleton&&) noexcept;
// Signals:
NazaraSignal(OnSkeletonDestroy, const Skeleton* /*skeleton*/);
NazaraSignal(OnSkeletonJointsInvalidated, const Skeleton* /*skeleton*/);
NazaraSignal(OnSkeletonRelease, const Skeleton* /*skeleton*/);
private:
void InvalidateJoints();
void InvalidateJointMap();
void UpdateJointMap() const;
static bool Initialize();
static void Uninitialize();
SkeletonImpl* m_impl = nullptr;
static SkeletonLibrary::LibraryMap s_library;
std::unique_ptr<SkeletonImpl> m_impl;
};
}

View File

@@ -7,14 +7,6 @@
namespace Nz
{
template<typename... Args>
SkeletonRef Skeleton::New(Args&&... args)
{
std::unique_ptr<Skeleton> object(new Skeleton(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -8,57 +8,36 @@
#define NAZARA_STATICMESH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Utility/SubMesh.hpp>
namespace Nz
{
class StaticMesh;
using StaticMeshConstRef = ObjectRef<const StaticMesh>;
using StaticMeshRef = ObjectRef<StaticMesh>;
class NAZARA_UTILITY_API StaticMesh final : public SubMesh
{
public:
StaticMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer);
NAZARA_DEPRECATED("StaticMesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
StaticMesh(const Mesh* parent);
~StaticMesh();
StaticMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer);
~StaticMesh() = default;
void Center();
NAZARA_DEPRECATED("StaticMesh create/destroy functions are deprecated, please use constructor")
bool Create(VertexBuffer* vertexBuffer);
void Destroy();
bool GenerateAABB();
const Boxf& GetAABB() const override;
AnimationType GetAnimationType() const final;
const IndexBuffer* GetIndexBuffer() const override;
VertexBuffer* GetVertexBuffer();
const VertexBuffer* GetVertexBuffer() const;
const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const override;
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
std::size_t GetVertexCount() const override;
bool IsAnimated() const final;
bool IsValid() const;
void SetAABB(const Boxf& aabb);
void SetIndexBuffer(const IndexBuffer* indexBuffer);
template<typename... Args> static StaticMeshRef New(Args&&... args);
// Signals:
NazaraSignal(OnStaticMeshDestroy, const StaticMesh* /*staticMesh*/);
NazaraSignal(OnStaticMeshRelease, const StaticMesh* /*staticMesh*/);
void SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer);
private:
Boxf m_aabb;
IndexBufferConstRef m_indexBuffer;
VertexBufferRef m_vertexBuffer;
std::shared_ptr<const IndexBuffer> m_indexBuffer;
std::shared_ptr<VertexBuffer> m_vertexBuffer;
};
}

View File

@@ -7,14 +7,6 @@
namespace Nz
{
template<typename... Args>
StaticMeshRef StaticMesh::New(Args&&... args)
{
std::unique_ptr<StaticMesh> object(new StaticMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -8,8 +8,7 @@
#define NAZARA_SUBMESH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
@@ -18,21 +17,13 @@
namespace Nz
{
class Mesh;
class SubMesh;
using SubMeshConstRef = ObjectRef<const SubMesh>;
using SubMeshRef = ObjectRef<SubMesh>;
class NAZARA_UTILITY_API SubMesh : public RefCounted
class NAZARA_UTILITY_API SubMesh
{
friend Mesh;
public:
SubMesh();
NAZARA_DEPRECATED("Submesh constructor taking a mesh is deprecated, submeshes no longer require to be part of a single mesh")
SubMesh(const Mesh* parent);
SubMesh(const SubMesh&) = delete;
SubMesh(SubMesh&&) = delete;
virtual ~SubMesh();
@@ -43,7 +34,7 @@ namespace Nz
virtual const Boxf& GetAABB() const = 0;
virtual AnimationType GetAnimationType() const = 0;
virtual const IndexBuffer* GetIndexBuffer() const = 0;
virtual const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const = 0;
std::size_t GetMaterialIndex() const;
PrimitiveMode GetPrimitiveMode() const;
std::size_t GetTriangleCount() const;
@@ -59,7 +50,6 @@ namespace Nz
// Signals:
NazaraSignal(OnSubMeshInvalidateAABB, const SubMesh* /*subMesh*/);
NazaraSignal(OnSubMeshRelease, const SubMesh* /*subMesh*/);
protected:
PrimitiveMode m_primitiveMode;

View File

@@ -18,8 +18,8 @@ namespace Nz
class NAZARA_UTILITY_API TriangleIterator
{
public:
TriangleIterator(PrimitiveMode primitiveMode, const IndexBuffer* indexBuffer);
TriangleIterator(const SubMesh* subMesh);
TriangleIterator(PrimitiveMode primitiveMode, const IndexBuffer& indexBuffer);
TriangleIterator(const SubMesh& subMesh);
~TriangleIterator() = default;
bool Advance();

View File

@@ -8,31 +8,24 @@
#define NAZARA_UNIFORMBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Utility/Buffer.hpp>
namespace Nz
{
class UniformBuffer;
using UniformBufferConstRef = ObjectRef<const UniformBuffer>;
using UniformBufferRef = ObjectRef<UniformBuffer>;
class NAZARA_UTILITY_API UniformBuffer : public RefCounted
class NAZARA_UTILITY_API UniformBuffer
{
public:
UniformBuffer() = default;
UniformBuffer(BufferRef buffer);
UniformBuffer(BufferRef buffer, UInt32 offset, UInt32 size);
UniformBuffer(std::shared_ptr<Buffer> buffer);
UniformBuffer(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size);
UniformBuffer(UInt32 length, DataStorage storage, BufferUsageFlags usage);
UniformBuffer(const UniformBuffer& uniformBuffer);
UniformBuffer(UniformBuffer&&) = delete;
~UniformBuffer();
UniformBuffer(const UniformBuffer&) = default;
UniformBuffer(UniformBuffer&&) noexcept = default;
~UniformBuffer() = default;
bool Fill(const void* data, UInt32 offset, UInt32 size);
inline const BufferRef& GetBuffer() const;
inline const std::shared_ptr<Buffer>& GetBuffer() const;
inline UInt32 GetEndOffset() const;
inline UInt32 GetStartOffset() const;
@@ -42,23 +35,18 @@ namespace Nz
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
void Reset();
void Reset(BufferRef buffer);
void Reset(BufferRef buffer, UInt32 offset, UInt32 size);
void Reset(std::shared_ptr<Buffer> buffer);
void Reset(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size);
void Reset(UInt32 size, DataStorage storage, BufferUsageFlags usage);
void Reset(const UniformBuffer& uniformBuffer);
void Unmap() const;
UniformBuffer& operator=(const UniformBuffer& uniformBuffer);
UniformBuffer& operator=(UniformBuffer&&) = delete;
template<typename... Args> static UniformBufferRef New(Args&&... args);
// Signals:
NazaraSignal(OnUniformBufferRelease, const UniformBuffer* /*UniformBuffer*/);
UniformBuffer& operator=(const UniformBuffer&) = default;
UniformBuffer& operator=(UniformBuffer&&) noexcept = default;
private:
BufferRef m_buffer;
std::shared_ptr<Buffer> m_buffer;
UInt32 m_endOffset;
UInt32 m_startOffset;
};

View File

@@ -8,7 +8,7 @@
namespace Nz
{
inline const BufferRef& UniformBuffer::GetBuffer() const
inline const std::shared_ptr<Buffer>& UniformBuffer::GetBuffer() const
{
return m_buffer;
}
@@ -25,16 +25,7 @@ namespace Nz
inline bool UniformBuffer::IsValid() const
{
return m_buffer.IsValid();
}
template<typename... Args>
UniformBufferRef UniformBuffer::New(Args&&... args)
{
std::unique_ptr<UniformBuffer> object(new UniformBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
return m_buffer != nullptr;
}
}

View File

@@ -9,7 +9,11 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Font.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/Mesh.hpp>
namespace Nz
{
@@ -23,9 +27,34 @@ namespace Nz
struct Config {};
Utility(Config /*config*/);
Utility(const Utility&) = delete;
Utility(Utility&&) = delete;
~Utility();
AnimationLoader& GetAnimationLoader();
const AnimationLoader& GetAnimationLoader() const;
FontLoader& GetFontLoader();
const FontLoader& GetFontLoader() const;
ImageLoader& GetImageLoader();
const ImageLoader& GetImageLoader() const;
ImageSaver& GetImageSaver();
const ImageSaver& GetImageSaver() const;
MeshLoader& GetMeshLoader();
const MeshLoader& GetMeshLoader() const;
MeshSaver& GetMeshSaver();
const MeshSaver& GetMeshSaver() const;
Utility& operator=(const Utility&) = delete;
Utility& operator=(Utility&&) = delete;
private:
AnimationLoader m_animationLoader;
FontLoader m_fontLoader;
ImageLoader m_imageLoader;
ImageSaver m_imageSaver;
MeshLoader m_meshLoader;
MeshSaver m_meshSaver;
static Utility* s_instance;
};
}

View File

@@ -8,39 +8,31 @@
#define NAZARA_VERTEXBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
namespace Nz
{
class VertexBuffer;
using VertexBufferConstRef = ObjectRef<VertexBuffer>;
using VertexBufferRef = ObjectRef<VertexBuffer>;
class NAZARA_UTILITY_API VertexBuffer : public RefCounted
class NAZARA_UTILITY_API VertexBuffer
{
public:
VertexBuffer() = default;
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer);
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, std::size_t offset, std::size_t size);
VertexBuffer(VertexDeclarationConstRef vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
VertexBuffer(const VertexBuffer& vertexBuffer);
VertexBuffer(VertexBuffer&&) = delete;
~VertexBuffer();
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
VertexBuffer(const VertexBuffer&) = default;
VertexBuffer(VertexBuffer&&) noexcept = default;
~VertexBuffer() = default;
bool Fill(const void* data, std::size_t startVertex, std::size_t length);
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
inline const BufferRef& GetBuffer() const;
inline const std::shared_ptr<Buffer>& GetBuffer() const;
inline std::size_t GetEndOffset() const;
inline std::size_t GetStartOffset() const;
inline std::size_t GetStride() const;
inline std::size_t GetVertexCount() const;
inline const VertexDeclarationConstRef& GetVertexDeclaration() const;
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration() const;
inline bool IsValid() const;
@@ -50,29 +42,24 @@ namespace Nz
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0) const;
void Reset();
void Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer);
void Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, std::size_t offset, std::size_t size);
void Reset(VertexDeclarationConstRef vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
void Reset(const VertexBuffer& vertexBuffer);
void SetVertexDeclaration(VertexDeclarationConstRef vertexDeclaration);
void SetVertexDeclaration(std::shared_ptr<const VertexDeclaration> vertexDeclaration);
void Unmap() const;
VertexBuffer& operator=(const VertexBuffer& vertexBuffer);
VertexBuffer& operator=(VertexBuffer&&) = delete;
template<typename... Args> static VertexBufferRef New(Args&&... args);
// Signals:
NazaraSignal(OnVertexBufferRelease, const VertexBuffer* /*vertexBuffer*/);
VertexBuffer& operator=(const VertexBuffer&) = default;
VertexBuffer& operator=(VertexBuffer&&) noexcept = default;
private:
BufferRef m_buffer;
std::shared_ptr<Buffer> m_buffer;
std::shared_ptr<const VertexDeclaration> m_vertexDeclaration;
std::size_t m_endOffset;
std::size_t m_startOffset;
std::size_t m_vertexCount;
VertexDeclarationConstRef m_vertexDeclaration;
};
}

View File

@@ -2,12 +2,13 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/VertexBuffer.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
{
inline const BufferRef& VertexBuffer::GetBuffer() const
inline const std::shared_ptr<Buffer>& VertexBuffer::GetBuffer() const
{
return m_buffer;
}
@@ -32,23 +33,14 @@ namespace Nz
return m_vertexCount;
}
inline const VertexDeclarationConstRef& VertexBuffer::GetVertexDeclaration() const
inline const std::shared_ptr<const VertexDeclaration>& VertexBuffer::GetVertexDeclaration() const
{
return m_vertexDeclaration;
}
inline bool VertexBuffer::IsValid() const
{
return m_buffer.IsValid() && m_vertexDeclaration.IsValid();
}
template<typename... Args>
VertexBufferRef VertexBuffer::New(Args&&... args)
{
std::unique_ptr<VertexBuffer> object(new VertexBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
return m_buffer && m_vertexDeclaration;
}
}

View File

@@ -9,8 +9,6 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
@@ -20,11 +18,9 @@ namespace Nz
{
class VertexDeclaration;
using VertexDeclarationConstRef = ObjectRef<const VertexDeclaration>;
using VertexDeclarationLibrary = ObjectLibrary<VertexDeclaration>;
using VertexDeclarationRef = ObjectRef<VertexDeclaration>;
class NAZARA_UTILITY_API VertexDeclaration : public RefCounted
class NAZARA_UTILITY_API VertexDeclaration
{
friend VertexDeclarationLibrary;
friend class Utility;
@@ -54,9 +50,8 @@ namespace Nz
VertexDeclaration& operator=(const VertexDeclaration&) = delete;
VertexDeclaration& operator=(VertexDeclaration&&) = delete;
static inline const VertexDeclarationRef& Get(VertexLayout layout);
static inline const std::shared_ptr<VertexDeclaration>& Get(VertexLayout layout);
static bool IsTypeSupported(ComponentType type);
template<typename... Args> static VertexDeclarationRef New(Args&&... args);
struct Component
{
@@ -81,8 +76,7 @@ namespace Nz
std::size_t m_stride;
VertexInputRate m_inputRate;
static std::array<VertexDeclarationRef, VertexLayout_Max + 1> s_declarations;
static VertexDeclarationLibrary::LibraryMap s_library;
static std::array<std::shared_ptr<VertexDeclaration>, VertexLayoutCount> s_declarations;
};
}

View File

@@ -12,7 +12,7 @@ namespace Nz
{
inline auto VertexDeclaration::FindComponent(VertexComponent vertexComponent, std::size_t componentIndex) const -> const Component*
{
assert(componentIndex == 0 || vertexComponent == VertexComponent_Userdata);
assert(componentIndex == 0 || vertexComponent == VertexComponent::Userdata);
for (const Component& component : m_components)
{
@@ -56,7 +56,7 @@ namespace Nz
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");
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)
@@ -72,20 +72,11 @@ namespace Nz
return GetComponentByType<T>(vertexComponent, componentIndex) != nullptr;
}
inline const VertexDeclarationRef& VertexDeclaration::Get(VertexLayout layout)
inline const std::shared_ptr<VertexDeclaration>& VertexDeclaration::Get(VertexLayout layout)
{
NazaraAssert(layout <= VertexLayout_Max, "Vertex layout out of enum");
NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum");
return s_declarations[layout];
}
template<typename... Args>
VertexDeclarationRef VertexDeclaration::New(Args&&... args)
{
std::unique_ptr<VertexDeclaration> object = std::make_unique<VertexDeclaration>(std::forward<Args>(args)...);
object->SetPersistent(false);
return object.release();
return s_declarations[UnderlyingCast(layout)];
}
}

View File

@@ -20,10 +20,10 @@ namespace Nz
class NAZARA_UTILITY_API VertexMapper
{
public:
VertexMapper(SubMesh* subMesh, BufferAccess access = BufferAccess_ReadWrite);
VertexMapper(VertexBuffer* vertexBuffer, BufferAccess access = BufferAccess_ReadWrite);
VertexMapper(const SubMesh* subMesh, BufferAccess access = BufferAccess_ReadOnly);
VertexMapper(const VertexBuffer* vertexBuffer, BufferAccess access = BufferAccess_ReadOnly);
VertexMapper(SubMesh& subMesh, BufferAccess access = BufferAccess::ReadWrite);
VertexMapper(VertexBuffer& vertexBuffer, BufferAccess access = BufferAccess::ReadWrite);
VertexMapper(const SubMesh& subMesh, BufferAccess access = BufferAccess::ReadOnly);
VertexMapper(const VertexBuffer& vertexBuffer, BufferAccess access = BufferAccess::ReadOnly);
~VertexMapper();
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component, std::size_t componentIndex = 0);

View File

@@ -13,7 +13,7 @@ namespace Nz
SparsePtr<T> VertexMapper::GetComponentPtr(VertexComponent component, std::size_t componentIndex)
{
// On récupère la déclaration depuis le buffer
const VertexDeclaration* declaration = m_mapper.GetBuffer()->GetVertexDeclaration();
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());

View File

@@ -14,12 +14,12 @@ namespace Nz
{
switch (format)
{
case VK_FORMAT_B8G8R8A8_UNORM: return PixelFormat::PixelFormat_BGRA8;
case VK_FORMAT_B8G8R8A8_SRGB: return PixelFormat::PixelFormat_BGRA8_SRGB;
case VK_FORMAT_D24_UNORM_S8_UINT: return PixelFormat::PixelFormat_Depth24Stencil8;
case VK_FORMAT_D32_SFLOAT: return PixelFormat::PixelFormat_Depth32;
case VK_FORMAT_R8G8B8A8_UNORM: return PixelFormat::PixelFormat_RGBA8;
case VK_FORMAT_R8G8B8A8_SRGB: return PixelFormat::PixelFormat_RGBA8_SRGB;
case VK_FORMAT_B8G8R8A8_UNORM: return PixelFormat::BGRA8;
case VK_FORMAT_B8G8R8A8_SRGB: return PixelFormat::BGRA8_SRGB;
case VK_FORMAT_D24_UNORM_S8_UINT: return PixelFormat::Depth24Stencil8;
case VK_FORMAT_D32_SFLOAT: return PixelFormat::Depth32;
case VK_FORMAT_R8G8B8A8_UNORM: return PixelFormat::RGBA8;
case VK_FORMAT_R8G8B8A8_SRGB: return PixelFormat::RGBA8_SRGB;
default: break;
}
@@ -94,12 +94,12 @@ namespace Nz
{
switch (bufferType)
{
case BufferType_Index: return VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
case BufferType_Vertex: return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
case BufferType_Uniform: return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
case BufferType::Index: return VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
case BufferType::Vertex: return VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
case BufferType::Uniform: return VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
}
NazaraError("Unhandled BufferType 0x" + NumberToString(bufferType, 16));
NazaraError("Unhandled BufferType 0x" + NumberToString(UnderlyingCast(bufferType), 16));
return 0;
}
@@ -107,23 +107,23 @@ namespace Nz
{
switch (componentType)
{
case ComponentType_Color: return VK_FORMAT_R8G8B8A8_UINT;
case ComponentType_Double1: return VK_FORMAT_R64_SFLOAT;
case ComponentType_Double2: return VK_FORMAT_R64G64_SFLOAT;
case ComponentType_Double3: return VK_FORMAT_R64G64B64_SFLOAT;
case ComponentType_Double4: return VK_FORMAT_R64G64B64A64_SFLOAT;
case ComponentType_Float1: return VK_FORMAT_R32_SFLOAT;
case ComponentType_Float2: return VK_FORMAT_R32G32_SFLOAT;
case ComponentType_Float3: return VK_FORMAT_R32G32B32_SFLOAT;
case ComponentType_Float4: return VK_FORMAT_R32G32B32A32_SFLOAT;
case ComponentType_Int1: return VK_FORMAT_R32_SINT;
case ComponentType_Int2: return VK_FORMAT_R32G32_SINT;
case ComponentType_Int3: return VK_FORMAT_R32G32B32_SINT;
case ComponentType_Int4: return VK_FORMAT_R32G32B32A32_SINT;
case ComponentType_Quaternion: return VK_FORMAT_R32G32B32A32_SFLOAT;
case ComponentType::Color: return VK_FORMAT_R8G8B8A8_UINT;
case ComponentType::Double1: return VK_FORMAT_R64_SFLOAT;
case ComponentType::Double2: return VK_FORMAT_R64G64_SFLOAT;
case ComponentType::Double3: return VK_FORMAT_R64G64B64_SFLOAT;
case ComponentType::Double4: return VK_FORMAT_R64G64B64A64_SFLOAT;
case ComponentType::Float1: return VK_FORMAT_R32_SFLOAT;
case ComponentType::Float2: return VK_FORMAT_R32G32_SFLOAT;
case ComponentType::Float3: return VK_FORMAT_R32G32B32_SFLOAT;
case ComponentType::Float4: return VK_FORMAT_R32G32B32A32_SFLOAT;
case ComponentType::Int1: return VK_FORMAT_R32_SINT;
case ComponentType::Int2: return VK_FORMAT_R32G32_SINT;
case ComponentType::Int3: return VK_FORMAT_R32G32B32_SINT;
case ComponentType::Int4: return VK_FORMAT_R32G32B32A32_SINT;
case ComponentType::Quaternion: return VK_FORMAT_R32G32B32A32_SFLOAT;
}
NazaraError("Unhandled ComponentType 0x" + NumberToString(componentType, 16));
NazaraError("Unhandled ComponentType 0x" + NumberToString(UnderlyingCast(componentType), 16));
return VK_FORMAT_UNDEFINED;
}
@@ -131,13 +131,13 @@ namespace Nz
{
switch (faceSide)
{
case FaceSide_None: return VK_CULL_MODE_NONE;
case FaceSide_Back: return VK_CULL_MODE_BACK_BIT;
case FaceSide_Front: return VK_CULL_MODE_FRONT_BIT;
case FaceSide_FrontAndBack: return VK_CULL_MODE_FRONT_AND_BACK;
case FaceSide::None: return VK_CULL_MODE_NONE;
case FaceSide::Back: return VK_CULL_MODE_BACK_BIT;
case FaceSide::Front: return VK_CULL_MODE_FRONT_BIT;
case FaceSide::FrontAndBack: return VK_CULL_MODE_FRONT_AND_BACK;
}
NazaraError("Unhandled FaceSide 0x" + NumberToString(faceSide, 16));
NazaraError("Unhandled FaceSide 0x" + NumberToString(UnderlyingCast(faceSide), 16));
return VK_CULL_MODE_BACK_BIT;
}
@@ -145,12 +145,12 @@ namespace Nz
{
switch (faceFilling)
{
case FaceFilling_Fill: return VK_POLYGON_MODE_FILL;
case FaceFilling_Line: return VK_POLYGON_MODE_LINE;
case FaceFilling_Point: return VK_POLYGON_MODE_POINT;
case FaceFilling::Fill: return VK_POLYGON_MODE_FILL;
case FaceFilling::Line: return VK_POLYGON_MODE_LINE;
case FaceFilling::Point: return VK_POLYGON_MODE_POINT;
}
NazaraError("Unhandled FaceFilling 0x" + NumberToString(faceFilling, 16));
NazaraError("Unhandled FaceFilling 0x" + NumberToString(UnderlyingCast(faceFilling), 16));
return VK_POLYGON_MODE_FILL;
}
@@ -234,17 +234,17 @@ namespace Nz
{
switch (pixelFormat)
{
case PixelFormat::PixelFormat_BGRA8: return VK_FORMAT_B8G8R8A8_UNORM;
case PixelFormat::PixelFormat_BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
case PixelFormat::PixelFormat_Depth24Stencil8: return VK_FORMAT_D24_UNORM_S8_UINT;
case PixelFormat::PixelFormat_Depth32: return VK_FORMAT_D32_SFLOAT;
case PixelFormat::PixelFormat_RGBA8: return VK_FORMAT_R8G8B8A8_UNORM;
case PixelFormat::PixelFormat_RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
case PixelFormat::PixelFormat_RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT;
case PixelFormat::BGRA8: return VK_FORMAT_B8G8R8A8_UNORM;
case PixelFormat::BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
case PixelFormat::Depth24Stencil8: return VK_FORMAT_D24_UNORM_S8_UINT;
case PixelFormat::Depth32: return VK_FORMAT_D32_SFLOAT;
case PixelFormat::RGBA8: return VK_FORMAT_R8G8B8A8_UNORM;
case PixelFormat::RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
case PixelFormat::RGBA32F: return VK_FORMAT_R32G32B32A32_SFLOAT;
default: break;
}
NazaraError("Unhandled PixelFormat 0x" + NumberToString(pixelFormat, 16));
NazaraError("Unhandled PixelFormat 0x" + NumberToString(UnderlyingCast(pixelFormat), 16));
return {};
}
@@ -252,15 +252,15 @@ namespace Nz
{
switch (primitiveMode)
{
case PrimitiveMode_LineList: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
case PrimitiveMode_LineStrip: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
case PrimitiveMode_PointList: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
case PrimitiveMode_TriangleList: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
case PrimitiveMode_TriangleStrip: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
case PrimitiveMode_TriangleFan: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
case PrimitiveMode::LineList: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
case PrimitiveMode::LineStrip: return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
case PrimitiveMode::PointList: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
case PrimitiveMode::TriangleList: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
case PrimitiveMode::TriangleStrip: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
case PrimitiveMode::TriangleFan: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
}
NazaraError("Unhandled FaceFilling 0x" + NumberToString(primitiveMode, 16));
NazaraError("Unhandled FaceFilling 0x" + NumberToString(UnderlyingCast(primitiveMode), 16));
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
}
@@ -268,17 +268,17 @@ namespace Nz
{
switch (comparison)
{
case RendererComparison_Never: return VK_COMPARE_OP_NEVER;
case RendererComparison_Less: return VK_COMPARE_OP_LESS;
case RendererComparison_Equal: return VK_COMPARE_OP_EQUAL;
case RendererComparison_LessOrEqual: return VK_COMPARE_OP_LESS_OR_EQUAL;
case RendererComparison_Greater: return VK_COMPARE_OP_GREATER;
case RendererComparison_NotEqual: return VK_COMPARE_OP_NOT_EQUAL;
case RendererComparison_GreaterOrEqual: return VK_COMPARE_OP_GREATER_OR_EQUAL;
case RendererComparison_Always: return VK_COMPARE_OP_ALWAYS;
case RendererComparison::Never: return VK_COMPARE_OP_NEVER;
case RendererComparison::Less: return VK_COMPARE_OP_LESS;
case RendererComparison::Equal: return VK_COMPARE_OP_EQUAL;
case RendererComparison::LessOrEqual: return VK_COMPARE_OP_LESS_OR_EQUAL;
case RendererComparison::Greater: return VK_COMPARE_OP_GREATER;
case RendererComparison::NotEqual: return VK_COMPARE_OP_NOT_EQUAL;
case RendererComparison::GreaterOrEqual: return VK_COMPARE_OP_GREATER_OR_EQUAL;
case RendererComparison::Always: return VK_COMPARE_OP_ALWAYS;
}
NazaraError("Unhandled RendererComparison 0x" + NumberToString(comparison, 16));
NazaraError("Unhandled RendererComparison 0x" + NumberToString(UnderlyingCast(comparison), 16));
return VK_COMPARE_OP_NEVER;
}
@@ -286,8 +286,8 @@ namespace Nz
{
switch (samplerFilter)
{
case SamplerFilter_Linear: return VK_FILTER_LINEAR;
case SamplerFilter_Nearest: return VK_FILTER_NEAREST;
case SamplerFilter::Linear: return VK_FILTER_LINEAR;
case SamplerFilter::Nearest: return VK_FILTER_NEAREST;
}
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(samplerFilter), 16));
@@ -298,8 +298,8 @@ namespace Nz
{
switch (samplerMipmap)
{
case SamplerMipmapMode_Linear: return VK_SAMPLER_MIPMAP_MODE_LINEAR;
case SamplerMipmapMode_Nearest: return VK_SAMPLER_MIPMAP_MODE_NEAREST;
case SamplerMipmapMode::Linear: return VK_SAMPLER_MIPMAP_MODE_LINEAR;
case SamplerMipmapMode::Nearest: return VK_SAMPLER_MIPMAP_MODE_NEAREST;
}
NazaraError("Unhandled SamplerMipmapMode 0x" + NumberToString(UnderlyingCast(samplerMipmap), 16));
@@ -310,9 +310,9 @@ namespace Nz
{
switch (samplerWrap)
{
case SamplerWrap_Clamp: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case SamplerWrap_MirroredRepeat: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
case SamplerWrap_Repeat: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
case SamplerWrap::Clamp: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
case SamplerWrap::MirroredRepeat: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
case SamplerWrap::Repeat: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
}
NazaraError("Unhandled SamplerWrap 0x" + NumberToString(UnderlyingCast(samplerWrap), 16));
@@ -360,17 +360,17 @@ namespace Nz
{
switch (stencilOp)
{
case StencilOperation_Decrement: return VK_STENCIL_OP_DECREMENT_AND_CLAMP;
case StencilOperation_DecrementNoClamp: return VK_STENCIL_OP_DECREMENT_AND_WRAP;
case StencilOperation_Increment: return VK_STENCIL_OP_INCREMENT_AND_CLAMP;
case StencilOperation_IncrementNoClamp: return VK_STENCIL_OP_INCREMENT_AND_WRAP;
case StencilOperation_Invert: return VK_STENCIL_OP_INVERT;
case StencilOperation_Keep: return VK_STENCIL_OP_KEEP;
case StencilOperation_Replace: return VK_STENCIL_OP_REPLACE;
case StencilOperation_Zero: return VK_STENCIL_OP_ZERO;
case StencilOperation::Decrement: return VK_STENCIL_OP_DECREMENT_AND_CLAMP;
case StencilOperation::DecrementNoClamp: return VK_STENCIL_OP_DECREMENT_AND_WRAP;
case StencilOperation::Increment: return VK_STENCIL_OP_INCREMENT_AND_CLAMP;
case StencilOperation::IncrementNoClamp: return VK_STENCIL_OP_INCREMENT_AND_WRAP;
case StencilOperation::Invert: return VK_STENCIL_OP_INVERT;
case StencilOperation::Keep: return VK_STENCIL_OP_KEEP;
case StencilOperation::Replace: return VK_STENCIL_OP_REPLACE;
case StencilOperation::Zero: return VK_STENCIL_OP_ZERO;
}
NazaraError("Unhandled StencilOperation 0x" + NumberToString(stencilOp, 16));
NazaraError("Unhandled StencilOperation 0x" + NumberToString(UnderlyingCast(stencilOp), 16));
return {};
}