[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51118] trunk/blender/source/blender/gpu/ intern/gpu_buffers.c: Code cleanups for PBVH GPU buffers
Nicholas Bishop
nicholasbishop at gmail.com
Sat Oct 6 18:42:11 CEST 2012
Revision: 51118
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51118
Author: nicholasbishop
Date: 2012-10-06 16:42:11 +0000 (Sat, 06 Oct 2012)
Log Message:
-----------
Code cleanups for PBVH GPU buffers
* De-duplicate GPU code to check if VBO should be used.
* Add a flag to indicate if the buffer should be drawn smooth or not,
rather than checking each time the node is drawn.
Modified Paths:
--------------
trunk/blender/source/blender/gpu/intern/gpu_buffers.c
Modified: trunk/blender/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_buffers.c 2012-10-06 16:28:02 UTC (rev 51117)
+++ trunk/blender/source/blender/gpu/intern/gpu_buffers.c 2012-10-06 16:42:11 UTC (rev 51118)
@@ -1269,6 +1269,14 @@
/* XXX: the rest of the code in this file is used for optimized PBVH
* drawing and doesn't interact at all with the buffer code above */
+/* Return false if VBO is either unavailable or disabled by the user,
+ true otherwise */
+static int gpu_vbo_enabled(void)
+{
+ return (GLEW_ARB_vertex_buffer_object &&
+ !(U.gameflags & USER_DISABLE_VBO));
+}
+
/* Convenience struct for building the VBO. */
typedef struct {
float co[3];
@@ -1304,6 +1312,10 @@
int has_hidden;
unsigned int tot_tri, tot_quad;
+
+ /* The PBVH ensures that either all faces in the node are
+ smooth-shaded or all faces are flat-shaded */
+ int smooth;
};
typedef enum {
VBO_ENABLED,
@@ -1434,6 +1446,7 @@
buffers = MEM_callocN(sizeof(GPU_Buffers), "GPU_Buffers");
buffers->index_type = GL_UNSIGNED_SHORT;
+ buffers->smooth = mface[face_indices[0]].flag & ME_SMOOTH;
/* Count the number of visible triangles */
for (i = 0, tottri = 0; i < totface; ++i) {
@@ -1442,7 +1455,7 @@
tottri += f->v4 ? 2 : 1;
}
- if (GLEW_ARB_vertex_buffer_object && !(U.gameflags & USER_DISABLE_VBO))
+ if (gpu_vbo_enabled())
glGenBuffersARB(1, &buffers->index_buf);
if (buffers->index_buf) {
@@ -1591,6 +1604,8 @@
buffers->grid_flag_mats = grid_flag_mats;
buffers->gridkey = *key;
+ buffers->smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
+
//printf("node updated %p\n", buffers);
}
@@ -1685,7 +1700,7 @@
/* VBO is disabled; delete the previous buffer (if it exists) and
* return an invalid handle */
- if (!GLEW_ARB_vertex_buffer_object || (U.gameflags & USER_DISABLE_VBO)) {
+ if (gpu_vbo_enabled()) {
if (buffer)
glDeleteBuffersARB(1, &buffer);
return 0;
@@ -1773,7 +1788,7 @@
#undef FILL_QUAD_BUFFER
-static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers, int smooth)
+static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers)
{
const MVert *mvert = buffers->mvert;
int i, j;
@@ -1793,7 +1808,7 @@
glBegin((f->v4) ? GL_QUADS : GL_TRIANGLES);
- if (smooth) {
+ if (buffers->smooth) {
for (j = 0; j < S; j++) {
if (has_mask) {
gpu_color_from_mask_set(buffers->vmask[fv[j]]);
@@ -1840,7 +1855,7 @@
}
}
-static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers, int smooth)
+static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers)
{
const CCGKey *key = &buffers->gridkey;
int i, j, x, y, gridsize = buffers->gridkey.grid_size;
@@ -1873,7 +1888,7 @@
if (paint_is_grid_face_hidden(gh, gridsize, x, y))
continue;
- if (smooth) {
+ if (buffers->smooth) {
for (j = 0; j < 4; j++) {
if (has_mask) {
gpu_color_from_mask_set(*CCG_elem_mask(key, e[j]));
@@ -1903,7 +1918,7 @@
glEnd();
}
- else if (smooth) {
+ else if (buffers->smooth) {
for (y = 0; y < gridsize - 1; y++) {
glBegin(GL_QUAD_STRIP);
for (x = 0; x < gridsize; x++) {
@@ -1970,19 +1985,15 @@
const MFace *f = &buffers->mface[buffers->face_indices[0]];
if (!setMaterial(f->mat_nr + 1, NULL))
return;
-
- smooth = f->flag & ME_SMOOTH;
- glShadeModel(smooth ? GL_SMOOTH : GL_FLAT);
}
else if (buffers->totgrid) {
const DMFlagMat *f = &buffers->grid_flag_mats[buffers->grid_indices[0]];
if (!setMaterial(f->mat_nr + 1, NULL))
return;
-
- smooth = f->flag & ME_SMOOTH;
- glShadeModel(smooth ? GL_SMOOTH : GL_FLAT);
}
+ glShadeModel(buffers->smooth ? GL_SMOOTH : GL_FLAT);
+
if (buffers->vert_buf && buffers->index_buf) {
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
@@ -2042,10 +2053,10 @@
}
/* fallbacks if we are out of memory or VBO is disabled */
else if (buffers->totface) {
- gpu_draw_buffers_legacy_mesh(buffers, smooth);
+ gpu_draw_buffers_legacy_mesh(buffers);
}
else if (buffers->totgrid) {
- gpu_draw_buffers_legacy_grids(buffers, smooth);
+ gpu_draw_buffers_legacy_grids(buffers);
}
}
More information about the Bf-blender-cvs
mailing list