<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>
**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:
- 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.
}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);
}
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;
_init_cmd_buff (ctx);
_clear_path (ctx);
+
+
return ctx;
}
void vkvg_flush (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;
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){
.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};
};
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 };
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){
//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;
//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);
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);
vkvg_test_curves(ctx);
test_text(ctx);
+ //test_img_surface(ctx);
+
vkvg_destroy(ctx);
ctx = vkvg_create(surf);
-Subproject commit 11a3c034e013251ae11e39d1bce38119b376db47
+Subproject commit 27fad24142f4cfbbc2e0069bf0446f2f9fafa345