diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-06-08 22:30:01 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-06-08 22:30:01 +0300 |
commit | 285a68b7bbf2fa40e41d507991467387f5dd5264 (patch) | |
tree | 0d1f4ea92f6d7e9eb512d85e541905bc198800f6 /source/blender/blenkernel/intern/pbvh.c | |
parent | 9c28f0eb37aebd6e5eae0763b008ef02d5ce081b (diff) |
Sculpt: PBVH Draw Support for EEVEE
This patch adds support for PBVH drawing in EEVEE.
Notes:
# PBVH_FACES only. For Multires we'll need an API to get/cache attributes. DynTopo support will be merged in later with sculpt-dev's DynTopo implementation.
# Supports vertex color and UV attributes only; other types can be added fairly easily though.
# Workbench only sends the active vertex color and UV layers to the GPU.
# Added a new draw engine API method, DRW_cdlayer_attr_aliases_add. Please review.
# The vertex format object is now stored in the pbvh.
Reviewed By: Clément Foucault & Brecht Van Lommel & Jeroen Bakker
Differential Revision: https://developer.blender.org/D13897
Ref D13897
Diffstat (limited to 'source/blender/blenkernel/intern/pbvh.c')
-rw-r--r-- | source/blender/blenkernel/intern/pbvh.c | 98 |
1 files changed, 77 insertions, 21 deletions
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index cdc4dfdccff..8c9db339753 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -714,6 +714,10 @@ void BKE_pbvh_free(PBVH *pbvh) MEM_SAFE_FREE(pbvh->vert_bitmap); + if (pbvh->vbo_id) { + GPU_pbvh_free_format(pbvh->vbo_id); + } + MEM_freeN(pbvh); } @@ -1299,6 +1303,17 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata, PBVH *pbvh = data->pbvh; PBVHNode *node = data->nodes[n]; + CustomData *vdata, *ldata; + + if (!pbvh->bm) { + vdata = pbvh->vdata; + ldata = pbvh->ldata; + } + else { + vdata = &pbvh->bm->vdata; + ldata = &pbvh->bm->ldata; + } + if (node->flag & PBVH_RebuildDrawBuffers) { switch (pbvh->type) { case PBVH_GRIDS: @@ -1326,7 +1341,8 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata, const int update_flags = pbvh_get_buffers_update_flags(pbvh); switch (pbvh->type) { case PBVH_GRIDS: - GPU_pbvh_grid_buffers_update(node->draw_buffers, + GPU_pbvh_grid_buffers_update(pbvh->vbo_id, + node->draw_buffers, pbvh->subdiv_ccg, pbvh->grids, pbvh->grid_flag_mats, @@ -1339,26 +1355,22 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata, update_flags); break; case PBVH_FACES: { - CustomDataLayer *layer = NULL; - eAttrDomain domain; - - BKE_pbvh_get_color_layer(pbvh->mesh, &layer, &domain); - - GPU_pbvh_mesh_buffers_update(node->draw_buffers, + GPU_pbvh_mesh_buffers_update(pbvh->vbo_id, + node->draw_buffers, pbvh->verts, - pbvh->vert_normals, + vdata, + ldata, CustomData_get_layer(pbvh->vdata, CD_PAINT_MASK), - layer ? layer->data : NULL, - layer ? layer->type : -1, - layer ? domain : ATTR_DOMAIN_AUTO, CustomData_get_layer(pbvh->pdata, CD_SCULPT_FACE_SETS), pbvh->face_sets_color_seed, pbvh->face_sets_color_default, - update_flags); + update_flags, + pbvh->vert_normals); break; } case PBVH_BMESH: - GPU_pbvh_bmesh_buffers_update(node->draw_buffers, + GPU_pbvh_bmesh_buffers_update(pbvh->vbo_id, + node->draw_buffers, pbvh->bm, node->bm_faces, node->bm_unique_verts, @@ -1379,8 +1391,49 @@ void pbvh_free_draw_buffers(PBVH *pbvh, PBVHNode *node) } } -static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag) +static void pbvh_update_draw_buffers( + PBVH *pbvh, PBVHNode **nodes, int totnode, int update_flag, bool full_render) { + const CustomData *vdata; + const CustomData *ldata; + + if (!pbvh->vbo_id) { + pbvh->vbo_id = GPU_pbvh_make_format(); + } + + switch (pbvh->type) { + case PBVH_BMESH: + if (!pbvh->bm) { + /* BMesh hasn't been created yet */ + return; + } + + vdata = &pbvh->bm->vdata; + ldata = &pbvh->bm->ldata; + break; + case PBVH_FACES: + vdata = pbvh->vdata; + ldata = pbvh->ldata; + break; + case PBVH_GRIDS: + ldata = vdata = NULL; + break; + } + + const bool active_attrs_only = !full_render; + + /* rebuild all draw buffers if attribute layout changed */ + if (GPU_pbvh_attribute_names_update(pbvh->type, pbvh->vbo_id, vdata, ldata, active_attrs_only)) { + /* attribute layout changed; force rebuild */ + for (int i = 0; i < pbvh->totnode; i++) { + PBVHNode *node = pbvh->nodes + i; + + if (node->flag & PBVH_Leaf) { + node->flag |= PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw; + } + } + } + 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++) { @@ -2783,8 +2836,11 @@ void BKE_pbvh_draw_cb(PBVH *pbvh, PBVHFrustumPlanes *update_frustum, PBVHFrustumPlanes *draw_frustum, void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers), - void *user_data) + void *user_data, + bool full_render) { + pbvh->draw_cache_invalid = false; + PBVHNode **nodes; int totnode; int update_flag = 0; @@ -2808,7 +2864,7 @@ void BKE_pbvh_draw_cb(PBVH *pbvh, /* Update draw buffers. */ if (totnode != 0 && (update_flag & (PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers))) { - pbvh_update_draw_buffers(pbvh, nodes, totnode, update_flag); + pbvh_update_draw_buffers(pbvh, nodes, totnode, update_flag, full_render); } MEM_SAFE_FREE(nodes); @@ -3156,6 +3212,11 @@ bool BKE_pbvh_is_drawing(const PBVH *pbvh) return pbvh->is_drawing; } +bool BKE_pbvh_draw_cache_invalid(const PBVH *pbvh) +{ + return pbvh->draw_cache_invalid; +} + void BKE_pbvh_is_drawing_set(PBVH *pbvh, bool val) { pbvh->is_drawing = val; @@ -3229,8 +3290,3 @@ void BKE_pbvh_ensure_node_loops(PBVH *pbvh) MEM_SAFE_FREE(visit); } - -bool BKE_pbvh_draw_cache_invalid(const PBVH *pbvh) -{ - return pbvh->draw_cache_invalid; -} |