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

@@ -22,6 +22,6 @@ namespace Nz
bool AbstractImage::IsCubemap() const
{
return GetType() == ImageType_Cubemap;
return GetType() == ImageType::Cubemap;
}
}

View File

@@ -8,6 +8,7 @@
#include <Nazara/Utility/Joint.hpp>
#include <Nazara/Utility/Sequence.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <vector>
#include <unordered_map>
#include <Nazara/Utility/Debug.hpp>
@@ -36,19 +37,16 @@ namespace Nz
return true;
}
Animation::~Animation()
{
OnAnimationRelease(this);
Destroy();
}
Animation::Animation() = default;
Animation::Animation(Animation&&) noexcept = default;
Animation::~Animation() = default;
bool Animation::AddSequence(const Sequence& sequence)
{
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(sequence.frameCount > 0, "Sequence frame count must be over zero");
if (m_impl->type == AnimationType_Skeletal)
if (m_impl->type == AnimationType::Skeletal)
{
std::size_t endFrame = sequence.firstFrame + sequence.frameCount - 1;
if (endFrame >= m_impl->frameCount)
@@ -80,7 +78,7 @@ namespace Nz
void Animation::AnimateSkeleton(Skeleton* targetSkeleton, std::size_t frameA, std::size_t frameB, float interpolation) const
{
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
NazaraAssert(m_impl->type == AnimationType::Skeletal, "Animation is not skeletal");
NazaraAssert(targetSkeleton && targetSkeleton->IsValid(), "Invalid skeleton");
NazaraAssert(targetSkeleton->GetJointCount() == m_impl->jointCount, "Skeleton joint does not match animation joint count");
NazaraAssert(frameA < m_impl->frameCount, "FrameA is out of range");
@@ -106,24 +104,18 @@ namespace Nz
Destroy();
m_impl = new AnimationImpl;
m_impl = std::make_unique<AnimationImpl>();
m_impl->frameCount = frameCount;
m_impl->jointCount = jointCount;
m_impl->sequenceJoints.resize(frameCount*jointCount);
m_impl->type = AnimationType_Skeletal;
m_impl->type = AnimationType::Skeletal;
return true;
}
void Animation::Destroy()
{
if (m_impl)
{
OnAnimationDestroy(this);
delete m_impl;
m_impl = nullptr;
}
m_impl.reset();
}
void Animation::EnableLoopPointInterpolation(bool loopPointInterpolation)
@@ -215,7 +207,7 @@ namespace Nz
SequenceJoint* Animation::GetSequenceJoints(std::size_t frameIndex)
{
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
NazaraAssert(m_impl->type == AnimationType::Skeletal, "Animation is not skeletal");
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
}
@@ -223,7 +215,7 @@ namespace Nz
const SequenceJoint* Animation::GetSequenceJoints(std::size_t frameIndex) const
{
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
NazaraAssert(m_impl->type == AnimationType::Skeletal, "Animation is not skeletal");
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
}
@@ -289,46 +281,29 @@ namespace Nz
m_impl->sequences.erase(it);
}
AnimationRef Animation::LoadFromFile(const std::filesystem::path& filePath, const AnimationParams& params)
Animation& Animation::operator=(Animation&&) noexcept = default;
std::shared_ptr<Animation> Animation::LoadFromFile(const std::filesystem::path& filePath, const AnimationParams& params)
{
return AnimationLoader::LoadFromFile(filePath, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetAnimationLoader().LoadFromFile(filePath, params);
}
AnimationRef Animation::LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params)
std::shared_ptr<Animation> Animation::LoadFromMemory(const void* data, std::size_t size, const AnimationParams& params)
{
return AnimationLoader::LoadFromMemory(data, size, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetAnimationLoader().LoadFromMemory(data, size, params);
}
AnimationRef Animation::LoadFromStream(Stream& stream, const AnimationParams& params)
std::shared_ptr<Animation> Animation::LoadFromStream(Stream& stream, const AnimationParams& params)
{
return AnimationLoader::LoadFromStream(stream, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetAnimationLoader().LoadFromStream(stream, params);
}
bool Animation::Initialize()
{
if (!AnimationLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
if (!AnimationManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true;
}
void Animation::Uninitialize()
{
AnimationManager::Uninitialize();
AnimationLibrary::Uninitialize();
}
AnimationLibrary::LibraryMap Animation::s_library;
AnimationLoader::LoaderList Animation::s_loaders;
AnimationManager::ManagerMap Animation::s_managerMap;
AnimationManager::ManagerParams Animation::s_managerParameters;
}

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
@@ -29,20 +30,13 @@ namespace Nz
Create(size, storage, usage);
}
Buffer::~Buffer()
{
OnBufferRelease(this);
Destroy();
}
bool Buffer::CopyContent(const BufferRef& buffer)
bool Buffer::CopyContent(const Buffer& buffer)
{
NazaraAssert(m_impl, "Invalid buffer");
NazaraAssert(!buffer && !buffer->IsValid(), "Invalid source buffer");
NazaraAssert(buffer.IsValid(), "Invalid source buffer");
BufferMapper<Buffer> mapper(*buffer, BufferAccess_ReadOnly);
return Fill(mapper.GetPointer(), 0, buffer->GetSize());
BufferMapper<Buffer> mapper(buffer, BufferAccess::ReadOnly);
return Fill(mapper.GetPointer(), 0, buffer.GetSize());
}
bool Buffer::Create(UInt32 size, DataStorage storage, BufferUsageFlags usage)
@@ -56,7 +50,7 @@ namespace Nz
return false;
}
std::unique_ptr<AbstractBuffer> impl(s_bufferFactories[storage](this, m_type));
std::unique_ptr<AbstractBuffer> impl = s_bufferFactories[UnderlyingCast(storage)](this, m_type);
if (!impl->Initialize(size, usage))
{
NazaraError("Failed to create buffer");
@@ -72,12 +66,7 @@ namespace Nz
void Buffer::Destroy()
{
if (m_impl)
{
OnBufferDestroy(this);
m_impl.reset();
}
m_impl.reset();
}
bool Buffer::Fill(const void* data, UInt32 offset, UInt32 size)
@@ -99,7 +88,7 @@ namespace Nz
void* Buffer::Map(BufferAccess access, UInt32 offset, UInt32 size) const
{
NazaraAssert(m_impl, "Invalid buffer");
NazaraAssert(access == BufferAccess_ReadOnly, "Buffer access must be read-only when used const");
NazaraAssert(access == BufferAccess::ReadOnly, "Buffer access must be read-only when used const");
NazaraAssert(offset + size <= m_size, "Exceeding buffer size");
return m_impl->Map(access, offset, (size == 0) ? m_size - offset : size);
@@ -118,7 +107,7 @@ namespace Nz
return false;
}
void* ptr = m_impl->Map(BufferAccess_ReadOnly, 0, m_size);
void* ptr = m_impl->Map(BufferAccess::ReadOnly, 0, m_size);
if (!ptr)
{
NazaraError("Failed to map buffer");
@@ -130,7 +119,7 @@ namespace Nz
m_impl->Unmap();
});
std::unique_ptr<AbstractBuffer> impl(s_bufferFactories[storage](this, m_type));
std::unique_ptr<AbstractBuffer> impl(s_bufferFactories[UnderlyingCast(storage)](this, m_type));
if (!impl->Initialize(m_size, m_usage))
{
NazaraError("Failed to create buffer");
@@ -160,19 +149,19 @@ namespace Nz
bool Buffer::IsStorageSupported(DataStorage storage)
{
return s_bufferFactories[storage] != nullptr;
return s_bufferFactories[UnderlyingCast(storage)] != nullptr;
}
void Buffer::SetBufferFactory(DataStorage storage, BufferFactory func)
{
s_bufferFactories[storage] = func;
s_bufferFactories[UnderlyingCast(storage)] = func;
}
bool Buffer::Initialize()
{
SetBufferFactory(DataStorage_Software, [](Buffer* parent, BufferType type) -> AbstractBuffer*
SetBufferFactory(DataStorage::Software, [](Buffer* parent, BufferType type) -> std::unique_ptr<AbstractBuffer>
{
return new SoftwareBuffer(parent, type);
return std::make_unique<SoftwareBuffer>(parent, type);
});
return true;
@@ -183,5 +172,5 @@ namespace Nz
std::fill(s_bufferFactories.begin(), s_bufferFactories.end(), nullptr);
}
std::array<Buffer::BufferFactory, DataStorage_Max + 1> Buffer::s_bufferFactories;
std::array<Buffer::BufferFactory, DataStorageCount> Buffer::s_bufferFactories;
}

View File

@@ -26,8 +26,8 @@ namespace Nz
std::size_t FieldOffsets::AddFieldArray(StructFieldType type, std::size_t arraySize)
{
std::size_t fieldAlignement = GetAlignement(m_layout, type);
if (m_layout == StructLayout_Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout_Std140, StructFieldType_Float4));
if (m_layout == StructLayout::Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout::Std140, StructFieldType::Float4));
m_largestFieldAlignment = std::max(fieldAlignement, m_largestFieldAlignment);
@@ -46,9 +46,9 @@ namespace Nz
assert(rows >= 2 && rows <= 4);
if (columnMajor)
return AddFieldArray(static_cast<StructFieldType>(cellType + rows - 1), columns);
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + rows - 1), columns);
else
return AddFieldArray(static_cast<StructFieldType>(cellType + columns - 1), rows);
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + columns - 1), rows);
}
std::size_t FieldOffsets::AddMatrixArray(StructFieldType cellType, unsigned int columns, unsigned int rows, bool columnMajor, std::size_t arraySize)
@@ -58,16 +58,16 @@ namespace Nz
assert(rows >= 2 && rows <= 4);
if (columnMajor)
return AddFieldArray(static_cast<StructFieldType>(cellType + rows - 1), columns * arraySize);
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + rows - 1), columns * arraySize);
else
return AddFieldArray(static_cast<StructFieldType>(cellType + columns - 1), rows * arraySize);
return AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(cellType) + columns - 1), rows * arraySize);
}
std::size_t FieldOffsets::AddStruct(const FieldOffsets& fieldStruct)
{
std::size_t fieldAlignement = fieldStruct.GetLargestFieldAlignement();
if (m_layout == StructLayout_Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout_Std140, StructFieldType_Float4));
if (m_layout == StructLayout::Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout::Std140, StructFieldType::Float4));
m_largestFieldAlignment = std::max(m_largestFieldAlignment, fieldAlignement);
@@ -84,8 +84,8 @@ namespace Nz
assert(arraySize > 0);
std::size_t fieldAlignement = fieldStruct.GetLargestFieldAlignement();
if (m_layout == StructLayout_Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout_Std140, StructFieldType_Float4));
if (m_layout == StructLayout::Std140)
fieldAlignement = Align(fieldAlignement, GetAlignement(StructLayout::Std140, StructFieldType::Float4));
m_largestFieldAlignment = std::max(m_largestFieldAlignment, fieldAlignement);

View File

@@ -8,6 +8,7 @@
#include <Nazara/Utility/FontData.hpp>
#include <Nazara/Utility/FontGlyph.hpp>
#include <Nazara/Utility/GuillotineImageAtlas.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
@@ -329,7 +330,7 @@ namespace Nz
return s_defaultAtlas;
}
const FontRef& Font::GetDefault()
const std::shared_ptr<Font>& Font::GetDefault()
{
// Nous n'initialisons la police par défaut qu'à la demande pour qu'elle prenne
// les paramètres par défaut (qui peuvent avoir étés changés par l'utilisateur),
@@ -355,19 +356,28 @@ namespace Nz
return s_defaultMinimumStepSize;
}
FontRef Font::OpenFromFile(const std::filesystem::path& filePath, const FontParams& params)
std::shared_ptr<Font> Font::OpenFromFile(const std::filesystem::path& filePath, const FontParams& params)
{
return FontLoader::LoadFromFile(filePath, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetFontLoader().LoadFromFile(filePath, params);
}
FontRef Font::OpenFromMemory(const void* data, std::size_t size, const FontParams& params)
std::shared_ptr<Font> Font::OpenFromMemory(const void* data, std::size_t size, const FontParams& params)
{
return FontLoader::LoadFromMemory(data, size, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetFontLoader().LoadFromMemory(data, size, params);
}
FontRef Font::OpenFromStream(Stream& stream, const FontParams& params)
std::shared_ptr<Font> Font::OpenFromStream(Stream& stream, const FontParams& params)
{
return FontLoader::LoadFromStream(stream, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetFontLoader().LoadFromStream(stream, params);
}
void Font::SetDefaultAtlas(const std::shared_ptr<AbstractAtlas>& atlas)
@@ -401,10 +411,10 @@ namespace Nz
sizeStylePart <<= 2;
// Store bold and italic flags (other style are handled directly by a TextDrawer)
if (style & TextStyle_Bold)
if (style & TextStyle::Bold)
sizeStylePart |= 1 << 0;
if (style & TextStyle_Italic)
if (style & TextStyle::Italic)
sizeStylePart |= 1 << 1;
return (sizeStylePart << 32) | reinterpret_cast<Nz::UInt32&>(outlineThickness);
@@ -488,16 +498,16 @@ namespace Nz
glyph.requireFauxItalic = false;
TextStyleFlags supportedStyle = style;
if (style & TextStyle_Bold && !m_data->SupportsStyle(TextStyle_Bold))
if (style & TextStyle::Bold && !m_data->SupportsStyle(TextStyle::Bold))
{
glyph.requireFauxBold = true;
supportedStyle &= ~TextStyle_Bold;
supportedStyle &= ~TextStyle::Bold;
}
if (style & TextStyle_Italic && !m_data->SupportsStyle(TextStyle_Italic))
if (style & TextStyle::Italic && !m_data->SupportsStyle(TextStyle::Italic))
{
glyph.requireFauxItalic = true;
supportedStyle &= ~TextStyle_Italic;
supportedStyle &= ~TextStyle::Italic;
}
float supportedOutlineThickness = outlineThickness;
@@ -572,13 +582,7 @@ namespace Nz
bool Font::Initialize()
{
if (!FontLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
s_defaultAtlas.reset(new GuillotineImageAtlas);
s_defaultAtlas = std::make_shared<GuillotineImageAtlas>();
s_defaultGlyphBorder = 1;
s_defaultMinimumStepSize = 1;
@@ -588,14 +592,11 @@ namespace Nz
void Font::Uninitialize()
{
s_defaultAtlas.reset();
s_defaultFont.Reset();
FontLibrary::Uninitialize();
s_defaultFont.reset();
}
std::shared_ptr<AbstractAtlas> Font::s_defaultAtlas;
FontRef Font::s_defaultFont;
FontLibrary::LibraryMap Font::s_library;
FontLoader::LoaderList Font::s_loaders;
std::shared_ptr<Font> Font::s_defaultFont;
unsigned int Font::s_defaultGlyphBorder;
unsigned int Font::s_defaultMinimumStepSize;
unsigned int Font::s_defaultMinimumStepSize;
}

View File

@@ -18,7 +18,7 @@ namespace Nz
DDSLoader() = delete;
~DDSLoader() = delete;
static bool IsSupported(const std::string& extension)
static bool IsSupported(const std::string_view& extension)
{
return (extension == "dds");
}
@@ -38,7 +38,7 @@ namespace Nz
return (magic == DDS_Magic) ? Ternary::True : Ternary::False;
}
static ImageRef Load(Stream& stream, const ImageParams& parameters)
static std::shared_ptr<Image> Load(Stream& stream, const ImageParams& parameters)
{
NazaraUnused(parameters);
@@ -88,7 +88,7 @@ namespace Nz
if (!IdentifyPixelFormat(header, headerDX10, &format))
return nullptr;
ImageRef image = Image::New(type, format, width, height, depth, levelCount);
std::shared_ptr<Image> image = std::make_shared<Image>(type, format, width, height, depth, levelCount);
// Read all mipmap levels
for (unsigned int i = 0; i < image->GetLevelCount(); i++)
@@ -114,7 +114,7 @@ namespace Nz
}
if (parameters.loadFormat != PixelFormat_Undefined)
if (parameters.loadFormat != PixelFormat::Undefined)
image->Convert(parameters.loadFormat);
return image;
@@ -131,9 +131,9 @@ namespace Nz
return false;
}
else if (header.flags & DDSD_HEIGHT)
*type = ImageType_2D_Array;
*type = ImageType::E2D_Array;
else
*type = ImageType_1D_Array;
*type = ImageType::E1D_Array;
}
else
{
@@ -145,7 +145,7 @@ namespace Nz
return false;
}
*type = ImageType_Cubemap;
*type = ImageType::Cubemap;
}
else if (headerExt.resourceDimension == D3D10_RESOURCE_DIMENSION_BUFFER)
{
@@ -153,11 +153,11 @@ namespace Nz
return false;
}
else if (headerExt.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE1D)
*type = ImageType_1D;
*type = ImageType::E1D;
else if (header.ddsCaps[1] & DDSCAPS2_VOLUME || header.flags & DDSD_DEPTH || headerExt.resourceDimension == D3D10_RESOURCE_DIMENSION_TEXTURE3D)
*type = ImageType_3D;
*type = ImageType::E3D;
else
*type = ImageType_2D;
*type = ImageType::E2D;
}
return true;
@@ -167,7 +167,7 @@ namespace Nz
{
if (header.format.flags & (DDPF_RGB | DDPF_ALPHA | DDPF_ALPHAPIXELS | DDPF_LUMINANCE))
{
PixelFormatDescription info(PixelFormatContent_ColorRGBA, header.format.bpp, PixelFormatSubType_Unsigned);
PixelFormatDescription info(PixelFormatContent::ColorRGBA, header.format.bpp, PixelFormatSubType::Unsigned);
if (header.format.flags & DDPF_RGB)
{
@@ -191,15 +191,15 @@ namespace Nz
switch (header.format.fourCC)
{
case D3DFMT_DXT1:
*format = PixelFormat_DXT1;
*format = PixelFormat::DXT1;
break;
case D3DFMT_DXT3:
*format = PixelFormat_DXT3;
*format = PixelFormat::DXT3;
break;
case D3DFMT_DXT5:
*format = PixelFormat_DXT3;
*format = PixelFormat::DXT3;
break;
case D3DFMT_DX10:
@@ -207,30 +207,35 @@ namespace Nz
switch (headerExt.dxgiFormat)
{
case DXGI_FORMAT_R32G32B32A32_FLOAT:
*format = PixelFormat_RGBA32F;
*format = PixelFormat::RGBA32F;
break;
case DXGI_FORMAT_R32G32B32A32_UINT:
*format = PixelFormat_RGBA32UI;
*format = PixelFormat::RGBA32UI;
break;
case DXGI_FORMAT_R32G32B32A32_SINT:
*format = PixelFormat_RGBA32I;
*format = PixelFormat::RGBA32I;
break;
case DXGI_FORMAT_R32G32B32_FLOAT:
*format = PixelFormat_RGB32F;
*format = PixelFormat::RGB32F;
break;
case DXGI_FORMAT_R32G32B32_UINT:
//*format = PixelFormat_RGB32U;
//*format = PixelFormat::RGB32U;
return false;
case DXGI_FORMAT_R32G32B32_SINT:
*format = PixelFormat_RGB32I;
*format = PixelFormat::RGB32I;
break;
case DXGI_FORMAT_R16G16B16A16_SNORM:
case DXGI_FORMAT_R16G16B16A16_SINT:
case DXGI_FORMAT_R16G16B16A16_UINT:
*format = PixelFormat_RGBA16I;
*format = PixelFormat::RGBA16I;
break;
case DXGI_FORMAT_R16G16B16A16_UNORM:
*format = PixelFormat_RGBA16UI;
*format = PixelFormat::RGBA16UI;
break;
default:
//TODO
NazaraError("TODO");
break;
}
break;
@@ -262,14 +267,14 @@ namespace Nz
namespace Loaders
{
void RegisterDDSLoader()
ImageLoader::Entry GetImageLoader_DDS()
{
ImageLoader::RegisterLoader(DDSLoader::IsSupported, DDSLoader::Check, DDSLoader::Load);
}
ImageLoader::Entry loaderEntry;
loaderEntry.extensionSupport = DDSLoader::IsSupported;
loaderEntry.streamChecker = DDSLoader::Check;
loaderEntry.streamLoader = DDSLoader::Load;
void UnregisterDDSLoader()
{
ImageLoader::UnregisterLoader(DDSLoader::IsSupported, DDSLoader::Check, DDSLoader::Load);
return loaderEntry;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_LOADERS_DDS_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Image.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterDDSLoader();
void UnregisterDDSLoader();
}
ImageLoader::Entry GetImageLoader_DDS();
}
#endif // NAZARA_LOADERS_DDS_HPP

View File

@@ -145,7 +145,7 @@ namespace Nz
const FT_Pos boldStrength = 2 << 6;
bool embolden = (style & TextStyle_Bold) != 0;
bool embolden = (style & TextStyle::Bold) != 0;
bool hasOutlineFormat = (glyph->format == FT_GLYPH_FORMAT_OUTLINE);
dst->advance = (embolden) ? boldStrength >> 6 : 0;
@@ -202,7 +202,7 @@ namespace Nz
if (width > 0 && height > 0)
{
dst->image.Create(ImageType_2D, PixelFormat_A8, width, height);
dst->image.Create(ImageType::E2D, PixelFormat::A8, width, height);
UInt8* pixels = dst->image.GetPixels();
const UInt8* data = bitmap.buffer;
@@ -363,7 +363,7 @@ namespace Nz
bool SupportsStyle(TextStyleFlags style) const override
{
///TODO
return style == TextStyle_Regular || style == TextStyle_Bold;
return style == TextStyle_Regular || style == TextStyle::Bold;
}
private:
@@ -384,10 +384,10 @@ namespace Nz
mutable unsigned int m_characterSize;
};
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
///FIXME: Je suppose qu'il en manque quelques unes..
static std::set<std::string> supportedExtensions = {
static std::set<std::string_view> supportedExtensions = {
"afm", "bdf", "cff", "cid", "dfont", "fnt", "fon", "otf", "pfa", "pfb", "pfm", "pfr", "sfnt", "ttc", "tte", "ttf"
};
@@ -409,7 +409,7 @@ namespace Nz
return Ternary::False;
}
FontRef LoadFile(const std::filesystem::path& filePath, const FontParams& parameters)
std::shared_ptr<Font> LoadFile(const std::filesystem::path& filePath, const FontParams& parameters)
{
NazaraUnused(parameters);
@@ -426,7 +426,7 @@ namespace Nz
return nullptr;
}
FontRef font = Font::New();
std::shared_ptr<Font> font = std::make_shared<Font>();
if (font->Create(face.get()))
{
face.release();
@@ -436,7 +436,7 @@ namespace Nz
return nullptr;
}
FontRef LoadMemory(const void* data, std::size_t size, const FontParams& parameters)
std::shared_ptr<Font> LoadMemory(const void* data, std::size_t size, const FontParams& parameters)
{
NazaraUnused(parameters);
@@ -449,7 +449,7 @@ namespace Nz
return nullptr;
}
FontRef font = Font::New();
std::shared_ptr<Font> font = std::make_shared<Font>();
if (font->Create(face.get()))
{
face.release();
@@ -459,7 +459,7 @@ namespace Nz
return nullptr;
}
FontRef LoadStream(Stream& stream, const FontParams& parameters)
std::shared_ptr<Font> LoadStream(Stream& stream, const FontParams& parameters)
{
NazaraUnused(parameters);
@@ -472,7 +472,7 @@ namespace Nz
return nullptr;
}
FontRef font = Font::New();
std::shared_ptr<Font> font = std::make_shared<Font>();
if (font->Create(face.get()))
{
face.release();
@@ -485,27 +485,36 @@ namespace Nz
namespace Loaders
{
void RegisterFreeType()
bool InitializeFreeType()
{
if (FT_Init_FreeType(&s_library) == 0)
NazaraAssert(!s_libraryOwner, "double initialization for FreeType");
if (FT_Init_FreeType(&s_library) != 0)
{
s_libraryOwner = std::make_shared<FreeTypeLibrary>();
FontLoader::RegisterLoader(IsSupported, Check, LoadStream, LoadFile, LoadMemory);
}
else
{
s_library = nullptr; // On s'assure que le pointeur ne pointe pas sur n'importe quoi
NazaraWarning("Failed to initialize FreeType library");
NazaraWarning("failed to initialize FreeType library");
return false;
}
s_libraryOwner = std::make_shared<FreeTypeLibrary>();
return true;
}
void UnregisterFreeType()
FontLoader::Entry GetFontLoader_FreeType()
{
if (s_library)
{
FontLoader::UnregisterLoader(IsSupported, Check, LoadStream, LoadFile, LoadMemory);
s_libraryOwner.reset();
}
NazaraAssert(s_libraryOwner, "FreeType has not been initialized");
FontLoader::Entry entry;
entry.extensionSupport = IsSupported;
entry.fileLoader = LoadFile;
entry.memoryLoader = LoadMemory;
entry.streamChecker = Check;
entry.streamLoader = LoadStream;
return entry;
}
void UninitializeFreeType()
{
s_libraryOwner.reset();
}
}
}

View File

@@ -8,14 +8,13 @@
#define NAZARA_LOADERS_FREETYPE_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Font.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterFreeType();
void UnregisterFreeType();
}
bool InitializeFreeType();
FontLoader::Entry GetFontLoader_FreeType();
void UninitializeFreeType();
}
#endif // NAZARA_LOADERS_FREETYPE_HPP

View File

@@ -20,7 +20,7 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
return (extension == "md2");
}
@@ -46,7 +46,7 @@ namespace Nz
return Ternary::False;
}
MeshRef Load(Stream& stream, const MeshParams& parameters)
std::shared_ptr<Mesh> Load(Stream& stream, const MeshParams& parameters)
{
MD2_Header header;
if (stream.Read(&header, sizeof(MD2_Header)) != sizeof(MD2_Header))
@@ -80,7 +80,7 @@ namespace Nz
}
// Since the engine no longer supports keyframe animations, let's make a static mesh
MeshRef mesh = Nz::Mesh::New();
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
if (!mesh->CreateStatic())
{
NazaraInternalError("Failed to create mesh");
@@ -107,7 +107,7 @@ namespace Nz
}
}
IndexBufferRef indexBuffer = IndexBuffer::New(false, header.num_tris*3, parameters.storage, parameters.indexBufferFlags);
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(false, header.num_tris*3, parameters.storage, parameters.indexBufferFlags);
// Extract triangles data
std::vector<MD2_Triangle> triangles(header.num_tris);
@@ -116,7 +116,7 @@ namespace Nz
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
// And convert them into an index buffer
BufferMapper<IndexBuffer> indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
BufferMapper<IndexBuffer> indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
UInt16* index = static_cast<UInt16*>(indexMapper.GetPointer());
for (unsigned int i = 0; i < header.num_tris; ++i)
@@ -158,8 +158,8 @@ namespace Nz
}
#endif
VertexBufferRef vertexBuffer = VertexBuffer::New(parameters.vertexDeclaration, header.num_vertices, parameters.storage, parameters.vertexBufferFlags);
StaticMeshRef subMesh = StaticMesh::New(vertexBuffer, indexBuffer);
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, header.num_vertices, parameters.storage, parameters.vertexBufferFlags);
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer);
// Extracting vertices
stream.SetCursorPos(header.offset_frames);
@@ -186,10 +186,10 @@ namespace Nz
scale *= ScaleAdjust;
translate *= ScaleAdjust;
VertexMapper vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
// Loading texture coordinates
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord))
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord))
{
const unsigned int indexFix[3] = {0, 2, 1};
@@ -214,7 +214,7 @@ namespace Nz
Nz::Matrix4f matrix = Matrix4f::Transform(translate, rotationQuat, scale);
matrix *= parameters.matrix;
if (auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal))
if (auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal))
{
Nz::Matrix4f normalMatrix = Matrix4f::Rotate(rotationQuat);
normalMatrix *= parameters.matrix;
@@ -227,7 +227,7 @@ namespace Nz
}
}
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
assert(posPtr);
for (unsigned int v = 0; v < header.num_vertices; ++v)
@@ -244,7 +244,7 @@ namespace Nz
subMesh->GenerateAABB();
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent_Tangent))
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent::Tangent))
subMesh->GenerateTangents();
mesh->AddSubMesh(subMesh);
@@ -258,14 +258,14 @@ namespace Nz
namespace Loaders
{
void RegisterMD2()
MeshLoader::Entry GetMeshLoader_MD2()
{
MeshLoader::RegisterLoader(IsSupported, Check, Load);
}
MeshLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
void UnregisterMD2()
{
MeshLoader::UnregisterLoader(IsSupported, Check, Load);
return loader;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_LOADERS_MD2_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Mesh.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterMD2();
void UnregisterMD2();
}
MeshLoader::Entry GetMeshLoader_MD2();
}
#endif // NAZARA_LOADERS_MD2_HPP

View File

@@ -12,7 +12,7 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
return (extension == "md5anim");
}
@@ -27,7 +27,7 @@ namespace Nz
return parser.Check();
}
AnimationRef Load(Stream& stream, const AnimationParams& /*parameters*/)
std::shared_ptr<Animation> Load(Stream& stream, const AnimationParams& /*parameters*/)
{
///TODO: Utiliser les paramètres
MD5AnimParser parser(stream);
@@ -45,7 +45,7 @@ namespace Nz
std::size_t jointCount = parser.GetJointCount();
// À ce stade, nous sommes censés avoir assez d'informations pour créer l'animation
AnimationRef animation = Animation::New();
std::shared_ptr<Animation> animation = std::make_shared<Animation>();
animation->CreateSkeletal(frameCount, jointCount);
Sequence sequence;
@@ -90,14 +90,14 @@ namespace Nz
namespace Loaders
{
void RegisterMD5Anim()
AnimationLoader::Entry GetAnimationLoader_MD5Anim()
{
AnimationLoader::RegisterLoader(IsSupported, Check, Load);
}
AnimationLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
void UnregisterMD5Anim()
{
AnimationLoader::UnregisterLoader(IsSupported, Check, Load);
return loader;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_LOADERS_MD5ANIM_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Animation.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterMD5Anim();
void UnregisterMD5Anim();
}
AnimationLoader::Entry GetAnimationLoader_MD5Anim();
}
#endif // NAZARA_LOADERS_MD5ANIM_HPP

View File

@@ -20,7 +20,7 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
return (extension == "md5mesh");
}
@@ -35,7 +35,7 @@ namespace Nz
return parser.Check();
}
MeshRef Load(Stream& stream, const MeshParams& parameters)
std::shared_ptr<Mesh> Load(Stream& stream, const MeshParams& parameters)
{
MD5MeshParser parser(stream);
if (!parser.Parse())
@@ -62,7 +62,7 @@ namespace Nz
if (parameters.animated)
{
MeshRef mesh = Mesh::New();
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
mesh->CreateSkeletal(jointCount);
Skeleton* skeleton = mesh->GetSkeleton();
@@ -96,11 +96,11 @@ namespace Nz
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, UInt32(indexCount), parameters.storage, parameters.indexBufferFlags);
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent_Skinning), UInt32(vertexCount), parameters.storage, parameters.vertexBufferFlags);
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, UInt32(indexCount), parameters.storage, parameters.indexBufferFlags);
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(VertexDeclaration::Get(VertexLayout::XYZ_Normal_UV_Tangent_Skinning), UInt32(vertexCount), parameters.storage, parameters.vertexBufferFlags);
// Index buffer
IndexMapper indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
IndexMapper indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
// Le format définit un set de triangles nous permettant de retrouver facilement les indices
// Cependant les sommets des triangles ne sont pas spécifiés dans le même ordre que ceux du moteur
@@ -128,7 +128,7 @@ namespace Nz
std::vector<Weight> tempWeights;
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
BufferMapper<VertexBuffer> vertexMapper(*vertexBuffer, BufferAccess::WriteOnly);
SkeletalMeshVertex* vertices = static_cast<SkeletalMeshVertex*>(vertexMapper.GetPointer());
for (const MD5MeshParser::Vertex& vertex : md5Mesh.vertices)
@@ -203,7 +203,7 @@ namespace Nz
mesh->SetMaterialData(i, std::move(matData));
// Submesh
SkeletalMeshRef subMesh = SkeletalMesh::New(vertexBuffer, indexBuffer);
std::shared_ptr<SkeletalMesh> subMesh = std::make_shared<SkeletalMesh>(vertexBuffer, indexBuffer);
subMesh->GenerateNormalsAndTangents();
subMesh->SetMaterialIndex(i);
@@ -224,7 +224,7 @@ namespace Nz
}
else
{
MeshRef mesh = Mesh::New();
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
if (!mesh->CreateStatic()) // Ne devrait jamais échouer
{
NazaraInternalError("Failed to create mesh");
@@ -241,9 +241,9 @@ namespace Nz
// Index buffer
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, UInt32(indexCount), parameters.storage, parameters.indexBufferFlags);
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(largeIndices, UInt32(indexCount), parameters.storage, parameters.indexBufferFlags);
IndexMapper indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
IndexMapper indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
IndexIterator index = indexMapper.begin();
for (const MD5MeshParser::Triangle& triangle : md5Mesh.triangles)
@@ -259,11 +259,11 @@ namespace Nz
indexBuffer->Optimize();
// Vertex buffer
VertexBufferRef vertexBuffer = VertexBuffer::New(parameters.vertexDeclaration, UInt32(vertexCount), parameters.storage, parameters.vertexBufferFlags);
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, UInt32(vertexCount), parameters.storage, parameters.vertexBufferFlags);
VertexMapper vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
for (const MD5MeshParser::Vertex& md5Vertex : md5Mesh.vertices)
{
@@ -281,7 +281,7 @@ namespace Nz
*posPtr++ = matrix * finalPos;
}
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord))
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord))
{
for (const MD5MeshParser::Vertex& md5Vertex : md5Mesh.vertices)
*uvPtr++ = parameters.texCoordOffset + md5Vertex.uv * parameters.texCoordScale;
@@ -290,13 +290,13 @@ namespace Nz
vertexMapper.Unmap();
// Submesh
StaticMeshRef subMesh = StaticMesh::New(vertexBuffer, indexBuffer);
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer);
subMesh->GenerateAABB();
subMesh->SetMaterialIndex(i);
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent_Normal))
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent::Normal))
{
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent_Tangent))
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent::Tangent))
subMesh->GenerateNormalsAndTangents();
else
subMesh->GenerateNormals();
@@ -321,14 +321,14 @@ namespace Nz
namespace Loaders
{
void RegisterMD5Mesh()
MeshLoader::Entry GetMeshLoader_MD5Mesh()
{
MeshLoader::RegisterLoader(IsSupported, Check, Load);
}
MeshLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
void UnregisterMD5Mesh()
{
MeshLoader::UnregisterLoader(IsSupported, Check, Load);
return loader;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_LOADERS_MD5MESH_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Mesh.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterMD5Mesh();
void UnregisterMD5Mesh();
}
MeshLoader::Entry GetMeshLoader_MD5Mesh();
}
#endif // NAZARA_LOADERS_MD5MESH_HPP

View File

@@ -22,7 +22,7 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
return (extension == "obj");
}
@@ -42,7 +42,7 @@ namespace Nz
return Ternary::Unknown;
}
bool ParseMTL(Mesh* mesh, const std::filesystem::path& filePath, const std::string* materials, const OBJParser::Mesh* meshes, std::size_t meshCount)
bool ParseMTL(Mesh& mesh, const std::filesystem::path& filePath, const std::string* materials, const OBJParser::Mesh* meshes, std::size_t meshCount)
{
File file(filePath);
if (!file.Open(OpenMode_ReadOnly | OpenMode_Text))
@@ -151,13 +151,13 @@ namespace Nz
it = materialCache.emplace(matName, std::move(data)).first;
}
mesh->SetMaterialData(meshes[i].material, it->second);
mesh.SetMaterialData(meshes[i].material, it->second);
}
return true;
}
MeshRef Load(Stream& stream, const MeshParams& parameters)
std::shared_ptr<Mesh> Load(Stream& stream, const MeshParams& parameters)
{
long long reservedVertexCount;
if (!parameters.custom.GetIntegerParameter("NativeOBJLoader_VertexCount", &reservedVertexCount))
@@ -170,7 +170,7 @@ namespace Nz
return nullptr;
}
MeshRef mesh = Mesh::New();
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
mesh->CreateStatic();
const std::string* materials = parser.GetMaterials();
@@ -254,11 +254,11 @@ namespace Nz
}
// Création des buffers
IndexBufferRef indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), std::size_t(indices.size()), parameters.storage, parameters.indexBufferFlags);
VertexBufferRef vertexBuffer = VertexBuffer::New(parameters.vertexDeclaration, std::size_t(vertexCount), parameters.storage, parameters.vertexBufferFlags);
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), std::size_t(indices.size()), parameters.storage, parameters.indexBufferFlags);
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, std::size_t(vertexCount), parameters.storage, parameters.vertexBufferFlags);
// Remplissage des indices
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
for (std::size_t j = 0; j < indices.size(); ++j)
indexMapper.Set(j, UInt32(indices[j]));
@@ -277,11 +277,11 @@ namespace Nz
bool hasNormals = true;
bool hasTexCoords = true;
VertexMapper vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
if (!normalPtr)
hasNormals = false;
@@ -321,7 +321,7 @@ namespace Nz
vertexMapper.Unmap();
StaticMeshRef subMesh = StaticMesh::New(vertexBuffer, indexBuffer);
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(std::move(vertexBuffer), indexBuffer);
subMesh->GenerateAABB();
subMesh->SetMaterialIndex(meshes[i].material);
@@ -345,7 +345,7 @@ namespace Nz
if (!mtlLib.empty())
{
ErrorFlags flags(ErrorFlag_ThrowExceptionDisabled);
ParseMTL(mesh, stream.GetDirectory() / mtlLib, materials, meshes, meshCount);
ParseMTL(*mesh, stream.GetDirectory() / mtlLib, materials, meshes, meshCount);
}
return mesh;
@@ -354,14 +354,14 @@ namespace Nz
namespace Loaders
{
void RegisterOBJLoader()
MeshLoader::Entry GetMeshLoader_OBJ()
{
MeshLoader::RegisterLoader(IsSupported, Check, Load);
}
MeshLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
void UnregisterOBJLoader()
{
MeshLoader::UnregisterLoader(IsSupported, Check, Load);
return loader;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_LOADERS_OBJ_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Mesh.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterOBJLoader();
void UnregisterOBJLoader();
}
MeshLoader::Entry GetMeshLoader_OBJ();
}
#endif // NAZARA_LOADERS_OBJ_HPP

View File

@@ -51,7 +51,7 @@ namespace Nz
T* m_buffer;
};
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
return (extension == "obj");
}
@@ -142,21 +142,21 @@ namespace Nz
OBJParser::Mesh* meshes = objFormat.SetMeshCount(meshCount);
for (std::size_t i = 0; i < meshCount; ++i)
{
const StaticMesh* staticMesh = static_cast<const StaticMesh*>(mesh.GetSubMesh(i));
const StaticMesh& staticMesh = static_cast<const StaticMesh&>(*mesh.GetSubMesh(i));
std::size_t triangleCount = staticMesh->GetTriangleCount();
std::size_t triangleCount = staticMesh.GetTriangleCount();
meshes[i].faces.resize(triangleCount);
meshes[i].material = staticMesh->GetMaterialIndex();
meshes[i].material = staticMesh.GetMaterialIndex();
meshes[i].name = "mesh_" + std::to_string(i);
meshes[i].vertices.resize(triangleCount * 3);
{
VertexMapper vertexMapper(staticMesh);
SparsePtr<Vector3f> normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
SparsePtr<Vector3f> positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
SparsePtr<Vector2f> texCoordsPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
SparsePtr<Vector3f> normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
SparsePtr<Vector3f> positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
SparsePtr<Vector2f> texCoordsPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
std::size_t faceIndex = 0;
TriangleIterator triangle(staticMesh);
@@ -201,14 +201,13 @@ namespace Nz
namespace Loaders
{
void RegisterOBJSaver()
MeshSaver::Entry GetMeshSaver_OBJ()
{
MeshSaver::RegisterSaver(IsSupported, SaveToStream);
}
MeshSaver::Entry entry;
entry.formatSupport = IsSupported;
entry.streamSaver = SaveToStream;
void UnregisterOBJSaver()
{
MeshSaver::UnregisterSaver(IsSupported, SaveToStream);
return entry;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_FORMATS_OBJSAVER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Mesh.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterOBJSaver();
void UnregisterOBJSaver();
}
MeshSaver::Entry GetMeshSaver_OBJ();
}
#endif // NAZARA_FORMATS_OBJSAVER_HPP

View File

@@ -40,7 +40,7 @@ namespace Nz
static_assert(sizeof(pcx_header) == (6+48+54)*sizeof(UInt8) + 10*sizeof(UInt16), "pcx_header struct must be packed");
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
return (extension == "pcx");
}
@@ -61,7 +61,7 @@ namespace Nz
return Ternary::False;
}
ImageRef Load(Stream& stream, const ImageParams& parameters)
std::shared_ptr<Image> Load(Stream& stream, const ImageParams& parameters)
{
NazaraUnused(parameters);
@@ -91,8 +91,8 @@ namespace Nz
unsigned int width = header.xmax - header.xmin+1;
unsigned int height = header.ymax - header.ymin+1;
ImageRef image = Image::New();
if (!image->Create(ImageType_2D, PixelFormat_RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1))
std::shared_ptr<Image> image = std::make_shared<Image>();
if (!image->Create(ImageType::E2D, PixelFormat::RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1))
{
NazaraError("Failed to create image");
return nullptr;
@@ -333,7 +333,7 @@ namespace Nz
return nullptr;
}
if (parameters.loadFormat != PixelFormat_Undefined)
if (parameters.loadFormat != PixelFormat::Undefined)
image->Convert(parameters.loadFormat);
return image;
@@ -342,14 +342,14 @@ namespace Nz
namespace Loaders
{
void RegisterPCX()
ImageLoader::Entry GetImageLoader_PCX()
{
ImageLoader::RegisterLoader(IsSupported, Check, Load);
}
ImageLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.streamChecker = Check;
loaderEntry.streamLoader = Load;
void UnregisterPCX()
{
ImageLoader::UnregisterLoader(IsSupported, Check, Load);
return loaderEntry;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_LOADERS_PCX_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Image.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterPCX();
void UnregisterPCX();
}
ImageLoader::Entry GetImageLoader_PCX();
}
#endif // NAZARA_LOADERS_PCX_HPP

View File

@@ -36,9 +36,9 @@ namespace Nz
static stbi_io_callbacks callbacks = {Read, Skip, Eof};
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
static std::unordered_set<std::string> supportedExtensions = {"bmp", "gif", "hdr", "jpg", "jpeg", "pic", "png", "ppm", "pgm", "psd", "tga"};
static std::unordered_set<std::string_view> supportedExtensions = {"bmp", "gif", "hdr", "jpg", "jpeg", "pic", "png", "ppm", "pgm", "psd", "tga"};
return supportedExtensions.find(extension) != supportedExtensions.end();
}
@@ -55,7 +55,7 @@ namespace Nz
return Ternary::False;
}
ImageRef Load(Stream& stream, const ImageParams& parameters)
std::shared_ptr<Image> Load(Stream& stream, const ImageParams& parameters)
{
// Je charge tout en RGBA8 et je converti ensuite via la méthode Convert
// Ceci à cause d'un bug de STB lorsqu'il s'agit de charger certaines images (ex: JPG) en "default"
@@ -65,7 +65,7 @@ namespace Nz
if (!ptr)
{
NazaraError("Failed to load image: " + std::string(stbi_failure_reason()));
return nullptr;
return {};
}
CallOnExit freeStbiImage([ptr]()
@@ -73,19 +73,25 @@ namespace Nz
stbi_image_free(ptr);
});
ImageRef image = Image::New();
if (!image->Create(ImageType_2D, PixelFormat_RGBA8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1))
std::shared_ptr<Image> image = std::make_shared<Image>();
if (!image->Create(ImageType::E2D, PixelFormat::RGBA8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1))
{
NazaraError("Failed to create image");
return nullptr;
return {};
}
image->Update(ptr);
freeStbiImage.CallAndReset();
if (parameters.loadFormat != PixelFormat_Undefined)
image->Convert(parameters.loadFormat);
if (parameters.loadFormat != PixelFormat::Undefined)
{
if (!image->Convert(parameters.loadFormat))
{
NazaraError("Failed to convert image to required format");
return {};
}
}
return image;
}
@@ -93,14 +99,14 @@ namespace Nz
namespace Loaders
{
void RegisterSTBLoader()
ImageLoader::Entry GetImageLoader_STB()
{
ImageLoader::RegisterLoader(IsSupported, Check, Load);
}
ImageLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.streamChecker = Check;
loaderEntry.streamLoader = Load;
void UnregisterSTBLoader()
{
ImageLoader::UnregisterLoader(IsSupported, Check, Load);
return loaderEntry;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_FORMATS_STBLOADER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Image.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterSTBLoader();
void UnregisterSTBLoader();
}
ImageLoader::Entry GetImageLoader_STB();
}
#endif // NAZARA_FORMATS_STBLOADER_HPP

View File

@@ -15,36 +15,36 @@ namespace Nz
{
using FormatHandler = bool(*)(const Image& image, const ImageParams& parameters, Stream& stream);
std::map<std::string, FormatHandler> s_formatHandlers;
std::map<std::string_view, FormatHandler> s_formatHandlers;
int ConvertToFloatFormat(Image& image)
{
switch (image.GetFormat())
{
case PixelFormat_R32F:
case PixelFormat::R32F:
return 1;
case PixelFormat_RG32F:
case PixelFormat::RG32F:
return 2;
case PixelFormat_RGB32F:
case PixelFormat::RGB32F:
return 3;
case PixelFormat_RGBA32F:
case PixelFormat::RGBA32F:
return 4;
default:
{
if (PixelFormatInfo::HasAlpha(image.GetFormat()))
{
if (!image.Convert(PixelFormat_RGBA32F))
if (!image.Convert(PixelFormat::RGBA32F))
break;
return 4;
}
else
{
if (!image.Convert(PixelFormat_RGB32F))
if (!image.Convert(PixelFormat::RGB32F))
break;
return 3;
@@ -59,32 +59,32 @@ namespace Nz
{
switch (image.GetFormat())
{
case PixelFormat_L8:
case PixelFormat_R8:
case PixelFormat::L8:
case PixelFormat::R8:
return 1;
case PixelFormat_LA8:
case PixelFormat_RG8:
case PixelFormat::LA8:
case PixelFormat::RG8:
return 2;
case PixelFormat_RGB8:
case PixelFormat::RGB8:
return 3;
case PixelFormat_RGBA8:
case PixelFormat::RGBA8:
return 4;
default:
{
if (PixelFormatInfo::HasAlpha(image.GetFormat()))
{
if (!image.Convert(PixelFormat_RGBA8))
if (!image.Convert(PixelFormat::RGBA8))
break;
return 4;
}
else
{
if (!image.Convert(PixelFormat_RGB8))
if (!image.Convert(PixelFormat::RGB8))
break;
return 3;
@@ -102,7 +102,7 @@ namespace Nz
throw std::runtime_error("Failed to write to stream");
}
bool FormatQuerier(const std::string& extension)
bool FormatQuerier(const std::string_view& extension)
{
return s_formatHandlers.find(extension) != s_formatHandlers.end();
}
@@ -118,9 +118,9 @@ namespace Nz
}
ImageType type = image.GetType();
if (type != ImageType_1D && type != ImageType_2D)
if (type != ImageType::E1D && type != ImageType::E2D)
{
NazaraError("Image type 0x" + NumberToString(type, 16) + " is not in a supported format");
NazaraError("Image type 0x" + NumberToString(UnderlyingCast(type), 16) + " is not in a supported format");
return false;
}
@@ -262,22 +262,20 @@ namespace Nz
namespace Loaders
{
void RegisterSTBSaver()
ImageSaver::Entry GetImageSaver_STB()
{
s_formatHandlers["bmp"] = &SaveBMP;
s_formatHandlers["hdr"] = &SaveHDR;
s_formatHandlers["jpg"] = &SaveJPEG;
s_formatHandlers["bmp"] = &SaveBMP;
s_formatHandlers["hdr"] = &SaveHDR;
s_formatHandlers["jpg"] = &SaveJPEG;
s_formatHandlers["jpeg"] = &SaveJPEG;
s_formatHandlers["png"] = &SavePNG;
s_formatHandlers["tga"] = &SaveTGA;
s_formatHandlers["png"] = &SavePNG;
s_formatHandlers["tga"] = &SaveTGA;
ImageSaver::RegisterSaver(FormatQuerier, SaveToStream);
}
ImageSaver::Entry entry;
entry.formatSupport = FormatQuerier;
entry.streamSaver = SaveToStream;
void UnregisterSTBSaver()
{
ImageSaver::UnregisterSaver(FormatQuerier, SaveToStream);
s_formatHandlers.clear();
return entry;
}
}
}

View File

@@ -8,14 +8,11 @@
#define NAZARA_FORMATS_STBSAVER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Image.hpp>
namespace Nz
namespace Nz::Loaders
{
namespace Loaders
{
void RegisterSTBSaver();
void UnregisterSTBSaver();
}
ImageSaver::Entry GetImageSaver_STB();
}
#endif // NAZARA_FORMATS_STBSAVER_HPP

View File

@@ -75,7 +75,7 @@ namespace Nz
UInt32 GuillotineImageAtlas::GetStorage() const
{
return DataStorage_Software;
return static_cast<UInt32>(DataStorage::Software);
}
bool GuillotineImageAtlas::Insert(const Image& image, Rectui* rect, bool* flipped, unsigned int* layerIndex)
@@ -161,10 +161,10 @@ namespace Nz
AbstractImage* GuillotineImageAtlas::ResizeImage(AbstractImage* oldImage, const Vector2ui& size) const
{
std::unique_ptr<Image> newImage(new Image(ImageType_2D, PixelFormat_A8, size.x, size.y));
std::unique_ptr<Image> newImage(new Image(ImageType::E2D, PixelFormat::A8, size.x, size.y));
if (oldImage)
{
newImage->Copy(static_cast<Image*>(oldImage), Rectui(size), Vector2ui(0, 0)); // Copie des anciennes données
newImage->Copy(static_cast<Image&>(*oldImage), Rectui(size), Vector2ui(0, 0)); // Copie des anciennes données
}
return newImage.release();

View File

@@ -8,6 +8,7 @@
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <memory>
#include <Nazara/Utility/Debug.hpp>
@@ -66,8 +67,6 @@ namespace Nz
Image::~Image()
{
OnImageRelease(this);
Destroy();
}
@@ -102,7 +101,7 @@ namespace Nz
unsigned int height = m_sharedImage->height;
// Les images 3D et cubemaps sont stockés de la même façon
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth;
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth;
for (unsigned int i = 0; i < levels.size(); ++i)
{
@@ -132,7 +131,7 @@ namespace Nz
if (height > 1)
height >>= 1;
if (depth > 1 && m_sharedImage->type != ImageType_Cubemap)
if (depth > 1 && m_sharedImage->type != ImageType::Cubemap)
depth >>= 1;
}
@@ -144,13 +143,13 @@ namespace Nz
return true;
}
void Image::Copy(const Image* source, const Boxui& srcBox, const Vector3ui& dstPos)
void Image::Copy(const Image& source, const Boxui& srcBox, const Vector3ui& dstPos)
{
NazaraAssert(IsValid(), "Invalid image");
NazaraAssert(source && source->IsValid(), "Invalid source image");
NazaraAssert(source->GetFormat() == m_sharedImage->format, "Image formats don't match");
NazaraAssert(IsValid(), "invalid image");
NazaraAssert(source.IsValid(), "invalid source image");
NazaraAssert(source.GetFormat() == m_sharedImage->format, "image formats don't match");
const UInt8* srcPtr = source->GetConstPixels(srcBox.x, srcBox.y, srcBox.z);
const UInt8* srcPtr = source.GetConstPixels(srcBox.x, srcBox.y, srcBox.z);
#if NAZARA_UTILITY_SAFE
if (!srcPtr)
{
@@ -162,7 +161,7 @@ namespace Nz
UInt8 bpp = PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format);
UInt8* dstPtr = GetPixelPtr(m_sharedImage->levels[0].get(), bpp, dstPos.x, dstPos.y, dstPos.z, m_sharedImage->width, m_sharedImage->height);
Copy(dstPtr, srcPtr, m_sharedImage->format, srcBox.width, srcBox.height, srcBox.depth, m_sharedImage->width, m_sharedImage->height, source->GetWidth(), source->GetHeight());
Copy(dstPtr, srcPtr, m_sharedImage->format, srcBox.width, srcBox.height, srcBox.depth, m_sharedImage->width, m_sharedImage->height, source.GetWidth(), source.GetHeight());
}
bool Image::Create(ImageType type, PixelFormat format, unsigned int width, unsigned int height, unsigned int depth, UInt8 levelCount)
@@ -196,7 +195,7 @@ namespace Nz
switch (type)
{
case ImageType_1D:
case ImageType::E1D:
if (height > 1)
{
NazaraError("1D textures must be 1 tall");
@@ -210,8 +209,8 @@ namespace Nz
}
break;
case ImageType_1D_Array:
case ImageType_2D:
case ImageType::E1D_Array:
case ImageType::E2D:
if (depth > 1)
{
NazaraError("2D textures must be 1 deep");
@@ -219,11 +218,11 @@ namespace Nz
}
break;
case ImageType_2D_Array:
case ImageType_3D:
case ImageType::E2D_Array:
case ImageType::E3D:
break;
case ImageType_Cubemap:
case ImageType::Cubemap:
if (depth > 1)
{
NazaraError("Cubemaps must be 1 deep");
@@ -249,7 +248,7 @@ namespace Nz
unsigned int w = width;
unsigned int h = height;
unsigned int d = (type == ImageType_Cubemap) ? 6 : depth;
unsigned int d = (type == ImageType::Cubemap) ? 6 : depth;
for (unsigned int i = 0; i < levelCount; ++i)
{
@@ -264,7 +263,7 @@ namespace Nz
if (h > 1)
h >>= 1;
if (d > 1 && type != ImageType_Cubemap)
if (d > 1 && type != ImageType::Cubemap)
d >>= 1;
}
catch (const std::exception& e)
@@ -282,10 +281,7 @@ namespace Nz
void Image::Destroy()
{
if (m_sharedImage != &emptyImage)
{
OnImageDestroy(this);
ReleaseImage();
}
}
bool Image::Fill(const Color& color)
@@ -308,7 +304,7 @@ namespace Nz
UInt8 bpp = PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format);
std::unique_ptr<UInt8[]> colorBuffer(new UInt8[bpp]);
if (!PixelFormatInfo::Convert(PixelFormat_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get()))
if (!PixelFormatInfo::Convert(PixelFormat::RGBA8, m_sharedImage->format, &color.r, colorBuffer.get()))
{
NazaraError("Failed to convert RGBA8 to " + PixelFormatInfo::GetName(m_sharedImage->format));
return false;
@@ -320,7 +316,7 @@ namespace Nz
unsigned int height = m_sharedImage->height;
// Les images 3D et cubemaps sont stockés de la même façon
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth;
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth;
for (auto & level : levels)
{
@@ -342,7 +338,7 @@ namespace Nz
if (height > 1U)
height >>= 1;
if (depth > 1U && m_sharedImage->type != ImageType_Cubemap)
if (depth > 1U && m_sharedImage->type != ImageType::Cubemap)
depth >>= 1;
}
@@ -386,7 +382,7 @@ namespace Nz
UInt8 bpp = PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format);
std::unique_ptr<UInt8[]> colorBuffer(new UInt8[bpp]);
if (!PixelFormatInfo::Convert(PixelFormat_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get()))
if (!PixelFormatInfo::Convert(PixelFormat::RGBA8, m_sharedImage->format, &color.r, colorBuffer.get()))
{
NazaraError("Failed to convert RGBA8 to " + PixelFormatInfo::GetName(m_sharedImage->format));
return false;
@@ -446,7 +442,7 @@ namespace Nz
return false;
}
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth;
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth;
if (z >= depth)
{
NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')');
@@ -458,7 +454,7 @@ namespace Nz
UInt8 bpp = PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format);
std::unique_ptr<UInt8[]> colorBuffer(new UInt8[bpp]);
if (!PixelFormatInfo::Convert(PixelFormat_RGBA8, m_sharedImage->format, &color.r, colorBuffer.get()))
if (!PixelFormatInfo::Convert(PixelFormat::RGBA8, m_sharedImage->format, &color.r, colorBuffer.get()))
{
NazaraError("Failed to convert RGBA8 to " + PixelFormatInfo::GetName(m_sharedImage->format));
return false;
@@ -498,11 +494,11 @@ namespace Nz
unsigned int width = m_sharedImage->width;
unsigned int height = m_sharedImage->height;
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth;
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth;
for (auto& level : m_sharedImage->levels)
{
UInt8* ptr = level.get();
if (!PixelFormatInfo::Flip(PixelFlipping_Horizontally, m_sharedImage->format, width, height, depth, ptr, ptr))
if (!PixelFormatInfo::Flip(PixelFlipping::Horizontally, m_sharedImage->format, width, height, depth, ptr, ptr))
{
NazaraError("Failed to flip image");
return false;
@@ -514,7 +510,7 @@ namespace Nz
if (height > 1U)
height >>= 1;
if (depth > 1U && m_sharedImage->type != ImageType_Cubemap)
if (depth > 1U && m_sharedImage->type != ImageType::Cubemap)
depth >>= 1;
}
@@ -541,11 +537,11 @@ namespace Nz
unsigned int width = m_sharedImage->width;
unsigned int height = m_sharedImage->height;
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth;
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth;
for (auto& level : m_sharedImage->levels)
{
UInt8* ptr = level.get();
if (!PixelFormatInfo::Flip(PixelFlipping_Vertically, m_sharedImage->format, width, height, depth, ptr, ptr))
if (!PixelFormatInfo::Flip(PixelFlipping::Vertically, m_sharedImage->format, width, height, depth, ptr, ptr))
{
NazaraError("Failed to flip image");
return false;
@@ -557,7 +553,7 @@ namespace Nz
if (height > 1U)
height >>= 1;
if (depth > 1U && m_sharedImage->type != ImageType_Cubemap)
if (depth > 1U && m_sharedImage->type != ImageType::Cubemap)
depth >>= 1;
}
@@ -597,7 +593,7 @@ namespace Nz
return nullptr;
}
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
if (z >= depth)
{
NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')');
@@ -670,7 +666,7 @@ namespace Nz
depth >>= 1;
}
if (m_sharedImage->type == ImageType_Cubemap)
if (m_sharedImage->type == ImageType::Cubemap)
size *= 6;
return size * PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format);
@@ -678,7 +674,7 @@ namespace Nz
std::size_t Image::GetMemoryUsage(UInt8 level) const
{
return PixelFormatInfo::ComputeSize(m_sharedImage->format, GetLevelSize(m_sharedImage->width, level), GetLevelSize(m_sharedImage->height, level), ((m_sharedImage->type == ImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)));
return PixelFormatInfo::ComputeSize(m_sharedImage->format, GetLevelSize(m_sharedImage->width, level), GetLevelSize(m_sharedImage->height, level), ((m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)));
}
Color Image::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const
@@ -708,7 +704,7 @@ namespace Nz
return Color();
}
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth;
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth;
if (z >= depth)
{
NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')');
@@ -719,7 +715,7 @@ namespace Nz
const UInt8* pixel = GetPixelPtr(m_sharedImage->levels[0].get(), PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height);
Color color;
if (!PixelFormatInfo::Convert(m_sharedImage->format, PixelFormat_RGBA8, pixel, &color.r))
if (!PixelFormatInfo::Convert(m_sharedImage->format, PixelFormat::RGBA8, pixel, &color.r))
NazaraError("Failed to convert image's format to RGBA8");
return color;
@@ -758,7 +754,7 @@ namespace Nz
return nullptr;
}
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
if (z >= depth)
{
NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')');
@@ -820,7 +816,7 @@ namespace Nz
const PixelFormatDescription& info = PixelFormatInfo::GetInfo(m_sharedImage->format);
Bitset<> workingBitset;
std::size_t pixelCount = m_sharedImage->width * m_sharedImage->height * ((m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth);
std::size_t pixelCount = m_sharedImage->width * m_sharedImage->height * ((m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth);
if (pixelCount == 0)
return false;
@@ -851,21 +847,21 @@ namespace Nz
}
// LoadArray
ImageRef Image::LoadArrayFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams, const Vector2ui& atlasSize)
std::shared_ptr<Image> Image::LoadArrayFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams, const Vector2ui& atlasSize)
{
ImageRef image = Image::LoadFromFile(filePath, imageParams);
std::shared_ptr<Image> image = Image::LoadFromFile(filePath, imageParams);
if (!image)
{
NazaraError("Failed to load image");
return nullptr;
}
return LoadArrayFromImage(image, atlasSize);
return LoadArrayFromImage(*image, atlasSize);
}
ImageRef Image::LoadArrayFromImage(const Image* image, const Vector2ui& atlasSize)
std::shared_ptr<Image> Image::LoadArrayFromImage(const Image& image, const Vector2ui& atlasSize)
{
NazaraAssert(image && image->IsValid(), "Invalid image");
NazaraAssert(image.IsValid(), "Invalid image");
#if NAZARA_UTILITY_SAFE
if (atlasSize.x == 0)
@@ -881,17 +877,17 @@ namespace Nz
}
#endif
ImageType type = image->GetType();
ImageType type = image.GetType();
#if NAZARA_UTILITY_SAFE
if (type != ImageType_1D && type != ImageType_2D)
if (type != ImageType::E1D && type != ImageType::E2D)
{
NazaraError("Image type not handled (0x" + NumberToString(type, 16) + ')');
NazaraError("Image type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')');
return nullptr;
}
#endif
Vector2ui imageSize(image->GetWidth(), image->GetHeight());
Vector2ui imageSize(image.GetWidth(), image.GetHeight());
if (imageSize.x % atlasSize.x != 0)
{
@@ -907,12 +903,12 @@ namespace Nz
unsigned int layerCount = atlasSize.x*atlasSize.y;
ImageRef arrayImage = New();
std::shared_ptr<Image> arrayImage = std::make_shared<Image>();
// Selon le type de l'image de base, on va créer un array d'images 2D ou 1D
if (type == ImageType_2D)
arrayImage->Create(ImageType_2D_Array, image->GetFormat(), faceSize.x, faceSize.y, layerCount);
if (type == ImageType::E2D)
arrayImage->Create(ImageType::E2D_Array, image.GetFormat(), faceSize.x, faceSize.y, layerCount);
else
arrayImage->Create(ImageType_1D_Array, image->GetFormat(), faceSize.x, layerCount);
arrayImage->Create(ImageType::E1D_Array, image.GetFormat(), faceSize.x, layerCount);
if (!arrayImage->IsValid())
{
@@ -928,57 +924,57 @@ namespace Nz
return arrayImage;
}
ImageRef Image::LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams, const Vector2ui& atlasSize)
std::shared_ptr<Image> Image::LoadArrayFromMemory(const void* data, std::size_t size, const ImageParams& imageParams, const Vector2ui& atlasSize)
{
ImageRef image = Image::LoadFromMemory(data, size, imageParams);
std::shared_ptr<Image> image = Image::LoadFromMemory(data, size, imageParams);
if (!image)
{
NazaraError("Failed to load image");
return nullptr;
}
return LoadArrayFromImage(image, atlasSize);
return LoadArrayFromImage(*image, atlasSize);
}
ImageRef Image::LoadArrayFromStream(Stream& stream, const ImageParams& imageParams, const Vector2ui& atlasSize)
std::shared_ptr<Image> Image::LoadArrayFromStream(Stream& stream, const ImageParams& imageParams, const Vector2ui& atlasSize)
{
ImageRef image = Image::LoadFromStream(stream, imageParams);
std::shared_ptr<Image> image = Image::LoadFromStream(stream, imageParams);
if (!image)
{
NazaraError("Failed to load image");
return nullptr;
}
return LoadArrayFromImage(image, atlasSize);
return LoadArrayFromImage(*image, atlasSize);
}
ImageRef Image::LoadCubemapFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams, const CubemapParams& cubemapParams)
std::shared_ptr<Image> Image::LoadCubemapFromFile(const std::filesystem::path& filePath, const ImageParams& imageParams, const CubemapParams& cubemapParams)
{
ImageRef image = Image::LoadFromFile(filePath, imageParams);
std::shared_ptr<Image> image = Image::LoadFromFile(filePath, imageParams);
if (!image)
{
NazaraError("Failed to load image");
return nullptr;
}
return LoadCubemapFromImage(image, cubemapParams);
return LoadCubemapFromImage(*image, cubemapParams);
}
ImageRef Image::LoadCubemapFromImage(const Image* image, const CubemapParams& params)
std::shared_ptr<Image> Image::LoadCubemapFromImage(const Image& image, const CubemapParams& params)
{
NazaraAssert(image && image->IsValid(), "Invalid image");
NazaraAssert(image.IsValid(), "Invalid image");
#if NAZARA_UTILITY_SAFE
ImageType type = image->GetType();
if (type != ImageType_2D)
ImageType type = image.GetType();
if (type != ImageType::E2D)
{
NazaraError("Image type not handled (0x" + NumberToString(type, 16) + ')');
NazaraError("Image type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')');
return nullptr;
}
#endif
unsigned int width = image->GetWidth();
unsigned int height = image->GetHeight();
unsigned int width = image.GetWidth();
unsigned int height = image.GetHeight();
unsigned int faceSize = (params.faceSize == 0) ? std::max(width, height)/4 : params.faceSize;
// Sans cette vérification, celles des rectangles pourrait réussir via un overflow
@@ -1034,52 +1030,52 @@ namespace Nz
return nullptr;
}
ImageRef cubemap = New();
if (!cubemap->Create(ImageType_Cubemap, image->GetFormat(), faceSize, faceSize))
std::shared_ptr<Image> cubemap = std::make_shared<Image>();
if (!cubemap->Create(ImageType::Cubemap, image.GetFormat(), faceSize, faceSize))
{
NazaraError("Failed to create cubemap");
return nullptr;
}
cubemap->Copy(image, Rectui(backPos.x, backPos.y, faceSize, faceSize), Vector3ui(0, 0, CubemapFace_NegativeZ));
cubemap->Copy(image, Rectui(downPos.x, downPos.y, faceSize, faceSize), Vector3ui(0, 0, CubemapFace_NegativeY));
cubemap->Copy(image, Rectui(forwardPos.x, forwardPos.y, faceSize, faceSize), Vector3ui(0, 0, CubemapFace_PositiveZ));
cubemap->Copy(image, Rectui(leftPos.x, leftPos.y, faceSize, faceSize), Vector3ui(0, 0, CubemapFace_NegativeX));
cubemap->Copy(image, Rectui(rightPos.x, rightPos.y, faceSize, faceSize), Vector3ui(0, 0, CubemapFace_PositiveX));
cubemap->Copy(image, Rectui(upPos.x, upPos.y, faceSize, faceSize), Vector3ui(0, 0, CubemapFace_PositiveY));
cubemap->Copy(image, Rectui(backPos.x, backPos.y, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(CubemapFace::NegativeZ)));
cubemap->Copy(image, Rectui(downPos.x, downPos.y, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(CubemapFace::NegativeY)));
cubemap->Copy(image, Rectui(forwardPos.x, forwardPos.y, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(CubemapFace::PositiveZ)));
cubemap->Copy(image, Rectui(leftPos.x, leftPos.y, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(CubemapFace::NegativeX)));
cubemap->Copy(image, Rectui(rightPos.x, rightPos.y, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(CubemapFace::PositiveX)));
cubemap->Copy(image, Rectui(upPos.x, upPos.y, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(CubemapFace::PositiveY)));
return cubemap;
}
ImageRef Image::LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams, const CubemapParams& cubemapParams)
std::shared_ptr<Image> Image::LoadCubemapFromMemory(const void* data, std::size_t size, const ImageParams& imageParams, const CubemapParams& cubemapParams)
{
ImageRef image = Image::LoadFromMemory(data, size, imageParams);
std::shared_ptr<Image> image = Image::LoadFromMemory(data, size, imageParams);
if (!image)
{
NazaraError("Failed to load image");
return nullptr;
}
return LoadCubemapFromImage(image, cubemapParams);
return LoadCubemapFromImage(*image, cubemapParams);
}
ImageRef Image::LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams, const CubemapParams& cubemapParams)
std::shared_ptr<Image> Image::LoadCubemapFromStream(Stream& stream, const ImageParams& imageParams, const CubemapParams& cubemapParams)
{
ImageRef image = Image::LoadFromStream(stream, imageParams);
std::shared_ptr<Image> image = Image::LoadFromStream(stream, imageParams);
if (!image)
{
NazaraError("Failed to load image");
return nullptr;
}
return LoadCubemapFromImage(image, cubemapParams);
return LoadCubemapFromImage(*image, cubemapParams);
}
bool Image::LoadFaceFromFile(CubemapFace face, const std::filesystem::path& filePath, const ImageParams& params)
{
NazaraAssert(IsValid() && IsCubemap(), "Texture must be a valid cubemap");
ImageRef image = Image::LoadFromFile(filePath, params);
std::shared_ptr<Image> image = Image::LoadFromFile(filePath, params);
if (!image)
{
NazaraError("Failed to load image");
@@ -1099,7 +1095,7 @@ namespace Nz
return false;
}
Copy(image, Rectui(0, 0, faceSize, faceSize), Vector3ui(0, 0, face));
Copy(*image, Rectui(0, 0, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(face)));
return true;
}
@@ -1107,7 +1103,7 @@ namespace Nz
{
NazaraAssert(IsValid() && IsCubemap(), "Texture must be a valid cubemap");
ImageRef image = Image::LoadFromMemory(data, size, params);
std::shared_ptr<Image> image = Image::LoadFromMemory(data, size, params);
if (!image)
{
NazaraError("Failed to load image");
@@ -1127,7 +1123,7 @@ namespace Nz
return false;
}
Copy(image, Rectui(0, 0, faceSize, faceSize), Vector3ui(0, 0, face));
Copy(*image, Rectui(0, 0, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(face)));
return true;
}
@@ -1135,7 +1131,7 @@ namespace Nz
{
NazaraAssert(IsValid() && IsCubemap(), "Texture must be a valid cubemap");
ImageRef image = Image::LoadFromStream(stream, params);
std::shared_ptr<Image> image = Image::LoadFromStream(stream, params);
if (!image)
{
NazaraError("Failed to load image");
@@ -1155,18 +1151,24 @@ namespace Nz
return false;
}
Copy(image, Rectui(0, 0, faceSize, faceSize), Vector3ui(0, 0, face));
Copy(*image, Rectui(0, 0, faceSize, faceSize), Vector3ui(0, 0, UnderlyingCast(face)));
return true;
}
bool Image::SaveToFile(const std::filesystem::path& filePath, const ImageParams& params)
{
return ImageSaver::SaveToFile(*this, filePath, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetImageSaver().SaveToFile(*this, filePath, params);
}
bool Image::SaveToStream(Stream& stream, const std::string& format, const ImageParams& params)
{
return ImageSaver::SaveToStream(*this, stream, format, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetImageSaver().SaveToStream(*this, stream, format, params);
}
void Image::SetLevelCount(UInt8 levelCount)
@@ -1227,7 +1229,7 @@ namespace Nz
return false;
}
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth;
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : m_sharedImage->depth;
if (z >= depth)
{
NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')');
@@ -1237,7 +1239,7 @@ namespace Nz
UInt8* pixel = GetPixelPtr(m_sharedImage->levels[0].get(), PixelFormatInfo::GetBytesPerPixel(m_sharedImage->format), x, y, z, m_sharedImage->width, m_sharedImage->height);
if (!PixelFormatInfo::Convert(PixelFormat_RGBA8, m_sharedImage->format, &color.r, pixel))
if (!PixelFormatInfo::Convert(PixelFormat::RGBA8, m_sharedImage->format, &color.r, pixel))
{
NazaraError("Failed to convert RGBA8 to image's format");
return false;
@@ -1312,9 +1314,9 @@ namespace Nz
return false;
}
unsigned int depth = (m_sharedImage->type == ImageType_Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
if (box.x+box.width > width || box.y+box.height > height || box.z+box.depth > depth ||
(m_sharedImage->type == ImageType_Cubemap && box.depth > 1)) // Nous n'autorisons pas de modifier plus d'une face du cubemap à la fois
(m_sharedImage->type == ImageType::Cubemap && box.depth > 1)) // Nous n'autorisons pas de modifier plus d'une face du cubemap à la fois
{
NazaraError("Box dimensions are out of bounds");
return false;
@@ -1413,36 +1415,45 @@ namespace Nz
// Pour éviter que la profondeur ne soit comptée dans le calcul des niveaux
switch (type)
{
case ImageType_1D:
case ImageType_1D_Array:
case ImageType::E1D:
case ImageType::E1D_Array:
return GetMaxLevel(width, 1U, 1U);
case ImageType_2D:
case ImageType_2D_Array:
case ImageType_Cubemap:
case ImageType::E2D:
case ImageType::E2D_Array:
case ImageType::Cubemap:
return GetMaxLevel(width, height, 1U);
case ImageType_3D:
case ImageType::E3D:
return GetMaxLevel(width, height, depth);
}
NazaraError("Image type not handled (0x" + NumberToString(type, 16) + ')');
NazaraError("Image type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')');
return 0;
}
ImageRef Image::LoadFromFile(const std::filesystem::path& filePath, const ImageParams& params)
std::shared_ptr<Image> Image::LoadFromFile(const std::filesystem::path& filePath, const ImageParams& params)
{
return ImageLoader::LoadFromFile(filePath, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetImageLoader().LoadFromFile(filePath, params);
}
ImageRef Image::LoadFromMemory(const void* data, std::size_t size, const ImageParams& params)
std::shared_ptr<Image> Image::LoadFromMemory(const void* data, std::size_t size, const ImageParams& params)
{
return ImageLoader::LoadFromMemory(data, size, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetImageLoader().LoadFromMemory(data, size, params);
}
ImageRef Image::LoadFromStream(Stream& stream, const ImageParams& params)
std::shared_ptr<Image> Image::LoadFromStream(Stream& stream, const ImageParams& params)
{
return ImageLoader::LoadFromStream(stream, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetImageLoader().LoadFromStream(stream, params);
}
void Image::EnsureOwnership()
@@ -1476,33 +1487,5 @@ namespace Nz
m_sharedImage = &emptyImage;
}
bool Image::Initialize()
{
if (!ImageLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
if (!ImageManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true;
}
void Image::Uninitialize()
{
ImageManager::Uninitialize();
ImageLibrary::Uninitialize();
}
Image::SharedImage Image::emptyImage(0, ImageType_2D, PixelFormat_Undefined, Image::SharedImage::PixelContainer(), 0, 0, 0);
ImageLibrary::LibraryMap Image::s_library;
ImageLoader::LoaderList Image::s_loaders;
ImageManager::ManagerMap Image::s_managerMap;
ImageManager::ManagerParams Image::s_managerParameters;
ImageSaver::SaverList Image::s_savers;
Image::SharedImage Image::emptyImage(0, ImageType::E2D, PixelFormat::Undefined, Image::SharedImage::PixelContainer(), 0, 0, 0);
}

View File

@@ -13,13 +13,13 @@
namespace Nz
{
IndexBuffer::IndexBuffer(bool largeIndices, BufferRef buffer)
IndexBuffer::IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer)
{
ErrorFlags(ErrorFlag_ThrowException, true);
Reset(largeIndices, std::move(buffer));
}
IndexBuffer::IndexBuffer(bool largeIndices, BufferRef buffer, std::size_t offset, std::size_t size)
IndexBuffer::IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size)
{
ErrorFlags(ErrorFlag_ThrowException, true);
Reset(largeIndices, std::move(buffer), offset, size);
@@ -31,24 +31,9 @@ namespace Nz
Reset(largeIndices, length, storage, usage);
}
IndexBuffer::IndexBuffer(const IndexBuffer& indexBuffer) :
RefCounted(),
m_buffer(indexBuffer.m_buffer),
m_endOffset(indexBuffer.m_endOffset),
m_indexCount(indexBuffer.m_indexCount),
m_startOffset(indexBuffer.m_startOffset),
m_largeIndices(indexBuffer.m_largeIndices)
{
}
IndexBuffer::~IndexBuffer()
{
OnIndexBufferRelease(this);
}
unsigned int IndexBuffer::ComputeCacheMissCount() const
{
IndexMapper mapper(this);
IndexMapper mapper(*this);
return Nz::ComputeCacheMissCount(mapper.begin(), m_indexCount);
}
@@ -86,27 +71,27 @@ namespace Nz
void IndexBuffer::Optimize()
{
IndexMapper mapper(this);
IndexMapper mapper(*this);
OptimizeIndices(mapper.begin(), m_indexCount);
}
void IndexBuffer::Reset()
{
m_buffer.Reset();
m_buffer.reset();
}
void IndexBuffer::Reset(bool largeIndices, BufferRef buffer)
void IndexBuffer::Reset(bool largeIndices, std::shared_ptr<Buffer> buffer)
{
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
Reset(largeIndices, buffer, 0, buffer->GetSize());
}
void IndexBuffer::Reset(bool largeIndices, BufferRef buffer, std::size_t offset, std::size_t size)
void IndexBuffer::Reset(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size)
{
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
NazaraAssert(buffer->GetType() == BufferType_Index, "Buffer must be an index buffer");
NazaraAssert(buffer->GetType() == BufferType::Index, "Buffer must be an index buffer");
NazaraAssert(size > 0, "Invalid size");
NazaraAssert(offset + size > buffer->GetSize(), "Virtual buffer exceed buffer bounds");
@@ -128,7 +113,7 @@ namespace Nz
m_largeIndices = largeIndices;
m_startOffset = 0;
m_buffer = Buffer::New(BufferType_Index, m_endOffset, storage, usage);
m_buffer = std::make_shared<Buffer>(BufferType::Index, m_endOffset, storage, usage);
}
void IndexBuffer::Reset(const IndexBuffer& indexBuffer)
@@ -144,11 +129,4 @@ namespace Nz
{
m_buffer->Unmap();
}
IndexBuffer& IndexBuffer::operator=(const IndexBuffer& indexBuffer)
{
Reset(indexBuffer);
return *this;
}
}

View File

@@ -49,67 +49,50 @@ namespace Nz
}
}
IndexMapper::IndexMapper(IndexBuffer* indexBuffer, BufferAccess access, std::size_t indexCount) :
m_indexCount((indexCount != 0) ? indexCount : indexBuffer->GetIndexCount())
IndexMapper::IndexMapper(IndexBuffer& indexBuffer, BufferAccess access, std::size_t indexCount) :
m_indexCount((indexCount != 0) ? indexCount : indexBuffer.GetIndexCount())
{
NazaraAssert(indexCount != 0 || indexBuffer, "Invalid index count with invalid index buffer");
if (!m_mapper.Map(indexBuffer, access))
NazaraError("Failed to map buffer"); ///TODO: Unexcepted
if (indexBuffer)
if (indexBuffer.HasLargeIndices())
{
if (!m_mapper.Map(indexBuffer, access))
NazaraError("Failed to map buffer"); ///TODO: Unexcepted
if (indexBuffer->HasLargeIndices())
{
m_getter = Getter32;
if (access != BufferAccess_ReadOnly)
m_setter = Setter32;
else
m_setter = SetterError;
}
m_getter = Getter32;
if (access != BufferAccess::ReadOnly)
m_setter = Setter32;
else
{
m_getter = Getter16;
if (access != BufferAccess_ReadOnly)
m_setter = Setter16;
else
m_setter = SetterError;
}
m_setter = SetterError;
}
else
{
m_getter = GetterSequential;
m_setter = SetterError;
m_getter = Getter16;
if (access != BufferAccess::ReadOnly)
m_setter = Setter16;
else
m_setter = SetterError;
}
}
IndexMapper::IndexMapper(SubMesh* subMesh, BufferAccess access) :
IndexMapper(subMesh->GetIndexBuffer(), access, (subMesh->GetIndexBuffer()) ? 0 : subMesh->GetVertexCount())
IndexMapper::IndexMapper(SubMesh& subMesh, BufferAccess access) :
IndexMapper(*subMesh.GetIndexBuffer(), access, (subMesh.GetIndexBuffer()) ? 0 : subMesh.GetVertexCount())
{
}
IndexMapper::IndexMapper(const IndexBuffer* indexBuffer, BufferAccess access, std::size_t indexCount) :
IndexMapper::IndexMapper(const IndexBuffer& indexBuffer, BufferAccess access, std::size_t indexCount) :
m_setter(SetterError),
m_indexCount((indexCount != 0) ? indexCount : indexBuffer->GetIndexCount())
m_indexCount((indexCount != 0) ? indexCount : indexBuffer.GetIndexCount())
{
NazaraAssert(indexCount != 0 || indexBuffer, "Invalid index count with invalid index buffer");
if (!m_mapper.Map(indexBuffer, access))
NazaraError("Failed to map buffer"); ///TODO: Unexcepted
if (indexBuffer)
{
if (!m_mapper.Map(indexBuffer, access))
NazaraError("Failed to map buffer"); ///TODO: Unexcepted
if (indexBuffer->HasLargeIndices())
m_getter = Getter32;
else
m_getter = Getter16;
}
if (indexBuffer.HasLargeIndices())
m_getter = Getter32;
else
m_getter = GetterSequential;
m_getter = Getter16;
}
IndexMapper::IndexMapper(const SubMesh* subMesh, BufferAccess access) :
IndexMapper(subMesh->GetIndexBuffer(), access, (subMesh->GetIndexBuffer()) ? 0 : subMesh->GetVertexCount())
IndexMapper::IndexMapper(const SubMesh& subMesh, BufferAccess access) :
IndexMapper(*subMesh.GetIndexBuffer(), access, (subMesh.GetIndexBuffer()) ? 0 : subMesh.GetVertexCount())
{
}

View File

@@ -14,6 +14,7 @@
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/StaticMesh.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/VertexMapper.hpp>
#include <limits>
#include <memory>
@@ -25,7 +26,7 @@ namespace Nz
MeshParams::MeshParams()
{
if (!Buffer::IsStorageSupported(storage))
storage = DataStorage_Software;
storage = DataStorage::Software;
}
bool MeshParams::IsValid() const
@@ -48,7 +49,7 @@ namespace Nz
return false;
}
if (!vertexDeclaration->HasComponent(VertexComponent_Position))
if (!vertexDeclaration->HasComponent(VertexComponent::Position))
{
NazaraError("Vertex declaration must contains a vertex position");
return false;
@@ -58,7 +59,7 @@ namespace Nz
}
void Mesh::AddSubMesh(SubMesh* subMesh)
void Mesh::AddSubMesh(std::shared_ptr<SubMesh> subMesh)
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(subMesh, "Invalid submesh");
@@ -66,13 +67,13 @@ namespace Nz
m_subMeshes.emplace_back();
SubMeshData& subMeshData = m_subMeshes.back();
subMeshData.subMesh = subMesh;
subMeshData.onSubMeshInvalidated.Connect(subMesh->OnSubMeshInvalidateAABB, [this](const SubMesh* /*subMesh*/) { InvalidateAABB(); });
subMeshData.subMesh = std::move(subMesh);
subMeshData.onSubMeshInvalidated.Connect(subMeshData.subMesh->OnSubMeshInvalidateAABB, [this](const SubMesh* /*subMesh*/) { InvalidateAABB(); });
InvalidateAABB();
}
void Mesh::AddSubMesh(const std::string& identifier, SubMesh* subMesh)
void Mesh::AddSubMesh(const std::string& identifier, std::shared_ptr<SubMesh> subMesh)
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(!identifier.empty(), "Identifier is empty");
@@ -82,26 +83,26 @@ namespace Nz
std::size_t index = m_subMeshes.size();
AddSubMesh(subMesh);
AddSubMesh(std::move(subMesh));
m_subMeshMap[identifier] = static_cast<std::size_t>(index);
}
SubMesh* Mesh::BuildSubMesh(const Primitive& primitive, const MeshParams& params)
std::shared_ptr<SubMesh> Mesh::BuildSubMesh(const Primitive& primitive, const MeshParams& params)
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(m_animationType == AnimationType_Static, "Submesh building only works for static meshes");
NazaraAssert(m_animationType == AnimationType::Static, "Submesh building only works for static meshes");
NazaraAssert(params.IsValid(), "Invalid parameters");
NazaraAssert(params.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent_Position), "The vertex declaration doesn't have a Vector3 position component");
NazaraAssert(params.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent::Position), "The vertex declaration doesn't have a Vector3 position component");
Boxf aabb;
IndexBufferRef indexBuffer;
VertexBufferRef vertexBuffer;
std::shared_ptr<IndexBuffer> indexBuffer;
std::shared_ptr<VertexBuffer> vertexBuffer;
Matrix4f matrix(primitive.matrix);
matrix *= params.matrix;
VertexDeclaration* declaration = params.vertexDeclaration;
const std::shared_ptr<VertexDeclaration>& declaration = params.vertexDeclaration;
switch (primitive.type)
{
@@ -111,18 +112,18 @@ namespace Nz
unsigned int vertexCount;
ComputeBoxIndexVertexCount(primitive.box.subdivision, &indexCount, &vertexCount);
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags);
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.storage, params.vertexBufferFlags);
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::WriteOnly);
VertexPointers pointers;
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
GenerateBox(primitive.box.lengths, primitive.box.subdivision, matrix, primitive.textureCoords, pointers, indexMapper.begin(), &aabb);
break;
}
@@ -133,18 +134,18 @@ namespace Nz
unsigned int vertexCount;
ComputeConeIndexVertexCount(primitive.cone.subdivision, &indexCount, &vertexCount);
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags);
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.storage, params.vertexBufferFlags);
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::WriteOnly);
VertexPointers pointers;
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
GenerateCone(primitive.cone.length, primitive.cone.radius, primitive.cone.subdivision, matrix, primitive.textureCoords, pointers, indexMapper.begin(), &aabb);
break;
}
@@ -155,18 +156,18 @@ namespace Nz
unsigned int vertexCount;
ComputePlaneIndexVertexCount(primitive.plane.subdivision, &indexCount, &vertexCount);
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags);
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.storage, params.vertexBufferFlags);
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::WriteOnly);
VertexPointers pointers;
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
GeneratePlane(primitive.plane.subdivision, primitive.plane.size, matrix, primitive.textureCoords, pointers, indexMapper.begin(), &aabb);
break;
}
@@ -181,18 +182,18 @@ namespace Nz
unsigned int vertexCount;
ComputeCubicSphereIndexVertexCount(primitive.sphere.cubic.subdivision, &indexCount, &vertexCount);
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags);
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.storage, params.vertexBufferFlags);
VertexMapper vertexMapper(vertexBuffer, BufferAccess_ReadWrite);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::ReadWrite);
VertexPointers pointers;
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
GenerateCubicSphere(primitive.sphere.size, primitive.sphere.cubic.subdivision, matrix, primitive.textureCoords, pointers, indexMapper.begin(), &aabb);
break;
}
@@ -203,18 +204,18 @@ namespace Nz
unsigned int vertexCount;
ComputeIcoSphereIndexVertexCount(primitive.sphere.ico.recursionLevel, &indexCount, &vertexCount);
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags);
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.storage, params.vertexBufferFlags);
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::WriteOnly);
VertexPointers pointers;
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
GenerateIcoSphere(primitive.sphere.size, primitive.sphere.ico.recursionLevel, matrix, primitive.textureCoords, pointers, indexMapper.begin(), &aabb);
break;
}
@@ -225,18 +226,18 @@ namespace Nz
unsigned int vertexCount;
ComputeUvSphereIndexVertexCount(primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, &indexCount, &vertexCount);
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags);
indexBuffer = std::make_shared<IndexBuffer>(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags);
vertexBuffer = std::make_shared<VertexBuffer>(declaration, vertexCount, params.storage, params.vertexBufferFlags);
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::WriteOnly);
VertexPointers pointers;
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
IndexMapper indexMapper(*indexBuffer, BufferAccess::WriteOnly);
GenerateUvSphere(primitive.sphere.size, primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, matrix, primitive.textureCoords, pointers, indexMapper.begin(), &aabb);
break;
}
@@ -248,7 +249,7 @@ namespace Nz
if (params.optimizeIndexBuffers)
indexBuffer->Optimize();
StaticMeshRef subMesh = StaticMesh::New(vertexBuffer, indexBuffer);
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer);
subMesh->SetAABB(aabb);
AddSubMesh(subMesh);
@@ -265,7 +266,7 @@ namespace Nz
{
Destroy();
m_animationType = AnimationType_Skeletal;
m_animationType = AnimationType::Skeletal;
m_jointCount = jointCount;
if (!m_skeleton.Create(jointCount))
{
@@ -282,7 +283,7 @@ namespace Nz
{
Destroy();
m_animationType = AnimationType_Static;
m_animationType = AnimationType::Static;
m_isValid = true;
return true;
@@ -292,8 +293,6 @@ namespace Nz
{
if (m_isValid)
{
OnMeshDestroy(this);
m_animationPath.clear();
m_materialData.clear();
m_materialData.resize(1);
@@ -368,7 +367,7 @@ namespace Nz
std::size_t Mesh::GetJointCount() const
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(m_animationType == AnimationType_Skeletal, "Mesh is not skeletal");
NazaraAssert(m_animationType == AnimationType::Skeletal, "Mesh is not skeletal");
return m_jointCount;
}
@@ -399,7 +398,7 @@ namespace Nz
Skeleton* Mesh::GetSkeleton()
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(m_animationType == AnimationType_Skeletal, "Mesh is not skeletal");
NazaraAssert(m_animationType == AnimationType::Skeletal, "Mesh is not skeletal");
return &m_skeleton;
}
@@ -407,12 +406,12 @@ namespace Nz
const Skeleton* Mesh::GetSkeleton() const
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(m_animationType == AnimationType_Skeletal, "Mesh is not skeletal");
NazaraAssert(m_animationType == AnimationType::Skeletal, "Mesh is not skeletal");
return &m_skeleton;
}
SubMesh* Mesh::GetSubMesh(const std::string& identifier)
const std::shared_ptr<SubMesh>& Mesh::GetSubMesh(const std::string& identifier) const
{
NazaraAssert(m_isValid, "Mesh should be created first");
@@ -422,25 +421,7 @@ namespace Nz
return m_subMeshes[it->second].subMesh;
}
SubMesh* Mesh::GetSubMesh(std::size_t index)
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(index < m_subMeshes.size(), "Submesh index out of range");
return m_subMeshes[index].subMesh;
}
const SubMesh* Mesh::GetSubMesh(const std::string& identifier) const
{
NazaraAssert(m_isValid, "Mesh should be created first");
auto it = m_subMeshMap.find(identifier);
NazaraAssert(it != m_subMeshMap.end(), "SubMesh " + identifier + " not found");
return m_subMeshes[it->second].subMesh;
}
const SubMesh* Mesh::GetSubMesh(std::size_t index) const
const std::shared_ptr<SubMesh>& Mesh::GetSubMesh(std::size_t index) const
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(index < m_subMeshes.size(), "Submesh index out of range");
@@ -514,7 +495,7 @@ namespace Nz
{
NazaraAssert(m_isValid, "Mesh should be created first");
return m_animationType != AnimationType_Static;
return m_animationType != AnimationType::Static;
}
bool Mesh::IsValid() const
@@ -525,7 +506,7 @@ namespace Nz
void Mesh::Recenter()
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(m_animationType == AnimationType_Static, "Mesh is not static");
NazaraAssert(m_animationType == AnimationType::Static, "Mesh is not static");
// The center of our mesh is the center of our *global* AABB
Vector3f center = GetAABB().GetCenter();
@@ -534,7 +515,7 @@ namespace Nz
{
StaticMesh& staticMesh = static_cast<StaticMesh&>(*data.subMesh);
BufferMapper<VertexBuffer> mapper(staticMesh.GetVertexBuffer(), BufferAccess_ReadWrite);
BufferMapper<VertexBuffer> mapper(*staticMesh.GetVertexBuffer(), BufferAccess::ReadWrite);
MeshVertex* vertices = static_cast<MeshVertex*>(mapper.GetPointer());
std::size_t vertexCount = staticMesh.GetVertexCount();
@@ -577,12 +558,18 @@ namespace Nz
bool Mesh::SaveToFile(const std::filesystem::path& filePath, const MeshParams& params)
{
return MeshSaver::SaveToFile(*this, filePath, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetMeshSaver().SaveToFile(*this, filePath, params);
}
bool Mesh::SaveToStream(Stream& stream, const std::string& format, const MeshParams& params)
{
return MeshSaver::SaveToStream(*this, stream, format, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetMeshSaver().SaveToStream(*this, stream, format, params);
}
void Mesh::SetAnimation(const std::filesystem::path& animationPath)
@@ -614,7 +601,7 @@ namespace Nz
if (matIndex >= matCount)
{
data.subMesh->SetMaterialIndex(0); // To prevent a crash
NazaraWarning("SubMesh " + PointerToString(data.subMesh) + " material index is over mesh new material count (" + NumberToString(matIndex) + " >= " + NumberToString(matCount) + "), setting it to first material");
NazaraWarning("SubMesh " + PointerToString(data.subMesh.get()) + " material index is over mesh new material count (" + NumberToString(matIndex) + " >= " + NumberToString(matCount) + "), setting it to first material");
}
}
#endif
@@ -623,13 +610,13 @@ namespace Nz
void Mesh::Transform(const Matrix4f& matrix)
{
NazaraAssert(m_isValid, "Mesh should be created first");
NazaraAssert(m_animationType == AnimationType_Static, "Mesh is not static");
NazaraAssert(m_animationType == AnimationType::Static, "Mesh is not static");
for (SubMeshData& data : m_subMeshes)
{
StaticMesh& staticMesh = static_cast<StaticMesh&>(*data.subMesh);
BufferMapper<VertexBuffer> mapper(staticMesh.GetVertexBuffer(), BufferAccess_ReadWrite);
BufferMapper<VertexBuffer> mapper(*staticMesh.GetVertexBuffer(), BufferAccess::ReadWrite);
MeshVertex* vertices = static_cast<MeshVertex*>(mapper.GetPointer());
Boxf aabb(vertices->position.x, vertices->position.y, vertices->position.z, 0.f, 0.f, 0.f);
@@ -647,47 +634,27 @@ namespace Nz
}
}
MeshRef Mesh::LoadFromFile(const std::filesystem::path& filePath, const MeshParams& params)
std::shared_ptr<Mesh> Mesh::LoadFromFile(const std::filesystem::path& filePath, const MeshParams& params)
{
return MeshLoader::LoadFromFile(filePath, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetMeshLoader().LoadFromFile(filePath, params);
}
MeshRef Mesh::LoadFromMemory(const void* data, std::size_t size, const MeshParams& params)
std::shared_ptr<Mesh> Mesh::LoadFromMemory(const void* data, std::size_t size, const MeshParams& params)
{
return MeshLoader::LoadFromMemory(data, size, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetMeshLoader().LoadFromMemory(data, size, params);
}
MeshRef Mesh::LoadFromStream(Stream& stream, const MeshParams& params)
std::shared_ptr<Mesh> Mesh::LoadFromStream(Stream& stream, const MeshParams& params)
{
return MeshLoader::LoadFromStream(stream, params);
Utility* utility = Utility::Instance();
NazaraAssert(utility, "Utility module has not been initialized");
return utility->GetMeshLoader().LoadFromStream(stream, params);
}
bool Mesh::Initialize()
{
if (!MeshLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
if (!MeshManager::Initialize())
{
NazaraError("Failed to initialise manager");
return false;
}
return true;
}
void Mesh::Uninitialize()
{
MeshManager::Uninitialize();
MeshLibrary::Uninitialize();
}
MeshLibrary::LibraryMap Mesh::s_library;
MeshLoader::LoaderList Mesh::s_loaders;
MeshManager::ManagerMap Mesh::s_managerMap;
MeshManager::ManagerParams Mesh::s_managerParameters;
MeshSaver::SaverList Mesh::s_savers;
}

View File

@@ -136,7 +136,7 @@ namespace Nz
NodeType Node::GetNodeType() const
{
return NodeType_Default;
return NodeType::Default;
}
const Node* Node::GetParent() const

File diff suppressed because it is too large Load Diff

View File

@@ -126,7 +126,7 @@ namespace Nz
return m_bounds;
}
Font* RichTextDrawer::GetFont(std::size_t index) const
const std::shared_ptr<Font>& RichTextDrawer::GetFont(std::size_t index) const
{
NazaraAssert(index < m_fonts.size(), "Font index out of range");
@@ -285,12 +285,12 @@ namespace Nz
return *this;
}
void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset, std::size_t glyphIndex, float glyphPosition) const
void RichTextDrawer::AppendNewLine(const Font& font, unsigned int characterSize, float lineSpacingOffset, std::size_t glyphIndex, float glyphPosition) const
{
// Ensure we're appending from last line
Line& lastLine = m_lines.back();
const Font::SizeInfo& sizeInfo = font->GetSizeInfo(characterSize);
const Font::SizeInfo& sizeInfo = font.GetSizeInfo(characterSize);
float previousDrawPos = m_drawPos.x;
@@ -336,12 +336,12 @@ namespace Nz
}
}
bool RichTextDrawer::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
bool RichTextDrawer::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
{
const Font::Glyph& fontGlyph = font->GetGlyph(characterSize, style, outlineThickness, character);
const Font::Glyph& fontGlyph = font.GetGlyph(characterSize, style, outlineThickness, character);
if (fontGlyph.valid && fontGlyph.fauxOutlineThickness <= 0.f)
{
glyph.atlas = font->GetAtlas()->GetLayer(fontGlyph.layerIndex);
glyph.atlas = font.GetAtlas()->GetLayer(fontGlyph.layerIndex);
glyph.atlasRect = fontGlyph.atlasRect;
glyph.color = color;
glyph.flipped = fontGlyph.flipped;
@@ -376,7 +376,7 @@ namespace Nz
return false;
};
void RichTextDrawer::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
void RichTextDrawer::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
{
if (text.empty())
return;
@@ -391,7 +391,7 @@ namespace Nz
char32_t previousCharacter = 0;
const Font::SizeInfo& sizeInfo = font->GetSizeInfo(characterSize);
const Font::SizeInfo& sizeInfo = font.GetSizeInfo(characterSize);
float lineHeight = GetLineHeight(lineSpacingOffset, sizeInfo);
float heightDifference = lineHeight - m_lines.back().bounds.height;
@@ -414,7 +414,7 @@ namespace Nz
for (char32_t character : characters)
{
if (previousCharacter != 0)
m_drawPos.x += font->GetKerning(characterSize, previousCharacter, character);
m_drawPos.x += font.GetKerning(characterSize, previousCharacter, character);
previousCharacter = character;
@@ -500,7 +500,7 @@ namespace Nz
NazaraUnused(font);
#ifdef NAZARA_DEBUG
auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font == font; });
auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font.get() == font; });
if (it == m_fonts.end())
{
NazaraInternalError("Not listening to " + PointerToString(font));
@@ -522,7 +522,7 @@ namespace Nz
NazaraUnused(font);
#ifdef NAZARA_DEBUG
auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font == font; });
auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font.get() == font; });
if (it == m_fonts.end())
{
NazaraInternalError("Not listening to " + PointerToString(font));
@@ -539,7 +539,7 @@ namespace Nz
NazaraUnused(font);
#ifdef NAZARA_DEBUG
auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font == font; });
auto it = std::find_if(m_fonts.begin(), m_fonts.end(), [font](const auto& fontData) { return fontData.font.get() == font; });
if (it == m_fonts.end())
{
NazaraInternalError("Not listening to " + PointerToString(font));
@@ -573,7 +573,7 @@ namespace Nz
assert(block.fontIndex < m_fonts.size());
const auto& fontData = m_fonts[block.fontIndex];
GenerateGlyphs(fontData.font, block.color, block.style, block.characterSize, block.outlineColor, block.outlineThickness, block.characterSpacingOffset, block.lineSpacingOffset, block.text);
GenerateGlyphs(*fontData.font, block.color, block.style, block.characterSize, block.outlineColor, block.outlineThickness, block.characterSpacingOffset, block.lineSpacingOffset, block.text);
}
}
else

View File

@@ -23,7 +23,7 @@ namespace Nz
return m_bounds;
}
Font* SimpleTextDrawer::GetFont(std::size_t index) const
const std::shared_ptr<Font>& SimpleTextDrawer::GetFont(std::size_t index) const
{
NazaraAssert(index == 0, "Font index out of range");
NazaraUnused(index);
@@ -288,7 +288,7 @@ namespace Nz
NazaraUnused(font);
#ifdef NAZARA_DEBUG
if (m_font != font)
if (m_font.get() != font)
{
NazaraInternalError("Not listening to " + PointerToString(font));
return;
@@ -309,7 +309,7 @@ namespace Nz
NazaraUnused(font);
#ifdef NAZARA_DEBUG
if (m_font != font)
if (m_font.get() != font)
{
NazaraInternalError("Not listening to " + PointerToString(font));
return;
@@ -325,7 +325,7 @@ namespace Nz
NazaraUnused(font);
#ifdef NAZARA_DEBUG
if (m_font != font)
if (m_font.get() != font)
{
NazaraInternalError("Not listening to " + PointerToString(font));
return;

View File

@@ -8,53 +8,14 @@
namespace Nz
{
SkeletalMesh::SkeletalMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer) :
SkeletalMesh::SkeletalMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer) :
m_aabb(Nz::Boxf::Zero()),
m_indexBuffer(indexBuffer),
m_vertexBuffer(vertexBuffer)
m_indexBuffer(std::move(indexBuffer)),
m_vertexBuffer(std::move(vertexBuffer))
{
NazaraAssert(m_vertexBuffer, "Invalid vertex buffer");
}
SkeletalMesh::SkeletalMesh(const Mesh* /*parent*/) :
m_aabb(Nz::Boxf::Zero())
{
}
SkeletalMesh::~SkeletalMesh()
{
OnSkeletalMeshRelease(this);
Destroy();
}
bool SkeletalMesh::Create(VertexBuffer* vertexBuffer)
{
Destroy();
#if NAZARA_UTILITY_SAFE
if (!vertexBuffer)
{
NazaraError("Invalid vertex buffer");
return false;
}
#endif
m_vertexBuffer = vertexBuffer;
return true;
}
void SkeletalMesh::Destroy()
{
if (m_vertexBuffer)
{
OnSkeletalMeshDestroy(this);
m_indexBuffer.Reset();
m_vertexBuffer.Reset();
}
}
const Boxf& SkeletalMesh::GetAABB() const
{
return m_aabb;
@@ -62,20 +23,15 @@ namespace Nz
AnimationType SkeletalMesh::GetAnimationType() const
{
return AnimationType_Skeletal;
return AnimationType::Skeletal;
}
const IndexBuffer* SkeletalMesh::GetIndexBuffer() const
const std::shared_ptr<const IndexBuffer>& SkeletalMesh::GetIndexBuffer() const
{
return m_indexBuffer;
}
VertexBuffer* SkeletalMesh::GetVertexBuffer()
{
return m_vertexBuffer;
}
const VertexBuffer* SkeletalMesh::GetVertexBuffer() const
const std::shared_ptr<VertexBuffer>& SkeletalMesh::GetVertexBuffer() const
{
return m_vertexBuffer;
}
@@ -102,8 +58,8 @@ namespace Nz
OnSubMeshInvalidateAABB(this);
}
void SkeletalMesh::SetIndexBuffer(const IndexBuffer* indexBuffer)
void SkeletalMesh::SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer)
{
m_indexBuffer = indexBuffer;
m_indexBuffer = std::move(indexBuffer);
}
}

View File

@@ -18,58 +18,36 @@ namespace Nz
bool jointMapUpdated = false;
};
Skeleton::Skeleton(const Skeleton& skeleton) :
RefCounted(),
m_impl(nullptr)
Skeleton::Skeleton() = default;
Skeleton::Skeleton(const Skeleton& skeleton)
{
operator=(skeleton);
}
Skeleton::~Skeleton()
{
OnSkeletonRelease(this);
Destroy();
}
Skeleton::Skeleton(Skeleton&&) noexcept = default;
Skeleton::~Skeleton() = default;
bool Skeleton::Create(std::size_t jointCount)
{
#if NAZARA_UTILITY_SAFE
if (jointCount == 0)
{
NazaraError("Joint count must be over zero");
return false;
}
#endif
NazaraAssert(jointCount > 0, "joint count must be over zero");
m_impl = new SkeletonImpl;
m_impl->joints.resize(jointCount, Joint(this));
m_impl = std::make_unique<SkeletonImpl>();
m_impl->joints.reserve(jointCount);
for (std::size_t i = 0; i < jointCount; ++i)
m_impl->joints.emplace_back(this);
return true;
}
void Skeleton::Destroy()
{
if (m_impl)
{
OnSkeletonDestroy(this);
delete m_impl;
m_impl = nullptr;
}
m_impl.reset();
}
const Boxf& Skeleton::GetAABB() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
static Boxf dummy;
return dummy;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
if (!m_impl->aabbUpdated)
{
@@ -92,240 +70,109 @@ namespace Nz
Joint* Skeleton::GetJoint(const std::string& jointName)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return nullptr;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
if (!m_impl->jointMapUpdated)
UpdateJointMap();
auto it = m_impl->jointMap.find(jointName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->jointMap.end())
{
NazaraError("Joint not found");
return nullptr;
}
#endif
NazaraAssert(it != m_impl->jointMap.end(), "joint not found");
InvalidateJoints();
return &m_impl->joints[it->second];
}
Joint* Skeleton::GetJoint(std::size_t index)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return nullptr;
}
if (index >= m_impl->joints.size())
{
NazaraError("Joint index out of range (" + NumberToString(index) + " >= " + NumberToString(m_impl->joints.size()) + ')');
return nullptr;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
NazaraAssert(index < m_impl->joints.size(), "joint index out of range");
InvalidateJoints();
return &m_impl->joints[index];
}
const Joint* Skeleton::GetJoint(const std::string& jointName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return nullptr;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
if (!m_impl->jointMapUpdated)
UpdateJointMap();
auto it = m_impl->jointMap.find(jointName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->jointMap.end())
{
NazaraError("Joint not found");
return nullptr;
}
#endif
NazaraAssert(it != m_impl->jointMap.end(), "joint not found");
return &m_impl->joints[it->second];
}
const Joint* Skeleton::GetJoint(std::size_t index) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return nullptr;
}
if (index >= m_impl->joints.size())
{
NazaraError("Joint index out of range (" + NumberToString(index) + " >= " + NumberToString(m_impl->joints.size()) + ')');
return nullptr;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
NazaraAssert(index < m_impl->joints.size(), "joint index out of range");
return &m_impl->joints[index];
}
Joint* Skeleton::GetJoints()
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return nullptr;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
InvalidateJoints();
return &m_impl->joints[0];
}
const Joint* Skeleton::GetJoints() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return nullptr;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
return &m_impl->joints[0];
}
std::size_t Skeleton::GetJointCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return 0;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
return static_cast<std::size_t>(m_impl->joints.size());
}
int Skeleton::GetJointIndex(const std::string& jointName) const
std::size_t Skeleton::GetJointIndex(const std::string& jointName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return -1;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
if (!m_impl->jointMapUpdated)
UpdateJointMap();
auto it = m_impl->jointMap.find(jointName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->jointMap.end())
{
NazaraError("Joint not found");
return -1;
}
#endif
NazaraAssert(it != m_impl->jointMap.end(), "joint not found");
return it->second;
}
void Skeleton::Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return;
}
NazaraAssert(m_impl, "skeleton must have been created");
NazaraAssert(skeletonA.IsValid(), "first skeleton is invalid");
NazaraAssert(skeletonB.IsValid(), "second skeleton is invalid");
NazaraAssert(skeletonA.GetJointCount() == skeletonB.GetJointCount() && m_impl->joints.size() == skeletonA.GetJointCount(), "both skeletons must have the same number of joints");
if (!skeletonA.IsValid())
{
NazaraError("Skeleton A is invalid");
return;
}
if (!skeletonB.IsValid())
{
NazaraError("Skeleton B is invalid");
return;
}
if (skeletonA.GetJointCount() != skeletonB.GetJointCount() || m_impl->joints.size() != skeletonA.GetJointCount())
{
NazaraError("Skeletons must have the same joint count");
return;
}
#endif
Joint* jointsA = &skeletonA.m_impl->joints[0];
Joint* jointsB = &skeletonB.m_impl->joints[0];
const Joint* jointsA = &skeletonA.m_impl->joints[0];
const Joint* jointsB = &skeletonB.m_impl->joints[0];
for (std::size_t i = 0; i < m_impl->joints.size(); ++i)
m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, CoordSys_Local);
InvalidateJoints();
}
void Skeleton::Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, std::size_t* indices, std::size_t indiceCount)
void Skeleton::Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, const std::size_t* indices, std::size_t indiceCount)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Skeleton not created");
return;
}
if (!skeletonA.IsValid())
{
NazaraError("Skeleton A is invalid");
return;
}
if (!skeletonB.IsValid())
{
NazaraError("Skeleton B is invalid");
return;
}
if (skeletonA.GetJointCount() != skeletonB.GetJointCount() || m_impl->joints.size() != skeletonA.GetJointCount())
{
NazaraError("Skeletons must have the same joint count");
return;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
NazaraAssert(skeletonA.IsValid(), "first skeleton is invalid");
NazaraAssert(skeletonB.IsValid(), "second skeleton is invalid");
NazaraAssert(skeletonA.GetJointCount() == skeletonB.GetJointCount() && m_impl->joints.size() == skeletonA.GetJointCount(), "both skeletons must have the same number of joints");
const Joint* jointsA = &skeletonA.m_impl->joints[0];
const Joint* jointsB = &skeletonB.m_impl->joints[0];
for (std::size_t i = 0; i < indiceCount; ++i)
{
std::size_t index = indices[i];
#if NAZARA_UTILITY_SAFE
if (index >= m_impl->joints.size())
{
NazaraError("Index #" + NumberToString(i) + " out of range (" + NumberToString(index) + " >= " + NumberToString(m_impl->joints.size()) + ')');
return;
}
#endif
NazaraAssert(index < m_impl->joints.size(), "joint index out of range");
m_impl->joints[index].Interpolate(jointsA[index], jointsB[index], interpolation, CoordSys_Local);
}
@@ -347,7 +194,7 @@ namespace Nz
if (skeleton.m_impl)
{
m_impl = new SkeletonImpl;
m_impl = std::make_unique<SkeletonImpl>();
m_impl->jointMap = skeleton.m_impl->jointMap;
m_impl->jointMapUpdated = skeleton.m_impl->jointMapUpdated;
m_impl->joints = skeleton.m_impl->joints;
@@ -376,6 +223,8 @@ namespace Nz
return *this;
}
Skeleton& Skeleton::operator=(Skeleton&&) noexcept = default;
void Skeleton::InvalidateJoints()
{
m_impl->aabbUpdated = false;
@@ -385,26 +234,13 @@ namespace Nz
void Skeleton::InvalidateJointMap()
{
#ifdef NAZARA_DEBUG
if (!m_impl)
{
NazaraError("Invalid skeleton");
return;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
m_impl->jointMapUpdated = false;
}
void Skeleton::UpdateJointMap() const
{
#ifdef NAZARA_DEBUG
if (!m_impl)
{
NazaraError("Invalid skeleton");
return;
}
#endif
NazaraAssert(m_impl, "skeleton must have been created");
m_impl->jointMap.clear();
for (std::size_t i = 0; i < m_impl->joints.size(); ++i)
@@ -420,22 +256,4 @@ namespace Nz
m_impl->jointMapUpdated = true;
}
bool Skeleton::Initialize()
{
if (!SkeletonLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
return true;
}
void Skeleton::Uninitialize()
{
SkeletonLibrary::Uninitialize();
}
SkeletonLibrary::LibraryMap Skeleton::s_library;
}

View File

@@ -52,7 +52,7 @@ namespace Nz
DataStorage SoftwareBuffer::GetStorage() const
{
return DataStorage_Software;
return DataStorage::Software;
}
void* SoftwareBuffer::Map(BufferAccess /*access*/, UInt64 offset, UInt64 /*size*/)

View File

@@ -10,32 +10,20 @@
namespace Nz
{
StaticMesh::StaticMesh(VertexBuffer* vertexBuffer, const IndexBuffer* indexBuffer) :
StaticMesh::StaticMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer) :
m_aabb(Nz::Boxf::Zero()),
m_indexBuffer(indexBuffer),
m_vertexBuffer(vertexBuffer)
m_indexBuffer(std::move(indexBuffer)),
m_vertexBuffer(std::move(vertexBuffer))
{
NazaraAssert(m_vertexBuffer, "Invalid vertex buffer");
}
StaticMesh::StaticMesh(const Mesh* /*parent*/) :
m_aabb(Nz::Boxf::Zero())
{
}
StaticMesh::~StaticMesh()
{
OnStaticMeshRelease(this);
Destroy();
}
void StaticMesh::Center()
{
Vector3f offset(m_aabb.x + m_aabb.width/2.f, m_aabb.y + m_aabb.height/2.f, m_aabb.z + m_aabb.depth/2.f);
VertexMapper mapper(m_vertexBuffer);
SparsePtr<Vector3f> position = mapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
VertexMapper mapper(*m_vertexBuffer);
SparsePtr<Vector3f> position = mapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
unsigned int vertexCount = m_vertexBuffer->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i)
@@ -46,38 +34,11 @@ namespace Nz
m_aabb.z -= offset.z;
}
bool StaticMesh::Create(VertexBuffer* vertexBuffer)
{
Destroy();
#if NAZARA_UTILITY_SAFE
if (!vertexBuffer)
{
NazaraError("Invalid vertex buffer");
return false;
}
#endif
m_vertexBuffer = vertexBuffer;
return true;
}
void StaticMesh::Destroy()
{
if (m_vertexBuffer)
{
OnStaticMeshDestroy(this);
m_indexBuffer.Reset();
m_vertexBuffer.Reset();
}
}
bool StaticMesh::GenerateAABB()
{
// On lock le buffer pour itérer sur toutes les positions et composer notre AABB
VertexMapper mapper(m_vertexBuffer, BufferAccess_ReadOnly);
SetAABB(ComputeAABB(mapper.GetComponentPtr<const Vector3f>(VertexComponent_Position), m_vertexBuffer->GetVertexCount()));
VertexMapper mapper(*m_vertexBuffer, BufferAccess::ReadOnly);
SetAABB(ComputeAABB(mapper.GetComponentPtr<const Vector3f>(VertexComponent::Position), m_vertexBuffer->GetVertexCount()));
return true;
}
@@ -89,20 +50,15 @@ namespace Nz
AnimationType StaticMesh::GetAnimationType() const
{
return AnimationType_Static;
return AnimationType::Static;
}
const IndexBuffer* StaticMesh::GetIndexBuffer() const
const std::shared_ptr<const IndexBuffer>& StaticMesh::GetIndexBuffer() const
{
return m_indexBuffer;
}
VertexBuffer* StaticMesh::GetVertexBuffer()
{
return m_vertexBuffer;
}
const VertexBuffer* StaticMesh::GetVertexBuffer() const
const std::shared_ptr<VertexBuffer>& StaticMesh::GetVertexBuffer() const
{
return m_vertexBuffer;
}
@@ -129,8 +85,8 @@ namespace Nz
OnSubMeshInvalidateAABB(this);
}
void StaticMesh::SetIndexBuffer(const IndexBuffer* indexBuffer)
void StaticMesh::SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer)
{
m_indexBuffer = indexBuffer;
m_indexBuffer = std::move(indexBuffer);
}
}

View File

@@ -12,36 +12,27 @@
namespace Nz
{
SubMesh::SubMesh() :
RefCounted(false), // wut
m_primitiveMode(PrimitiveMode_TriangleList),
m_primitiveMode(PrimitiveMode::TriangleList),
m_matIndex(0)
{
}
SubMesh::SubMesh(const Mesh* /*parent*/) :
SubMesh()
{
}
SubMesh::~SubMesh()
{
OnSubMeshRelease(this);
}
SubMesh::~SubMesh() = default;
void SubMesh::GenerateNormals()
{
VertexMapper mapper(this);
VertexMapper mapper(*this);
std::size_t vertexCount = mapper.GetVertexCount();
SparsePtr<Vector3f> normals = mapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
SparsePtr<Vector3f> positions = mapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
SparsePtr<Vector3f> normals = mapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
SparsePtr<Vector3f> positions = mapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
if (!normals || !positions)
return;
for (std::size_t i = 0; i < vertexCount; ++i)
normals[i].MakeZero();
TriangleIterator iterator(this);
TriangleIterator iterator(*this);
do
{
Vector3f pos0 = positions[iterator[0]];
@@ -63,13 +54,13 @@ namespace Nz
void SubMesh::GenerateNormalsAndTangents()
{
VertexMapper mapper(this);
VertexMapper mapper(*this);
std::size_t vertexCount = mapper.GetVertexCount();
SparsePtr<Vector3f> normals = mapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
SparsePtr<Vector3f> positions = mapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
SparsePtr<Vector3f> tangents = mapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
SparsePtr<Vector2f> texCoords = mapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
SparsePtr<Vector3f> normals = mapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
SparsePtr<Vector3f> positions = mapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
SparsePtr<Vector3f> tangents = mapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
SparsePtr<Vector2f> texCoords = mapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
if (!normals || !positions || !tangents || !texCoords)
return;
@@ -79,7 +70,7 @@ namespace Nz
tangents[i].MakeZero();
}
TriangleIterator iterator(this);
TriangleIterator iterator(*this);
do
{
Vector3f pos0 = positions[iterator[0]];
@@ -121,16 +112,16 @@ namespace Nz
void SubMesh::GenerateTangents()
{
VertexMapper mapper(this);
VertexMapper mapper(*this);
SparsePtr<Vector3f> normals = mapper.GetComponentPtr<Vector3f>(VertexComponent_Normal);
SparsePtr<Vector3f> positions = mapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
SparsePtr<Vector3f> tangents = mapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent);
SparsePtr<Vector2f> texCoords = mapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
SparsePtr<Vector3f> normals = mapper.GetComponentPtr<Vector3f>(VertexComponent::Normal);
SparsePtr<Vector3f> positions = mapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
SparsePtr<Vector3f> tangents = mapper.GetComponentPtr<Vector3f>(VertexComponent::Tangent);
SparsePtr<Vector2f> texCoords = mapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord);
if (!normals || !positions || !tangents || !texCoords)
return;
TriangleIterator iterator(this);
TriangleIterator iterator(*this);
do
{
Vector3f pos0 = positions[iterator[0]];
@@ -170,7 +161,7 @@ namespace Nz
std::size_t SubMesh::GetTriangleCount() const
{
const IndexBuffer* indexBuffer = GetIndexBuffer();
const std::shared_ptr<const IndexBuffer>& indexBuffer = GetIndexBuffer();
std::size_t indexCount;
if (indexBuffer)
indexCount = indexBuffer->GetIndexCount();
@@ -179,22 +170,22 @@ namespace Nz
switch (m_primitiveMode)
{
case PrimitiveMode_LineList:
case PrimitiveMode_LineStrip:
case PrimitiveMode_PointList:
case PrimitiveMode::LineList:
case PrimitiveMode::LineStrip:
case PrimitiveMode::PointList:
return 0;
case PrimitiveMode_TriangleFan:
case PrimitiveMode::TriangleFan:
return (indexCount - 1) / 2;
case PrimitiveMode_TriangleList:
case PrimitiveMode::TriangleList:
return indexCount / 3;
case PrimitiveMode_TriangleStrip:
case PrimitiveMode::TriangleStrip:
return indexCount - 2;
}
NazaraError("Primitive mode not handled (0x" + NumberToString(m_primitiveMode, 16) + ')');
NazaraError("Primitive mode not handled (0x" + NumberToString(UnderlyingCast(m_primitiveMode), 16) + ')');
return 0;
}

View File

@@ -8,9 +8,9 @@
namespace Nz
{
TriangleIterator::TriangleIterator(PrimitiveMode primitiveMode, const IndexBuffer* indexBuffer) :
TriangleIterator::TriangleIterator(PrimitiveMode primitiveMode, const IndexBuffer& indexBuffer) :
m_primitiveMode(primitiveMode),
m_indexMapper(indexBuffer, BufferAccess_ReadOnly)
m_indexMapper(indexBuffer, BufferAccess::ReadOnly)
{
m_currentIndex = 3;
m_triangleIndices[0] = m_indexMapper.Get(0);
@@ -20,9 +20,9 @@ namespace Nz
m_indexCount = m_indexMapper.GetIndexCount();
}
TriangleIterator::TriangleIterator(const SubMesh* subMesh) :
m_primitiveMode(subMesh->GetPrimitiveMode()),
m_indexMapper(subMesh, BufferAccess_ReadOnly)
TriangleIterator::TriangleIterator(const SubMesh& subMesh) :
m_primitiveMode(subMesh.GetPrimitiveMode()),
m_indexMapper(subMesh, BufferAccess::ReadOnly)
{
m_currentIndex = 3;
m_triangleIndices[0] = m_indexMapper.Get(0);
@@ -42,18 +42,18 @@ namespace Nz
switch (m_primitiveMode)
{
case PrimitiveMode_TriangleFan:
case PrimitiveMode::TriangleFan:
m_triangleIndices[1] = m_indexMapper.Get(m_currentIndex++);
m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++);
break;
case PrimitiveMode_TriangleList:
case PrimitiveMode::TriangleList:
m_triangleIndices[0] = m_indexMapper.Get(m_currentIndex++);
m_triangleIndices[1] = m_indexMapper.Get(m_currentIndex++);
m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++);
break;
case PrimitiveMode_TriangleStrip:
case PrimitiveMode::TriangleStrip:
m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++);
m_triangleIndices[0] = m_triangleIndices[1];
m_triangleIndices[1] = m_triangleIndices[2];

View File

@@ -10,13 +10,13 @@
namespace Nz
{
UniformBuffer::UniformBuffer(BufferRef buffer)
UniformBuffer::UniformBuffer(std::shared_ptr<Buffer> buffer)
{
ErrorFlags(ErrorFlag_ThrowException, true);
Reset(std::move(buffer));
}
UniformBuffer::UniformBuffer(BufferRef buffer, UInt32 offset, UInt32 size)
UniformBuffer::UniformBuffer(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size)
{
ErrorFlags(ErrorFlag_ThrowException, true);
Reset(std::move(buffer), offset, size);
@@ -28,19 +28,6 @@ namespace Nz
Reset(length, storage, usage);
}
UniformBuffer::UniformBuffer(const UniformBuffer& uniformBuffer) :
RefCounted(),
m_buffer(uniformBuffer.m_buffer),
m_endOffset(uniformBuffer.m_endOffset),
m_startOffset(uniformBuffer.m_startOffset)
{
}
UniformBuffer::~UniformBuffer()
{
OnUniformBufferRelease(this);
}
bool UniformBuffer::Fill(const void* data, UInt32 offset, UInt32 size)
{
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
@@ -67,20 +54,20 @@ namespace Nz
void UniformBuffer::Reset()
{
m_buffer.Reset();
m_buffer.reset();
}
void UniformBuffer::Reset(BufferRef buffer)
void UniformBuffer::Reset(std::shared_ptr<Buffer> buffer)
{
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
Reset(buffer, 0, buffer->GetSize());
}
void UniformBuffer::Reset(BufferRef buffer, UInt32 offset, UInt32 size)
void UniformBuffer::Reset(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size)
{
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
NazaraAssert(buffer->GetType() == BufferType_Uniform, "Buffer must be an uniform buffer");
NazaraAssert(buffer->GetType() == BufferType::Uniform, "Buffer must be an uniform buffer");
NazaraAssert(size > 0, "Invalid size");
NazaraAssert(offset + size > buffer->GetSize(), "Virtual buffer exceed buffer bounds");
@@ -94,7 +81,7 @@ namespace Nz
m_endOffset = size;
m_startOffset = 0;
m_buffer = Buffer::New(BufferType_Uniform, m_endOffset, storage, usage);
m_buffer = std::make_shared<Buffer>(BufferType::Uniform, m_endOffset, storage, usage);
}
void UniformBuffer::Reset(const UniformBuffer& uniformBuffer)
@@ -108,11 +95,4 @@ namespace Nz
{
m_buffer->Unmap();
}
UniformBuffer& UniformBuffer::operator=(const UniformBuffer& uniformBuffer)
{
Reset(uniformBuffer);
return *this;
}
}

View File

@@ -39,27 +39,15 @@ namespace Nz
Utility::Utility(Config /*config*/) :
ModuleBase("Utility", this)
{
if (!Animation::Initialize())
throw std::runtime_error("failed to initialize animations");
if (!Buffer::Initialize())
throw std::runtime_error("failed to initialize buffers");
if (!Font::Initialize())
throw std::runtime_error("failed to initialize fonts");
if (!Image::Initialize())
throw std::runtime_error("failed to initialize images");
if (!Mesh::Initialize())
throw std::runtime_error("failed to initialize meshes");
if (!PixelFormatInfo::Initialize())
throw std::runtime_error("failed to initialize pixel formats");
if (!Skeleton::Initialize())
throw std::runtime_error("failed to initialize skeletons");
if (!VertexDeclaration::Initialize())
throw std::runtime_error("failed to initialize vertex declarations");
@@ -68,50 +56,99 @@ namespace Nz
/// Loaders génériques
// Font
Loaders::RegisterFreeType();
if (Loaders::InitializeFreeType())
m_fontLoader.RegisterLoader(Loaders::GetFontLoader_FreeType());
// Image
Loaders::RegisterDDSLoader(); // DDS Loader (DirectX format)
Loaders::RegisterSTBLoader(); // Generic loader (STB)
Loaders::RegisterSTBSaver(); // Generic saver (STB)
m_imageLoader.RegisterLoader(Loaders::GetImageLoader_STB()); // Generic loader (STB)
m_imageSaver.RegisterSaver(Loaders::GetImageSaver_STB()); // Generic saver (STB)
/// Loaders spécialisés
// Animation
Loaders::RegisterMD5Anim(); // Loader de fichiers .md5anim (v10)
m_animationLoader.RegisterLoader(Loaders::GetAnimationLoader_MD5Anim()); // Loader de fichiers .md5anim (v10)
// Mesh (text)
Loaders::RegisterOBJLoader();
Loaders::RegisterOBJSaver();
m_meshLoader.RegisterLoader(Loaders::GetMeshLoader_OBJ());
m_meshSaver.RegisterSaver(Loaders::GetMeshSaver_OBJ());
// Mesh
Loaders::RegisterMD2(); // Loader de fichiers .md2 (v8)
Loaders::RegisterMD5Mesh(); // Loader de fichiers .md5mesh (v10)
Loaders::RegisterOBJLoader(); // Loader de fichiers .md5mesh (v10)
m_meshLoader.RegisterLoader(Loaders::GetMeshLoader_MD2()); // .md2 (v8)
m_meshLoader.RegisterLoader(Loaders::GetMeshLoader_MD5Mesh()); // .md5mesh (v10)
m_meshLoader.RegisterLoader(Loaders::GetMeshLoader_OBJ()); // .obj
// Image
Loaders::RegisterPCX(); // Loader de fichiers .pcx (1, 4, 8, 24 bits)
m_imageLoader.RegisterLoader(Loaders::GetImageLoader_DDS()); // DDS Loader (DirectX format)
m_imageLoader.RegisterLoader(Loaders::GetImageLoader_PCX()); // .pcx loader (1, 4, 8, 24 bits)
}
Utility::~Utility()
{
Loaders::UnregisterFreeType();
Loaders::UnregisterMD2();
Loaders::UnregisterMD5Anim();
Loaders::UnregisterMD5Mesh();
Loaders::UnregisterOBJLoader();
Loaders::UnregisterOBJSaver();
Loaders::UnregisterPCX();
Loaders::UnregisterSTBLoader();
Loaders::UnregisterSTBSaver();
Loaders::UninitializeFreeType();
VertexDeclaration::Uninitialize();
Skeleton::Uninitialize();
PixelFormatInfo::Uninitialize();
Mesh::Uninitialize();
Image::Uninitialize();
Font::Uninitialize();
Buffer::Uninitialize();
Animation::Uninitialize();
}
AnimationLoader& Utility::GetAnimationLoader()
{
return m_animationLoader;
}
const AnimationLoader& Utility::GetAnimationLoader() const
{
return m_animationLoader;
}
FontLoader& Utility::GetFontLoader()
{
return m_fontLoader;
}
const FontLoader& Utility::GetFontLoader() const
{
return m_fontLoader;
}
ImageLoader& Utility::GetImageLoader()
{
return m_imageLoader;
}
const ImageLoader& Utility::GetImageLoader() const
{
return m_imageLoader;
}
ImageSaver& Utility::GetImageSaver()
{
return m_imageSaver;
}
const ImageSaver& Utility::GetImageSaver() const
{
return m_imageSaver;
}
MeshLoader& Utility::GetMeshLoader()
{
return m_meshLoader;
}
const MeshLoader& Utility::GetMeshLoader() const
{
return m_meshLoader;
}
MeshSaver& Utility::GetMeshSaver()
{
return m_meshSaver;
}
const MeshSaver& Utility::GetMeshSaver() const
{
return m_meshSaver;
}
Utility* Utility::s_instance = nullptr;

View File

@@ -9,39 +9,24 @@
namespace Nz
{
VertexBuffer::VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer)
VertexBuffer::VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer)
{
ErrorFlags(ErrorFlag_ThrowException, true);
Reset(std::move(vertexDeclaration), std::move(buffer));
}
VertexBuffer::VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, std::size_t offset, std::size_t size)
VertexBuffer::VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size)
{
ErrorFlags(ErrorFlag_ThrowException, true);
Reset(std::move(vertexDeclaration), std::move(buffer), offset, size);
}
VertexBuffer::VertexBuffer(VertexDeclarationConstRef vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage)
VertexBuffer::VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage)
{
ErrorFlags(ErrorFlag_ThrowException, true);
Reset(std::move(vertexDeclaration), length, storage, usage);
}
VertexBuffer::VertexBuffer(const VertexBuffer& vertexBuffer) :
RefCounted(),
m_buffer(vertexBuffer.m_buffer),
m_endOffset(vertexBuffer.m_endOffset),
m_startOffset(vertexBuffer.m_startOffset),
m_vertexCount(vertexBuffer.m_vertexCount),
m_vertexDeclaration(vertexBuffer.m_vertexDeclaration)
{
}
VertexBuffer::~VertexBuffer()
{
OnVertexBufferRelease(this);
}
bool VertexBuffer::Fill(const void* data, std::size_t startVertex, std::size_t length)
{
std::size_t stride = static_cast<std::size_t>(m_vertexDeclaration->GetStride());
@@ -91,20 +76,20 @@ namespace Nz
void VertexBuffer::Reset()
{
m_buffer.Reset();
m_vertexDeclaration.Reset();
m_buffer.reset();
m_vertexDeclaration.reset();
}
void VertexBuffer::Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer)
void VertexBuffer::Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer)
{
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
NazaraAssert(buffer->GetType() == BufferType_Vertex, "Buffer must be a vertex buffer");
NazaraAssert(buffer->GetType() == BufferType::Vertex, "Buffer must be a vertex buffer");
std::size_t size = buffer->GetSize();
Reset(std::move(vertexDeclaration), std::move(buffer), 0, size);
}
void VertexBuffer::Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, std::size_t offset, std::size_t size)
void VertexBuffer::Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size)
{
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
NazaraAssert(size > 0, "Invalid size");
@@ -117,14 +102,14 @@ namespace Nz
m_vertexDeclaration = vertexDeclaration;
}
void VertexBuffer::Reset(VertexDeclarationConstRef vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage)
void VertexBuffer::Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage)
{
m_endOffset = length * ((vertexDeclaration) ? static_cast<std::size_t>(vertexDeclaration->GetStride()) : 1);
m_startOffset = 0;
m_vertexCount = length;
m_vertexDeclaration = std::move(vertexDeclaration);
m_buffer = Buffer::New(BufferType_Vertex, m_endOffset, storage, usage);
m_buffer = std::make_shared<Buffer>(BufferType::Vertex, m_endOffset, storage, usage);
}
void VertexBuffer::Reset(const VertexBuffer& vertexBuffer)
@@ -136,7 +121,7 @@ namespace Nz
m_vertexDeclaration = vertexBuffer.m_vertexDeclaration;
}
void VertexBuffer::SetVertexDeclaration(VertexDeclarationConstRef vertexDeclaration)
void VertexBuffer::SetVertexDeclaration(std::shared_ptr<const VertexDeclaration> vertexDeclaration)
{
NazaraAssert(vertexDeclaration, "Invalid vertex declaration");
@@ -148,11 +133,4 @@ namespace Nz
{
m_buffer->Unmap();
}
VertexBuffer& VertexBuffer::operator=(const VertexBuffer& vertexBuffer)
{
Reset(vertexBuffer);
return *this;
}
}

View File

@@ -16,22 +16,22 @@ namespace Nz
{
namespace
{
std::size_t s_componentStride[ComponentType_Max + 1] =
std::size_t s_componentStride[ComponentTypeCount] =
{
4 * sizeof(UInt8), // ComponentType_Color
1 * sizeof(double), // ComponentType_Double1
2 * sizeof(double), // ComponentType_Double2
3 * sizeof(double), // ComponentType_Double3
4 * sizeof(double), // ComponentType_Double4
1 * sizeof(float), // ComponentType_Float1
2 * sizeof(float), // ComponentType_Float2
3 * sizeof(float), // ComponentType_Float3
4 * sizeof(float), // ComponentType_Float4
1 * sizeof(UInt32), // ComponentType_Int1
2 * sizeof(UInt32), // ComponentType_Int2
3 * sizeof(UInt32), // ComponentType_Int3
4 * sizeof(UInt32), // ComponentType_Int4
4 * sizeof(float) // ComponentType_Quaternion
4 * sizeof(UInt8), // ComponentType::Color
1 * sizeof(double), // ComponentType::Double1
2 * sizeof(double), // ComponentType::Double2
3 * sizeof(double), // ComponentType::Double3
4 * sizeof(double), // ComponentType::Double4
1 * sizeof(float), // ComponentType::Float1
2 * sizeof(float), // ComponentType::Float2
3 * sizeof(float), // ComponentType::Float3
4 * sizeof(float), // ComponentType::Float4
1 * sizeof(UInt32), // ComponentType::Int1
2 * sizeof(UInt32), // ComponentType::Int2
3 * sizeof(UInt32), // ComponentType::Int3
4 * sizeof(UInt32), // ComponentType::Int4
4 * sizeof(float) // ComponentType::Quaternion
};
}
VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) :
@@ -43,10 +43,10 @@ namespace Nz
m_components.reserve(components.size());
for (const ComponentEntry& entry : components)
{
NazaraAssert(IsTypeSupported(entry.type), "Component type 0x" + NumberToString(entry.type, 16) + " is not supported by vertex declarations");
NazaraAssert(entry.componentIndex == 0 || entry.component == VertexComponent_Userdata, "Only userdata components can have non-zero component indexes");
NazaraAssert(IsTypeSupported(entry.type), "Component type 0x" + NumberToString(UnderlyingCast(entry.type), 16) + " is not supported by vertex declarations");
NazaraAssert(entry.componentIndex == 0 || entry.component == VertexComponent::Userdata, "Only userdata components can have non-zero component indexes");
if (entry.component != VertexComponent_Unused)
if (entry.component != VertexComponent::Unused)
{
// Check for duplicates
for (const Component& component : m_components)
@@ -62,7 +62,7 @@ namespace Nz
component.offset = offset;
component.type = entry.type;
offset += s_componentStride[component.type];
offset += s_componentStride[UnderlyingCast(component.type)];
}
m_stride = offset;
@@ -72,281 +72,275 @@ namespace Nz
{
switch (type)
{
case ComponentType_Color:
case ComponentType_Double1:
case ComponentType_Double2:
case ComponentType_Double3:
case ComponentType_Double4:
case ComponentType_Float1:
case ComponentType_Float2:
case ComponentType_Float3:
case ComponentType_Float4:
case ComponentType_Int1:
case ComponentType_Int2:
case ComponentType_Int3:
case ComponentType_Int4:
case ComponentType::Color:
case ComponentType::Double1:
case ComponentType::Double2:
case ComponentType::Double3:
case ComponentType::Double4:
case ComponentType::Float1:
case ComponentType::Float2:
case ComponentType::Float3:
case ComponentType::Float4:
case ComponentType::Int1:
case ComponentType::Int2:
case ComponentType::Int3:
case ComponentType::Int4:
return true;
case ComponentType_Quaternion:
case ComponentType::Quaternion:
return false;
}
NazaraError("Component type not handled (0x" + NumberToString(type, 16) + ')');
NazaraError("Component type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')');
return false;
}
bool VertexDeclaration::Initialize()
{
if (!VertexDeclarationLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
try
{
ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowException);
auto NewDeclaration = [](VertexInputRate inputRate, std::initializer_list<ComponentEntry> components)
{
return New(inputRate, std::move(components));
return std::make_shared<VertexDeclaration>(inputRate, std::move(components));
};
// VertexLayout_XY : VertexStruct_XY
s_declarations[VertexLayout_XY] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XY : VertexStruct_XY
s_declarations[UnderlyingCast(VertexLayout::XY)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float2,
VertexComponent::Position,
ComponentType::Float2,
0
}
});
NazaraAssert(s_declarations[VertexLayout_XY]->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout_XY");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY)]->GetStride() == sizeof(VertexStruct_XY), "Invalid stride for declaration VertexLayout::XY");
s_declarations[VertexLayout_XY_Color] = NewDeclaration(VertexInputRate::Vertex, {
s_declarations[UnderlyingCast(VertexLayout::XY_Color)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float2,
VertexComponent::Position,
ComponentType::Float2,
0
},
{
VertexComponent_Color,
ComponentType_Color,
VertexComponent::Color,
ComponentType::Color,
0
},
});
NazaraAssert(s_declarations[VertexLayout_XY_Color]->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout_XY_Color");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY_Color)]->GetStride() == sizeof(VertexStruct_XY_Color), "Invalid stride for declaration VertexLayout::XY_Color");
// VertexLayout_XY_UV : VertexStruct_XY_UV
s_declarations[VertexLayout_XY_UV] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XY_UV : VertexStruct_XY_UV
s_declarations[UnderlyingCast(VertexLayout::XY_UV)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float2,
VertexComponent::Position,
ComponentType::Float2,
0
},
{
VertexComponent_TexCoord,
ComponentType_Float2,
VertexComponent::TexCoord,
ComponentType::Float2,
0
},
});
NazaraAssert(s_declarations[VertexLayout_XY_UV]->GetStride() == sizeof(VertexStruct_XY_UV), "Invalid stride for declaration VertexLayout_XY_UV");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XY_UV)]->GetStride() == sizeof(VertexStruct_XY_UV), "Invalid stride for declaration VertexLayout::XY_UV");
// VertexLayout_XYZ : VertexStruct_XYZ
s_declarations[VertexLayout_XYZ] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ : VertexStruct_XYZ
s_declarations[UnderlyingCast(VertexLayout::XYZ)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
});
NazaraAssert(s_declarations[VertexLayout_XYZ]->GetStride() == sizeof(VertexStruct_XYZ), "Invalid stride for declaration VertexLayout_XYZ");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ)]->GetStride() == sizeof(VertexStruct_XYZ), "Invalid stride for declaration VertexLayout::XYZ");
// VertexLayout_XYZ_Color : VertexStruct_XYZ_Color
s_declarations[VertexLayout_XYZ_Color] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ_Color : VertexStruct_XYZ_Color
s_declarations[UnderlyingCast(VertexLayout::XYZ_Color)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
{
VertexComponent_Color,
ComponentType_Color,
VertexComponent::Color,
ComponentType::Color,
0
}
});
NazaraAssert(s_declarations[VertexLayout_XYZ_Color]->GetStride() == sizeof(VertexStruct_XYZ_Color), "Invalid stride for declaration VertexLayout_XYZ_Color");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Color)]->GetStride() == sizeof(VertexStruct_XYZ_Color), "Invalid stride for declaration VertexLayout::XYZ_Color");
// VertexLayout_XYZ_Color_UV : VertexStruct_XYZ_Color_UV
s_declarations[VertexLayout_XYZ_Color_UV] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ_Color_UV : VertexStruct_XYZ_Color_UV
s_declarations[UnderlyingCast(VertexLayout::XYZ_Color_UV)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
{
VertexComponent_Color,
ComponentType_Color,
VertexComponent::Color,
ComponentType::Color,
0
},
{
VertexComponent_TexCoord,
ComponentType_Float2,
VertexComponent::TexCoord,
ComponentType::Float2,
0
},
});
NazaraAssert(s_declarations[VertexLayout_XYZ_Color_UV]->GetStride() == sizeof(VertexStruct_XYZ_Color_UV), "Invalid stride for declaration VertexLayout_XYZ_Color_UV");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Color_UV)]->GetStride() == sizeof(VertexStruct_XYZ_Color_UV), "Invalid stride for declaration VertexLayout::XYZ_Color_UV");
// VertexLayout_XYZ_Normal : VertexStruct_XYZ_Normal
s_declarations[VertexLayout_XYZ_Normal] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ_Normal : VertexStruct_XYZ_Normal
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
{
VertexComponent_Normal,
ComponentType_Float3,
VertexComponent::Normal,
ComponentType::Float3,
0
}
});
NazaraAssert(s_declarations[VertexLayout_XYZ_Normal]->GetStride() == sizeof(VertexStruct_XYZ_Normal), "Invalid stride for declaration VertexLayout_XYZ_Normal");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal)]->GetStride() == sizeof(VertexStruct_XYZ_Normal), "Invalid stride for declaration VertexLayout::XYZ_Normal");
// VertexLayout_XYZ_Normal_UV : VertexStruct_XYZ_Normal_UV
s_declarations[VertexLayout_XYZ_Normal_UV] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ_Normal_UV : VertexStruct_XYZ_Normal_UV
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
{
VertexComponent_Normal,
ComponentType_Float3,
VertexComponent::Normal,
ComponentType::Float3,
0
},
{
VertexComponent_TexCoord,
ComponentType_Float2,
VertexComponent::TexCoord,
ComponentType::Float2,
0
}
});
NazaraAssert(s_declarations[VertexLayout_XYZ_Normal_UV]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV), "Invalid stride for declaration VertexLayout_XYZ_Normal_UV");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV");
// VertexLayout_XYZ_Normal_UV_Tangent : VertexStruct_XYZ_Normal_UV_Tangent
s_declarations[VertexLayout_XYZ_Normal_UV_Tangent] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ_Normal_UV_Tangent : VertexStruct_XYZ_Normal_UV_Tangent
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
{
VertexComponent_Normal,
ComponentType_Float3,
VertexComponent::Normal,
ComponentType::Float3,
0
},
{
VertexComponent_TexCoord,
ComponentType_Float2,
VertexComponent::TexCoord,
ComponentType::Float2,
0
},
{
VertexComponent_Tangent,
ComponentType_Float3,
VertexComponent::Tangent,
ComponentType::Float3,
0
}
});
NazaraAssert(s_declarations[VertexLayout_XYZ_Normal_UV_Tangent]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration VertexLayout_XYZ_Normal_UV_Tangent");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent");
// VertexLayout_XYZ_Normal_UV_Tangent_Skinning : VertexStruct_XYZ_Normal_UV_Tangent_Skinning
s_declarations[VertexLayout_XYZ_Normal_UV_Tangent_Skinning] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ_Normal_UV_Tangent_Skinning : VertexStruct_XYZ_Normal_UV_Tangent_Skinning
s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent_Skinning)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
{
VertexComponent_Normal,
ComponentType_Float3,
VertexComponent::Normal,
ComponentType::Float3,
0
},
{
VertexComponent_TexCoord,
ComponentType_Float2,
VertexComponent::TexCoord,
ComponentType::Float2,
0
},
{
VertexComponent_Tangent,
ComponentType_Float3,
VertexComponent::Tangent,
ComponentType::Float3,
0
},
{
VertexComponent_Userdata,
ComponentType_Int1,
VertexComponent::Userdata,
ComponentType::Int1,
0 // Weight count
},
{
VertexComponent_Userdata,
ComponentType_Float4,
VertexComponent::Userdata,
ComponentType::Float4,
1 // Weights
},
{
VertexComponent_Userdata,
ComponentType_Int4,
VertexComponent::Userdata,
ComponentType::Int4,
2 // Joint indexes
},
});
NazaraAssert(s_declarations[VertexLayout_XYZ_Normal_UV_Tangent_Skinning]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration VertexLayout_XYZ_Normal_UV_Tangent_Skinning");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_Normal_UV_Tangent_Skinning)]->GetStride() == sizeof(VertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration VertexLayout::XYZ_Normal_UV_Tangent_Skinning");
// VertexLayout_XYZ_UV : VertexStruct_XYZ_UV
s_declarations[VertexLayout_XYZ_UV] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::XYZ_UV : VertexStruct_XYZ_UV
s_declarations[UnderlyingCast(VertexLayout::XYZ_UV)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Position,
ComponentType_Float3,
VertexComponent::Position,
ComponentType::Float3,
0
},
{
VertexComponent_TexCoord,
ComponentType_Float2,
VertexComponent::TexCoord,
ComponentType::Float2,
0
}
});
NazaraAssert(s_declarations[VertexLayout_XYZ_UV]->GetStride() == sizeof(VertexStruct_XYZ_UV), "Invalid stride for declaration VertexLayout_XYZ_UV");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::XYZ_UV)]->GetStride() == sizeof(VertexStruct_XYZ_UV), "Invalid stride for declaration VertexLayout::XYZ_UV");
// VertexLayout_Matrix4 : Matrix4f
s_declarations[VertexLayout_Matrix4] = NewDeclaration(VertexInputRate::Vertex, {
// VertexLayout::Matrix4 : Matrix4f
s_declarations[UnderlyingCast(VertexLayout::Matrix4)] = NewDeclaration(VertexInputRate::Vertex, {
{
VertexComponent_Userdata,
ComponentType_Float4,
VertexComponent::Userdata,
ComponentType::Float4,
0
},
{
VertexComponent_Userdata,
ComponentType_Float4,
VertexComponent::Userdata,
ComponentType::Float4,
1
},
{
VertexComponent_Userdata,
ComponentType_Float4,
VertexComponent::Userdata,
ComponentType::Float4,
2
},
{
VertexComponent_Userdata,
ComponentType_Float4,
VertexComponent::Userdata,
ComponentType::Float4,
3
}
});
NazaraAssert(s_declarations[VertexLayout_Matrix4]->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout_Matrix4");
NazaraAssert(s_declarations[UnderlyingCast(VertexLayout::Matrix4)]->GetStride() == sizeof(Matrix4f), "Invalid stride for declaration VertexLayout::Matrix4");
}
catch (const std::exception& e)
{
@@ -359,11 +353,8 @@ namespace Nz
void VertexDeclaration::Uninitialize()
{
VertexDeclarationLibrary::Uninitialize();
s_declarations.fill(nullptr);
}
std::array<VertexDeclarationRef, VertexLayout_Max + 1> VertexDeclaration::s_declarations;
VertexDeclarationLibrary::LibraryMap VertexDeclaration::s_library;
std::array<std::shared_ptr<VertexDeclaration>, VertexLayoutCount> VertexDeclaration::s_declarations;
}

View File

@@ -12,73 +12,73 @@
namespace Nz
{
VertexMapper::VertexMapper(SubMesh* subMesh, BufferAccess access)
VertexMapper::VertexMapper(SubMesh& subMesh, BufferAccess access)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
VertexBuffer* buffer = nullptr;
switch (subMesh->GetAnimationType())
std::shared_ptr<VertexBuffer> buffer = nullptr;
switch (subMesh.GetAnimationType())
{
case AnimationType_Skeletal:
case AnimationType::Skeletal:
{
SkeletalMesh* skeletalMesh = static_cast<SkeletalMesh*>(subMesh);
buffer = skeletalMesh->GetVertexBuffer();
SkeletalMesh& skeletalMesh = static_cast<SkeletalMesh&>(subMesh);
buffer = skeletalMesh.GetVertexBuffer();
break;
}
case AnimationType_Static:
case AnimationType::Static:
{
StaticMesh* staticMesh = static_cast<StaticMesh*>(subMesh);
buffer = staticMesh->GetVertexBuffer();
StaticMesh& staticMesh = static_cast<StaticMesh&>(subMesh);
buffer = staticMesh.GetVertexBuffer();
break;
}
}
if (!buffer)
{
NazaraInternalError("Animation type not handled (0x" + NumberToString(subMesh->GetAnimationType(), 16) + ')');
NazaraInternalError("Animation type not handled (0x" + NumberToString(UnderlyingCast(subMesh.GetAnimationType()), 16) + ')');
}
m_mapper.Map(buffer, access);
m_mapper.Map(*buffer, access);
}
VertexMapper::VertexMapper(VertexBuffer* vertexBuffer, BufferAccess access)
VertexMapper::VertexMapper(VertexBuffer& vertexBuffer, BufferAccess access)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
m_mapper.Map(vertexBuffer, access);
}
VertexMapper::VertexMapper(const SubMesh* subMesh, BufferAccess access)
VertexMapper::VertexMapper(const SubMesh& subMesh, BufferAccess access)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
const VertexBuffer* buffer = nullptr;
switch (subMesh->GetAnimationType())
std::shared_ptr<VertexBuffer> buffer = nullptr;
switch (subMesh.GetAnimationType())
{
case AnimationType_Skeletal:
case AnimationType::Skeletal:
{
const SkeletalMesh* skeletalMesh = static_cast<const SkeletalMesh*>(subMesh);
buffer = skeletalMesh->GetVertexBuffer();
const SkeletalMesh& skeletalMesh = static_cast<const SkeletalMesh&>(subMesh);
buffer = skeletalMesh.GetVertexBuffer();
break;
}
case AnimationType_Static:
case AnimationType::Static:
{
const StaticMesh* staticMesh = static_cast<const StaticMesh*>(subMesh);
buffer = staticMesh->GetVertexBuffer();
const StaticMesh& staticMesh = static_cast<const StaticMesh&>(subMesh);
buffer = staticMesh.GetVertexBuffer();
break;
}
}
if (!buffer)
{
NazaraInternalError("Animation type not handled (0x" + NumberToString(subMesh->GetAnimationType(), 16) + ')');
NazaraInternalError("Animation type not handled (0x" + NumberToString(UnderlyingCast(subMesh.GetAnimationType()), 16) + ')');
}
m_mapper.Map(buffer, access);
m_mapper.Map(*buffer, access);
}
VertexMapper::VertexMapper(const VertexBuffer* vertexBuffer, BufferAccess access)
VertexMapper::VertexMapper(const VertexBuffer& vertexBuffer, BufferAccess access)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
m_mapper.Map(vertexBuffer, access);