From 53946a5710f63299f1da4499c647439920782fcd Mon Sep 17 00:00:00 2001 From: Martin Fouilleul Date: Wed, 5 Apr 2023 09:52:12 +0200 Subject: [PATCH] [mtl canvas] fix end joint not generated for paths with only 2 elements --- examples/polygon/main.c | 2 +- src/mtl_renderer.m | 3 ++- src/mtl_renderer.metal | 26 -------------------------- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/examples/polygon/main.c b/examples/polygon/main.c index ea94d50..4b61cb1 100644 --- a/examples/polygon/main.c +++ b/examples/polygon/main.c @@ -130,7 +130,7 @@ int main() mg_set_joint(MG_JOINT_MITER); mg_set_max_joint_excursion(20); - mg_set_cap(MG_CAP_SQUARE); + mg_set_cap(MG_CAP_NONE); mg_move_to(200, 200); mg_line_to(300, 300); diff --git a/src/mtl_renderer.m b/src/mtl_renderer.m index 2e91df5..62e1730 100644 --- a/src/mtl_renderer.m +++ b/src/mtl_renderer.m @@ -514,7 +514,7 @@ u32 mg_mtl_render_stroke_subpath(mg_mtl_encoding_context* context, previousEndTangent = endTangent; currentPoint = endPoint; } - u32 subPathEltCount = eltIndex - (startIndex+1); + u32 subPathEltCount = eltIndex - startIndex; //NOTE(martin): draw end cap / joint. We ensure there's at least two segments to draw a closing joint if( subPathEltCount > 1 @@ -525,6 +525,7 @@ u32 mg_mtl_render_stroke_subpath(mg_mtl_encoding_context* context, { //NOTE(martin): add a closing joint if the path is closed mg_mtl_stroke_joint(context, endPoint, endTangent, firstTangent); + printf("closing joint for shape %i\n", context->pathIndex); } } else if(attributes->cap == MG_CAP_SQUARE) diff --git a/src/mtl_renderer.metal b/src/mtl_renderer.metal index c1b3072..5e1e395 100644 --- a/src/mtl_renderer.metal +++ b/src/mtl_renderer.metal @@ -316,24 +316,6 @@ void mtl_segment_bin_to_tiles(thread mtl_segment_setup_context* context, device bool crossT = (stl*str < 0); bool crossB = (sbl*sbr < 0); - mtl_log(context->log, "tile "); - mtl_log_i32(context->log, x); - mtl_log(context->log, ", "); - mtl_log_i32(context->log, y); - mtl_log(context->log, "\n"); - mtl_log(context->log, "crossL "); - mtl_log_i32(context->log, crossL); - mtl_log(context->log, "\n"); - mtl_log(context->log, "crossR "); - mtl_log_i32(context->log, crossR); - mtl_log(context->log, "\n"); - mtl_log(context->log, "crossT "); - mtl_log_i32(context->log, crossT); - mtl_log(context->log, "\n"); - mtl_log(context->log, "crossB "); - mtl_log_i32(context->log, crossB); - mtl_log(context->log, "\n"); - float2 s0, s1; if(seg->config == MG_MTL_TL||seg->config == MG_MTL_BR) { @@ -355,14 +337,6 @@ void mtl_segment_bin_to_tiles(thread mtl_segment_setup_context* context, device && s1.y >= tileBox.y && s1.y < tileBox.w; - mtl_log(context->log, "s0Inside "); - mtl_log_i32(context->log, s0Inside ? 1 : 0); - mtl_log(context->log, "\n"); - mtl_log(context->log, "s1Inside "); - mtl_log_i32(context->log, s1Inside ? 1 : 0); - mtl_log(context->log, "\n"); - - if(crossL || crossR || crossT || crossB || s0Inside || s1Inside) { int tileOpIndex = atomic_fetch_add_explicit(context->tileOpCount, 1, memory_order_relaxed);