diff options
Diffstat (limited to 'servers/rendering/rendering_device_binds.cpp')
-rw-r--r-- | servers/rendering/rendering_device_binds.cpp | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/servers/rendering/rendering_device_binds.cpp b/servers/rendering/rendering_device_binds.cpp index 111755eba3..0400cebfdc 100644 --- a/servers/rendering/rendering_device_binds.cpp +++ b/servers/rendering/rendering_device_binds.cpp @@ -1,7 +1,36 @@ -#include "rendering_device_binds.h" +/*************************************************************************/ +/* rendering_device_binds.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ -Error RDShaderFile::parse_versions_from_text(const String &p_text, OpenIncludeFunction p_include_func, void *p_include_func_userdata) { +#include "rendering_device_binds.h" +Error RDShaderFile::parse_versions_from_text(const String &p_text, const String p_defines, OpenIncludeFunction p_include_func, void *p_include_func_userdata) { Vector<String> lines = p_text.split("\n"); bool reading_versions = false; @@ -12,7 +41,7 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, OpenIncludeFu "fragment", "tesselation_control", "tesselation_evaluation", - "compute" + "compute", }; String stage_code[RD::SHADER_STAGE_MAX]; int stages_found = 0; @@ -26,11 +55,11 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, OpenIncludeFu { String ls = line.strip_edges(); - 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; @@ -60,27 +89,39 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, OpenIncludeFu } } + if (stage == RD::SHADER_STAGE_MAX && line.strip_edges() != "") { + line = line.strip_edges(); + if (line.begins_with("//") || line.begins_with("/*")) { + continue; //assuming comment (single line) + } + } + if (reading_versions) { String l = line.strip_edges(); if (l != "") { - int eqpos = l.find("="); - if (eqpos == -1) { - base_error = "Version syntax is version=\"<defines with C escaping>\"."; + if (l.find("=") == -1) { + base_error = "Missing `=` in '" + l + "'. Version syntax is `version = \"<defines with C escaping>\";`."; break; } - String version = l.get_slice("=", 0).strip_edges(); + 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 = \"<defines with C escaping>\";`."; + break; + } + Vector<String> 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; + version_texts[version] = define + "\n" + p_defines; } } else { if (stage == RD::SHADER_STAGE_MAX && line.strip_edges() != "") { @@ -108,7 +149,6 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, OpenIncludeFu base_error = "#include used, but no include function provided."; } } else { - stage_code[stage] += line + "\n"; } } @@ -119,7 +159,6 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, OpenIncludeFu shader_file.instance(); if (base_error == "") { - if (stage_found[RD::SHADER_STAGE_COMPUTE] && stages_found > 1) { ERR_FAIL_V_MSG(ERR_PARSE_ERROR, "When writing compute shaders, [compute] mustbe the only stage present."); } @@ -133,7 +172,6 @@ Error RDShaderFile::parse_versions_from_text(const String &p_text, OpenIncludeFu /* STEP 2, Compile the versions, add to shader file */ for (Map<StringName, String>::Element *E = version_texts.front(); E; E = E->next()) { - Ref<RDShaderBytecode> bytecode; bytecode.instance(); |