[Bf-blender-cvs] [3a9ee33328a] blender2.8: GPU: Fix partial draw of batches with index buffers

Clément Foucault noreply at git.blender.org
Mon Oct 1 15:20:58 CEST 2018


Commit: 3a9ee33328a48278290af429b8b0e18fd36de1c0
Author: Clément Foucault
Date:   Mon Oct 1 14:52:02 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB3a9ee33328a48278290af429b8b0e18fd36de1c0

GPU: Fix partial draw of batches with index buffers

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

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 87ea112148c..2cbeeb26924 100644
--- a/source/blender/gpu/intern/gpu_batch.c
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -528,6 +528,18 @@ static void primitive_restart_disable(void)
 	glDisable(GL_PRIMITIVE_RESTART);
 }
 
+static void *elem_offset(const GPUIndexBuf *el, int v_first)
+{
+#if GPU_TRACK_INDEX_RANGE
+	if (el->index_type == GPU_INDEX_U8)
+		return (GLubyte *)0 + v_first;
+	else if (el->index_type == GPU_INDEX_U16)
+		return (GLushort *)0 + v_first;
+	else
+#endif
+		return (GLuint *)0 + v_first;
+}
+
 void GPU_batch_draw(GPUBatch *batch)
 {
 #if TRUST_NO_ONE
@@ -547,10 +559,11 @@ void GPU_batch_draw_range_ex(GPUBatch *batch, int v_first, int v_count, bool for
 #if TRUST_NO_ONE
 	assert(!(force_instance && (batch->inst == NULL)) || v_count > 0); // we cannot infer length if force_instance
 #endif
+
 	const bool do_instance = (force_instance || batch->inst);
 
 	// If using offset drawing, use the default VAO and redo bindings.
-	if (v_first != 0 && (do_instance || batch->elem)) {
+	if (v_first != 0 && do_instance) {
 		glBindVertexArray(GPU_vao_default());
 		batch_update_program_bindings(batch, v_first);
 	}
@@ -601,6 +614,8 @@ void GPU_batch_draw_range_ex(GPUBatch *batch, int v_first, int v_count, bool for
 				primitive_restart_enable(el);
 			}
 
+			void *v_first_ofs = elem_offset(el, v_first);
+
 #if GPU_TRACK_INDEX_RANGE
 			if (el->base_index) {
 				glDrawRangeElementsBaseVertex(
@@ -609,14 +624,14 @@ void GPU_batch_draw_range_ex(GPUBatch *batch, int v_first, int v_count, bool for
 				        el->max_index,
 				        v_count,
 				        el->gl_index_type,
-				        0,
+				        v_first_ofs,
 				        el->base_index);
 			}
 			else {
-				glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, 0);
+				glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, v_first_ofs);
 			}
 #else
-			glDrawElements(batch->gl_prim_type, v_count, GL_UNSIGNED_INT, 0);
+			glDrawElements(batch->gl_prim_type, v_count, GL_UNSIGNED_INT, v_first_ofs);
 #endif
 			if (el->use_prim_restart) {
 				primitive_restart_disable();



More information about the Bf-blender-cvs mailing list