]> git.tdb.fi Git - libs/gl.git/commitdiff
Use a different method of adding builtins to stages
authorMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 21:26:19 +0000 (23:26 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 4 Mar 2021 22:30:28 +0000 (00:30 +0200)
This gets them in the correct order with the module's shared stage, and
also allows builtins to have shared declarations.

source/glsl/builtin.cpp
source/glsl/compiler.cpp

index 049740657a5c251432f5054a67a40d1fa4b98164..955266fe0a1ce4ad3a8abfcd9fb3afb0340266f8 100644 (file)
@@ -49,6 +49,8 @@ Stage *get_builtins(Stage::Type type)
        if(!module)
                return 0;
 
+       if(type==Stage::SHARED)
+               return &module->shared;
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
                if(i->type==type)
                        return &*i;
index d5ee6691ff83cd3d877c845431ab9a29698c1edb..c2a0656d412265c94d789489a9f3099b8c352f84 100644 (file)
@@ -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<Statement>::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);