]> O.S.I.I.S - jp/vkvg.git/commitdiff
no explicit close for path on fill, empty path test debug, scalled _get_arc_step...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 20 Nov 2021 23:51:02 +0000 (00:51 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 20 Nov 2021 23:51:02 +0000 (00:51 +0100)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h

index b59bcb5ff9a9fbf91e0c7e23401c802566fe0a19..65374bb80238e85c04ea72cf7da9364091097aaf 100644 (file)
@@ -171,7 +171,7 @@ void vkvg_flush (VkvgContext ctx){
        if (ctx->status)
                return;
        _flush_cmd_buff(ctx);
-       _wait_flush_fence(ctx);
+//     _wait_flush_fence(ctx);
 /*
 #ifdef DEBUG
 
@@ -509,7 +509,9 @@ void vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float h){
        _add_point (ctx, x + w, y + h);
        _add_point (ctx, x, y + h);     
 
-       vkvg_close_path (ctx);
+       ctx->pathes[ctx->pathPtr] |= PATH_CLOSED_BIT;
+
+       _finish_path(ctx);
 }
 static const VkClearAttachment clearStencil               = {VK_IMAGE_ASPECT_STENCIL_BIT, 1, {{{0}}}};
 static const VkClearAttachment clearColorAttach           = {VK_IMAGE_ASPECT_COLOR_BIT,   0, {{{0}}}};
@@ -558,11 +560,12 @@ void vkvg_clip_preserve (VkvgContext ctx){
        if (ctx->status)
                return;
 
-       _emit_draw_cmd_undrawn_vertices(ctx);
-
        _finish_path(ctx);
 
-       vkvg_close_path (ctx);
+       if (!ctx->pathPtr)//nothing to clip
+               return;
+
+       _emit_draw_cmd_undrawn_vertices(ctx);
 
        LOG(VKVG_LOG_INFO, "CLIP: ctx = %p; path cpt = %d;\n", ctx, ctx->pathPtr / 2);
 
@@ -602,7 +605,7 @@ void vkvg_path_extents (VkvgContext ctx, float *x1, float *y1, float *x2, float
 
        _finish_path(ctx);
 
-       if (_current_path_is_empty(ctx)) {
+       if (!ctx->pathPtr) {//no path
                *x1 = *x2 = *y1 = *y2 = 0;
                return;
        }
@@ -618,7 +621,8 @@ void vkvg_fill_preserve (VkvgContext ctx){
 
        _finish_path(ctx);
 
-       vkvg_close_path (ctx);
+       if (!ctx->pathPtr)//nothing to fill
+               return;
 
        LOG(VKVG_LOG_INFO, "FILL: ctx = %p; path cpt = %d;\n", ctx, ctx->pathPtr / 2);
 
@@ -754,10 +758,11 @@ void vkvg_stroke_preserve (VkvgContext ctx)
        if (ctx->status)
                return;
 
-       if (ctx->pathPtr == 0 && _current_path_is_empty(ctx))//nothing to stroke
-               return;
        _finish_path(ctx);
 
+       if (!ctx->pathPtr)//nothing to stroke
+               return;
+
        LOG(VKVG_LOG_INFO, "STROKE: ctx = %p; path ptr = %d;\n", ctx, ctx->pathPtr);
 
        curPathPointIdx = lastPathPointIdx = ptrPath = iL = iR = 0;
@@ -873,14 +878,13 @@ void vkvg_paint (VkvgContext ctx){
        if (ctx->status)
                return;
 
-       if (!_current_path_is_empty(ctx)){//maybe path to fill
-               vkvg_close_path(ctx);
-               if (ctx->pathes[ctx->pathPtr] & PATH_CLOSED_BIT) {
-                       vkvg_fill(ctx);
-                       return;
-               }
-               _clear_path (ctx);
+       _finish_path (ctx);
+
+       if (ctx->pathPtr) {
+               vkvg_fill(ctx);
+               return;
        }
+
        _ensure_renderpass_is_started (ctx);
        _draw_full_screen_quad (ctx, true);
 }
index b813944af2ac4edafb296cf1aeda5d18dc9cdd7a..d5be84a113d5b6812bca6ea90f41c9c03cf17433 100644 (file)
@@ -223,9 +223,12 @@ float _normalizeAngle(float a)
     return res;
 }
 float _get_arc_step (VkvgContext ctx, float radius) {
-       if (radius < 3.0f)
-               return asinf (1.0f / radius) * 0.25f;
-       return asinf (1.0f / radius) * 1.5f * sqrtf(radius);
+       float dx = radius, dy = radius;
+       vkvg_matrix_transform_distance (&ctx->pushConsts.mat, &dx, &dy);
+       float r = fmaxf(dx,dy);
+       if (r < 3.0f)
+               return asinf (1.0f / r) * 0.25f;
+       return asinf (1.0f / r) * 1.5f * sqrtf(r);
 }
 void _create_gradient_buff (VkvgContext ctx){
        vkvg_buffer_create (ctx->pSurf->dev,
@@ -1083,22 +1086,19 @@ void _poly_fill (VkvgContext ctx){
        uint32_t firstPtIdx = 0;
 
        while (ptrPath < ctx->pathPtr){
-               //close path
-               ctx->pathes[ptrPath] |= PATH_CLOSED_BIT;
-
                uint32_t pathPointCount = ctx->pathes[ptrPath] & PATH_ELT_MASK;
+               if (pathPointCount > 2) {
+                       VKVG_IBO_INDEX_TYPE firstVertIdx = (VKVG_IBO_INDEX_TYPE)ctx->vertCount;
 
-               VKVG_IBO_INDEX_TYPE firstVertIdx = (VKVG_IBO_INDEX_TYPE)ctx->vertCount;
+                       for (uint32_t i = 0; i < pathPointCount; i++) {
+                               v.pos = ctx->points [i+firstPtIdx];
+                               ctx->vertexCache[ctx->vertCount++] = v;
+                               _check_vertex_cache_size(ctx);
+                       }
 
-               for (uint32_t i = 0; i < pathPointCount; i++) {
-                       v.pos = ctx->points [i+firstPtIdx];
-                       ctx->vertexCache[ctx->vertCount++] = v;
-                       _check_vertex_cache_size(ctx);
+                       LOG(VKVG_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);
                }
-
-               LOG(VKVG_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);
-
                firstPtIdx += pathPointCount;
 
                if (_path_has_curves (ctx, ptrPath)) {
@@ -1120,65 +1120,69 @@ void _fill_ec (VkvgContext ctx){
        uint32_t firstPtIdx = 0;
 
        while (ptrPath < ctx->pathPtr){
-               ctx->pathes[ptrPath] |= PATH_CLOSED_BIT;//close path
-
-               uint32_t pathPointCount = ctx->pathes[ptrPath] & PATH_ELT_MASK;         
+               uint32_t pathPointCount = ctx->pathes[ptrPath] & PATH_ELT_MASK;
 
-               VKVG_IBO_INDEX_TYPE firstVertIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
-               ear_clip_point* ecps = (ear_clip_point*)malloc(pathPointCount*sizeof(ear_clip_point));
-               uint32_t ecps_count = pathPointCount;
-               VKVG_IBO_INDEX_TYPE i = 0;
+               if (pathPointCount > 2) {
+                       VKVG_IBO_INDEX_TYPE firstVertIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
+                       ear_clip_point* ecps = (ear_clip_point*)malloc(pathPointCount*sizeof(ear_clip_point));
+                       uint32_t ecps_count = pathPointCount;
+                       VKVG_IBO_INDEX_TYPE i = 0;
+
+                       //init points link list
+                       while (i < pathPointCount-1){
+                               v.pos = ctx->points[i+firstPtIdx];
+                               ear_clip_point ecp = {v.pos, firstVertIdx+i, &ecps[i+1]};
+                               ecps[i] = ecp;
+                               _add_vertex(ctx, v);
+                               i++;
+                       }
 
-               //init points link list
-               while (i < pathPointCount-1){
                        v.pos = ctx->points[i+firstPtIdx];
-                       ear_clip_point ecp = {v.pos, firstVertIdx+i, &ecps[i+1]};
+                       ear_clip_point ecp = {v.pos, firstVertIdx+i, ecps};
                        ecps[i] = ecp;
                        _add_vertex(ctx, v);
-                       i++;
-               }
-
-               v.pos = ctx->points[i+firstPtIdx];
-               ear_clip_point ecp = {v.pos, firstVertIdx+i, ecps};
-               ecps[i] = ecp;
-               _add_vertex(ctx, v);
 
-               ear_clip_point* ecp_current = ecps;
-               uint32_t tries = 0;
+                       ear_clip_point* ecp_current = ecps;
+                       uint32_t tries = 0;
 
-               while (ecps_count > 3) {
-                       if (tries > ecps_count) {
-                               break;
-                       }
-                       ear_clip_point* v0 = ecp_current->next,
-                                       *v1 = ecp_current, *v2 = ecp_current->next->next;
-                       if (ecp_zcross (v0, v2, v1)<0){
-                               ecp_current = ecp_current->next;
-                               tries++;
-                               continue;
-                       }
-                       ear_clip_point* vP = v2->next;
-                       bool isEar = true;
-                       while (vP!=v1){
-                               if (ptInTriangle (vP->pos, v0->pos, v2->pos, v1->pos)){
-                                       isEar = false;
+                       while (ecps_count > 3) {
+                               if (tries > ecps_count) {
                                        break;
                                }
-                               vP = vP->next;
-                       }
-                       if (isEar){
-                               _add_triangle_indices (ctx, v0->idx, v1->idx, v2->idx);
-                               v1->next = v2;
-                               ecps_count --;
-                               tries = 0;
-                       }else{
-                               ecp_current = ecp_current->next;
-                               tries++;
+                               ear_clip_point* v0 = ecp_current->next,
+                                               *v1 = ecp_current, *v2 = ecp_current->next->next;
+                               if (ecp_zcross (v0, v2, v1)<0){
+                                       ecp_current = ecp_current->next;
+                                       tries++;
+                                       continue;
+                               }
+                               ear_clip_point* vP = v2->next;
+                               bool isEar = true;
+                               while (vP!=v1){
+                                       if (ptInTriangle (vP->pos, v0->pos, v2->pos, v1->pos)){
+                                               isEar = false;
+                                               break;
+                                       }
+                                       vP = vP->next;
+                               }
+                               if (isEar){
+                                       _add_triangle_indices (ctx, v0->idx, v1->idx, v2->idx);
+                                       v1->next = v2;
+                                       ecps_count --;
+                                       tries = 0;
+                               }else{
+                                       ecp_current = ecp_current->next;
+                                       tries++;
+                               }
                        }
+                       if (ecps_count == 3)
+                               _add_triangle_indices(ctx, ecp_current->next->idx, ecp_current->idx, ecp_current->next->next->idx);
+                       free (ecps);
+
+                       //limit batch size here to 1/3 of the ibo index type ability
+                       if (ctx->vertCount - ctx->curVertOffset > VKVG_IBO_MAX / 3)
+                               _emit_draw_cmd_undrawn_vertices(ctx);
                }
-               if (ecps_count == 3)
-                       _add_triangle_indices(ctx, ecp_current->next->idx, ecp_current->idx, ecp_current->next->next->idx);
-               free (ecps);
 
                firstPtIdx += pathPointCount;
                if (_path_has_curves (ctx, ptrPath)) {
index ec5ea29b3675d5508d2b99fe7fdecbc69f5da18d..7013690a8e5c26da42de59b384913ee815923e6d 100644 (file)
@@ -28,7 +28,7 @@
 #include "vkh.h"
 #include "vkvg_fonts.h"
 
-#define VKVG_PTS_SIZE                          256
+#define VKVG_PTS_SIZE                          1024
 #define VKVG_VBO_SIZE                          (VKVG_PTS_SIZE * 4)
 #define VKVG_IBO_SIZE                          (VKVG_VBO_SIZE * 6)
 #define VKVG_PATHES_SIZE                       16