mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-07 17:31:49 +00:00
chore: update image namespacing
This commit is contained in:
@@ -38,11 +38,13 @@ function ImageConverter:project()
|
||||
|
||||
self:include(includes)
|
||||
Utils:include(includes)
|
||||
Common:include(includes)
|
||||
ObjImage:include(includes)
|
||||
|
||||
Raw:use()
|
||||
|
||||
links:linkto(Utils)
|
||||
links:linkto(Common)
|
||||
links:linkto(ObjImage)
|
||||
links:linkall()
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "ImageConverter.h"
|
||||
|
||||
#include "Game/IGame.h"
|
||||
#include "Image/DdsLoader.h"
|
||||
#include "Image/DdsWriter.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
@@ -17,10 +18,12 @@
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using namespace image;
|
||||
|
||||
namespace image_converter
|
||||
namespace
|
||||
{
|
||||
constexpr auto EXTENSION_IWI = ".iwi";
|
||||
constexpr auto EXTENSION_DDS = ".dds";
|
||||
@@ -29,7 +32,7 @@ namespace image_converter
|
||||
{
|
||||
public:
|
||||
ImageConverterImpl()
|
||||
: m_game_to_convert_to(image_converter::Game::UNKNOWN)
|
||||
: m_game_to_convert_to(std::nullopt)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -76,7 +79,7 @@ namespace image_converter
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto texture = iwi::LoadIwi(file);
|
||||
const auto texture = image::LoadIwi(file);
|
||||
if (!texture)
|
||||
return false;
|
||||
|
||||
@@ -103,7 +106,7 @@ namespace image_converter
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto texture = dds::LoadDds(file);
|
||||
const auto texture = image::LoadDds(file);
|
||||
if (!texture)
|
||||
return false;
|
||||
|
||||
@@ -129,23 +132,23 @@ namespace image_converter
|
||||
if (m_iwi_writer)
|
||||
return true;
|
||||
|
||||
if (m_game_to_convert_to == Game::UNKNOWN && !ShowGameTui())
|
||||
if (!m_game_to_convert_to && !ShowGameTui())
|
||||
return false;
|
||||
|
||||
switch (m_game_to_convert_to)
|
||||
switch (*m_game_to_convert_to)
|
||||
{
|
||||
case Game::IW3:
|
||||
m_iwi_writer = std::make_unique<iwi6::IwiWriter>();
|
||||
case GameId::IW3:
|
||||
m_iwi_writer = std::make_unique<image::iwi6::IwiWriter>();
|
||||
break;
|
||||
case Game::IW4:
|
||||
case Game::IW5:
|
||||
m_iwi_writer = std::make_unique<iwi8::IwiWriter>();
|
||||
case GameId::IW4:
|
||||
case GameId::IW5:
|
||||
m_iwi_writer = std::make_unique<image::iwi8::IwiWriter>();
|
||||
break;
|
||||
case Game::T5:
|
||||
m_iwi_writer = std::make_unique<iwi13::IwiWriter>();
|
||||
case GameId::T5:
|
||||
m_iwi_writer = std::make_unique<image::iwi13::IwiWriter>();
|
||||
break;
|
||||
case Game::T6:
|
||||
m_iwi_writer = std::make_unique<iwi27::IwiWriter>();
|
||||
case GameId::T6:
|
||||
m_iwi_writer = std::make_unique<image::iwi27::IwiWriter>();
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
@@ -170,19 +173,19 @@ namespace image_converter
|
||||
switch (num)
|
||||
{
|
||||
case 1:
|
||||
m_game_to_convert_to = Game::IW3;
|
||||
m_game_to_convert_to = GameId::IW3;
|
||||
break;
|
||||
case 2:
|
||||
m_game_to_convert_to = Game::IW4;
|
||||
m_game_to_convert_to = GameId::IW4;
|
||||
break;
|
||||
case 3:
|
||||
m_game_to_convert_to = Game::IW5;
|
||||
m_game_to_convert_to = GameId::IW5;
|
||||
break;
|
||||
case 4:
|
||||
m_game_to_convert_to = Game::T5;
|
||||
m_game_to_convert_to = GameId::T5;
|
||||
break;
|
||||
case 5:
|
||||
m_game_to_convert_to = Game::T6;
|
||||
m_game_to_convert_to = GameId::T6;
|
||||
break;
|
||||
default:
|
||||
con::error("Invalid input");
|
||||
@@ -193,13 +196,13 @@ namespace image_converter
|
||||
}
|
||||
|
||||
ImageConverterArgs m_args;
|
||||
image_converter::Game m_game_to_convert_to;
|
||||
std::optional<GameId> m_game_to_convert_to;
|
||||
DdsWriter m_dds_writer;
|
||||
std::unique_ptr<IImageWriter> m_iwi_writer;
|
||||
std::unique_ptr<ImageWriter> m_iwi_writer;
|
||||
};
|
||||
} // namespace image_converter
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<ImageConverter> ImageConverter::Create()
|
||||
{
|
||||
return std::make_unique<image_converter::ImageConverterImpl>();
|
||||
return std::make_unique<ImageConverterImpl>();
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
|
||||
};
|
||||
|
||||
ImageConverterArgs::ImageConverterArgs()
|
||||
: m_game_to_convert_to(image_converter::Game::UNKNOWN),
|
||||
: m_game_to_convert_to(std::nullopt),
|
||||
m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Game/IGame.h"
|
||||
#include "Utils/Arguments/ArgumentParser.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace image_converter
|
||||
{
|
||||
enum class Game : std::uint8_t
|
||||
{
|
||||
UNKNOWN,
|
||||
IW3,
|
||||
IW4,
|
||||
IW5,
|
||||
T5,
|
||||
T6
|
||||
};
|
||||
} // namespace image_converter
|
||||
|
||||
class ImageConverterArgs
|
||||
{
|
||||
public:
|
||||
@@ -26,7 +15,7 @@ public:
|
||||
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
|
||||
|
||||
std::vector<std::string> m_files_to_convert;
|
||||
image_converter::Game m_game_to_convert_to;
|
||||
std::optional<GameId> m_game_to_convert_to;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
namespace dds
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
class DdsLoaderInternal
|
||||
{
|
||||
@@ -193,7 +195,7 @@ namespace dds
|
||||
return ReadPixelFormatUnsigned(pf);
|
||||
}
|
||||
|
||||
_NODISCARD bool ReadHeader()
|
||||
[[nodiscard]] bool ReadHeader()
|
||||
{
|
||||
DDS_HEADER header{};
|
||||
m_stream.read(reinterpret_cast<char*>(&header), sizeof(header));
|
||||
@@ -277,10 +279,13 @@ namespace dds
|
||||
unsigned m_depth;
|
||||
const ImageFormat* m_format;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace image
|
||||
{
|
||||
std::unique_ptr<Texture> LoadDds(std::istream& stream)
|
||||
{
|
||||
DdsLoaderInternal internal(stream);
|
||||
return internal.LoadDds();
|
||||
}
|
||||
} // namespace dds
|
||||
} // namespace image
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <istream>
|
||||
#include <memory>
|
||||
|
||||
namespace dds
|
||||
namespace image
|
||||
{
|
||||
std::unique_ptr<Texture> LoadDds(std::istream& stream);
|
||||
}
|
||||
|
||||
@@ -2,23 +2,25 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
constexpr uint32_t MakeFourCc(const char ch0, const char ch1, const char ch2, const char ch3)
|
||||
namespace image
|
||||
{
|
||||
constexpr uint32_t MakeFourCc(const char ch0, const char ch1, const char ch2, const char ch3)
|
||||
{
|
||||
return static_cast<uint32_t>(ch0) | static_cast<uint32_t>(ch1) << 8 | static_cast<uint32_t>(ch2) << 16 | static_cast<uint32_t>(ch3) << 24;
|
||||
}
|
||||
}
|
||||
|
||||
enum DDP_FLAGS
|
||||
{
|
||||
enum DDP_FLAGS
|
||||
{
|
||||
DDPF_ALPHAPIXELS = 0x1,
|
||||
DDPF_ALPHA = 0x2,
|
||||
DDPF_FOURCC = 0x4,
|
||||
DDPF_RGB = 0x40,
|
||||
DDPF_YUV = 0x200,
|
||||
DDPF_LUMINANCE = 0x20000
|
||||
};
|
||||
};
|
||||
|
||||
enum DDS_HEADER_FLAGS
|
||||
{
|
||||
enum DDS_HEADER_FLAGS
|
||||
{
|
||||
DDSD_CAPS = 0x1,
|
||||
DDSD_HEIGHT = 0x2,
|
||||
DDSD_WIDTH = 0x4,
|
||||
@@ -27,17 +29,17 @@ enum DDS_HEADER_FLAGS
|
||||
DDSD_MIPMAPCOUNT = 0x20000,
|
||||
DDSD_LINEARSIZE = 0x80000,
|
||||
DDSD_DEPTH = 0x800000,
|
||||
};
|
||||
};
|
||||
|
||||
enum DDS_HEADER_CAPS
|
||||
{
|
||||
enum DDS_HEADER_CAPS
|
||||
{
|
||||
DDSCAPS_COMPLEX = 0x8,
|
||||
DDSCAPS_TEXTURE = 0x1000,
|
||||
DDSCAPS_MIPMAP = 0x400000,
|
||||
};
|
||||
};
|
||||
|
||||
enum DDS_HEADER_CAPS2
|
||||
{
|
||||
enum DDS_HEADER_CAPS2
|
||||
{
|
||||
DDSCAPS2_CUBEMAP = 0x200,
|
||||
DDSCAPS2_CUBEMAP_POSITIVEX = 0x400,
|
||||
DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800,
|
||||
@@ -46,10 +48,10 @@ enum DDS_HEADER_CAPS2
|
||||
DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000,
|
||||
DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000,
|
||||
DDSCAPS2_VOLUME = 0x200000,
|
||||
};
|
||||
};
|
||||
|
||||
struct DDS_PIXELFORMAT
|
||||
{
|
||||
struct DDS_PIXELFORMAT
|
||||
{
|
||||
uint32_t dwSize;
|
||||
uint32_t dwFlags;
|
||||
uint32_t dwFourCC;
|
||||
@@ -58,10 +60,10 @@ struct DDS_PIXELFORMAT
|
||||
uint32_t dwGBitMask;
|
||||
uint32_t dwBBitMask;
|
||||
uint32_t dwABitMask;
|
||||
};
|
||||
};
|
||||
|
||||
struct DDS_HEADER
|
||||
{
|
||||
struct DDS_HEADER
|
||||
{
|
||||
uint32_t dwSize;
|
||||
uint32_t dwFlags;
|
||||
uint32_t dwHeight;
|
||||
@@ -76,36 +78,38 @@ struct DDS_HEADER
|
||||
uint32_t dwCaps3;
|
||||
uint32_t dwCaps4;
|
||||
uint32_t dwReserved2;
|
||||
};
|
||||
};
|
||||
|
||||
enum D3D10_RESOURCE_DIMENSION
|
||||
{
|
||||
enum D3D10_RESOURCE_DIMENSION
|
||||
{
|
||||
D3D10_RESOURCE_DIMENSION_UNKNOWN,
|
||||
D3D10_RESOURCE_DIMENSION_BUFFER,
|
||||
D3D10_RESOURCE_DIMENSION_TEXTURE1D,
|
||||
D3D10_RESOURCE_DIMENSION_TEXTURE2D,
|
||||
D3D10_RESOURCE_DIMENSION_TEXTURE3D
|
||||
};
|
||||
};
|
||||
|
||||
enum DDS_HEADER_DXT10_MISC
|
||||
{
|
||||
enum DDS_HEADER_DXT10_MISC
|
||||
{
|
||||
DDS_RESOURCE_MISC_TEXTURECUBE = 0x4
|
||||
};
|
||||
};
|
||||
|
||||
enum DDS_HEADER_DXT10_MISC2
|
||||
{
|
||||
enum DDS_HEADER_DXT10_MISC2
|
||||
{
|
||||
DDS_ALPHA_MODE_UNKNOWN = 0x0,
|
||||
DDS_ALPHA_MODE_STRAIGHT = 0x1,
|
||||
DDS_ALPHA_MODE_PREMULTIPLIED = 0x2,
|
||||
DDS_ALPHA_MODE_OPAQUE = 0x3,
|
||||
DDS_ALPHA_MODE_CUSTOM = 0x4,
|
||||
};
|
||||
};
|
||||
|
||||
struct DDS_HEADER_DXT10
|
||||
{
|
||||
struct DDS_HEADER_DXT10
|
||||
{
|
||||
oat::DXGI_FORMAT dxgiFormat;
|
||||
D3D10_RESOURCE_DIMENSION resourceDimension;
|
||||
uint32_t miscFlag;
|
||||
uint32_t arraySize;
|
||||
uint32_t miscFlags2;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace image
|
||||
|
||||
@@ -7,13 +7,17 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
const std::map<ImageFormatId, ImageFormatId> DDS_CONVERSION_TABLE{
|
||||
{ImageFormatId::R8_G8_B8, ImageFormatId::B8_G8_R8_X8},
|
||||
};
|
||||
using namespace image;
|
||||
|
||||
class DdsWriterInternal
|
||||
namespace
|
||||
{
|
||||
public:
|
||||
const std::map<ImageFormatId, ImageFormatId> DDS_CONVERSION_TABLE{
|
||||
{ImageFormatId::R8_G8_B8, ImageFormatId::B8_G8_R8_X8},
|
||||
};
|
||||
|
||||
class DdsWriterInternal
|
||||
{
|
||||
public:
|
||||
static bool SupportsImageFormat(const ImageFormat* imageFormat)
|
||||
{
|
||||
return true;
|
||||
@@ -219,22 +223,26 @@ public:
|
||||
const Texture* m_texture;
|
||||
std::unique_ptr<Texture> m_converted_texture;
|
||||
bool m_use_dx10_extension;
|
||||
};
|
||||
};
|
||||
} // namespace
|
||||
|
||||
DdsWriter::~DdsWriter() = default;
|
||||
|
||||
bool DdsWriter::SupportsImageFormat(const ImageFormat* imageFormat)
|
||||
namespace image
|
||||
{
|
||||
DdsWriter::~DdsWriter() = default;
|
||||
|
||||
bool DdsWriter::SupportsImageFormat(const ImageFormat* imageFormat)
|
||||
{
|
||||
return DdsWriterInternal::SupportsImageFormat(imageFormat);
|
||||
}
|
||||
}
|
||||
|
||||
std::string DdsWriter::GetFileExtension()
|
||||
{
|
||||
std::string DdsWriter::GetFileExtension()
|
||||
{
|
||||
return DdsWriterInternal::GetFileExtension();
|
||||
}
|
||||
}
|
||||
|
||||
void DdsWriter::DumpImage(std::ostream& stream, const Texture* texture)
|
||||
{
|
||||
void DdsWriter::DumpImage(std::ostream& stream, const Texture* texture)
|
||||
{
|
||||
DdsWriterInternal internal(stream, texture);
|
||||
internal.DumpImage();
|
||||
}
|
||||
}
|
||||
} // namespace image
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
#pragma once
|
||||
#include "IImageWriter.h"
|
||||
|
||||
class DdsWriter final : public IImageWriter
|
||||
#include "ImageWriter.h"
|
||||
|
||||
namespace image
|
||||
{
|
||||
public:
|
||||
class DdsWriter final : public ImageWriter
|
||||
{
|
||||
public:
|
||||
~DdsWriter() override;
|
||||
|
||||
bool SupportsImageFormat(const ImageFormat* imageFormat) override;
|
||||
std::string GetFileExtension() override;
|
||||
void DumpImage(std::ostream& stream, const Texture* texture) override;
|
||||
};
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
Dx12TextureLoader::Dx12TextureLoader()
|
||||
namespace image
|
||||
{
|
||||
Dx12TextureLoader::Dx12TextureLoader()
|
||||
: m_format(oat::DXGI_FORMAT_UNKNOWN),
|
||||
m_type(TextureType::T_2D),
|
||||
m_has_mip_maps(false),
|
||||
m_width(1u),
|
||||
m_height(1u),
|
||||
m_depth(1u)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
const ImageFormat* Dx12TextureLoader::GetFormatForDx12Format() const
|
||||
{
|
||||
const ImageFormat* Dx12TextureLoader::GetFormatForDx12Format() const
|
||||
{
|
||||
for (const auto* i : ImageFormat::ALL_FORMATS)
|
||||
{
|
||||
if (i->GetDxgiFormat() == m_format)
|
||||
@@ -21,46 +23,46 @@ const ImageFormat* Dx12TextureLoader::GetFormatForDx12Format() const
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Format(const oat::DXGI_FORMAT format)
|
||||
{
|
||||
Dx12TextureLoader& Dx12TextureLoader::Format(const oat::DXGI_FORMAT format)
|
||||
{
|
||||
m_format = format;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Type(const TextureType textureType)
|
||||
{
|
||||
Dx12TextureLoader& Dx12TextureLoader::Type(const TextureType textureType)
|
||||
{
|
||||
m_type = textureType;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::HasMipMaps(const bool hasMipMaps)
|
||||
{
|
||||
Dx12TextureLoader& Dx12TextureLoader::HasMipMaps(const bool hasMipMaps)
|
||||
{
|
||||
m_has_mip_maps = hasMipMaps;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Width(const unsigned width)
|
||||
{
|
||||
Dx12TextureLoader& Dx12TextureLoader::Width(const unsigned width)
|
||||
{
|
||||
m_width = width;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Height(const unsigned height)
|
||||
{
|
||||
Dx12TextureLoader& Dx12TextureLoader::Height(const unsigned height)
|
||||
{
|
||||
m_height = height;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Depth(const unsigned depth)
|
||||
{
|
||||
Dx12TextureLoader& Dx12TextureLoader::Depth(const unsigned depth)
|
||||
{
|
||||
m_depth = depth;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> Dx12TextureLoader::LoadTexture(const void* data)
|
||||
{
|
||||
std::unique_ptr<Texture> Dx12TextureLoader::LoadTexture(const void* data)
|
||||
{
|
||||
const auto* format = GetFormatForDx12Format();
|
||||
|
||||
if (format == nullptr)
|
||||
@@ -101,4 +103,5 @@ std::unique_ptr<Texture> Dx12TextureLoader::LoadTexture(const void* data)
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
} // namespace image
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
class Dx12TextureLoader
|
||||
namespace image
|
||||
{
|
||||
public:
|
||||
class Dx12TextureLoader
|
||||
{
|
||||
public:
|
||||
Dx12TextureLoader();
|
||||
|
||||
Dx12TextureLoader& Format(oat::DXGI_FORMAT format);
|
||||
@@ -20,7 +22,7 @@ public:
|
||||
|
||||
std::unique_ptr<Texture> LoadTexture(const void* data);
|
||||
|
||||
private:
|
||||
private:
|
||||
[[nodiscard]] const ImageFormat* GetFormatForDx12Format() const;
|
||||
|
||||
static std::unordered_map<ImageFormatId, ImageFormatId> m_conversion_table;
|
||||
@@ -31,4 +33,5 @@ private:
|
||||
unsigned m_width;
|
||||
unsigned m_height;
|
||||
unsigned m_depth;
|
||||
};
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
Dx9TextureLoader::Dx9TextureLoader()
|
||||
namespace image
|
||||
{
|
||||
Dx9TextureLoader::Dx9TextureLoader()
|
||||
: m_format(oat::D3DFMT_UNKNOWN),
|
||||
m_type(TextureType::T_2D),
|
||||
m_has_mip_maps(false),
|
||||
m_width(1u),
|
||||
m_height(1u),
|
||||
m_depth(1u)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
const ImageFormat* Dx9TextureLoader::GetFormatForDx9Format() const
|
||||
{
|
||||
const ImageFormat* Dx9TextureLoader::GetFormatForDx9Format() const
|
||||
{
|
||||
for (const auto* i : ImageFormat::ALL_FORMATS)
|
||||
{
|
||||
if (i->GetD3DFormat() == m_format)
|
||||
@@ -21,46 +23,46 @@ const ImageFormat* Dx9TextureLoader::GetFormatForDx9Format() const
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Format(const oat::D3DFORMAT format)
|
||||
{
|
||||
Dx9TextureLoader& Dx9TextureLoader::Format(const oat::D3DFORMAT format)
|
||||
{
|
||||
m_format = format;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Type(const TextureType textureType)
|
||||
{
|
||||
Dx9TextureLoader& Dx9TextureLoader::Type(const TextureType textureType)
|
||||
{
|
||||
m_type = textureType;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::HasMipMaps(const bool hasMipMaps)
|
||||
{
|
||||
Dx9TextureLoader& Dx9TextureLoader::HasMipMaps(const bool hasMipMaps)
|
||||
{
|
||||
m_has_mip_maps = hasMipMaps;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Width(const unsigned width)
|
||||
{
|
||||
Dx9TextureLoader& Dx9TextureLoader::Width(const unsigned width)
|
||||
{
|
||||
m_width = width;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Height(const unsigned height)
|
||||
{
|
||||
Dx9TextureLoader& Dx9TextureLoader::Height(const unsigned height)
|
||||
{
|
||||
m_height = height;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Depth(const unsigned depth)
|
||||
{
|
||||
Dx9TextureLoader& Dx9TextureLoader::Depth(const unsigned depth)
|
||||
{
|
||||
m_depth = depth;
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> Dx9TextureLoader::LoadTexture(const void* data)
|
||||
{
|
||||
std::unique_ptr<Texture> Dx9TextureLoader::LoadTexture(const void* data)
|
||||
{
|
||||
const auto* format = GetFormatForDx9Format();
|
||||
|
||||
if (format == nullptr)
|
||||
@@ -101,4 +103,5 @@ std::unique_ptr<Texture> Dx9TextureLoader::LoadTexture(const void* data)
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
} // namespace image
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Dx9TextureLoader
|
||||
namespace image
|
||||
{
|
||||
public:
|
||||
class Dx9TextureLoader
|
||||
{
|
||||
public:
|
||||
Dx9TextureLoader();
|
||||
|
||||
Dx9TextureLoader& Format(oat::D3DFORMAT format);
|
||||
@@ -19,7 +21,7 @@ public:
|
||||
|
||||
std::unique_ptr<Texture> LoadTexture(const void* data);
|
||||
|
||||
private:
|
||||
private:
|
||||
[[nodiscard]] const ImageFormat* GetFormatForDx9Format() const;
|
||||
|
||||
oat::D3DFORMAT m_format;
|
||||
@@ -28,4 +30,5 @@ private:
|
||||
unsigned m_width;
|
||||
unsigned m_height;
|
||||
unsigned m_depth;
|
||||
};
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Image/Texture.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
class IImageWriter
|
||||
{
|
||||
public:
|
||||
IImageWriter() = default;
|
||||
virtual ~IImageWriter() = default;
|
||||
IImageWriter(const IImageWriter& other) = default;
|
||||
IImageWriter(IImageWriter&& other) noexcept = default;
|
||||
IImageWriter& operator=(const IImageWriter& other) = default;
|
||||
IImageWriter& operator=(IImageWriter&& other) noexcept = default;
|
||||
|
||||
virtual bool SupportsImageFormat(const ImageFormat* imageFormat) = 0;
|
||||
virtual std::string GetFileExtension() = 0;
|
||||
virtual void DumpImage(std::ostream& stream, const Texture* texture) = 0;
|
||||
};
|
||||
@@ -1,28 +1,30 @@
|
||||
#include "ImageFormat.h"
|
||||
|
||||
ImageFormat::ImageFormat(const ImageFormatId id, const oat::D3DFORMAT d3dFormat, const oat::DXGI_FORMAT dxgiFormat)
|
||||
namespace image
|
||||
{
|
||||
ImageFormat::ImageFormat(const ImageFormatId id, const oat::D3DFORMAT d3dFormat, const oat::DXGI_FORMAT dxgiFormat)
|
||||
: m_id(id),
|
||||
m_d3d_format(d3dFormat),
|
||||
m_dxgi_format(dxgiFormat)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ImageFormatId ImageFormat::GetId() const
|
||||
{
|
||||
ImageFormatId ImageFormat::GetId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
}
|
||||
|
||||
oat::D3DFORMAT ImageFormat::GetD3DFormat() const
|
||||
{
|
||||
oat::D3DFORMAT ImageFormat::GetD3DFormat() const
|
||||
{
|
||||
return m_d3d_format;
|
||||
}
|
||||
}
|
||||
|
||||
oat::DXGI_FORMAT ImageFormat::GetDxgiFormat() const
|
||||
{
|
||||
oat::DXGI_FORMAT ImageFormat::GetDxgiFormat() const
|
||||
{
|
||||
return m_dxgi_format;
|
||||
}
|
||||
}
|
||||
|
||||
ImageFormatUnsigned::ImageFormatUnsigned(const ImageFormatId id,
|
||||
ImageFormatUnsigned::ImageFormatUnsigned(const ImageFormatId id,
|
||||
const oat::D3DFORMAT d3dFormat,
|
||||
const oat::DXGI_FORMAT dxgiFormat,
|
||||
const unsigned bitsPerPixel,
|
||||
@@ -44,25 +46,25 @@ ImageFormatUnsigned::ImageFormatUnsigned(const ImageFormatId id,
|
||||
m_b_size(bSize),
|
||||
m_a_offset(aOffset),
|
||||
m_a_size(aSize)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ImageFormatType ImageFormatUnsigned::GetType() const
|
||||
{
|
||||
ImageFormatType ImageFormatUnsigned::GetType() const
|
||||
{
|
||||
return ImageFormatType::UNSIGNED;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ImageFormatUnsigned::GetPitch(const unsigned mipLevel, const unsigned width) const
|
||||
{
|
||||
size_t ImageFormatUnsigned::GetPitch(const unsigned mipLevel, const unsigned width) const
|
||||
{
|
||||
unsigned mipWidth = width >> mipLevel;
|
||||
if (mipWidth == 0)
|
||||
mipWidth = 1;
|
||||
|
||||
return mipWidth * m_bits_per_pixel / 8;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ImageFormatUnsigned::GetSizeOfMipLevel(const unsigned mipLevel, const unsigned width, const unsigned height, const unsigned depth) const
|
||||
{
|
||||
size_t ImageFormatUnsigned::GetSizeOfMipLevel(const unsigned mipLevel, const unsigned width, const unsigned height, const unsigned depth) const
|
||||
{
|
||||
unsigned mipWidth = width >> mipLevel;
|
||||
unsigned mipHeight = height >> mipLevel;
|
||||
unsigned mipDepth = depth >> mipLevel;
|
||||
@@ -75,23 +77,23 @@ size_t ImageFormatUnsigned::GetSizeOfMipLevel(const unsigned mipLevel, const uns
|
||||
mipDepth = 1;
|
||||
|
||||
return mipWidth * mipHeight * mipDepth * m_bits_per_pixel / 8;
|
||||
}
|
||||
}
|
||||
|
||||
ImageFormatBlockCompressed::ImageFormatBlockCompressed(
|
||||
ImageFormatBlockCompressed::ImageFormatBlockCompressed(
|
||||
const ImageFormatId id, const oat::D3DFORMAT d3dFormat, const oat::DXGI_FORMAT dxgiFormat, const unsigned blockSize, const unsigned bitsPerBlock)
|
||||
: ImageFormat(id, d3dFormat, dxgiFormat),
|
||||
m_block_size(blockSize),
|
||||
m_bits_per_block(bitsPerBlock)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ImageFormatType ImageFormatBlockCompressed::GetType() const
|
||||
{
|
||||
ImageFormatType ImageFormatBlockCompressed::GetType() const
|
||||
{
|
||||
return ImageFormatType::BLOCK_COMPRESSED;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ImageFormatBlockCompressed::GetPitch(const unsigned mipLevel, const unsigned width) const
|
||||
{
|
||||
size_t ImageFormatBlockCompressed::GetPitch(const unsigned mipLevel, const unsigned width) const
|
||||
{
|
||||
unsigned mipWidth = width >> mipLevel;
|
||||
|
||||
if (mipWidth == 0)
|
||||
@@ -100,10 +102,10 @@ size_t ImageFormatBlockCompressed::GetPitch(const unsigned mipLevel, const unsig
|
||||
const unsigned blockCount = (mipWidth + m_block_size - 1) / m_block_size;
|
||||
|
||||
return blockCount * m_bits_per_block / 8;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ImageFormatBlockCompressed::GetSizeOfMipLevel(const unsigned mipLevel, const unsigned width, const unsigned height, const unsigned depth) const
|
||||
{
|
||||
size_t ImageFormatBlockCompressed::GetSizeOfMipLevel(const unsigned mipLevel, const unsigned width, const unsigned height, const unsigned depth) const
|
||||
{
|
||||
unsigned mipWidth = width >> mipLevel;
|
||||
unsigned mipHeight = height >> mipLevel;
|
||||
unsigned mipDepth = depth >> mipLevel;
|
||||
@@ -118,47 +120,47 @@ size_t ImageFormatBlockCompressed::GetSizeOfMipLevel(const unsigned mipLevel, co
|
||||
const unsigned blockCount = ((mipWidth + m_block_size - 1) / m_block_size) * ((mipHeight + m_block_size - 1) / m_block_size) * mipDepth;
|
||||
|
||||
return blockCount * m_bits_per_block / 8;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageFormatUnsigned::HasR() const
|
||||
{
|
||||
bool ImageFormatUnsigned::HasR() const
|
||||
{
|
||||
return m_r_size > 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageFormatUnsigned::HasG() const
|
||||
{
|
||||
bool ImageFormatUnsigned::HasG() const
|
||||
{
|
||||
return m_g_size > 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageFormatUnsigned::HasB() const
|
||||
{
|
||||
bool ImageFormatUnsigned::HasB() const
|
||||
{
|
||||
return m_b_size > 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageFormatUnsigned::HasA() const
|
||||
{
|
||||
bool ImageFormatUnsigned::HasA() const
|
||||
{
|
||||
return m_a_size > 0;
|
||||
}
|
||||
}
|
||||
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R8_G8_B8(ImageFormatId::R8_G8_B8, oat::D3DFMT_R8G8B8, oat::DXGI_FORMAT_UNKNOWN, 24, 0, 8, 8, 8, 16, 8, 0, 0);
|
||||
const ImageFormatUnsigned
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R8_G8_B8(ImageFormatId::R8_G8_B8, oat::D3DFMT_R8G8B8, oat::DXGI_FORMAT_UNKNOWN, 24, 0, 8, 8, 8, 16, 8, 0, 0);
|
||||
const ImageFormatUnsigned
|
||||
ImageFormat::FORMAT_B8_G8_R8_X8(ImageFormatId::B8_G8_R8_X8, oat::D3DFMT_X8R8G8B8, oat::DXGI_FORMAT_B8G8R8X8_UNORM, 32, 16, 8, 8, 8, 0, 8, 0, 0);
|
||||
const ImageFormatUnsigned
|
||||
const ImageFormatUnsigned
|
||||
ImageFormat::FORMAT_R8_G8_B8_A8(ImageFormatId::R8_G8_B8_A8, oat::D3DFMT_A8B8G8R8, oat::DXGI_FORMAT_R8G8B8A8_UNORM, 32, 0, 8, 8, 8, 16, 8, 24, 8);
|
||||
const ImageFormatUnsigned
|
||||
const ImageFormatUnsigned
|
||||
ImageFormat::FORMAT_B8_G8_R8_A8(ImageFormatId::B8_G8_R8_A8, oat::D3DFMT_A8R8G8B8, oat::DXGI_FORMAT_B8G8R8A8_UNORM, 32, 16, 8, 8, 8, 0, 8, 24, 8);
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_A8(ImageFormatId::A8, oat::D3DFMT_A8, oat::DXGI_FORMAT_A8_UNORM, 8, 0, 0, 0, 0, 0, 0, 0, 8);
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R16_G16_B16_A16_FLOAT(
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_A8(ImageFormatId::A8, oat::D3DFMT_A8, oat::DXGI_FORMAT_A8_UNORM, 8, 0, 0, 0, 0, 0, 0, 0, 8);
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R16_G16_B16_A16_FLOAT(
|
||||
ImageFormatId::R16_G16_B16_A16_FLOAT, oat::D3DFMT_A16B16G16R16F, oat::DXGI_FORMAT_R16G16B16A16_FLOAT, 128, 0, 0, 0, 0, 0, 0, 0, 8);
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R8(ImageFormatId::R8, oat::D3DFMT_L8, oat::DXGI_FORMAT_R8_UNORM, 8, 0, 8, 0, 0, 0, 0, 0, 0);
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R8_A8(ImageFormatId::R8_A8, oat::D3DFMT_A8L8, oat::DXGI_FORMAT_UNKNOWN, 16, 0, 8, 0, 0, 0, 0, 8, 8);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC1(ImageFormatId::BC1, oat::D3DFMT_DXT1, oat::DXGI_FORMAT_BC1_UNORM, 4, 64);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC2(ImageFormatId::BC2, oat::D3DFMT_DXT3, oat::DXGI_FORMAT_BC2_UNORM, 4, 128);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC3(ImageFormatId::BC3, oat::D3DFMT_DXT5, oat::DXGI_FORMAT_BC3_UNORM, 4, 128);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC4(ImageFormatId::BC4, oat::D3DFMT_UNKNOWN, oat::DXGI_FORMAT_BC4_UNORM, 4, 64);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC5(ImageFormatId::BC5, oat::D3DFMT_UNKNOWN, oat::DXGI_FORMAT_BC5_UNORM, 4, 128);
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R8(ImageFormatId::R8, oat::D3DFMT_L8, oat::DXGI_FORMAT_R8_UNORM, 8, 0, 8, 0, 0, 0, 0, 0, 0);
|
||||
const ImageFormatUnsigned ImageFormat::FORMAT_R8_A8(ImageFormatId::R8_A8, oat::D3DFMT_A8L8, oat::DXGI_FORMAT_UNKNOWN, 16, 0, 8, 0, 0, 0, 0, 8, 8);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC1(ImageFormatId::BC1, oat::D3DFMT_DXT1, oat::DXGI_FORMAT_BC1_UNORM, 4, 64);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC2(ImageFormatId::BC2, oat::D3DFMT_DXT3, oat::DXGI_FORMAT_BC2_UNORM, 4, 128);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC3(ImageFormatId::BC3, oat::D3DFMT_DXT5, oat::DXGI_FORMAT_BC3_UNORM, 4, 128);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC4(ImageFormatId::BC4, oat::D3DFMT_UNKNOWN, oat::DXGI_FORMAT_BC4_UNORM, 4, 64);
|
||||
const ImageFormatBlockCompressed ImageFormat::FORMAT_BC5(ImageFormatId::BC5, oat::D3DFMT_UNKNOWN, oat::DXGI_FORMAT_BC5_UNORM, 4, 128);
|
||||
|
||||
const ImageFormat* const ImageFormat::ALL_FORMATS[static_cast<unsigned>(ImageFormatId::MAX)]{
|
||||
const ImageFormat* const ImageFormat::ALL_FORMATS[static_cast<unsigned>(ImageFormatId::MAX)]{
|
||||
&FORMAT_R8_G8_B8,
|
||||
&FORMAT_B8_G8_R8_X8,
|
||||
&FORMAT_R8_G8_B8_A8,
|
||||
@@ -172,4 +174,5 @@ const ImageFormat* const ImageFormat::ALL_FORMATS[static_cast<unsigned>(ImageFor
|
||||
&FORMAT_BC3,
|
||||
&FORMAT_BC4,
|
||||
&FORMAT_BC5,
|
||||
};
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
enum class ImageFormatId
|
||||
namespace image
|
||||
{
|
||||
enum class ImageFormatId
|
||||
{
|
||||
UNKNOWN = -1,
|
||||
R8_G8_B8,
|
||||
B8_G8_R8_X8,
|
||||
@@ -24,28 +26,28 @@ enum class ImageFormatId
|
||||
BC5,
|
||||
|
||||
MAX
|
||||
};
|
||||
};
|
||||
|
||||
enum class ImageFormatType
|
||||
{
|
||||
enum class ImageFormatType
|
||||
{
|
||||
UNKNOWN,
|
||||
UNSIGNED,
|
||||
BLOCK_COMPRESSED
|
||||
};
|
||||
};
|
||||
|
||||
class ImageFormatUnsigned;
|
||||
class ImageFormatBlockCompressed;
|
||||
class ImageFormatUnsigned;
|
||||
class ImageFormatBlockCompressed;
|
||||
|
||||
class ImageFormat
|
||||
{
|
||||
class ImageFormat
|
||||
{
|
||||
ImageFormatId m_id;
|
||||
oat::D3DFORMAT m_d3d_format;
|
||||
oat::DXGI_FORMAT m_dxgi_format;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
ImageFormat(ImageFormatId id, oat::D3DFORMAT d3dFormat, oat::DXGI_FORMAT dxgiFormat);
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual ~ImageFormat() = default;
|
||||
|
||||
[[nodiscard]] ImageFormatId GetId() const;
|
||||
@@ -70,11 +72,11 @@ public:
|
||||
static const ImageFormatBlockCompressed FORMAT_BC4;
|
||||
static const ImageFormatBlockCompressed FORMAT_BC5;
|
||||
static const ImageFormat* const ALL_FORMATS[static_cast<unsigned>(ImageFormatId::MAX)];
|
||||
};
|
||||
};
|
||||
|
||||
class ImageFormatUnsigned final : public ImageFormat
|
||||
{
|
||||
public:
|
||||
class ImageFormatUnsigned final : public ImageFormat
|
||||
{
|
||||
public:
|
||||
unsigned m_bits_per_pixel;
|
||||
unsigned m_r_offset;
|
||||
unsigned m_r_size;
|
||||
@@ -106,11 +108,11 @@ public:
|
||||
[[nodiscard]] bool HasG() const;
|
||||
[[nodiscard]] bool HasB() const;
|
||||
[[nodiscard]] bool HasA() const;
|
||||
};
|
||||
};
|
||||
|
||||
class ImageFormatBlockCompressed final : public ImageFormat
|
||||
{
|
||||
public:
|
||||
class ImageFormatBlockCompressed final : public ImageFormat
|
||||
{
|
||||
public:
|
||||
unsigned m_block_size;
|
||||
unsigned m_bits_per_block;
|
||||
|
||||
@@ -119,4 +121,5 @@ public:
|
||||
[[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;
|
||||
};
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
24
src/ObjImage/Image/ImageWriter.h
Normal file
24
src/ObjImage/Image/ImageWriter.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "Image/Texture.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace image
|
||||
{
|
||||
class ImageWriter
|
||||
{
|
||||
public:
|
||||
ImageWriter() = default;
|
||||
virtual ~ImageWriter() = default;
|
||||
ImageWriter(const ImageWriter& other) = default;
|
||||
ImageWriter(ImageWriter&& other) noexcept = default;
|
||||
ImageWriter& operator=(const ImageWriter& other) = default;
|
||||
ImageWriter& operator=(ImageWriter&& other) noexcept = default;
|
||||
|
||||
virtual bool SupportsImageFormat(const ImageFormat* imageFormat) = 0;
|
||||
virtual std::string GetFileExtension() = 0;
|
||||
virtual void DumpImage(std::ostream& stream, const Texture* texture) = 0;
|
||||
};
|
||||
} // namespace image
|
||||
@@ -8,7 +8,9 @@
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
namespace iwi
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
const ImageFormat* GetFormat6(int8_t format)
|
||||
{
|
||||
@@ -74,7 +76,7 @@ namespace iwi
|
||||
|
||||
texture->Allocate();
|
||||
|
||||
auto currentFileSize = sizeof(iwi6::IwiHeader) + sizeof(IwiVersion);
|
||||
auto currentFileSize = sizeof(iwi6::IwiHeader) + sizeof(IwiVersionHeader);
|
||||
const auto mipMapCount = hasMipMaps ? texture->GetMipMapCount() : 1;
|
||||
|
||||
for (auto currentMipLevel = mipMapCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
@@ -188,7 +190,7 @@ namespace iwi
|
||||
|
||||
texture->Allocate();
|
||||
|
||||
auto currentFileSize = sizeof(iwi8::IwiHeader) + sizeof(IwiVersion);
|
||||
auto currentFileSize = sizeof(iwi8::IwiHeader) + sizeof(IwiVersionHeader);
|
||||
const auto mipMapCount = hasMipMaps ? texture->GetMipMapCount() : 1;
|
||||
|
||||
for (auto currentMipLevel = mipMapCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
@@ -283,7 +285,7 @@ namespace iwi
|
||||
|
||||
texture->Allocate();
|
||||
|
||||
auto currentFileSize = sizeof(iwi13::IwiHeader) + sizeof(IwiVersion);
|
||||
auto currentFileSize = sizeof(iwi13::IwiHeader) + sizeof(IwiVersionHeader);
|
||||
const auto mipMapCount = hasMipMaps ? texture->GetMipMapCount() : 1;
|
||||
|
||||
for (auto currentMipLevel = mipMapCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
@@ -380,7 +382,7 @@ namespace iwi
|
||||
|
||||
texture->Allocate();
|
||||
|
||||
auto currentFileSize = sizeof(iwi27::IwiHeader) + sizeof(IwiVersion);
|
||||
auto currentFileSize = sizeof(iwi27::IwiHeader) + sizeof(IwiVersionHeader);
|
||||
const auto mipMapCount = hasMipMaps ? texture->GetMipMapCount() : 1;
|
||||
|
||||
for (auto currentMipLevel = mipMapCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
@@ -405,22 +407,25 @@ namespace iwi
|
||||
|
||||
return texture;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace image
|
||||
{
|
||||
std::unique_ptr<Texture> LoadIwi(std::istream& stream)
|
||||
{
|
||||
IwiVersion iwiVersion{};
|
||||
IwiVersionHeader iwiVersionHeader{};
|
||||
|
||||
stream.read(reinterpret_cast<char*>(&iwiVersion), sizeof(iwiVersion));
|
||||
if (stream.gcount() != sizeof(iwiVersion))
|
||||
stream.read(reinterpret_cast<char*>(&iwiVersionHeader), sizeof(iwiVersionHeader));
|
||||
if (stream.gcount() != sizeof(iwiVersionHeader))
|
||||
return nullptr;
|
||||
|
||||
if (iwiVersion.tag[0] != 'I' || iwiVersion.tag[1] != 'W' || iwiVersion.tag[2] != 'i')
|
||||
if (iwiVersionHeader.tag[0] != 'I' || iwiVersionHeader.tag[1] != 'W' || iwiVersionHeader.tag[2] != 'i')
|
||||
{
|
||||
con::error("Invalid IWI magic");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
switch (iwiVersion.version)
|
||||
switch (iwiVersionHeader.version)
|
||||
{
|
||||
case 6:
|
||||
return LoadIwi6(stream);
|
||||
@@ -438,7 +443,7 @@ namespace iwi
|
||||
break;
|
||||
}
|
||||
|
||||
con::error("Unknown IWI version {}", iwiVersion.version);
|
||||
con::error("Unknown IWI version {}", iwiVersionHeader.version);
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace iwi
|
||||
} // namespace image
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <istream>
|
||||
#include <memory>
|
||||
|
||||
namespace iwi
|
||||
namespace image
|
||||
{
|
||||
std::unique_ptr<Texture> LoadIwi(std::istream& stream);
|
||||
}; // namespace iwi
|
||||
}; // namespace image
|
||||
|
||||
@@ -2,15 +2,28 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct IwiVersion
|
||||
namespace image
|
||||
{
|
||||
enum class IwiVersion : std::uint8_t
|
||||
{
|
||||
// IW3
|
||||
IWI_6 = 6,
|
||||
// IW4, IW5
|
||||
IWI_8 = 8,
|
||||
// T5
|
||||
IWI_13 = 13,
|
||||
// T6
|
||||
IWI_27 = 27
|
||||
};
|
||||
|
||||
struct IwiVersionHeader
|
||||
{
|
||||
char tag[3];
|
||||
char version;
|
||||
};
|
||||
};
|
||||
|
||||
// IW3
|
||||
namespace iwi6
|
||||
{
|
||||
namespace iwi6
|
||||
{
|
||||
struct IwiHeader
|
||||
{
|
||||
int8_t format;
|
||||
@@ -54,11 +67,10 @@ namespace iwi6
|
||||
IMG_FLAG_RENDER_TARGET = 1 << 17,
|
||||
IMG_FLAG_SYSTEMMEM = 1 << 18
|
||||
};
|
||||
} // namespace iwi6
|
||||
} // namespace iwi6
|
||||
|
||||
// IW4
|
||||
namespace iwi8
|
||||
{
|
||||
namespace iwi8
|
||||
{
|
||||
struct IwiHeader
|
||||
{
|
||||
uint32_t flags;
|
||||
@@ -122,11 +134,10 @@ namespace iwi8
|
||||
IMG_FLAG_RENDER_TARGET = 1 << 25,
|
||||
IMG_FLAG_SYSTEMMEM = 1 << 26
|
||||
};
|
||||
} // namespace iwi8
|
||||
} // namespace iwi8
|
||||
|
||||
// T5
|
||||
namespace iwi13
|
||||
{
|
||||
namespace iwi13
|
||||
{
|
||||
struct IwiHeader
|
||||
{
|
||||
int8_t format;
|
||||
@@ -177,11 +188,10 @@ namespace iwi13
|
||||
IMG_FLAG_SYSTEMMEM = 1 << 18,
|
||||
};
|
||||
|
||||
} // namespace iwi13
|
||||
} // namespace iwi13
|
||||
|
||||
// T6
|
||||
namespace iwi27
|
||||
{
|
||||
namespace iwi27
|
||||
{
|
||||
struct IwiHeader
|
||||
{
|
||||
int8_t format;
|
||||
@@ -232,4 +242,5 @@ namespace iwi27
|
||||
IMG_FLAG_MULTISAMPLE = 1 << 18,
|
||||
};
|
||||
|
||||
} // namespace iwi27
|
||||
} // namespace iwi27
|
||||
} // namespace image
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cassert>
|
||||
#include <ostream>
|
||||
|
||||
using namespace iwi13;
|
||||
using namespace image::iwi13;
|
||||
|
||||
IwiWriter::IwiWriter() = default;
|
||||
|
||||
@@ -54,13 +54,13 @@ std::string IwiWriter::GetFileExtension()
|
||||
|
||||
void IwiWriter::WriteVersion(std::ostream& stream)
|
||||
{
|
||||
IwiVersion version{};
|
||||
IwiVersionHeader version{};
|
||||
version.tag[0] = 'I';
|
||||
version.tag[1] = 'W';
|
||||
version.tag[2] = 'i';
|
||||
version.version = 13;
|
||||
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersion));
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersionHeader));
|
||||
}
|
||||
|
||||
void IwiWriter::FillHeader2D(IwiHeader& header, const Texture2D& texture)
|
||||
@@ -101,7 +101,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
|
||||
if (!texture->HasMipMaps())
|
||||
header.flags |= IMG_FLAG_NOMIPMAPS;
|
||||
|
||||
auto currentFileSize = sizeof(IwiVersion) + sizeof(IwiHeader);
|
||||
auto currentFileSize = sizeof(IwiVersionHeader) + sizeof(IwiHeader);
|
||||
|
||||
const auto textureMipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
|
||||
for (auto currentMipLevel = textureMipCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "IImageWriter.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "ImageWriter.h"
|
||||
|
||||
namespace iwi13
|
||||
namespace image::iwi13
|
||||
{
|
||||
class IwiWriter final : public IImageWriter
|
||||
class IwiWriter final : public ImageWriter
|
||||
{
|
||||
static IwiFormat GetIwiFormatForImageFormat(const ImageFormat* imageFormat);
|
||||
|
||||
@@ -27,4 +27,4 @@ namespace iwi13
|
||||
std::string GetFileExtension() override;
|
||||
void DumpImage(std::ostream& stream, const Texture* texture) override;
|
||||
};
|
||||
} // namespace iwi13
|
||||
} // namespace image::iwi13
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cassert>
|
||||
#include <ostream>
|
||||
|
||||
using namespace iwi27;
|
||||
using namespace image::iwi27;
|
||||
|
||||
IwiWriter::IwiWriter() = default;
|
||||
|
||||
@@ -54,13 +54,13 @@ std::string IwiWriter::GetFileExtension()
|
||||
|
||||
void IwiWriter::WriteVersion(std::ostream& stream)
|
||||
{
|
||||
IwiVersion version{};
|
||||
IwiVersionHeader version{};
|
||||
version.tag[0] = 'I';
|
||||
version.tag[1] = 'W';
|
||||
version.tag[2] = 'i';
|
||||
version.version = 27;
|
||||
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersion));
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersionHeader));
|
||||
}
|
||||
|
||||
void IwiWriter::FillHeader2D(IwiHeader& header, const Texture2D& texture)
|
||||
@@ -104,7 +104,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
|
||||
for (auto& i : header.maxGlossForMip)
|
||||
i = 0;
|
||||
|
||||
auto currentFileSize = sizeof(IwiVersion) + sizeof(IwiHeader);
|
||||
auto currentFileSize = sizeof(IwiVersionHeader) + sizeof(IwiHeader);
|
||||
|
||||
const auto textureMipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
|
||||
for (auto currentMipLevel = textureMipCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "IImageWriter.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "ImageWriter.h"
|
||||
|
||||
namespace iwi27
|
||||
namespace image::iwi27
|
||||
{
|
||||
class IwiWriter final : public IImageWriter
|
||||
class IwiWriter final : public ImageWriter
|
||||
{
|
||||
static IwiFormat GetIwiFormatForImageFormat(const ImageFormat* imageFormat);
|
||||
|
||||
@@ -27,4 +27,4 @@ namespace iwi27
|
||||
std::string GetFileExtension() override;
|
||||
void DumpImage(std::ostream& stream, const Texture* texture) override;
|
||||
};
|
||||
} // namespace iwi27
|
||||
} // namespace image::iwi27
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace iwi6;
|
||||
using namespace image::iwi6;
|
||||
|
||||
IwiWriter::IwiWriter() = default;
|
||||
|
||||
@@ -40,13 +40,13 @@ IwiFormat IwiWriter::GetIwiFormatForImageFormat(const ImageFormat* imageFormat)
|
||||
|
||||
void IwiWriter::WriteVersion(std::ostream& stream)
|
||||
{
|
||||
IwiVersion version{};
|
||||
IwiVersionHeader version{};
|
||||
version.tag[0] = 'I';
|
||||
version.tag[1] = 'W';
|
||||
version.tag[2] = 'i';
|
||||
version.version = 6;
|
||||
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersion));
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersionHeader));
|
||||
}
|
||||
|
||||
void IwiWriter::FillHeader2D(IwiHeader& header, const Texture2D& texture)
|
||||
@@ -96,7 +96,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
|
||||
if (!texture->HasMipMaps())
|
||||
header.flags |= IMG_FLAG_NOMIPMAPS;
|
||||
|
||||
auto currentFileSize = sizeof(IwiVersion) + sizeof(IwiHeader);
|
||||
auto currentFileSize = sizeof(IwiVersionHeader) + sizeof(IwiHeader);
|
||||
|
||||
const auto textureMipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
|
||||
for (auto currentMipLevel = textureMipCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "IImageWriter.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "ImageWriter.h"
|
||||
|
||||
namespace iwi6
|
||||
namespace image::iwi6
|
||||
{
|
||||
class IwiWriter final : public IImageWriter
|
||||
class IwiWriter final : public ImageWriter
|
||||
{
|
||||
static IwiFormat GetIwiFormatForImageFormat(const ImageFormat* imageFormat);
|
||||
|
||||
@@ -27,4 +27,4 @@ namespace iwi6
|
||||
std::string GetFileExtension() override;
|
||||
void DumpImage(std::ostream& stream, const Texture* texture) override;
|
||||
};
|
||||
} // namespace iwi6
|
||||
} // namespace image::iwi6
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace iwi8;
|
||||
using namespace image::iwi8;
|
||||
|
||||
IwiWriter::IwiWriter() = default;
|
||||
|
||||
@@ -40,13 +40,13 @@ IwiFormat IwiWriter::GetIwiFormatForImageFormat(const ImageFormat* imageFormat)
|
||||
|
||||
void IwiWriter::WriteVersion(std::ostream& stream)
|
||||
{
|
||||
IwiVersion version{};
|
||||
IwiVersionHeader version{};
|
||||
version.tag[0] = 'I';
|
||||
version.tag[1] = 'W';
|
||||
version.tag[2] = 'i';
|
||||
version.version = 8;
|
||||
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersion));
|
||||
stream.write(reinterpret_cast<char*>(&version), sizeof(IwiVersionHeader));
|
||||
}
|
||||
|
||||
void IwiWriter::FillHeader2D(IwiHeader& header, const Texture2D& texture)
|
||||
@@ -96,7 +96,7 @@ void IwiWriter::DumpImage(std::ostream& stream, const Texture* texture)
|
||||
if (!texture->HasMipMaps())
|
||||
header.flags |= IMG_FLAG_NOMIPMAPS;
|
||||
|
||||
auto currentFileSize = sizeof(IwiVersion) + sizeof(IwiHeader);
|
||||
auto currentFileSize = sizeof(IwiVersionHeader) + sizeof(IwiHeader);
|
||||
|
||||
const auto textureMipCount = texture->HasMipMaps() ? texture->GetMipMapCount() : 1;
|
||||
for (auto currentMipLevel = textureMipCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "IImageWriter.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "ImageWriter.h"
|
||||
|
||||
namespace iwi8
|
||||
namespace image::iwi8
|
||||
{
|
||||
class IwiWriter final : public IImageWriter
|
||||
class IwiWriter final : public ImageWriter
|
||||
{
|
||||
static IwiFormat GetIwiFormatForImageFormat(const ImageFormat* imageFormat);
|
||||
|
||||
@@ -27,4 +27,4 @@ namespace iwi8
|
||||
std::string GetFileExtension() override;
|
||||
void DumpImage(std::ostream& stream, const Texture* texture) override;
|
||||
};
|
||||
} // namespace iwi8
|
||||
} // namespace image::iwi8
|
||||
|
||||
@@ -4,27 +4,29 @@
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
// ==============================================
|
||||
// ================= Texture ====================
|
||||
// ==============================================
|
||||
Texture::Texture(const ImageFormat* format, const bool mipMaps)
|
||||
namespace image
|
||||
{
|
||||
// ==============================================
|
||||
// ================= Texture ====================
|
||||
// ==============================================
|
||||
Texture::Texture(const ImageFormat* format, const bool mipMaps)
|
||||
{
|
||||
m_format = format;
|
||||
m_has_mip_maps = mipMaps;
|
||||
m_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Texture::Texture(Texture&& other) noexcept
|
||||
{
|
||||
Texture::Texture(Texture&& other) noexcept
|
||||
{
|
||||
m_format = other.m_format;
|
||||
m_has_mip_maps = other.m_has_mip_maps;
|
||||
m_data = other.m_data;
|
||||
|
||||
other.m_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Texture& Texture::operator=(Texture&& other) noexcept
|
||||
{
|
||||
Texture& Texture::operator=(Texture&& other) noexcept
|
||||
{
|
||||
m_format = other.m_format;
|
||||
m_has_mip_maps = other.m_has_mip_maps;
|
||||
m_data = other.m_data;
|
||||
@@ -32,21 +34,21 @@ Texture& Texture::operator=(Texture&& other) noexcept
|
||||
other.m_data = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
Texture::~Texture()
|
||||
{
|
||||
delete[] m_data;
|
||||
m_data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
const ImageFormat* Texture::GetFormat() const
|
||||
{
|
||||
const ImageFormat* Texture::GetFormat() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::Allocate()
|
||||
{
|
||||
void Texture::Allocate()
|
||||
{
|
||||
size_t storageRequirement = 0;
|
||||
const int mipLevelCount = m_has_mip_maps ? GetMipMapCount() : 1;
|
||||
|
||||
@@ -60,54 +62,54 @@ void Texture::Allocate()
|
||||
m_data = new uint8_t[storageRequirement];
|
||||
memset(m_data, 0, storageRequirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Texture::Empty() const
|
||||
{
|
||||
bool Texture::Empty() const
|
||||
{
|
||||
return m_data == nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool Texture::HasMipMaps() const
|
||||
{
|
||||
bool Texture::HasMipMaps() const
|
||||
{
|
||||
return m_has_mip_maps;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* Texture::GetBufferForMipLevel(const int mipLevel)
|
||||
{
|
||||
uint8_t* Texture::GetBufferForMipLevel(const int mipLevel)
|
||||
{
|
||||
return GetBufferForMipLevel(mipLevel, 0);
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t* Texture::GetBufferForMipLevel(const int mipLevel) const
|
||||
{
|
||||
const uint8_t* Texture::GetBufferForMipLevel(const int mipLevel) const
|
||||
{
|
||||
return GetBufferForMipLevel(mipLevel, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
// ================ Texture2D ===================
|
||||
// ==============================================
|
||||
Texture2D::Texture2D(const ImageFormat* format, const unsigned width, const unsigned height)
|
||||
// ==============================================
|
||||
// ================ Texture2D ===================
|
||||
// ==============================================
|
||||
Texture2D::Texture2D(const ImageFormat* format, const unsigned width, const unsigned height)
|
||||
: Texture2D(format, width, height, false)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(const ImageFormat* format, const unsigned width, const unsigned height, const bool mipMaps)
|
||||
Texture2D::Texture2D(const ImageFormat* format, const unsigned width, const unsigned height, const bool mipMaps)
|
||||
: Texture(format, mipMaps)
|
||||
{
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
Texture2D::Texture2D(Texture2D&& other) noexcept
|
||||
Texture2D::Texture2D(Texture2D&& other) noexcept
|
||||
: Texture(std::move(other)),
|
||||
m_width(other.m_width),
|
||||
m_height(other.m_height)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
Texture2D::~Texture2D() = default;
|
||||
Texture2D::~Texture2D() = default;
|
||||
|
||||
Texture2D& Texture2D::operator=(Texture2D&& other) noexcept
|
||||
{
|
||||
Texture2D& Texture2D::operator=(Texture2D&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
@@ -116,40 +118,40 @@ Texture2D& Texture2D::operator=(Texture2D&& other) noexcept
|
||||
m_height = other.m_height;
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
TextureType Texture2D::GetTextureType() const
|
||||
{
|
||||
TextureType Texture2D::GetTextureType() const
|
||||
{
|
||||
return TextureType::T_2D;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Texture2D::GetWidth() const
|
||||
{
|
||||
unsigned Texture2D::GetWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Texture2D::GetHeight() const
|
||||
{
|
||||
unsigned Texture2D::GetHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Texture2D::GetDepth() const
|
||||
{
|
||||
unsigned Texture2D::GetDepth() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int Texture2D::GetFaceCount() const
|
||||
{
|
||||
int Texture2D::GetFaceCount() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t Texture2D::GetSizeOfMipLevel(const int mipLevel) const
|
||||
{
|
||||
size_t Texture2D::GetSizeOfMipLevel(const int mipLevel) const
|
||||
{
|
||||
return m_format->GetSizeOfMipLevel(mipLevel, m_width, m_height, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int Texture2D::GetMipMapCount() const
|
||||
{
|
||||
int Texture2D::GetMipMapCount() const
|
||||
{
|
||||
unsigned maxDimension = std::max(m_width, m_height);
|
||||
|
||||
int mipMapCount = 0;
|
||||
@@ -161,10 +163,10 @@ int Texture2D::GetMipMapCount() const
|
||||
}
|
||||
|
||||
return mipMapCount;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* Texture2D::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
{
|
||||
uint8_t* Texture2D::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
{
|
||||
assert(mipLevel >= 0);
|
||||
assert(mipLevel < (m_has_mip_maps ? GetMipMapCount() : 1));
|
||||
assert(face == 0);
|
||||
@@ -186,10 +188,10 @@ uint8_t* Texture2D::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
}
|
||||
|
||||
return &m_data[bufferOffset];
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t* Texture2D::GetBufferForMipLevel(const int mipLevel, const int face) const
|
||||
{
|
||||
const uint8_t* Texture2D::GetBufferForMipLevel(const int mipLevel, const int face) const
|
||||
{
|
||||
assert(mipLevel >= 0);
|
||||
assert(mipLevel < (m_has_mip_maps ? GetMipMapCount() : 1));
|
||||
assert(face == 0);
|
||||
@@ -211,52 +213,52 @@ const uint8_t* Texture2D::GetBufferForMipLevel(const int mipLevel, const int fac
|
||||
}
|
||||
|
||||
return &m_data[bufferOffset];
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
// =============== TextureCube ==================
|
||||
// ==============================================
|
||||
const int TextureCube::FACE_COUNT = 6;
|
||||
// ==============================================
|
||||
// =============== TextureCube ==================
|
||||
// ==============================================
|
||||
const int TextureCube::FACE_COUNT = 6;
|
||||
|
||||
TextureCube::TextureCube(const ImageFormat* format, const unsigned width, const unsigned height)
|
||||
TextureCube::TextureCube(const ImageFormat* format, const unsigned width, const unsigned height)
|
||||
: Texture2D(format, width, height)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
TextureCube::TextureCube(const ImageFormat* format, const unsigned width, const unsigned height, const bool mipMaps)
|
||||
TextureCube::TextureCube(const ImageFormat* format, const unsigned width, const unsigned height, const bool mipMaps)
|
||||
: Texture2D(format, width, height, mipMaps)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
TextureCube::TextureCube(TextureCube&& other) noexcept
|
||||
TextureCube::TextureCube(TextureCube&& other) noexcept
|
||||
: Texture2D(std::move(other))
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
TextureCube::~TextureCube() = default;
|
||||
TextureCube::~TextureCube() = default;
|
||||
|
||||
TextureCube& TextureCube::operator=(TextureCube&& other) noexcept
|
||||
{
|
||||
TextureCube& TextureCube::operator=(TextureCube&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
Texture2D::operator=(std::move(other));
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
TextureType TextureCube::GetTextureType() const
|
||||
{
|
||||
TextureType TextureCube::GetTextureType() const
|
||||
{
|
||||
return TextureType::T_CUBE;
|
||||
}
|
||||
}
|
||||
|
||||
int TextureCube::GetFaceCount() const
|
||||
{
|
||||
int TextureCube::GetFaceCount() const
|
||||
{
|
||||
return FACE_COUNT;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* TextureCube::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
{
|
||||
uint8_t* TextureCube::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
{
|
||||
assert(mipLevel >= 0);
|
||||
assert(mipLevel < (m_has_mip_maps ? GetMipMapCount() : 1));
|
||||
assert(face >= 0);
|
||||
@@ -279,10 +281,10 @@ uint8_t* TextureCube::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
}
|
||||
|
||||
return &m_data[bufferOffset + GetSizeOfMipLevel(mipLevel) * face];
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t* TextureCube::GetBufferForMipLevel(const int mipLevel, const int face) const
|
||||
{
|
||||
const uint8_t* TextureCube::GetBufferForMipLevel(const int mipLevel, const int face) const
|
||||
{
|
||||
assert(mipLevel >= 0);
|
||||
assert(mipLevel < (m_has_mip_maps ? GetMipMapCount() : 1));
|
||||
assert(face >= 0);
|
||||
@@ -305,37 +307,37 @@ const uint8_t* TextureCube::GetBufferForMipLevel(const int mipLevel, const int f
|
||||
}
|
||||
|
||||
return &m_data[bufferOffset + GetSizeOfMipLevel(mipLevel) * face];
|
||||
}
|
||||
}
|
||||
|
||||
// ==============================================
|
||||
// ================ Texture3D ===================
|
||||
// ==============================================
|
||||
// ==============================================
|
||||
// ================ Texture3D ===================
|
||||
// ==============================================
|
||||
|
||||
Texture3D::Texture3D(const ImageFormat* format, const unsigned width, const unsigned height, const unsigned depth)
|
||||
Texture3D::Texture3D(const ImageFormat* format, const unsigned width, const unsigned height, const unsigned depth)
|
||||
: Texture3D(format, width, height, depth, false)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
Texture3D::Texture3D(const ImageFormat* format, const unsigned width, const unsigned height, const unsigned depth, const bool mipMaps)
|
||||
Texture3D::Texture3D(const ImageFormat* format, const unsigned width, const unsigned height, const unsigned depth, const bool mipMaps)
|
||||
: Texture(format, mipMaps)
|
||||
{
|
||||
{
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_depth = depth;
|
||||
}
|
||||
}
|
||||
|
||||
Texture3D::Texture3D(Texture3D&& other) noexcept
|
||||
Texture3D::Texture3D(Texture3D&& other) noexcept
|
||||
: Texture(std::move(other)),
|
||||
m_width(other.m_width),
|
||||
m_height(other.m_height),
|
||||
m_depth(other.m_depth)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
Texture3D::~Texture3D() = default;
|
||||
Texture3D::~Texture3D() = default;
|
||||
|
||||
Texture3D& Texture3D::operator=(Texture3D&& other) noexcept
|
||||
{
|
||||
Texture3D& Texture3D::operator=(Texture3D&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
@@ -345,40 +347,40 @@ Texture3D& Texture3D::operator=(Texture3D&& other) noexcept
|
||||
m_depth = other.m_depth;
|
||||
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
TextureType Texture3D::GetTextureType() const
|
||||
{
|
||||
TextureType Texture3D::GetTextureType() const
|
||||
{
|
||||
return TextureType::T_3D;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Texture3D::GetWidth() const
|
||||
{
|
||||
unsigned Texture3D::GetWidth() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Texture3D::GetHeight() const
|
||||
{
|
||||
unsigned Texture3D::GetHeight() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Texture3D::GetDepth() const
|
||||
{
|
||||
unsigned Texture3D::GetDepth() const
|
||||
{
|
||||
return m_depth;
|
||||
}
|
||||
}
|
||||
|
||||
int Texture3D::GetFaceCount() const
|
||||
{
|
||||
int Texture3D::GetFaceCount() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t Texture3D::GetSizeOfMipLevel(const int mipLevel) const
|
||||
{
|
||||
size_t Texture3D::GetSizeOfMipLevel(const int mipLevel) const
|
||||
{
|
||||
return m_format->GetSizeOfMipLevel(mipLevel, m_width, m_height, m_depth);
|
||||
}
|
||||
}
|
||||
|
||||
int Texture3D::GetMipMapCount() const
|
||||
{
|
||||
int Texture3D::GetMipMapCount() const
|
||||
{
|
||||
unsigned maxDimension = std::max(std::max(m_width, m_height), m_depth);
|
||||
|
||||
int mipMapCount = 0;
|
||||
@@ -390,10 +392,10 @@ int Texture3D::GetMipMapCount() const
|
||||
}
|
||||
|
||||
return mipMapCount;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* Texture3D::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
{
|
||||
uint8_t* Texture3D::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
{
|
||||
assert(mipLevel >= 0);
|
||||
assert(mipLevel < (m_has_mip_maps ? GetMipMapCount() : 1));
|
||||
assert(face == 0);
|
||||
@@ -415,10 +417,10 @@ uint8_t* Texture3D::GetBufferForMipLevel(const int mipLevel, const int face)
|
||||
}
|
||||
|
||||
return &m_data[bufferOffset];
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t* Texture3D::GetBufferForMipLevel(const int mipLevel, const int face) const
|
||||
{
|
||||
const uint8_t* Texture3D::GetBufferForMipLevel(const int mipLevel, const int face) const
|
||||
{
|
||||
assert(mipLevel >= 0);
|
||||
assert(mipLevel < (m_has_mip_maps ? GetMipMapCount() : 1));
|
||||
assert(face == 0);
|
||||
@@ -440,4 +442,5 @@ const uint8_t* Texture3D::GetBufferForMipLevel(const int mipLevel, const int fac
|
||||
}
|
||||
|
||||
return &m_data[bufferOffset];
|
||||
}
|
||||
}
|
||||
} // namespace image
|
||||
|
||||
@@ -3,16 +3,18 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
enum class TextureType : std::uint8_t
|
||||
namespace image
|
||||
{
|
||||
enum class TextureType : std::uint8_t
|
||||
{
|
||||
T_2D,
|
||||
T_CUBE,
|
||||
T_3D
|
||||
};
|
||||
};
|
||||
|
||||
class Texture
|
||||
{
|
||||
protected:
|
||||
class Texture
|
||||
{
|
||||
protected:
|
||||
const ImageFormat* m_format;
|
||||
bool m_has_mip_maps;
|
||||
uint8_t* m_data;
|
||||
@@ -22,7 +24,7 @@ protected:
|
||||
|
||||
Texture& operator=(Texture&& other) noexcept;
|
||||
|
||||
public:
|
||||
public:
|
||||
Texture(const Texture& other) = delete;
|
||||
virtual ~Texture();
|
||||
|
||||
@@ -47,15 +49,15 @@ public:
|
||||
|
||||
[[nodiscard]] bool HasMipMaps() const;
|
||||
[[nodiscard]] virtual int GetMipMapCount() const = 0;
|
||||
};
|
||||
};
|
||||
|
||||
class Texture2D : public Texture
|
||||
{
|
||||
protected:
|
||||
class Texture2D : public Texture
|
||||
{
|
||||
protected:
|
||||
unsigned m_width;
|
||||
unsigned m_height;
|
||||
|
||||
public:
|
||||
public:
|
||||
Texture2D(const ImageFormat* format, unsigned width, unsigned height);
|
||||
Texture2D(const ImageFormat* format, unsigned width, unsigned height, bool mipMaps);
|
||||
Texture2D(const Texture2D& other) = delete;
|
||||
@@ -77,13 +79,13 @@ public:
|
||||
[[nodiscard]] const uint8_t* GetBufferForMipLevel(int mipLevel, int face) const override;
|
||||
|
||||
[[nodiscard]] int GetMipMapCount() const override;
|
||||
};
|
||||
};
|
||||
|
||||
class TextureCube final : public Texture2D
|
||||
{
|
||||
class TextureCube final : public Texture2D
|
||||
{
|
||||
static const int FACE_COUNT;
|
||||
|
||||
public:
|
||||
public:
|
||||
TextureCube(const ImageFormat* format, unsigned width, unsigned height);
|
||||
TextureCube(const ImageFormat* format, unsigned width, unsigned height, bool mipMaps);
|
||||
TextureCube(const TextureCube& other) = delete;
|
||||
@@ -99,15 +101,15 @@ public:
|
||||
|
||||
[[nodiscard]] uint8_t* GetBufferForMipLevel(int mipLevel, int face) override;
|
||||
[[nodiscard]] const uint8_t* GetBufferForMipLevel(int mipLevel, int face) const override;
|
||||
};
|
||||
};
|
||||
|
||||
class Texture3D final : public Texture
|
||||
{
|
||||
class Texture3D final : public Texture
|
||||
{
|
||||
unsigned m_width;
|
||||
unsigned m_height;
|
||||
unsigned m_depth;
|
||||
|
||||
public:
|
||||
public:
|
||||
Texture3D(const ImageFormat* format, unsigned width, unsigned height, unsigned depth);
|
||||
Texture3D(const ImageFormat* format, unsigned width, unsigned height, unsigned depth, bool mipMaps);
|
||||
Texture3D(const Texture3D& other) = delete;
|
||||
@@ -129,4 +131,5 @@ public:
|
||||
[[nodiscard]] const uint8_t* GetBufferForMipLevel(int mipLevel, int face) const override;
|
||||
|
||||
[[nodiscard]] int GetMipMapCount() const override;
|
||||
};
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
constexpr uint64_t TextureConverter::Mask1(const unsigned length)
|
||||
namespace image
|
||||
{
|
||||
constexpr uint64_t TextureConverter::Mask1(const unsigned length)
|
||||
{
|
||||
if (length >= sizeof(uint64_t) * 8)
|
||||
return UINT64_MAX;
|
||||
|
||||
return UINT64_MAX >> (sizeof(uint64_t) * 8 - length);
|
||||
}
|
||||
}
|
||||
|
||||
void TextureConverter::SetPixelFunctions(const unsigned inBitCount, const unsigned outBitCount)
|
||||
{
|
||||
void TextureConverter::SetPixelFunctions(const unsigned inBitCount, const unsigned outBitCount)
|
||||
{
|
||||
switch (inBitCount)
|
||||
{
|
||||
case 16:
|
||||
@@ -102,18 +104,18 @@ void TextureConverter::SetPixelFunctions(const unsigned inBitCount, const unsign
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TextureConverter::TextureConverter(const Texture* inputTexture, const ImageFormat* targetFormat)
|
||||
TextureConverter::TextureConverter(const Texture* inputTexture, const ImageFormat* targetFormat)
|
||||
: m_input_texture(inputTexture),
|
||||
m_output_texture(nullptr),
|
||||
m_input_format(inputTexture->GetFormat()),
|
||||
m_output_format(targetFormat)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
void TextureConverter::CreateOutputTexture()
|
||||
{
|
||||
void TextureConverter::CreateOutputTexture()
|
||||
{
|
||||
switch (m_input_texture->GetTextureType())
|
||||
{
|
||||
case TextureType::T_2D:
|
||||
@@ -136,10 +138,10 @@ void TextureConverter::CreateOutputTexture()
|
||||
}
|
||||
|
||||
m_output_texture->Allocate();
|
||||
}
|
||||
}
|
||||
|
||||
void TextureConverter::ReorderUnsignedToUnsigned() const
|
||||
{
|
||||
void TextureConverter::ReorderUnsignedToUnsigned() const
|
||||
{
|
||||
const auto* inputFormat = dynamic_cast<const ImageFormatUnsigned*>(m_input_format);
|
||||
const auto* outputFormat = dynamic_cast<const ImageFormatUnsigned*>(m_output_format);
|
||||
const auto mipCount = m_input_texture->HasMipMaps() ? m_input_texture->GetMipMapCount() : 1;
|
||||
@@ -180,10 +182,10 @@ void TextureConverter::ReorderUnsignedToUnsigned() const
|
||||
m_write_pixel_func(&outputBuffer[outputOffset], outPixel, outputFormat->m_bits_per_pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextureConverter::ConvertUnsignedToUnsigned()
|
||||
{
|
||||
void TextureConverter::ConvertUnsignedToUnsigned()
|
||||
{
|
||||
const auto* inputFormat = dynamic_cast<const ImageFormatUnsigned*>(m_input_format);
|
||||
const auto* outputFormat = dynamic_cast<const ImageFormatUnsigned*>(m_output_format);
|
||||
|
||||
@@ -192,8 +194,8 @@ void TextureConverter::ConvertUnsignedToUnsigned()
|
||||
|
||||
SetPixelFunctions(inputFormat->m_bits_per_pixel, outputFormat->m_bits_per_pixel);
|
||||
|
||||
if (inputFormat->m_r_size == outputFormat->m_r_size && inputFormat->m_g_size == outputFormat->m_g_size && inputFormat->m_b_size == outputFormat->m_b_size
|
||||
&& inputFormat->m_a_size == outputFormat->m_a_size)
|
||||
if (inputFormat->m_r_size == outputFormat->m_r_size && inputFormat->m_g_size == outputFormat->m_g_size
|
||||
&& inputFormat->m_b_size == outputFormat->m_b_size && inputFormat->m_a_size == outputFormat->m_a_size)
|
||||
{
|
||||
ReorderUnsignedToUnsigned();
|
||||
}
|
||||
@@ -202,10 +204,10 @@ void TextureConverter::ConvertUnsignedToUnsigned()
|
||||
// Unsupported as of now
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> TextureConverter::Convert()
|
||||
{
|
||||
std::unique_ptr<Texture> TextureConverter::Convert()
|
||||
{
|
||||
CreateOutputTexture();
|
||||
|
||||
if (m_input_format->GetType() == ImageFormatType::UNSIGNED && m_output_format->GetType() == ImageFormatType::UNSIGNED)
|
||||
@@ -219,4 +221,5 @@ std::unique_ptr<Texture> TextureConverter::Convert()
|
||||
}
|
||||
|
||||
return std::move(m_output_texture);
|
||||
}
|
||||
}
|
||||
} // namespace image
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class TextureConverter
|
||||
namespace image
|
||||
{
|
||||
public:
|
||||
class TextureConverter
|
||||
{
|
||||
public:
|
||||
TextureConverter(const Texture* inputTexture, const ImageFormat* targetFormat);
|
||||
|
||||
std::unique_ptr<Texture> Convert();
|
||||
|
||||
private:
|
||||
private:
|
||||
static constexpr uint64_t Mask1(unsigned length);
|
||||
void SetPixelFunctions(unsigned inBitCount, unsigned outBitCount);
|
||||
|
||||
@@ -28,4 +30,5 @@ private:
|
||||
std::unique_ptr<Texture> m_output_texture;
|
||||
const ImageFormat* m_input_format;
|
||||
const ImageFormat* m_output_format;
|
||||
};
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace IW3;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -38,7 +39,7 @@ namespace
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
const auto texture = dds::LoadDds(*file.m_stream);
|
||||
const auto texture = image::LoadDds(*file.m_stream);
|
||||
if (!texture)
|
||||
{
|
||||
con::error("Failed to load dds file for image asset \"{}\"", assetName);
|
||||
@@ -91,11 +92,11 @@ namespace
|
||||
loadDef->levelCount = static_cast<char>(mipCount);
|
||||
loadDef->flags = 0;
|
||||
if (!texture->HasMipMaps())
|
||||
loadDef->flags |= iwi6::IMG_FLAG_NOMIPMAPS;
|
||||
loadDef->flags |= image::iwi6::IMG_FLAG_NOMIPMAPS;
|
||||
if (texture->GetTextureType() == TextureType::T_CUBE)
|
||||
loadDef->flags |= iwi6::IMG_FLAG_CUBEMAP;
|
||||
loadDef->flags |= image::iwi6::IMG_FLAG_CUBEMAP;
|
||||
if (texture->GetTextureType() == TextureType::T_3D)
|
||||
loadDef->flags |= iwi6::IMG_FLAG_VOLMAP;
|
||||
loadDef->flags |= image::iwi6::IMG_FLAG_VOLMAP;
|
||||
loadDef->dimensions[0] = image->width;
|
||||
loadDef->dimensions[1] = image->height;
|
||||
loadDef->dimensions[2] = image->depth;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace
|
||||
file.m_stream->read(fileData.get(), fileSize);
|
||||
|
||||
std::istringstream ss(std::string(fileData.get(), fileSize));
|
||||
const auto texture = iwi::LoadIwi(ss);
|
||||
const auto texture = image::LoadIwi(ss);
|
||||
if (!texture)
|
||||
{
|
||||
con::error("Failed to load texture from: {}", fileName);
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace
|
||||
const auto dataHash = static_cast<unsigned>(crc32(0u, reinterpret_cast<const Bytef*>(fileData.get()), static_cast<unsigned>(fileSize)));
|
||||
|
||||
std::istringstream ss(std::string(fileData.get(), fileSize));
|
||||
const auto texture = iwi::LoadIwi(ss);
|
||||
const auto texture = image::LoadIwi(ss);
|
||||
if (!texture)
|
||||
{
|
||||
con::error("Failed to load texture from: {}", fileName);
|
||||
|
||||
15
src/ObjLoading/Image/ImageLoaderCommon.cpp
Normal file
15
src/ObjLoading/Image/ImageLoaderCommon.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "ImageLoaderCommon.h"
|
||||
|
||||
namespace image
|
||||
{
|
||||
std::optional<AssetCreationResult> CommonImageLoaderResult::GetResultIfCancelled() const
|
||||
{
|
||||
if (m_failure)
|
||||
return AssetCreationResult::Failure();
|
||||
|
||||
if (!m_texture)
|
||||
return AssetCreationResult::NoAction();
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace image
|
||||
23
src/ObjLoading/Image/ImageLoaderCommon.h
Normal file
23
src/ObjLoading/Image/ImageLoaderCommon.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreationResult.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "Image/Texture.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace image
|
||||
{
|
||||
struct CommonImageLoaderResult
|
||||
{
|
||||
std::optional<AssetCreationResult> GetResultIfCancelled() const;
|
||||
|
||||
bool m_failure;
|
||||
std::string m_iwi_path;
|
||||
std::unique_ptr<Texture> m_texture;
|
||||
};
|
||||
|
||||
CommonImageLoaderResult LoadImageCommon();
|
||||
} // namespace image
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <format>
|
||||
|
||||
using namespace IW3;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -26,15 +27,15 @@ namespace
|
||||
const auto& loadDef = *image.texture.loadDef;
|
||||
textureLoader.Width(loadDef.dimensions[0]).Height(loadDef.dimensions[1]).Depth(loadDef.dimensions[2]);
|
||||
|
||||
if (loadDef.flags & iwi6::IMG_FLAG_VOLMAP)
|
||||
if (loadDef.flags & image::iwi6::IMG_FLAG_VOLMAP)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if (loadDef.flags & iwi6::IMG_FLAG_CUBEMAP)
|
||||
else if (loadDef.flags & image::iwi6::IMG_FLAG_CUBEMAP)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef.format));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & iwi6::IMG_FLAG_NOMIPMAPS));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & image::iwi6::IMG_FLAG_NOMIPMAPS));
|
||||
return textureLoader.LoadTexture(loadDef.data);
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ namespace
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return iwi::LoadIwi(*filePathImage.m_stream);
|
||||
return image::LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/IImageWriter.h"
|
||||
#include "Image/ImageWriter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace image
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::AssetImage::Type>& asset) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IImageWriter> m_writer;
|
||||
std::unique_ptr<ImageWriter> m_writer;
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <format>
|
||||
|
||||
using namespace IW4;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -23,15 +24,15 @@ namespace
|
||||
const auto& loadDef = *image.texture.loadDef;
|
||||
textureLoader.Width(image.width).Height(image.height).Depth(image.depth);
|
||||
|
||||
if ((loadDef.flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_3D)
|
||||
if ((loadDef.flags & image::iwi8::IMG_FLAG_MAPTYPE_MASK) == image::iwi8::IMG_FLAG_MAPTYPE_3D)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if ((loadDef.flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_CUBE)
|
||||
else if ((loadDef.flags & image::iwi8::IMG_FLAG_MAPTYPE_MASK) == image::iwi8::IMG_FLAG_MAPTYPE_CUBE)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef.format));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & iwi8::IMG_FLAG_NOMIPMAPS));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & image::iwi8::IMG_FLAG_NOMIPMAPS));
|
||||
return textureLoader.LoadTexture(loadDef.data);
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return iwi::LoadIwi(*filePathImage.m_stream);
|
||||
return image::LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Image/IImageWriter.h"
|
||||
#include "Image/ImageWriter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace image
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW4::AssetImage::Type>& asset) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IImageWriter> m_writer;
|
||||
std::unique_ptr<ImageWriter> m_writer;
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <format>
|
||||
|
||||
using namespace IW5;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -24,15 +25,15 @@ namespace
|
||||
|
||||
textureLoader.Width(image.width).Height(image.height).Depth(image.depth);
|
||||
|
||||
if ((loadDef.flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_3D)
|
||||
if ((loadDef.flags & image::iwi8::IMG_FLAG_MAPTYPE_MASK) == image::iwi8::IMG_FLAG_MAPTYPE_3D)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if ((loadDef.flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_CUBE)
|
||||
else if ((loadDef.flags & image::iwi8::IMG_FLAG_MAPTYPE_MASK) == image::iwi8::IMG_FLAG_MAPTYPE_CUBE)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef.format));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & iwi8::IMG_FLAG_NOMIPMAPS));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & image::iwi8::IMG_FLAG_NOMIPMAPS));
|
||||
return textureLoader.LoadTexture(loadDef.data);
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ namespace
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return iwi::LoadIwi(*filePathImage.m_stream);
|
||||
return image::LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Image/IImageWriter.h"
|
||||
#include "Image/ImageWriter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace image
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW5::AssetImage::Type>& asset) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IImageWriter> m_writer;
|
||||
std::unique_ptr<ImageWriter> m_writer;
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <format>
|
||||
|
||||
using namespace T5;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -23,15 +24,15 @@ namespace
|
||||
const auto& loadDef = *image.texture.loadDef;
|
||||
textureLoader.Width(image.width).Height(image.height).Depth(image.depth);
|
||||
|
||||
if (loadDef.flags & iwi13::IMG_FLAG_VOLMAP)
|
||||
if (loadDef.flags & image::iwi13::IMG_FLAG_VOLMAP)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if (loadDef.flags & iwi13::IMG_FLAG_CUBEMAP)
|
||||
else if (loadDef.flags & image::iwi13::IMG_FLAG_CUBEMAP)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef.format));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & iwi13::IMG_FLAG_NOMIPMAPS));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & image::iwi13::IMG_FLAG_NOMIPMAPS));
|
||||
return textureLoader.LoadTexture(loadDef.data);
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return iwi::LoadIwi(*filePathImage.m_stream);
|
||||
return image::LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Image/IImageWriter.h"
|
||||
#include "Image/ImageWriter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace image
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T5::AssetImage::Type>& asset) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IImageWriter> m_writer;
|
||||
std::unique_ptr<ImageWriter> m_writer;
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <format>
|
||||
|
||||
using namespace T6;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -24,15 +25,15 @@ namespace
|
||||
const auto& loadDef = *image.texture.loadDef;
|
||||
textureLoader.Width(image.width).Height(image.height).Depth(image.depth);
|
||||
|
||||
if (loadDef.flags & iwi27::IMG_FLAG_VOLMAP)
|
||||
if (loadDef.flags & image::iwi27::IMG_FLAG_VOLMAP)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if (loadDef.flags & iwi27::IMG_FLAG_CUBEMAP)
|
||||
else if (loadDef.flags & image::iwi27::IMG_FLAG_CUBEMAP)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::DXGI_FORMAT>(loadDef.format));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & iwi27::IMG_FLAG_NOMIPMAPS));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & image::iwi27::IMG_FLAG_NOMIPMAPS));
|
||||
return textureLoader.LoadTexture(loadDef.data);
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ namespace
|
||||
|
||||
if (ipakStream)
|
||||
{
|
||||
auto loadedTexture = iwi::LoadIwi(*ipakStream);
|
||||
auto loadedTexture = image::LoadIwi(*ipakStream);
|
||||
ipakStream->close();
|
||||
|
||||
if (loadedTexture != nullptr)
|
||||
@@ -63,7 +64,7 @@ namespace
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return iwi::LoadIwi(*filePathImage.m_stream);
|
||||
return image::LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Image/IImageWriter.h"
|
||||
#include "Image/ImageWriter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace image
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T6::AssetImage::Type>& asset) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IImageWriter> m_writer;
|
||||
std::unique_ptr<ImageWriter> m_writer;
|
||||
};
|
||||
} // namespace image
|
||||
|
||||
Reference in New Issue
Block a user