]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Require passing features to SL::Compiler constructor
[libs/gl.git] / source / glsl / compiler.cpp
index 8d96cc4270b5b1566f75e37f26e1e35fa04c0352..3f25935064beafe5c0fbecd86bcf4dae40eaa16c 100644 (file)
@@ -23,18 +23,8 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
-Compiler::Compiler():
-       features(Features::from_context()),
-       module(0),
-       compiled(false),
-       specialized(false)
-{ }
-
 Compiler::Compiler(const Features &f):
-       features(f),
-       module(0),
-       compiled(false),
-       specialized(false)
+       features(f)
 { }
 
 Compiler::~Compiler()
@@ -200,6 +190,14 @@ const map<string, unsigned> &Compiler::get_uniform_block_bindings() const
        return module->shared.uniform_block_bindings;
 }
 
+unsigned Compiler::get_n_clip_distances() const
+{
+       if(!compiled)
+               throw invalid_operation("Compiler::get_n_clip_distances");
+       auto i = find_member(module->stages, Stage::VERTEX, &Stage::type);
+       return (i!=module->stages.end() ? i->n_clip_distances : 0);
+}
+
 const SourceMap &Compiler::get_source_map() const
 {
        return module->source_map;
@@ -278,7 +276,7 @@ void Compiler::import(ModuleCache &mod_cache, const string &name)
 
 void Compiler::generate(Stage &stage)
 {
-       stage.required_features.gl_api = features.gl_api;
+       stage.required_features.target_api = features.target_api;
        if(module->shared.required_features.glsl_version>stage.required_features.glsl_version)
                stage.required_features.glsl_version = module->shared.required_features.glsl_version;
 
@@ -368,6 +366,11 @@ Compiler::OptimizeResult Compiler::optimize(Stage &stage)
                resolve(stage, RESOLVE_TYPES|RESOLVE_VARIABLES|RESOLVE_FUNCTIONS|RESOLVE_EXPRESSIONS);
                any_inlined = true;
        }
+       if(AggregateDismantler().apply(stage))
+       {
+               resolve(stage, RESOLVE_TYPES|RESOLVE_VARIABLES|RESOLVE_FUNCTIONS|RESOLVE_EXPRESSIONS);
+               any_inlined = true;
+       }
        if(ExpressionInliner().apply(stage))
        {
                resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS|RESOLVE_EXPRESSIONS);
@@ -388,7 +391,8 @@ void Compiler::finalize(Stage &stage, Mode mode)
 {
        if(mode==PROGRAM)
        {
-               LegacyConverter().apply(stage, features);
+               StructuralFeatureConverter().apply(stage, features);
+               QualifierConverter().apply(stage, features);
                resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
                PrecisionConverter().apply(stage);
        }