summaryrefslogtreecommitdiffstats
path: root/servers
diff options
context:
space:
mode:
authorChaosus <chaosus89@gmail.com>2024-10-26 12:31:01 +0300
committerChaosus <chaosus89@gmail.com>2024-10-26 13:49:55 +0300
commite021076b4c75b221fd496906aeaea3d2d9cf07d5 (patch)
tree471fa8e89091214cc1170c1c054330d7986d214e /servers
parent61accf060515416da07d913580419fd8c8490f7b (diff)
downloadredot-engine-e021076b4c75b221fd496906aeaea3d2d9cf07d5.tar.gz
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 {