]> O.S.I.I.S - jp/vkvg.git/commitdiff
use vertexOffset in drawCommand to be able to flush just before emiting a new draw...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 5 Sep 2019 15:34:12 +0000 (17:34 +0200)
committerj-p <jp_bruyere@hotmail.com>
Thu, 5 Sep 2019 22:59:25 +0000 (00:59 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
src/vkvg_fonts.c
tests/stroke.c

index 02e47e873290782b5915255a0eff86b4d9039755..edb9c19ac23e48367b55d041df3cc2791afdcd8d 100644 (file)
@@ -68,6 +68,7 @@ VkvgContext vkvg_create(VkvgSurface surf)
     ctx->vertCount      = 0;
     ctx->indCount       = 0;
     ctx->curIndStart    = 0;
+    ctx->curVertOffset  = 0;
 
     VkRect2D scissor = {{0,0},{ctx->pSurf->width,ctx->pSurf->height}};
     ctx->bounds        = scissor;
@@ -568,7 +569,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
 
     while (ptrPath < ctx->pathPtr){
         uint ptrCurve = 0;
-        VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)ctx->vertCount;
+        VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
         i = ctx->pathes[ptrPath]&PATH_ELT_MASK;
 
         LOG(LOG_INFO_PATH, "\tPATH: start = %d; ", ctx->pathes[ptrPath]&PATH_ELT_MASK, ctx->pathes[ptrPath+1]&PATH_ELT_MASK);
@@ -607,7 +608,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
                     _add_vertexf(ctx, cosf(a) * hw + p0.x, sinf(a) * hw + p0.y);
                     a+=step;
                 }
-                uint32_t p0Idx = ctx->vertCount;
+                VKVG_IBO_INDEX_TYPE p0Idx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
                 for (uint p = firstIdx; p < p0Idx; p++)
                     _add_triangle_indices(ctx, p0Idx+1, p, p+1);
                 firstIdx = p0Idx;
@@ -663,7 +664,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
             _add_vertex(ctx, v);
 
             if (ctx->lineCap == VKVG_LINE_CAP_ROUND){
-                firstIdx = ctx->vertCount;
+                firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
                 float step = M_PIF / hw;
                 float a = acosf(n.x)+ M_PIF_2;
                 if (n.y < 0)
@@ -675,7 +676,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
                     a-=step;
                 }
 
-                uint32_t p0Idx = ctx->vertCount-1;
+                VKVG_IBO_INDEX_TYPE p0Idx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset - 1);
                 for (uint p = firstIdx-1 ; p < p0Idx; p++)
                     _add_triangle_indices(ctx, p+1, p, firstIdx-2);
             }
index 48e9bf87eb6dfeb3135dff88c09d6675eeb9d562..4be4550293b90a9af2c575e766f72f97db8d22ff 100644 (file)
@@ -254,9 +254,9 @@ void _create_cmd_buff (VkvgContext ctx){
 void _record_draw_cmd (VkvgContext ctx){
     if (ctx->indCount == ctx->curIndStart)
         return;
-    LOG(LOG_INFO, "RECORD DRAW CMD: ctx = %lu; vertices = %d; indices = %d\n", (ulong)ctx, ctx->vertCount - *((uint32_t*)(ctx->indices.allocInfo.pMappedData + (ctx->curIndStart * sizeof(uint32_t)))), ctx->indCount - ctx->curIndStart);
+    LOG(LOG_INFO, "RECORD DRAW CMD: ctx = %lu; vertices = %d; indices = %d\n", (ulong)ctx, ctx->vertCount - ctx->indexCache[ctx->curIndStart], ctx->indCount - ctx->curIndStart);
     _check_cmd_buff_state(ctx);
-    CmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, 0, 1);
+    CmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, (int32_t)ctx->curVertOffset, 0);
 
 #ifdef VKVG_WIRED_DEBUG
     CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineWired);
@@ -265,6 +265,7 @@ void _record_draw_cmd (VkvgContext ctx){
 #endif
 
     ctx->curIndStart = ctx->indCount;
+    ctx->curVertOffset = ctx->vertCount;
 }
 void _clear_attachment (VkvgContext ctx) {
 
@@ -327,9 +328,7 @@ void _end_render_pass (VkvgContext ctx) {
     memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->vertCount * sizeof (Vertex));
     memcpy(ctx->indices.allocInfo.pMappedData, ctx->indexCache, ctx->indCount * sizeof (VKVG_IBO_INDEX_TYPE));
 
-    ctx->vertCount = 0;
-    ctx->indCount = 0;
-    ctx->curIndStart = 0;
+    ctx->vertCount = ctx->indCount = ctx->curIndStart = ctx->curVertOffset = 0;
 }
 void _flush_cmd_buff (VkvgContext ctx){
     if (!ctx->cmdStarted)
@@ -615,7 +614,7 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_
     bisec = vec2_perp(bisec);
     bisec = vec2_mult(bisec,lh);
 
-    uint32_t idx = ctx->vertCount;
+    uint32_t idx = ctx->vertCount - ctx->curVertOffset;
 
     if (ctx->lineJoin == VKVG_LINE_JOIN_MITER || isCurve){
         v.pos = vec2_add(ctx->points[i], bisec);
@@ -668,7 +667,7 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_
                     a+=step;
                 }
             }
-            uint32_t p0Idx = ctx->vertCount;
+            uint32_t p0Idx = ctx->vertCount - ctx->curVertOffset;
             _add_triangle_indices(ctx, idx, idx+2, idx+1);
             if (cross<0){
                 for (uint p = idx+2; p < p0Idx; p++)
@@ -949,7 +948,7 @@ void _fill_ec (VkvgContext ctx){
         uint32_t firstPtIdx = ctx->pathes[ptrPath]&PATH_ELT_MASK;
         uint32_t lastPtIdx = ctx->pathes[ptrPath+1]&PATH_ELT_MASK;
         uint32_t pathPointCount = lastPtIdx - firstPtIdx + 1;
-        uint32_t firstVertIdx = ctx->vertCount;
+        uint32_t firstVertIdx = ctx->vertCount-ctx->curVertOffset;
 
         ear_clip_point ecps[pathPointCount];
         uint32_t ecps_count = pathPointCount;
index b378caf563eaed5ed6ad670966b01e582543bc6c..622cbe81cf93c42caeddbe86e7651dd49a198728 100644 (file)
@@ -101,6 +101,7 @@ typedef struct _vkvg_context_t {
     uint32_t   indCount;       //current indice count
 
     uint32_t   curIndStart;    //last index recorded in cmd buff
+    uint32_t    curVertOffset;  //vertex offset in draw indexed command
 
     vkvg_buff  vertices;       //vertex buffer with persistent mapped memory
     size_t             sizeVertices;   //reserved size
index c670f0f6712b30041f19edb962f0454d8ce173e3..adb05cbcc94e2e4bf938878860cec37172551449 100644 (file)
@@ -477,7 +477,7 @@ void _show_text_run (VkvgContext ctx, VkvgText tr) {
                        pen.y - cr->bmpDiff.y + (tr->glyph_pos[i].y_offset >> 6)};
             v.pos = p0;
 
-            uint32_t firstIdx = ctx->vertCount;
+            uint32_t firstIdx = ctx->vertCount - ctx->curVertOffset;
 
             v.uv.x = cr->bounds.x;
             v.uv.y = cr->bounds.y;
index 3f6d1d58d8267aa2e4fde3e422c18658ad21eba6..028e9bc61e63153e4d0c6e3eeeb04d2671b63216 100644 (file)
@@ -3,22 +3,31 @@
 void test(){
     VkvgContext ctx = vkvg_create(surf);
 
-    vkvg_set_line_width(ctx, 2);
+    vkvg_set_line_width(ctx, 1);
     vkvg_set_source_rgba(ctx,1,0,0,1);
     vkvg_move_to(ctx,200.5,200.5);
     vkvg_line_to(ctx,400.5,200.5);
     vkvg_line_to(ctx,400.5,400.5);
     vkvg_line_to(ctx,200.5,400.5);
     vkvg_close_path(ctx);
-    vkvg_stroke_preserve(ctx);
-    vkvg_set_source_rgba(ctx,0,0.2,0.35,1);
-    vkvg_fill(ctx);
-    vkvg_set_source_rgba(ctx,0.5,1,0,1);
+    vkvg_stroke(ctx);
+
+    vkvg_set_source_rgba(ctx,0,1,0,1);
     vkvg_move_to(ctx,300.5,300.5);
     vkvg_line_to(ctx,500.5,300.5);
     vkvg_line_to(ctx,500.5,500.5);
     vkvg_line_to(ctx,300.5,500.5);
-    vkvg_close_path(ctx);
+    vkvg_stroke(ctx);
+
+    //vkvg_set_source_rgba(ctx,0,0.2,0.35,1);
+    //vkvg_fill(ctx);
+
+    vkvg_set_source_rgba(ctx,0.5,1,0,1);
+    vkvg_move_to(ctx,320.5,320.5);
+    vkvg_line_to(ctx,520.5,320.5);
+    vkvg_line_to(ctx,520.5,520.5);
+    vkvg_line_to(ctx,320.5,520.5);
+    //vkvg_close_path(ctx);
     vkvg_stroke(ctx);
     vkvg_set_line_width(ctx, 40);
     vkvg_set_source_rgba(ctx,0.5,0.6,1,1.0);