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 the update logic for user-added custom defines. #41837

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion drivers/dummy/rasterizer_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class RasterizerStorageDummy : public RasterizerStorage {

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_clear_custom_defines(RID p_shader) {}
void shader_remove_custom_define(RID p_shader, const String &p_define) {}

/* COMMON MATERIAL API */

Expand Down
4 changes: 2 additions & 2 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,12 +1753,12 @@ void RasterizerStorageGLES2::shader_get_custom_defines(RID p_shader, Vector<Stri
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);
ERR_FAIL_COND(!shader);

shader->shader->clear_custom_defines();
shader->shader->remove_custom_define(p_define);

_shader_make_dirty(shader);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_storage_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class RasterizerStorageGLES2 : public RasterizerStorage {

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_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_dirty_shaders();
Expand Down
4 changes: 2 additions & 2 deletions drivers/gles2/shader_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ class ShaderGLES2 {
}
}

void clear_custom_defines() {
custom_defines.clear();
void remove_custom_define(const String &p_define) {
custom_defines.erase(p_define.utf8());
}

virtual ~ShaderGLES2();
Expand Down
4 changes: 2 additions & 2 deletions drivers/gles3/rasterizer_storage_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2584,12 +2584,12 @@ void RasterizerStorageGLES3::shader_get_custom_defines(RID p_shader, Vector<Stri
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);
ERR_FAIL_COND(!shader);

shader->shader->clear_custom_defines();
shader->shader->remove_custom_define(p_define);

_shader_make_dirty(shader);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/rasterizer_storage_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class RasterizerStorageGLES3 : public RasterizerStorage {

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_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;

Expand Down
4 changes: 2 additions & 2 deletions drivers/gles3/shader_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ class ShaderGLES3 {
}
}

void clear_custom_defines() {
custom_defines.clear();
void remove_custom_define(const String &p_define) {
custom_defines.erase(p_define.utf8());
}

virtual ~ShaderGLES3();
Expand Down
26 changes: 11 additions & 15 deletions scene/resources/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (shader_custom_defines == p_defines) {
return;
}

VS::get_singleton()->shader_clear_custom_defines(shader);
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];
if (!shader_custom_defines.empty()) {
VS::get_singleton()->shader_remove_custom_define(shader, shader_custom_defines);
}

return concatenated_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 {
Expand Down
3 changes: 2 additions & 1 deletion scene/resources/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Shader : public Resource {
private:
RID shader;
Mode mode;
String shader_custom_defines;

// hack the name of performance
// shaders keep a list of ShaderMaterial -> VisualServer name translations, to make
Expand Down Expand Up @@ -80,7 +81,7 @@ class Shader : public Resource {
void get_default_texture_param_list(List<StringName> *r_textures) const;

void set_custom_defines(const String &p_defines);
String get_custom_defines();
String get_custom_defines() const;

virtual bool is_text_shader() const;

Expand Down
2 changes: 1 addition & 1 deletion servers/visual/rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class RasterizerStorage {

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_clear_custom_defines(RID p_shader) = 0;
virtual void shader_remove_custom_define(RID p_shader, const String &p_define) = 0;

/* COMMON MATERIAL API */

Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_raster.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class VisualServerRaster : public VisualServer {

BIND2(shader_add_custom_define, RID, const 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 */

Expand Down
2 changes: 1 addition & 1 deletion servers/visual/visual_server_wrap_mt.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class VisualServerWrapMT : public VisualServer {

FUNC2(shader_add_custom_define, RID, const 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 */

Expand Down
2 changes: 1 addition & 1 deletion servers/visual_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class VisualServer : public Object {

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_clear_custom_defines(RID p_shader) = 0;
virtual void shader_remove_custom_define(RID p_shader, const String &p_define) = 0;

/* COMMON MATERIAL API */

Expand Down