From: Jean-Philippe Bruyère Date: Fri, 7 Jan 2022 20:24:01 +0000 (+0100) Subject: uint_32 for log_level, log commands X-Git-Tag: v0.3.0-beta~39 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=4d18fadf00a22a7a3b51951f5291309a41ab2731;p=jp%2Fvkvg.git uint_32 for log_level, log commands --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ef9718a..1866ef5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,7 +169,7 @@ IF(GLSLC AND XXD) ADD_CUSTOM_COMMAND ( OUTPUT ${shader-output} COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${SHADER_DIR}" - COMMAND ${GLSLC} ${shader-input} -o ${shader-output} --target-env=vulkan1.2 + COMMAND ${GLSLC} ${shader-input} -o ${shader-output}# --target-env=vulkan1.2 COMMENT "Compiling ${shader-input}" DEPENDS ${SHADER} VERBATIM diff --git a/include/vkvg.h b/include/vkvg.h index ef37977..1dea2ac 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -80,16 +80,21 @@ extern "C" { #endif -#define VKVG_LOG_ERR 0x10 -#define VKVG_LOG_DEBUG 0x20 -#define VKVG_LOG_INFO 0x40 -#define VKVG_LOG_INFO_PTS 0x41 -#define VKVG_LOG_INFO_PATH 0x42 -#define VKVG_LOG_DBG_ARRAYS 0x80 -#define VKVG_LOG_FULL 0xff +#define VKVG_LOG_ERR 0x00000001 +#define VKVG_LOG_DEBUG 0x00000002 +#define VKVG_LOG_INFO_PTS 0x00000004 +#define VKVG_LOG_INFO_PATH 0x00000008 +#define VKVG_LOG_INFO_CMD 0x00000010 +#define VKVG_LOG_INFO_VBO 0x00000010 +#define VKVG_LOG_INFO_IBO 0x00000010 +#define VKVG_LOG_INFO_VAO VKVG_LOG_INFO_VBO|VKVG_LOG_INFO_IBO +#define VKVG_LOG_DBG_ARRAYS 0x00001000 +#define VKVG_LOG_FULL 0xffffffff + +#define VKVG_LOG_INFO VKVG_LOG_INFO_PTS|VKVG_LOG_INFO_PATH|VKVG_LOG_INFO_CMD|VKVG_LOG_INFO_VAO #ifdef DEBUG -extern uint8_t vkvg_log_level; +extern uint32_t vkvg_log_level; #endif /** diff --git a/src/vkvg_context.c b/src/vkvg_context.c index c2a9994..7f7936b 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -313,16 +313,25 @@ uint32_t vkvg_get_reference_count (VkvgContext ctx) { void vkvg_new_sub_path (VkvgContext ctx){ if (ctx->status) return; + + LOG(VKVG_LOG_INFO_CMD, "\tCMD: new_sub_path:\n"); + _finish_path(ctx); } void vkvg_new_path (VkvgContext ctx){ if (ctx->status) return; + + LOG(VKVG_LOG_INFO_CMD, "\tCMD: new_path:\n"); + _clear_path(ctx); } void vkvg_close_path (VkvgContext ctx){ if (ctx->status) return; + + LOG(VKVG_LOG_INFO_CMD, "\tCMD: close_path:\n"); + if (ctx->pathes[ctx->pathPtr] & PATH_CLOSED_BIT) //already closed return; //check if at least 3 points are present @@ -344,6 +353,9 @@ void vkvg_close_path (VkvgContext ctx){ void vkvg_rel_line_to (VkvgContext ctx, float dx, float dy){ if (ctx->status) return; + + LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_line_to:\n"); + if (_current_path_is_empty(ctx)) _add_point(ctx, 0, 0); vec2 cp = _get_current_position(ctx); @@ -353,6 +365,9 @@ void vkvg_line_to (VkvgContext ctx, float x, float y) { if (ctx->status) return; + + LOG(VKVG_LOG_INFO_CMD, "\tCMD: line_to:\n"); + vec2 p = {x,y}; if (!_current_path_is_empty (ctx)){ //prevent adding the same point @@ -364,6 +379,9 @@ void vkvg_line_to (VkvgContext ctx, float x, float y) void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2){ if (ctx->status) return; + + LOG(VKVG_LOG_INFO_CMD, "\tCMD: arc:\n"); + while (a2 < a1)//positive arc must have a1status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: arc_neg:\n"); while (a2 > a1) a2 -= 2.f*M_PIF; if (a1 - a2 > a1 + 2.f * M_PIF) //limit arc to 2PI @@ -459,6 +478,7 @@ void vkvg_rel_move_to (VkvgContext ctx, float x, float y) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_mote_to:\n"); if (_current_path_is_empty(ctx)) _add_point(ctx, 0, 0); vec2 cp = _get_current_position(ctx); @@ -468,6 +488,7 @@ void vkvg_move_to (VkvgContext ctx, float x, float y) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: move_to:\n"); _finish_path(ctx); _add_point (ctx, x, y); } @@ -483,6 +504,7 @@ void vkvg_get_current_point (VkvgContext ctx, float* x, float* y) { void vkvg_rel_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_quadratic_to:\n"); vec2 cp = _get_current_position(ctx); vkvg_quadratic_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2); } @@ -490,6 +512,7 @@ const double quadraticFact = 2.0/3.0; void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: quadratic_to:\n"); float x0, y0; if (_current_path_is_empty(ctx)) { @@ -507,6 +530,7 @@ void vkvg_quadratic_to (VkvgContext ctx, float x1, float y1, float x2, float y2) void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: curve_to:\n"); //prevent running _recursive_bezier when all 4 curve points are equal if (EQUF(x1,x2) && EQUF(x2,x3) && EQUF(y1,y2) && EQUF(y2,y3)) { if (_current_path_is_empty(ctx) || (EQUF(_get_current_position(ctx).x,x1) && EQUF(_get_current_position(ctx).y,y1))) @@ -533,12 +557,14 @@ void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, flo void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_curve_to:\n"); vec2 cp = _get_current_position(ctx); vkvg_curve_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2, cp.x + x3, cp.y + y3); } void vkvg_fill_rectangle (VkvgContext ctx, float x, float y, float w, float h){ if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: fill_rectangle:\n"); _vao_add_rectangle (ctx,x,y,w,h); //_record_draw_cmd(ctx); } @@ -546,6 +572,7 @@ void vkvg_fill_rectangle (VkvgContext ctx, float x, float y, float w, float h){ vkvg_status_t vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float h){ if (ctx->status) return ctx->status; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: rectangle:\n"); _finish_path (ctx); if (w <= 0 || h <= 0) @@ -564,6 +591,7 @@ vkvg_status_t vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float vkvg_status_t vkvg_rounded_rectangle (VkvgContext ctx, float x, float y, float w, float h, float radius){ if (ctx->status) return ctx->status; + LOG(VKVG_LOG_INFO_CMD, "CMD: rounded_rectangle:\n"); _finish_path (ctx); if (w <= 0 || h <= 0) @@ -586,6 +614,9 @@ vkvg_status_t vkvg_rounded_rectangle (VkvgContext ctx, float x, float y, float w return VKVG_STATUS_SUCCESS; } void vkvg_rounded_rectangle2 (VkvgContext ctx, float x, float y, float w, float h, float rx, float ry){ + if (ctx->status) + return; + LOG(VKVG_LOG_INFO_CMD, "CMD: rounded_rectangle2:\n"); vkvg_move_to (ctx, x+rx, y); vkvg_line_to (ctx, x+w-rx, y); vkvg_elliptic_arc_to(ctx, x+w, y+ry, false, true, rx, ry, 0); @@ -712,7 +743,7 @@ void vkvg_fill_preserve (VkvgContext ctx){ if (!ctx->pathPtr)//nothing to fill return; - LOG(VKVG_LOG_INFO, "FILL: ctx = %p; path cpt = %d;\n", ctx, ctx->pathPtr / 2); + LOG(VKVG_LOG_INFO, "FILL: ctx = %p; path cpt = %d;\n", ctx, ctx->subpathCount); if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){ _emit_draw_cmd_undrawn_vertices(ctx); @@ -764,8 +795,7 @@ void vkvg_stroke_preserve (VkvgContext ctx) str.firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset); - //LOG(VKVG_LOG_INFO_PATH, "\tPATH: start=%d end=%d", ctx->pathes[ptrPath]&PATH_ELT_MASK, ctx->pathes[ptrPath+1]&PATH_ELT_MASK); - LOG(VKVG_LOG_INFO_PATH, "end = %d\n", lastPathPointIdx); + //LOG(VKVG_LOG_INFO_PATH, "\tPATH: points count=%10d end point idx=%10d", ctx->pathes[ptrPath]&PATH_ELT_MASK, lastPathPointIdx); if (ctx->dashCount > 0) { //init dash stroke @@ -1004,6 +1034,7 @@ void vkvg_set_text_direction (vkvg_context* ctx, vkvg_direction_t direction){ void vkvg_show_text (VkvgContext ctx, const char* text){ if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: show_text:\n"); //_ensure_renderpass_is_started(ctx); _show_text (ctx, text); //_flush_undrawn_vertices (ctx); @@ -1270,6 +1301,7 @@ void vkvg_restore (VkvgContext ctx){ void vkvg_translate (VkvgContext ctx, float dx, float dy){ if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: translate:\n"); _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_translate (&ctx->pushConsts.mat, dx, dy); _set_mat_inv_and_vkCmdPush (ctx); @@ -1277,6 +1309,7 @@ void vkvg_translate (VkvgContext ctx, float dx, float dy){ void vkvg_scale (VkvgContext ctx, float sx, float sy){ if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: scale:\n"); _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_scale (&ctx->pushConsts.mat, sx, sy); _set_mat_inv_and_vkCmdPush (ctx); @@ -1284,6 +1317,7 @@ void vkvg_scale (VkvgContext ctx, float sx, float sy){ void vkvg_rotate (VkvgContext ctx, float radians){ if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: rotate:\n"); _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_rotate (&ctx->pushConsts.mat, radians); _set_mat_inv_and_vkCmdPush (ctx); @@ -1291,6 +1325,7 @@ void vkvg_rotate (VkvgContext ctx, float radians){ void vkvg_transform (VkvgContext ctx, const vkvg_matrix_t* matrix) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: transform:\n"); _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_t res; vkvg_matrix_multiply (&res, &ctx->pushConsts.mat, matrix); @@ -1300,6 +1335,7 @@ void vkvg_transform (VkvgContext ctx, const vkvg_matrix_t* matrix) { void vkvg_identity_matrix (VkvgContext ctx) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: identity_matrix:\n"); _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_t im = VKVG_IDENTITY_MATRIX; ctx->pushConsts.mat = im; @@ -1308,6 +1344,7 @@ void vkvg_identity_matrix (VkvgContext ctx) { void vkvg_set_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){ if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: set_matrix:\n"); _emit_draw_cmd_undrawn_vertices(ctx); ctx->pushConsts.mat = (*matrix); _set_mat_inv_and_vkCmdPush (ctx); @@ -1317,11 +1354,18 @@ void vkvg_get_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){ } void vkvg_elliptic_arc_to (VkvgContext ctx, float x2, float y2, bool largeArc, bool counterClockWise, float rx, float ry, float phi) { + if (ctx->status) + return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: elliptic_arc_to:\n"); float x1, y1; vkvg_get_current_point(ctx, &x1, &y1); _elliptic_arc(ctx, x1, y1, x2, y2, largeArc, counterClockWise, rx, ry, phi); } void vkvg_rel_elliptic_arc_to (VkvgContext ctx, float x2, float y2, bool largeArc, bool counterClockWise, float rx, float ry, float phi) { + if (ctx->status) + return; + LOG(VKVG_LOG_INFO_CMD, "\tCMD: rel_elliptic_arc_to: x2:%10.5f y2:%10.5f large:%d sweep:%d rx:%10.5f ry:%10.5f phi:%10.5f \n", x2,y2,largeArc,counterClockWise,rx,ry,phi); + float x1, y1; vkvg_get_current_point(ctx, &x1, &y1); _elliptic_arc(ctx, x1, y1, x2+x1, y2+y1, largeArc, counterClockWise, rx, ry, phi); @@ -1330,6 +1374,7 @@ void vkvg_rel_elliptic_arc_to (VkvgContext ctx, float x2, float y2, bool largeAr void vkvg_ellipse (VkvgContext ctx, float radiusX, float radiusY, float x, float y, float rotationAngle) { if (ctx->status) return; + LOG(VKVG_LOG_INFO_CMD, "CMD: ellipse:\n"); float width_two_thirds = radiusX * 4 / 3; diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 5af91aa..4f9b2df 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -149,6 +149,8 @@ void _finish_path (VkvgContext ctx){ return; } + LOG(VKVG_LOG_INFO_PATH, "PATH: points count=%10d\n", ctx->pathes[ctx->pathPtr]&PATH_ELT_MASK); + if (ctx->segmentPtr > 0) { ctx->pathes[ctx->pathPtr] |= PATH_HAS_CURVES_BIT; //if last segment is not a curve and point count > 0 @@ -217,11 +219,12 @@ float _normalizeAngle(float a) } float _get_arc_step (VkvgContext ctx, float radius) { float dx = radius, dy = radius; - vkvg_matrix_transform_point (&ctx->pushConsts.mat, &dx, &dy); + vkvg_matrix_transform_distance (&ctx->pushConsts.mat, &dx, &dy); float r = fabsf(fmaxf(dx,dy)); - if (r < 3.0f) + /*if (r < 3.0f) return asinf (1.0f / r) * 0.25f; - return asinf (1.0f / r) * 1.5f * sqrtf(r); + return asinf (1.0f / r) * 1.5f * sqrtf(r);*/ + return M_PI / (r * 1.5f); } void _create_gradient_buff (VkvgContext ctx){ vkvg_buffer_create (ctx->pSurf->dev, @@ -273,14 +276,14 @@ void _add_vertexf (VkvgContext ctx, float x, float y){ pVert->pos.y = y; pVert->color = ctx->curColor; pVert->uv.z = -1; + LOG(VKVG_LOG_INFO_VBO, "Add Vertexf %10d: pos:(%10.4f, %10.4f) uv:(%10.4f,%10.4f,%10.4f) color:0x%.8x \n", ctx->vertCount, pVert->pos.x, pVert->pos.y, pVert->uv.x, pVert->uv.y, pVert->uv.z, pVert->color); ctx->vertCount++; - _check_vertex_cache_size(ctx); } void _add_vertex(VkvgContext ctx, Vertex v){ ctx->vertexCache[ctx->vertCount] = v; + LOG(VKVG_LOG_INFO_VBO, "Add Vertex %10d: pos:(%10.4f, %10.4f) uv:(%10.4f,%10.4f,%10.4f) color:0x%.8x \n", ctx->vertCount, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.uv.z, v.color); ctx->vertCount++; - _check_vertex_cache_size(ctx); } void _set_vertex(VkvgContext ctx, uint32_t idx, Vertex v){ @@ -297,7 +300,7 @@ void _add_tri_indices_for_rect (VkvgContext ctx, VKVG_IBO_INDEX_TYPE i){ ctx->indCount+=6; _check_index_cache_size(ctx); - LOG(VKVG_LOG_INFO, "Rectangle IDX: %d %d %d | %d %d %d (count=%d)\n", inds[0], inds[1], inds[2], inds[3], inds[4], inds[5], ctx->indCount); + LOG(VKVG_LOG_INFO_IBO, "Rectangle IDX: %d %d %d | %d %d %d (count=%d)\n", inds[0], inds[1], inds[2], inds[3], inds[4], inds[5], ctx->indCount); } void _add_triangle_indices(VkvgContext ctx, VKVG_IBO_INDEX_TYPE i0, VKVG_IBO_INDEX_TYPE i1, VKVG_IBO_INDEX_TYPE i2){ VKVG_IBO_INDEX_TYPE* inds = &ctx->indexCache[ctx->indCount]; @@ -307,7 +310,7 @@ void _add_triangle_indices(VkvgContext ctx, VKVG_IBO_INDEX_TYPE i0, VKVG_IBO_IND ctx->indCount+=3; _check_index_cache_size(ctx); - LOG(VKVG_LOG_INFO, "Triangle IDX: %d %d %d (indCount=%d)\n", i0,i1,i2,ctx->indCount); + LOG(VKVG_LOG_INFO_IBO, "Triangle IDX: %d %d %d (indCount=%d)\n", i0,i1,i2,ctx->indCount); } void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, float height){ Vertex v[4] = @@ -796,16 +799,32 @@ bool _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool is return false; vec2 v0n = vec2_div_s (v0, length_v0); vec2 v1n = vec2_div_s (v1, length_v1); + float dot = vec2_dot (v0n, v1n); + float det = v0n.x * v1n.y - v0n.y * v1n.x; + if (EQUF(dot,1.0f)) + return false; + + if (EQUF(dot,-1.0f)) { + vec2 vPerp = vec2_mult_s(vec2_perp (v0n), hw); + + VKVG_IBO_INDEX_TYPE idx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset); + + v.pos = vec2_add(p0, vPerp); + _add_vertex(ctx, v); + v.pos = vec2_sub(p0, vPerp); + _add_vertex(ctx, v); + + _add_triangle_indices(ctx, idx, idx+1, idx+2); + _add_triangle_indices(ctx, idx, idx+2, idx+3); + return true; + } + vec2 bisec_n = vec2_norm(vec2_add(v0n,v1n)); - float dot = vec2_dot (v0n, v1n); float alpha = acosf(dot); - float det = v0n.x * v1n.y - v0n.y * v1n.x; - if (EQUF(dot,1.0f)) - return false; if (det<0) alpha = -alpha; @@ -1389,7 +1408,7 @@ void _elliptic_arc (VkvgContext ctx, float x1, float y1, float x2, float y2, boo double theta = sa; double ea = sa + delta_theta; - float step = _get_arc_step(ctx, fminf (rx, ry))*0.1f; + float step = fmaxf(0.0001f, fminf(M_PI, _get_arc_step(ctx, fminf (rx, ry))*0.1f)); p = (vec2) { rx * cosf (theta), @@ -1531,6 +1550,8 @@ void _fill_non_zero (VkvgContext ctx){ int *tris_out; int nverts, ntris; + LOG(VKVG_LOG_INFO, "glutess: ctx = %p; point cpt = %d;\n", ctx, ctx->pointCount); + tessellate(&coordinates_out, &nverts, &tris_out, &ntris, contours_array, contours_array + contours_size); diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 699fce7..21a19eb 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -37,7 +37,7 @@ #define VKVG_IBO_16 0 #define VKVG_IBO_32 1 -#define VKVG_CUR_IBO_TYPE VKVG_IBO_16//change this only +#define VKVG_CUR_IBO_TYPE VKVG_IBO_32//change this only #if VKVG_CUR_IBO_TYPE == VKVG_IBO_16 #define VKVG_IBO_MAX UINT16_MAX diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index 046a292..bc95cc5 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -28,7 +28,7 @@ #include "vkvg_context_internal.h" #include "shaders.h" -uint8_t vkvg_log_level = VKVG_LOG_DEBUG; +uint32_t vkvg_log_level = VKVG_LOG_DEBUG; PFN_vkCmdBindPipeline CmdBindPipeline; PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets; diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index 379505d..ec82a74 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -44,7 +44,7 @@ #ifdef DEBUG #define LOG(level,...) { \ - if (vkvg_log_level & level) \ + if ((vkvg_log_level) & (level)) \ fprintf (stdout, __VA_ARGS__); \ } #else