Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting a global shader variable in the project settings #69600

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions editor/shader_globals_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,12 @@ static const char *global_var_type_names[RS::GLOBAL_VAR_TYPE_MAX] = {
class ShaderGlobalsEditorInterface : public Object {
GDCLASS(ShaderGlobalsEditorInterface, Object)

void _var_changed() {
emit_signal(SNAME("var_changed"));
}

protected:
static void _bind_methods() {
ClassDB::bind_method("_var_changed", &ShaderGlobalsEditorInterface::_var_changed);
ADD_SIGNAL(MethodInfo("var_changed"));
}

bool _set(const StringName &p_name, const Variant &p_value) {
Variant existing = RS::get_singleton()->global_shader_parameter_get(p_name);

if (existing.get_type() == Variant::NIL) {
return false;
}

void _set_var(const StringName &p_name, const Variant &p_value, const Variant &p_prev_value) {
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();

undo_redo->create_action(TTR("Set Shader Global Variable"));
undo_redo->add_do_method(RS::get_singleton(), "global_shader_parameter_set", p_name, p_value);
undo_redo->add_undo_method(RS::get_singleton(), "global_shader_parameter_set", p_name, existing);
undo_redo->add_undo_method(RS::get_singleton(), "global_shader_parameter_set", p_name, p_prev_value);
RS::GlobalShaderParameterType type = RS::get_singleton()->global_shader_parameter_get_type(p_name);
Dictionary gv;
gv["type"] = global_var_type_names[type];
Expand All @@ -111,8 +95,29 @@ class ShaderGlobalsEditorInterface : public Object {
undo_redo->add_do_method(this, "_var_changed");
undo_redo->add_undo_method(this, "_var_changed");
block_update = true;
undo_redo->commit_action(false);
undo_redo->commit_action();
block_update = false;
}

void _var_changed() {
emit_signal(SNAME("var_changed"));
}

protected:
static void _bind_methods() {
ClassDB::bind_method("_set_var", &ShaderGlobalsEditorInterface::_set_var);
ClassDB::bind_method("_var_changed", &ShaderGlobalsEditorInterface::_var_changed);
ADD_SIGNAL(MethodInfo("var_changed"));
}

bool _set(const StringName &p_name, const Variant &p_value) {
Variant existing = RS::get_singleton()->global_shader_parameter_get(p_name);

if (existing.get_type() == Variant::NIL) {
return false;
}

call_deferred("_set_var", p_name, p_value, existing);

return true;
}
Expand Down