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
This commit is contained in:
parent
0efe89bdd8
commit
de0cae29cf
Notes:
blender-bot
2023-02-14 11:24:03 +01:00
Referenced by issue #65659, blender 2.8 subdivide surface Referenced by issue #65383, UI graphics glitches on macOS with Intel HD 4000 Referenced by issue #65364, Corrupted mesh display on macOS
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue