From 210775252cceff4db6e94ed60541f7683dae4da7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Fri, 24 Jan 2020 00:39:49 +0100 Subject: [PATCH] prepare func _build_vb_step for custom points from dashed lines; build badges --- README.md | 16 +++++------- src/vkvg_context.c | 52 ++++++++++++++++++------------------- src/vkvg_context_internal.c | 38 +++++++++++++-------------- src/vkvg_context_internal.h | 3 ++- 4 files changed, 53 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 786d238..047b99f 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,10 @@

- + - + @@ -21,12 +21,11 @@

-### What is vkvg? -**vkvg** is a multiplatform **c** library for drawing 2D vector graphics with [Vulkan](https://www.khronos.org/vulkan/). It's api follows the same pattern as [Cairo](https://www.cairographics.org/), but new functions and original drawing mechanics may be added. +**vkvg** is an open source *2D graphics library* written in **c** using [Vulkan](https://www.khronos.org/vulkan/) as backend. It's **api** follows the same pattern as [Cairo](https://www.cairographics.org/), but new functions and original drawing mechanics may be added. **vkvg** is in early development stage, api may change, any contribution is welcome. -For API documentation and usage, please refer to the [Cairo](https://www.cairographics.org/) documentation. +For API documentation and usage, please refer to the [Cairo](https://www.cairographics.org/) documentation for now. ### Current status: @@ -51,17 +50,16 @@ For API documentation and usage, please refer to the [Cairo](https://www.cairogr ### Requirements: +- [CMake](https://cmake.org/): version > 12. - [Vulkan](https://www.khronos.org/vulkan/) - [FontConfig](https://www.freedesktop.org/wiki/Software/fontconfig/) - [Freetype](https://www.freetype.org/) -- PkgConfig (currently used only to find harbfbuzz) - [Harfbuzz](https://www.freedesktop.org/wiki/Software/HarfBuzz/) - GLSLC: spirv compiler, included in [LunarG SDK](https://www.lunarg.com/vulkan-sdk/) (building only) - [xxd](https://linux.die.net/man/1/xxd): generate headers with precompiled shaders (building only) -- [GLFW](http://www.glfw.org/) (only for running demo app) -- CMake +- [GLFW](http://www.glfw.org/): optional, if present tests are built. -if glslc or xxd are not present, a precompiled version of the shaders is stored in the git tree. +if `glslc` or `xxd` are not present, a precompiled version of the shaders is stored in the git tree. ### Building diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 2cdbadc..49706df 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -588,14 +588,12 @@ void vkvg_stroke_preserve (VkvgContext ctx) v.uv.z = -1; float hw = ctx->lineWidth / 2.0f; - uint32_t i = 0, ptrPath = 0; - - uint32_t lastPathPointIdx, iL, iR; + uint32_t firstPathPointIdx = 0, lastPathPointIdx, ptrPath = 0, iL, iR; while (ptrPath < ctx->pathPtr){ uint32_t ptrCurve = 0; VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset); - i = ctx->pathes[ptrPath]&PATH_ELT_MASK; + firstPathPointIdx = 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); @@ -604,16 +602,16 @@ void vkvg_stroke_preserve (VkvgContext ctx) LOG(LOG_INFO_PATH, "end = %d\n", lastPathPointIdx); //prevent closing on the same position, this could be generalize //to prevent processing of two consecutive point at the same position - if (vec2_equ(ctx->points[i], ctx->points[lastPathPointIdx])) + if (vec2_equ(ctx->points[firstPathPointIdx], ctx->points[lastPathPointIdx])) lastPathPointIdx--; iL = lastPathPointIdx; }else{ lastPathPointIdx = ctx->pathes[ptrPath+1]&PATH_ELT_MASK; LOG(LOG_INFO_PATH, "end = %d\n", lastPathPointIdx); - vec2 n = vec2_line_norm(ctx->points[i], ctx->points[i+1]); + vec2 n = vec2_line_norm(ctx->points[firstPathPointIdx], ctx->points[firstPathPointIdx+1]); - vec2 p0 = ctx->points[i]; + vec2 p0 = ctx->points[firstPathPointIdx]; vec2 vhw = vec2_mult(n,hw); if (ctx->lineCap == VKVG_LINE_CAP_SQUARE) @@ -646,36 +644,36 @@ void vkvg_stroke_preserve (VkvgContext ctx) _add_tri_indices_for_rect(ctx, firstIdx); - iL = i++; + iL = firstPathPointIdx++; } if (_path_has_curves (ctx,ptrPath)) { - while (i < lastPathPointIdx){ - if (ptrPath + ptrCurve + 2 < ctx->pathPtr && (ctx->pathes [ptrPath + 2 + ptrCurve]&PATH_ELT_MASK) == i){ - uint32_t lastCurvePoint = ctx->pathes[ptrPath + 3 + ptrCurve]&PATH_ELT_MASK; - while (ipathPtr && (ctx->pathes [ptrPath + 2 + ptrCurve]&PATH_ELT_MASK) == firstPathPointIdx){ + uint32_t lastCurvePointIdx = ctx->pathes[ptrPath + 3 + ptrCurve]&PATH_ELT_MASK; + while (firstPathPointIdx < lastCurvePointIdx){ + iR = firstPathPointIdx+1; + _build_vb_step (ctx, v, hw, ctx->points[iL], ctx->points[firstPathPointIdx], ctx->points[iR], true); + iL = firstPathPointIdx++; } ptrCurve += 2; }else{ - iR = i+1; - _build_vb_step (ctx, v, hw, iL, i, iR, false); - iL = i++; + iR = firstPathPointIdx+1; + _build_vb_step (ctx, v, hw, ctx->points[iL], ctx->points[firstPathPointIdx], ctx->points[iR], false); + iL = firstPathPointIdx++; } } }else{ - while (i < lastPathPointIdx){ - iR = i+1; - _build_vb_step(ctx,v,hw,iL,i,iR, false); - iL = i++; + while (firstPathPointIdx < lastPathPointIdx){ + iR = firstPathPointIdx+1; + _build_vb_step (ctx, v, hw, ctx->points[iL], ctx->points[firstPathPointIdx], ctx->points[iR], false); + iL = firstPathPointIdx++; } } if (!_path_is_closed(ctx,ptrPath)){ - vec2 n = vec2_line_norm(ctx->points[i-1], ctx->points[i]); - vec2 p0 = ctx->points[i]; + vec2 n = vec2_line_norm(ctx->points[firstPathPointIdx-1], ctx->points[firstPathPointIdx]); + vec2 p0 = ctx->points[firstPathPointIdx]; vec2 vhw = vec2_mult(n, hw); if (ctx->lineCap == VKVG_LINE_CAP_SQUARE) @@ -707,10 +705,10 @@ void vkvg_stroke_preserve (VkvgContext ctx) _add_triangle_indices(ctx, p+1, p, firstIdx-2); } - i++; + firstPathPointIdx++; }else{ iR = ctx->pathes[ptrPath] & PATH_ELT_MASK; - float cross =_build_vb_step (ctx,v,hw,iL,i,iR, false); + float cross = _build_vb_step (ctx, v, hw, ctx->points[iL], ctx->points[firstPathPointIdx], ctx->points[iR], false); VKVG_IBO_INDEX_TYPE* inds = &ctx->indexCache [ctx->indCount-6]; VKVG_IBO_INDEX_TYPE ii = firstIdx; @@ -723,7 +721,7 @@ void vkvg_stroke_preserve (VkvgContext ctx) inds[4] = ii; inds[5] = ii+1; } - i++; + firstPathPointIdx++; } ptrPath+=2+ptrCurve; diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index f59aaf9..f5c78e0 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -672,12 +672,12 @@ void _init_descriptor_sets (VkvgContext ctx){ VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsGrad)); } -float _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, vec2 pL, vec2 p0, vec2 pR, bool isCurve){ //if two of the three points are equal, normal is null - vec2 v0n = vec2_line_norm(ctx->points[iL], ctx->points[i]); + vec2 v0n = vec2_line_norm(pL, p0); if (vec2_isnan(v0n)) return 0; - vec2 v1n = vec2_line_norm(ctx->points[i], ctx->points[iR]); + vec2 v1n = vec2_line_norm(p0, pR); if (vec2_isnan(v1n)) return 0; @@ -697,21 +697,21 @@ float _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32 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); + v.pos = vec2_add(p0, bisec); _add_vertex(ctx, v); - v.pos = vec2_sub(ctx->points[i], bisec); + v.pos = vec2_sub(p0, bisec); _add_vertex(ctx, v); _add_tri_indices_for_rect(ctx, idx); }else{ vec2 vp = vec2_perp(v0n); if (cross<0){ - v.pos = vec2_add (ctx->points[i], bisec); + v.pos = vec2_add (p0, bisec); _add_vertex(ctx, v); - v.pos = vec2_sub (ctx->points[i], vec2_mult (vp, hw)); + v.pos = vec2_sub (p0, vec2_mult (vp, hw)); }else{ - v.pos = vec2_add (ctx->points[i], vec2_mult (vp, hw)); + v.pos = vec2_add (p0, vec2_mult (vp, hw)); _add_vertex(ctx, v); - v.pos = vec2_sub (ctx->points[i], bisec); + v.pos = vec2_sub (p0, bisec); } _add_vertex(ctx, v); @@ -736,14 +736,14 @@ float _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32 float a1 = a + alpha*2; a-=step; while (a > a1){ - _add_vertexf(ctx, cosf(a) * hw + ctx->points[i].x, sinf(a) * hw + ctx->points[i].y); + _add_vertexf(ctx, cosf(a) * hw + p0.x, sinf(a) * hw + p0.y); a-=step; } }else{ float a1 = a + alpha*2; a+=step; while (a < a1){ - _add_vertexf(ctx, cosf(a) * hw + ctx->points[i].x, sinf(a) * hw + ctx->points[i].y); + _add_vertexf(ctx, cosf(a) * hw + p0.x, sinf(a) * hw + p0.y); a+=step; } } @@ -765,23 +765,23 @@ float _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32 vp = vec2_mult (vec2_perp(v1n), hw); if (cross<0) - v.pos = vec2_sub (ctx->points[i], vp); + v.pos = vec2_sub (p0, vp); else - v.pos = vec2_add (ctx->points[i], vp); + v.pos = vec2_add (p0, vp); _add_vertex(ctx, v); } /* #ifdef DEBUG - debugLinePoints[dlpCount] = ctx->points[i]; - debugLinePoints[dlpCount+1] = _v2add(ctx->points[i], _vec2dToVec2(_v2Multd(v0n,10))); + debugLinePoints[dlpCount] = p0; + debugLinePoints[dlpCount+1] = _v2add(p0, _vec2dToVec2(_v2Multd(v0n,10))); dlpCount+=2; - debugLinePoints[dlpCount] = ctx->points[i]; - debugLinePoints[dlpCount+1] = _v2add(ctx->points[i], _vec2dToVec2(_v2Multd(v1n,10))); + debugLinePoints[dlpCount] = p0; + debugLinePoints[dlpCount+1] = _v2add(p0, _vec2dToVec2(_v2Multd(v1n,10))); dlpCount+=2; - debugLinePoints[dlpCount] = ctx->points[i]; - debugLinePoints[dlpCount+1] = ctx->points[iR]; + debugLinePoints[dlpCount] = p0; + debugLinePoints[dlpCount+1] = pR; dlpCount+=2; #endif*/ return cross; diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 4fdc045..806543f 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -200,7 +200,8 @@ 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); -float _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, vec2 pL, vec2 p0, vec2 pR, bool isCurve); +void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, float height); void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, float height); void _bind_draw_pipeline (VkvgContext ctx); -- 2.47.3