X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramcompiler.cpp;h=6b8eb6e6135ddb68702537cbc4d3c9b626a341c1;hb=ff072e148afae24018696c03a413c9ae2da6c929;hp=13b203b4f4ace5e93fbf5c27a155d94ffe540c51;hpb=eb4f947bcd825230cfa0f1f27046d9c729435d6e;p=libs%2Fgl.git diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 13b203b4..6b8eb6e6 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -228,9 +228,23 @@ ProgramCompiler::Formatter::Formatter(): void ProgramCompiler::Formatter::apply(ProgramSyntax::Stage &s) { + GLApi api = get_gl_api(); const Version &ver = s.required_version; + if(ver.major) - formatted += format("#version %d%d\n", ver.major, ver.minor); + { + formatted += format("#version %d%d", ver.major, ver.minor); + if(api==OPENGL_ES2 && ver>=Version(3, 0)) + formatted += " es"; + formatted += '\n'; + } + + if(api==OPENGL_ES2) + { + if(s.type==FRAGMENT) + formatted += "precision mediump float;\n"; + } + Visitor::apply(s); } @@ -368,7 +382,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) { @@ -1447,7 +1471,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); } @@ -1484,14 +1508,18 @@ void ProgramCompiler::NodeRemover::visit(VariableDeclaration &var) ProgramCompiler::LegacyConverter::LegacyConverter(): - target_version(get_glsl_version()) + target_api(get_gl_api()), + target_version(get_glsl_version()), + frag_out(0) { } ProgramCompiler::LegacyConverter::LegacyConverter(const Version &v): - target_version(v) + target_api(get_gl_api()), + target_version(v), + frag_out(0) { } -bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_version) +bool ProgramCompiler::LegacyConverter::check_version(const Version &feature_version) const { if(target_version >::iterator i = call.arguments.begin(); if(i!=call.arguments.end()) @@ -1542,9 +1593,17 @@ void ProgramCompiler::LegacyConverter::visit(FunctionCall &call) TraversingVisitor::visit(call); } +bool ProgramCompiler::LegacyConverter::supports_interface_layouts() const +{ + if(target_api==OPENGL_ES2) + return check_version(Version(3, 0)); + else + return check_version(Version(3, 30)); +} + void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var) { - if(var.layout && !check_version(Version(3, 30))) + if(var.layout && !supports_interface_layouts()) { vector::iterator i; for(i=var.layout->qualifiers.begin(); (i!=var.layout->qualifiers.end() && i->identifier!="location"); ++i) ; @@ -1567,15 +1626,11 @@ void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var) } } - if((var.interface=="in" || var.interface=="out") && !check_version(Version(1, 30))) + if((var.interface=="in" || var.interface=="out") && !supports_unified_interface_syntax()) { - 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; } } @@ -1583,9 +1638,22 @@ void ProgramCompiler::LegacyConverter::visit(VariableDeclaration &var) TraversingVisitor::visit(var); } +bool ProgramCompiler::LegacyConverter::supports_interface_blocks(const string &iface) const +{ + if(target_api==OPENGL_ES2) + { + if(iface=="uniform") + return check_version(Version(3, 0)); + else + return check_version(Version(3, 20)); + } + else + return check_version(Version(1, 50)); +} + void ProgramCompiler::LegacyConverter::visit(InterfaceBlock &iface) { - if(!check_version(Version(1, 50))) + if(!supports_interface_blocks(iface.interface)) flatten_block(iface.members); }