X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Fcompiler.cpp;h=21060cb4b783975f72da2a039de2f6a07b86888f;hp=e6c035775a89b0ff1aaa98464755d031a73fed98;hb=1fa69bb8eec3070f5da296d6dd0bd67aea62d3bf;hpb=a93a69e53263005709fa172845b01f81cd1c074c diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index e6c03577..21060cb4 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -65,17 +65,19 @@ void Compiler::add_shaders(Program &program) { for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) { + string stage_src = Formatter().apply(*i); + if(i->type==Stage::VERTEX) { - program.attach_shader_owned(new VertexShader(apply(*i))); + program.attach_shader_owned(new VertexShader(stage_src)); for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) program.bind_attribute(j->second, j->first); } else if(i->type==Stage::GEOMETRY) - program.attach_shader_owned(new GeometryShader(apply(*i))); + program.attach_shader_owned(new GeometryShader(stage_src)); else if(i->type==Stage::FRAGMENT) { - program.attach_shader_owned(new FragmentShader(apply(*i))); + program.attach_shader_owned(new FragmentShader(stage_src)); if(EXT_gpu_shader4) { for(map::iterator j=i->locations.begin(); j!=i->locations.end(); ++j) @@ -124,10 +126,10 @@ void Compiler::add_shaders(Program &program) void Compiler::append_module(Module &mod) { - vector imports = apply >(mod.shared); + vector imports = NodeGatherer().apply(mod.shared); for(vector::iterator i=imports.begin(); i!=imports.end(); ++i) import((*i)->module); - apply(mod.shared, set(imports.begin(), imports.end())); + NodeRemover(set(imports.begin(), imports.end())).apply(mod.shared); append_stage(mod.shared); for(list::iterator i=mod.stages.begin(); i!=mod.stages.end(); ++i) @@ -160,7 +162,7 @@ void Compiler::append_stage(Stage &stage) target->required_version = stage.required_version; for(NodeList::iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i) target->content.body.push_back(*i); - apply(*target); + DeclarationCombiner().apply(*target); } void Compiler::process() @@ -198,27 +200,27 @@ void Compiler::generate(Stage &stage) stage.required_version = module->shared.required_version; inject_block(stage.content, module->shared.content); - apply(stage); - apply(stage); - apply(stage); - apply(stage); - apply(stage); - apply(stage); - apply(stage); - apply(stage); + DeclarationReorderer().apply(stage); + FunctionResolver().apply(stage); + VariableResolver().apply(stage); + InterfaceGenerator().apply(stage); + VariableResolver().apply(stage); + DeclarationReorderer().apply(stage); + FunctionResolver().apply(stage); + LegacyConverter().apply(stage); } bool Compiler::optimize(Stage &stage) { - apply(stage); + ConstantConditionEliminator().apply(stage); - set inlineable = apply(stage); - apply(stage, inlineable); + set inlineable = InlineableFunctionLocator().apply(stage); + FunctionInliner(inlineable).apply(stage); - set unused = apply(stage); - set unused2 = apply(stage); + set unused = UnusedVariableLocator().apply(stage); + set unused2 = UnusedFunctionLocator().apply(stage); unused.insert(unused2.begin(), unused2.end()); - apply(stage, unused); + NodeRemover(unused).apply(stage); return !unused.empty(); } @@ -226,9 +228,9 @@ bool Compiler::optimize(Stage &stage) void Compiler::finalize(Stage &stage) { if(get_gl_api()==OPENGL_ES2) - apply(stage); + DefaultPrecisionGenerator().apply(stage); else - apply(stage); + PrecisionRemover().apply(stage); } void Compiler::inject_block(Block &target, const Block &source) @@ -238,22 +240,6 @@ void Compiler::inject_block(Block &target, const Block &source) target.body.insert(insert_point, (*i)->clone()); } -template -typename T::ResultType Compiler::apply(Stage &stage) -{ - T visitor; - visitor.apply(stage); - return visitor.get_result(); -} - -template -typename T::ResultType Compiler::apply(Stage &stage, const A &arg) -{ - T visitor(arg); - visitor.apply(stage); - return visitor.get_result(); -} - } // namespace SL } // namespace GL } // namespace Msp