From f36d98bb1d510cf11d397ad4323e04c183f62e92 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 13 Mar 2020 12:54:04 +0100 Subject: Subdiv: Fix loose geometry callbacks in certain conditions Loose vertices and vertices of loose edges callback was not working correct if some of other callbacks were set to NULL. Was caused by missing bitmask set in the callbacks which were set to NULL. --- source/blender/blenkernel/intern/subdiv_foreach.c | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/blender/blenkernel/intern/subdiv_foreach.c') diff --git a/source/blender/blenkernel/intern/subdiv_foreach.c b/source/blender/blenkernel/intern/subdiv_foreach.c index 0f56fc5ec21..347e2843423 100644 --- a/source/blender/blenkernel/intern/subdiv_foreach.c +++ b/source/blender/blenkernel/intern/subdiv_foreach.c @@ -1772,6 +1772,21 @@ static void subdiv_foreach_single_geometry_vertices(SubdivForeachTaskContext *ct } } +static void subdiv_foreach_mark_non_loose_geometry(SubdivForeachTaskContext *ctx) +{ + const Mesh *coarse_mesh = ctx->coarse_mesh; + const MPoly *coarse_mpoly = coarse_mesh->mpoly; + const MLoop *coarse_mloop = coarse_mesh->mloop; + for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) { + const MPoly *coarse_poly = &coarse_mpoly[poly_index]; + for (int corner = 0; corner < coarse_poly->totloop; corner++) { + const MLoop *loop = &coarse_mloop[coarse_poly->loopstart + corner]; + BLI_BITMAP_ENABLE(ctx->coarse_edges_used_map, loop->e); + BLI_BITMAP_ENABLE(ctx->coarse_vertices_used_map, loop->v); + } + } +} + static void subdiv_foreach_single_thread_tasks(SubdivForeachTaskContext *ctx) { /* NOTE: In theory, we can try to skip allocation of TLS here, but in @@ -1785,6 +1800,15 @@ static void subdiv_foreach_single_thread_tasks(SubdivForeachTaskContext *ctx) /* Run callbacks which are supposed to be run once per shared geometry. */ subdiv_foreach_single_geometry_vertices(ctx, tls); subdiv_foreach_tls_free(ctx, tls); + + const SubdivForeachContext *foreach_context = ctx->foreach_context; + const bool is_loose_geometry_tagged = (foreach_context->vertex_every_edge != NULL && + foreach_context->vertex_every_corner != NULL); + const bool is_loose_geometry_tags_needed = (foreach_context->vertex_loose != NULL || + foreach_context->vertex_of_loose_edge != NULL); + if (is_loose_geometry_tagged && is_loose_geometry_tags_needed) { + subdiv_foreach_mark_non_loose_geometry(ctx); + } } static void subdiv_foreach_task(void *__restrict userdata, -- cgit v1.2.3