]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Implement constant folding in the GLSL compiler
[libs/gl.git] / source / glsl / compiler.cpp
index c5f0a9a3d05b6fd640f9afe5a5cba5a05e0ec5ab..e9933e2f9b67c4ec414999438a9e8c1c0ec60ba9 100644 (file)
@@ -108,7 +108,7 @@ string Compiler::get_combined_glsl() const
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
        {
                glsl += format("#pragma MSP stage(%s)\n", Stage::get_stage_name(i->type));
-               glsl += Formatter().apply(*i, MODULE);
+               glsl += Formatter().apply(*i);
                glsl += '\n';
        }
 
@@ -128,7 +128,7 @@ string Compiler::get_stage_glsl(Stage::Type stage_type) const
 {
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
                if(i->type==stage_type)
-                       return Formatter().apply(*i, PROGRAM);
+                       return Formatter().apply(*i);
        throw key_error(Stage::get_stage_name(stage_type));
 }
 
@@ -214,7 +214,6 @@ void Compiler::append_stage(Stage &stage)
                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)
                target->content.body.push_back(*i);
-       DeclarationCombiner().apply(*target);
 }
 
 void Compiler::import(DataFile::Collection *resources, const string &name)
@@ -319,6 +318,8 @@ bool Compiler::diagnostic_line_order(const Diagnostic &diag1, const Diagnostic &
 
 Compiler::OptimizeResult Compiler::optimize(Stage &stage)
 {
+       if(ConstantFolder().apply(stage))
+               resolve(stage, RESOLVE_EXPRESSIONS);
        ConstantConditionEliminator().apply(stage);
 
        bool any_inlined = false;