From: Mikko Rasa Date: Thu, 11 Jul 2019 22:22:59 +0000 (+0300) Subject: Recognize #version directive in GLSL X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=53dac3ba3cb3a1e4ed23d5fa459187acde7a4904 Recognize #version directive in GLSL This allows shaders to explicitly specify the required version in case there's a feature which is not detected by the program compiler framework. --- diff --git a/source/programcompiler.cpp b/source/programcompiler.cpp index 989098d7..f30ccfa6 100644 --- a/source/programcompiler.cpp +++ b/source/programcompiler.cpp @@ -209,6 +209,8 @@ void ProgramCompiler::append_stage(Stage &stage) target = &*i; } + if(stage.required_version>target->required_version) + 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); @@ -245,6 +247,8 @@ void ProgramCompiler::import(const string &name) void ProgramCompiler::generate(Stage &stage) { + if(module->shared.required_version>stage.required_version) + stage.required_version = module->shared.required_version; inject_block(stage.content, module->shared.content); apply(stage); diff --git a/source/programparser.cpp b/source/programparser.cpp index ca554f42..7477f38b 100644 --- a/source/programparser.cpp +++ b/source/programparser.cpp @@ -369,8 +369,10 @@ void ProgramParser::preprocess() string token = peek_token(); if(token=="pragma") preprocess_pragma(); + else if(token=="version") + preprocess_version(); else if(token=="define" || token=="undef" || token=="if" || token=="ifdef" || token=="ifndef" || token=="else" || - token=="elif" || token=="endif" || token=="error" || token=="extension" || token=="version" || token=="line") + token=="elif" || token=="endif" || token=="error" || token=="extension" || token=="line") throw runtime_error(format_error(format("Unsupported preprocessor directive '%s'", token))); else if(!token.empty()) throw runtime_error(format_syntax_error("a preprocessor directive")); @@ -378,6 +380,18 @@ void ProgramParser::preprocess() iter = line_end; } +void ProgramParser::preprocess_version() +{ + expect("version"); + string token = parse_token(); + unsigned version = lexical_cast(token); + cur_stage->required_version = Version(version/100, version%100); + + token = parse_token(); + if(!token.empty()) + throw runtime_error(format_syntax_error("end of line")); +} + void ProgramParser::preprocess_pragma() { expect("pragma"); diff --git a/source/programparser.h b/source/programparser.h index dc94bd00..e3660473 100644 --- a/source/programparser.h +++ b/source/programparser.h @@ -87,6 +87,7 @@ private: bool is_identifier(const std::string &); void preprocess(); + void preprocess_version(); void preprocess_pragma(); void preprocess_pragma_msp(); void preprocess_stage();