mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-01 14:37:25 +00:00
refactor: streamline techset dumper
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#include "Sound/AssetDumperSndBank.h"
|
||||
#include "Sound/AssetDumperSndDriverGlobals.h"
|
||||
#include "StringTable/StringTableDumperT6.h"
|
||||
#include "Techset/AssetDumperTechniqueSet.h"
|
||||
#include "Techset/TechsetDumperT6.h"
|
||||
#include "Tracer/AssetDumperTracer.h"
|
||||
#include "Vehicle/AssetDumperVehicle.h"
|
||||
#include "Weapon/AssetDumperWeapon.h"
|
||||
@@ -52,7 +52,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
|
||||
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL)
|
||||
DUMP_ASSET_POOL(material::JsonDumper, m_material, ASSET_TYPE_MATERIAL)
|
||||
DUMP_ASSET_POOL(AssetDumperTechniqueSet, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
|
||||
DUMP_ASSET_POOL(techset::Dumper, m_technique_set, ASSET_TYPE_TECHNIQUE_SET)
|
||||
DUMP_ASSET_POOL(image::Dumper, m_image, ASSET_TYPE_IMAGE)
|
||||
DUMP_ASSET_POOL(AssetDumperSndBank, m_sound_bank, ASSET_TYPE_SOUND)
|
||||
// DUMP_ASSET_POOL(AssetDumperSndPatch, m_sound_patch, ASSET_TYPE_SOUND_PATCH)
|
||||
|
@@ -1,106 +0,0 @@
|
||||
#include "AssetDumperTechniqueSet.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
class ShaderZoneState final : public IZoneAssetDumperState
|
||||
{
|
||||
public:
|
||||
bool ShouldDumpTechnique(const MaterialTechnique* technique)
|
||||
{
|
||||
const auto existingTechnique = m_dumped_techniques.find(technique);
|
||||
if (existingTechnique == m_dumped_techniques.end())
|
||||
{
|
||||
m_dumped_techniques.emplace(technique);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ShouldDumpPixelShader(const MaterialPixelShader* pixelShader)
|
||||
{
|
||||
const auto existingPixelShader = m_dumped_pixel_shaders.find(pixelShader);
|
||||
if (existingPixelShader == m_dumped_pixel_shaders.end())
|
||||
{
|
||||
m_dumped_pixel_shaders.emplace(pixelShader);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ShouldDumpVertexShader(const MaterialVertexShader* vertexShader)
|
||||
{
|
||||
const auto existingVertexShader = m_dumped_vertex_shaders.find(vertexShader);
|
||||
if (existingVertexShader == m_dumped_vertex_shaders.end())
|
||||
{
|
||||
m_dumped_vertex_shaders.emplace(vertexShader);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_set<const MaterialTechnique*> m_dumped_techniques;
|
||||
std::unordered_set<const MaterialPixelShader*> m_dumped_pixel_shaders;
|
||||
std::unordered_set<const MaterialVertexShader*> m_dumped_vertex_shaders;
|
||||
};
|
||||
|
||||
bool AssetDumperTechniqueSet::ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperTechniqueSet::DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader* pixelShader)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "shader_bin/ps_" << pixelShader->name << ".cso";
|
||||
|
||||
const auto shaderFile = context.OpenAssetFile(ss.str());
|
||||
|
||||
if (!shaderFile)
|
||||
return;
|
||||
|
||||
shaderFile->write(pixelShader->prog.loadDef.program, pixelShader->prog.loadDef.programSize);
|
||||
}
|
||||
|
||||
void AssetDumperTechniqueSet::DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader* vertexShader)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "shader_bin/vs_" << vertexShader->name << ".cso";
|
||||
|
||||
const auto shaderFile = context.OpenAssetFile(ss.str());
|
||||
|
||||
if (!shaderFile)
|
||||
return;
|
||||
|
||||
shaderFile->write(vertexShader->prog.loadDef.program, vertexShader->prog.loadDef.programSize);
|
||||
}
|
||||
|
||||
void AssetDumperTechniqueSet::DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset)
|
||||
{
|
||||
const auto* techniqueSet = asset->Asset();
|
||||
auto* shaderState = context.GetZoneAssetDumperState<ShaderZoneState>();
|
||||
|
||||
for (const auto* technique : techniqueSet->techniques)
|
||||
{
|
||||
if (!technique || !shaderState->ShouldDumpTechnique(technique))
|
||||
continue;
|
||||
|
||||
for (auto passIndex = 0u; passIndex < technique->passCount; passIndex++)
|
||||
{
|
||||
const auto* pixelShader = technique->passArray[passIndex].pixelShader;
|
||||
|
||||
if (pixelShader && shaderState->ShouldDumpPixelShader(pixelShader))
|
||||
DumpPixelShader(context, pixelShader);
|
||||
|
||||
const auto* vertexShader = technique->passArray[passIndex].vertexShader;
|
||||
if (vertexShader && shaderState->ShouldDumpVertexShader(vertexShader))
|
||||
DumpVertexShader(context, vertexShader);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class AssetDumperTechniqueSet final : public AbstractAssetDumper<MaterialTechniqueSet>
|
||||
{
|
||||
static void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader* pixelShader);
|
||||
static void DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader* vertexShader);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset) override;
|
||||
};
|
||||
} // namespace T6
|
107
src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp
Normal file
107
src/ObjWriting/Game/T6/Techset/TechsetDumperT6.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "TechsetDumperT6.h"
|
||||
|
||||
#include "Shader/ShaderCommon.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace
|
||||
{
|
||||
class ShaderZoneState final : public IZoneAssetDumperState
|
||||
{
|
||||
public:
|
||||
bool ShouldDumpTechnique(const MaterialTechnique* technique)
|
||||
{
|
||||
const auto existingTechnique = m_dumped_techniques.find(technique);
|
||||
if (existingTechnique == m_dumped_techniques.end())
|
||||
{
|
||||
m_dumped_techniques.emplace(technique);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ShouldDumpPixelShader(const MaterialPixelShader* pixelShader)
|
||||
{
|
||||
const auto existingPixelShader = m_dumped_pixel_shaders.find(pixelShader);
|
||||
if (existingPixelShader == m_dumped_pixel_shaders.end())
|
||||
{
|
||||
m_dumped_pixel_shaders.emplace(pixelShader);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ShouldDumpVertexShader(const MaterialVertexShader* vertexShader)
|
||||
{
|
||||
const auto existingVertexShader = m_dumped_vertex_shaders.find(vertexShader);
|
||||
if (existingVertexShader == m_dumped_vertex_shaders.end())
|
||||
{
|
||||
m_dumped_vertex_shaders.emplace(vertexShader);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_set<const MaterialTechnique*> m_dumped_techniques;
|
||||
std::unordered_set<const MaterialPixelShader*> m_dumped_pixel_shaders;
|
||||
std::unordered_set<const MaterialVertexShader*> m_dumped_vertex_shaders;
|
||||
};
|
||||
|
||||
void DumpPixelShader(const AssetDumpingContext& context, const MaterialPixelShader& pixelShader)
|
||||
{
|
||||
const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForPixelShaderAssetName(pixelShader.name));
|
||||
|
||||
if (!shaderFile)
|
||||
return;
|
||||
|
||||
shaderFile->write(pixelShader.prog.loadDef.program, pixelShader.prog.loadDef.programSize);
|
||||
}
|
||||
|
||||
void DumpVertexShader(const AssetDumpingContext& context, const MaterialVertexShader& vertexShader)
|
||||
{
|
||||
const auto shaderFile = context.OpenAssetFile(shader::GetFileNameForVertexShaderAssetName(vertexShader.name));
|
||||
|
||||
if (!shaderFile)
|
||||
return;
|
||||
|
||||
shaderFile->write(vertexShader.prog.loadDef.program, vertexShader.prog.loadDef.programSize);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace T6::techset
|
||||
{
|
||||
bool Dumper::ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset)
|
||||
{
|
||||
const auto* techniqueSet = asset->Asset();
|
||||
auto* shaderState = context.GetZoneAssetDumperState<ShaderZoneState>();
|
||||
|
||||
for (const auto* technique : techniqueSet->techniques)
|
||||
{
|
||||
if (!technique || !shaderState->ShouldDumpTechnique(technique))
|
||||
continue;
|
||||
|
||||
for (auto passIndex = 0u; passIndex < technique->passCount; passIndex++)
|
||||
{
|
||||
const auto* pixelShader = technique->passArray[passIndex].pixelShader;
|
||||
if (pixelShader && shaderState->ShouldDumpPixelShader(pixelShader))
|
||||
DumpPixelShader(context, *pixelShader);
|
||||
|
||||
const auto* vertexShader = technique->passArray[passIndex].vertexShader;
|
||||
if (vertexShader && shaderState->ShouldDumpVertexShader(vertexShader))
|
||||
DumpVertexShader(context, *vertexShader);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace T6::techset
|
14
src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h
Normal file
14
src/ObjWriting/Game/T6/Techset/TechsetDumperT6.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
|
||||
namespace T6::techset
|
||||
{
|
||||
class Dumper final : public AbstractAssetDumper<MaterialTechniqueSet>
|
||||
{
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<MaterialTechniqueSet>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<MaterialTechniqueSet>* asset) override;
|
||||
};
|
||||
} // namespace T6::techset
|
Reference in New Issue
Block a user