From ed7873c261c6626591b462d09cb569dfbbac79c2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 2 Sep 2019 14:15:33 +0200 Subject: [PATCH] simplify path loops increment with PATH_IS_CURVE_BIT on end point of begin/end pair --- src/vkvg_context.c | 4 +- src/vkvg_context_internal.c | 76 +++++++++++-------------------------- src/vkvg_internal.h | 6 +-- tests/common/test.c | 2 +- tests/multilines.c | 6 +-- 5 files changed, 30 insertions(+), 64 deletions(-) diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 1c80d37..92849c2 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -357,8 +357,7 @@ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, floa } if (EQUF(a2-a1,M_PIF*2.f)){//if arc is complete circle, last point is the same as the first one - ctx->pathes[ctx->pathPtr+ctx->curvePtr+2] = ctx->pointCount - 1; - ctx->curvePtr+=2; + _set_curve_end(ctx); vkvg_close_path(ctx); return; } @@ -619,7 +618,6 @@ void vkvg_stroke_preserve (VkvgContext ctx) } if (_path_has_curves (ctx,ptrPath)) { - while (i < lastPathPointIdx){ if (ptrPath + ptrCurve + 2 < ctx->pathPtr && (ctx->pathes [ptrPath + 2 + ptrCurve]&PATH_ELT_MASK) == i){ uint32_t lastCurvePoint = ctx->pathes[ptrPath + 3 + ptrCurve]&PATH_ELT_MASK; diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index f8365bc..c25528a 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -59,12 +59,12 @@ inline vec2 _get_current_position (VkvgContext ctx) { } //set curve start point and set path has curve bit inline void _set_curve_start (VkvgContext ctx) { - ctx->pathes[ctx->pathPtr+ctx->curvePtr+1] = ctx->pointCount - 1; + ctx->pathes[ctx->pathPtr+ctx->curvePtr+1] = (ctx->pointCount - 1); ctx->pathes[ctx->pathPtr-1] |= PATH_HAS_CURVES_BIT; } //set curve end point and set path has curve bit inline void _set_curve_end (VkvgContext ctx) { - ctx->pathes[ctx->pathPtr+ctx->curvePtr+2] = ctx->pointCount - 1; + ctx->pathes[ctx->pathPtr+ctx->curvePtr+2] = (ctx->pointCount - 1)|PATH_IS_CURVE_BIT; ctx->curvePtr+=2; _check_pathes_array(ctx); } @@ -847,8 +847,11 @@ void _poly_fill (VkvgContext ctx){ v.uv.z = -1; while (ptrPath < ctx->pathPtr){ + if (ctx->pathes[ptrPath+1]&PATH_IS_CURVE_BIT){ + ptrPath += 2; + continue; + } //close path - uint32_t ptrCurve = 0; ctx->pathes[ptrPath] |= PATH_CLOSED_BIT;// ctx->pathes[ptrPath];//close path by setting start and end equal uint32_t firstPtIdx = ctx->pathes[ptrPath]&PATH_ELT_MASK; @@ -856,33 +859,15 @@ void _poly_fill (VkvgContext ctx){ uint32_t pathPointCount = lastPtIdx - firstPtIdx + 1; uint32_t firstVertIdx = ctx->vertCount; - if (_path_has_curves(ctx, ptrPath)) { - uint i=0; - while (i < pathPointCount) { - if (ptrPath + ptrCurve < ctx->pathPtr && ctx->pathes[ptrPath+2+ptrCurve] == i+firstPtIdx){ - while (i < ctx->pathes[ptrPath+3+ptrCurve] && i < pathPointCount){ - v.pos = ctx->points[i+firstPtIdx]; - _add_vertex(ctx, v); - i++; - } - ptrCurve+=2; - }else{ - v.pos = ctx->points[i+firstPtIdx]; - _add_vertex(ctx, v); - i++; - } - } - }else{ - for (uint i = 0; i < pathPointCount; i++) { - v.pos = ctx->points[i+firstPtIdx]; - _add_vertex(ctx, v); - } + for (uint i = 0; i < pathPointCount; i++) { + v.pos = ctx->points[i+firstPtIdx]; + _add_vertex(ctx, v); } LOG(LOG_INFO_PATH, "\tpoly fill: point count = %d; 1st vert = %d; vert count = %d\n", pathPointCount, firstVertIdx, ctx->vertCount - firstVertIdx); CmdDraw (ctx->cmd, pathPointCount, 1, firstVertIdx ,0); - ptrPath+=2+ptrCurve; + ptrPath+=2; } } void _fill_ec (VkvgContext ctx){ @@ -891,7 +876,10 @@ void _fill_ec (VkvgContext ctx){ v.uv.z = -1; while (ptrPath < ctx->pathPtr){ - uint32_t ptrCurve = 0; + if (ctx->pathes[ptrPath+1]&PATH_IS_CURVE_BIT){ + ptrPath += 2; + continue; + } ctx->pathes[ptrPath]|=PATH_CLOSED_BIT;//close path uint32_t firstPtIdx = ctx->pathes[ptrPath]&PATH_ELT_MASK; @@ -904,34 +892,14 @@ void _fill_ec (VkvgContext ctx){ uint32_t i = 0; //init points link list - if (_path_has_curves(ctx, ptrPath)) { - while (i < pathPointCount-1){ - if (ptrPath + ptrCurve < ctx->pathPtr && ctx->pathes[ptrPath+2+ptrCurve] == i+firstPtIdx){ - while (i < ctx->pathes[ptrPath+3+ptrCurve] && i < pathPointCount-1){ - v.pos = ctx->points[i+firstPtIdx]; - ear_clip_point ecp = {v.pos, i+firstVertIdx, &ecps[i+1]}; - ecps[i] = ecp; - _add_vertex(ctx, v); - i++; - } - ptrCurve+=2; - }else{ - v.pos = ctx->points[i+firstPtIdx]; - ear_clip_point ecp = {v.pos, i+firstVertIdx, &ecps[i+1]}; - ecps[i] = ecp; - _add_vertex(ctx, v); - i++; - } - } - }else{ - while (i < pathPointCount-1){ - v.pos = ctx->points[i+firstPtIdx]; - ear_clip_point ecp = {v.pos, i+firstVertIdx, &ecps[i+1]}; - ecps[i] = ecp; - _add_vertex(ctx, v); - i++; - } + while (i < pathPointCount-1){ + v.pos = ctx->points[i+firstPtIdx]; + ear_clip_point ecp = {v.pos, i+firstVertIdx, &ecps[i+1]}; + ecps[i] = ecp; + _add_vertex(ctx, v); + i++; } + v.pos = ctx->points[i+firstPtIdx]; ear_clip_point ecp = {v.pos, i+firstVertIdx, ecps}; ecps[i] = ecp; @@ -973,7 +941,7 @@ void _fill_ec (VkvgContext ctx){ if (ecps_count == 3) _add_triangle_indices(ctx, ecp_current->next->idx, ecp_current->idx, ecp_current->next->next->idx); - ptrPath+=2+ptrCurve; + ptrPath+=2; } _record_draw_cmd(ctx); } diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index 459e9ae..8b035ad 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -33,10 +33,10 @@ #define M_PIF 3.14159265358979323846f /* float pi */ #define M_PIF_2 1.57079632679489661923f #define PATH_CLOSED_BIT 0x80000000 /* most significant bit of path elmts is closed/open path state */ -#define PATH_HAS_CURVES_BIT 0x40000000 /* most significant bit of path elmts end is continue path bit - Used to handle curved/line transition */ -#define PATH_IS_CURVE_BIT 0x80000000 /* most significant bit of path elmts end is curve/line state, +#define PATH_HAS_CURVES_BIT 0x40000000 /* 2d most significant bit of path elmts start = true if curve data are present, stored to avoid emiting join in curves */ +#define PATH_IS_CURVE_BIT 0x80000000 /* most significant bit of path elmts end mark curves data in path array */ + #define PATH_ELT_MASK 0x3FFFFFFF /* Bit mask for fetching path element value */ #define ROUNDF(f, c) (((float)((int)((f) * (c))) / (c))) diff --git a/tests/common/test.c b/tests/common/test.c index 88da594..17e5ff8 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -135,7 +135,7 @@ void perform_test (void(*testfunc)(void),uint width, uint height) { bool deferredResolve = false; - device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_8_BIT, deferredResolve); + device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_4_BIT, deferredResolve); vkvg_device_set_dpy(device, 96, 96); diff --git a/tests/multilines.c b/tests/multilines.c index 0e86481..bfe2eea 100644 --- a/tests/multilines.c +++ b/tests/multilines.c @@ -13,10 +13,10 @@ void test(){ //vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); vkvg_set_line_width(ctx,2); //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); - vkvg_set_source_rgba(ctx,1.0,0.0,0.0,0.1); + randomize_color(ctx); for (int i=0; i<250; i++) { - randomize_color(ctx); + float x1 = trunc( ((float)w*rand())/RAND_MAX ); float y1 = trunc( ((float)h*rand())/RAND_MAX ); float x2 = trunc( ((float)w*rand())/RAND_MAX ) + 1; @@ -24,8 +24,8 @@ void test(){ vkvg_move_to (ctx, x1, y1); vkvg_line_to (ctx, x2, y2); - vkvg_stroke (ctx); } + vkvg_stroke (ctx); vkvg_destroy(ctx); } -- 2.47.3