[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44345] trunk/blender/source/blender: Code cleanup: de-duplicate code in GPU_build_grid_buffers() with a macro.
Nicholas Bishop
nicholasbishop at gmail.com
Thu Feb 23 00:31:03 CET 2012
Revision: 44345
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44345
Author: nicholasbishop
Date: 2012-02-22 23:30:56 +0000 (Wed, 22 Feb 2012)
Log Message:
-----------
Code cleanup: de-duplicate code in GPU_build_grid_buffers() with a macro.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/pbvh.c
trunk/blender/source/blender/gpu/GPU_buffers.h
trunk/blender/source/blender/gpu/intern/gpu_buffers.c
Modified: trunk/blender/source/blender/blenlib/intern/pbvh.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/pbvh.c 2012-02-22 23:13:05 UTC (rev 44344)
+++ trunk/blender/source/blender/blenlib/intern/pbvh.c 2012-02-22 23:30:56 UTC (rev 44345)
@@ -435,8 +435,7 @@
{
if(!G.background) {
node->draw_buffers =
- GPU_build_grid_buffers(bvh->grids, node->prim_indices,
- node->totprim, bvh->gridsize);
+ GPU_build_grid_buffers(node->totprim, bvh->gridsize);
}
node->flag |= PBVH_UpdateDrawBuffers;
}
Modified: trunk/blender/source/blender/gpu/GPU_buffers.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_buffers.h 2012-02-22 23:13:05 UTC (rev 44344)
+++ trunk/blender/source/blender/gpu/GPU_buffers.h 2012-02-22 23:30:56 UTC (rev 44345)
@@ -166,8 +166,7 @@
void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert,
int *vert_indices, int totvert, int smooth);
-GPU_Buffers *GPU_build_grid_buffers(struct DMGridData **grids,
- int *grid_indices, int totgrid, int gridsize);
+GPU_Buffers *GPU_build_grid_buffers(int totgrid, int gridsize);
void GPU_update_grid_buffers(GPU_Buffers *buffers, struct DMGridData **grids,
int *grid_indices, int totgrid, int gridsize, int smooth);
Modified: trunk/blender/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_buffers.c 2012-02-22 23:13:05 UTC (rev 44344)
+++ trunk/blender/source/blender/gpu/intern/gpu_buffers.c 2012-02-22 23:30:56 UTC (rev 44345)
@@ -1334,9 +1334,6 @@
buffers->smooth = smooth;
}
-/*GPU_Buffers *GPU_build_mesh_buffers(GHash *map, MFace *mface,
- int *face_indices, int totface,
- int tot_uniq_verts)*/
GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4],
MFace *mface, int *face_indices,
int totface)
@@ -1459,11 +1456,47 @@
//printf("node updated %p\n", buffers);
}
-GPU_Buffers *GPU_build_grid_buffers(DMGridData **UNUSED(grids), int *UNUSED(grid_indices),
- int totgrid, int gridsize)
+/* Build the element array buffer of grid indices using either
+ unsigned shorts or unsigned ints. */
+#define FILL_QUAD_BUFFER(type_) \
+ { \
+ type_ *quad_data; \
+ int offset = 0; \
+ int i, j, k; \
+ \
+ glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
+ sizeof(type_) * totquad * 4, NULL, \
+ GL_STATIC_DRAW_ARB); \
+ \
+ /* Fill the quad buffer */ \
+ quad_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, \
+ GL_WRITE_ONLY_ARB); \
+ if(quad_data) { \
+ for(i = 0; i < totgrid; ++i) { \
+ for(j = 0; j < gridsize-1; ++j) { \
+ for(k = 0; k < gridsize-1; ++k) { \
+ *(quad_data++)= offset + j*gridsize + k+1; \
+ *(quad_data++)= offset + j*gridsize + k; \
+ *(quad_data++)= offset + (j+1)*gridsize + k; \
+ *(quad_data++)= offset + (j+1)*gridsize + k+1; \
+ } \
+ } \
+ \
+ offset += gridsize*gridsize; \
+ } \
+ glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); \
+ } \
+ else { \
+ glDeleteBuffersARB(1, &buffers->index_buf); \
+ buffers->index_buf = 0; \
+ } \
+ }
+/* end FILL_QUAD_BUFFER */
+
+GPU_Buffers *GPU_build_grid_buffers(int totgrid, int gridsize)
{
GPU_Buffers *buffers;
- int i, j, k, totquad, offset= 0;
+ int totquad;
buffers = MEM_callocN(sizeof(GPU_Buffers), "GPU_Buffers");
@@ -1478,63 +1511,12 @@
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
if(totquad < USHRT_MAX) {
- unsigned short *quad_data;
-
buffers->index_type = GL_UNSIGNED_SHORT;
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
- sizeof(unsigned short) * totquad * 4, NULL, GL_STATIC_DRAW_ARB);
-
- /* Fill the quad buffer */
- quad_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
- if(quad_data) {
- for(i = 0; i < totgrid; ++i) {
- for(j = 0; j < gridsize-1; ++j) {
- for(k = 0; k < gridsize-1; ++k) {
- *(quad_data++)= offset + j*gridsize + k+1;
- *(quad_data++)= offset + j*gridsize + k;
- *(quad_data++)= offset + (j+1)*gridsize + k;
- *(quad_data++)= offset + (j+1)*gridsize + k+1;
- }
- }
-
- offset += gridsize*gridsize;
- }
- glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
- }
- else {
- glDeleteBuffersARB(1, &buffers->index_buf);
- buffers->index_buf = 0;
- }
+ FILL_QUAD_BUFFER(unsigned short);
}
else {
- unsigned int *quad_data;
-
buffers->index_type = GL_UNSIGNED_INT;
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
- sizeof(unsigned int) * totquad * 4, NULL, GL_STATIC_DRAW_ARB);
-
- /* Fill the quad buffer */
- quad_data = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
-
- if(quad_data) {
- for(i = 0; i < totgrid; ++i) {
- for(j = 0; j < gridsize-1; ++j) {
- for(k = 0; k < gridsize-1; ++k) {
- *(quad_data++)= offset + j*gridsize + k+1;
- *(quad_data++)= offset + j*gridsize + k;
- *(quad_data++)= offset + (j+1)*gridsize + k;
- *(quad_data++)= offset + (j+1)*gridsize + k+1;
- }
- }
-
- offset += gridsize*gridsize;
- }
- glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
- }
- else {
- glDeleteBuffersARB(1, &buffers->index_buf);
- buffers->index_buf = 0;
- }
+ FILL_QUAD_BUFFER(unsigned int);
}
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
@@ -1549,6 +1531,8 @@
return buffers;
}
+#undef FILL_QUAD_BUFFER
+
static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers)
{
const MVert *mvert = buffers->mvert;
More information about the Bf-blender-cvs
mailing list