]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Process loop initialization outside the body in UnusedVariableRemover
[libs/gl.git] / source / glsl / compiler.cpp
index 233e37ea33727814042069dd7df2b068abed7670..e658a79ea98c2adc7c469b092f43ca84da9db161 100644 (file)
@@ -25,17 +25,11 @@ namespace GL {
 namespace SL {
 
 Compiler::Compiler():
-       features(DeviceInfo::get_global().glsl_features),
-       module(0),
-       compiled(false),
-       specialized(false)
+       features(DeviceInfo::get_global().glsl_features)
 { }
 
 Compiler::Compiler(const Features &f):
-       features(f),
-       module(0),
-       compiled(false),
-       specialized(false)
+       features(f)
 { }
 
 Compiler::~Compiler()
@@ -201,6 +195,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;
@@ -279,7 +281,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;
 
@@ -369,6 +371,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);