mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-08-19 21:44:26 +00:00
* feat: QOS (007: Quantum of Solace) support * feat: add qos localize loader * feat: add qos stringtable loader * chore: comment about official zones * fix: add qos gfximage runtime fields * chore: remove useless dev time comments * fix: remove all `static_asserts`s from asset headers causing build fail on x64 * chore: change union ordering of qos `entryInternalData` * chore: move qos asset type enum to qos.h * fix: qos and t4 xsurface index buffer * chore: implement qos MaterialInfo struct * chore: adjust some gfxworld struct members * chore: implement qos PhysPreset and PhysConstraints * chore: fix and adjust slight inconsistencies with qos zone code * chore: reorder qos ZoneCode.lua entries in order of asset type enum * chore: remove asset types that are not actual asset types in zones * chore: check common asset arrays with static_assert * chore: rename qos assets * chore: reorder qos in templates to be in alphabetical order * chore: use function for CopyMipLevel in Dx9TextureLoader * chore: use templates for qos MapEntsDumper * chore: add missing braces in XModelToCommonConverter * chore: add generic way to peek at zone data * Qos does not use a classic ZoneHeader so code needs to be more generic * fix: do not use raw_byte and raw_uint typedefs for qos * fix: not being able to write clipmapmp * chore: additional research on qos vertex property and stuff --------- Co-authored-by: Jan Laupetin <[email protected]>
129 lines
3.6 KiB
C++
129 lines
3.6 KiB
C++
#include "Dx9TextureLoader.h"
|
|
|
|
#include <cstring>
|
|
|
|
namespace
|
|
{
|
|
void CopyMipLevel(image::Texture& texture, const int currentMipLevel, const int faceCount, const uint8_t*& currentDataOffset)
|
|
{
|
|
for (auto currentFace = 0; currentFace < faceCount; currentFace++)
|
|
{
|
|
const auto mipSize = texture.GetSizeOfMipLevel(currentMipLevel);
|
|
memcpy(texture.GetBufferForMipLevel(currentMipLevel, currentFace), currentDataOffset, mipSize);
|
|
currentDataOffset += mipSize;
|
|
}
|
|
}
|
|
} // namespace
|
|
|
|
namespace image
|
|
{
|
|
Dx9TextureLoader::Dx9TextureLoader()
|
|
: m_format(oat::D3DFMT_UNKNOWN),
|
|
m_type(TextureType::T_2D),
|
|
m_has_mip_maps(false),
|
|
m_mip_map_order(MipMapDataOrder::LargestToSmallest),
|
|
m_width(1u),
|
|
m_height(1u),
|
|
m_depth(1u)
|
|
{
|
|
}
|
|
|
|
const ImageFormat* Dx9TextureLoader::GetFormatForDx9Format() const
|
|
{
|
|
for (const auto* i : format::ALL)
|
|
{
|
|
if (i->GetD3DFormat() == m_format)
|
|
return i;
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
Dx9TextureLoader& Dx9TextureLoader::Format(const oat::D3DFORMAT format)
|
|
{
|
|
m_format = format;
|
|
return *this;
|
|
}
|
|
|
|
Dx9TextureLoader& Dx9TextureLoader::Type(const TextureType textureType)
|
|
{
|
|
m_type = textureType;
|
|
return *this;
|
|
}
|
|
|
|
Dx9TextureLoader& Dx9TextureLoader::HasMipMaps(const bool hasMipMaps)
|
|
{
|
|
m_has_mip_maps = hasMipMaps;
|
|
return *this;
|
|
}
|
|
|
|
Dx9TextureLoader& Dx9TextureLoader::MipMapOrder(const MipMapDataOrder mipMapOrder)
|
|
{
|
|
m_mip_map_order = mipMapOrder;
|
|
return *this;
|
|
}
|
|
|
|
Dx9TextureLoader& Dx9TextureLoader::Width(const unsigned width)
|
|
{
|
|
m_width = width;
|
|
return *this;
|
|
}
|
|
|
|
Dx9TextureLoader& Dx9TextureLoader::Height(const unsigned height)
|
|
{
|
|
m_height = height;
|
|
return *this;
|
|
}
|
|
|
|
Dx9TextureLoader& Dx9TextureLoader::Depth(const unsigned depth)
|
|
{
|
|
m_depth = depth;
|
|
return *this;
|
|
}
|
|
|
|
std::unique_ptr<Texture> Dx9TextureLoader::LoadTexture(const void* data)
|
|
{
|
|
const auto* format = GetFormatForDx9Format();
|
|
|
|
if (format == nullptr)
|
|
return nullptr;
|
|
|
|
std::unique_ptr<Texture> texture;
|
|
switch (m_type)
|
|
{
|
|
case TextureType::T_2D:
|
|
texture = std::make_unique<Texture2D>(format, m_width, m_height, m_has_mip_maps);
|
|
break;
|
|
|
|
case TextureType::T_3D:
|
|
texture = std::make_unique<Texture3D>(format, m_width, m_height, m_depth, m_has_mip_maps);
|
|
break;
|
|
|
|
case TextureType::T_CUBE:
|
|
texture = std::make_unique<TextureCube>(format, m_width, m_width, m_has_mip_maps);
|
|
break;
|
|
|
|
default:
|
|
return nullptr;
|
|
}
|
|
|
|
texture->Allocate();
|
|
const auto mipMapCount = m_has_mip_maps ? texture->GetMipMapCount() : 1;
|
|
const auto faceCount = m_type == TextureType::T_CUBE ? 6 : 1;
|
|
auto* currentDataOffset = static_cast<const uint8_t*>(data);
|
|
|
|
if (m_mip_map_order == MipMapDataOrder::LargestToSmallest)
|
|
{
|
|
for (auto currentMipLevel = 0; currentMipLevel < mipMapCount; currentMipLevel++)
|
|
CopyMipLevel(*texture, currentMipLevel, faceCount, currentDataOffset);
|
|
}
|
|
else
|
|
{
|
|
for (auto currentMipLevel = mipMapCount - 1; currentMipLevel >= 0; currentMipLevel--)
|
|
CopyMipLevel(*texture, currentMipLevel, faceCount, currentDataOffset);
|
|
}
|
|
|
|
return texture;
|
|
}
|
|
} // namespace image
|