From: Mikko Rasa Date: Thu, 4 Mar 2021 21:26:19 +0000 (+0200) Subject: Use a different method of adding builtins to stages X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=9328859840052a49ca3ba868e35fcf64d417c623 Use a different method of adding builtins to stages This gets them in the correct order with the module's shared stage, and also allows builtins to have shared declarations. --- diff --git a/source/glsl/builtin.cpp b/source/glsl/builtin.cpp index 04974065..955266fe 100644 --- a/source/glsl/builtin.cpp +++ b/source/glsl/builtin.cpp @@ -49,6 +49,8 @@ Stage *get_builtins(Stage::Type type) if(!module) return 0; + if(type==Stage::SHARED) + return &module->shared; for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) if(i->type==type) return &*i; diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index d5ee6691..c2a0656d 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -206,13 +206,6 @@ void Compiler::append_stage(Stage &stage) target = &*i; } - if(target->content.body.empty()) - { - Stage *builtins = get_builtins(stage.type); - if(builtins && builtins!=&stage) - append_stage(*builtins); - } - if(stage.required_features.glsl_version>target->required_features.glsl_version) target->required_features.glsl_version = stage.required_features.glsl_version; for(NodeList::iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i) @@ -239,7 +232,12 @@ void Compiler::generate(Stage &stage, Mode mode) stage.required_features.gl_api = features.gl_api; if(module->shared.required_features.glsl_version>stage.required_features.glsl_version) stage.required_features.glsl_version = module->shared.required_features.glsl_version; + inject_block(stage.content, module->shared.content); + if(Stage *builtins = get_builtins(stage.type)) + inject_block(stage.content, builtins->content); + if(Stage *builtins = get_builtins(Stage::SHARED)) + inject_block(stage.content, builtins->content); // Initial resolving pass BlockHierarchyResolver().apply(stage);