2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-06 19:21:52 +00:00

refactor: fix x64 compilation issues in Common,ObjCommon,ObjCompiling,ObjImage components

This commit is contained in:
Jan
2025-04-25 22:55:04 +01:00
committed by Jan Laupetin
parent 5635470b6e
commit ee4301952a
18 changed files with 116 additions and 119 deletions

View File

@ -14,16 +14,28 @@ namespace dds
{
static constexpr auto DDS_MAGIC = FileUtils::MakeMagic32('D', 'D', 'S', ' ');
std::istream& m_stream;
public:
explicit DdsLoaderInternal(std::istream& stream)
: m_stream(stream),
m_texture_type(TextureType::T_2D),
m_has_mip_maps(false),
m_width(0u),
m_height(0u),
m_depth(0u),
m_format(nullptr)
{
}
TextureType m_texture_type;
bool m_has_mip_maps;
size_t m_width;
size_t m_height;
size_t m_depth;
const ImageFormat* m_format;
std::unique_ptr<Texture> LoadDds()
{
if (!ReadMagic() || !ReadHeader())
return nullptr;
_NODISCARD bool ReadMagic() const
return ReadTextureData();
}
private:
[[nodiscard]] bool ReadMagic() const
{
uint32_t magic;
m_stream.read(reinterpret_cast<char*>(&magic), sizeof(magic));
@ -42,7 +54,7 @@ namespace dds
return true;
}
_NODISCARD bool ReadDxt10Header()
[[nodiscard]] bool ReadDxt10Header()
{
DDS_HEADER_DXT10 headerDx10{};
m_stream.read(reinterpret_cast<char*>(&headerDx10), sizeof(headerDx10));
@ -86,7 +98,7 @@ namespace dds
return false;
}
_NODISCARD bool ReadPixelFormatFourCc(DDS_PIXELFORMAT& pf)
[[nodiscard]] bool ReadPixelFormatFourCc(DDS_PIXELFORMAT& pf)
{
switch (pf.dwFourCC)
{
@ -132,7 +144,7 @@ namespace dds
}
}
_NODISCARD bool ReadPixelFormatUnsigned(DDS_PIXELFORMAT& pf)
[[nodiscard]] bool ReadPixelFormatUnsigned(DDS_PIXELFORMAT& pf)
{
unsigned rOffset, rSize, gOffset, gSize, bOffset, bSize, aOffset, aSize;
@ -163,7 +175,7 @@ namespace dds
return false;
}
_NODISCARD bool ReadPixelFormat(DDS_PIXELFORMAT& pf)
[[nodiscard]] bool ReadPixelFormat(DDS_PIXELFORMAT& pf)
{
if (pf.dwFlags & DDPF_FOURCC)
return ReadPixelFormatFourCc(pf);
@ -200,7 +212,7 @@ namespace dds
return ReadPixelFormat(header.ddspf);
}
_NODISCARD std::unique_ptr<Texture> ReadTextureData() const
[[nodiscard]] std::unique_ptr<Texture> ReadTextureData() const
{
std::unique_ptr<Texture> result;
@ -229,7 +241,7 @@ namespace dds
for (auto mipLevel = 0; mipLevel < mipMapCount; mipLevel++)
{
const auto mipSize = result->GetSizeOfMipLevel(mipLevel);
const auto mipSize = static_cast<std::streamsize>(result->GetSizeOfMipLevel(mipLevel));
for (auto face = 0; face < faceCount; face++)
{
@ -246,25 +258,14 @@ namespace dds
return result;
}
public:
explicit DdsLoaderInternal(std::istream& stream)
: m_stream(stream),
m_texture_type(TextureType::T_2D),
m_has_mip_maps(false),
m_width(0u),
m_height(0u),
m_depth(0u),
m_format(nullptr)
{
}
std::istream& m_stream;
std::unique_ptr<Texture> LoadDds()
{
if (!ReadMagic() || !ReadHeader())
return nullptr;
return ReadTextureData();
}
TextureType m_texture_type;
bool m_has_mip_maps;
unsigned m_width;
unsigned m_height;
unsigned m_depth;
const ImageFormat* m_format;
};
std::unique_ptr<Texture> LoadDds(std::istream& stream)

View File

@ -55,7 +55,7 @@ public:
{
const auto* buffer = m_texture->GetBufferForMipLevel(mipLevel);
const auto mipLevelSize = m_texture->GetSizeOfMipLevel(mipLevel) * m_texture->GetFaceCount();
m_stream.write(reinterpret_cast<const char*>(buffer), mipLevelSize);
m_stream.write(reinterpret_cast<const char*>(buffer), static_cast<std::streamsize>(mipLevelSize));
}
}
@ -153,7 +153,7 @@ public:
header.dwHeight = m_texture->GetHeight();
header.dwWidth = m_texture->GetWidth();
header.dwDepth = m_texture->GetDepth();
header.dwPitchOrLinearSize = m_texture->GetFormat()->GetPitch(0, m_texture->GetWidth());
header.dwPitchOrLinearSize = static_cast<uint32_t>(m_texture->GetFormat()->GetPitch(0, m_texture->GetWidth()));
header.dwMipMapCount = m_texture->HasMipMaps() ? m_texture->GetMipMapCount() : 1;
PopulatePixelFormat(header.ddspf);

View File

@ -14,7 +14,7 @@ Dx12TextureLoader::Dx12TextureLoader()
const ImageFormat* Dx12TextureLoader::GetFormatForDx12Format() const
{
for (auto i : ImageFormat::ALL_FORMATS)
for (const auto* i : ImageFormat::ALL_FORMATS)
{
if (i->GetDxgiFormat() == m_format)
return i;
@ -41,19 +41,19 @@ Dx12TextureLoader& Dx12TextureLoader::HasMipMaps(const bool hasMipMaps)
return *this;
}
Dx12TextureLoader& Dx12TextureLoader::Width(const size_t width)
Dx12TextureLoader& Dx12TextureLoader::Width(const unsigned width)
{
m_width = width;
return *this;
}
Dx12TextureLoader& Dx12TextureLoader::Height(const size_t height)
Dx12TextureLoader& Dx12TextureLoader::Height(const unsigned height)
{
m_height = height;
return *this;
}
Dx12TextureLoader& Dx12TextureLoader::Depth(const size_t depth)
Dx12TextureLoader& Dx12TextureLoader::Depth(const unsigned depth)
{
m_depth = depth;
return *this;

View File

@ -2,8 +2,6 @@
#include "Image/DxgiFormat.h"
#include "Image/Texture.h"
#include "Utils/ClassUtils.h"
#include "Utils/MemoryManager.h"
#include <memory>
#include <unordered_map>
@ -16,21 +14,21 @@ public:
Dx12TextureLoader& Format(oat::DXGI_FORMAT format);
Dx12TextureLoader& Type(TextureType textureType);
Dx12TextureLoader& HasMipMaps(bool hasMipMaps);
Dx12TextureLoader& Width(size_t width);
Dx12TextureLoader& Height(size_t height);
Dx12TextureLoader& Depth(size_t depth);
Dx12TextureLoader& Width(unsigned width);
Dx12TextureLoader& Height(unsigned height);
Dx12TextureLoader& Depth(unsigned depth);
std::unique_ptr<Texture> LoadTexture(const void* data);
private:
_NODISCARD const ImageFormat* GetFormatForDx12Format() const;
[[nodiscard]] const ImageFormat* GetFormatForDx12Format() const;
static std::unordered_map<ImageFormatId, ImageFormatId> m_conversion_table;
oat::DXGI_FORMAT m_format;
TextureType m_type;
bool m_has_mip_maps;
size_t m_width;
size_t m_height;
size_t m_depth;
unsigned m_width;
unsigned m_height;
unsigned m_depth;
};

View File

@ -41,19 +41,19 @@ Dx9TextureLoader& Dx9TextureLoader::HasMipMaps(const bool hasMipMaps)
return *this;
}
Dx9TextureLoader& Dx9TextureLoader::Width(const size_t width)
Dx9TextureLoader& Dx9TextureLoader::Width(const unsigned width)
{
m_width = width;
return *this;
}
Dx9TextureLoader& Dx9TextureLoader::Height(const size_t height)
Dx9TextureLoader& Dx9TextureLoader::Height(const unsigned height)
{
m_height = height;
return *this;
}
Dx9TextureLoader& Dx9TextureLoader::Depth(const size_t depth)
Dx9TextureLoader& Dx9TextureLoader::Depth(const unsigned depth)
{
m_depth = depth;
return *this;

View File

@ -2,11 +2,8 @@
#include "Image/D3DFormat.h"
#include "Image/Texture.h"
#include "Utils/ClassUtils.h"
#include "Utils/MemoryManager.h"
#include <memory>
#include <unordered_map>
class Dx9TextureLoader
{
@ -16,19 +13,19 @@ public:
Dx9TextureLoader& Format(oat::D3DFORMAT format);
Dx9TextureLoader& Type(TextureType textureType);
Dx9TextureLoader& HasMipMaps(bool hasMipMaps);
Dx9TextureLoader& Width(size_t width);
Dx9TextureLoader& Height(size_t height);
Dx9TextureLoader& Depth(size_t depth);
Dx9TextureLoader& Width(unsigned width);
Dx9TextureLoader& Height(unsigned height);
Dx9TextureLoader& Depth(unsigned depth);
std::unique_ptr<Texture> LoadTexture(const void* data);
private:
_NODISCARD const ImageFormat* GetFormatForDx9Format() const;
[[nodiscard]] const ImageFormat* GetFormatForDx9Format() const;
oat::D3DFORMAT m_format;
TextureType m_type;
bool m_has_mip_maps;
size_t m_width;
size_t m_height;
size_t m_depth;
unsigned m_width;
unsigned m_height;
unsigned m_depth;
};

View File

@ -48,13 +48,13 @@ protected:
public:
virtual ~ImageFormat() = default;
ImageFormatId GetId() const;
oat::D3DFORMAT GetD3DFormat() const;
oat::DXGI_FORMAT GetDxgiFormat() const;
[[nodiscard]] ImageFormatId GetId() const;
[[nodiscard]] oat::D3DFORMAT GetD3DFormat() const;
[[nodiscard]] oat::DXGI_FORMAT GetDxgiFormat() const;
virtual ImageFormatType GetType() const = 0;
virtual size_t GetPitch(unsigned mipLevel, unsigned width) const = 0;
virtual size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const = 0;
[[nodiscard]] virtual ImageFormatType GetType() const = 0;
[[nodiscard]] virtual size_t GetPitch(unsigned mipLevel, unsigned width) const = 0;
[[nodiscard]] virtual size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const = 0;
static const ImageFormatUnsigned FORMAT_R8_G8_B8;
static const ImageFormatUnsigned FORMAT_B8_G8_R8_X8;
@ -98,14 +98,14 @@ public:
unsigned aOffset,
unsigned aSize);
ImageFormatType GetType() const override;
size_t GetPitch(unsigned mipLevel, unsigned width) const override;
size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override;
[[nodiscard]] ImageFormatType GetType() const override;
[[nodiscard]] size_t GetPitch(unsigned mipLevel, unsigned width) const override;
[[nodiscard]] size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override;
bool HasR() const;
bool HasG() const;
bool HasB() const;
bool HasA() const;
[[nodiscard]] bool HasR() const;
[[nodiscard]] bool HasG() const;
[[nodiscard]] bool HasB() const;
[[nodiscard]] bool HasA() const;
};
class ImageFormatBlockCompressed final : public ImageFormat
@ -116,7 +116,7 @@ public:
ImageFormatBlockCompressed(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat, unsigned blockSize, unsigned bitsPerBlock);
ImageFormatType GetType() const override;
size_t GetPitch(unsigned mipLevel, unsigned width) const override;
size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override;
[[nodiscard]] ImageFormatType GetType() const override;
[[nodiscard]] size_t GetPitch(unsigned mipLevel, unsigned width) const override;
[[nodiscard]] size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override;
};

View File

@ -110,7 +110,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize;
header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
}
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))

View File

@ -113,7 +113,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(iwi27::IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize;
header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
}
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))

View File

@ -105,7 +105,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize;
header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
}
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))

View File

@ -105,7 +105,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>))
header.fileSizeForPicmip[currentMipLevel] = currentFileSize;
header.fileSizeForPicmip[currentMipLevel] = static_cast<uint32_t>(currentFileSize);
}
if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))