From bf8b1958fff1ce0bd9878eed69ca7c08d38d65d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 14 Jan 2020 07:34:02 +0100 Subject: [PATCH] debug stroke closed path anticlockwise with join != mitter --- src/shaders.h | 12 ++++++------ src/vkvg_context.c | 20 +++++++++++++------- src/vkvg_context_internal.c | 33 +++++++++++++-------------------- src/vkvg_context_internal.h | 2 +- src/vkvg_fonts.c | 2 +- 5 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/shaders.h b/src/shaders.h index 844f3e0..d031708 100644 --- a/src/shaders.h +++ b/src/shaders.h @@ -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, diff --git a/src/vkvg_context.c b/src/vkvg_context.c index f93be7e..fd2252e 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -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++; } diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 9647894..08fa586 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -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; diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index e83fd3a..f7a385f 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -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); diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c index adb05cb..c993a1e 100644 --- a/src/vkvg_fonts.c +++ b/src/vkvg_fonts.c @@ -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)) -- 2.47.3