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
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
18 changed files with 116 additions and 119 deletions

View File

@ -27,9 +27,9 @@
#define gcc_align(x) #define gcc_align(x)
#else #else
#ifdef _MSVC_LANG #ifdef _MSVC_LANG
#define type_align(x) __declspec(align(x)) #define type_align(x) /* __declspec(align(x)) */
#define tdef_align(x) __declspec(align(x)) #define tdef_align(x) /* __declspec(align(x)) */
#define memb_align(x) __declspec(align(x)) #define memb_align(x) /* __declspec(align(x)) */
#define gcc_align(x) #define gcc_align(x)
#else #else
#define type_align(x) __attribute__((__aligned__(x))) #define type_align(x) __attribute__((__aligned__(x)))

View File

@ -21,7 +21,7 @@ bool CsvHeaderRow::RequireIndexForHeader(const std::string& headerName, unsigned
if (existingHeader == m_header_row.end()) if (existingHeader == m_header_row.end())
return false; return false;
out = std::distance(m_header_row.begin(), existingHeader); out = static_cast<unsigned>(std::distance(m_header_row.begin(), existingHeader));
return true; return true;
} }

View File

@ -13,7 +13,7 @@ public:
bool Read(const CsvInputStream& inputStream); bool Read(const CsvInputStream& inputStream);
const std::string& HeaderNameForColumn(unsigned columnIndex) const; [[nodiscard]] const std::string& HeaderNameForColumn(unsigned columnIndex) const;
bool RequireIndexForHeader(const std::string& headerName, unsigned& out) const; bool RequireIndexForHeader(const std::string& headerName, unsigned& out) const;
[[nodiscard]] std::optional<unsigned> GetIndexForHeader(const std::string& headerName) const; [[nodiscard]] std::optional<unsigned> GetIndexForHeader(const std::string& headerName) const;

View File

@ -42,14 +42,14 @@ uint32_t CommonStructuredDataEnum::CalculateChecksum(const uint32_t initialValue
{ {
auto checksum = initialValue; auto checksum = initialValue;
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), static_cast<unsigned>(m_name.size() + 1u));
const auto littleEndianElementCount = endianness::ToLittleEndian(ElementCount()); const auto littleEndianElementCount = endianness::ToLittleEndian(ElementCount());
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianElementCount), sizeof(littleEndianElementCount)); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianElementCount), sizeof(littleEndianElementCount));
for (const auto& entry : m_entries) for (const auto& entry : m_entries)
{ {
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(entry.m_name.c_str()), entry.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(entry.m_name.c_str()), static_cast<unsigned>(entry.m_name.size() + 1));
const auto littleEndianValue = endianness::ToLittleEndian(entry.m_value); const auto littleEndianValue = endianness::ToLittleEndian(entry.m_value);
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianValue), sizeof(littleEndianValue)); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianValue), sizeof(littleEndianValue));

View File

@ -41,10 +41,10 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
{ {
auto checksum = initialValue; auto checksum = initialValue;
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(m_name.c_str()), static_cast<unsigned>(m_name.size() + 1u));
for (const auto& property : m_properties) for (const auto& property : m_properties)
{ {
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(property.m_name.c_str()), property.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(property.m_name.c_str()), static_cast<unsigned>(property.m_name.size() + 1u));
const auto littleEndianOffset = endianness::ToLittleEndian(property.m_offset_in_bits); const auto littleEndianOffset = endianness::ToLittleEndian(property.m_offset_in_bits);
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianOffset), sizeof(littleEndianOffset)); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(&littleEndianOffset), sizeof(littleEndianOffset));
@ -68,7 +68,7 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
if (currentType.m_info.type_index < def.m_enums.size()) if (currentType.m_info.type_index < def.m_enums.size())
{ {
const auto& _enum = *def.m_enums[currentType.m_info.type_index]; const auto& _enum = *def.m_enums[currentType.m_info.type_index];
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), _enum.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), static_cast<unsigned>(_enum.m_name.size() + 1u));
currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN); currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN);
} }
break; break;
@ -76,7 +76,7 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
if (currentType.m_info.type_index < def.m_structs.size()) if (currentType.m_info.type_index < def.m_structs.size())
{ {
const auto& _struct = *def.m_structs[currentType.m_info.type_index]; const auto& _struct = *def.m_structs[currentType.m_info.type_index];
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_struct.m_name.c_str()), _struct.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_struct.m_name.c_str()), static_cast<unsigned>(_struct.m_name.size() + 1u));
currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN); currentType = CommonStructuredDataType(CommonStructuredDataTypeCategory::UNKNOWN);
} }
break; break;
@ -99,7 +99,7 @@ uint32_t CommonStructuredDataStruct::CalculateChecksum(const CommonStructuredDat
if (enumedArray.m_enum_index < def.m_enums.size()) if (enumedArray.m_enum_index < def.m_enums.size())
{ {
const auto& _enum = *def.m_enums[enumedArray.m_enum_index]; const auto& _enum = *def.m_enums[enumedArray.m_enum_index];
checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), _enum.m_name.size() + 1); checksum = crc32(checksum, reinterpret_cast<const Bytef*>(_enum.m_name.c_str()), static_cast<unsigned>(_enum.m_name.size() + 1u));
} }
currentType = enumedArray.m_array_type; currentType = enumedArray.m_array_type;
} }

View File

@ -6,7 +6,6 @@
#include <cassert> #include <cassert>
#include <format> #include <format>
#include <iostream>
using namespace T6; using namespace T6;
@ -42,7 +41,7 @@ namespace
auto* gameKvps = m_memory.Alloc<KeyValuePairs>(); auto* gameKvps = m_memory.Alloc<KeyValuePairs>();
gameKvps->name = m_memory.Dup(m_zone.m_name.c_str()); gameKvps->name = m_memory.Dup(m_zone.m_name.c_str());
gameKvps->numVariables = commonKvps.size(); gameKvps->numVariables = static_cast<unsigned>(commonKvps.size());
gameKvps->keyValuePairs = m_memory.Alloc<KeyValuePair>(commonKvps.size()); gameKvps->keyValuePairs = m_memory.Alloc<KeyValuePair>(commonKvps.size());
const auto namespaceHash = Common::Com_HashKey(m_zone.m_name.c_str(), 64); const auto namespaceHash = Common::Com_HashKey(m_zone.m_name.c_str(), 64);

View File

@ -1,7 +1,6 @@
#include "IPakCreator.h" #include "IPakCreator.h"
#include "Game/T6/CommonT6.h" #include "Game/T6/CommonT6.h"
#include "Game/T6/GameT6.h"
#include "GitVersion.h" #include "GitVersion.h"
#include "ObjContainer/IPak/IPakTypes.h" #include "ObjContainer/IPak/IPakTypes.h"
#include "Utils/Alignment.h" #include "Utils/Alignment.h"
@ -23,7 +22,7 @@ namespace
static constexpr char BRANDING[] = "Created with OpenAssetTools " GIT_VERSION; static constexpr char BRANDING[] = "Created with OpenAssetTools " GIT_VERSION;
static constexpr auto SECTION_COUNT = 3; // Index + Data + Branding static constexpr auto SECTION_COUNT = 3; // Index + Data + Branding
inline static const std::string PAD_DATA = std::string(256, '\xA7'); inline static const auto PAD_DATA = std::string(256, '\xA7');
public: public:
IPakWriter(std::ostream& stream, ISearchPath& searchPath, const std::vector<std::string>& images) IPakWriter(std::ostream& stream, ISearchPath& searchPath, const std::vector<std::string>& images)
@ -70,8 +69,8 @@ namespace
void Write(const void* data, const size_t dataSize) void Write(const void* data, const size_t dataSize)
{ {
m_stream.write(static_cast<const char*>(data), dataSize); m_stream.write(static_cast<const char*>(data), static_cast<std::streamsize>(dataSize));
m_current_offset += dataSize; m_current_offset += static_cast<int64_t>(dataSize);
} }
void Pad(const size_t paddingSize) void Pad(const size_t paddingSize)
@ -100,27 +99,30 @@ namespace
{ {
GoTo(0); GoTo(0);
const IPakHeader header{ipak_consts::IPAK_MAGIC, ipak_consts::IPAK_VERSION, static_cast<uint32_t>(m_total_size), SECTION_COUNT}; const IPakHeader header{.magic = ipak_consts::IPAK_MAGIC,
.version = ipak_consts::IPAK_VERSION,
.size = static_cast<uint32_t>(m_total_size),
.sectionCount = SECTION_COUNT};
const IPakSection dataSection{ const IPakSection dataSection{
ipak_consts::IPAK_DATA_SECTION, .type = ipak_consts::IPAK_DATA_SECTION,
static_cast<uint32_t>(m_data_section_offset), .offset = static_cast<uint32_t>(m_data_section_offset),
static_cast<uint32_t>(m_data_section_size), .size = static_cast<uint32_t>(m_data_section_size),
static_cast<uint32_t>(m_index_entries.size()), .itemCount = static_cast<uint32_t>(m_index_entries.size()),
}; };
const IPakSection indexSection{ const IPakSection indexSection{
ipak_consts::IPAK_INDEX_SECTION, .type = ipak_consts::IPAK_INDEX_SECTION,
static_cast<uint32_t>(m_index_section_offset), .offset = static_cast<uint32_t>(m_index_section_offset),
static_cast<uint32_t>(sizeof(IPakIndexEntry) * m_index_entries.size()), .size = static_cast<uint32_t>(sizeof(IPakIndexEntry) * m_index_entries.size()),
static_cast<uint32_t>(m_index_entries.size()), .itemCount = static_cast<uint32_t>(m_index_entries.size()),
}; };
const IPakSection brandingSection{ const IPakSection brandingSection{
ipak_consts::IPAK_BRANDING_SECTION, .type = ipak_consts::IPAK_BRANDING_SECTION,
static_cast<uint32_t>(m_branding_section_offset), .offset = static_cast<uint32_t>(m_branding_section_offset),
std::extent_v<decltype(BRANDING)>, .size = std::extent_v<decltype(BRANDING)>,
1, .itemCount = 1,
}; };
Write(&header, sizeof(header)); Write(&header, sizeof(header));
@ -147,7 +149,7 @@ namespace
imageSize = static_cast<size_t>(openFile.m_length); imageSize = static_cast<size_t>(openFile.m_length);
auto imageData = std::make_unique<char[]>(imageSize); auto imageData = std::make_unique<char[]>(imageSize);
openFile.m_stream->read(imageData.get(), imageSize); openFile.m_stream->read(imageData.get(), static_cast<std::streamsize>(imageSize));
return imageData; return imageData;
} }
@ -177,7 +179,7 @@ namespace
IPakDataBlockHeader skipBlockHeader{}; IPakDataBlockHeader skipBlockHeader{};
skipBlockHeader.countAndOffset.count = 1; skipBlockHeader.countAndOffset.count = 1;
skipBlockHeader.commands[0].compressed = ipak_consts::IPAK_COMMAND_SKIP; skipBlockHeader.commands[0].compressed = ipak_consts::IPAK_COMMAND_SKIP;
skipBlockHeader.commands[0].size = sizeToSkip - sizeof(IPakDataBlockHeader); skipBlockHeader.commands[0].size = static_cast<uint32_t>(sizeToSkip - sizeof(IPakDataBlockHeader));
Write(&skipBlockHeader, sizeof(skipBlockHeader)); Write(&skipBlockHeader, sizeof(skipBlockHeader));
} }
@ -199,12 +201,12 @@ namespace
m_current_block.countAndOffset.offset = static_cast<uint32_t>(m_file_offset); m_current_block.countAndOffset.offset = static_cast<uint32_t>(m_file_offset);
// Reserve space to later write actual block header data // Reserve space to later write actual block header data
GoTo(m_current_offset + sizeof(IPakDataBlockHeader)); GoTo(static_cast<int64_t>(m_current_offset + sizeof(IPakDataBlockHeader)));
} }
void WriteChunkData(const void* data, const size_t dataSize) void WriteChunkData(const void* data, const size_t dataSize)
{ {
auto dataOffset = 0u; auto dataOffset = 0uz;
while (dataOffset < dataSize) while (dataOffset < dataSize)
{ {
if (m_current_block.countAndOffset.count >= std::extent_v<decltype(IPakDataBlockHeader::commands)>) if (m_current_block.countAndOffset.count >= std::extent_v<decltype(IPakDataBlockHeader::commands)>)
@ -225,7 +227,7 @@ namespace
continue; continue;
} }
const auto commandSize = std::min(std::min(remainingSize, ipak_consts::IPAK_COMMAND_DEFAULT_SIZE), remainingChunkBufferWindowSize); const auto commandSize = std::min({remainingSize, ipak_consts::IPAK_COMMAND_DEFAULT_SIZE, remainingChunkBufferWindowSize});
auto writeUncompressed = true; auto writeUncompressed = true;
if (USE_IPAK_COMPRESSION) if (USE_IPAK_COMPRESSION)
@ -254,7 +256,7 @@ namespace
Write(&static_cast<const char*>(data)[dataOffset], commandSize); Write(&static_cast<const char*>(data)[dataOffset], commandSize);
const auto currentCommand = m_current_block.countAndOffset.count; const auto currentCommand = m_current_block.countAndOffset.count;
m_current_block.commands[currentCommand].size = commandSize; m_current_block.commands[currentCommand].size = static_cast<uint32_t>(commandSize);
m_current_block.commands[currentCommand].compressed = ipak_consts::IPAK_COMMAND_UNCOMPRESSED; m_current_block.commands[currentCommand].compressed = ipak_consts::IPAK_COMMAND_UNCOMPRESSED;
m_current_block.countAndOffset.count = currentCommand + 1u; m_current_block.countAndOffset.count = currentCommand + 1u;
} }
@ -281,7 +283,7 @@ namespace
return; return;
const auto nameHash = T6::Common::R_HashString(imageName.c_str(), 0); const auto nameHash = T6::Common::R_HashString(imageName.c_str(), 0);
const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(imageData.get()), imageSize)); const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(imageData.get()), static_cast<unsigned>(imageSize)));
StartNewFile(); StartNewFile();
const auto startOffset = m_current_block_header_offset; const auto startOffset = m_current_block_header_offset;
@ -294,7 +296,7 @@ namespace
WriteChunkData(imageData.get(), imageSize); WriteChunkData(imageData.get(), imageSize);
const auto writtenImageSize = static_cast<size_t>(m_current_offset - startOffset); const auto writtenImageSize = static_cast<size_t>(m_current_offset - startOffset);
indexEntry.size = writtenImageSize; indexEntry.size = static_cast<uint32_t>(writtenImageSize);
m_index_entries.emplace_back(indexEntry); m_index_entries.emplace_back(indexEntry);
} }

View File

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

View File

@ -55,7 +55,7 @@ public:
{ {
const auto* buffer = m_texture->GetBufferForMipLevel(mipLevel); const auto* buffer = m_texture->GetBufferForMipLevel(mipLevel);
const auto mipLevelSize = m_texture->GetSizeOfMipLevel(mipLevel) * m_texture->GetFaceCount(); 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.dwHeight = m_texture->GetHeight();
header.dwWidth = m_texture->GetWidth(); header.dwWidth = m_texture->GetWidth();
header.dwDepth = m_texture->GetDepth(); 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; header.dwMipMapCount = m_texture->HasMipMaps() ? m_texture->GetMipMapCount() : 1;
PopulatePixelFormat(header.ddspf); PopulatePixelFormat(header.ddspf);

View File

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

View File

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

View File

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

View File

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

View File

@ -48,13 +48,13 @@ protected:
public: public:
virtual ~ImageFormat() = default; virtual ~ImageFormat() = default;
ImageFormatId GetId() const; [[nodiscard]] ImageFormatId GetId() const;
oat::D3DFORMAT GetD3DFormat() const; [[nodiscard]] oat::D3DFORMAT GetD3DFormat() const;
oat::DXGI_FORMAT GetDxgiFormat() const; [[nodiscard]] oat::DXGI_FORMAT GetDxgiFormat() const;
virtual ImageFormatType GetType() const = 0; [[nodiscard]] virtual ImageFormatType GetType() const = 0;
virtual size_t GetPitch(unsigned mipLevel, unsigned width) const = 0; [[nodiscard]] 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 size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const = 0;
static const ImageFormatUnsigned FORMAT_R8_G8_B8; static const ImageFormatUnsigned FORMAT_R8_G8_B8;
static const ImageFormatUnsigned FORMAT_B8_G8_R8_X8; static const ImageFormatUnsigned FORMAT_B8_G8_R8_X8;
@ -98,14 +98,14 @@ public:
unsigned aOffset, unsigned aOffset,
unsigned aSize); unsigned aSize);
ImageFormatType GetType() const override; [[nodiscard]] ImageFormatType GetType() const override;
size_t GetPitch(unsigned mipLevel, unsigned width) const override; [[nodiscard]] size_t GetPitch(unsigned mipLevel, unsigned width) const override;
size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override; [[nodiscard]] size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) const override;
bool HasR() const; [[nodiscard]] bool HasR() const;
bool HasG() const; [[nodiscard]] bool HasG() const;
bool HasB() const; [[nodiscard]] bool HasB() const;
bool HasA() const; [[nodiscard]] bool HasA() const;
}; };
class ImageFormatBlockCompressed final : public ImageFormat class ImageFormatBlockCompressed final : public ImageFormat
@ -116,7 +116,7 @@ public:
ImageFormatBlockCompressed(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat, unsigned blockSize, unsigned bitsPerBlock); ImageFormatBlockCompressed(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat, unsigned blockSize, unsigned bitsPerBlock);
ImageFormatType GetType() const override; [[nodiscard]] ImageFormatType GetType() const override;
size_t GetPitch(unsigned mipLevel, unsigned width) const override; [[nodiscard]] size_t GetPitch(unsigned mipLevel, unsigned width) const override;
size_t GetSizeOfMipLevel(unsigned mipLevel, unsigned width, unsigned height, unsigned depth) 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; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>)) 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)) 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; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(iwi27::IwiHeader::fileSizeForPicmip)>)) 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)) 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; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>)) 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)) 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; currentFileSize += mipLevelSize;
if (currentMipLevel < static_cast<int>(std::extent_v<decltype(IwiHeader::fileSizeForPicmip)>)) 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)) if (const auto* texture2D = dynamic_cast<const Texture2D*>(texture))