]> O.S.I.I.S - jp/vkvg.git/commitdiff
simplify path loops increment with PATH_IS_CURVE_BIT on end point of begin/end pair
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 2 Sep 2019 12:15:33 +0000 (14:15 +0200)
committerj-p <jp_bruyere@hotmail.com>
Tue, 3 Sep 2019 18:36:09 +0000 (20:36 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_internal.h
tests/common/test.c
tests/multilines.c

index 1c80d37298a5b4541083a8023bed257ab68abe83..92849c2f3089b5cd0157b403fc6be6424fb5031b 100644 (file)
@@ -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;
index f8365bc0aca9933c650b0ab6cae867db747e43fb..c25528a5a01d35dbad3990a99d784d6f71160f10 100644 (file)
@@ -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);
 }
index 459e9aebfea2126ed32dfe504c58d0ef3f3a8cc8..8b035ad0b4b55cd7ad79e6ca40aea8e32c5572d4 100644 (file)
 #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)))
index 88da594b893677f31661ab5af272d31a46922f45..17e5ff83eaa8843f62f145ab1771d68b486acfc6 100644 (file)
@@ -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);
 
index 0e86481e8c29ad1a903143bfbb6fa260d838bbf4..bfe2eeade5ef9a1b512b512ec7965e8475f52992 100644 (file)
@@ -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);
 }