mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-15 17:33:03 +00:00
feat: add templated technique compiler for IW4
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "ObjCompilerIW4.h"
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW4/Techset/TechniqueCompilerIW4.h"
|
||||
#include "Game/IW4/Techset/TechsetCompilerIW4.h"
|
||||
#include "Game/IW4/Techset/VertexDeclCompilerIW4.h"
|
||||
#include "Image/ImageIwdPostProcessor.h"
|
||||
@@ -21,6 +22,8 @@ namespace
|
||||
#endif
|
||||
collection.AddAssetCreator(techset::CreateVertexDeclCompilerIW4(memory));
|
||||
collection.AddAssetCreator(techset::CreateTechsetCompilerIW4(memory, searchPath));
|
||||
|
||||
collection.AddSubAssetCreator(techset::CreateTechniqueCompilerIW4(memory, zone, searchPath));
|
||||
}
|
||||
|
||||
void ConfigurePostProcessors(AssetCreatorCollection& collection,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#options GAME(T6)
|
||||
#options GAME(IW4, T6)
|
||||
|
||||
#filename "Game/" + GAME + "/Techset/TechniqueCompiler" + GAME + ".cpp"
|
||||
|
||||
@@ -8,14 +8,21 @@
|
||||
|
||||
#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
|
||||
#define SHADERS_ARE_SUBASSETS
|
||||
#elif GAME == "T6"
|
||||
#define FEATURE_T6
|
||||
#define IS_DX11
|
||||
#define SHADERS_ARE_SUBASSETS
|
||||
#endif
|
||||
|
||||
// This file was templated.
|
||||
@@ -131,6 +138,9 @@ namespace
|
||||
|
||||
arg.type = static_cast<decltype(MaterialShaderArgument::type)>(ConvertArgumentType(commonArg.m_type));
|
||||
|
||||
#if defined(IS_DX9)
|
||||
arg.dest = static_cast<decltype(MaterialShaderArgument::dest)>(commonArg.m_destination.dx9.m_destination_register);
|
||||
#else
|
||||
arg.size = static_cast<decltype(MaterialShaderArgument::size)>(commonArg.m_destination.dx11.m_size);
|
||||
arg.buffer = static_cast<decltype(MaterialShaderArgument::buffer)>(commonArg.m_destination.dx11.m_buffer);
|
||||
|
||||
@@ -146,6 +156,7 @@ namespace
|
||||
arg.location.samplerIndex =
|
||||
static_cast<decltype(MaterialArgumentLocation::samplerIndex)>(commonArg.m_destination.dx11.m_location.sampler_index);
|
||||
}
|
||||
#endif
|
||||
|
||||
ConvertArgumentValue(arg.u, commonArg, memory, context);
|
||||
}
|
||||
@@ -161,7 +172,11 @@ namespace
|
||||
}
|
||||
|
||||
const std::string declName(nameStream.str());
|
||||
#if defined(SHADERS_ARE_SUBASSETS)
|
||||
auto* vertexDeclAsset = context.LoadSubAsset<SubAssetVertexDecl>(declName);
|
||||
#else
|
||||
auto* vertexDeclAsset = context.LoadDependency<AssetVertexDecl>(declName);
|
||||
#endif
|
||||
assert(vertexDeclAsset);
|
||||
pass.vertexDecl = vertexDeclAsset ? vertexDeclAsset->Asset() : nullptr;
|
||||
}
|
||||
@@ -172,14 +187,22 @@ namespace
|
||||
|
||||
if (!commonPass.m_vertex_shader.m_name.empty())
|
||||
{
|
||||
#if defined(SHADERS_ARE_SUBASSETS)
|
||||
auto* vertexShaderAsset = context.LoadSubAsset<SubAssetVertexShader>(commonPass.m_vertex_shader.m_name);
|
||||
#else
|
||||
auto* vertexShaderAsset = context.LoadDependency<AssetVertexShader>(commonPass.m_vertex_shader.m_name);
|
||||
#endif
|
||||
assert(vertexShaderAsset);
|
||||
pass.vertexShader = vertexShaderAsset ? vertexShaderAsset->Asset() : nullptr;
|
||||
}
|
||||
|
||||
if (!commonPass.m_pixel_shader.m_name.empty())
|
||||
{
|
||||
#if defined(SHADERS_ARE_SUBASSETS)
|
||||
auto* pixelShaderAsset = context.LoadSubAsset<SubAssetPixelShader>(commonPass.m_pixel_shader.m_name);
|
||||
#else
|
||||
auto* pixelShaderAsset = context.LoadDependency<AssetPixelShader>(commonPass.m_pixel_shader.m_name);
|
||||
#endif
|
||||
assert(pixelShaderAsset);
|
||||
pass.pixelShader = pixelShaderAsset ? pixelShaderAsset->Asset() : nullptr;
|
||||
}
|
||||
@@ -205,6 +228,9 @@ namespace
|
||||
|
||||
void UpdateTechniqueFlags(MaterialTechnique& technique, const techset::CommonTechnique& commonTechnique)
|
||||
{
|
||||
#if defined(FEATURE_IW4)
|
||||
// TODO
|
||||
#elif defined(FEATURE_T6)
|
||||
std::string lowerTechniqueName(commonTechnique.m_name);
|
||||
utils::MakeStringLowerCase(lowerTechniqueName);
|
||||
|
||||
@@ -215,9 +241,14 @@ namespace
|
||||
{
|
||||
technique.flags |= TECHNIQUE_FLAG_4;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (AnyDeclHasOptionalSource(technique))
|
||||
#if defined(FEATURE_IW4)
|
||||
technique.flags |= TECHNIQUE_FLAG_20;
|
||||
#elif defined(FEATURE_T6)
|
||||
technique.flags |= TECHNIQUE_FLAG_8;
|
||||
#endif
|
||||
}
|
||||
|
||||
MaterialTechnique* ConvertTechnique(const techset::CommonTechnique& commonTechnique, AssetCreationContext& context, MemoryManager& memory)
|
||||
@@ -241,6 +272,7 @@ namespace
|
||||
return technique;
|
||||
}
|
||||
|
||||
#if defined(FEATURE_T6)
|
||||
void ApplyTechFlagsFromMaterial(const Material& material, const Zone& zone)
|
||||
{
|
||||
if (!material.techniqueSet || !material.techniqueSet->name || !material.stateBitsTable)
|
||||
@@ -266,6 +298,7 @@ namespace
|
||||
technique->flags |= TECHNIQUE_FLAG_80;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
class SHADER_LOADER_CLASS_NAME final : public techset::ITechniqueShaderLoader
|
||||
{
|
||||
@@ -277,7 +310,11 @@ namespace
|
||||
|
||||
std::optional<techset::CommonTechniqueShaderBin> LoadVertexShader(const std::string& name) override
|
||||
{
|
||||
#if defined(SHADERS_ARE_SUBASSETS)
|
||||
auto* shaderAsset = m_context.LoadSubAsset<SubAssetVertexShader>(name);
|
||||
#else
|
||||
auto* shaderAsset = m_context.ForceLoadDependency<AssetVertexShader>(name);
|
||||
#endif
|
||||
if (!shaderAsset)
|
||||
return std::nullopt;
|
||||
|
||||
@@ -288,13 +325,22 @@ namespace
|
||||
|
||||
return techset::CommonTechniqueShaderBin{
|
||||
.m_shader_bin = shader->prog.loadDef.program,
|
||||
#if defined(IS_DX9)
|
||||
.m_shader_bin_size =
|
||||
static_cast<size_t>(shader->prog.loadDef.programSize) * sizeof(std::remove_pointer_t<decltype(GfxVertexShaderLoadDef::program)>),
|
||||
#else
|
||||
.m_shader_bin_size = shader->prog.loadDef.programSize,
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
std::optional<techset::CommonTechniqueShaderBin> LoadPixelShader(const std::string& name) override
|
||||
{
|
||||
#if defined(SHADERS_ARE_SUBASSETS)
|
||||
auto* shaderAsset = m_context.LoadSubAsset<SubAssetPixelShader>(name);
|
||||
#else
|
||||
auto* shaderAsset = m_context.ForceLoadDependency<AssetPixelShader>(name);
|
||||
#endif
|
||||
if (!shaderAsset)
|
||||
return std::nullopt;
|
||||
|
||||
@@ -305,7 +351,12 @@ namespace
|
||||
|
||||
return techset::CommonTechniqueShaderBin{
|
||||
.m_shader_bin = shader->prog.loadDef.program,
|
||||
#if defined(IS_DX9)
|
||||
.m_shader_bin_size =
|
||||
static_cast<size_t>(shader->prog.loadDef.programSize) * sizeof(std::remove_pointer_t<decltype(GfxPixelShaderLoadDef::program)>),
|
||||
#else
|
||||
.m_shader_bin_size = shader->prog.loadDef.programSize,
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
@@ -327,7 +378,11 @@ namespace
|
||||
{
|
||||
bool failure = false;
|
||||
SHADER_LOADER_CLASS_NAME shaderLoader(context);
|
||||
#if defined(IS_DX9)
|
||||
const auto commonShaderArgCreator = techset::CommonShaderArgCreator::CreateDx9(shaderLoader, context, commonCodeSourceInfos);
|
||||
#else
|
||||
const auto commonShaderArgCreator = techset::CommonShaderArgCreator::CreateDx11(shaderLoader, context, commonCodeSourceInfos);
|
||||
#endif
|
||||
|
||||
const auto commonTechnique =
|
||||
techset::LoadCommonTechnique(subAssetName, commonCodeSourceInfos, commonRoutingInfos, *commonShaderArgCreator, m_search_path, failure);
|
||||
@@ -343,6 +398,9 @@ namespace
|
||||
|
||||
void FinalizeZone(AssetCreationContext& context) override
|
||||
{
|
||||
#if defined(FEATURE_IW4)
|
||||
// TODO
|
||||
#elif defined(FEATURE_T6)
|
||||
const auto materials = m_zone.m_pools.PoolAssets<AssetMaterial>();
|
||||
for (auto* materialAsset : materials)
|
||||
{
|
||||
@@ -358,6 +416,7 @@ namespace
|
||||
ApplyPrecompiledIndex(technique.passArray[passIndex]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#options GAME(T6)
|
||||
#options GAME(IW4, T6)
|
||||
|
||||
#filename "Game/" + GAME + "/Techset/TechniqueCompiler" + GAME + ".h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user