summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbitsawer <sawerduster@gmail.com>2023-09-28 21:48:24 +0300
committerbitsawer <sawerduster@gmail.com>2023-09-29 11:44:37 +0300
commit6f88ed73be786e93e60a3c9dd4f9a4127badeba7 (patch)
treef71834b3a9590295258eef1220c538183df58bc4
parentfe8a58b9d7ca5b85348b3a984eeb16371a097481 (diff)
downloadredot-engine-6f88ed73be786e93e60a3c9dd4f9a4127badeba7.tar.gz
Fix GLES3 instanced rendering color and custom data defaults
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp7
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp8
2 files changed, 15 insertions, 0 deletions
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index 2894f4164f..fcd3af8d62 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -1420,6 +1420,13 @@ void RasterizerCanvasGLES3::_render_batch(Light *p_lights, uint32_t p_index) {
glEnableVertexAttribArray(5);
glVertexAttribIPointer(5, 4, GL_UNSIGNED_INT, instance_stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(instance_color_offset * sizeof(float)));
glVertexAttribDivisor(5, 1);
+ } else {
+ // Set all default instance color and custom data values to 1.0 or 0.0 using a compressed format.
+ uint16_t zero = Math::make_half_float(0.0f);
+ uint16_t one = Math::make_half_float(1.0f);
+ GLuint default_color = (uint32_t(one) << 16) | one;
+ GLuint default_custom = (uint32_t(zero) << 16) | zero;
+ glVertexAttribI4ui(5, default_color, default_color, default_custom, default_custom);
}
}
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 1f8e9180e3..22bb772e4f 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -2962,7 +2962,15 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
glEnableVertexAttribArray(15);
glVertexAttribIPointer(15, 4, GL_UNSIGNED_INT, stride * sizeof(float), CAST_INT_TO_UCHAR_PTR(color_custom_offset * sizeof(float)));
glVertexAttribDivisor(15, 1);
+ } else {
+ // Set all default instance color and custom data values to 1.0 or 0.0 using a compressed format.
+ uint16_t zero = Math::make_half_float(0.0f);
+ uint16_t one = Math::make_half_float(1.0f);
+ GLuint default_color = (uint32_t(one) << 16) | one;
+ GLuint default_custom = (uint32_t(zero) << 16) | zero;
+ glVertexAttribI4ui(15, default_color, default_color, default_custom, default_custom);
}
+
if (use_index_buffer) {
glDrawElementsInstanced(primitive_gl, count, mesh_storage->mesh_surface_get_index_type(mesh_surface), 0, inst->instance_count);
} else {