diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index 5642bf4a..7f5fbc09 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -29,6 +29,8 @@ #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" @@ -434,6 +436,9 @@ namespace T6 // collection.AddAssetCreator(std::make_unique(memory)); collection.AddAssetCreator(z_barrier::CreateRawLoaderT6(memory, searchPath, zone)); collection.AddAssetCreator(z_barrier::CreateGdtLoaderT6(memory, searchPath, gdt, zone)); + + collection.AddSubAssetCreator(techset::CreateVertexShaderLoaderT6(memory, searchPath)); + collection.AddSubAssetCreator(techset::CreatePixelShaderLoaderT6(memory, searchPath)); } } // namespace diff --git a/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp b/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp new file mode 100644 index 00000000..acd67d55 --- /dev/null +++ b/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.cpp @@ -0,0 +1,55 @@ +#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 new file mode 100644 index 00000000..199960cf --- /dev/null +++ b/src/ObjLoading/Game/T6/Techset/PixelShaderLoaderT6.h @@ -0,0 +1,13 @@ +#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 new file mode 100644 index 00000000..8dd2fa06 --- /dev/null +++ b/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.cpp @@ -0,0 +1,55 @@ +#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 new file mode 100644 index 00000000..d0ae6c76 --- /dev/null +++ b/src/ObjLoading/Game/T6/Techset/VertexShaderLoaderT6.h @@ -0,0 +1,13 @@ +#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