X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramcompiler.cpp;h=fd27839da25e1f7cb377a7fdf46079bfb1e862f3;hb=ad3238a5acffa0f200a550c5668c18d931d1c569;hp=cc4b5efe3df0bfca482feb8d9ae3f46e46391d42;hpb=4fe225bf15048fcb7a678370f87d09f2de37031a;p=libs%2Fgl.git diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index cc4b5efe..fd27839d 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -368,7 +368,17 @@ void ProgramCompiler::Formatter::visit(VariableDeclaration &var) if(!var.sampling.empty()) formatted += format("%s ", var.sampling); if(!var.interface.empty() && var.interface!=block_interface) - formatted += format("%s ", var.interface); + { + string interface = var.interface; + if(stage->required_versiontype==VERTEX && var.interface=="in") + interface = "attribute"; + else if((stage->type==VERTEX && var.interface=="out") || (stage->type==FRAGMENT && var.interface=="in")) + interface = "varying"; + } + formatted += format("%s ", interface); + } formatted += format("%s %s", var.type, var.name); if(var.array) { @@ -1346,6 +1356,8 @@ void ProgramCompiler::UnusedVariableLocator::visit(FunctionDeclaration &func) BlockVariableMap &block_variables = variables.back(); for(BlockVariableMap::iterator i=block_variables.begin(); i!=block_variables.end(); ++i) i->second.conditionally_assigned = true; + for(vector >::iterator i=func.parameters.begin(); i!=func.parameters.end(); ++i) + block_variables[i->get()].referenced = true; merge_down_variables(); } @@ -1445,7 +1457,7 @@ void ProgramCompiler::UnusedFunctionLocator::visit(FunctionDeclaration &func) { TraversingVisitor::visit(func); - if(func.name!="main" && !used_definitions.count(&func)) + if((func.name!="main" || func.body.body.empty()) && !used_definitions.count(&func)) unused_nodes.insert(&func); } @@ -1482,11 +1494,13 @@ void ProgramCompiler::NodeRemover::visit(VariableDeclaration &var) ProgramCompiler::LegacyConverter::LegacyConverter(): - target_version(get_glsl_version()) + target_version(get_glsl_version()), + frag_out(0) { } ProgramCompiler::LegacyConverter::LegacyConverter(const Version &v): - target_version(v) + target_version(v), + frag_out(0) { } bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_version) @@ -1501,7 +1515,7 @@ bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_vers void ProgramCompiler::LegacyConverter::visit(VariableReference &var) { - if(var.name==frag_out_name && !check_version(Version(1, 30))) + if(var.declaration==frag_out && !check_version(Version(1, 30))) { var.name = "gl_FragColor"; var.declaration = 0; @@ -1513,6 +1527,13 @@ void ProgramCompiler::LegacyConverter::visit(VariableReference &var) type = string(); } +void ProgramCompiler::LegacyConverter::visit(Assignment &assign) +{ + TraversingVisitor::visit(assign); + if(assign.target_declaration==frag_out && !check_version(Version(1, 30))) + assign.target_declaration = 0; +} + void ProgramCompiler::LegacyConverter::visit(FunctionCall &call) { if(call.name=="texture" && !call.declaration && !check_version(Version(1, 30))) @@ -1567,13 +1588,9 @@ void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var) if((var.interface=="in" || var.interface=="out") && !check_version(Version(1, 30))) { - if(stage->type==VERTEX && var.interface=="in") - var.interface = "attribute"; - else if((stage->type==VERTEX && var.interface=="out") || (stage->type==FRAGMENT && var.interface=="in")) - var.interface = "varying"; - else if(stage->type==FRAGMENT && var.interface=="out") + if(stage->type==FRAGMENT && var.interface=="out") { - frag_out_name = var.name; + frag_out = &var; remove_node = true; } }