]> O.S.I.I.S - jp/vkvg.git/commitdiff
rename _flush_undrawn to emit_undrawn
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 10 Sep 2020 16:45:50 +0000 (18:45 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 10 Sep 2020 16:45:50 +0000 (18:45 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
tests/common/test.c
tests/dashes.c
tests/test1.c

index d3051092255f042418808220e224cacc185ba0ca..f2f0988556bb4f7818aad0910eb0622cd66ac0bd 100644 (file)
@@ -450,7 +450,7 @@ static const VkClearAttachment clearStencil        = {VK_IMAGE_ASPECT_STENCIL_BI
 static const VkClearAttachment clearColorAttach    = {VK_IMAGE_ASPECT_COLOR_BIT,   0, {{{0}}}};
 
 void vkvg_reset_clip (VkvgContext ctx){
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        if (!ctx->cmdStarted) {
                //if command buffer is not already started and in a renderpass, we use the renderpass
                //with the loadop clear for stencil
@@ -462,7 +462,7 @@ void vkvg_reset_clip (VkvgContext ctx){
        vkCmdClearAttachments(ctx->cmd, 1, &clearStencil, 1, &ctx->clearRect);
 }
 void vkvg_clear (VkvgContext ctx){
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        if (!ctx->cmdStarted) {
                ctx->renderPassBeginInfo.renderPass = ctx->pSurf->dev->renderPass_ClearAll;
                _start_cmd_for_render_pass(ctx);
@@ -489,7 +489,7 @@ void vkvg_clip_preserve (VkvgContext ctx){
        if (ctx->pathPtr == 0 && _current_path_is_empty(ctx))//nothing to clip
                return;
 
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
 
        _finish_path(ctx);
 
@@ -506,7 +506,7 @@ void vkvg_clip_preserve (VkvgContext ctx){
                CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
                CmdSetStencilWriteMask  (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
                _fill_ec(ctx);
-               _flush_undrawn_vertices(ctx);
+               _emit_draw_cmd_undrawn_vertices(ctx);
        }
        CmdSetStencilReference  (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
        CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
@@ -526,7 +526,7 @@ void vkvg_fill_preserve (VkvgContext ctx){
        LOG(VKVG_LOG_INFO, "FILL: ctx = %p; path cpt = %d;\n", ctx, ctx->pathPtr / 2);
 
         if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){
-                _flush_undrawn_vertices(ctx);
+                _emit_draw_cmd_undrawn_vertices(ctx);
 
                _poly_fill (ctx);
                _bind_draw_pipeline (ctx);
@@ -537,7 +537,7 @@ void vkvg_fill_preserve (VkvgContext ctx){
        }
 
        if (ctx->vertCount - ctx->curVertOffset + ctx->pointCount > VKVG_IBO_MAX)
-               _flush_undrawn_vertices(ctx);//limit draw call to addressable vx with choosen index type
+               _emit_draw_cmd_undrawn_vertices(ctx);//limit draw call to addressable vx with choosen index type
 
        if (ctx->pattern)//if not solid color, source img of gradient has to be bound
                _ensure_renderpass_is_started(ctx);
@@ -546,7 +546,7 @@ void vkvg_fill_preserve (VkvgContext ctx){
 void _draw_stoke_cap (VkvgContext ctx, float hw, vec2 p0, vec2 n, bool isStart) {
        Vertex v = {{0},ctx->curColor,{0,0,-1}};
 
-       VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
+       VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);      
 
        if (isStart){
                vec2 vhw = vec2_mult(n,hw);
@@ -650,7 +650,14 @@ void _draw_segment (VkvgContext ctx, float hw, bool isCurve) {
        iL = curPathPointIdx++;
 }
 
-bool _process_stroke (VkvgContext ctx) {
+void vkvg_stroke_preserve (VkvgContext ctx)
+{
+       if (ctx->pathPtr == 0 && _current_path_is_empty(ctx))//nothing to stroke
+               return;
+       _finish_path(ctx);
+
+       LOG(VKVG_LOG_INFO, "STROKE: ctx = %p; path ptr = %d;\n", ctx, ctx->pathPtr);
+
        curPathPointIdx = lastPathPointIdx = ptrPath = iL = iR = 0;
        float hw = ctx->lineWidth / 2.0f;
 
@@ -681,7 +688,7 @@ bool _process_stroke (VkvgContext ctx) {
                                totDashLength+=ctx->dashes[i];
                        if (totDashLength == 0){
                                ctx->status = VKVG_STATUS_INVALID_DASH;
-                               return true;
+                               return;
                        }
                        /*if (ctx->dashOffset == 0)
                                curDashOffset = 0;
@@ -752,8 +759,28 @@ bool _process_stroke (VkvgContext ctx) {
                }else
                        _draw_stoke_cap (ctx, hw, ctx->points[curPathPointIdx], vec2_line_norm(ctx->points[curPathPointIdx-1], ctx->points[curPathPointIdx]), false);
 
-               if (ctx->vertCount - ctx->curVertOffset > VKVG_IBO_MAX)
-                       return false;
+               /*if (ctx->vertCount - ctx->curVertOffset > VKVG_IBO_MAX) {
+                       _check_vao_size (ctx);
+                       _ensure_renderpass_is_started(ctx);
+
+                       //split triangle emission into batch adressable by VKVG_IBO_MAX (index type)
+                       VKVG_IBO_INDEX_TYPE indexMax = VKVG_IBO_MAX - VKVG_IBO_MAX % 3;
+                       uint32_t vxTot = ctx->vertCount;
+                       uint32_t idxTot = ctx->indCount;
+                       ctx->indCount = ctx->curIndStart;
+
+
+                       while (ctx->curVertOffset < vxTot) {
+                               while (ctx->indexCache[ctx->indCount] < indexMax)
+                                       ctx->indCount++;
+                               ctx->indCount -= ctx->indCount % 3;
+                               uint32_t minInd = 
+                               uint32_t newVertOffset = ctx->indexCache[ctx->indCount-1];
+
+                               _emit_draw (ctx);                               
+                       }
+
+               }               */      
 
                curPathPointIdx = firstPathPointIdx + pathPointCount;
 
@@ -763,29 +790,6 @@ bool _process_stroke (VkvgContext ctx) {
                        ptrPath++;
        }
 
-
-
-
-       return true;
-}
-
-void vkvg_stroke_preserve (VkvgContext ctx)
-{
-       if (ctx->pathPtr == 0 && _current_path_is_empty(ctx))//nothing to stroke
-               return;
-       _finish_path(ctx);
-
-       LOG(VKVG_LOG_INFO, "STROKE: ctx = %p; path ptr = %d;\n", ctx, ctx->pathPtr);
-
-       uint32_t tmpVxCount = ctx->vertCount;
-       uint32_t tmpIxCount = ctx->indCount;
-
-       if (!_process_stroke(ctx)) {
-               ctx->vertCount = tmpVxCount;
-               ctx->indCount = tmpIxCount;
-               _flush_undrawn_vertices(ctx);//limit draw call to addressable vx with choosen index type
-               _process_stroke(ctx);
-       }
 }
 void vkvg_paint (VkvgContext ctx){
        if (ctx->pathPtr || ctx->segmentPtr){//path to fill
@@ -1098,35 +1102,35 @@ void vkvg_restore (VkvgContext ctx){
 }
 
 void vkvg_translate (VkvgContext ctx, float dx, float dy){
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_translate (&ctx->pushConsts.mat, dx, dy);
        _set_mat_inv_and_vkCmdPush (ctx);
 }
 void vkvg_scale (VkvgContext ctx, float sx, float sy){
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_scale (&ctx->pushConsts.mat, sx, sy);
        _set_mat_inv_and_vkCmdPush (ctx);
 }
 void vkvg_rotate (VkvgContext ctx, float radians){
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_rotate (&ctx->pushConsts.mat, radians);
        _set_mat_inv_and_vkCmdPush (ctx);
 }
 void vkvg_transform (VkvgContext ctx, const vkvg_matrix_t* matrix) {
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_t res;
        vkvg_matrix_multiply (&res, &ctx->pushConsts.mat, matrix);
        ctx->pushConsts.mat = res;
        _set_mat_inv_and_vkCmdPush (ctx);
 }
 void vkvg_identity_matrix (VkvgContext ctx) {
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        vkvg_matrix_t im = VKVG_IDENTITY_MATRIX;
        ctx->pushConsts.mat = im;
        _set_mat_inv_and_vkCmdPush (ctx);
 }
 void vkvg_set_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){
-       _flush_undrawn_vertices(ctx);
+       _emit_draw_cmd_undrawn_vertices(ctx);
        ctx->pushConsts.mat = (*matrix);
        _set_mat_inv_and_vkCmdPush (ctx);
 }
index dceba198b4becf605d6edb53236e0996564fb3eb..d0a53e337af48fd06d37a830a8c35040e38bce09 100644 (file)
@@ -439,7 +439,7 @@ void _check_vao_size (VkvgContext ctx) {
 }
 
 //stroke and non-zero draw call for solid color flush
-void _flush_undrawn_vertices (VkvgContext ctx){
+void _emit_draw_cmd_undrawn_vertices (VkvgContext ctx){
        if (ctx->indCount == ctx->curIndStart)
                return;
 
@@ -472,7 +472,7 @@ void _flush_cmd_until_vx_base (VkvgContext ctx){
        _wait_and_submit_cmd (ctx);
 }
 void _flush_cmd_buff (VkvgContext ctx){
-       _flush_undrawn_vertices (ctx);
+       _emit_draw_cmd_undrawn_vertices (ctx);
        if (!ctx->cmdStarted)
                return;
        _end_render_pass        (ctx);
@@ -578,7 +578,7 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) {
                break;
        case VKVG_PATTERN_TYPE_SURFACE:
        {
-               _flush_undrawn_vertices(ctx);
+               _emit_draw_cmd_undrawn_vertices(ctx);
 
                VkvgSurface surf = (VkvgSurface)pat->data;
 
index 9d1a1410a1bdd39149f4d5fb2512982eab987109..95a52ab0f2c8dd0ab5fa0bbb5dc8ced1d0adc77b 100644 (file)
@@ -215,9 +215,10 @@ void _vao_add_rectangle     (VkvgContext ctx, float x, float y, float width, flo
 
 void _bind_draw_pipeline    (VkvgContext ctx);
 void _create_cmd_buff          (VkvgContext ctx);
+void _check_vao_size           (VkvgContext ctx);
 void _ensure_renderpass_is_started  (VkvgContext ctx);
 void _flush_cmd_buff           (VkvgContext ctx);
-void _flush_undrawn_vertices(VkvgContext ctx);
+void _emit_draw_cmd_undrawn_vertices(VkvgContext ctx);
 void _flush_cmd_until_vx_base (VkvgContext ctx);
 void _wait_flush_fence      (VkvgContext ctx);
 void _reset_flush_fence     (VkvgContext ctx);
index ef7d2073804f6bbc147a0d63c4284d6aab9dbeb1..349ada80cbf14d587201ddd31ceae0bbbd1f159c 100644 (file)
@@ -33,8 +33,8 @@ bool mouseDown = false;
 VkvgDevice device      = NULL;
 VkvgSurface surf       = NULL;
 
-uint32_t test_size     = 10;   // items drawn in one run, or complexity
-uint32_t iterations    = 100;// repeat test n times
+uint32_t test_size     = 500;  // items drawn in one run, or complexity
+uint32_t iterations    = 500;// repeat test n times
 uint32_t test_width    = 512;
 uint32_t test_height= 512;
 bool   test_vsync      = false;
index d0d6269e7f31abb0f073f40d4c2accf88857c02c..310d4ae0a34320f05e2d7d16255670f4bccecceb 100644 (file)
@@ -89,12 +89,12 @@ void curve () {
 int main(int argc, char *argv[]) {     
        //PERFORM_TEST(test, argc, argv);
        //vkvg_log_level = VKVG_LOG_ERR|VKVG_LOG_DEBUG|VKVG_LOG_INFO|VKVG_LOG_INFO_PATH|VKVG_LOG_DBG_ARRAYS|VKVG_LOG_FULL;
-       dashes_count = 1;
-       dashes[0] = 50;
-       dashes[1] = 60;
-       line_width = 10;
+       dashes_count = 2;
+       dashes[0] = 2;
+       dashes[1] = 3;
+       line_width = 2;
        line_cap = VKVG_LINE_CAP_ROUND;
        PERFORM_TEST(path, argc, argv);
-       PERFORM_TEST(curve, argc, argv);
+       //PERFORM_TEST(curve, argc, argv);
        return 0;
 }
index a689a2e2758965e5edc46e643a7cfab4ca42ec45..7b6603740541c7648bbc3cffa152beb5ab394ae4 100644 (file)
@@ -297,6 +297,23 @@ void cairo_test_line_joins (VkvgContext cr) {
        vkvg_rel_line_to (cr, 51.2f, 51.2f);
        vkvg_set_line_join (cr, VKVG_LINE_JOIN_ROUND);
        vkvg_stroke (cr);
+
+               /* draw helping lines */
+       vkvg_set_source_rgb (cr, 1, 0.2f, 0.2f);
+       vkvg_set_line_width (cr, 2.56f);
+       vkvg_set_line_join (cr, VKVG_LINE_JOIN_MITER);
+       vkvg_move_to (cr, 76.8f, 84.48f);
+       vkvg_rel_line_to (cr, 51.2f, -51.2f);
+       vkvg_rel_line_to (cr, 51.2f, 51.2f);
+       vkvg_move_to (cr, 76.8f, 161.28f);
+       vkvg_rel_line_to (cr, 51.2f, -51.2f);
+       vkvg_rel_line_to (cr, 51.2f, 51.2f);
+       vkvg_move_to (cr, 76.8f, 238.08f);
+       vkvg_rel_line_to (cr, 51.2f, -51.2f);
+       vkvg_rel_line_to (cr, 51.2f, 51.2f);
+
+       vkvg_stroke (cr);
+
 }
 void cairo_print_arc (VkvgContext cr) {
        float xc = 128.0f;