Files
funnygame/shadercompiler/main.cpp
2025-12-23 15:03:44 +02:00

62 lines
1.6 KiB
C++

#include "tier0/lib.h"
#include "tier1/commandline.h"
#include "tier1/appinit.h"
#include "tier1/utlstring.h"
#include "tier2/ifilesystem.h"
#include "shadercompiler/icompiler.h"
#include "materialsystem/compiledshadermgr.h"
static IShaderCompiler *s_pVulkanSpirvCompiler;
static const char *s_szGameRoot;
void CompileShader( const char *szShader )
{
CCompiledShader shader;
if (V_strcmp("shader",Plat_GetExtension(szShader)))
return;
s_pVulkanSpirvCompiler->CompileShader(szShader, &shader);
Plat_MakeDir("build/funnygame/assets", 0755);
Plat_MakeDir("build/funnygame/assets/shaders", 0755);
CUtlString szOutputDirectory = szShader;
szOutputDirectory.RemoveHead(strlen(s_szGameRoot)+1);
szOutputDirectory.AppendHead("build/funnygame/assets/");
szOutputDirectory.AppendTail("_c");
printf("%s\n",szOutputDirectory.GetString());
CompiledShaderManager()->WriteToFile(&shader, szOutputDirectory);
};
void PrintHelp()
{
printf("Usage: fsc -i [shader folder] -o [game root]");
Plat_Exit(0);
}
int main( int c, char **v )
{
CUtlString szExePath = Plat_GetExecutablePath();
CommandLine()->CreateCommandLine(c, v);
filesystem->Init();
s_pVulkanSpirvCompiler = (IShaderCompiler*)CreateInterface(SLANG_SHADER_COMPILER_SPIRV_VULKAN, NULL);
s_pVulkanSpirvCompiler->Init();
const char *szInputDirectory = CommandLine()->ParamValue("-i");
if (!szInputDirectory)
PrintHelp();
s_szGameRoot = szInputDirectory;
CUtlString szShaderDirectory = CUtlString("%s/shaders\n", szInputDirectory);
Plat_ListDirRecursive(szInputDirectory, CompileShader, NULL);
s_pVulkanSpirvCompiler->Shutdown();
return 0;
}