[Bf-blender-cvs] [de0cae29cf7] master: GPU: Fix Restart index bug

Clément Foucault noreply at git.blender.org
Mon Jun 3 17:58:32 CEST 2019


Commit: de0cae29cf75133ec0afc82f4b21de281992ede0
Author: Clément Foucault
Date:   Mon Jun 3 17:47:42 2019 +0200
Branches: master
https://developer.blender.org/rBde0cae29cf75133ec0afc82f4b21de281992ede0

GPU: Fix Restart index bug

Restart index can have been changed in another context and the static
var can get out of sync. A better solution is to set the restart index
when binding the VAO. It also have less perf impact.

Fix T65364 Corrupted mesh display on macOS

===================================================================

M	source/blender/gpu/intern/gpu_batch.c

===================================================================

diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
index fb2a87fc8d1..1fb11da4fea 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -545,22 +545,6 @@ void GPU_batch_uniform_mat4(GPUBatch *batch, const char *name, const float data[
   glUniformMatrix4fv(uniform->location, 1, GL_FALSE, (const float *)data);
 }
 
-static void primitive_restart_index(const GPUIndexBuf *el)
-{
-#if GPU_TRACK_INDEX_RANGE
-  /* Can be removed if GL 4.3 is available. */
-  if (!GLEW_ARB_ES3_compatibility) {
-    /* Stay sync with GPU_state_init(). */
-    static int last_type = GPU_INDEX_U32;
-    if (el->index_type != last_type) {
-      GLuint restart_index = (el->index_type == GPU_INDEX_U16) ? (GLuint)0xFFFF :
-                                                                 (GLuint)0xFFFFFFFF;
-      glPrimitiveRestartIndex(restart_index);
-    }
-  }
-#endif
-}
-
 static void *elem_offset(const GPUIndexBuf *el, int v_first)
 {
 #if GPU_TRACK_INDEX_RANGE
@@ -575,6 +559,15 @@ static void *elem_offset(const GPUIndexBuf *el, int v_first)
 void GPU_batch_bind(GPUBatch *batch)
 {
   glBindVertexArray(batch->vao_id);
+
+#if GPU_TRACK_INDEX_RANGE
+  /* Can be removed if GL 4.3 is required. */
+  if (!GLEW_ARB_ES3_compatibility && batch->elem != NULL) {
+    GLuint restart_index = (batch->elem->index_type == GPU_INDEX_U16) ? (GLuint)0xFFFF :
+                                                                        (GLuint)0xFFFFFFFF;
+    glPrimitiveRestartIndex(restart_index);
+  }
+#endif
 }
 
 void GPU_batch_draw(GPUBatch *batch)
@@ -631,8 +624,6 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi
 #endif
     void *v_first_ofs = elem_offset(el, v_first);
 
-    primitive_restart_index(el);
-
     if (GLEW_ARB_base_instance) {
       glDrawElementsInstancedBaseVertexBaseInstance(
           batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index, i_first);



More information about the Bf-blender-cvs mailing list