summaryrefslogtreecommitdiffstats
path: root/servers
diff options
context:
space:
mode:
authorThaddeus Crews <repiteo@outlook.com>2024-11-10 12:13:04 -0600
committerThaddeus Crews <repiteo@outlook.com>2024-11-10 12:13:04 -0600
commit9dfb36ca0cf650a3809d9e70e64aacac422486ee (patch)
treeaa9a73ccee4b273096e611d29204bf7b365f869c /servers
parent6bbc1cb6a9f906123a991a7abfd1dc5108b5def0 (diff)
parente021076b4c75b221fd496906aeaea3d2d9cf07d5 (diff)
downloadredot-engine-9dfb36ca0cf650a3809d9e70e64aacac422486ee.tar.gz
Merge pull request #98549 from Chaosus/shader_renderer_states
Add renderer state defines to shader preprocessor
Diffstat (limited to 'servers')
-rw-r--r--servers/rendering/shader_preprocessor.cpp34
-rw-r--r--servers/rendering/shader_preprocessor.h1
2 files changed, 35 insertions, 0 deletions
diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp
index 0e41a178b5..88ea74cdfc 100644
--- a/servers/rendering/shader_preprocessor.cpp
+++ b/servers/rendering/shader_preprocessor.cpp
@@ -816,6 +816,11 @@ void ShaderPreprocessor::process_undef(Tokenizer *p_tokenizer) {
}
if (state->defines.has(label)) {
+ if (state->defines[label]->is_builtin) {
+ set_error(vformat(RTR("Cannot use '%s' on built-in define."), "undef"), line);
+ return;
+ }
+
memdelete(state->defines[label]);
state->defines.erase(label);
}
@@ -1324,6 +1329,35 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen
pp_state.current_filename = p_filename;
pp_state.save_regions = r_regions != nullptr;
}
+
+ // Built-in defines.
+ {
+ static HashMap<StringName, String> defines;
+
+ 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);
+ }
+
+ 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;
+ }
+ }
+
Error err = preprocess(&pp_state, p_code, r_result);
if (err != OK) {
if (r_error_text) {
diff --git a/servers/rendering/shader_preprocessor.h b/servers/rendering/shader_preprocessor.h
index 0a90aec958..b3d9594bcb 100644
--- a/servers/rendering/shader_preprocessor.h
+++ b/servers/rendering/shader_preprocessor.h
@@ -132,6 +132,7 @@ private:
struct Define {
Vector<String> arguments;
String body;
+ bool is_builtin = false;
};
struct Branch {