]> O.S.I.I.S - jp/vkvg.git/commitdiff
reset descriptor of bound source when no longer used, update readme
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 14 Apr 2018 03:57:40 +0000 (05:57 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 14 Apr 2018 03:57:40 +0000 (05:57 +0200)
README.md
shaders/triangle.vert
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
src/vkvg_surface.c
tests/test1.c
vkh

index 294c053513a52fe35374f414cce933817b59a2a7..6e087393d999a0c6502f00f0d36879d9528662c8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,15 +1,15 @@
 <h1 align="center">
   <br>
   <a href="https://github.com/jpbruyere/vkvg/blob/master/vkvg.svg">
-    <img src="https://github.com/jpbruyere/vkvg/blob/master/vkvg.svg?sanitize=true" alt="vkvg" width="140">
+       <img src="https://github.com/jpbruyere/vkvg/blob/master/vkvg.svg?sanitize=true" alt="vkvg" width="140">
   </a>
-  <br>  
-    <br>
+  <br>
+       <br>
   Vulkan Vector Graphics
-  <br>  
+  <br>
 <p align="center">
   <a href="https://www.paypal.me/GrandTetraSoftware">
-    <img src="https://img.shields.io/badge/Donate-PayPal-green.svg">
+       <img src="https://img.shields.io/badge/Donate-PayPal-green.svg">
   </a>
 </p>
 </h1>
@@ -18,9 +18,9 @@
 
 **vkvg** is a multiplatform **c** library for drawing 2D vector graphics with [Vulkan](https://www.khronos.org/vulkan/).
 
-[Cairo](https://www.cairographics.org/) is missing a Vulkan backend, so I decided to start one myself trying to keep my api as close to Cairo as possible. Maybe vkvg could serve as a starting point for Cairo maintainers to start their Vulkan backend.
+[Cairo](https://www.cairographics.org/) was missing a Vulkan backend, so I decided to start one myself trying to keep my api as close to Cairo as possible. Maybe vkvg could serve as a starting point for Cairo maintainers to start their Vulkan backend.
 
-### Current status: 
+### Current status:
 
 vkvg is in early development stage, and no guarantee is given on the possible roadmap:
 
@@ -28,9 +28,25 @@ vkvg is in early development stage, and no guarantee is given on the possible ro
 - Basic painting operation.
 - Font system with caching operational.
 - Context should be thread safe, tests required.
+- Image loading with [stb lib](https://github.com/nothings/stb)
 - Nice logo.
 
+### Requirements:
+
+- [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
+
 ### Roadmap
 
-- Offscreen pattern building. 
+- Improve triangulation algorithm.
+- Offscreen pattern building.
+- Matrix transformations.
+- SVG rendering.
 
index c36ca9584aa6058c2131a2a27ee74d004a605435..4e583c4d19899456c6535003d7408e4573ed16e7 100644 (file)
@@ -31,5 +31,5 @@ void main()
        }else
                outSrcRect = pushConsts.source;
 
-       gl_Position = vec4(inPos.xy*pushConsts.scale+pushConsts.translate,0.0, 1.0);
+       gl_Position = vec4(inPos.xy * pushConsts.scale - vec2(1), 0.0, 1.0);
 }
index 9569b73d1e9969c33f716297398ffa130600109e..856bc43c9c5af76130e9217d47be18485cce94ed 100644 (file)
@@ -23,7 +23,7 @@ VkvgContext vkvg_create(VkvgSurface surf)
     push_constants pc = {
             {},
             {2.0f/(float)ctx->pSurf->width,2.0f/(float)ctx->pSurf->height},
-            {-1.f,-1.f},
+            {0.f,0.f},
             VKVG_SRC_SOLID
     };
     ctx->pushConsts = pc;
@@ -50,6 +50,8 @@ VkvgContext vkvg_create(VkvgSurface surf)
     _init_cmd_buff          (ctx);
     _clear_path             (ctx);
 
+
+
     return ctx;
 }
 void vkvg_flush (VkvgContext ctx){
@@ -429,6 +431,12 @@ void vkvg_paint (VkvgContext ctx){
 
 void vkvg_set_rgba (VkvgContext ctx, float r, float g, float b, float a)
 {
+    if (ctx->pushConsts.srcType == VKVG_SRC_PATTERN){
+        _flush_cmd_buff             (ctx);
+        _reset_src_descriptor_set   (ctx);
+        _init_cmd_buff              (ctx);
+    }
+
     vec4 c = {r,g,b,a};
     ctx->pushConsts.source = c;
     ctx->pushConsts.srcType = VKVG_SRC_SOLID;
@@ -464,7 +472,8 @@ void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y
 
     ctx->source = surf->img;
 
-    vkh_image_create_sampler(ctx->source,VK_FILTER_NEAREST, VK_FILTER_NEAREST,
+    if (vkh_image_get_sampler(ctx->source) == VK_NULL_HANDLE)
+        vkh_image_create_sampler(ctx->source,VK_FILTER_NEAREST, VK_FILTER_NEAREST,
                              VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
 
     if (vkh_image_get_layout (ctx->source) != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL){
index 94ac6d006b567428ffad4de3a341fc0a738d98eb..3d7f317b59b8fcef6c650be1fc4d8cbc26e319b3 100644 (file)
@@ -168,9 +168,9 @@ void _init_cmd_buff (VkvgContext ctx){
                                                   .renderPass = ctx->pSurf->dev->renderPass,
                                                   .framebuffer = ctx->pSurf->fb,
                                                   .renderArea.extent = {ctx->pSurf->width,ctx->pSurf->height},
-
                                                   .clearValueCount = 4,
                                                   .pClearValues = clearValues};
+
     vkh_cmd_begin (ctx->cmd,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
     vkCmdBeginRenderPass (ctx->cmd, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
     VkViewport viewport = {0,0,ctx->pSurf->width,ctx->pSurf->height,0,1};
@@ -231,6 +231,22 @@ void _update_descriptor_set (VkvgContext ctx, VkhImage img, VkDescriptorSet ds){
     };
     vkUpdateDescriptorSets(ctx->pSurf->dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
 }
+
+/*
+ * Reset currently bound descriptor which image could be destroyed
+ */
+void _reset_src_descriptor_set (VkvgContext ctx){
+    VkvgDevice dev = ctx->pSurf->dev;
+    //VkDescriptorSet dss[] = {ctx->dsSrc};
+    vkFreeDescriptorSets    (dev->vkDev, ctx->descriptorPool, 1, &ctx->dsSrc);
+
+    VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
+                                                              .descriptorPool = ctx->descriptorPool,
+                                                              .descriptorSetCount = 1,
+                                                              .pSetLayouts = &dev->dslSrc };
+    VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsSrc));
+}
+
 void _createDescriptorPool (VkvgContext ctx) {
     VkvgDevice dev = ctx->pSurf->dev;
     VkDescriptorPoolSize descriptorPoolSize = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2 };
index 5399dfc2b2b0c5a77e4c44afd0c61e783bae520a..fd206376d2e9fa44798c64354ce907a6186e22cb 100644 (file)
@@ -140,6 +140,7 @@ uint32_t _get_last_point_of_closed_path (VkvgContext ctx, uint32_t ptrPath);
 void _createDescriptorPool  (VkvgContext ctx);
 void _init_descriptor_sets  (VkvgContext ctx);
 void _update_descriptor_set (VkvgContext ctx, VkhImage img, VkDescriptorSet ds);
+void _reset_src_descriptor_set(VkvgContext ctx);
 void _free_ctx_save         (vkvg_context_save_t* sav);
 
 static inline float vec2_zcross (vec2 v1, vec2 v2){
index 2fe0a9a044a393e47d5592ce33a0180fdf54b7a4..0e8955cc53653740b9559796b41cff82ddb079b8 100644 (file)
@@ -146,6 +146,11 @@ VkvgSurface vkvg_surface_create_from_image (VkvgDevice dev, const char* filePath
 
     //create tmp context with rendering pipeline to create the multisample img
     VkvgContext ctx = vkvg_create (surf);
+
+    VkClearAttachment ca = {VK_IMAGE_ASPECT_COLOR_BIT,0, { 0.0f, 0.0f, 0.0f, 0.0f }};
+    VkClearRect cr = {{{0,0},{surf->width,surf->height}},0,1};
+    vkCmdClearAttachments(ctx->cmd, 1, &ca, 1, &cr);
+
     vec4 srcRect = {0,0,surf->width,surf->height};
     ctx->pushConsts.source = srcRect;
     ctx->pushConsts.srcType = VKVG_SRC_PATTERN;
index 4dbf7f1f24e915b0fe37a3ba5743753f16897b63..732d481a8cb9602513c88e47620ceb73b2417258 100644 (file)
@@ -649,7 +649,15 @@ void test_img_surface (VkvgContext ctx) {
     //VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "/mnt/data/images/path2674.png");
     //VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "/mnt/data/images/horse-black-head-shape-of-a-chess-piece_318-52446.jpg");
 
-    vkvg_set_source_surface(ctx, imgSurf, 300, 300);
+    vkvg_set_source_surface(ctx, imgSurf, 200, 200);
+    vkvg_paint(ctx);
+    vkvg_set_source_surface(ctx, imgSurf, 400, 400);
+    vkvg_paint(ctx);
+    vkvg_flush(ctx);
+    vkvg_surface_destroy(imgSurf);
+
+    imgSurf = vkvg_surface_create_from_image(device, "/mnt/data/images/path2674.png");
+    vkvg_set_source_surface(ctx, imgSurf, 0, 0);
     vkvg_paint(ctx);
     vkvg_flush(ctx);
     vkvg_surface_destroy(imgSurf);
@@ -674,9 +682,7 @@ int main(int argc, char *argv[]) {
     VkvgSurface surf2 = vkvg_surface_create (device,1024,800);;
     VkvgContext ctx = vkvg_create(surf2);
 
-    //test_img_surface(ctx);
-
-    vkvg_set_rgba(ctx,0.02,0.02,0.1,1);
+    vkvg_set_rgba(ctx,0.02,0.02,0.3,1.0);
     //vkvg_paint(ctx);
     vkvg_rectangle (ctx,0,0,1024,800);
     vkvg_fill (ctx);
@@ -687,6 +693,8 @@ int main(int argc, char *argv[]) {
     vkvg_test_curves(ctx);
     test_text(ctx);
 
+    //test_img_surface(ctx);
+
     vkvg_destroy(ctx);
     ctx = vkvg_create(surf);
 
diff --git a/vkh b/vkh
index 11a3c034e013251ae11e39d1bce38119b376db47..27fad24142f4cfbbc2e0069bf0446f2f9fafa345 160000 (submodule)
--- a/vkh
+++ b/vkh
@@ -1 +1 @@
-Subproject commit 11a3c034e013251ae11e39d1bce38119b376db47
+Subproject commit 27fad24142f4cfbbc2e0069bf0446f2f9fafa345