From c74d65cec84532d14d39be970438516c2b9f6c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 18 May 2020 10:56:22 +0200 Subject: GLSL: Change shader type specifier from [vertex] to #[vertex] The added `#` prevents clang-format from misinterpreting the meaning of this statement and thus messing up the formatting of the next lines up until the first `layout` statement. Similarly, a semicolon is now enforced on `versions` defines to prevent clang-format from messing up formatting and putting them all on a single line. Note: In its current state the code will ignore chained statements on a single line separated by a semicolon. Also removed some extraneous lines missed in previous style changes or added by mistake with said changes (e.g. after uniform definitions that clang-format messes up somewhat too, but we live with it). --- servers/rendering/rendering_device_binds.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'servers/rendering/rendering_device_binds.cpp') diff --git a/servers/rendering/rendering_device_binds.cpp b/servers/rendering/rendering_device_binds.cpp index 2936843a9c..291f2ff705 100644 --- a/servers/rendering/rendering_device_binds.cpp +++ b/servers/rendering/rendering_device_binds.cpp @@ -41,7 +41,7 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, const String "fragment", "tesselation_control", "tesselation_evaluation", - "compute" + "compute", }; String stage_code[RD::SHADER_STAGE_MAX]; int stages_found = 0; @@ -55,14 +55,11 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, const String { String ls = line.strip_edges(); - if (ls.begins_with("#[")) { //workaround for clang format - ls = ls.replace_first("#[", "["); - } - if (ls.begins_with("[") && ls.ends_with("]")) { - String section = ls.substr(1, ls.length() - 2).strip_edges(); + if (ls.begins_with("#[") && ls.ends_with("]")) { + String section = ls.substr(2, ls.length() - 3).strip_edges(); if (section == "versions") { if (stages_found) { - base_error = "Invalid shader file, [version] must be the first section found."; + base_error = "Invalid shader file, #[versions] must be the first section found."; break; } reading_versions = true; @@ -102,22 +99,27 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, const String if (reading_versions) { String l = line.strip_edges(); if (l != "") { - int eqpos = l.find("="); - if (eqpos == -1) { - base_error = "Version syntax is version=\"\"."; + if (l.find("=") == -1) { + base_error = "Missing `=` in '" + l + "'. Version syntax is `version = \"\";`."; + break; + } + if (l.find(";") != -1) { + // We don't require a semicolon per se, but it's needed for clang-format to handle things properly. + base_error = "Missing `;` in '" + l + "'. Version syntax is `version = \"\";`."; break; } - String version = l.get_slice("=", 0).strip_edges(); + Vector slices = l.get_slice(";", 0).split("="); + String version = slices[0].strip_edges(); if (!version.is_valid_identifier()) { base_error = "Version names must be valid identifiers, found '" + version + "' instead."; break; } - String define = l.get_slice("=", 1).strip_edges(); + String define = slices[1].strip_edges(); if (!define.begins_with("\"") || !define.ends_with("\"")) { base_error = "Version text must be quoted using \"\", instead found '" + define + "'."; break; } - define = "\n" + define.substr(1, define.length() - 2).c_unescape() + "\n"; //add newline before and after jsut in case + define = "\n" + define.substr(1, define.length() - 2).c_unescape() + "\n"; // Add newline before and after just in case. version_texts[version] = define + "\n" + p_defines; } -- cgit v1.2.3