]> O.S.I.I.S - jp/vkvg.git/commitdiff
debug line joins
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 1 Sep 2019 11:46:41 +0000 (13:46 +0200)
committerj-p <jp_bruyere@hotmail.com>
Tue, 3 Sep 2019 18:36:09 +0000 (20:36 +0200)
CMakeLists.txt
src/vkvg_context.c
src/vkvg_context_internal.c
tests/curve.c
tests/line_join_2.c [new file with mode: 0644]
tests/random_rects.c
tests/svg.c

index 086f7862f5a5551742964fe08babaa88927836a2..c2b7f4692c4c01a98f56cc56b9aea8a815ebd2dd 100644 (file)
@@ -126,44 +126,52 @@ if(GLSLC AND XXD)
        #add_definitions( -DDEBUG_VK_PERF=true )
 endif()
 
-FILE(GLOB VKVG_SRC src/*.c)
-
-ADD_LIBRARY(${PROJECT_NAME} SHARED ${VKVG_SRC} ${SHADERS})
-
 if (BuildShaderHeader)
        add_dependencies(${PROJECT_NAME} BuildShaderHeader)
 endif ()
 
-SET_TARGET_PROPERTIES(vkvg PROPERTIES
-       VERSION ${PROJECT_VERSION}
-       SOVERSION 1
-       PUBLIC_HEADER include/vkvg.h
-)
-
-TARGET_INCLUDE_DIRECTORIES(vkvg PRIVATE
-       ${Vulkan_INCLUDE_DIRS}
-       ${FREETYPE_INCLUDE_DIRS}
-       ${HARFBUZZ_INCLUDE_DIRS}
-       ${FONTCONFIG_INCLUDE_DIRS}
-       ${CMAKE_CURRENT_SOURCE_DIR}/include
-       ${CMAKE_CURRENT_SOURCE_DIR}/src
-       ${CMAKE_CURRENT_SOURCE_DIR}/vkh/include
-       ${CMAKE_CURRENT_SOURCE_DIR}/vkh/src
-)
-
-TARGET_LINK_LIBRARIES(${PROJECT_NAME}
-       ${Vulkan_LIBRARIES}
-       ${FREETYPE_LIBRARIES}
-       ${HARFBUZZ_LIBRARIES}
-       ${FONTCONFIG_LIBRARIES}
-       vkh_static
-)
+FILE(GLOB VKVG_SRC src/*.c)
 
 CONFIGURE_FILE(vkvg.pc.in vkvg.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/vkvg.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
-INSTALL(TARGETS vkvg
-       LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
-       PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
+FUNCTION (setup_lib LibName)
+       SET_TARGET_PROPERTIES(${LibName} PROPERTIES
+                       OUTPUT_NAME ${PROJECT_NAME}
+                       VERSION ${PROJECT_VERSION}
+                       SOVERSION 1
+                       PUBLIC_HEADER include/vkvg.h
+       )
+       TARGET_INCLUDE_DIRECTORIES(${LibName} PRIVATE
+               ${Vulkan_INCLUDE_DIRS}
+               ${FREETYPE_INCLUDE_DIRS}
+               ${HARFBUZZ_INCLUDE_DIRS}
+               ${FONTCONFIG_INCLUDE_DIRS}
+               ${CMAKE_CURRENT_SOURCE_DIR}/include
+               ${CMAKE_CURRENT_SOURCE_DIR}/src
+               ${CMAKE_CURRENT_SOURCE_DIR}/vkh/include
+               ${CMAKE_CURRENT_SOURCE_DIR}/vkh/src
+       )
+       TARGET_LINK_LIBRARIES(${LibName}
+               ${Vulkan_LIBRARIES}
+               ${FREETYPE_LIBRARIES}
+               ${HARFBUZZ_LIBRARIES}
+               ${FONTCONFIG_LIBRARIES}
+               vkh_static
+       )
+       INSTALL(TARGETS ${LibName}
+               LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+               ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+               PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+ENDFUNCTION ()
+
+ADD_LIBRARY("${PROJECT_NAME}_static" STATIC ${VKVG_SRC} ${SHADERS})
+SET_PROPERTY(TARGET "${PROJECT_NAME}_static" PROPERTY POSITION_INDEPENDENT_CODE OFF)
+setup_lib ("${PROJECT_NAME}_static")
+
+ADD_LIBRARY("${PROJECT_NAME}_shared" SHARED ${VKVG_SRC} ${SHADERS})
+SET_PROPERTY(TARGET "${PROJECT_NAME}_static" PROPERTY POSITION_INDEPENDENT_CODE ON)
+setup_lib ("${PROJECT_NAME}_shared")
 
 FUNCTION (buildtest TEST_NAME)
        ADD_EXECUTABLE(test_${TEST_NAME} "tests/${TEST_NAME}.c" )
@@ -196,7 +204,7 @@ if (GLFW3_FOUND)
                ${Vulkan_LIBRARIES}
                ${GLFW3_LIBRARY}
                vkh_static
-               vkvg
+               vkvg_static
        )
        file(GLOB_RECURSE DATAS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/tests" "tests/data/*")
        FOREACH(DATA_FILE ${DATAS})
index 747a2089fbb1f2e9f9eaf684ee6248db234490e2..d4ecc15aae1124a4aa089f94d7e227ff8105f052 100644 (file)
@@ -617,8 +617,9 @@ void vkvg_stroke_preserve (VkvgContext ctx)
 
         if (_path_has_curves (ctx,ptrPath)) {
             while (i < lastPathPointIdx){
-                if (i + ptrCurve + 2 < ctx->pathPtr && ctx->pathes [ptrPath + 2 + ptrCurve] == i){
-                    while (i<ctx->pathes[ptrPath + 2 + ptrCurve+1]){
+                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 (i<lastCurvePoint){
                         iR = i+1;
                         _build_vb_step(ctx,v,hw,iL,i,iR,true);
                         iL = i++;
index 1bff46c58846e0463d55f950a30d45c772a2e0f3..82a2721d8d7f4f31a5fa701191fc2940a37f43e3 100644 (file)
@@ -548,9 +548,9 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_
     }else{
         vec2 vp = vec2_perp(v0n);
         if (cross<0){
-            v.pos = vec2_sub (ctx->points[i], vec2_mult (vp, hw));
-            _add_vertex(ctx, v);
             v.pos = vec2_add (ctx->points[i], bisec);
+            _add_vertex(ctx, v);
+            v.pos = vec2_sub (ctx->points[i], vec2_mult (vp, hw));
         }else{
             v.pos = vec2_add (ctx->points[i], vec2_mult (vp, hw));
             _add_vertex(ctx, v);
@@ -559,9 +559,15 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_
         _add_vertex(ctx, v);
 
         if (ctx->lineJoin == VKVG_LINE_JOIN_BEVEL){
-            _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 (cross<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);
+            }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 (ctx->lineJoin == VKVG_LINE_JOIN_ROUND){
             float step = M_PIF / hw;
             float a = acos(vp.x);
@@ -586,11 +592,18 @@ void _build_vb_step (vkvg_context* ctx, Vertex v, float hw, uint32_t iL, uint32_
             }
             uint32_t p0Idx = ctx->vertCount;
             _add_triangle_indices(ctx, idx, idx+2, idx+1);
-            for (int p = idx+2; p < p0Idx; p++)
-                _add_triangle_indices(ctx, p, p+1, idx+1);
+            if (cross<0){
+                for (int 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 (int 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);
+            }
 
-            _add_triangle_indices(ctx, p0Idx, p0Idx+1, idx+1);
-            _add_triangle_indices(ctx, idx+1, p0Idx+1, p0Idx+2);
         }
 
         vp = vec2_mult (vec2_perp(v1n), hw);
index e305c51aee921988a10a2532774c80d8f52b13ee..d64545bd08e720c35fb1f64451d63b5cfb3f9750 100644 (file)
@@ -4,53 +4,37 @@ void test(){
     VkvgContext ctx = vkvg_create(surf);
 
     vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO);
-    vkvg_set_line_width(ctx, 10);
+    vkvg_set_line_width(ctx, 50);
 
-    //vkvg_move_to(ctx,400,100);
-    vkvg_arc(ctx, 300, 300, 100, 0, M_PI);
+    vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL);
+
+    //vkvg_arc (ctx, 200, 500, 100, 0, M_PI);
+
+    vkvg_set_source_rgb   (ctx, 0.5,0,0);
+
+
+    /*vkvg_move_to(ctx,100,100);
+    vkvg_line_to(ctx,300,100);
+    vkvg_line_to(ctx,500,300);
+    vkvg_line_to(ctx,300,500);
+    //vkvg_arc (ctx, 200, 500, 100, 0, M_PI);
+    vkvg_line_to(ctx,300,700);
+    vkvg_line_to(ctx,100,500);*/
+
+    /*vkvg_arc(ctx, 300, 300, 100, 0, M_PI);
+    vkvg_line_to(ctx,100,200);
     vkvg_line_to(ctx,200,100);
     vkvg_arc(ctx, 250, 100, 50, M_PI, M_PI * 1.5f);
     vkvg_line_to(ctx,350,50);
     vkvg_arc(ctx, 350, 100, 50, M_PI*1.5f, M_PI * 2.0f);
 
-    vkvg_set_source_rgb   (ctx, 1,0,0);
-    vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgb   (ctx, 1,1,0);
-    vkvg_stroke_preserve(ctx);
-    vkvg_translate(ctx,50,50);
-    vkvg_set_source_rgb   (ctx, 1,0,0);
-    vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgb   (ctx, 1,1,0);
-    vkvg_stroke_preserve(ctx);
-    vkvg_translate(ctx,50,50);
-    vkvg_set_source_rgb   (ctx, 1,0,0);
-    vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgb   (ctx, 1,1,0);
-    vkvg_stroke_preserve(ctx);
-    vkvg_translate(ctx,50,50);
-    vkvg_set_source_rgb   (ctx, 1,0,0);
-    vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgb   (ctx, 1,1,0);
-    vkvg_stroke_preserve(ctx);
-    vkvg_translate(ctx,50,50);
-    vkvg_set_source_rgb   (ctx, 1,0,0);
-    vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgb   (ctx, 1,1,0);
-    vkvg_stroke_preserve(ctx);
-    vkvg_translate(ctx,50,50);
-    vkvg_set_source_rgb   (ctx, 1,0,0);
-    vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgb   (ctx, 1,1,0);
-    vkvg_stroke_preserve(ctx);
-    vkvg_translate(ctx,50,50);
-    vkvg_set_source_rgb   (ctx, 1,0,0);
-    vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgb   (ctx, 1,1,0);
-    vkvg_stroke_preserve(ctx);
-    vkvg_translate(ctx,100,100);
-
-    /*vkvg_arc(ctx, 200, 200, 10, 0, M_PI*2);
+    vkvg_stroke(ctx);
+    vkvg_translate(ctx,400,30);
 
+    */
+    vkvg_translate(ctx,200,30);
+    vkvg_arc(ctx, 200, 200, 20, 0, M_PI*2);
+    //vkvg_stroke(ctx);
 
     vkvg_set_source_rgba   (ctx, 0.5,0.0,1.0,0.5);
     vkvg_move_to(ctx,100,100);
@@ -62,11 +46,10 @@ void test(){
     vkvg_curve_to(ctx,50,400,10,350,10,300);
     vkvg_line_to(ctx,10,200);
     vkvg_curve_to(ctx,10,150,50,100,100,100);
-    vkvg_close_path(ctx);
-    //vkvg_curve_to(ctx, 150,100,200,150,200,200);
     vkvg_fill_preserve(ctx);
-    vkvg_set_source_rgba   (ctx, 1,1,1.0,0.5);*/
-    //vkvg_stroke(ctx);
+    vkvg_set_source_rgba   (ctx, 0.1f,0.3,0.7,0.5);
+    vkvg_stroke(ctx);
+
 
     vkvg_destroy(ctx);
 }
diff --git a/tests/line_join_2.c b/tests/line_join_2.c
new file mode 100644 (file)
index 0000000..a6e0ea7
--- /dev/null
@@ -0,0 +1,58 @@
+#include "test.h"
+
+void test(){
+    VkvgContext ctx = vkvg_create(surf);
+
+    vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD);
+    vkvg_set_line_width(ctx, 30);
+
+    vkvg_set_line_join(ctx, VKVG_LINE_JOIN_ROUND);
+
+    //vkvg_arc (ctx, 200, 500, 100, 0, M_PI);
+
+    vkvg_translate(ctx,-50,-50);
+
+    vkvg_set_source_rgb   (ctx, 0.5,0,0);
+
+    for (int j=0;j<2;j++) {
+         int i=0;
+         vkvg_move_to(ctx,100,100);
+         for (i=0;i<5;i++) {
+             vkvg_rel_line_to(ctx,70,50);
+             vkvg_rel_line_to(ctx,-70,50);
+         }
+         vkvg_stroke(ctx);
+
+         vkvg_move_to(ctx,200,600);
+         for (i=0;i<5;i++) {
+             vkvg_rel_line_to(ctx,70,-50);
+             vkvg_rel_line_to(ctx,-70,-50);
+         }
+         vkvg_stroke(ctx);
+
+         vkvg_move_to(ctx,400,100);
+         for (i=0;i<5;i++) {
+             vkvg_rel_line_to(ctx,-70,50);
+             vkvg_rel_line_to(ctx,70,50);
+         }
+         vkvg_stroke(ctx);
+
+         vkvg_move_to(ctx,500,600);
+         for (i=0;i<5;i++) {
+             vkvg_rel_line_to(ctx,-70,-50);
+             vkvg_rel_line_to(ctx,70,-50);
+         }
+         vkvg_stroke(ctx);
+         vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL);
+         vkvg_translate(ctx,500,0);
+    }
+
+    vkvg_destroy(ctx);
+}
+
+int main(int argc, char *argv[]) {
+
+    perform_test (test, 1024, 768);
+
+    return 0;
+}
index 002510f3dcfa46424ada6d2cfe9c999ae0137b23..3ad539bca8004326c396940b4f843b801943668b 100644 (file)
@@ -11,8 +11,9 @@ void test(){
     VkvgContext ctx = vkvg_create(surf);
     vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO);
     vkvg_set_line_width(ctx,2);
-    for (int i=0; i<500; i++) {
-        randomize_color(ctx);
+    vkvg_set_source_rgba(ctx,1.0,0.0,0.0,0.1);
+    for (int i=0; i<1500; i++) {
+        //randomize_color(ctx);
         float x = trunc( (0.5*(float)w*rand())/RAND_MAX );
         float y = trunc( (0.5*(float)w*rand())/RAND_MAX );
         float z = trunc( (0.5*(float)w*rand())/RAND_MAX ) + 1;
@@ -20,7 +21,7 @@ void test(){
 
         vkvg_rectangle(ctx, x+1, y+1, z, v);
         vkvg_fill_preserve(ctx);
-        randomize_color(ctx);
+        //randomize_color(ctx);
         vkvg_stroke(ctx);
     }
     vkvg_destroy(ctx);
index a8d880f08e5276ea743afe18c86c01dd3dace44b..3fb5c23102524a1f4269c0210d85f758ede6334a 100644 (file)
@@ -1,16 +1,16 @@
 #include "test.h"
 
 #include "string.h" //for nanosvg
-#define NANOSVG_IMPLEMENTATION // Expands implementation
+//#define NANOSVG_IMPLEMENTATION       // Expands implementation
 #include "nanosvg.h"
 
-void _svg_set_color (VkvgContext ctx, uint32_t c, float alpha) {
+/*void _svg_set_color (VkvgContext ctx, uint32_t c, float alpha) {
     float a = (c >> 24 & 255) / 255.f;
     float b = (c >> 16 & 255) / 255.f;
     float g = (c >> 8 & 255) / 255.f;
     float r = (c & 255) / 255.f;
     vkvg_set_source_rgba(ctx,r,g,b,a*alpha);
-}
+}*/
 
 static float rotation = 0.f;
 static const char* path = "data/tiger.svg";