Fix orphan strings in shader preprocessor

This commit is contained in:
Chaosus 2024-11-26 11:59:52 +03:00
parent 9aed9eca40
commit 5a48e527b2
4 changed files with 25 additions and 27 deletions

View file

@ -1236,6 +1236,13 @@ ShaderPreprocessor::Define *ShaderPreprocessor::create_define(const String &p_bo
return define;
}
void ShaderPreprocessor::insert_builtin_define(String p_name, String p_value, State &p_state) {
Define *define = memnew(Define);
define->is_builtin = true;
define->body = p_value;
p_state.defines[p_name] = define;
}
void ShaderPreprocessor::clear_state() {
if (state != nullptr) {
for (const RBMap<String, Define *>::Element *E = state->defines.front(); E; E = E->next()) {
@ -1332,30 +1339,19 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen
// Built-in defines.
{
static HashMap<StringName, String> defines;
const String rendering_method = OS::get_singleton()->get_current_rendering_method();
if (defines.is_empty()) {
const String rendering_method = OS::get_singleton()->get_current_rendering_method();
if (rendering_method == "forward_plus") {
defines["CURRENT_RENDERER"] = _MKSTR(2);
} else if (rendering_method == "mobile") {
defines["CURRENT_RENDERER"] = _MKSTR(1);
} else { // gl_compatibility
defines["CURRENT_RENDERER"] = _MKSTR(0);
}
defines["RENDERER_COMPATIBILITY"] = _MKSTR(0);
defines["RENDERER_MOBILE"] = _MKSTR(1);
defines["RENDERER_FORWARD_PLUS"] = _MKSTR(2);
if (rendering_method == "forward_plus") {
insert_builtin_define("CURRENT_RENDERER", _MKSTR(2), pp_state);
} else if (rendering_method == "mobile") {
insert_builtin_define("CURRENT_RENDERER", _MKSTR(1), pp_state);
} else { // gl_compatibility
insert_builtin_define("CURRENT_RENDERER", _MKSTR(0), pp_state);
}
for (const KeyValue<StringName, String> &E : defines) {
Define *define = memnew(Define);
define->is_builtin = true;
define->body = E.value;
pp_state.defines[E.key] = define;
}
insert_builtin_define("RENDERER_COMPATIBILITY", _MKSTR(0), pp_state);
insert_builtin_define("RENDERER_MOBILE", _MKSTR(1), pp_state);
insert_builtin_define("RENDERER_FORWARD_PLUS", _MKSTR(2), pp_state);
}
Error err = preprocess(&pp_state, p_code, r_result);