diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-06-03 18:47:42 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-06-03 18:58:28 +0300 |
commit | de0cae29cf75133ec0afc82f4b21de281992ede0 (patch) | |
tree | 27d2cd432f0f2b22c0512099c73ee3529d7ff7b1 /source/blender/gpu/intern/gpu_batch.c | |
parent | 0efe89bdd810226f7474b90ab79d927eadf6746a (diff) |
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
Diffstat (limited to 'source/blender/gpu/intern/gpu_batch.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_batch.c | 27 |
1 files changed, 9 insertions, 18 deletions
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); |