Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pbvh.c
| Show First 20 Lines • Show All 1,003 Lines • ▼ Show 20 Lines | |||||
| typedef struct PBVHUpdateData { | typedef struct PBVHUpdateData { | ||||
| PBVH *bvh; | PBVH *bvh; | ||||
| PBVHNode **nodes; | PBVHNode **nodes; | ||||
| int totnode; | int totnode; | ||||
| float (*vnors)[3]; | float (*vnors)[3]; | ||||
| int flag; | int flag; | ||||
| bool show_vcol; | |||||
| bool show_sculpt_face_sets; | bool show_sculpt_face_sets; | ||||
| } PBVHUpdateData; | } PBVHUpdateData; | ||||
| static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, | static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict UNUSED(tls)) | const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| PBVHUpdateData *data = userdata; | PBVHUpdateData *data = userdata; | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | PBVHUpdateData data = { | ||||
| .flag = flag, | .flag = flag, | ||||
| }; | }; | ||||
| PBVHParallelSettings settings; | PBVHParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, totnode); | BKE_pbvh_parallel_range_settings(&settings, true, totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings); | ||||
| } | } | ||||
| static int pbvh_get_buffers_update_flags(PBVH *bvh, bool show_vcol) | static int pbvh_get_buffers_update_flags(PBVH *UNUSED(bvh)) | ||||
| { | { | ||||
| int update_flags = 0; | int update_flags = GPU_PBVH_BUFFERS_SHOW_VCOL | GPU_PBVH_BUFFERS_SHOW_MASK | | ||||
| update_flags |= bvh->show_mask ? GPU_PBVH_BUFFERS_SHOW_MASK : 0; | GPU_PBVH_BUFFERS_SHOW_SCULPT_FACE_SETS; | ||||
| update_flags |= show_vcol ? GPU_PBVH_BUFFERS_SHOW_VCOL : 0; | |||||
| update_flags |= bvh->show_face_sets ? GPU_PBVH_BUFFERS_SHOW_SCULPT_FACE_SETS : 0; | |||||
| return update_flags; | return update_flags; | ||||
| } | } | ||||
| static void pbvh_update_draw_buffer_cb(void *__restrict userdata, | static void pbvh_update_draw_buffer_cb(void *__restrict userdata, | ||||
| const int n, | const int n, | ||||
| const TaskParallelTLS *__restrict UNUSED(tls)) | const TaskParallelTLS *__restrict UNUSED(tls)) | ||||
| { | { | ||||
| /* Create and update draw buffers. The functions called here must not | /* Create and update draw buffers. The functions called here must not | ||||
| Show All 23 Lines | switch (bvh->type) { | ||||
| case PBVH_BMESH: | case PBVH_BMESH: | ||||
| node->draw_buffers = GPU_pbvh_bmesh_buffers_build(bvh->flags & | node->draw_buffers = GPU_pbvh_bmesh_buffers_build(bvh->flags & | ||||
| PBVH_DYNTOPO_SMOOTH_SHADING); | PBVH_DYNTOPO_SMOOTH_SHADING); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (node->flag & PBVH_UpdateDrawBuffers) { | if (node->flag & PBVH_UpdateDrawBuffers) { | ||||
| const int update_flags = pbvh_get_buffers_update_flags(bvh, data->show_vcol); | const int update_flags = pbvh_get_buffers_update_flags(bvh); | ||||
| switch (bvh->type) { | switch (bvh->type) { | ||||
| case PBVH_GRIDS: | case PBVH_GRIDS: | ||||
| GPU_pbvh_grid_buffers_update(node->draw_buffers, | GPU_pbvh_grid_buffers_update(node->draw_buffers, | ||||
| bvh->subdiv_ccg, | bvh->subdiv_ccg, | ||||
| bvh->grids, | bvh->grids, | ||||
| bvh->grid_flag_mats, | bvh->grid_flag_mats, | ||||
| node->prim_indices, | node->prim_indices, | ||||
| node->totprim, | node->totprim, | ||||
| Show All 23 Lines | switch (bvh->type) { | ||||
| node->bm_unique_verts, | node->bm_unique_verts, | ||||
| node->bm_other_verts, | node->bm_other_verts, | ||||
| update_flags); | update_flags); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void pbvh_update_draw_buffers( | static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode, int update_flag) | ||||
| PBVH *bvh, PBVHNode **nodes, int totnode, bool show_vcol, int update_flag) | |||||
| { | { | ||||
| if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(bvh->type, PBVH_GRIDS, PBVH_BMESH)) { | if ((update_flag & PBVH_RebuildDrawBuffers) || ELEM(bvh->type, PBVH_GRIDS, PBVH_BMESH)) { | ||||
| /* Free buffers uses OpenGL, so not in parallel. */ | /* Free buffers uses OpenGL, so not in parallel. */ | ||||
| for (int n = 0; n < totnode; n++) { | for (int n = 0; n < totnode; n++) { | ||||
| PBVHNode *node = nodes[n]; | PBVHNode *node = nodes[n]; | ||||
| if (node->flag & PBVH_RebuildDrawBuffers) { | if (node->flag & PBVH_RebuildDrawBuffers) { | ||||
| GPU_pbvh_buffers_free(node->draw_buffers); | GPU_pbvh_buffers_free(node->draw_buffers); | ||||
| node->draw_buffers = NULL; | node->draw_buffers = NULL; | ||||
| Show All 9 Lines | for (int n = 0; n < totnode; n++) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Parallel creation and update of draw buffers. */ | /* Parallel creation and update of draw buffers. */ | ||||
| PBVHUpdateData data = { | PBVHUpdateData data = { | ||||
| .bvh = bvh, | .bvh = bvh, | ||||
| .nodes = nodes, | .nodes = nodes, | ||||
| .show_vcol = show_vcol, | |||||
| }; | }; | ||||
| PBVHParallelSettings settings; | PBVHParallelSettings settings; | ||||
| BKE_pbvh_parallel_range_settings(&settings, true, totnode); | BKE_pbvh_parallel_range_settings(&settings, true, totnode); | ||||
| BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_draw_buffer_cb, &settings); | BKE_pbvh_parallel_range(0, totnode, &data, pbvh_update_draw_buffer_cb, &settings); | ||||
| } | } | ||||
| static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag) | static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag) | ||||
| ▲ Show 20 Lines • Show All 1,300 Lines • ▼ Show 20 Lines | if (data->frustum && !BKE_pbvh_node_frustum_contain_AABB(node, data->frustum)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| data->accum_update_flag |= node->flag; | data->accum_update_flag |= node->flag; | ||||
| return true; | return true; | ||||
| } | } | ||||
| void BKE_pbvh_draw_cb(PBVH *bvh, | void BKE_pbvh_draw_cb(PBVH *bvh, | ||||
| bool show_vcol, | |||||
| bool update_only_visible, | bool update_only_visible, | ||||
| PBVHFrustumPlanes *update_frustum, | PBVHFrustumPlanes *update_frustum, | ||||
| PBVHFrustumPlanes *draw_frustum, | PBVHFrustumPlanes *draw_frustum, | ||||
| void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers), | void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers), | ||||
| void *user_data) | void *user_data) | ||||
| { | { | ||||
| PBVHNode **nodes; | PBVHNode **nodes; | ||||
| int totnode; | int totnode; | ||||
| const int update_flag = PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers; | const int update_flag = PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers; | ||||
| if (!update_only_visible) { | if (!update_only_visible) { | ||||
| /* Update all draw buffers, also those outside the view. */ | /* Update all draw buffers, also those outside the view. */ | ||||
| BKE_pbvh_search_gather(bvh, update_search_cb, POINTER_FROM_INT(update_flag), &nodes, &totnode); | BKE_pbvh_search_gather(bvh, update_search_cb, POINTER_FROM_INT(update_flag), &nodes, &totnode); | ||||
| if (totnode) { | if (totnode) { | ||||
| pbvh_update_draw_buffers(bvh, nodes, totnode, show_vcol, update_flag); | pbvh_update_draw_buffers(bvh, nodes, totnode, update_flag); | ||||
| } | } | ||||
| MEM_SAFE_FREE(nodes); | MEM_SAFE_FREE(nodes); | ||||
| } | } | ||||
| /* Gather visible nodes. */ | /* Gather visible nodes. */ | ||||
| PBVHDrawSearchData data = {.frustum = update_frustum, .accum_update_flag = 0}; | PBVHDrawSearchData data = {.frustum = update_frustum, .accum_update_flag = 0}; | ||||
| BKE_pbvh_search_gather(bvh, pbvh_draw_search_cb, &data, &nodes, &totnode); | BKE_pbvh_search_gather(bvh, pbvh_draw_search_cb, &data, &nodes, &totnode); | ||||
| if (update_only_visible && (data.accum_update_flag & update_flag)) { | if (update_only_visible && (data.accum_update_flag & update_flag)) { | ||||
| /* Update draw buffers in visible nodes. */ | /* Update draw buffers in visible nodes. */ | ||||
| pbvh_update_draw_buffers(bvh, nodes, totnode, show_vcol, data.accum_update_flag); | pbvh_update_draw_buffers(bvh, nodes, totnode, data.accum_update_flag); | ||||
| } | } | ||||
| /* Draw. */ | /* Draw. */ | ||||
| for (int a = 0; a < totnode; a++) { | for (int a = 0; a < totnode; a++) { | ||||
| PBVHNode *node = nodes[a]; | PBVHNode *node = nodes[a]; | ||||
| if (node->flag & PBVH_UpdateDrawBuffers) { | if (node->flag & PBVH_UpdateDrawBuffers) { | ||||
| /* Flush buffers uses OpenGL, so not in parallel. */ | /* Flush buffers uses OpenGL, so not in parallel. */ | ||||
| ▲ Show 20 Lines • Show All 307 Lines • Show Last 20 Lines | |||||