Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Bishop <nicholasbishop@gmail.com>2012-02-23 03:30:56 +0400
committerNicholas Bishop <nicholasbishop@gmail.com>2012-02-23 03:30:56 +0400
commit5e12c7fecac2a8521de92d7e54b7436b70c762a7 (patch)
tree2ba862e180525287f84368389d07f28035e375f5 /source/blender/gpu
parent5e29a678393d79549114380375326b78e4bdf296 (diff)
Code cleanup: de-duplicate code in GPU_build_grid_buffers() with a macro.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/GPU_buffers.h3
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c102
2 files changed, 44 insertions, 61 deletions
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index e244b20bbb0..15505f44e6e 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -166,8 +166,7 @@ GPU_Buffers *GPU_build_mesh_buffers(int (*face_vert_indices)[4],
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);
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 9a5585d4ace..48ab313c589 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -1334,9 +1334,6 @@ void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert,
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 @@ void GPU_update_grid_buffers(GPU_Buffers *buffers, DMGridData **grids,
//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 @@ GPU_Buffers *GPU_build_grid_buffers(DMGridData **UNUSED(grids), int *UNUSED(grid
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 @@ GPU_Buffers *GPU_build_grid_buffers(DMGridData **UNUSED(grids), int *UNUSED(grid
return buffers;
}
+#undef FILL_QUAD_BUFFER
+
static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers)
{
const MVert *mvert = buffers->mvert;