]> O.S.I.I.S - jp/vkvg.git/commitdiff
code clean, add optional dashes config for lines, curves, and rnd rect tests
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 7 Sep 2020 15:52:10 +0000 (15:52 +0000)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 7 Sep 2020 15:52:10 +0000 (15:52 +0000)
src/vkvg_device.c
tests/curve.c
tests/lines.c
tests/random_rects.c

index 6f94cf550a2ba7e8a8afac44617686ab739d539d..e17b81b4778f39cae1991b8a5acca0178cf1b103 100644 (file)
 #include "vkh_queue.h"
 #include "vkh_phyinfo.h"
 #include "vk_mem_alloc.h"
-/**
- * @brief Create VkvgDevice with default multisampling configuration
- * @param Vulkan instance, usefull to retrieve function pointers
- * @param Vulkan physical device
- * @param Vulkan Device
- * @param Queue familly index
- * @param Queue index in selected familly
- * @return
- */
+
 VkvgDevice vkvg_device_create(VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex)
 {
        return vkvg_device_create_multisample (inst,phy,vkdev,qFamIdx,qIndex, VK_SAMPLE_COUNT_1_BIT, false);
 }
-/**
- * @brief Create VkvgDevice with default multisampling configuration
- * @param Vulkan instance, usefull to retrieve function pointers
- * @param Vulkan physical device
- * @param Vulkan Device
- * @param Queue familly index
- * @param Queue index in selected familly
- * @param multisample count
- * @param When set to false, surface is resolve after each renderpasses on resolve attachment of surface.
- * If set to true, multisample surface image is resolve with vkvg_multisample_surface_resolve. This function
- * is called automatically when surface's VkImage is querried with vkvg_surface_get_vk_image.
- * @return
- */
 VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex, VkSampleCountFlags samples, bool deferredResolve)
 {
        LOG(VKVG_LOG_INFO, "CREATE Device: qFam = %d; qIdx = %d\n", qFamIdx, qIndex);
@@ -198,24 +177,12 @@ VkvgDevice vkvg_device_reference (VkvgDevice dev) {
 uint32_t vkvg_device_get_reference_count (VkvgDevice dev) {
        return dev->references;
 }
-/**
- * @brief set horizontal and vertical resolution of device in dot per inch
- * @param vkvg device pointer
- * @param horizontal device resolution in dot per inch
- * @param vertical device resolution in dot per inch
- */
 void vkvg_device_set_dpy (VkvgDevice dev, int hdpy, int vdpy) {
        dev->hdpi = hdpy;
        dev->vdpi = vdpy;
 
        //TODO: reset font cache
 }
-/**
- * @brief get horizontal and vertical resolution of device in dot per inch
- * @param vkvg device pointer
- * @param return horizontal device resolution in dot per inch
- * @param return vertical device resolution in dot per inch
- */
 void vkvg_device_get_dpy (VkvgDevice dev, int* hdpy, int* vdpy) {
        *hdpy = dev->hdpi;
        *vdpy = dev->vdpi;
index 2a76693ff73670a450b29f7cfb47c981d231e206..1367b6000f7a89b711f2ae2599e8b8e8f5726b90 100644 (file)
@@ -111,6 +111,8 @@ void test2() {
 static float line_width = 1.f;
 static vkvg_line_cap_t line_cap = VKVG_LINE_CAP_ROUND;
 static vkvg_fill_rule_t fill_rule = VKVG_FILL_RULE_NON_ZERO;
+static float dashes[] = {30.0f, 10.0f};
+static uint32_t dashes_count = 0;
 static bool fillAndStroke = true;
 
 void _rnd_curve (VkvgContext ctx) {
@@ -127,15 +129,20 @@ void _rnd_curve (VkvgContext ctx) {
        vkvg_curve_to(ctx, cp_x1, cp_y1, cp_x2, cp_y2, x2, y2);
 }
 
+VkvgContext _initCtx() {
+       VkvgContext ctx = vkvg_create(surf);
+       vkvg_clear(ctx);
+       vkvg_set_line_width (ctx,line_width);
+       vkvg_set_line_cap(ctx, line_cap);
+       vkvg_set_dash (ctx, dashes, dashes_count, 0);
+       return ctx;
+}
 
 void random_curves () {
        float w = (float)test_width;
        float h = (float)test_height;
 
-       VkvgContext ctx = vkvg_create(surf);
-       vkvg_clear(ctx);
-       vkvg_set_line_width (ctx,line_width);
-       vkvg_set_line_cap(ctx, line_cap);
+       VkvgContext ctx = _initCtx();
 
        for (uint32_t i=0; i<test_size; i++) {
                randomize_color(ctx);
@@ -153,10 +160,7 @@ void single_long_line_curved () {
        float w = (float)test_width;
        float h = (float)test_height;
 
-       VkvgContext ctx = vkvg_create(surf);
-       vkvg_clear(ctx);
-       vkvg_set_line_width (ctx,line_width);
-       vkvg_set_line_cap(ctx, line_cap);
+       VkvgContext ctx = _initCtx();
        vkvg_set_fill_rule(ctx, fill_rule);
 
        randomize_color(ctx);
index d6ea3d7ead641282734dea3c378a28f1ddfe6cac..57bf035d3e0ddb63fcf474fd00d676b2cde4385c 100644 (file)
@@ -1,16 +1,24 @@
 #include "test.h"
 
-static float line_width = 4.f;
-static vkvg_line_cap_t line_cap = VKVG_LINE_CAP_BUTT;
-
-void horizontal() {
-       float w = (float)test_width;
-       float h = (float)test_height;
+static float line_width = 1.f;
+static vkvg_line_cap_t line_cap = VKVG_LINE_CAP_ROUND;
+static float dashes[] = {1.0f, 5.0f};
+static uint32_t dashes_count = 0;
 
+VkvgContext _initCtx() {
        VkvgContext ctx = vkvg_create(surf);
        vkvg_clear(ctx);
        vkvg_set_line_width (ctx,line_width);
        vkvg_set_line_cap(ctx, line_cap);
+       vkvg_set_dash (ctx, dashes, dashes_count, 0);
+       return ctx;
+}
+
+void horizontal() {
+       float w = (float)test_width;
+       float h = (float)test_height;
+
+       VkvgContext ctx = _initCtx();
 
        for (uint32_t i=0; i<test_size; i++) {
                randomize_color(ctx);
@@ -28,9 +36,7 @@ void vertical() {
        float w = (float)test_width;
        float h = (float)test_height;
 
-       VkvgContext ctx = vkvg_create(surf);
-       vkvg_clear(ctx);
-       vkvg_set_line_width (ctx,line_width);
+       VkvgContext ctx = _initCtx();
 
        for (uint32_t i=0; i<test_size; i++) {
                randomize_color(ctx);
@@ -48,9 +54,7 @@ void horzAndVert(){
        float w = (float)test_width;
        float h = (float)test_height;
 
-       VkvgContext ctx = vkvg_create(surf);
-       vkvg_clear(ctx);
-       vkvg_set_line_width (ctx,line_width);
+       VkvgContext ctx = _initCtx();
 
        for (uint32_t i=0; i<test_size; i++) {
                randomize_color(ctx);
@@ -70,9 +74,7 @@ void multilines(){
        float w = (float)test_width;
        float h = (float)test_height;
 
-       VkvgContext ctx = vkvg_create(surf);
-       vkvg_clear(ctx);
-       vkvg_set_line_width (ctx,line_width);
+       VkvgContext ctx = _initCtx();
 
        randomize_color(ctx);
 
@@ -93,9 +95,7 @@ void multi_segments() {
     float w = (float)test_width-10;
     float h = (float)test_height-10;
 
-    VkvgContext ctx = vkvg_create(surf);
-    vkvg_clear(ctx);
-    vkvg_set_line_width (ctx,line_width);
+    VkvgContext ctx = _initCtx();
 
     randomize_color(ctx);
     float x1 = w*rand()/RAND_MAX;
index 89eb8dcccbfe782224acd3ea918e5259481844a9..d8bf7d6cab1a532858b8706997958e1d1123d4b4 100644 (file)
 
        vkvg_rectangle(ctx, x, y, z, v);
 }*/
-static vkvg_fill_rule_t fill_rule = VKVG_FILL_RULE_NON_ZERO;
-static float line_width = 5.f;
-static float shape_size = 0.1f;
+static vkvg_fill_rule_t fill_rule = VKVG_FILL_RULE_EVEN_ODD;
+static vkvg_line_cap_t line_cap = VKVG_LINE_CAP_BUTT;
+static vkvg_line_join_t line_join = VKVG_LINE_JOIN_MITER;
+static float line_width = 1.f;
+static float shape_size = 0.2f;
+static float dashes[] = {3.0f, 10.0f};
+static uint32_t dashes_count = 0;
+
 
 void _shape_fill(shape_t shape){
        VkvgContext ctx = vkvg_create(surf);
@@ -30,6 +35,9 @@ void _shape_stroke(shape_t shape){
        VkvgContext ctx = vkvg_create(surf);
        vkvg_clear(ctx);
        vkvg_set_line_width (ctx, line_width);
+       vkvg_set_line_cap(ctx, line_cap);
+       vkvg_set_line_join (ctx, line_join);
+       vkvg_set_dash (ctx, dashes, dashes_count, 0);
        vkvg_set_fill_rule(ctx, fill_rule);
        for (uint32_t i=0; i<test_size; i++) {
                draw_random_shape(ctx, shape, shape_size);
@@ -41,6 +49,10 @@ void _shape_fill_stroke(shape_t shape){
        VkvgContext ctx = vkvg_create(surf);
        vkvg_clear(ctx);
        vkvg_set_line_width (ctx, line_width);
+       vkvg_set_line_cap(ctx, line_cap);
+       vkvg_set_line_join (ctx, line_join);
+
+       vkvg_set_dash (ctx, dashes, dashes_count, 0);
        vkvg_set_fill_rule(ctx, fill_rule);
        for (uint32_t i=0; i<test_size; i++) {
                draw_random_shape(ctx, shape, shape_size);