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:
-rw-r--r--source/blender/blenkernel/BKE_pbvh.h4
-rw-r--r--source/blender/blenkernel/intern/pbvh.c52
-rw-r--r--source/blender/blenkernel/intern/pbvh_bmesh.c6
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c35
4 files changed, 62 insertions, 35 deletions
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 304272d391d..c163054f681 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -128,6 +128,10 @@ void BKE_pbvh_bounding_box(const PBVH *bvh, float min[3], float max[3]);
/* multires hidden data, only valid for type == PBVH_GRIDS */
unsigned int **BKE_pbvh_grid_hidden(const PBVH *bvh);
+int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
+ int *grid_indices, int totgrid,
+ int gridsize);
+
/* multires level, only valid for type == PBVH_GRIDS */
void BKE_pbvh_get_grid_key(const PBVH *pbvh, struct CCGKey *key);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 17b8f5e474f..7de361db2d2 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -275,6 +275,7 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
GHashIterator *iter;
GHash *map;
int i, j, totface;
+ bool has_visible = false;
node->uniq_verts = node->face_verts = 0;
totface = node->totprim;
@@ -294,6 +295,9 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
map_insert_vert(bvh, map, &node->face_verts,
&node->uniq_verts, (&f->v1)[j]);
}
+
+ if(!paint_is_face_hidden(f, bvh->verts))
+ has_visible = true;
}
node->vert_indices = MEM_callocN(sizeof(int) *
@@ -331,6 +335,8 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
BKE_pbvh_node_mark_rebuild_draw(node);
+ BKE_pbvh_node_fully_hidden_set(node, !has_visible);
+
BLI_ghash_free(map, NULL, NULL);
}
@@ -346,6 +352,45 @@ static void update_vb(PBVH *bvh, PBVHNode *node, BBC *prim_bbc,
node->orig_vb = node->vb;
}
+/* Returns the number of visible quads in the nodes' grids. */
+int BKE_pbvh_count_grid_quads(BLI_bitmap **grid_hidden,
+ int *grid_indices, int totgrid,
+ int gridsize)
+{
+ int gridarea = (gridsize - 1) * (gridsize - 1);
+ int i, x, y, totquad;
+
+ /* grid hidden layer is present, so have to check each grid for
+ * visibility */
+
+ for (i = 0, totquad = 0; i < totgrid; i++) {
+ const BLI_bitmap *gh = grid_hidden[grid_indices[i]];
+
+ if (gh) {
+ /* grid hidden are present, have to check each element */
+ for (y = 0; y < gridsize - 1; y++) {
+ for (x = 0; x < gridsize - 1; x++) {
+ if (!paint_is_grid_face_hidden(gh, gridsize, x, y))
+ totquad++;
+ }
+ }
+ }
+ else
+ totquad += gridarea;
+ }
+
+ return totquad;
+}
+
+static void build_grid_leaf_node(PBVH *bvh, PBVHNode *node)
+{
+ int totquads = BKE_pbvh_count_grid_quads(bvh->grid_hidden, node->prim_indices,
+ node->totprim, bvh->gridkey.grid_size);
+ BKE_pbvh_node_fully_hidden_set(node, (totquads == 0));
+ BKE_pbvh_node_mark_rebuild_draw(node);
+}
+
+
static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc,
int offset, int count)
{
@@ -359,8 +404,9 @@ static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc,
if (bvh->faces)
build_mesh_leaf_node(bvh, bvh->nodes + node_index);
- else
- BKE_pbvh_node_mark_rebuild_draw(bvh->nodes + node_index);
+ else {
+ build_grid_leaf_node(bvh, bvh->nodes + node_index);
+ }
}
/* Return zero if all primitives in the node can be drawn with the
@@ -1033,7 +1079,7 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
GPU_build_grid_pbvh_buffers(node->prim_indices,
node->totprim,
bvh->grid_hidden,
- bvh->gridkey.grid_size);
+ bvh->gridkey.grid_size);
break;
case PBVH_FACES:
node->draw_buffers =
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index b5495ded487..83e0d1a4740 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -48,6 +48,7 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index, const int cd_ver
{
GSetIterator gs_iter;
PBVHNode *n = &bvh->nodes[node_index];
+ bool has_visible = false;
/* Create vert hash sets */
n->bm_unique_verts = BLI_gset_ptr_new("bm_unique_verts");
@@ -80,6 +81,9 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index, const int cd_ver
/* Update node bounding box */
BB_expand(&n->vb, v->co);
} while ((l_iter = l_iter->next) != l_first);
+
+ if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN))
+ has_visible = true;
}
BLI_assert(n->vb.bmin[0] <= n->vb.bmax[0] &&
@@ -90,6 +94,8 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index, const int cd_ver
/* Build GPU buffers for new node and update vertex normals */
BKE_pbvh_node_mark_rebuild_draw(n);
+
+ BKE_pbvh_node_fully_hidden_set(n, !has_visible);
n->flag |= PBVH_UpdateNormals;
}
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index e33d72e980c..f5256f18897 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -51,6 +51,7 @@
#include "BKE_ccg.h"
#include "BKE_DerivedMesh.h"
#include "BKE_paint.h"
+#include "BKE_pbvh.h"
#include "DNA_userdef_types.h"
@@ -1827,36 +1828,6 @@ void GPU_update_grid_pbvh_buffers(GPU_PBVH_Buffers *buffers, CCGElem **grids,
//printf("node updated %p\n", buffers);
}
-/* Returns the number of visible quads in the nodes' grids. */
-static int gpu_count_grid_quads(BLI_bitmap **grid_hidden,
- int *grid_indices, int totgrid,
- int gridsize)
-{
- int gridarea = (gridsize - 1) * (gridsize - 1);
- int i, x, y, totquad;
-
- /* grid hidden layer is present, so have to check each grid for
- * visibility */
-
- for (i = 0, totquad = 0; i < totgrid; i++) {
- const BLI_bitmap *gh = grid_hidden[grid_indices[i]];
-
- if (gh) {
- /* grid hidden are present, have to check each element */
- for (y = 0; y < gridsize - 1; y++) {
- for (x = 0; x < gridsize - 1; x++) {
- if (!paint_is_grid_face_hidden(gh, gridsize, x, y))
- totquad++;
- }
- }
- }
- else
- totquad += gridarea;
- }
-
- return totquad;
-}
-
/* Build the element array buffer of grid indices using either
* unsigned shorts or unsigned ints. */
#define FILL_QUAD_BUFFER(type_, tot_quad_, buffer_) \
@@ -1960,7 +1931,7 @@ static GLuint gpu_get_grid_buffer(int gridsize, GLenum *index_type, unsigned *to
}
GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
- BLI_bitmap **grid_hidden, int gridsize)
+ BLI_bitmap **grid_hidden, int gridsize)
{
GPU_PBVH_Buffers *buffers;
int totquad;
@@ -1974,7 +1945,7 @@ GPU_PBVH_Buffers *GPU_build_grid_pbvh_buffers(int *grid_indices, int totgrid,
buffers->use_matcaps = false;
/* Count the number of quads */
- totquad = gpu_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize);
+ totquad = BKE_pbvh_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize);
/* totally hidden node, return here to avoid BufferData with zero below. */
if (totquad == 0)