]> O.S.I.I.S - jp/vkvg.git/commitdiff
debug stroke closed path anticlockwise with join != mitter
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 14 Jan 2020 06:34:02 +0000 (07:34 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 14 Jan 2020 06:34:02 +0000 (07:34 +0100)
src/shaders.h
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
src/vkvg_fonts.c

index 844f3e00b09cb3bf548329e8f515f00edd958148..d0317082d52d6cb899b17e4bca7fca2d9ae26eb8 100644 (file)
@@ -1,5 +1,5 @@
 unsigned char shader_comp_spv[] = {
-  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0d, 0x00,
+  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x0d, 0x00,
   0xa1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
   0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
@@ -301,7 +301,7 @@ unsigned char shader_comp_spv[] = {
 };
 unsigned int shader_comp_spv_len = 3580;
 unsigned char shader2_comp_spv[] = {
-  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0d, 0x00,
+  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x0d, 0x00,
   0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
   0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
@@ -521,7 +521,7 @@ unsigned char shader2_comp_spv[] = {
 };
 unsigned int shader2_comp_spv_len = 2604;
 unsigned char vkvg_main_frag_spv[] = {
-  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0d, 0x00,
+  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x0d, 0x00,
   0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
   0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
@@ -1006,7 +1006,7 @@ unsigned char vkvg_main_frag_spv[] = {
 };
 unsigned int vkvg_main_frag_spv_len = 5780;
 unsigned char vkvg_main_vert_spv[] = {
-  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0d, 0x00,
+  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x0d, 0x00,
   0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
   0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
@@ -1284,7 +1284,7 @@ unsigned char vkvg_main_vert_spv[] = {
 };
 unsigned int vkvg_main_vert_spv_len = 3292;
 unsigned char vkvg_main_lcd_frag_spv[] = {
-  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0d, 0x00,
+  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x0d, 0x00,
   0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
   0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
@@ -1769,7 +1769,7 @@ unsigned char vkvg_main_lcd_frag_spv[] = {
 };
 unsigned int vkvg_main_lcd_frag_spv_len = 5784;
 unsigned char wired_frag_spv[] = {
-  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x0d, 0x00,
+  0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x0d, 0x00,
   0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
   0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
   0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
index f93be7e21ddd8f45817c6b849f8444ef043cf082..fd2252eb05c25ed5f7289981d5fd7c8281163cc3 100644 (file)
@@ -614,7 +614,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
                     a+=step;
                 }
                 VKVG_IBO_INDEX_TYPE p0Idx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
-                for (uint p = firstIdx; p < p0Idx; p++)
+                for (VKVG_IBO_INDEX_TYPE p = firstIdx; p < p0Idx; p++)
                     _add_triangle_indices(ctx, p0Idx+1, p, p+1);
                 firstIdx = p0Idx;
             }
@@ -670,7 +670,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
 
             firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
 
-            if (ctx->lineCap == VKVG_LINE_CAP_ROUND){                
+            if (ctx->lineCap == VKVG_LINE_CAP_ROUND){
                 float step = M_PIF / hw;
                 float a = acosf(n.x)+ M_PIF_2;
                 if (n.y < 0)
@@ -683,20 +683,26 @@ void vkvg_stroke_preserve (VkvgContext ctx)
                 }
 
                 VKVG_IBO_INDEX_TYPE p0Idx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset - 1);
-                for (uint p = firstIdx-1 ; p < p0Idx; p++)
+                for (VKVG_IBO_INDEX_TYPE p = firstIdx-1 ; p < p0Idx; p++)
                     _add_triangle_indices(ctx, p+1, p, firstIdx-2);
             }
 
             i++;
         }else{
             iR = ctx->pathes[ptrPath] & PATH_ELT_MASK;
-            _build_vb_step (ctx,v,hw,iL,i,iR, false);
+            float cross =_build_vb_step (ctx,v,hw,iL,i,iR, false);
 
             VKVG_IBO_INDEX_TYPE* inds = &ctx->indexCache [ctx->indCount-6];
             VKVG_IBO_INDEX_TYPE ii = firstIdx;
-            inds[1] = ii;
-            inds[4] = ii;
-            inds[5] = ii+1;
+            if (cross < 0 && ctx->lineJoin != VKVG_LINE_JOIN_MITER){
+                inds[1] = ii+1;
+                inds[4] = ii+1;
+                inds[5] = ii;
+            }else{
+                inds[1] = ii;
+                inds[4] = ii;
+                inds[5] = ii+1;
+            }
             i++;
         }
 
index 964789449dc13b6d48b493065890759adc4e88c2..08fa586c49488bb0a7f16bde20a60460fdc9b347 100644 (file)
@@ -215,7 +215,7 @@ void _add_vertexf (VkvgContext ctx, float x, float y){
     Vertex* pVert = &ctx->vertexCache[ctx->vertCount];
     pVert->pos.x = x;
     pVert->pos.y = y;
-    pVert->uv = (vec3){0};
+    pVert->uv = (vec3){0,0,-1};
     ctx->vertCount++;
 
     _check_vbo_size(ctx);
@@ -663,24 +663,17 @@ void _init_descriptor_sets (VkvgContext ctx){
     descriptorSetAllocateInfo.pSetLayouts = &dev->dslGrad;
     VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsGrad));
 }
-void add_line(vkvg_context* ctx, vec2 p1, vec2 p2, vec4 col){
-    Vertex v = {{p1.x,p1.y},{0,0,-1}};
-    _add_vertex(ctx, v);
-    v.pos = p2;
-    _add_vertex(ctx, v);
-    VKVG_IBO_INDEX_TYPE* inds = &ctx->indexCache [ctx->indCount];
-    inds[0] = ctx->vertCount - 2;
-    inds[1] = ctx->vertCount - 1;
-    ctx->indCount+=2;
-}
 
-void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_t i, uint32_t iR, bool isCurve){
+float _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_t i, uint32_t iR, bool isCurve){
     vec2 v0n = vec2_line_norm(ctx->points[iL], ctx->points[i]);
     vec2 v1n = vec2_line_norm(ctx->points[i], ctx->points[iR]);
 
     vec2 bisec = vec2_norm(vec2_add(v0n,v1n));
 
-    float alpha = acosf(v0n.x * v1n.x + v0n.y * v1n.y)/2;
+    float dot = v0n.x * v1n.x + v0n.y * v1n.y;
+    //printf("%f\n", dot);
+
+    float alpha = acosf(dot)/2;
     float cross = v0n.x * v1n.y - v0n.y * v1n.x;
 
     if (cross<0)
@@ -690,7 +683,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 - ctx->curVertOffset;
+    VKVG_IBO_INDEX_TYPE idx = ctx->vertCount - ctx->curVertOffset;
 
     if (ctx->lineJoin == VKVG_LINE_JOIN_MITER || isCurve){
         v.pos = vec2_add(ctx->points[i], bisec);
@@ -743,15 +736,15 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_
                     a+=step;
                 }
             }
-            uint32_t p0Idx = ctx->vertCount - ctx->curVertOffset;
+            VKVG_IBO_INDEX_TYPE 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++)
+                for (VKVG_IBO_INDEX_TYPE p = idx+2; p < p0Idx; p++)
                     _add_triangle_indices(ctx, p, p+1, idx);
                 _add_triangle_indices(ctx, p0Idx, p0Idx+2, idx);
                 _add_triangle_indices(ctx, idx, p0Idx+1, p0Idx+2);
             }else{
-                for (uint p = idx+2; p < p0Idx; p++)
+                for (VKVG_IBO_INDEX_TYPE p = idx+2; p < p0Idx; p++)
                     _add_triangle_indices(ctx, p, p+1, idx+1);
                 _add_triangle_indices(ctx, p0Idx, p0Idx+1, idx+1);
                 _add_triangle_indices(ctx, idx+1, p0Idx+1, p0Idx+2);
@@ -780,6 +773,7 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_
     debugLinePoints[dlpCount+1] = ctx->points[iR];
     dlpCount+=2;
 #endif*/
+    return cross;
 }
 
 bool ptInTriangle(vec2 p, vec2 p0, vec2 p1, vec2 p2) {
@@ -998,8 +992,7 @@ void _poly_fill (VkvgContext ctx){
     CmdBindPipeline (ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelinePolyFill);
 
     uint32_t ptrPath = 0;
-    Vertex v = {0};
-    v.uv.z = -1;
+    Vertex v = {{0},{0,0,-1}};
 
     while (ptrPath < ctx->pathPtr){
         if (ctx->pathes[ptrPath+1]&PATH_IS_CURVE_BIT){
@@ -1101,7 +1094,7 @@ void _fill_ec (VkvgContext ctx){
 
         ptrPath+=2;
     }
-    _record_draw_cmd(ctx);    
+    _record_draw_cmd(ctx);
 }
 
 static const uint32_t one = 1;
index e83fd3a4f94d7c75f979f8bc33dbb86214186d84..f7a385f9ea68ec6710e0f08cdb3ff9a9fd6ba458 100644 (file)
@@ -193,7 +193,7 @@ void _add_vertexf           (VkvgContext ctx, float x, float y);
 void _set_vertex                       (VkvgContext ctx, uint32_t idx, Vertex v);
 void _add_triangle_indices     (VkvgContext ctx, VKVG_IBO_INDEX_TYPE i0, VKVG_IBO_INDEX_TYPE i1, VKVG_IBO_INDEX_TYPE i2);
 void _add_tri_indices_for_rect (VkvgContext ctx, VKVG_IBO_INDEX_TYPE i);
-void _build_vb_step         (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_t i, uint32_t iR, bool isCurve);
+float _build_vb_step         (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_t i, uint32_t iR, bool isCurve);
 void _vao_add_rectangle     (VkvgContext ctx, float x, float y, float width, float height);
 
 void _bind_draw_pipeline    (VkvgContext ctx);
index adb05cbcc94e2e4bf938878860cec37172551449..c993a1e6e1261166e09e60c4ba9a6a3e6dd59786 100644 (file)
@@ -457,7 +457,7 @@ void _show_text_run (VkvgContext ctx, VkvgText tr) {
     unsigned int glyph_count;
     hb_glyph_info_t* glyph_info = hb_buffer_get_glyph_infos (tr->hbBuf, &glyph_count);
 
-    Vertex v = {};
+    Vertex v = {{0},{0}};
     vec2 pen = {0,0};
 
     if (!_current_path_is_empty(ctx))