[Bf-blender-cvs] [9503751c833] temp_bmesh_multires: Sculpt dyntopo
Joseph Eagar
noreply at git.blender.org
Tue Aug 17 06:04:37 CEST 2021
Commit: 9503751c83345b2941a4fc41dcc979ef456b0c5f
Author: Joseph Eagar
Date: Mon Aug 16 20:50:02 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB9503751c83345b2941a4fc41dcc979ef456b0c5f
Sculpt dyntopo
* Added a limited "fast draw" mode to pbvh drawing
that tries to limit data sent to the GPU.
- Facesets and mask data are disabled.
- Indexed mode is forced.
- Does not work (at all) for multires.
* Finally fixed some outstanding bmesh sculpt undo bugs:
- Forgot to mark pbvh nodes to update their bounds, which
produced a bug I had thought was caused by something else.
- Hopefully fixed a long-standing occasional memory corruption
bug.
===================================================================
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenkernel/intern/pbvh_bmesh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/draw/engines/overlay/overlay_sculpt.c
M source/blender/editors/sculpt_paint/paint_mask.c
M source/blender/editors/sculpt_paint/sculpt_undo.c
M source/blender/gpu/GPU_buffers.h
M source/blender/gpu/intern/gpu_buffers.c
M source/blender/makesdna/DNA_scene_types.h
M source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index da05ae7b1cc..25e4f2d501a 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -935,6 +935,7 @@ class VIEW3D_PT_sculpt_options(Panel, View3DPaintPanel):
col = layout.column(heading="Display", align=True)
col.prop(sculpt, "show_low_resolution")
col.prop(sculpt, "use_sculpt_delay_updates")
+ col.prop(sculpt, "use_fast_draw")
col.prop(sculpt, "use_deform_only")
col.separator()
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 7314a2dc8ff..db091a8b878 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -655,6 +655,8 @@ typedef struct SculptSession {
// id of current stroke, used to detect
// if vertex original data needs to be updated
int stroke_id;
+
+ bool fast_draw; // hides facesets/masks and forces smooth to save GPU bandwidth
} SculptSession;
void BKE_sculptsession_free(struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 97d3c77fb50..2f87895b262 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -240,21 +240,24 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
struct CustomData *ldata,
struct CustomData *pdata,
const struct MLoopTri *looptri,
- int looptri_num);
+ int looptri_num,
+ bool fast_draw);
void BKE_pbvh_build_grids(PBVH *pbvh,
struct CCGElem **grids,
int totgrid,
struct CCGKey *key,
void **gridfaces,
struct DMFlagMat *flagmats,
- unsigned int **grid_hidden);
+ unsigned int **grid_hidden,
+ bool fast_draw);
void BKE_pbvh_build_bmesh(PBVH *pbvh,
struct BMesh *bm,
bool smooth_shading,
struct BMLog *log,
const int cd_vert_node_offset,
const int cd_face_node_offset,
- const int cd_dyn_vert);
+ const int cd_dyn_vert,
+ bool fast_draw);
void BKE_pbvh_update_offsets(PBVH *pbvh,
const int cd_vert_node_offset,
const int cd_face_node_offset,
@@ -682,10 +685,10 @@ bool BKE_pbvh_node_vert_update_check_any(PBVH *pbvh, PBVHNode *node);
// void BKE_pbvh_node_BB_reset(PBVHNode *node);
// void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]);
-bool pbvh_has_mask(const PBVH *pbvh);
+bool BKE_pbvh_draw_mask(const PBVH *pbvh);
void pbvh_show_mask_set(PBVH *pbvh, bool show_mask);
-bool pbvh_has_face_sets(PBVH *pbvh);
+bool BKE_pbvh_draw_face_sets(PBVH *pbvh);
void pbvh_show_face_sets_set(PBVH *pbvh, bool show_face_sets);
/* Parallelization */
@@ -740,6 +743,8 @@ void BKE_pbvh_update_vert_boundary(int cd_dyn_vert, int cd_faceset_offset, struc
#define DYNTOPO_DYNAMIC_TESS
+PBVHNode *BKE_pbvh_get_node_leaf_safe(PBVH *pbvh, int i);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 6463fcf8780..2cc5561000b 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1701,6 +1701,7 @@ static void sculpt_update_object(Depsgraph *depsgraph,
}
ss->subdiv_ccg = me_eval->runtime.subdiv_ccg;
+ ss->fast_draw = (scene->toolsettings->sculpt->flags & SCULPT_FAST_DRAW) != 0;
PBVH *pbvh = BKE_sculpt_object_pbvh_ensure(depsgraph, ob);
BLI_assert(pbvh == ss->pbvh);
@@ -2137,7 +2138,8 @@ static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
ob->sculpt->bm_log,
ob->sculpt->cd_vert_node_offset,
ob->sculpt->cd_face_node_offset,
- ob->sculpt->cd_dyn_vert);
+ ob->sculpt->cd_dyn_vert,
+ ob->sculpt->fast_draw);
pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
pbvh_show_face_sets_set(pbvh, false);
@@ -2167,7 +2169,8 @@ static PBVH *build_pbvh_from_regular_mesh(Object *ob, Mesh *me_eval_deform, bool
&me->ldata,
&me->pdata,
looptri,
- looptris_num);
+ looptris_num,
+ ob->sculpt->fast_draw);
pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
pbvh_show_face_sets_set(pbvh, ob->sculpt->show_face_sets);
@@ -2199,7 +2202,8 @@ static PBVH *build_pbvh_from_ccg(Object *ob, SubdivCCG *subdiv_ccg, bool respect
&key,
(void **)subdiv_ccg->grid_faces,
subdiv_ccg->grid_flag_mats,
- subdiv_ccg->grid_hidden);
+ subdiv_ccg->grid_hidden,
+ ob->sculpt->fast_draw);
pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
pbvh_show_face_sets_set(pbvh, ob->sculpt->show_face_sets);
return pbvh;
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index abadab127a8..52058661da6 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -591,7 +591,8 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
struct CustomData *ldata,
struct CustomData *pdata,
const MLoopTri *looptri,
- int looptri_num)
+ int looptri_num,
+ bool fast_draw)
{
BBC *prim_bbc = NULL;
BB cb;
@@ -639,6 +640,10 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
pbvh_build(pbvh, &cb, prim_bbc, looptri_num);
}
+ if (fast_draw) {
+ pbvh->flags |= PBVH_FAST_DRAW;
+ }
+
MEM_freeN(prim_bbc);
MEM_freeN(pbvh->vert_bitmap);
}
@@ -650,7 +655,8 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
CCGKey *key,
void **gridfaces,
DMFlagMat *flagmats,
- BLI_bitmap **grid_hidden)
+ BLI_bitmap **grid_hidden,
+ bool fast_draw)
{
const int gridsize = key->grid_size;
@@ -689,6 +695,10 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
pbvh_build(pbvh, &cb, prim_bbc, totgrid);
}
+ if (fast_draw) {
+ pbvh->flags |= PBVH_FAST_DRAW;
+ }
+
MEM_freeN(prim_bbc);
}
@@ -1454,20 +1464,11 @@ void pbvh_update_free_all_draw_buffers(PBVH *pbvh, PBVHNode *node)
}
}
-static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag)
+ATTR_NO_OPT static void pbvh_update_draw_buffers(PBVH *pbvh,
+ PBVHNode **nodes,
+ int totnode,
+ int update_flag)
{
- if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
- /* Free buffers uses OpenGL, so not in parallel. */
- for (int n = 0; n < totnode; n++) {
- PBVHNode *node = nodes[n];
- if (node->flag & PBVH_RebuildDrawBuffers) {
- pbvh_free_all_draw_buffers(node);
- }
- else if ((node->flag & PBVH_UpdateDrawBuffers)) {
- pbvh_update_free_all_draw_buffers(pbvh, node);
- }
- }
- }
CustomData *vdata;
CustomData *ldata;
@@ -1486,7 +1487,21 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
ldata = pbvh->ldata;
}
- GPU_pbvh_update_attribute_names(vdata, ldata, GPU_pbvh_need_full_render_get());
+ GPU_pbvh_update_attribute_names(
+ vdata, ldata, GPU_pbvh_need_full_render_get(), pbvh->flags & PBVH_FAST_DRAW);
+
+ if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(pbvh->type, PBVH_GRIDS, PBVH_BMESH)) {
+ /* Free buffers uses OpenGL, so not in parallel. */
+ for (int n = 0; n < totnode; n++) {
+ PBVHNode *node = nodes[n];
+ if (node->flag & PBVH_RebuildDrawBuffers) {
+ pbvh_free_all_draw_buffers(node);
+ }
+ else if ((node->flag & PBVH_UpdateDrawBuffers)) {
+ pbvh_update_free_all_draw_buffers(pbvh, node);
+ }
+ }
+ }
/* Parallel creation and update of draw buffers. */
PBVHUpdateData data = {
@@ -3252,8 +3267,12 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
}
}
-bool pbvh_has_mask(const PBVH *pbvh)
+bool BKE_pbvh_draw_mask(const PBVH *pbvh)
{
+ if (pbvh->flags & PBVH_FAST_DRAW) {
+ return false;
+ }
+
switch (pbvh->type) {
case PBVH_GRIDS:
return (pbvh->gridkey.has_mask != 0);
@@ -3286,8 +3305,12 @@ SculptFaceRef BKE_pbvh_table_index_to_face(PBVH *pbvh, int idx)
return BKE_pbvh_make_fref(idx);
}
-bool pbvh_has_face_sets(PBVH *pbvh)
+bool BKE_pbvh_draw_face_sets(PBVH *pbvh)
{
+ if (pbvh->flags & PBVH_FAST_DRAW) {
+ return false;
+ }
+
switch (pbvh->type) {
case PBVH_GRIDS:
return (pbvh->pdata && CustomData_get_layer(pbvh->pdata, CD_SCULPT_FACE_SETS));
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index e2f926fa2f8..f8f3beaccaa 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -545,11 +545,13 @@ void bke_pbvh_insert_face(PBVH *pbvh, struct BMFace *f)
static void pbvh_bmesh_regen_node_verts(PBVH *pbvh, PBVHNode *node)
{
- int usize = BLI_table_gset_len(node->bm_other_verts);
+ node->flag &= ~PBVH_RebuildNodeVerts;
+
+ int usize = BLI_table_gset_len(node->bm_unique_verts);
int osize = BLI_table_gset_len(node->bm_other_verts);
- BLI_table_gset_free(node->bm_other_verts, NULL);
BLI_table_gset_free(
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list