Просмотр исходного кода

sokol_gl.h: fix subtle bug in the "merge draw call optimization"

The bug might have happened when no vertices were recorded between
an sgl_begin/sgl_end pair. This could lead to the following
draw call being rendered with the wrong uniform data.
Andre Weissflog 5 лет назад
Родитель
Сommit
e5ca86fd18
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      util/sokol_gl.h

+ 4 - 4
util/sokol_gl.h

@@ -2030,10 +2030,8 @@ SOKOL_API_IMPL void sgl_begin_quads(void) {
 SOKOL_API_IMPL void sgl_end(void) {
 SOKOL_API_IMPL void sgl_end(void) {
     SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
     SOKOL_ASSERT(_SGL_INIT_COOKIE == _sgl.init_cookie);
     SOKOL_ASSERT(_sgl.in_begin);
     SOKOL_ASSERT(_sgl.in_begin);
+    SOKOL_ASSERT(_sgl.cur_vertex >= _sgl.base_vertex);
     _sgl.in_begin = false;
     _sgl.in_begin = false;
-    if (_sgl.base_vertex == _sgl.cur_vertex) {
-        return;
-    }
     bool matrix_dirty = _sgl.matrix_dirty;
     bool matrix_dirty = _sgl.matrix_dirty;
     if (matrix_dirty) {
     if (matrix_dirty) {
         _sgl.matrix_dirty = false;
         _sgl.matrix_dirty = false;
@@ -2360,7 +2358,9 @@ SOKOL_API_IMPL void sgl_draw(void) {
                             cur_uniform_index = args->uniform_index;
                             cur_uniform_index = args->uniform_index;
                         }
                         }
                         /* FIXME: what if number of vertices doesn't match the primitive type? */
                         /* FIXME: what if number of vertices doesn't match the primitive type? */
-                        sg_draw(args->base_vertex, args->num_vertices, 1);
+                        if (args->num_vertices > 0) {
+                            sg_draw(args->base_vertex, args->num_vertices, 1);
+                        }
                     }
                     }
                     break;
                     break;
             }
             }