2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-15 17:33:03 +00:00

chore: use templated loaders for shaders in IW4,T6

This commit is contained in:
Jan Laupetin
2026-03-07 11:11:53 +00:00
parent fbfd418e20
commit 6e19b94b9b
20 changed files with 325 additions and 307 deletions

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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)

View File

@@ -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"

View File

@@ -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<AssetLoaderXModelSurfs>(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<AssetLoaderTechset>(memory));
collection.AddAssetCreator(image::CreateLoaderEmbeddedIW4(memory, searchPath));
collection.AddAssetCreator(image::CreateLoaderExternalIW4(memory, searchPath));

View File

@@ -1,64 +0,0 @@
#include "LoaderPixelShaderIW4.h"
#include "Game/IW4/IW4.h"
#include "Shader/ShaderCommon.h"
#include "Utils/Logging/Log.h"
#include <cstdint>
#include <format>
#include <iostream>
using namespace IW4;
namespace
{
class PixelShaderLoader final : public AssetCreator<AssetPixelShader>
{
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<MaterialPixelShader>();
pixelShader->name = m_memory.Dup(assetName.c_str());
pixelShader->prog.loadDef.programSize = static_cast<uint16_t>(static_cast<size_t>(file.m_length) / sizeof(uint32_t));
pixelShader->prog.loadDef.loadForRenderer = 0;
pixelShader->prog.ps = nullptr;
auto* fileBuffer = m_memory.Alloc<uint32_t>(pixelShader->prog.loadDef.programSize);
file.m_stream->read(reinterpret_cast<char*>(fileBuffer), static_cast<std::streamsize>(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<AssetPixelShader>(assetName, pixelShader));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace shader
{
std::unique_ptr<AssetCreator<AssetPixelShader>> CreatePixelShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<PixelShaderLoader>(memory, searchPath);
}
} // namespace shader

View File

@@ -1,13 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/IW4/IW4.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace shader
{
std::unique_ptr<AssetCreator<IW4::AssetPixelShader>> CreatePixelShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace shader

View File

@@ -1,64 +0,0 @@
#include "LoaderVertexShaderIW4.h"
#include "Game/IW4/IW4.h"
#include "Shader/ShaderCommon.h"
#include "Utils/Logging/Log.h"
#include <cstdint>
#include <format>
#include <iostream>
using namespace IW4;
namespace
{
class VertexShaderLoader final : public AssetCreator<AssetVertexShader>
{
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<MaterialVertexShader>();
vertexShader->name = m_memory.Dup(assetName.c_str());
vertexShader->prog.loadDef.programSize = static_cast<uint16_t>(static_cast<size_t>(file.m_length) / sizeof(uint32_t));
vertexShader->prog.loadDef.loadForRenderer = 0;
vertexShader->prog.vs = nullptr;
auto* fileBuffer = m_memory.Alloc<uint32_t>(vertexShader->prog.loadDef.programSize);
file.m_stream->read(reinterpret_cast<char*>(fileBuffer), static_cast<std::streamsize>(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<AssetVertexShader>(assetName, vertexShader));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace shader
{
std::unique_ptr<AssetCreator<AssetVertexShader>> CreateVertexShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<VertexShaderLoader>(memory, searchPath);
}
} // namespace shader

View File

@@ -1,13 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/IW4/IW4.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace shader
{
std::unique_ptr<AssetCreator<IW4::AssetVertexShader>> CreateVertexShaderLoaderIW4(MemoryManager& memory, ISearchPath& searchPath);
} // namespace shader

View File

@@ -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"

View File

@@ -1,55 +0,0 @@
#include "PixelShaderLoaderT6.h"
#include "Game/T6/T6.h"
#include "Shader/ShaderCommon.h"
#include <format>
#include <iostream>
using namespace T6;
namespace
{
class PixelShaderLoader final : public SubAssetCreator<SubAssetPixelShader>
{
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<MaterialPixelShader>();
pixelShader->name = m_memory.Dup(assetName.c_str());
pixelShader->prog.loadDef.programSize = static_cast<decltype(GfxPixelShaderLoadDef::programSize)>(file.m_length);
pixelShader->prog.ps = nullptr;
auto* fileBuffer = m_memory.Alloc<char>(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<SubAssetPixelShader>(assetName, pixelShader));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace techset
{
std::unique_ptr<SubAssetCreator<SubAssetPixelShader>> CreatePixelShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<PixelShaderLoader>(memory, searchPath);
}
} // namespace techset

View File

@@ -1,13 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace techset
{
std::unique_ptr<SubAssetCreator<T6::SubAssetPixelShader>> CreatePixelShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath);
} // namespace techset

View File

@@ -1,55 +0,0 @@
#include "VertexShaderLoaderT6.h"
#include "Game/T6/T6.h"
#include "Shader/ShaderCommon.h"
#include <format>
#include <iostream>
using namespace T6;
namespace
{
class VertexShaderLoader final : public SubAssetCreator<SubAssetVertexShader>
{
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<MaterialVertexShader>();
vertexShader->name = m_memory.Dup(assetName.c_str());
vertexShader->prog.loadDef.programSize = static_cast<decltype(GfxVertexShaderLoadDef::programSize)>(file.m_length);
vertexShader->prog.vs = nullptr;
auto* fileBuffer = m_memory.Alloc<char>(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<SubAssetVertexShader>(assetName, vertexShader));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
namespace techset
{
std::unique_ptr<SubAssetCreator<SubAssetVertexShader>> CreateVertexShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<VertexShaderLoader>(memory, searchPath);
}
} // namespace techset

View File

@@ -1,13 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace techset
{
std::unique_ptr<SubAssetCreator<T6::SubAssetVertexShader>> CreateVertexShaderLoaderT6(MemoryManager& memory, ISearchPath& searchPath);
} // namespace techset

View File

@@ -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 <format>
#include <iostream>
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<ASSET_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<MaterialPixelShader>();
pixelShader->name = m_memory.Dup(assetName.c_str());
pixelShader->prog.loadDef.programSize = static_cast<decltype(GfxPixelShaderLoadDef::programSize)>(
#if defined(IS_DX9)
file.m_length / sizeof(std::remove_pointer_t<decltype(GfxPixelShaderLoadDef::program)>)
#else
file.m_length
#endif
);
pixelShader->prog.ps = nullptr;
auto* fileBuffer = m_memory.Alloc<char>(static_cast<size_t>(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<decltype(GfxPixelShaderLoadDef::program)>(fileBuffer);
#else
pixelShader->prog.loadDef.program = fileBuffer;
#endif
return AssetCreationResult::Success(context.ADD_ASSET_METHOD<ASSET_NAME>(assetName, pixelShader));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
#set CREATE_LOADER_METHOD "CreatePixelShaderLoader" + GAME
namespace techset
{
std::unique_ptr<INTERFACE_NAME> CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LOADER_CLASS_NAME>(memory, searchPath);
}
} // namespace techset

View File

@@ -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 <memory>
#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<INTERFACE_NAME> CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath);
} // namespace techset

View File

@@ -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 <format>
#include <iostream>
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<ASSET_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<MaterialVertexShader>();
vertexShader->name = m_memory.Dup(assetName.c_str());
vertexShader->prog.loadDef.programSize = static_cast<decltype(GfxVertexShaderLoadDef::programSize)>(
#if defined(IS_DX9)
file.m_length / sizeof(std::remove_pointer_t<decltype(GfxVertexShaderLoadDef::program)>)
#else
file.m_length
#endif
);
vertexShader->prog.vs = nullptr;
auto* fileBuffer = m_memory.Alloc<char>(static_cast<size_t>(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<decltype(GfxVertexShaderLoadDef::program)>(fileBuffer);
#else
vertexShader->prog.loadDef.program = fileBuffer;
#endif
return AssetCreationResult::Success(context.ADD_ASSET_METHOD<ASSET_NAME>(assetName, vertexShader));
}
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
};
} // namespace
#set CREATE_LOADER_METHOD "CreateVertexShaderLoader" + GAME
namespace techset
{
std::unique_ptr<INTERFACE_NAME> CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<LOADER_CLASS_NAME>(memory, searchPath);
}
} // namespace techset

View File

@@ -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 <memory>
#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<INTERFACE_NAME> CREATE_LOADER_METHOD(MemoryManager& memory, ISearchPath& searchPath);
} // namespace techset

View File

@@ -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")
}