From: Mikko Rasa Date: Mon, 15 Feb 2021 15:50:03 +0000 (+0200) Subject: Refactor creation of the shader builtin module X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=47d9d5d10469340af44909de9c8ab9fd4f1a19a1;p=libs%2Fgl.git Refactor creation of the shader builtin module It can now use VariableResolver::apply like everything else. --- 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;