mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 11:32:13 +00:00
Add renderer state defines to shader preprocessor
This commit is contained in:
parent
61accf0605
commit
e021076b4c
@ -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) {
|
||||
|
@ -132,6 +132,7 @@ private:
|
||||
struct Define {
|
||||
Vector<String> arguments;
|
||||
String body;
|
||||
bool is_builtin = false;
|
||||
};
|
||||
|
||||
struct Branch {
|
||||
|
Loading…
Reference in New Issue
Block a user