Revision: 39127
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39127
Author:   jwilkins
Date:     2011-08-07 11:06:03 +0000 (Sun, 07 Aug 2011)
Log Message:
-----------
Revision: 30844
Author: nicholasbishop
Date: 11:46:49 AM, Wednesday, July 28, 2010
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 : /branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
Modified : /branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
Modified : /branches/soc-2010-nicolasbishop/source/blender/gpu/GPU_buffers.h
Modified : 
/branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c

Modified Paths:
--------------
    branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
    branches/soc-2011-onion/source/blender/gpu/GPU_buffers.h
    branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c

Modified: branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h   2011-08-07 
11:01:55 UTC (rev 39126)
+++ branches/soc-2011-onion/source/blender/blenlib/BLI_pbvh.h   2011-08-07 
11:06:03 UTC (rev 39127)
@@ -148,6 +148,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-2011-onion/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c        
2011-08-07 11:01:55 UTC (rev 39126)
+++ branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c        
2011-08-07 11:06:03 UTC (rev 39127)
@@ -1332,6 +1332,18 @@
        *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)
@@ -1615,8 +1627,12 @@
 }
 
 //#include <GL/glew.h>
+typedef struct {
+       PBVH *pbvh;
+       GPUDrawFlags flags;
+} PBVHDrawData;
 
-void BLI_pbvh_node_draw(PBVHNode *node, void *data)
+void BLI_pbvh_node_draw(PBVHNode *node, void *data_v)
 {
 #if 0
        /* XXX: Just some quick code to show leaf nodes in different colors */
@@ -1634,7 +1650,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)
@@ -1649,8 +1667,12 @@
 void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int 
flags)
 {
        PBVHNode **nodes;
+       PBVHDrawData draw_data;
        int totnode;
 
+       draw_data.flags= flags;
+       draw_data.pbvh=  bvh;
+
        BLI_pbvh_search_gather(bvh, update_search_cb,
                               
SET_INT_IN_POINTER(PBVH_UpdateNormals|PBVH_UpdateVertBuffers|PBVH_UpdateColorBuffers),
                &nodes, &totnode);
@@ -1662,10 +1684,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-2011-onion/source/blender/gpu/GPU_buffers.h
===================================================================
--- branches/soc-2011-onion/source/blender/gpu/GPU_buffers.h    2011-08-07 
11:01:55 UTC (rev 39126)
+++ branches/soc-2011-onion/source/blender/gpu/GPU_buffers.h    2011-08-07 
11:06:03 UTC (rev 39127)
@@ -162,7 +162,8 @@
                                   int *grid_indices, int totgrid,
                                   int gridsize, struct GridKey *gridkey,
                                   struct CustomData *vdata, int flags);
-void GPU_draw_buffers(GPU_Buffers *buffers, int 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-2011-onion/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c     
2011-08-07 11:01:55 UTC (rev 39126)
+++ branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c     
2011-08-07 11:06:03 UTC (rev 39127)
@@ -1287,19 +1287,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;
 };
 
@@ -1350,6 +1337,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, int flags)
 {
@@ -1361,6 +1371,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,
@@ -1379,7 +1392,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);
@@ -1395,32 +1408,31 @@
                           draw separate quads so that mcols can abruptly
                           transition from one face to another */
                        for(j = 0; j < S; ++j) {
-                               int node_vert_index = face_vert_indices[i*4 + 
j];
-                               float mask_strength, mask_color[3];
-                               float v[3] = {1, 1, 1};
+                               int node_vert_index= face_vert_indices[i*4 + j];
+                               float col[3];
+                               float mask_strength;
+                               float mask_color[3];
 
-                               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,
+                                       4*face_index + j,
+                                       col);
 
-                                       mcol = fdata->layers[k].data;
-                                       mcol += face_index*4+j;
+                               paint_mask_color_from_vertex(
+                                       &mask_strength,
+                                       mask_color,
+                                       vdata,
+                                       vert_indices[node_vert_index],
+                                       pmask_totlayer,
+                                       pmask_first_layer);
 
-                                       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);
-                               }
-
-                               paint_mask_color_from_vertex(&mask_strength, 
mask_color, vdata,
-                                                             
vert_indices[node_vert_index],
-                                                             pmask_totlayer,
-                                                             
pmask_first_layer);
-
-                               gpu_colors_from_floats(color_data + 
node_vert_index*3, v, mask_strength, mask_color);
+                               gpu_colors_from_floats(
+                                       color_data + 3*node_vert_index,
+                                       col,
+                                       mask_strength,
+                                       mask_color);
                        }
                }
 
@@ -1458,8 +1470,6 @@
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
        }
-
-       buffers->mvert = mvert;
 }
 
 GPU_Buffers *GPU_build_mesh_buffers(GHash *map, MVert *mvert, MFace *mface,
@@ -1533,13 +1543,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,
                                   int flags)
@@ -1548,6 +1574,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) ||
@@ -1557,31 +1586,31 @@
        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_strength, 
mask_color[3];
+                               float col[3];
+                               float mask_strength;
+                               float mask_color[3];
 
-                               /* combine colors */
-                               for(k = 0; k < gridkey->color; ++k) {
-                                       float *col = GRIDELEM_COLOR(elem, 
gridkey)[k];
+                               color_from_gridelem(elem, gridkey, col);
 
-                                       /* TODO: check layer enabled/strength */
+                               paint_mask_color_from_gridelem(
+                                       &mask_strength,
+                                       mask_color,
+                                       elem,
+                                       gridkey,
+                                       vdata);
 
-                                       /* 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]);
-                               }
-
-                               paint_mask_color_from_gridelem(&mask_strength, 
mask_color, elem, gridkey, vdata);
-
-                               gpu_colors_from_floats(color_data, vc, 
mask_strength, mask_color);
+                               gpu_colors_from_floats(
+                                       color_data,
+                                       col,
+                                       mask_strength,
+                                       mask_color);
                        }
                }
 
@@ -1647,12 +1676,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);
 }
 
@@ -1743,8 +1766,143 @@
        return buffers;
 }
 
-void GPU_draw_buffers(GPU_Buffers *buffers, int flags)
+static void gpu_draw_node_without_vb(GPU_Buffers *buffers, PBVH *pbvh, 
PBVHNode *node, GPUDrawFlags flags)
 {
+       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);
+

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to