From 47d9d5d10469340af44909de9c8ab9fd4f1a19a1 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 15 Feb 2021 17:50:03 +0200 Subject: [PATCH] Refactor creation of the shader builtin module It can now use VariableResolver::apply like everything else. --- source/glsl/builtin.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/source/glsl/builtin.cpp b/source/glsl/builtin.cpp index c9118f69..1fd496b4 100644 --- a/source/glsl/builtin.cpp +++ b/source/glsl/builtin.cpp @@ -28,29 +28,35 @@ namespace Msp { namespace GL { namespace SL { -Module *create_builtins_module() +Module *get_builtins_module() { - Parser parser; - Module *module = new Module(parser.parse(builtins_src, "")); - for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + static RefPtr builtins_module; + static bool initialized = false; + if(!initialized) { - VariableResolver().visit(i->content); - for(map::iterator j=i->content.variables.begin(); j!=i->content.variables.end(); ++j) - j->second->linked_declaration = j->second; - } - return module; -} + initialized = true; -Module &get_builtins_module() -{ - static RefPtr builtins_module = create_builtins_module(); - return *builtins_module; + Parser parser; + Module *module = new Module(parser.parse(builtins_src, "")); + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + { + VariableResolver().apply(*i); + for(map::iterator j=i->content.variables.begin(); j!=i->content.variables.end(); ++j) + j->second->linked_declaration = j->second; + } + + builtins_module = module; + } + return builtins_module.get(); } Stage *get_builtins(Stage::Type type) { - Module &module = get_builtins_module(); - for(list::iterator i=module.stages.begin(); i!=module.stages.end(); ++i) + Module *module = get_builtins_module(); + if(!module) + return 0; + + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) if(i->type==type) return &*i; return 0; -- 2.45.2