summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2021-10-17 14:38:26 +0300
committerYuri Roubinsky <chaosus89@gmail.com>2021-11-12 12:53:40 +0300
commit826e781bfa90f55eed579e9b512a19b0c1c19ba4 (patch)
tree5c6f1a88cfed28ab09ff3e959e1c724dcdbebae1 /drivers
parent13769aebe9d435b9041f4ec8dc6f4b277a87b444 (diff)
Fix default_texture_param in shader pipeline to support uniform arrays
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp34
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.h6
2 files changed, 24 insertions, 16 deletions
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 8a070313f8..4759a2b0d0 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -1871,31 +1871,38 @@ void RasterizerStorageGLES3::shader_get_param_list(RID p_shader, List<PropertyIn
}
}
-void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
+void RasterizerStorageGLES3::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) {
Shader *shader = shader_owner.get_or_null(p_shader);
ERR_FAIL_COND(!shader);
ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
- if (p_texture.is_valid()) {
- shader->default_textures[p_name] = p_texture;
+ if (!p_texture.is_valid()) {
+ if (shader->default_textures.has(p_name) && shader->default_textures[p_name].has(p_index)) {
+ shader->default_textures[p_name].erase(p_index);
+
+ if (shader->default_textures[p_name].is_empty()) {
+ shader->default_textures.erase(p_name);
+ }
+ }
} else {
- shader->default_textures.erase(p_name);
+ if (!shader->default_textures.has(p_name)) {
+ shader->default_textures[p_name] = Map<int, RID>();
+ }
+ shader->default_textures[p_name][p_index] = p_texture;
}
_shader_make_dirty(shader);
}
-RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
+RID RasterizerStorageGLES3::shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const {
const Shader *shader = shader_owner.get_or_null(p_shader);
ERR_FAIL_COND_V(!shader, RID());
- const Map<StringName, RID>::Element *E = shader->default_textures.find(p_name);
-
- if (!E) {
- return RID();
+ if (shader->default_textures.has(p_name) && shader->default_textures[p_name].has(p_index)) {
+ return shader->default_textures[p_name][p_index];
}
- return E->get();
+ return RID();
}
void RasterizerStorageGLES3::shader_add_custom_define(RID p_shader, const String &p_define) {
@@ -2195,10 +2202,11 @@ void RasterizerStorageGLES3::_update_material(Material *p_material) {
}
if (!texture.is_valid()) {
- Map<StringName, RID>::Element *W = p_material->shader->default_textures.find(E->key());
+ Map<StringName, Map<int, RID>>::Element *W = p_material->shader->default_textures.find(E->key());
- if (W) {
- texture = W->get();
+ // TODO: make texture uniform array properly works with GLES3
+ if (W && W->get().has(0)) {
+ texture = W->get()[0];
}
}
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
index eb5614f70f..3f9f208964 100644
--- a/drivers/gles3/rasterizer_storage_gles3.h
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -580,7 +580,7 @@ public:
SelfList<Shader> dirty_list;
- Map<StringName, RID> default_textures;
+ Map<StringName, Map<int, RID>> default_textures;
Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
@@ -706,8 +706,8 @@ public:
String shader_get_code(RID p_shader) const override;
void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const override;
- void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) override;
- RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const override;
+ void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture, int p_index) override;
+ RID shader_get_default_texture_param(RID p_shader, const StringName &p_name, int p_index) const override;
RS::ShaderNativeSourceCode shader_get_native_source_code(RID p_shader) const override { return RS::ShaderNativeSourceCode(); };