Merge pull request #41837 from m4gr3d/fix_custom_defines_update_logic
Fix the update logic for user-added custom defines.
This commit is contained in:
commit
784e854e58
|
@ -264,7 +264,7 @@ public:
|
||||||
|
|
||||||
void shader_add_custom_define(RID p_shader, const String &p_define) {}
|
void shader_add_custom_define(RID p_shader, const String &p_define) {}
|
||||||
void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const {}
|
void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const {}
|
||||||
void shader_clear_custom_defines(RID p_shader) {}
|
void shader_remove_custom_define(RID p_shader, const String &p_define) {}
|
||||||
|
|
||||||
/* COMMON MATERIAL API */
|
/* COMMON MATERIAL API */
|
||||||
|
|
||||||
|
|
|
@ -1753,12 +1753,12 @@ void RasterizerStorageGLES2::shader_get_custom_defines(RID p_shader, Vector<Stri
|
||||||
shader->shader->get_custom_defines(p_defines);
|
shader->shader->get_custom_defines(p_defines);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerStorageGLES2::shader_clear_custom_defines(RID p_shader) {
|
void RasterizerStorageGLES2::shader_remove_custom_define(RID p_shader, const String &p_define) {
|
||||||
|
|
||||||
Shader *shader = shader_owner.get(p_shader);
|
Shader *shader = shader_owner.get(p_shader);
|
||||||
ERR_FAIL_COND(!shader);
|
ERR_FAIL_COND(!shader);
|
||||||
|
|
||||||
shader->shader->clear_custom_defines();
|
shader->shader->remove_custom_define(p_define);
|
||||||
|
|
||||||
_shader_make_dirty(shader);
|
_shader_make_dirty(shader);
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,7 +543,7 @@ public:
|
||||||
|
|
||||||
virtual void shader_add_custom_define(RID p_shader, const String &p_define);
|
virtual void shader_add_custom_define(RID p_shader, const String &p_define);
|
||||||
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const;
|
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const;
|
||||||
virtual void shader_clear_custom_defines(RID p_shader);
|
virtual void shader_remove_custom_define(RID p_shader, const String &p_define);
|
||||||
|
|
||||||
void _update_shader(Shader *p_shader) const;
|
void _update_shader(Shader *p_shader) const;
|
||||||
void update_dirty_shaders();
|
void update_dirty_shaders();
|
||||||
|
|
|
@ -252,8 +252,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_custom_defines() {
|
void remove_custom_define(const String &p_define) {
|
||||||
custom_defines.clear();
|
custom_defines.erase(p_define.utf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~ShaderGLES2();
|
virtual ~ShaderGLES2();
|
||||||
|
|
|
@ -2584,12 +2584,12 @@ void RasterizerStorageGLES3::shader_get_custom_defines(RID p_shader, Vector<Stri
|
||||||
shader->shader->get_custom_defines(p_defines);
|
shader->shader->get_custom_defines(p_defines);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerStorageGLES3::shader_clear_custom_defines(RID p_shader) {
|
void RasterizerStorageGLES3::shader_remove_custom_define(RID p_shader, const String &p_define) {
|
||||||
|
|
||||||
Shader *shader = shader_owner.get(p_shader);
|
Shader *shader = shader_owner.get(p_shader);
|
||||||
ERR_FAIL_COND(!shader);
|
ERR_FAIL_COND(!shader);
|
||||||
|
|
||||||
shader->shader->clear_custom_defines();
|
shader->shader->remove_custom_define(p_define);
|
||||||
|
|
||||||
_shader_make_dirty(shader);
|
_shader_make_dirty(shader);
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,7 +539,7 @@ public:
|
||||||
|
|
||||||
virtual void shader_add_custom_define(RID p_shader, const String &p_define);
|
virtual void shader_add_custom_define(RID p_shader, const String &p_define);
|
||||||
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const;
|
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const;
|
||||||
virtual void shader_clear_custom_defines(RID p_shader);
|
virtual void shader_remove_custom_define(RID p_shader, const String &p_define);
|
||||||
|
|
||||||
void _update_shader(Shader *p_shader) const;
|
void _update_shader(Shader *p_shader) const;
|
||||||
|
|
||||||
|
|
|
@ -374,8 +374,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_custom_defines() {
|
void remove_custom_define(const String &p_define) {
|
||||||
custom_defines.clear();
|
custom_defines.erase(p_define.utf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~ShaderGLES3();
|
virtual ~ShaderGLES3();
|
||||||
|
|
|
@ -128,24 +128,20 @@ void Shader::get_default_texture_param_list(List<StringName> *r_textures) const
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::set_custom_defines(const String &p_defines) {
|
void Shader::set_custom_defines(const String &p_defines) {
|
||||||
|
if (shader_custom_defines == p_defines) {
|
||||||
VS::get_singleton()->shader_clear_custom_defines(shader);
|
return;
|
||||||
VS::get_singleton()->shader_add_custom_define(shader, p_defines);
|
|
||||||
}
|
|
||||||
|
|
||||||
String Shader::get_custom_defines() {
|
|
||||||
Vector<String> custom_defines;
|
|
||||||
VS::get_singleton()->shader_get_custom_defines(shader, &custom_defines);
|
|
||||||
|
|
||||||
String concatenated_defines;
|
|
||||||
for (int i = 0; i < custom_defines.size(); i++) {
|
|
||||||
if (i != 0) {
|
|
||||||
concatenated_defines += "\n";
|
|
||||||
}
|
|
||||||
concatenated_defines += custom_defines[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return concatenated_defines;
|
if (!shader_custom_defines.empty()) {
|
||||||
|
VS::get_singleton()->shader_remove_custom_define(shader, shader_custom_defines);
|
||||||
|
}
|
||||||
|
|
||||||
|
shader_custom_defines = p_defines;
|
||||||
|
VS::get_singleton()->shader_add_custom_define(shader, shader_custom_defines);
|
||||||
|
}
|
||||||
|
|
||||||
|
String Shader::get_custom_defines() const {
|
||||||
|
return shader_custom_defines;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Shader::is_text_shader() const {
|
bool Shader::is_text_shader() const {
|
||||||
|
|
|
@ -53,6 +53,7 @@ public:
|
||||||
private:
|
private:
|
||||||
RID shader;
|
RID shader;
|
||||||
Mode mode;
|
Mode mode;
|
||||||
|
String shader_custom_defines;
|
||||||
|
|
||||||
// hack the name of performance
|
// hack the name of performance
|
||||||
// shaders keep a list of ShaderMaterial -> VisualServer name translations, to make
|
// shaders keep a list of ShaderMaterial -> VisualServer name translations, to make
|
||||||
|
@ -80,7 +81,7 @@ public:
|
||||||
void get_default_texture_param_list(List<StringName> *r_textures) const;
|
void get_default_texture_param_list(List<StringName> *r_textures) const;
|
||||||
|
|
||||||
void set_custom_defines(const String &p_defines);
|
void set_custom_defines(const String &p_defines);
|
||||||
String get_custom_defines();
|
String get_custom_defines() const;
|
||||||
|
|
||||||
virtual bool is_text_shader() const;
|
virtual bool is_text_shader() const;
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,7 @@ public:
|
||||||
|
|
||||||
virtual void shader_add_custom_define(RID p_shader, const String &p_define) = 0;
|
virtual void shader_add_custom_define(RID p_shader, const String &p_define) = 0;
|
||||||
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const = 0;
|
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const = 0;
|
||||||
virtual void shader_clear_custom_defines(RID p_shader) = 0;
|
virtual void shader_remove_custom_define(RID p_shader, const String &p_define) = 0;
|
||||||
|
|
||||||
/* COMMON MATERIAL API */
|
/* COMMON MATERIAL API */
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ public:
|
||||||
|
|
||||||
BIND2(shader_add_custom_define, RID, const String &)
|
BIND2(shader_add_custom_define, RID, const String &)
|
||||||
BIND2C(shader_get_custom_defines, RID, Vector<String> *)
|
BIND2C(shader_get_custom_defines, RID, Vector<String> *)
|
||||||
BIND1(shader_clear_custom_defines, RID)
|
BIND2(shader_remove_custom_define, RID, const String &)
|
||||||
|
|
||||||
/* COMMON MATERIAL API */
|
/* COMMON MATERIAL API */
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ public:
|
||||||
|
|
||||||
FUNC2(shader_add_custom_define, RID, const String &)
|
FUNC2(shader_add_custom_define, RID, const String &)
|
||||||
FUNC2SC(shader_get_custom_defines, RID, Vector<String> *)
|
FUNC2SC(shader_get_custom_defines, RID, Vector<String> *)
|
||||||
FUNC1(shader_clear_custom_defines, RID)
|
FUNC2(shader_remove_custom_define, RID, const String &)
|
||||||
|
|
||||||
/* COMMON MATERIAL API */
|
/* COMMON MATERIAL API */
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ public:
|
||||||
|
|
||||||
virtual void shader_add_custom_define(RID p_shader, const String &p_define) = 0;
|
virtual void shader_add_custom_define(RID p_shader, const String &p_define) = 0;
|
||||||
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const = 0;
|
virtual void shader_get_custom_defines(RID p_shader, Vector<String> *p_defines) const = 0;
|
||||||
virtual void shader_clear_custom_defines(RID p_shader) = 0;
|
virtual void shader_remove_custom_define(RID p_shader, const String &p_define) = 0;
|
||||||
|
|
||||||
/* COMMON MATERIAL API */
|
/* COMMON MATERIAL API */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue