[Bf-blender-cvs] [8e08b34] GPU_data_request: clean up GPUx vertex buffer API (part 1)

Mike Erwin noreply at git.blender.org
Thu May 14 08:58:14 CEST 2015


Commit: 8e08b34061919f1435ffa26b4888cf0370f778ce
Author: Mike Erwin
Date:   Thu May 14 02:57:40 2015 -0400
Branches: GPU_data_request
https://developer.blender.org/rB8e08b34061919f1435ffa26b4888cf0370f778ce

clean up GPUx vertex buffer API (part 1)

Removed unprimed version of GPUx_vertex_buffer_use function. The new
pattern is create, fill, prime, use {draw} done_using, use {draw}
done_using ...

Renamed GPUx_vertex_buffer_use_primed to GPUx_vertex_buffer_use since
there's only one version now.

Also removed the _primed suffix from GPUx_element_list_use.

TODO: make a wiki page about how to use this API

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

M	source/blender/gpu/GPUx_element.h
M	source/blender/gpu/GPUx_vbo.h
M	source/blender/gpu/intern/gpux_draw.c
M	source/blender/gpu/intern/gpux_element.c
M	source/blender/gpu/intern/gpux_vbo.c

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

diff --git a/source/blender/gpu/GPUx_element.h b/source/blender/gpu/GPUx_element.h
index f44152d..0ffe6b8 100644
--- a/source/blender/gpu/GPUx_element.h
+++ b/source/blender/gpu/GPUx_element.h
@@ -23,9 +23,10 @@ void GPUx_set_triangle_vertices(ElementList*, unsigned prim_idx, unsigned v1, un
 
 void GPUx_optimize(ElementList*); /* optionally call this after setting all vertex indices */
 
-/* prime does all the setup (create VBO, send to GPU, etc.) so use_primed doesn't have to */
+/* prime does all the setup (create VBO, send to GPU, etc.) */
 void GPUx_element_list_prime(ElementList*);
-void GPUx_element_list_use_primed(const ElementList*);
+
+void GPUx_element_list_use(const ElementList*);
 void GPUx_element_list_done_using(const ElementList*);
 
 #endif /* BLENDER_GL_ELEMENT_LIST */
diff --git a/source/blender/gpu/GPUx_vbo.h b/source/blender/gpu/GPUx_vbo.h
index 2155e00..358191e 100644
--- a/source/blender/gpu/GPUx_vbo.h
+++ b/source/blender/gpu/GPUx_vbo.h
@@ -62,17 +62,13 @@ void GPUx_fill_attrib(VertexBuffer*, unsigned attrib_num, const void *data);
 void GPUx_fill_attrib_stride(VertexBuffer*, unsigned attrib_num, const void *data, unsigned stride);
 
 /* call before drawing to make this vertex buffer part of current OpenGL state */
-void GPUx_vertex_buffer_use(VertexBuffer*);
+void GPUx_vertex_buffer_use(const VertexBuffer*);
 /* call after drawing */
 void GPUx_vertex_buffer_done_using(const VertexBuffer*);
 
-/* alternative to vertex_buffer_use:
- * prime does all the setup (create VBOs, send to GPU, etc.) so use_primed doesn't have to */
+/* prime does all the setup (create VBOs, send to GPU, etc.)
+ * call sequence: prime, use {draw} done_using, use {draw} done_using ...
+ * TODO: wiki page about this */
 void GPUx_vertex_buffer_prime(VertexBuffer*);
-void GPUx_vertex_buffer_use_primed(const VertexBuffer*);
-/* prime, use_primed, done_using, use_primed, done_using ...
- * use, done_using, use, done_using ... (first use auto-primes)
- * 'use' modifies VAO and VBO IDs on first run, so is non-const (no 'mutable' in C)
- * this was primary motivation for splitting into two functions */
 
 #endif /* BLENDER_GL_VERTEX_BUFFER */
diff --git a/source/blender/gpu/intern/gpux_draw.c b/source/blender/gpu/intern/gpux_draw.c
index 6ae3e8e..b02da93 100644
--- a/source/blender/gpu/intern/gpux_draw.c
+++ b/source/blender/gpu/intern/gpux_draw.c
@@ -28,10 +28,10 @@ void GPUx_draw_points(const VertexBuffer *vbo, const ElementList *el, const Poin
 #endif /* TRUST_NO_ONE */
 
 #ifdef REALLY_DRAW
-	GPUx_vertex_buffer_use_primed(vbo);
+	GPUx_vertex_buffer_use(vbo);
 
 	if (el) {
-		GPUx_element_list_use_primed(el);
+		GPUx_element_list_use(el);
 		glDrawRangeElements(GL_POINTS, min_index(el), max_index(el), el->prim_ct, el->index_type, index_ptr(el));
 		GPUx_element_list_done_using(el);
 	}
@@ -55,10 +55,10 @@ void GPUx_draw_lines(const VertexBuffer *vbo, const ElementList *el, const LineD
 #endif /* TRUST_NO_ONE */
 
 #ifdef REALLY_DRAW
-	GPUx_vertex_buffer_use_primed(vbo);
+	GPUx_vertex_buffer_use(vbo);
 
 	if (el) {
-		GPUx_element_list_use_primed(el);
+		GPUx_element_list_use(el);
 		glDrawRangeElements(GL_LINES, min_index(el), max_index(el), el->prim_ct * 2, el->index_type, index_ptr(el));
 		GPUx_element_list_done_using(el);
 	}
@@ -82,10 +82,10 @@ void GPUx_draw_triangles(const VertexBuffer *vbo, const ElementList *el, const P
 #endif /* TRUST_NO_ONE */
 
 #ifdef REALLY_DRAW
-	GPUx_vertex_buffer_use_primed(vbo);
+	GPUx_vertex_buffer_use(vbo);
 
 	if (el) {
-		GPUx_element_list_use_primed(el);
+		GPUx_element_list_use(el);
 		glDrawRangeElements(GL_TRIANGLES, min_index(el), max_index(el), el->prim_ct * 3, el->index_type, index_ptr(el));
 		GPUx_element_list_done_using(el);
 	}
@@ -128,8 +128,8 @@ void GPUx_draw_primitives(const VertexBuffer *vbo, const ElementList *el, const
 	GPUx_set_common_state(common_state);
 
 #ifdef REALLY_DRAW
-	GPUx_vertex_buffer_use_primed(vbo);
-	GPUx_element_list_use_primed(el);
+	GPUx_vertex_buffer_use(vbo);
+	GPUx_element_list_use(el);
 
 	glDrawRangeElements(el->prim_type, min_index(el), max_index(el), el->prim_ct * vert_per_prim, el->index_type, index_ptr(el));
 
@@ -197,10 +197,10 @@ void GPUx_draw_batch(const GPUxBatch *batch)
 	GPUx_set_common_state(&batch->state.common);
 
 #ifdef REALLY_DRAW
-	GPUx_vertex_buffer_use_primed(batch->buff);
+	GPUx_vertex_buffer_use(batch->buff);
 
 	if (batch->elem) {
-		GPUx_element_list_use_primed(batch->elem);
+		GPUx_element_list_use(batch->elem);
 		glDrawRangeElements(batch->prim_type, min_index(batch->elem), max_index(batch->elem),
 		                    batch->elem->prim_ct * vert_per_prim, batch->elem->index_type, index_ptr(batch->elem));
 		GPUx_element_list_done_using(batch->elem);
diff --git a/source/blender/gpu/intern/gpux_element.c b/source/blender/gpu/intern/gpux_element.c
index 9b1efd9..427c715 100644
--- a/source/blender/gpu/intern/gpux_element.c
+++ b/source/blender/gpu/intern/gpux_element.c
@@ -269,7 +269,7 @@ void GPUx_element_list_prime(ElementList *el)
 #endif /* USE_ELEM_VBO */
 }
 
-void GPUx_element_list_use_primed(const ElementList *el)
+void GPUx_element_list_use(const ElementList *el)
 {
 #ifdef USE_ELEM_VBO
   #ifdef TRUST_NO_ONE
diff --git a/source/blender/gpu/intern/gpux_vbo.c b/source/blender/gpu/intern/gpux_vbo.c
index 1888617..c7cde1b 100644
--- a/source/blender/gpu/intern/gpux_vbo.c
+++ b/source/blender/gpu/intern/gpux_vbo.c
@@ -373,89 +373,6 @@ void GPUx_fill_attrib_stride(VertexBuffer *buff, unsigned attrib_num, const void
 	}
 }
 
-void GPUx_vertex_buffer_use(VertexBuffer *buff)
-{
-	unsigned a_idx;
-	const void *data;
-#ifdef USE_VAO
-	if (buff->vao_id) {
-		/* simply bind & exit */
-		glBindVertexArray(buff->vao_id);
-		return;
-	}
-	else {
-		buff->vao_id = vao_id_alloc();
-		glBindVertexArray(buff->vao_id);
-	}
-#endif /* USE_VAO */
-
-	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
-		Attrib *a = buff->attribs + a_idx;
-
-#ifdef GENERIC_ATTRIB
-		glEnableVertexAttribArray(a_idx);
-#else
-		glEnableClientState(a->array);
-#endif /* GENERIC_ATTRIB */
-
-#ifdef USE_VBO
-		if (a->vbo_id)
-			glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
-		else {
-			a->vbo_id = buffer_id_alloc();
-			glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
-			/* fill with delicious data & send to GPU the first time only */
-			glBufferData(GL_ARRAY_BUFFER, attrib_total_size(buff, a_idx), a->data, GL_STATIC_DRAW);
-  #ifdef KEEP_SINGLE_COPY
-			/* now that GL has a copy, discard original */
-			MEM_freeN(a->data);
-			a->data = NULL;
-  #endif /* KEEP_SINGLE_COPY */
-		}
-
-		data = 0;
-#else /* client vertex array */
-		data = a->data;
-#endif /* USE_VBO */
-
-#ifdef GENERIC_ATTRIB
-		switch (a->fetch_mode) {
-			case KEEP_FLOAT:
-			case CONVERT_INT_TO_FLOAT:
-				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_FALSE, a->stride, data);
-				break;
-			case NORMALIZE_INT_TO_FLOAT:
-				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_TRUE, a->stride, data);
-				break;
-			case KEEP_INT:
-				glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, data);
-		}
-#else /* classic (non-generic) attributes */
-		switch (a->array) {
-			case GL_VERTEX_ARRAY:
-				glVertexPointer(a->comp_ct, a->comp_type, a->stride, data);
-				break;
-			case GL_NORMAL_ARRAY:
-				glNormalPointer(a->comp_type, a->stride, data);
-				break;
-			case GL_COLOR_ARRAY:
-				glColorPointer(a->comp_ct, a->comp_type, a->stride, data);
-				break;
-			case GL_TEXTURE_COORD_ARRAY:
-				glTexCoordPointer(a->comp_ct, a->comp_type, a->stride, data);
-				/* TODO: transition to glMultiTexCoordPointer? */
-				break;
-			default:
-				;
-		}
-#endif /* GENERIC_ATTRIB */
-	}
-
-#ifdef USE_VBO
-	glBindBuffer(GL_ARRAY_BUFFER, 0);
-#endif /* USE_VBO */
-}
-
 void GPUx_vertex_buffer_prime(VertexBuffer *buff)
 {
 	unsigned a_idx;
@@ -538,7 +455,7 @@ void GPUx_vertex_buffer_prime(VertexBuffer *buff)
 #endif /* USE_VAO */
 }
 
-void GPUx_vertex_buffer_use_primed(const VertexBuffer *buff)
+void GPUx_vertex_buffer_use(const VertexBuffer *buff)
 {
 #ifdef USE_VAO
   #ifdef TRUST_NO_ONE




More information about the Bf-blender-cvs mailing list