@@ -816,6 +816,11 @@ void ShaderPreprocessor::process_undef(Tokenizer *p_tokenizer) {
816816 }
817817
818818 if (state->defines .has (label)) {
819+ if (state->defines [label]->is_builtin ) {
820+ set_error (vformat (RTR (" Cannot use '%s' on built-in define." ), " undef" ), line);
821+ return ;
822+ }
823+
819824 memdelete (state->defines [label]);
820825 state->defines .erase (label);
821826 }
@@ -1324,6 +1329,35 @@ Error ShaderPreprocessor::preprocess(const String &p_code, const String &p_filen
13241329 pp_state.current_filename = p_filename;
13251330 pp_state.save_regions = r_regions != nullptr ;
13261331 }
1332+
1333+ // Built-in defines.
1334+ {
1335+ static HashMap<StringName, String> defines;
1336+
1337+ if (defines.is_empty ()) {
1338+ const String rendering_method = OS::get_singleton ()->get_current_rendering_method ();
1339+
1340+ if (rendering_method == " forward_plus" ) {
1341+ defines[" CURRENT_RENDERER" ] = _MKSTR (2 );
1342+ } else if (rendering_method == " mobile" ) {
1343+ defines[" CURRENT_RENDERER" ] = _MKSTR (1 );
1344+ } else { // gl_compatibility
1345+ defines[" CURRENT_RENDERER" ] = _MKSTR (0 );
1346+ }
1347+
1348+ defines[" RENDERER_COMPATIBILITY" ] = _MKSTR (0 );
1349+ defines[" RENDERER_MOBILE" ] = _MKSTR (1 );
1350+ defines[" RENDERER_FORWARD_PLUS" ] = _MKSTR (2 );
1351+ }
1352+
1353+ for (const KeyValue<StringName, String> &E : defines) {
1354+ Define *define = memnew (Define);
1355+ define->is_builtin = true ;
1356+ define->body = E.value ;
1357+ pp_state.defines [E.key ] = define;
1358+ }
1359+ }
1360+
13271361 Error err = preprocess (&pp_state, p_code, r_result);
13281362 if (err != OK) {
13291363 if (r_error_text) {
0 commit comments