X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramcompiler.cpp;h=bc021c97b04874ccf375d82383218da4d9a4b4d7;hb=a29cc14162e911b36d18d1d1896216697c7dc0c1;hp=2dae07c8f4d3ecc049c153e66de8793d347e3134;hpb=fd103d76d7546f7e22aefc18c090a844fc67409f;p=libs%2Fgl.git diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 2dae07c8..bc021c97 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -35,12 +35,15 @@ void ProgramCompiler::add_shaders(Program &program) throw invalid_operation("ProgramCompiler::add_shaders"); string head = "#version 150\n"; - if(module->vertex_stage.present) - program.attach_shader_owned(new VertexShader(head+format_stage(module->vertex_stage))); - if(module->geometry_stage.present) - program.attach_shader_owned(new GeometryShader(head+format_stage(module->geometry_stage))); - if(module->fragment_stage.present) - program.attach_shader_owned(new FragmentShader(head+format_stage(module->fragment_stage))); + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + { + if(i->type==VERTEX) + program.attach_shader_owned(new VertexShader(head+create_source(*i))); + else if(i->type==GEOMETRY) + program.attach_shader_owned(new GeometryShader(head+create_source(*i))); + else if(i->type==FRAGMENT) + program.attach_shader_owned(new FragmentShader(head+create_source(*i))); + } program.bind_attribute(VERTEX4, "vertex"); program.bind_attribute(NORMAL3, "normal"); @@ -50,19 +53,10 @@ void ProgramCompiler::add_shaders(Program &program) void ProgramCompiler::process() { - if(module->vertex_stage.present) - generate(module->vertex_stage); - if(module->geometry_stage.present) - generate(module->geometry_stage); - if(module->fragment_stage.present) - generate(module->fragment_stage); - - if(module->vertex_stage.present) - optimize(module->vertex_stage); - if(module->geometry_stage.present) - optimize(module->geometry_stage); - if(module->fragment_stage.present) - optimize(module->fragment_stage); + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + generate(*i); + for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) + optimize(*i); } void ProgramCompiler::generate(Stage &stage) @@ -109,7 +103,7 @@ void ProgramCompiler::resolve_variables(Stage &stage) stage.content.visit(resolver); } -string ProgramCompiler::format_stage(Stage &stage) +string ProgramCompiler::create_source(Stage &stage) { Formatter formatter; stage.content.visit(formatter);