From b9550388afdf53b1efc858cd568181217b060897 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 15 Dec 2024 10:33:09 +1100 Subject: use the Shader_Type in the shader compiler instead of another stage enum --- sc/sc.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/sc/sc.cpp b/sc/sc.cpp index ae4ae02..a385619 100644 --- a/sc/sc.cpp +++ b/sc/sc.cpp @@ -115,11 +115,6 @@ int type_from_string(const char* s) { } struct Desc { - enum { - VERTEX, - FRAGMENT, - stage_count - }; struct Variable { int type; std::string name; @@ -128,7 +123,7 @@ struct Desc { int type; std::vector attrs; std::vector trgts; - std::string entrypoints[stage_count]; + std::string entrypoints[shader_type_count]; void read_var(Variable& d, cfg_Object* desc) { const char* stype = find_string_default(desc, "type", 0); if (!stype) { @@ -159,13 +154,13 @@ struct Desc { print_err("Graphics programs must define a vertex shader entry point.\n"); pbreak(301); } - entrypoints[VERTEX] = sv; + entrypoints[shader_type_vertex] = sv; const char* sf = find_string_default(desc, "fragment", 0); if (!sf) { print_err("Graphics programs must define a fragment shader entry point.\n"); pbreak(302); } - entrypoints[FRAGMENT] = sf; + entrypoints[shader_type_fragment] = sf; desc = desc->next; while (desc) { Variable v; @@ -277,12 +272,12 @@ void configure( std::string& ps ) { switch (stage) { - case Desc::VERTEX: + case shader_type_vertex: dfn = "VERTEX_SHADER"; l = EShLangVertex; ps += d.build_vs(); break; - case Desc::FRAGMENT: + case shader_type_fragment: dfn = "FRAGMENT_SHADER"; l = EShLangFragment; ps += d.build_fs(); @@ -298,7 +293,7 @@ void compile_shaders( const char* define; EShLanguage lang; int i; - for (i = 0; i < Desc::stage_count; i++) { + for (i = 0; i < shader_type_count; i++) { if (!d.entrypoints[i].empty()) { std::string ps; configure(d, i, define, lang, ps); @@ -343,7 +338,7 @@ void write_csh( fwrite(&t.type, 4, 1, f); hsize += 32; } - for (i = 0, coff = 0; i < Desc::stage_count; i++) { + for (i = 0, coff = 0; i < shader_type_count; i++) { int o = 0; if (d.entrypoints[i].empty()) fwrite(&o, 4, 1, f); @@ -353,7 +348,7 @@ void write_csh( coff += stages[i].size() * sizeof(uint32_t); } } - for (i = 0; i < Desc::stage_count; i++) + for (i = 0; i < shader_type_count; i++) if (!d.entrypoints[i].empty()) { auto& stage = stages[i]; fwrite(&stage[0], sizeof(uint32_t), stage.size(), f); @@ -364,7 +359,7 @@ int main(int argc, const char** argv) { char* src; size_t src_size; std::string desc_src; - std::vector spv[Desc::stage_count]; + std::vector spv[shader_type_count]; cfg_Object* cdesc; void* dp_mem; Desc desc; -- cgit v1.2.3-54-g00ecf