From aeca8f07fa8ea3680a8013e8047ff948c81b04b0 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Tue, 11 Apr 2023 16:58:42 -0700 Subject: Check for instancing without relying on instance_count when drawing 2D meshes This ensures that Particles and MultiMeshes still draw when instance_count is 1 (cherry picked from commit 579ca03e885f294b2d430a3550693b43d58d4f64) --- drivers/gles3/rasterizer_canvas_gles3.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp index 522685bf87..19f2cfd47d 100644 --- a/drivers/gles3/rasterizer_canvas_gles3.cpp +++ b/drivers/gles3/rasterizer_canvas_gles3.cpp @@ -1310,6 +1310,7 @@ void RasterizerCanvasGLES3::_render_batch(Light *p_lights, uint32_t p_index) { uint32_t instance_color_offset = 0; bool instance_uses_color = false; bool instance_uses_custom_data = false; + bool use_instancing = false; if (state.canvas_instance_batches[p_index].command_type == Item::Command::TYPE_MESH) { const Item::CommandMesh *m = static_cast(state.canvas_instance_batches[p_index].command); @@ -1336,6 +1337,7 @@ void RasterizerCanvasGLES3::_render_batch(Light *p_lights, uint32_t p_index) { instance_color_offset = mesh_storage->multimesh_get_color_offset(multimesh); instance_uses_color = mesh_storage->multimesh_uses_colors(multimesh); instance_uses_custom_data = mesh_storage->multimesh_uses_custom_data(multimesh); + use_instancing = true; } else if (state.canvas_instance_batches[p_index].command_type == Item::Command::TYPE_PARTICLES) { const Item::CommandParticles *pt = static_cast(state.canvas_instance_batches[p_index].command); @@ -1362,6 +1364,7 @@ void RasterizerCanvasGLES3::_render_batch(Light *p_lights, uint32_t p_index) { instance_color_offset = 8; // 8 bytes for instance transform. instance_uses_color = true; instance_uses_custom_data = true; + use_instancing = true; } ERR_FAIL_COND(mesh.is_null()); @@ -1397,7 +1400,7 @@ void RasterizerCanvasGLES3::_render_batch(Light *p_lights, uint32_t p_index) { use_index_buffer = true; } - if (instance_count > 1) { + if (use_instancing) { if (instance_buffer == 0) { break; } @@ -1426,7 +1429,7 @@ void RasterizerCanvasGLES3::_render_batch(Light *p_lights, uint32_t p_index) { } glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - if (instance_count > 1) { + if (use_instancing) { glDisableVertexAttribArray(5); glDisableVertexAttribArray(6); glDisableVertexAttribArray(7); -- cgit v1.2.3