mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
Dump images from GfxImageLoadDef
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
#include "ObjLoaderIW3.h"
|
||||
|
||||
#include "Game/IW3/GameIW3.h"
|
||||
#include "Game/IW3/GameAssetPoolIW3.h"
|
||||
#include "ObjContainer/IPak/IPak.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "AssetLoaders/AssetLoaderRawFile.h"
|
||||
#include "AssetLoading/AssetLoadingManager.h"
|
||||
#include "Image/Dx9TextureLoader.h"
|
||||
#include "Image/Texture.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
@ -74,7 +77,31 @@ void ObjLoader::UnloadContainersOfZone(Zone* zone) const
|
||||
|
||||
void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
|
||||
{
|
||||
// TODO: Load Texture from LoadDef here
|
||||
const auto* loadDef = image->texture.loadDef;
|
||||
Dx9TextureLoader textureLoader(zone->GetMemory());
|
||||
|
||||
textureLoader.Width(loadDef->dimensions[0]).Height(loadDef->dimensions[1]).Depth(loadDef->dimensions[2]);
|
||||
|
||||
if (loadDef->flags & iwi6::IMG_FLAG_VOLMAP)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if (loadDef->flags & iwi6::IMG_FLAG_CUBEMAP)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<D3DFORMAT>(loadDef->format));
|
||||
textureLoader.HasMipMaps(!(loadDef->flags & iwi6::IMG_FLAG_NOMIPMAPS));
|
||||
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);
|
||||
|
||||
if (loadedTexture != nullptr)
|
||||
{
|
||||
image->texture.texture = loadedTexture;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
|
||||
const auto textureMipCount = loadedTexture->GetMipMapCount();
|
||||
for (auto mipLevel = 0; mipLevel < textureMipCount; mipLevel++)
|
||||
image->cardMemory.platform[0] += static_cast<int>(loadedTexture->GetSizeOfMipLevel(mipLevel) * loadedTexture->GetFaceCount());
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* zone)
|
||||
@ -145,7 +172,7 @@ void ObjLoader::LoadObjDataForZone(ISearchPath* searchPath, Zone* zone) const
|
||||
LoadImageData(searchPath, zone);
|
||||
}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext* context, asset_type_t assetType, const std::string& assetName) const
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext* context, const asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, *context);
|
||||
return assetLoadingManager.LoadAssetFromLoader(assetType, assetName);
|
||||
|
@ -1,12 +1,15 @@
|
||||
#include "ObjLoaderIW4.h"
|
||||
|
||||
#include "Game/IW4/GameIW4.h"
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
#include "ObjContainer/IPak/IPak.h"
|
||||
#include "ObjLoading.h"
|
||||
#include "AssetLoaders/AssetLoaderRawFile.h"
|
||||
#include "AssetLoading/AssetLoadingManager.h"
|
||||
#include "Image/Dx9TextureLoader.h"
|
||||
#include "Image/Texture.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
@ -84,7 +87,31 @@ void ObjLoader::UnloadContainersOfZone(Zone* zone) const
|
||||
|
||||
void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
|
||||
{
|
||||
// TODO: Load Texture from LoadDef here
|
||||
const auto* loadDef = image->texture.loadDef;
|
||||
Dx9TextureLoader textureLoader(zone->GetMemory());
|
||||
|
||||
textureLoader.Width(image->width).Height(image->height).Depth(image->depth);
|
||||
|
||||
if ((loadDef->flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_3D)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if ((loadDef->flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_CUBE)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<D3DFORMAT>(loadDef->format));
|
||||
textureLoader.HasMipMaps(!(loadDef->flags & iwi8::IMG_FLAG_NOMIPMAPS));
|
||||
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);
|
||||
|
||||
if (loadedTexture != nullptr)
|
||||
{
|
||||
image->texture.texture = loadedTexture;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
|
||||
const auto textureMipCount = loadedTexture->GetMipMapCount();
|
||||
for (auto mipLevel = 0; mipLevel < textureMipCount; mipLevel++)
|
||||
image->cardMemory.platform[0] += static_cast<int>(loadedTexture->GetSizeOfMipLevel(mipLevel) * loadedTexture->GetFaceCount());
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* zone)
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "Image/Texture.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Image/Dx12TextureLoader.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
@ -329,7 +331,31 @@ namespace T6
|
||||
|
||||
void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
|
||||
{
|
||||
// TODO: Load Texture from LoadDef here
|
||||
const auto* loadDef = image->texture.loadDef;
|
||||
Dx12TextureLoader textureLoader(zone->GetMemory());
|
||||
|
||||
textureLoader.Width(image->width).Height(image->height).Depth(image->depth);
|
||||
|
||||
if (loadDef->flags & iwi27::IMG_FLAG_VOLMAP)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if (loadDef->flags & iwi27::IMG_FLAG_CUBEMAP)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<DXGI_FORMAT>(loadDef->format));
|
||||
textureLoader.HasMipMaps(!(loadDef->flags & iwi27::IMG_FLAG_NOMIPMAPS));
|
||||
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);
|
||||
|
||||
if (loadedTexture != nullptr)
|
||||
{
|
||||
image->texture.texture = loadedTexture;
|
||||
image->loadedSize = 0;
|
||||
|
||||
const auto textureMipCount = loadedTexture->GetMipMapCount();
|
||||
for (auto mipLevel = 0; mipLevel < textureMipCount; mipLevel++)
|
||||
image->loadedSize += static_cast<int>(loadedTexture->GetSizeOfMipLevel(mipLevel) * loadedTexture->GetFaceCount());
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* zone)
|
||||
|
103
src/ObjLoading/Image/Dx12TextureLoader.cpp
Normal file
103
src/ObjLoading/Image/Dx12TextureLoader.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#include "Dx12TextureLoader.h"
|
||||
|
||||
Dx12TextureLoader::Dx12TextureLoader(MemoryManager* memoryManager)
|
||||
: m_memory_manager(memoryManager),
|
||||
m_format(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
|
||||
{
|
||||
for (auto i : ImageFormat::ALL_FORMATS)
|
||||
{
|
||||
if (i->GetDxgiFormat() == m_format)
|
||||
return i;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Format(const DXGI_FORMAT format)
|
||||
{
|
||||
m_format = format;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Type(const TextureType textureType)
|
||||
{
|
||||
m_type = textureType;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::HasMipMaps(const bool hasMipMaps)
|
||||
{
|
||||
m_has_mip_maps = hasMipMaps;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Width(const size_t width)
|
||||
{
|
||||
m_width = width;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Height(const size_t height)
|
||||
{
|
||||
m_height = height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dx12TextureLoader& Dx12TextureLoader::Depth(const size_t depth)
|
||||
{
|
||||
m_depth = depth;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Texture* Dx12TextureLoader::LoadTexture(const void* data)
|
||||
{
|
||||
const auto* format = GetFormatForDx12Format();
|
||||
|
||||
if (format == nullptr)
|
||||
return nullptr;
|
||||
|
||||
Texture* texture;
|
||||
switch (m_type)
|
||||
{
|
||||
case TextureType::T_2D:
|
||||
texture = m_memory_manager->Create<Texture2D>(format, m_width, m_height, m_has_mip_maps);
|
||||
break;
|
||||
|
||||
case TextureType::T_3D:
|
||||
texture = m_memory_manager->Create<Texture3D>(format, m_width, m_height, m_depth, m_has_mip_maps);
|
||||
break;
|
||||
|
||||
case TextureType::T_CUBE:
|
||||
texture = m_memory_manager->Create<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;
|
||||
const void* currentDataOffset = data;
|
||||
|
||||
for (auto currentMipLevel = 0; currentMipLevel < mipMapCount; currentMipLevel++)
|
||||
{
|
||||
for (auto currentFace = 0; currentFace < faceCount; currentFace++)
|
||||
{
|
||||
const auto mipSize = texture->GetSizeOfMipLevel(currentMipLevel);
|
||||
memcpy(texture->GetBufferForMipLevel(currentMipLevel, currentFace), currentDataOffset, mipSize);
|
||||
currentDataOffset = reinterpret_cast<const void*>(reinterpret_cast<uintptr_t>(currentDataOffset) + mipSize);
|
||||
}
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
35
src/ObjLoading/Image/Dx12TextureLoader.h
Normal file
35
src/ObjLoading/Image/Dx12TextureLoader.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Image/DxgiFormat.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
#include "Image/Texture.h"
|
||||
|
||||
class Dx12TextureLoader
|
||||
{
|
||||
static std::unordered_map<ImageFormatId, ImageFormatId> m_conversion_table;
|
||||
|
||||
MemoryManager* m_memory_manager;
|
||||
DXGI_FORMAT m_format;
|
||||
TextureType m_type;
|
||||
bool m_has_mip_maps;
|
||||
size_t m_width;
|
||||
size_t m_height;
|
||||
size_t m_depth;
|
||||
|
||||
_NODISCARD const ImageFormat* GetFormatForDx12Format() const;
|
||||
|
||||
public:
|
||||
explicit Dx12TextureLoader(MemoryManager* memoryManager);
|
||||
|
||||
Dx12TextureLoader& Format(DXGI_FORMAT format);
|
||||
Dx12TextureLoader& Type(TextureType textureType);
|
||||
Dx12TextureLoader& HasMipMaps(bool hasMipMaps);
|
||||
Dx12TextureLoader& Width(size_t width);
|
||||
Dx12TextureLoader& Height(size_t height);
|
||||
Dx12TextureLoader& Depth(size_t depth);
|
||||
|
||||
Texture* LoadTexture(const void* data);
|
||||
};
|
103
src/ObjLoading/Image/Dx9TextureLoader.cpp
Normal file
103
src/ObjLoading/Image/Dx9TextureLoader.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
#include "Dx9TextureLoader.h"
|
||||
|
||||
Dx9TextureLoader::Dx9TextureLoader(MemoryManager* memoryManager)
|
||||
: m_memory_manager(memoryManager),
|
||||
m_format(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
|
||||
{
|
||||
for (auto i : ImageFormat::ALL_FORMATS)
|
||||
{
|
||||
if (i->GetD3DFormat() == m_format)
|
||||
return i;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Format(const 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::Width(const size_t width)
|
||||
{
|
||||
m_width = width;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Height(const size_t height)
|
||||
{
|
||||
m_height = height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dx9TextureLoader& Dx9TextureLoader::Depth(const size_t depth)
|
||||
{
|
||||
m_depth = depth;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Texture* Dx9TextureLoader::LoadTexture(const void* data)
|
||||
{
|
||||
const auto* format = GetFormatForDx9Format();
|
||||
|
||||
if (format == nullptr)
|
||||
return nullptr;
|
||||
|
||||
Texture* texture;
|
||||
switch (m_type)
|
||||
{
|
||||
case TextureType::T_2D:
|
||||
texture = m_memory_manager->Create<Texture2D>(format, m_width, m_height, m_has_mip_maps);
|
||||
break;
|
||||
|
||||
case TextureType::T_3D:
|
||||
texture = m_memory_manager->Create<Texture3D>(format, m_width, m_height, m_depth, m_has_mip_maps);
|
||||
break;
|
||||
|
||||
case TextureType::T_CUBE:
|
||||
texture = m_memory_manager->Create<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;
|
||||
const void* currentDataOffset = data;
|
||||
|
||||
for (auto currentMipLevel = 0; currentMipLevel < mipMapCount; currentMipLevel++)
|
||||
{
|
||||
for (auto currentFace = 0; currentFace < faceCount; currentFace++)
|
||||
{
|
||||
const auto mipSize = texture->GetSizeOfMipLevel(currentMipLevel);
|
||||
memcpy(texture->GetBufferForMipLevel(currentMipLevel, currentFace), currentDataOffset, mipSize);
|
||||
currentDataOffset = reinterpret_cast<const void*>(reinterpret_cast<uintptr_t>(currentDataOffset) + mipSize);
|
||||
}
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
33
src/ObjLoading/Image/Dx9TextureLoader.h
Normal file
33
src/ObjLoading/Image/Dx9TextureLoader.h
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Image/D3DFormat.h"
|
||||
#include "Utils/MemoryManager.h"
|
||||
#include "Image/Texture.h"
|
||||
|
||||
class Dx9TextureLoader
|
||||
{
|
||||
MemoryManager* m_memory_manager;
|
||||
D3DFORMAT m_format;
|
||||
TextureType m_type;
|
||||
bool m_has_mip_maps;
|
||||
size_t m_width;
|
||||
size_t m_height;
|
||||
size_t m_depth;
|
||||
|
||||
_NODISCARD const ImageFormat* GetFormatForDx9Format() const;
|
||||
|
||||
public:
|
||||
explicit Dx9TextureLoader(MemoryManager* memoryManager);
|
||||
|
||||
Dx9TextureLoader& Format(D3DFORMAT format);
|
||||
Dx9TextureLoader& Type(TextureType textureType);
|
||||
Dx9TextureLoader& HasMipMaps(bool hasMipMaps);
|
||||
Dx9TextureLoader& Width(size_t width);
|
||||
Dx9TextureLoader& Height(size_t height);
|
||||
Dx9TextureLoader& Depth(size_t depth);
|
||||
|
||||
Texture* LoadTexture(const void* data);
|
||||
};
|
Reference in New Issue
Block a user