]> O.S.I.I.S - jp/vkvg.git/commitdiff
solve most of stroking gliches, add lines options to tests
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 12 Dec 2021 03:13:27 +0000 (04:13 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 12 Dec 2021 03:13:27 +0000 (04:13 +0100)
src/vkvg_context_internal.c
src/vkvg_device_internal.c
tests/common/test.c
tests/inverse_colinear.c

index 49b716a27e5e0ed5ac9c8e8a73caa8569fc90f07..3049748b9234ba627ba33259aef71b8b5cd85bc0 100644 (file)
@@ -454,13 +454,12 @@ void _emit_draw_cmd_undrawn_vertices (VkvgContext ctx){
 
        _ensure_renderpass_is_started(ctx);
 
+       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);
        CmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, (int32_t)ctx->curVertOffset, 0);
        //CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipe_OVER);
-#else
-       CmdDrawIndexed(ctx->cmd, ctx->indCount - ctx->curIndStart, 1, ctx->curIndStart, (int32_t)ctx->curVertOffset, 0);
-
 #endif
        LOG(VKVG_LOG_INFO, "RECORD DRAW CMD: ctx = %p; vertices = %d; indices = %d (vxOff = %d idxStart = %d idxTot = %d )\n",
                ctx, ctx->vertCount - ctx->curVertOffset,
@@ -799,8 +798,6 @@ float _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool i
                                v.pos = vec2_add (p0, vec2_mult (vec2_perp(v1n), hw));
                        else
                                v.pos = vec2_sub (p0, vec2_mult (vec2_perp(v1n), hw));
-                       /*else
-                               v.pos = vec2_add (p0, vec2_mult (vec2_perp(v1n), hw));*/
                } else
                        v.pos = vec2_add(p0, bisec);
 
@@ -819,9 +816,6 @@ float _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool i
                } else*/
                        _add_vertex(ctx, v);
 
-               /*if (reducedLH)
-                       v.pos = ctx->vertexCache[ctx->vertCount-3].pos;
-               else*/
                if (dot < 0 && reducedLH && det > 0) {
                        if (length_v0 < length_v1)
                                v.pos = vec2_sub (p0, vec2_mult (vec2_perp(v1n), hw));
@@ -836,37 +830,41 @@ float _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool i
        }else{
                vec2 vp = vec2_perp(v0n);
                if (det<0){
-                       if (reducedLH) {
-                               if (length_v0 < length_v1)
-                                       v.pos = vec2_add (p0, vec2_mult (vec2_perp(v1n), hw));
-                               else
-                                       v.pos = vec2_sub (p0, vec2_mult (vec2_perp(v1n), hw));
-                       } else
+                       if (dot < 0 && reducedLH)
+                               v.pos = vec2_sub (p0, vec2_mult (vec2_perp(v1n), hw));
+                       else
                                v.pos = vec2_add (p0, bisec);
                        _add_vertex(ctx, v);
                        v.pos = vec2_sub (p0, vec2_mult (vp, hw));
                }else{
                        v.pos = vec2_add (p0, vec2_mult (vp, hw));
                        _add_vertex(ctx, v);
-                       if (reducedLH) {
-                               if (length_v0 < length_v1)
-                                       v.pos = vec2_sub (p0, vec2_mult (vec2_perp(v1n), hw));
-                               else
-                                       v.pos = vec2_add (p0, vec2_mult (vec2_perp(v1n), hw));
-                       } else
+                       if (dot < 0 && reducedLH)
+                               v.pos = vec2_add (p0, vec2_mult (vec2_perp(v1n), hw));
+                       else
                                v.pos = vec2_sub (p0, bisec);
                }
                _add_vertex(ctx, v);
 
                if (join == VKVG_LINE_JOIN_BEVEL){
                        if (det<0){
-                               _add_triangle_indices(ctx, idx, idx+2, idx+1);
-                               _add_triangle_indices(ctx, idx+2, idx+4, idx+0);
-                               _add_triangle_indices(ctx, idx, idx+3, idx+4);
+                               if (dot < 0 && reducedLH) {
+                                       _add_triangle_indices(ctx, idx, idx+3, idx+4);
+                                       _add_triangle_indices(ctx, idx+1, idx+3, idx+0);
+                               }else{
+                                       _add_triangle_indices(ctx, idx, idx+2, idx+1);
+                                       _add_triangle_indices(ctx, idx+2, idx+4, idx+0);
+                                       _add_triangle_indices(ctx, idx, idx+3, idx+4);
+                               }
                        }else{
-                               _add_triangle_indices(ctx, idx, idx+2, idx+1);
-                               _add_triangle_indices(ctx, idx+2, idx+3, idx+1);
-                               _add_triangle_indices(ctx, idx+1, idx+3, idx+4);
+                               if (dot < 0 && reducedLH) {
+                                       _add_triangle_indices(ctx, idx+1, idx+3, idx+4);
+                                       _add_triangle_indices(ctx, idx, idx+1, idx+4);
+                               }else{
+                                       _add_triangle_indices(ctx, idx, idx+2, idx+1);
+                                       _add_triangle_indices(ctx, idx+2, idx+3, idx+1);
+                                       _add_triangle_indices(ctx, idx+1, idx+3, idx+4);
+                               }
                        }
                }else if (join == VKVG_LINE_JOIN_ROUND){
                        float step = M_PIF / hw;
@@ -893,15 +891,29 @@ float _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool i
                        VKVG_IBO_INDEX_TYPE p0Idx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset);
                        _add_triangle_indices(ctx, idx, idx+2, idx+1);
                        if (det < 0){
-                               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);
+                               if (dot < 0 && reducedLH) {
+                                       for (VKVG_IBO_INDEX_TYPE p = idx+2; p < p0Idx; p++)
+                                               _add_triangle_indices(ctx, p, p+1, idx);
+                                       _add_triangle_indices(ctx, idx+1, p0Idx+1, idx);
+                                       _add_triangle_indices(ctx, idx, p0Idx+1, p0Idx+2);
+                               }else{
+                                       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 (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);
+                               if (dot < 0 && reducedLH) {
+                                       for (VKVG_IBO_INDEX_TYPE p = idx+2; p < p0Idx; p++)
+                                               _add_triangle_indices(ctx, p, p+1, idx+1);
+                                       _add_triangle_indices(ctx, idx, p0Idx+2, idx+1);
+                                       _add_triangle_indices(ctx, idx+1, p0Idx+1, p0Idx+2);
+                               }else{
+                                       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);
+                               }
                        }
 
                }
@@ -927,7 +939,10 @@ float _build_vb_step (vkvg_context* ctx, float hw, stroke_context_t* str, bool i
        debugLinePoints[dlpCount+1] = pR;
        dlpCount+=2;
 #endif*/
-       return det;
+       /*if (reducedLH)
+               return -det;
+       else*/
+               return det;
 }
 
 void _draw_stoke_cap (VkvgContext ctx, float hw, vec2 p0, vec2 n, bool isStart) {
index af2e1df0ef7e6526b7ced4ecbb2beeacfbde1a60..86e384044e104c43ffe78b705c042ce7cd4bd826 100644 (file)
@@ -375,7 +375,7 @@ void _setupPipelines(VkvgDevice dev)
        VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modFragWired));
 
        shaderStages[1].module = modFragWired;
-       inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
+       inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
        rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
        VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineWired));
        vkDestroyShaderModule(dev->vkDev, modFragWired, NULL);
index 645948b12059687efa75ecc3be19e2ed6dbe7231..bec0e4da88753a6a9f9c607d1de555740511ef0b 100644 (file)
@@ -179,6 +179,16 @@ void _print_usage_and_exit () {
        printf("\t\t\t - 2: Discrete (first choice)\n");
        printf("\t\t\t - 3: Virtual\n");
        printf("\t\t\t - 4: Cpu\n");
+       printf("\t-l line_width:\tset lines width for stokes.\n");
+       printf("\t-j line_join:\tset line joins for strokes:\n");
+       printf("\t\t\t - m: Mitter(default)\n");
+       printf("\t\t\t - r: Rount\n");
+       printf("\t\t\t - b: Bevel\n");
+       printf("\t-c line_cap:\tset line caps for strokes:\n");
+       printf("\t\t\t - b: Butt (default)\n");
+       printf("\t\t\t - r: Rount\n");
+       printf("\t\t\t - s: Square\n");
+       printf("\t-d:\t\tenable dashes.\n");
        printf("\t-n index:\tRun only a single test, zero based index.\n");
        printf("\t-q:\t\tQuiet, don't print measures table head row, usefull for batch tests.\n");
        printf("\t-p:\t\tPrint test details and exit without performing test, usefull to print details in logs.\n");
@@ -226,49 +236,87 @@ void _parse_args (int argc, char* argv[]) {
                        if (argc -1 < ++i)
                                _print_usage_and_exit();
                        preferedPhysicalDeviceType = (VkPhysicalDeviceType)atoi (argv[i]);
-               }
-               if (printTestDetailsAndExit) {
-                       #ifdef DEBUG
-                       printf("Debug build\n");
-                       #else
-                       printf("Release build\n");
-                       #endif
-                       #ifdef VKVG_USE_RENDERDOC
-                       printf("Render doc enabled\n");
-                       #endif
-                       #ifdef VKVG_USE_VALIDATION
-                       printf("Validation enabled\n");
-                       #endif
-                       printf("surf dims:\t%d x %d\n", test_width, test_height);
-                       printf("Samples:\t%d\n", samples);
-                       printf("Gpu type:\t");
-                       switch (preferedPhysicalDeviceType) {
-                       case VK_PHYSICAL_DEVICE_TYPE_OTHER:
-                               printf("Other\n");
+               }else if (strcmp (argv[i], "-l\0") == 0) {
+                       if (argc -1 < ++i)
+                               _print_usage_and_exit();
+                       line_width = atoi (argv[i]);
+               }else if (strcmp (argv[i], "-d\0") == 0) {
+                       dashes_count = 2;
+               }else if (strcmp (argv[i], "-j\0") == 0) {
+                       if (argc -1 < ++i)
+                               _print_usage_and_exit();
+                       switch (argv[i][0]) {
+                       case 'm':
+                               line_join = VKVG_LINE_JOIN_MITER;
                                break;
-                       case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
-                               printf("Integrated\n");
+                       case 'r':
+                               line_join = VKVG_LINE_JOIN_ROUND;
                                break;
-                       case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
-                               printf("Discrete\n");
+                       case 'b':
+                               line_join = VKVG_LINE_JOIN_BEVEL;
                                break;
-                       case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
-                               printf("Virtual\n");
+                       default:
+                               _print_usage_and_exit();
+                       }
+               }else if (strcmp (argv[i], "-c\0") == 0) {
+                       if (argc -1 < ++i)
+                               _print_usage_and_exit();
+                       switch (argv[i][0]) {
+                       case 'b':
+                               line_cap = VKVG_LINE_CAP_BUTT;
+                               break;
+                       case 'r':
+                               line_cap = VKVG_LINE_CAP_ROUND;
                                break;
-                       case VK_PHYSICAL_DEVICE_TYPE_CPU:
-                               printf("CPU\n");
+                       case 's':
+                               line_cap = VKVG_LINE_CAP_SQUARE;
                                break;
+                       default:
+                               _print_usage_and_exit();
                        }
-
-                       #ifdef VKVG_TEST_OFFSCREEN
-                       printf("Offscreen:\ttrue\n");
-                       #else
-                       printf("Offscreen:\tfalse\n");
-                       #endif
-                       printf("\n");
-                       exit(0);
                }
        }
+       if (printTestDetailsAndExit) {
+               #ifdef DEBUG
+               printf("Debug build\n");
+               #else
+               printf("Release build\n");
+               #endif
+               #ifdef VKVG_USE_RENDERDOC
+               printf("Render doc enabled\n");
+               #endif
+               #ifdef VKVG_USE_VALIDATION
+               printf("Validation enabled\n");
+               #endif
+               printf("surf dims:\t%d x %d\n", test_width, test_height);
+               printf("Samples:\t%d\n", samples);
+               printf("Gpu type:\t");
+               switch (preferedPhysicalDeviceType) {
+               case VK_PHYSICAL_DEVICE_TYPE_OTHER:
+                       printf("Other\n");
+                       break;
+               case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
+                       printf("Integrated\n");
+                       break;
+               case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
+                       printf("Discrete\n");
+                       break;
+               case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
+                       printf("Virtual\n");
+                       break;
+               case VK_PHYSICAL_DEVICE_TYPE_CPU:
+                       printf("CPU\n");
+                       break;
+               }
+
+               #ifdef VKVG_TEST_OFFSCREEN
+               printf("Offscreen:\ttrue\n");
+               #else
+               printf("Offscreen:\tfalse\n");
+               #endif
+               printf("\n");
+               exit(0);
+       }
 }
 
 void _print_results (const char *testName, int argc, char* argv[], uint32_t i, double run_total, double* run_time_values) {
@@ -570,7 +618,8 @@ void perform_test (void(*testfunc)(void), const char *testName, int argc, char*
 vkvg_fill_rule_t       fill_rule       = VKVG_FILL_RULE_NON_ZERO;
 vkvg_line_cap_t                line_cap        = VKVG_LINE_CAP_BUTT;
 vkvg_line_join_t       line_join       = VKVG_LINE_JOIN_MITER;
-float          dashes[]        = {20.0f, 10.0f};
+float          dashes[]        = {10.0f, 6.0f};
+//float                dashes[]        = {0.0f, 10.0f};
 uint32_t       dashes_count= 0;
 float          dash_offset     = 0;
 float          line_width      = 2.f;
index 5799aec4f5a499d01bb6f7fbf67a5bfef7b140b8..b2559ed759a49da6680aae898bec05073dfc1767 100644 (file)
@@ -19,13 +19,22 @@ vec2 pts[] = {
 int hoverPt = -1;
 double pointSize = 7;
 
+float dash[] = {0, 60};
+uint32_t dashCountInit = 2;
+uint32_t dashCount = 0;
+
+
 
 void draw (){
+
        VkvgContext ctx = vkvg_create(surf);
        vkvg_clear(ctx);
+       if (dashCount > 0)
+               vkvg_set_dash(ctx, dash, dashCount,0);
        vkvg_set_source_rgba(ctx,1,0,0,1);
        vkvg_set_line_width(ctx,lineWidth);
-       vkvg_set_line_join      (ctx, line_join);
+       vkvg_set_line_join      (ctx, lineJoin);
+       vkvg_set_line_cap       (ctx, lineCap);
        vkvg_move_to(ctx,pts[0].x,pts[0].y);
        for (int i=1; i<ptsCount; i++)
                vkvg_line_to(ctx,pts[i].x,pts[i].y);
@@ -34,6 +43,7 @@ void draw (){
 
        if (hoverPt>=0) {
                vkvg_stroke_preserve(ctx);
+               vkvg_set_dash(ctx, NULL, 0, 0);
                vkvg_set_line_width(ctx,2);
                vkvg_set_source_rgba(ctx,0,0,0,1);
                vkvg_stroke(ctx);
@@ -55,9 +65,31 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
        case GLFW_KEY_ESCAPE :
                glfwSetWindowShouldClose(window, GLFW_TRUE);
                break;
-       case GLFW_KEY_C :
+       case GLFW_KEY_W :
                isClosed ^= true;
                break;
+       case GLFW_KEY_J :
+               lineJoin++;
+               if (lineJoin > 2)
+                       lineJoin = 0;
+               break;
+       case GLFW_KEY_C :
+               lineCap++;
+               if (lineCap > 2)
+                       lineCap = 0;
+               break;
+       case GLFW_KEY_D :
+               if (dashCount == 0)
+                       dashCount = dashCountInit;
+               else
+                       dashCount = 0;
+               break;
+       case GLFW_KEY_E :
+               if (dash[0] > 0)
+                       dash[0] = 0;
+               else
+                       dash[0] = 80;
+               break;
        case GLFW_KEY_KP_ADD :
                if (ptsCount < initPtsCount)
                        ptsCount++;