[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30844] branches/soc-2010-nicolasbishop/ source/blender: == PBVH ==
Nicholas Bishop
nicholasbishop at gmail.com
Wed Jul 28 18:46:49 CEST 2010
Revision: 30844
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30844
Author: nicholasbishop
Date: 2010-07-28 18:46:49 +0200 (Wed, 28 Jul 2010)
Log Message:
-----------
== PBVH ==
Note to testers: if you couldn't see colors or masks before, this should fix it.
* Updated non-VBO drawing for colors; paintmasks and vertex colors should now work OK with VBO disabled (or for OOM condition)
Modified Paths:
--------------
branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h
branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h 2010-07-28 16:26:42 UTC (rev 30843)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h 2010-07-28 16:46:49 UTC (rev 30844)
@@ -139,6 +139,11 @@
void BLI_pbvh_node_mark_update(PBVHNode *node);
void BLI_pbvh_node_set_flags(PBVHNode *node, void *data);
+/* returns true if the pbvh is using grids rather than faces */
+int BLI_pbvh_uses_grids(PBVH *bvh);
+
+void BLI_pbvh_get_customdata(PBVH *pbvh, struct CustomData **vdata, struct CustomData **fdata);
+
void BLI_pbvh_node_get_faces(PBVH *bvh, PBVHNode *node,
struct MFace **faces, struct CustomData **fdata,
int **face_indices, int **face_vert_indices,
Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c 2010-07-28 16:26:42 UTC (rev 30843)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c 2010-07-28 16:46:49 UTC (rev 30844)
@@ -1314,6 +1314,19 @@
*gridfaces= faces;
}
+/**** Access to mesh/grid data ****/
+int BLI_pbvh_uses_grids(PBVH *bvh)
+{
+ return !!bvh->grids;
+}
+
+void BLI_pbvh_get_customdata(PBVH *bvh, CustomData **vdata, CustomData **fdata)
+{
+ if(vdata) *vdata = bvh->vdata;
+ if(fdata) *fdata = bvh->fdata;
+}
+
+
/***************************** Node Access ***********************************/
void BLI_pbvh_node_mark_update(PBVHNode *node)
@@ -1597,7 +1610,11 @@
//#include <GL/glew.h>
-void BLI_pbvh_node_draw(PBVHNode *node, void *data)
+typedef struct {
+ PBVH *pbvh;
+ GPUDrawFlags flags;
+} PBVHDrawData;
+void BLI_pbvh_node_draw(PBVHNode *node, void *data_v)
{
#if 0
/* XXX: Just some quick code to show leaf nodes in different colors */
@@ -1615,7 +1632,9 @@
glColor3f(1, 0, 0);
#endif
- GPU_draw_buffers(node->draw_buffers, *((GPUDrawFlags*)data));
+
+ PBVHDrawData *data = data_v;
+ GPU_draw_buffers(node->draw_buffers, data->pbvh, node, data->flags);
}
int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data)
@@ -1630,6 +1649,7 @@
void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int flags)
{
PBVHNode **nodes;
+ PBVHDrawData draw_data = {bvh, flags};
int totnode;
BLI_pbvh_search_gather(bvh, update_search_cb,
@@ -1643,10 +1663,10 @@
if(planes) {
BLI_pbvh_search_callback(bvh, BLI_pbvh_node_planes_contain_AABB,
- planes, BLI_pbvh_node_draw, &flags);
+ planes, BLI_pbvh_node_draw, &draw_data);
}
else {
- BLI_pbvh_search_callback(bvh, NULL, NULL, BLI_pbvh_node_draw, &flags);
+ BLI_pbvh_search_callback(bvh, NULL, NULL, BLI_pbvh_node_draw, &draw_data);
}
}
Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h 2010-07-28 16:26:42 UTC (rev 30843)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h 2010-07-28 16:46:49 UTC (rev 30844)
@@ -162,7 +162,8 @@
int *grid_indices, int totgrid,
int gridsize, struct GridKey *gridkey,
struct CustomData *vdata, GPUDrawFlags flags);
-void GPU_draw_buffers(GPU_Buffers *buffers, GPUDrawFlags flags);
+void GPU_draw_buffers(GPU_Buffers *buffers, struct PBVH *bvh,
+ struct PBVHNode *node, GPUDrawFlags flags);
void GPU_free_buffers(GPU_Buffers *buffers);
/* called before drawing */
Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c 2010-07-28 16:26:42 UTC (rev 30843)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c 2010-07-28 16:46:49 UTC (rev 30844)
@@ -423,19 +423,6 @@
GLuint vert_buf, index_buf, color_buf;
GLenum index_type;
- /* mesh pointers in case buffer allocation fails */
- MFace *mface;
- MVert *mvert;
- int *face_indices;
- int totface;
-
- /* grid pointers */
- DMGridData **grids;
- int *grid_indices;
- int totgrid;
- int gridsize;
- struct GridKey *gridkey;
-
unsigned int tot_tri, tot_quad;
};
@@ -482,6 +469,29 @@
return color_data;
}
+static void color_from_face_corner(CustomData *fdata, int mcol_first_layer,
+ int mcol_totlayer, int cndx, float v[3])
+{
+ int i;
+
+ v[0] = v[1] = v[2] = 1;
+
+ for(i = mcol_first_layer; i < mcol_first_layer+mcol_totlayer; ++i) {
+ MCol *mcol;
+ float col[3];
+
+ mcol = fdata->layers[i].data;
+ mcol += cndx;
+
+ col[0] = mcol->b / 255.0f;
+ col[1] = mcol->g / 255.0f;
+ col[2] = mcol->r / 255.0f;
+
+ interp_v3_v3v3(v, v, col,
+ mcol->a / 255.0f);
+ }
+}
+
void GPU_update_mesh_color_buffers(GPU_Buffers *buffers, PBVH *bvh,
PBVHNode *node, GPUDrawFlags flags)
{
@@ -493,6 +503,9 @@
int mcol_totlayer, pmask_totlayer;
int color_needed;
+ if(!buffers->vert_buf)
+ return;
+
BLI_pbvh_node_num_verts(bvh, node, NULL, &totvert);
BLI_pbvh_node_get_verts(bvh, node, &vert_indices, NULL, &vdata);
BLI_pbvh_node_get_faces(bvh, node, &mface, &fdata, &face_indices,
@@ -511,7 +524,7 @@
color_data = map_color_buffer(buffers, color_needed, totvert);
if(color_data) {
- int i, j, k, mcol_first_layer, pmask_first_layer;
+ int i, j, mcol_first_layer, pmask_first_layer;
mcol_first_layer = CustomData_get_layer_index(fdata, CD_MCOL);
pmask_first_layer = CustomData_get_layer_index(vdata, CD_PAINTMASK);
@@ -528,31 +541,21 @@
transition from one face to another */
for(j = 0; j < S; ++j) {
int node_vert_index = face_vert_indices[i*4 + j];
- float mask;
- float v[3] = {1, 1, 1};
+ float col[3], mask;
- for(k = mcol_first_layer;
- k < mcol_first_layer+mcol_totlayer; ++k) {
- MCol *mcol;
- float col[3];
+ color_from_face_corner(fdata,
+ mcol_first_layer,
+ mcol_totlayer,
+ face_index*4+j, col);
- mcol = fdata->layers[k].data;
- mcol += face_index*4+j;
-
- col[0] = mcol->b / 255.0f;
- col[1] = mcol->g / 255.0f;
- col[2] = mcol->r / 255.0f;
-
- interp_v3_v3v3(v, v, col,
- mcol->a / 255.0f);
- }
-
mask = paint_mask_from_vertex(vdata,
vert_indices[node_vert_index],
pmask_totlayer,
pmask_first_layer);
- gpu_colors_from_floats(color_data + node_vert_index*3, v, mask);
+ gpu_colors_from_floats(color_data +
+ node_vert_index*3,
+ col, mask);
}
}
@@ -594,8 +597,6 @@
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
-
- buffers->mvert = mvert;
}
GPU_Buffers *GPU_build_mesh_buffers(GHash *map, MVert *mvert, MFace *mface,
@@ -665,13 +666,29 @@
buffers->tot_tri = tottri;
- buffers->mface = mface;
- buffers->face_indices = face_indices;
- buffers->totface = totface;
-
return buffers;
}
+static void color_from_gridelem(DMGridData *elem, GridKey *gridkey, float col[3])
+{
+ int i;
+
+ col[0] = col[1] = col[2] = 1;
+
+ /* combine colors */
+ for(i = 0; i < gridkey->color; ++i) {
+ float *c = GRIDELEM_COLOR(elem, gridkey)[i];
+
+ /* TODO: check layer enabled/strength */
+
+ /* for now we just combine layers in order
+ interpolating using the alpha component
+ ("order" is ill-defined here since we
+ don't guarantee the order of cdm data) */
+ interp_v3_v3v3(col, col, c, c[3]);
+ }
+}
+
void GPU_update_grid_color_buffers(GPU_Buffers *buffers, DMGridData **grids, int *grid_indices,
int totgrid, int gridsize, GridKey *gridkey, CustomData *vdata,
GPUDrawFlags flags)
@@ -680,6 +697,9 @@
int totvert;
int color_needed;
+ if(!buffers->vert_buf)
+ return;
+
/* avoid creating color buffer if not needed */
color_needed =
((flags & GPU_DRAW_ACTIVE_MCOL) && gridkey->color) ||
@@ -689,31 +709,19 @@
color_data= map_color_buffer(buffers, color_needed, totvert);
if(color_data) {
- int i, j, k;
+ int i, j;
for(i = 0; i < totgrid; ++i) {
DMGridData *grid= grids[grid_indices[i]];
for(j = 0; j < gridsize*gridsize; ++j, color_data += 3) {
DMGridData *elem = GRIDELEM_AT(grid, j, gridkey);
- float vc[3] = {1, 1, 1}, mask;
+ float col[3], mask;
- /* combine colors */
- for(k = 0; k < gridkey->color; ++k) {
- float *col = GRIDELEM_COLOR(elem, gridkey)[k];
-
- /* TODO: check layer enabled/strength */
-
- /* for now we just combine layers in order
- interpolating using the alpha component
- ("order" is ill-defined here since we
- don't guarantee the order of cdm data) */
- interp_v3_v3v3(vc, vc, col, col[3]);
- }
-
+ color_from_gridelem(elem, gridkey, col);
mask = paint_mask_from_gridelem(elem, gridkey, vdata);
- gpu_colors_from_floats(color_data, vc, mask);
+ gpu_colors_from_floats(color_data, col, mask);
}
}
@@ -779,12 +787,6 @@
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
}
- buffers->grids = grids;
- buffers->grid_indices = grid_indices;
- buffers->totgrid = totgrid;
- buffers->gridsize = gridsize;
- buffers->gridkey = gridkey;
-
//printf("node updated %p\n", buffers_v);
}
@@ -875,10 +877,137 @@
return buffers;
}
-void GPU_draw_buffers(GPU_Buffers *buffers_v, GPUDrawFlags flags)
+static void gpu_draw_node_without_vb(GPU_Buffers *buffers, PBVH *pbvh, PBVHNode *node, GPUDrawFlags flags)
{
- GPU_Buffers *buffers = buffers_v;
+ DMGridData **grids;
+ GridKey *gridkey;
+ int *grid_indices, totgrid, gridsize;
+ CustomData *vdata = NULL, *fdata = NULL;
+ int mcol_first_layer, pmask_first_layer;
+ int i, use_grids, use_color;
+ use_grids = BLI_pbvh_uses_grids(pbvh);
+
+ /* see if color data is needed */
+ if(use_grids) {
+ BLI_pbvh_node_get_grids(pbvh, node, &grid_indices,
+ &totgrid, NULL, &gridsize,
+ &grids, NULL, &gridkey);
+ use_color = gridkey->color || gridkey->mask;
+ if(use_color)
+ BLI_pbvh_get_customdata(pbvh, &vdata, NULL);
+ }
+ else {
+ BLI_pbvh_get_customdata(pbvh, &vdata, &fdata);
+
+ mcol_first_layer = CustomData_get_layer_index(fdata, CD_MCOL);
+ pmask_first_layer = CustomData_get_layer_index(vdata, CD_PAINTMASK);
+
+ use_color = mcol_first_layer != -1 || pmask_first_layer != -1;
+ }
+
+ if(use_color) {
+ glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+ glEnable(GL_COLOR_MATERIAL);
+ }
+
+ if(use_grids) {
+ int x, y;
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list