[Bf-blender-cvs] [b300fa49234] blender2.8: Gawain: Modify batch draw function to work with ranges.

Clément Foucault noreply at git.blender.org
Tue Jan 9 15:17:21 CET 2018


Commit: b300fa4923424ebff000f0b78fb80148ca690f3c
Author: Clément Foucault
Date:   Tue Jan 9 13:37:28 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBb300fa4923424ebff000f0b78fb80148ca690f3c

Gawain: Modify batch draw function to work with ranges.

This enables to draw the same vbo but only with a selected range. (useful for selection with instancing/batching)

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

M	intern/gawain/gawain/gwn_batch.h
M	intern/gawain/src/gwn_batch.c
M	source/blender/draw/intern/draw_manager.c
M	source/blender/gpu/intern/gpu_compositing.c

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

diff --git a/intern/gawain/gawain/gwn_batch.h b/intern/gawain/gawain/gwn_batch.h
index ee1599845c8..b2b2f00a5a1 100644
--- a/intern/gawain/gawain/gwn_batch.h
+++ b/intern/gawain/gawain/gwn_batch.h
@@ -86,8 +86,8 @@ void GWN_batch_draw(Gwn_Batch*);
 
 
 // clement : temp stuff
-void GWN_batch_draw_stupid(Gwn_Batch*);
-void GWN_batch_draw_stupid_instanced(Gwn_Batch*, unsigned int instance_vbo, int instance_count,
+void GWN_batch_draw_stupid(Gwn_Batch*, int v_first, int v_count);
+void GWN_batch_draw_stupid_instanced(Gwn_Batch*, unsigned int instance_vbo, int instance_first, int instance_count,
                                  int attrib_nbr, int attrib_stride, int attrib_loc[16], int attrib_size[16]);
 void GWN_batch_draw_stupid_instanced_with_batch(Gwn_Batch*, Gwn_Batch*);
 
diff --git a/intern/gawain/src/gwn_batch.c b/intern/gawain/src/gwn_batch.c
index 00448b4924d..3b7cdd1fa8d 100644
--- a/intern/gawain/src/gwn_batch.c
+++ b/intern/gawain/src/gwn_batch.c
@@ -118,7 +118,7 @@ void GWN_batch_program_unset(Gwn_Batch* batch)
 	batch->program_in_use = false;
 	}
 
-static void Batch_update_program_bindings(Gwn_Batch* batch)
+static void Batch_update_program_bindings(Gwn_Batch* batch, unsigned int v_first)
 	{
 	// disable all as a precaution
 	// why are we not using prev_attrib_enabled_bits?? see immediate.c
@@ -142,7 +142,7 @@ static void Batch_update_program_bindings(Gwn_Batch* batch)
 			{
 			const Gwn_VertAttr* a = format->attribs + a_idx;
 
-			const GLvoid* pointer = (const GLubyte*)0 + a->offset;
+			const GLvoid* pointer = (const GLubyte*)0 + a->offset + v_first * stride;
 
 			for (unsigned n_idx = 0; n_idx < a->name_ct; ++n_idx)
 				{
@@ -284,7 +284,7 @@ void GWN_batch_draw(Gwn_Batch* batch)
 		Batch_prime(batch);
 
 	if (batch->program_dirty)
-		Batch_update_program_bindings(batch);
+		Batch_update_program_bindings(batch, 0);
 
 	GWN_batch_program_use_begin(batch);
 
@@ -313,7 +313,7 @@ void GWN_batch_draw(Gwn_Batch* batch)
 
 
 // clement : temp stuff
-void GWN_batch_draw_stupid(Gwn_Batch* batch)
+void GWN_batch_draw_stupid(Gwn_Batch* batch, int v_first, int v_count)
 	{
 	if (batch->vao_id)
 		glBindVertexArray(batch->vao_id);
@@ -321,34 +321,39 @@ void GWN_batch_draw_stupid(Gwn_Batch* batch)
 		Batch_prime(batch);
 
 	if (batch->program_dirty)
-		Batch_update_program_bindings(batch);
+		Batch_update_program_bindings(batch, v_first);
 
 	// GWN_batch_program_use_begin(batch);
 
 	//gpuBindMatrices(batch->program);
 
+	// Infer lenght if vertex count is not given
+	if (v_count == 0) {
+		v_count = (batch->elem) ? batch->elem->index_ct : batch->verts[0]->vertex_ct;
+	}
+
 	if (batch->elem)
 		{
 		const Gwn_IndexBuf* el = batch->elem;
 
 #if GWN_TRACK_INDEX_RANGE
 		if (el->base_index)
-			glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->gl_index_type, 0, el->base_index);
+			glDrawRangeElementsBaseVertex(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, 0, el->base_index);
 		else
-			glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, el->index_ct, el->gl_index_type, 0);
+			glDrawRangeElements(batch->gl_prim_type, el->min_index, el->max_index, v_count, el->gl_index_type, 0);
 #else
-		glDrawElements(batch->gl_prim_type, el->index_ct, GL_UNSIGNED_INT, 0);
+		glDrawElements(batch->gl_prim_type, v_count, GL_UNSIGNED_INT, 0);
 #endif
 		}
 	else
-		glDrawArrays(batch->gl_prim_type, 0, batch->verts[0]->vertex_ct);
+		glDrawArrays(batch->gl_prim_type, 0, v_count);
 
 	// GWN_batch_program_use_end(batch);
 	glBindVertexArray(0);
 	}
 
 // clement : temp stuff
-void GWN_batch_draw_stupid_instanced(Gwn_Batch* batch, unsigned int instance_vbo, int instance_count,
+void GWN_batch_draw_stupid_instanced(Gwn_Batch* batch, unsigned int instance_vbo, int instance_first, int instance_count,
                                  int attrib_nbr, int attrib_stride, int attrib_size[16], int attrib_loc[16])
 	{
 	if (batch->vao_id)
@@ -357,10 +362,10 @@ void GWN_batch_draw_stupid_instanced(Gwn_Batch* batch, unsigned int instance_vbo
 		Batch_prime(batch);
 
 	if (batch->program_dirty)
-		Batch_update_program_bindings(batch);
+		Batch_update_program_bindings(batch, 0);
 
 	glBindBuffer(GL_ARRAY_BUFFER, instance_vbo);
-	int ptr_ofs = 0;
+	int ptr_ofs = instance_first * attrib_stride;
 	for (int i = 0; i < attrib_nbr; ++i)
 		{
 		int size = attrib_size[i];
@@ -412,7 +417,7 @@ void GWN_batch_draw_stupid_instanced_with_batch(Gwn_Batch* batch_instanced, Gwn_
 		Batch_prime(batch_instanced);
 
 	if (batch_instanced->program_dirty)
-		Batch_update_program_bindings(batch_instanced);
+		Batch_update_program_bindings(batch_instanced, 0);
 
 	Gwn_VertBuf* verts = batch_instancing->verts[0];
 
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 91fc7047a69..eda2f775028 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -1856,11 +1856,11 @@ static void draw_geometry_execute(DRWShadingGroup *shgroup, Gwn_Batch *geom)
 	}
 	else if (interface->instance_vbo) {
 		GWN_batch_draw_stupid_instanced(
-		        geom, interface->instance_vbo, interface->instance_count, interface->attribs_count,
+		        geom, interface->instance_vbo, 0, interface->instance_count, interface->attribs_count,
 		        interface->attribs_stride, interface->attribs_size, interface->attribs_loc);
 	}
 	else {
-		GWN_batch_draw_stupid(geom);
+		GWN_batch_draw_stupid(geom, 0, 0);
 	}
 	/* XXX this just tells gawain we are done with the shader.
 	 * This does not unbind the shader. */
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 12ed67cdf4e..3de363cc76e 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -1007,7 +1007,7 @@ bool GPU_fx_do_composite_pass(
 				glClearColor(0.0, 0.0, 0.0, 0.0);
 				glClear(GL_COLOR_BUFFER_BIT);
 				/* the draw call we all waited for, draw a point per pixel, scaled per circle of confusion */
-				GWN_batch_draw_stupid_instanced(fx->point_batch, 0, fx->dof_downsampled_w * fx->dof_downsampled_h, 0, 0, NULL, NULL);
+				GWN_batch_draw_stupid_instanced(fx->point_batch, 0, fx->dof_downsampled_w * fx->dof_downsampled_h, 0, 0, 0, NULL, NULL);
 
 				GPU_texture_unbind(fx->dof_half_downsampled_far);
 				GPU_framebuffer_texture_detach(fx->dof_far_blur);
@@ -1023,7 +1023,7 @@ bool GPU_fx_do_composite_pass(
 				/* have to clear the buffer unfortunately */
 				glClear(GL_COLOR_BUFFER_BIT);
 				/* the draw call we all waited for, draw a point per pixel, scaled per circle of confusion */
-				GWN_batch_draw_stupid_instanced(fx->point_batch, 0, fx->dof_downsampled_w * fx->dof_downsampled_h, 0, 0, NULL, NULL);
+				GWN_batch_draw_stupid_instanced(fx->point_batch, 0, fx->dof_downsampled_w * fx->dof_downsampled_h, 0, 0, 0, NULL, NULL);
 				GWN_batch_program_use_end(fx->point_batch);
 
 				/* disable bindings */



More information about the Bf-blender-cvs mailing list