diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp index f3a4d0df..abe15d9d 100644 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp +++ b/src/ObjCompiling/Game/IW4/Techset/CompilerTechsetIW4.cpp @@ -1,8 +1,6 @@ #include "CompilerTechsetIW4.h" #include "Game/IW4/IW4.h" -#include "Game/IW4/Shader/LoaderPixelShaderIW4.h" -#include "Game/IW4/Shader/LoaderVertexShaderIW4.h" #include "Game/IW4/Techset/TechsetConstantsIW4.h" #include "Shader/D3D9ShaderAnalyser.h" #include "Shader/ShaderCommon.h" diff --git a/src/ObjCompiling/Techset/TechniqueCompiler.h.template b/src/ObjCompiling/Techset/TechniqueCompiler.h.template index f858775d..a1bbe9f0 100644 --- a/src/ObjCompiling/Techset/TechniqueCompiler.h.template +++ b/src/ObjCompiling/Techset/TechniqueCompiler.h.template @@ -2,8 +2,6 @@ #filename "Game/" + GAME + "/Techset/TechniqueCompiler" + GAME + ".h" -#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\"" - #if GAME == "IW3" #define FEATURE_IW3 #elif GAME == "IW4" diff --git a/src/ObjCompiling/Techset/TechsetCompiler.h.template b/src/ObjCompiling/Techset/TechsetCompiler.h.template index 4bbdfc78..6e6d8abd 100644 --- a/src/ObjCompiling/Techset/TechsetCompiler.h.template +++ b/src/ObjCompiling/Techset/TechsetCompiler.h.template @@ -2,8 +2,6 @@ #filename "Game/" + GAME + "/Techset/TechsetCompiler" + GAME + ".h" -#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\"" - #if GAME == "IW3" #define FEATURE_IW3 #elif GAME == "IW4" diff --git a/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template b/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template index 313f9ca3..b3a9ba17 100644 --- a/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template +++ b/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template @@ -36,13 +36,13 @@ using namespace GAME; #if defined(IS_SUB_ASSET) #define ABSTRACT_CREATOR_NAME SubAssetCreator -#define OVERRIDEN_CREATOR_METHOD CreateSubAsset +#define OVERRIDDEN_CREATOR_METHOD CreateSubAsset #define ADD_ASSET_METHOD AddSubAsset #define ASSET_NAME SubAssetVertexDecl #define INTERFACE_NAME ISubAssetCreator #else #define ABSTRACT_CREATOR_NAME AssetCreator -#define OVERRIDEN_CREATOR_METHOD CreateAsset +#define OVERRIDDEN_CREATOR_METHOD CreateAsset #define ADD_ASSET_METHOD AddAsset #define ASSET_NAME AssetVertexDecl #define INTERFACE_NAME IAssetCreator @@ -58,7 +58,7 @@ namespace { } - AssetCreationResult OVERRIDEN_CREATOR_METHOD(const std::string& assetName, AssetCreationContext& context) override + AssetCreationResult OVERRIDDEN_CREATOR_METHOD(const std::string& assetName, AssetCreationContext& context) override { const auto commonVertexDecl = techset::CreateVertexDeclFromName(assetName, commonRoutingInfos); if (!commonVertexDecl) diff --git a/src/ObjCompiling/Techset/VertexDeclCompiler.h.template b/src/ObjCompiling/Techset/VertexDeclCompiler.h.template index d236b706..c7c4b6a5 100644 --- a/src/ObjCompiling/Techset/VertexDeclCompiler.h.template +++ b/src/ObjCompiling/Techset/VertexDeclCompiler.h.template @@ -2,8 +2,6 @@ #filename "Game/" + GAME + "/Techset/VertexDeclCompiler" + GAME + ".h" -#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\"" - #if GAME == "IW3" #define FEATURE_IW3 #elif GAME == "IW4" diff --git a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp index 8d5899a2..1bc7f913 100644 --- a/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp +++ b/src/ObjLoading/Game/IW4/ObjLoaderIW4.cpp @@ -6,6 +6,8 @@ #include "Game/IW4/IW4.h" #include "Game/IW4/Image/ImageLoaderEmbeddedIW4.h" #include "Game/IW4/Image/ImageLoaderExternalIW4.h" +#include "Game/IW4/Techset/PixelShaderLoaderIW4.h" +#include "Game/IW4/Techset/VertexShaderLoaderIW4.h" #include "Game/IW4/XModel/LoaderXModelIW4.h" #include "Leaderboard/LoaderLeaderboardIW4.h" #include "LightDef/LightDefLoaderIW4.h" @@ -16,8 +18,6 @@ #include "PhysPreset/GdtLoaderPhysPresetIW4.h" #include "PhysPreset/RawLoaderPhysPresetIW4.h" #include "RawFile/LoaderRawFileIW4.h" -#include "Shader/LoaderPixelShaderIW4.h" -#include "Shader/LoaderVertexShaderIW4.h" #include "Sound/LoaderSoundCurveIW4.h" #include "StringTable/LoaderStringTableIW4.h" #include "StructuredDataDef/LoaderStructuredDataDefIW4.h" @@ -129,8 +129,8 @@ namespace // collection.AddAssetCreator(std::make_unique(memory)); collection.AddAssetCreator(xmodel::CreateLoaderIW4(memory, searchPath, zone)); collection.AddAssetCreator(material::CreateLoaderIW4(memory, searchPath)); - collection.AddAssetCreator(shader::CreatePixelShaderLoaderIW4(memory, searchPath)); - collection.AddAssetCreator(shader::CreateVertexShaderLoaderIW4(memory, searchPath)); + collection.AddAssetCreator(techset::CreateVertexShaderLoaderIW4(memory, searchPath)); + collection.AddAssetCreator(techset::CreatePixelShaderLoaderIW4(memory, searchPath)); // collection.AddAssetCreator(std::make_unique(memory)); collection.AddAssetCreator(image::CreateLoaderEmbeddedIW4(memory, searchPath)); collection.AddAssetCreator(image::CreateLoaderExternalIW4(memory, searchPath)); diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp deleted file mode 100644 index 4450dc92..00000000 --- a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "LoaderPixelShaderIW4.h" - -#include "Game/IW4/IW4.h" -#include "Shader/ShaderCommon.h" -#include "Utils/Logging/Log.h" - -#include -#include -#include - -using namespace IW4; - -namespace -{ - class PixelShaderLoader final : public AssetCreator - { - public: - PixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath) - : m_memory(memory), - m_search_path(searchPath) - { - } - - AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override - { - const auto fileName = shader::GetFileNameForPixelShaderAssetName(assetName); - const auto file = m_search_path.Open(fileName); - if (!file.IsOpen()) - return AssetCreationResult::NoAction(); - - if (file.m_length % sizeof(uint32_t) != 0) - { - con::error("Invalid pixel shader \"{}\": Size must be dividable by {}", assetName, sizeof(uint32_t)); - return AssetCreationResult::Failure(); - } - - auto* pixelShader = m_memory.Alloc(); - pixelShader->name = m_memory.Dup(assetName.c_str()); - pixelShader->prog.loadDef.programSize = static_cast(static_cast(file.m_length) / sizeof(uint32_t)); - pixelShader->prog.loadDef.loadForRenderer = 0; - pixelShader->prog.ps = nullptr; - - auto* fileBuffer = m_memory.Alloc(pixelShader->prog.loadDef.programSize); - file.m_stream->read(reinterpret_cast(fileBuffer), static_cast(pixelShader->prog.loadDef.programSize) * sizeof(uint32_t)); - if (file.m_stream->gcount() != file.m_length) - return AssetCreationResult::Failure(); - - pixelShader->prog.loadDef.program = fileBuffer; - return AssetCreationResult::Success(context.AddAsset(assetName, pixelShader)); - } - - private: - MemoryManager& m_memory; - ISearchPath& m_search_path; - }; -} // namespace - -namespace shader -{ - std::unique_ptr> CreatePixelShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath) - { - return std::make_unique(memory, searchPath); - } -} // namespace shader diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h b/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h deleted file mode 100644 index 0bc212a5..00000000 --- a/src/ObjLoading/Game/IW4/Shader/LoaderPixelShaderIW4.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace shader -{ - std::unique_ptr> CreatePixelShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath); -} // namespace shader diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp deleted file mode 100644 index 79fcff64..00000000 --- a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "LoaderVertexShaderIW4.h" - -#include "Game/IW4/IW4.h" -#include "Shader/ShaderCommon.h" -#include "Utils/Logging/Log.h" - -#include -#include -#include - -using namespace IW4; - -namespace -{ - class VertexShaderLoader final : public AssetCreator - { - public: - VertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath) - : m_memory(memory), - m_search_path(searchPath) - { - } - - AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override - { - const auto fileName = shader::GetFileNameForVertexShaderAssetName(assetName); - const auto file = m_search_path.Open(fileName); - if (!file.IsOpen()) - return AssetCreationResult::NoAction(); - - if (file.m_length % sizeof(uint32_t) != 0) - { - con::error("Invalid vertex shader \"{}\": Size must be dividable by {}", assetName, sizeof(uint32_t)); - return AssetCreationResult::Failure(); - } - - auto* vertexShader = m_memory.Alloc(); - vertexShader->name = m_memory.Dup(assetName.c_str()); - vertexShader->prog.loadDef.programSize = static_cast(static_cast(file.m_length) / sizeof(uint32_t)); - vertexShader->prog.loadDef.loadForRenderer = 0; - vertexShader->prog.vs = nullptr; - - auto* fileBuffer = m_memory.Alloc(vertexShader->prog.loadDef.programSize); - file.m_stream->read(reinterpret_cast(fileBuffer), static_cast(vertexShader->prog.loadDef.programSize) * sizeof(uint32_t)); - if (file.m_stream->gcount() != file.m_length) - return AssetCreationResult::Failure(); - - vertexShader->prog.loadDef.program = fileBuffer; - return AssetCreationResult::Success(context.AddAsset(assetName, vertexShader)); - } - - private: - MemoryManager& m_memory; - ISearchPath& m_search_path; - }; -} // namespace - -namespace shader -{ - std::unique_ptr> CreateVertexShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath) - { - return std::make_unique(memory, searchPath); - } -} // namespace shader diff --git a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h b/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h deleted file mode 100644 index 28076aaf..00000000 --- a/src/ObjLoading/Game/IW4/Shader/LoaderVertexShaderIW4.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace shader -{ - std::unique_ptr> CreateVertexShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath); -} // namespace shader diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index 7f5fbc09..97c9128b 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -9,6 +9,8 @@ #include "Game/T6/Image/ImageLoaderEmbeddedT6.h" #include "Game/T6/Image/ImageLoaderExternalT6.h" #include "Game/T6/T6.h" +#include "Game/T6/Techset/PixelShaderLoaderT6.h" +#include "Game/T6/Techset/VertexShaderLoaderT6.h" #include "Game/T6/XModel/LoaderXModelT6.h" #include "Image/Dx12TextureLoader.h" #include "Image/IwiLoader.h" @@ -29,8 +31,6 @@ #include "Slug/LoaderSlugT6.h" #include "Sound/LoaderSoundBankT6.h" #include "StringTable/LoaderStringTableT6.h" -#include "Techset/PixelShaderLoaderT6.h" -#include "Techset/VertexShaderLoaderT6.h" #include "Tracer/GdtLoaderTracerT6.h" #include "Tracer/RawLoaderTracerT6.h" #include "Utils/Logging/Log.h" diff --git a/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp b/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp deleted file mode 100644 index acd67d55..00000000 --- a/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "PixelShaderLoaderT6.h" - -#include "Game/T6/T6.h" -#include "Shader/ShaderCommon.h" - -#include -#include - -using namespace T6; - -namespace -{ - class PixelShaderLoader final : public SubAssetCreator - { - public: - PixelShaderLoader(MemoryManager& memory, ISearchPath& searchPath) - : m_memory(memory), - m_search_path(searchPath) - { - } - - AssetCreationResult CreateSubAsset(const std::string& assetName, AssetCreationContext& context) override - { - const auto fileName = shader::GetFileNameForPixelShaderAssetName(assetName); - const auto file = m_search_path.Open(fileName); - if (!file.IsOpen()) - return AssetCreationResult::NoAction(); - - auto* pixelShader = m_memory.Alloc(); - pixelShader->name = m_memory.Dup(assetName.c_str()); - pixelShader->prog.loadDef.programSize = static_cast(file.m_length); - pixelShader->prog.ps = nullptr; - - auto* fileBuffer = m_memory.Alloc(pixelShader->prog.loadDef.programSize); - file.m_stream->read(fileBuffer, pixelShader->prog.loadDef.programSize); - if (file.m_stream->gcount() != file.m_length) - return AssetCreationResult::Failure(); - - pixelShader->prog.loadDef.program = fileBuffer; - return AssetCreationResult::Success(context.AddSubAsset(assetName, pixelShader)); - } - - private: - MemoryManager& m_memory; - ISearchPath& m_search_path; - }; -} // namespace - -namespace techset -{ - std::unique_ptr> CreatePixelShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath) - { - return std::make_unique(memory, searchPath); - } -} // namespace techset diff --git a/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.h b/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.h deleted file mode 100644 index 199960cf..00000000 --- a/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace techset -{ - std::unique_ptr> CreatePixelShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath); -} // namespace techset diff --git a/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.cpp b/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.cpp deleted file mode 100644 index 8dd2fa06..00000000 --- a/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "VertexShaderLoaderT6.h" - -#include "Game/T6/T6.h" -#include "Shader/ShaderCommon.h" - -#include -#include - -using namespace T6; - -namespace -{ - class VertexShaderLoader final : public SubAssetCreator - { - public: - VertexShaderLoader(MemoryManager& memory, ISearchPath& searchPath) - : m_memory(memory), - m_search_path(searchPath) - { - } - - AssetCreationResult CreateSubAsset(const std::string& assetName, AssetCreationContext& context) override - { - const auto fileName = shader::GetFileNameForVertexShaderAssetName(assetName); - const auto file = m_search_path.Open(fileName); - if (!file.IsOpen()) - return AssetCreationResult::NoAction(); - - auto* vertexShader = m_memory.Alloc(); - vertexShader->name = m_memory.Dup(assetName.c_str()); - vertexShader->prog.loadDef.programSize = static_cast(file.m_length); - vertexShader->prog.vs = nullptr; - - auto* fileBuffer = m_memory.Alloc(vertexShader->prog.loadDef.programSize); - file.m_stream->read(fileBuffer, vertexShader->prog.loadDef.programSize); - if (file.m_stream->gcount() != file.m_length) - return AssetCreationResult::Failure(); - - vertexShader->prog.loadDef.program = fileBuffer; - return AssetCreationResult::Success(context.AddSubAsset(assetName, vertexShader)); - } - - private: - MemoryManager& m_memory; - ISearchPath& m_search_path; - }; -} // namespace - -namespace techset -{ - std::unique_ptr> CreateVertexShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath) - { - return std::make_unique(memory, searchPath); - } -} // namespace techset diff --git a/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.h b/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.h deleted file mode 100644 index d0ae6c76..00000000 --- a/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/T6/T6.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace techset -{ - std::unique_ptr> CreateVertexShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath); -} // namespace techset diff --git a/src/ObjLoading/Techset/PixelShaderLoader.cpp.template b/src/ObjLoading/Techset/PixelShaderLoader.cpp.template new file mode 100644 index 00000000..19de8f72 --- /dev/null +++ b/src/ObjLoading/Techset/PixelShaderLoader.cpp.template @@ -0,0 +1,117 @@ +#options GAME(IW4, T6) + +#filename "Game/" + GAME + "/Techset/PixelShaderLoader" + GAME + ".cpp" + +#set LOADER_HEADER "\"PixelShaderLoader" + GAME + ".h\"" +#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\"" + +#if GAME == "IW3" +#define FEATURE_IW3 +#define IS_DX9 +#elif GAME == "IW4" +#define FEATURE_IW4 +#define IS_DX9 +#elif GAME == "IW5" +#define FEATURE_IW5 +#define IS_DX9 +#elif GAME == "T5" +#define FEATURE_T5 +#define IS_DX9 +#elif GAME == "T6" +#define FEATURE_T6 +#define IS_DX11 +#define IS_SUB_ASSET +#endif + +#include LOADER_HEADER + +#include GAME_HEADER +#include "Shader/ShaderCommon.h" +#include "Utils/Logging/Log.h" + +#include +#include + +using namespace GAME; + +#set LOADER_CLASS_NAME "PixelShaderLoader" + GAME + +#if defined(IS_SUB_ASSET) +#define ABSTRACT_CREATOR_NAME SubAssetCreator +#define OVERRIDDEN_CREATOR_METHOD CreateSubAsset +#define ADD_ASSET_METHOD AddSubAsset +#define ASSET_NAME SubAssetPixelShader +#define INTERFACE_NAME ISubAssetCreator +#else +#define ABSTRACT_CREATOR_NAME AssetCreator +#define OVERRIDDEN_CREATOR_METHOD CreateAsset +#define ADD_ASSET_METHOD AddAsset +#define ASSET_NAME AssetPixelShader +#define INTERFACE_NAME IAssetCreator +#endif + +namespace +{ + class LOADER_CLASS_NAME final : public ABSTRACT_CREATOR_NAME + { + public: + LOADER_CLASS_NAME(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult OVERRIDDEN_CREATOR_METHOD(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = shader::GetFileNameForPixelShaderAssetName(assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + +#if defined(IS_DX9) + if (file.m_length % sizeof(uint32_t) != 0) + { + con::error("Invalid pixel shader \"{}\": Size must be dividable by {}", assetName, sizeof(uint32_t)); + return AssetCreationResult::Failure(); + } +#endif + + auto* pixelShader = m_memory.Alloc(); + pixelShader->name = m_memory.Dup(assetName.c_str()); + pixelShader->prog.loadDef.programSize = static_cast( +#if defined(IS_DX9) + file.m_length / sizeof(std::remove_pointer_t) +#else + file.m_length +#endif + ); + pixelShader->prog.ps = nullptr; + + auto* fileBuffer = m_memory.Alloc(static_cast(file.m_length)); + file.m_stream->read(fileBuffer, file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + +#if defined(IS_DX9) + pixelShader->prog.loadDef.program = reinterpret_cast(fileBuffer); +#else + pixelShader->prog.loadDef.program = fileBuffer; +#endif + return AssetCreationResult::Success(context.ADD_ASSET_METHOD(assetName, pixelShader)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +#set CREATE_LOADER_METHOD "CreatePixelShaderLoader" + GAME + +namespace techset +{ + std::unique_ptr CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace techset diff --git a/src/ObjLoading/Techset/PixelShaderLoader.h.template b/src/ObjLoading/Techset/PixelShaderLoader.h.template new file mode 100644 index 00000000..05933dab --- /dev/null +++ b/src/ObjLoading/Techset/PixelShaderLoader.h.template @@ -0,0 +1,40 @@ +#options GAME(IW4, T6) + +#filename "Game/" + GAME + "/Techset/PixelShaderLoader" + GAME + ".h" + +#if GAME == "IW3" +#define FEATURE_IW3 +#elif GAME == "IW4" +#define FEATURE_IW4 +#elif GAME == "IW5" +#define FEATURE_IW5 +#elif GAME == "T5" +#define FEATURE_T5 +#elif GAME == "T6" +#define FEATURE_T6 +#endif + +// This file was templated. +// See PixelShaderLoader.h.template. +// Do not modify, changes will be lost. + +#pragma once + +#include "Asset/IAssetCreator.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +#set CREATE_LOADER_METHOD "CreatePixelShaderLoader" + GAME + +#if defined(FEATURE_T6) +#define INTERFACE_NAME ISubAssetCreator +#else +#define INTERFACE_NAME IAssetCreator +#endif + +namespace techset +{ + std::unique_ptr CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath); +} // namespace techset diff --git a/src/ObjLoading/Techset/VertexShaderLoader.cpp.template b/src/ObjLoading/Techset/VertexShaderLoader.cpp.template new file mode 100644 index 00000000..fb68e435 --- /dev/null +++ b/src/ObjLoading/Techset/VertexShaderLoader.cpp.template @@ -0,0 +1,118 @@ +#options GAME(IW4, T6) + +#filename "Game/" + GAME + "/Techset/VertexShaderLoader" + GAME + ".cpp" + +#set LOADER_HEADER "\"VertexShaderLoader" + GAME + ".h\"" +#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\"" + +#if GAME == "IW3" +#define FEATURE_IW3 +#define IS_DX9 +#elif GAME == "IW4" +#define FEATURE_IW4 +#define IS_DX9 +#elif GAME == "IW5" +#define FEATURE_IW5 +#define IS_DX9 +#elif GAME == "T5" +#define FEATURE_T5 +#define IS_DX9 +#elif GAME == "T6" +#define FEATURE_T6 +#define IS_DX11 +#define IS_SUB_ASSET +#endif + +#include LOADER_HEADER + +#include GAME_HEADER +#include "Shader/ShaderCommon.h" +#include "Utils/Logging/Log.h" + +#include +#include + +using namespace GAME; + +#set LOADER_CLASS_NAME "VertexShaderLoader" + GAME + +#if defined(IS_SUB_ASSET) +#define ABSTRACT_CREATOR_NAME SubAssetCreator +#define OVERRIDDEN_CREATOR_METHOD CreateSubAsset +#define ADD_ASSET_METHOD AddSubAsset +#define ASSET_NAME SubAssetVertexShader +#define INTERFACE_NAME ISubAssetCreator +#else +#define ABSTRACT_CREATOR_NAME AssetCreator +#define OVERRIDDEN_CREATOR_METHOD CreateAsset +#define ADD_ASSET_METHOD AddAsset +#define ASSET_NAME AssetVertexShader +#define INTERFACE_NAME IAssetCreator +#endif + +namespace +{ + class LOADER_CLASS_NAME final : public ABSTRACT_CREATOR_NAME + { + public: + LOADER_CLASS_NAME(MemoryManager& memory, ISearchPath& searchPath) + : m_memory(memory), + m_search_path(searchPath) + { + } + + AssetCreationResult OVERRIDDEN_CREATOR_METHOD(const std::string& assetName, AssetCreationContext& context) override + { + const auto fileName = shader::GetFileNameForVertexShaderAssetName(assetName); + const auto file = m_search_path.Open(fileName); + if (!file.IsOpen()) + return AssetCreationResult::NoAction(); + +#if defined(IS_DX9) + if (file.m_length % sizeof(uint32_t) != 0) + { + con::error("Invalid vertex shader \"{}\": Size must be dividable by {}", assetName, sizeof(uint32_t)); + return AssetCreationResult::Failure(); + } +#endif + + auto* vertexShader = m_memory.Alloc(); + vertexShader->name = m_memory.Dup(assetName.c_str()); + vertexShader->prog.loadDef.programSize = static_cast( +#if defined(IS_DX9) + file.m_length / sizeof(std::remove_pointer_t) +#else + file.m_length +#endif + ); + vertexShader->prog.vs = nullptr; + + auto* fileBuffer = m_memory.Alloc(static_cast(file.m_length)); + file.m_stream->read(fileBuffer, file.m_length); + if (file.m_stream->gcount() != file.m_length) + return AssetCreationResult::Failure(); + +#if defined(IS_DX9) + vertexShader->prog.loadDef.program = reinterpret_cast(fileBuffer); +#else + vertexShader->prog.loadDef.program = fileBuffer; +#endif + + return AssetCreationResult::Success(context.ADD_ASSET_METHOD(assetName, vertexShader)); + } + + private: + MemoryManager& m_memory; + ISearchPath& m_search_path; + }; +} // namespace + +#set CREATE_LOADER_METHOD "CreateVertexShaderLoader" + GAME + +namespace techset +{ + std::unique_ptr CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath) + { + return std::make_unique(memory, searchPath); + } +} // namespace techset diff --git a/src/ObjLoading/Techset/VertexShaderLoader.h.template b/src/ObjLoading/Techset/VertexShaderLoader.h.template new file mode 100644 index 00000000..b9e37b0d --- /dev/null +++ b/src/ObjLoading/Techset/VertexShaderLoader.h.template @@ -0,0 +1,40 @@ +#options GAME(IW4, T6) + +#filename "Game/" + GAME + "/Techset/VertexShaderLoader" + GAME + ".h" + +#if GAME == "IW3" +#define FEATURE_IW3 +#elif GAME == "IW4" +#define FEATURE_IW4 +#elif GAME == "IW5" +#define FEATURE_IW5 +#elif GAME == "T5" +#define FEATURE_T5 +#elif GAME == "T6" +#define FEATURE_T6 +#endif + +// This file was templated. +// See VertexShaderLoader.h.template. +// Do not modify, changes will be lost. + +#pragma once + +#include "Asset/IAssetCreator.h" +#include "SearchPath/ISearchPath.h" +#include "Utils/MemoryManager.h" + +#include + +#set CREATE_LOADER_METHOD "CreateVertexShaderLoader" + GAME + +#if defined(FEATURE_T6) +#define INTERFACE_NAME ISubAssetCreator +#else +#define INTERFACE_NAME IAssetCreator +#endif + +namespace techset +{ + std::unique_ptr CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath); +} // namespace techset diff --git a/test/ObjCompilingTests.lua b/test/ObjCompilingTests.lua index 1e382f12..fa64961e 100644 --- a/test/ObjCompilingTests.lua +++ b/test/ObjCompilingTests.lua @@ -3,6 +3,7 @@ ObjCompilingTests = {} function ObjCompilingTests:include(includes) if includes:handle(self:name()) then includedirs { + "%{wks.location}/src/ObjLoading", "%{wks.location}/src/ObjCompiling", path.join(TestFolder(), "ObjCompilingTests") }