From 472e59991fa2423f977e03c8d7d3f81535033107 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Mon, 4 Aug 2025 21:36:47 +0200 Subject: [PATCH] refactor: streamline shader dumping --- src/ObjWriting/Game/IW4/ObjWriterIW4.cpp | 8 +++--- .../IW4/Shader/AssetDumperPixelShader.cpp | 26 ------------------- .../IW4/Shader/AssetDumperVertexShader.cpp | 26 ------------------- .../Game/IW4/Shader/PixelShaderDumperIW4.cpp | 26 +++++++++++++++++++ ...erPixelShader.h => PixelShaderDumperIW4.h} | 6 ++--- .../Game/IW4/Shader/VertexShaderDumperIW4.cpp | 26 +++++++++++++++++++ ...VertexShader.h => VertexShaderDumperIW4.h} | 6 ++--- 7 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 src/ObjWriting/Game/IW4/Shader/AssetDumperPixelShader.cpp delete mode 100644 src/ObjWriting/Game/IW4/Shader/AssetDumperVertexShader.cpp create mode 100644 src/ObjWriting/Game/IW4/Shader/PixelShaderDumperIW4.cpp rename src/ObjWriting/Game/IW4/Shader/{AssetDumperPixelShader.h => PixelShaderDumperIW4.h} (68%) create mode 100644 src/ObjWriting/Game/IW4/Shader/VertexShaderDumperIW4.cpp rename src/ObjWriting/Game/IW4/Shader/{AssetDumperVertexShader.h => VertexShaderDumperIW4.h} (68%) diff --git a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp index fbfca499..75d93683 100644 --- a/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp +++ b/src/ObjWriting/Game/IW4/ObjWriterIW4.cpp @@ -15,8 +15,8 @@ #include "PhysCollmap/PhysCollmapDumperIW4.h" #include "PhysPreset/PhysPresetInfoStringDumperIW4.h" #include "RawFile/RawFileDumperIW4.h" -#include "Shader/AssetDumperPixelShader.h" -#include "Shader/AssetDumperVertexShader.h" +#include "Shader/PixelShaderDumperIW4.h" +#include "Shader/VertexShaderDumperIW4.h" #include "Sound/LoadedSoundDumperIW4.h" #include "Sound/SndCurveDumperIW4.h" #include "StringTable/StringTableDumperIW4.h" @@ -47,8 +47,8 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const #ifdef EXPERIMENTAL_MATERIAL_COMPILATION DUMP_ASSET_POOL(material::DecompilingGdtDumper, m_material, ASSET_TYPE_MATERIAL) #endif - DUMP_ASSET_POOL(AssetDumperPixelShader, m_material_pixel_shader, ASSET_TYPE_PIXELSHADER) - DUMP_ASSET_POOL(AssetDumperVertexShader, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER) + DUMP_ASSET_POOL(shader::PixelShaderDumper, m_material_pixel_shader, ASSET_TYPE_PIXELSHADER) + DUMP_ASSET_POOL(shader::VertexShaderDumper, m_material_vertex_shader, ASSET_TYPE_VERTEXSHADER) 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(AssetDumpersnd_alias_list_t, m_sound, ASSET_TYPE_SOUND) diff --git a/src/ObjWriting/Game/IW4/Shader/AssetDumperPixelShader.cpp b/src/ObjWriting/Game/IW4/Shader/AssetDumperPixelShader.cpp deleted file mode 100644 index 40bb4089..00000000 --- a/src/ObjWriting/Game/IW4/Shader/AssetDumperPixelShader.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "AssetDumperPixelShader.h" - -#include - -using namespace IW4; - -bool AssetDumperPixelShader::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperPixelShader::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto* pixelShader = asset->Asset(); - - std::ostringstream ss; - ss << "shader_bin/ps_" << pixelShader->name << ".cso"; - - const auto shaderFile = context.OpenAssetFile(ss.str()); - - if (!shaderFile) - return; - - shaderFile->write(reinterpret_cast(pixelShader->prog.loadDef.program), - static_cast(pixelShader->prog.loadDef.programSize) * 4u); -} diff --git a/src/ObjWriting/Game/IW4/Shader/AssetDumperVertexShader.cpp b/src/ObjWriting/Game/IW4/Shader/AssetDumperVertexShader.cpp deleted file mode 100644 index 6bc12d7a..00000000 --- a/src/ObjWriting/Game/IW4/Shader/AssetDumperVertexShader.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "AssetDumperVertexShader.h" - -#include - -using namespace IW4; - -bool AssetDumperVertexShader::ShouldDump(XAssetInfo* asset) -{ - return true; -} - -void AssetDumperVertexShader::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) -{ - const auto* vertexShader = asset->Asset(); - - std::ostringstream ss; - ss << "shader_bin/vs_" << vertexShader->name << ".cso"; - - const auto shaderFile = context.OpenAssetFile(ss.str()); - - if (!shaderFile) - return; - - shaderFile->write(reinterpret_cast(vertexShader->prog.loadDef.program), - static_cast(vertexShader->prog.loadDef.programSize) * 4u); -} diff --git a/src/ObjWriting/Game/IW4/Shader/PixelShaderDumperIW4.cpp b/src/ObjWriting/Game/IW4/Shader/PixelShaderDumperIW4.cpp new file mode 100644 index 00000000..bbd382fa --- /dev/null +++ b/src/ObjWriting/Game/IW4/Shader/PixelShaderDumperIW4.cpp @@ -0,0 +1,26 @@ +#include "PixelShaderDumperIW4.h" + +#include "Shader/ShaderCommon.h" + +using namespace IW4; +using namespace ::shader; + +namespace IW4::shader +{ + bool PixelShaderDumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void PixelShaderDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto* pixelShader = asset->Asset(); + const auto shaderFile = context.OpenAssetFile(GetFileNameForPixelShaderAssetName(asset->m_name)); + + if (!shaderFile) + return; + + shaderFile->write(reinterpret_cast(pixelShader->prog.loadDef.program), + static_cast(pixelShader->prog.loadDef.programSize) * 4u); + } +} // namespace IW4::shader diff --git a/src/ObjWriting/Game/IW4/Shader/AssetDumperPixelShader.h b/src/ObjWriting/Game/IW4/Shader/PixelShaderDumperIW4.h similarity index 68% rename from src/ObjWriting/Game/IW4/Shader/AssetDumperPixelShader.h rename to src/ObjWriting/Game/IW4/Shader/PixelShaderDumperIW4.h index 925e80f9..875576ca 100644 --- a/src/ObjWriting/Game/IW4/Shader/AssetDumperPixelShader.h +++ b/src/ObjWriting/Game/IW4/Shader/PixelShaderDumperIW4.h @@ -3,12 +3,12 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/IW4/IW4.h" -namespace IW4 +namespace IW4::shader { - class AssetDumperPixelShader final : public AbstractAssetDumper + class PixelShaderDumper final : public AbstractAssetDumper { protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace IW4 +} // namespace IW4::shader diff --git a/src/ObjWriting/Game/IW4/Shader/VertexShaderDumperIW4.cpp b/src/ObjWriting/Game/IW4/Shader/VertexShaderDumperIW4.cpp new file mode 100644 index 00000000..3dacbc04 --- /dev/null +++ b/src/ObjWriting/Game/IW4/Shader/VertexShaderDumperIW4.cpp @@ -0,0 +1,26 @@ +#include "VertexShaderDumperIW4.h" + +#include "Shader/ShaderCommon.h" + +using namespace IW4; +using namespace ::shader; + +namespace IW4::shader +{ + bool VertexShaderDumper::ShouldDump(XAssetInfo* asset) + { + return true; + } + + void VertexShaderDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) + { + const auto* vertexShader = asset->Asset(); + const auto shaderFile = context.OpenAssetFile(GetFileNameForVertexShaderAssetName(asset->m_name)); + + if (!shaderFile) + return; + + shaderFile->write(reinterpret_cast(vertexShader->prog.loadDef.program), + static_cast(vertexShader->prog.loadDef.programSize) * 4u); + } +} // namespace IW4::shader diff --git a/src/ObjWriting/Game/IW4/Shader/AssetDumperVertexShader.h b/src/ObjWriting/Game/IW4/Shader/VertexShaderDumperIW4.h similarity index 68% rename from src/ObjWriting/Game/IW4/Shader/AssetDumperVertexShader.h rename to src/ObjWriting/Game/IW4/Shader/VertexShaderDumperIW4.h index a9d631ef..6f24fce7 100644 --- a/src/ObjWriting/Game/IW4/Shader/AssetDumperVertexShader.h +++ b/src/ObjWriting/Game/IW4/Shader/VertexShaderDumperIW4.h @@ -3,12 +3,12 @@ #include "Dumping/AbstractAssetDumper.h" #include "Game/IW4/IW4.h" -namespace IW4 +namespace IW4::shader { - class AssetDumperVertexShader final : public AbstractAssetDumper + class VertexShaderDumper final : public AbstractAssetDumper { protected: bool ShouldDump(XAssetInfo* asset) override; void DumpAsset(AssetDumpingContext& context, XAssetInfo* asset) override; }; -} // namespace IW4 +} // namespace IW4::shader