* create surface from image, split device internal funs in separate file, update_descriptors from surf more generic
* curve_to implementation with antigrain algorithm, should find correct limits
#define VKVG_SAMPLES VK_SAMPLE_COUNT_4_BIT
-typedef enum VkvgDirection {
+typedef enum _vkvg_direction {
VKVG_HORIZONTAL = 0,
VKVG_VERTICAL = 1
-}VkvgDirection;
+}vkvg_direction_t;
+
+typedef enum _vkvg_format {
+ VKVG_FORMAT_ARGB32,
+ VKVG_FORMAT_RGB24,
+ VKVG_FORMAT_A8,
+ VKVG_FORMAT_A1
+} vkvg_format_t;
typedef struct _vkvg_context_t* VkvgContext;
typedef struct _vkvg_surface_t* VkvgSurface;
void vkvg_device_destroy (VkvgDevice dev);
VkvgSurface vkvg_surface_create (VkvgDevice dev, uint32_t width, uint32_t height);
+VkvgSurface vkvg_surface_create_from_image (VkvgDevice dev, const char* filePath);
+
void vkvg_surface_destroy (VkvgSurface surf);
VkImage vkvg_surface_get_vk_image (VkvgSurface surf);
VkImage vkvg_surface_get_vkh_image (VkvgSurface surf);
void vkvg_line_to (VkvgContext ctx, float x, float y);
void vkvg_move_to (VkvgContext ctx, float x, float y);
void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2);
+void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3);
void vkvg_stroke (VkvgContext ctx);
void vkvg_stroke_preserve (VkvgContext ctx);
void vkvg_fill (VkvgContext ctx);
_create_cmd_buff (ctx);
_createDescriptorPool (ctx);
_init_descriptor_sets (ctx);
- _update_font_descriptor_set (ctx);
+ _update_descriptor_set (ctx, ctx->pSurf->dev->fontCache->cacheTex, ctx->dsFont);
_init_cmd_buff (ctx);
_clear_path (ctx);
}
-void _free_ctx_save (vkvg_context_save_t* sav){
- free(sav->pathes);
- free(sav->points);
- free(sav->selectedFont.fontFile);
- vkh_image_destroy (sav->stencilMS);
- free (sav);
-}
-
void vkvg_destroy (VkvgContext ctx)
{
_flush_cmd_buff(ctx);
ctx->pathPtr++;
_add_curpos(ctx);
}
- _add_point(ctx, x, y);
+ _add_point_cp_update(ctx, x, y);
}
void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2){
while(a > aa2){
v.x = cos(a)*radius + xc;
v.y = sin(a)*radius + yc;
- _add_point(ctx,v.x,v.y);
+ _add_point_cp_update(ctx,v.x,v.y);
a-=step;
}
}else{
while(a < aa2){
v.x = cos(a)*radius + xc;
v.y = sin(a)*radius + yc;
- _add_point(ctx,v.x,v.y);
+ _add_point_cp_update(ctx,v.x,v.y);
a+=step;
}
}
v.x = cos(a)*radius + xc;
v.y = sin(a)*radius + yc;
if (!vec2_equ (v,ctx->curPos))
- _add_point(ctx,v.x,v.y);
+ _add_point_cp_update(ctx,v.x,v.y);
}
void vkvg_move_to (VkvgContext ctx, float x, float y)
ctx->curPos.y = y;
}
+void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3) {
+ _bezier (ctx, ctx->curPos.x, ctx->curPos.y, x1, y1, x2, y2, x3, y3);
+}
+
void vkvg_clip_preserve (VkvgContext ctx){
vkCmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
vkvg_fill_preserve(ctx);
_submit_wait_and_reset_cmd (ctx);
}
- _update_source_descriptor_set (ctx);
+ _update_descriptor_set (ctx, ctx->source, ctx->dsSrc);
_init_cmd_buff (ctx);
vec4 srcRect = {x,y,surf->width,surf->height};
_set_font_size (ctx,size);
}
-void vkvg_set_text_direction (vkvg_context* ctx, VkvgDirection direction){
+void vkvg_set_text_direction (vkvg_context* ctx, vkvg_direction_t direction){
}
+
+//credits for bezier algorithms to:
+// Anti-Grain Geometry (AGG) - Version 2.5
+// A high quality rendering engine for C++
+// Copyright (C) 2002-2006 Maxim Shemanarev
+// Contact: mcseem@antigrain.com
+// mcseemagg@yahoo.com
+// http://antigrain.com
+
+
#include "vkvg_surface_internal.h"
#include "vkvg_context_internal.h"
#include "vkvg_device_internal.h"
ctx->sizePathes += VKVG_PATHES_SIZE;
ctx->pathes = (uint32_t*) realloc (ctx->pathes, ctx->sizePathes*sizeof(uint32_t));
}
-void _add_point(VkvgContext ctx, float x, float y){
+void _add_point (VkvgContext ctx, float x, float y){
+ vec2 v = {x,y};
+ ctx->points[ctx->pointCount] = v;
+ ctx->pointCount++;
+}
+void _add_point_cp_update(VkvgContext ctx, float x, float y){
ctx->curPos.x = x;
ctx->curPos.y = y;
ctx->points[ctx->pointCount] = ctx->curPos;
return ctx->pathes[ptrPath+2]-1; //last p is p prior to first idx of next path
return ctx->pointCount-1; //last point of path is last point of point array
}
-void _update_source_descriptor_set (VkvgContext ctx){
- VkvgDevice dev = ctx->pSurf->dev;
- VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor (ctx->source, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
+void _update_descriptor_set (VkvgContext ctx, VkhImage img, VkDescriptorSet ds){
+ VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor (img, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkWriteDescriptorSet writeDescriptorSet = {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
- .dstSet = ctx->dsSrc,
+ .dstSet = ds,
.dstBinding = 0,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = &descSrcTex
};
- vkUpdateDescriptorSets(dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
-}
-void _update_font_descriptor_set (VkvgContext ctx){
- VkvgDevice dev = ctx->pSurf->dev;
- _font_cache_t* cache = dev->fontCache;
- VkDescriptorImageInfo descFontTex = vkh_image_get_descriptor (cache->cacheTex, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
- VkWriteDescriptorSet writeDescriptorSet = {
- .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
- .dstSet = ctx->dsFont,
- .dstBinding = 0,
- .descriptorCount = 1,
- .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
- .pImageInfo = &descFontTex
- };
- vkUpdateDescriptorSets(dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
+ vkUpdateDescriptorSets(ctx->pSurf->dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
}
void _createDescriptorPool (VkvgContext ctx) {
VkvgDevice dev = ctx->pSurf->dev;
return (s<=0) && (t<=0) && (s+t>=D);
return (s>=0) && (t>=0) && (s+t<=D);
}
+
+void _free_ctx_save (vkvg_context_save_t* sav){
+ free(sav->pathes);
+ free(sav->points);
+ free(sav->selectedFont.fontFile);
+ vkh_image_destroy (sav->stencilMS);
+ free (sav);
+}
+
+
+#define m_approximation_scale 1.0
+#define m_angle_tolerance 0.5
+#define m_distance_tolerance 0.25
+#define m_cusp_limit 0.2
+#define curve_recursion_limit 32
+#define curve_collinearity_epsilon 0.01
+#define curve_angle_tolerance_epsilon 0.01
+
+void _recursive_bezier (VkvgContext ctx,
+ float x1, float y1, float x2, float y2,
+ float x3, float y3, float x4, float y4,
+ unsigned level) {
+ if(level > curve_recursion_limit)
+ {
+ return;
+ }
+
+ // Calculate all the mid-points of the line segments
+ //----------------------
+ float x12 = (x1 + x2) / 2;
+ float y12 = (y1 + y2) / 2;
+ float x23 = (x2 + x3) / 2;
+ float y23 = (y2 + y3) / 2;
+ float x34 = (x3 + x4) / 2;
+ float y34 = (y3 + y4) / 2;
+ float x123 = (x12 + x23) / 2;
+ float y123 = (y12 + y23) / 2;
+ float x234 = (x23 + x34) / 2;
+ float y234 = (y23 + y34) / 2;
+ float x1234 = (x123 + x234) / 2;
+ float y1234 = (y123 + y234) / 2;
+
+ if(level > 0) // Enforce subdivision first time
+ {
+ // Try to approximate the full cubic curve by a single straight line
+ //------------------
+ float dx = x4-x1;
+ float dy = y4-y1;
+
+ float d2 = fabs(((x2 - x4) * dy - (y2 - y4) * dx));
+ float d3 = fabs(((x3 - x4) * dy - (y3 - y4) * dx));
+
+ float da1, da2;
+
+ if(d2 > curve_collinearity_epsilon && d3 > curve_collinearity_epsilon)
+ {
+ // Regular care
+ //-----------------
+ if((d2 + d3)*(d2 + d3) <= m_distance_tolerance * (dx*dx + dy*dy))
+ {
+ // If the curvature doesn't exceed the distance_tolerance value
+ // we tend to finish subdivisions.
+ //----------------------
+ if(m_angle_tolerance < curve_angle_tolerance_epsilon)
+ {
+ _add_point (ctx, x1234, y1234);
+ return;
+ }
+
+ // Angle & Cusp Condition
+ //----------------------
+ float a23 = atan2(y3 - y2, x3 - x2);
+ da1 = fabs(a23 - atan2(y2 - y1, x2 - x1));
+ da2 = fabs(atan2(y4 - y3, x4 - x3) - a23);
+ if(da1 >= M_PI) da1 = M_2_PI - da1;
+ if(da2 >= M_PI) da2 = M_2_PI - da2;
+
+ if(da1 + da2 < m_angle_tolerance)
+ {
+ // Finally we can stop the recursion
+ //----------------------
+ _add_point (ctx, x1234, y1234);
+ return;
+ }
+
+ if(m_cusp_limit != 0.0)
+ {
+ if(da1 > m_cusp_limit)
+ {
+ _add_point (ctx, x2, y2);
+ return;
+ }
+
+ if(da2 > m_cusp_limit)
+ {
+ _add_point (ctx, x3, y3);
+ return;
+ }
+ }
+ }
+ } else {
+ if(d2 > curve_collinearity_epsilon)
+ {
+ // p1,p3,p4 are collinear, p2 is considerable
+ //----------------------
+ if(d2 * d2 <= m_distance_tolerance * (dx*dx + dy*dy))
+ {
+ if(m_angle_tolerance < curve_angle_tolerance_epsilon)
+ {
+ _add_point (ctx, x1234, y1234);
+ return;
+ }
+
+ // Angle Condition
+ //----------------------
+ da1 = fabs(atan2(y3 - y2, x3 - x2) - atan2(y2 - y1, x2 - x1));
+ if(da1 >= M_PI) da1 = M_2_PI - da1;
+
+ if(da1 < m_angle_tolerance)
+ {
+ _add_point (ctx, x2, y2);
+ _add_point (ctx, x3, y3);
+ return;
+ }
+
+ if(m_cusp_limit != 0.0)
+ {
+ if(da1 > m_cusp_limit)
+ {
+ _add_point (ctx, x2, y2);
+ return;
+ }
+ }
+ }
+ } else if(d3 > curve_collinearity_epsilon) {
+ // p1,p2,p4 are collinear, p3 is considerable
+ //----------------------
+ if(d3 * d3 <= m_distance_tolerance * (dx*dx + dy*dy))
+ {
+ if(m_angle_tolerance < curve_angle_tolerance_epsilon)
+ {
+ _add_point (ctx, x1234, y1234);
+ return;
+ }
+
+ // Angle Condition
+ //----------------------
+ da1 = fabs(atan2(y4 - y3, x4 - x3) - atan2(y3 - y2, x3 - x2));
+ if(da1 >= M_PI) da1 = M_2_PI - da1;
+
+ if(da1 < m_angle_tolerance)
+ {
+ _add_point (ctx, x2, y2);
+ _add_point (ctx, x3, y3);
+ return;
+ }
+
+ if(m_cusp_limit != 0.0)
+ {
+ if(da1 > m_cusp_limit)
+ {
+ _add_point (ctx, x3, y3);
+ return;
+ }
+ }
+ }
+ }
+ else
+ {
+ // Collinear case
+ //-----------------
+ dx = x1234 - (x1 + x4) / 2;
+ dy = y1234 - (y1 + y4) / 2;
+ if(dx*dx + dy*dy <= m_distance_tolerance)
+ {
+ _add_point (ctx, x1234, y1234);
+ return;
+ }
+ }
+ }
+ }
+
+ // Continue subdivision
+ //----------------------
+ _recursive_bezier(ctx, x1, y1, x12, y12, x123, y123, x1234, y1234, level + 1);
+ _recursive_bezier(ctx, x1234, y1234, x234, y234, x34, y34, x4, y4, level + 1);
+}
+
+//------------------------------------------------------------------------
+void _bezier (VkvgContext ctx,
+ float x1, float y1,
+ float x2, float y2,
+ float x3, float y3,
+ float x4, float y4) {
+ if (ctx->pathPtr % 2 == 0){//current path is empty
+ //set start to current idx in point array
+ ctx->pathes[ctx->pathPtr] = ctx->pointCount;
+ _check_pathes_array(ctx);
+ ctx->pathPtr++;
+ }
+ _add_point (ctx, x1, y1);
+ _recursive_bezier (ctx, x1, y1, x2, y2, x3, y3, x4, y4, 0);
+ _add_point_cp_update (ctx, x4, y4);
+}
_vkvg_font_t selectedFont; //hold current face and size before cache addition
_vkvg_font_t* currentFont; //font ready for lookup
- VkvgDirection textDirection;
+ vkvg_direction_t textDirection;
push_constants pushConsts;
}vkvg_context_save_t;
_vkvg_font_t selectedFont; //hold current face and size before cache addition
_vkvg_font_t* currentFont; //font ready for lookup
- VkvgDirection textDirection;
+ vkvg_direction_t textDirection;
push_constants pushConsts;
void _check_pathes_array (VkvgContext ctx);
float _normalizeAngle (float a);
-void _add_point (VkvgContext ctx, float x, float y);
+void _add_point (VkvgContext ctx, float x, float y);
+void _add_point_cp_update (VkvgContext ctx, float x, float y);
void _add_point_v2 (VkvgContext ctx, vec2 v);
void _add_curpos (VkvgContext ctx);
void _vkvg_fill_rectangle (VkvgContext ctx, float x, float y, float width, float height);
void _create_vertices_buff (VkvgContext ctx);
void _add_vertex (VkvgContext ctx, Vertex v);
void _set_vertex (VkvgContext ctx, uint32_t idx, Vertex v);
+void _add_triangle_indices (VkvgContext ctx, uint32_t i0, uint32_t i1,uint32_t i2);
void _add_tri_indices_for_rect (VkvgContext ctx, uint32_t i);
-void _add_triangle_indices (VkvgContext ctx, uint32_t i0, uint32_t i1,uint32_t i2);
void _create_cmd_buff (VkvgContext ctx);
void _init_cmd_buff (VkvgContext ctx);
bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath);
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_source_descriptor_set (VkvgContext ctx);
-void _update_font_descriptor_set (VkvgContext ctx);
+void _createDescriptorPool (VkvgContext ctx);
+void _init_descriptor_sets (VkvgContext ctx);
+void _update_descriptor_set (VkvgContext ctx, VkhImage img, VkDescriptorSet ds);
+void _free_ctx_save (vkvg_context_save_t* sav);
static inline float vec2_zcross (vec2 v1, vec2 v2){
return v1.x*v2.y-v1.y*v2.x;
static inline float ecp_zcross (ear_clip_point* p0, ear_clip_point* p1, ear_clip_point* p2){
return vec2_zcross (vec2_sub (p1->pos, p0->pos), vec2_sub (p2->pos, p0->pos));
}
+void _recursive_bezier(VkvgContext ctx,
+ float x1, float y1, float x2, float y2,
+ float x3, float y3, float x4, float y4,
+ unsigned level);
+void _bezier (VkvgContext ctx,
+ float x1, float y1, float x2, float y2,
+ float x3, float y3, float x4, float y4);
#endif
#include "vkvg_device_internal.h"
-#include "vkvg_context_internal.h"
-#include "shaders.h"
-
-void _create_pipeline_cache (VkvgDevice dev);
-void _setupRenderPass (VkvgDevice dev);
-void _setupPipelines (VkvgDevice dev);
-void _createDescriptorSetLayout (VkvgDevice dev);
VkvgDevice vkvg_device_create(VkPhysicalDevice phy, VkDevice vkdev, VkQueue queue, uint32_t qFam)
{
dev->vkDev = vkdev;
vkGetPhysicalDeviceMemoryProperties (phy, &dev->phyMemProps);
- dev->queue = queue;
- dev->qFam = qFam;
- dev->lastCtx = NULL;
-
- dev->cmdPool = vkh_cmd_pool_create (dev->vkDev, qFam, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
- dev->cmd = vkh_cmd_buff_create (dev->vkDev, dev->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
- dev->fence = vkh_fence_create_signaled (dev->vkDev);
-
- _create_pipeline_cache(dev);
+ for (int i=0; i<120; i++){
+ VkFormatProperties formatProps = {};
+ vkGetPhysicalDeviceFormatProperties (phy, (VkFormat)i, &formatProps);
+ printf("%d => Buff = %d, Lin = %d, Opt = %d\n", i, formatProps.bufferFeatures, formatProps.linearTilingFeatures, formatProps.optimalTilingFeatures);
+ }
- _init_fonts_cache(dev);
+ dev->queue = queue;
+ dev->qFam = qFam;
+ dev->lastCtx= NULL;
- _setupRenderPass (dev);
+ dev->cmdPool= vkh_cmd_pool_create (dev->vkDev, qFam, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
+ dev->cmd = vkh_cmd_buff_create (dev->vkDev, dev->cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
+ dev->fence = vkh_fence_create_signaled (dev->vkDev);
- _createDescriptorSetLayout (dev);
+ _create_pipeline_cache (dev);
+ _init_fonts_cache (dev);
+ _setupRenderPass (dev);
+ _createDescriptorSetLayout (dev);
+ _setupPipelines (dev);
- _setupPipelines (dev);
return dev;
}
_destroy_font_cache(dev);
free(dev);
}
-void _flush_all_contexes (VkvgDevice dev){
- VkvgContext next = dev->lastCtx;
- while (next != NULL){
- _flush_cmd_buff(next);
- next = next->pPrev;
- }
-}
-void _init_all_contexes (VkvgDevice dev){
- VkvgContext next = dev->lastCtx;
- while (next != NULL){
- _init_cmd_buff (next);
- next = next->pPrev;
- }
-}
-
-void _create_pipeline_cache(VkvgDevice dev){
- VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO};
- VK_CHECK_RESULT(vkCreatePipelineCache(dev->vkDev, &pipelineCacheCreateInfo, NULL, &dev->pipelineCache));
-}
-void _setupRenderPass(VkvgDevice dev)
-{
- VkAttachmentDescription attColor = {
- .format = FB_COLOR_FORMAT,
- .samples = VKVG_SAMPLES,
- .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
- .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
- .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
- .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
- .finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
- VkAttachmentDescription attColorResolve = {
- .format = FB_COLOR_FORMAT,
- .samples = VK_SAMPLE_COUNT_1_BIT,
- .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
- .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
- .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
- .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
- .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
- .finalLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL };
- VkAttachmentDescription attDS = {
- .format = VK_FORMAT_S8_UINT,
- .samples = VKVG_SAMPLES,
- .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
- .storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
- .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
- .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
- .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
-/* VkAttachmentDescription attDSResolve = {
- .format = VK_FORMAT_S8_UINT,
- .samples = VK_SAMPLE_COUNT_1_BIT,
- .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
- .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
- .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
- .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
- .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
- .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };*/
- VkAttachmentDescription attachments[] = {attColor,attColorResolve,attDS};
- VkAttachmentReference colorRef = {
- .attachment = 0,
- .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
- VkAttachmentReference colorResolveRef = {
- .attachment = 1,
- .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
- VkAttachmentReference dsRef = {
- .attachment = 2,
- .layout = VK_IMAGE_LAYOUT_GENERAL };
- /*VkAttachmentReference dsResolveRef = {
- .attachment = 3,
- .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };*/
- VkSubpassDescription subpassDescription = { .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
- .colorAttachmentCount = 1,
- .pColorAttachments = &colorRef,
- .pResolveAttachments = &colorResolveRef,
- .pDepthStencilAttachment = &dsRef};
- VkSubpassDependency dep0 = {
- .srcSubpass = VK_SUBPASS_EXTERNAL,
- .dstSubpass = 0,
- .srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
- .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
- .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
- .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
- .dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT };
- VkSubpassDependency dep1 = {
- .srcSubpass = 0,
- .dstSubpass = VK_SUBPASS_EXTERNAL,
- .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
- .dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
- .srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
- .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
- .dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT };
-
- VkSubpassDependency dependencies[] = {dep0,dep1};
- VkRenderPassCreateInfo renderPassInfo = { .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
- .attachmentCount = 3,
- .pAttachments = attachments,
- .subpassCount = 1,
- .pSubpasses = &subpassDescription,
- .dependencyCount = 2,
- .pDependencies = dependencies };
-
- VK_CHECK_RESULT(vkCreateRenderPass(dev->vkDev, &renderPassInfo, NULL, &dev->renderPass));
-}
-
-void _setupPipelines(VkvgDevice dev)
-{
- VkGraphicsPipelineCreateInfo pipelineCreateInfo = { .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
- .renderPass = dev->renderPass };
-
- VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
- .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST };
-
- VkPipelineRasterizationStateCreateInfo rasterizationState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
- .polygonMode = VK_POLYGON_MODE_FILL,
- .cullMode = VK_CULL_MODE_NONE,
- .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
- .depthClampEnable = VK_FALSE,
- .rasterizerDiscardEnable = VK_FALSE,
- .depthBiasEnable = VK_FALSE,
- .lineWidth = 1.0f };
-
- VkPipelineColorBlendAttachmentState blendAttachmentState =
- { .colorWriteMask = 0x0, .blendEnable = VK_TRUE,
- .srcColorBlendFactor = VK_BLEND_FACTOR_ONE,
- .dstColorBlendFactor= VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
- .colorBlendOp = VK_BLEND_OP_ADD,
- .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
- .dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
- .alphaBlendOp = VK_BLEND_OP_ADD,
- };
-
- VkPipelineColorBlendStateCreateInfo colorBlendState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
- .attachmentCount = 1,
- .pAttachments = &blendAttachmentState };
-
- /*failOp,passOp,depthFailOp,compareOp, compareMask, writeMask, reference;*/
- VkStencilOpState clipingOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_INCREMENT_AND_CLAMP,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0x0,0xf,0};
- VkStencilOpState stencilOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_REPLACE,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0xf,0x0,0};
-
- VkPipelineDepthStencilStateCreateInfo dsStateCreateInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
- .depthTestEnable = VK_FALSE,
- .depthWriteEnable = VK_FALSE,
- .depthCompareOp = VK_COMPARE_OP_ALWAYS,
- .stencilTestEnable = VK_TRUE,
- .front = clipingOpState,
- .back = clipingOpState };
-
- VkDynamicState dynamicStateEnables[] = {
- VK_DYNAMIC_STATE_VIEWPORT,
- VK_DYNAMIC_STATE_SCISSOR,
- VK_DYNAMIC_STATE_STENCIL_REFERENCE,
- };
- VkPipelineDynamicStateCreateInfo dynamicState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
- .dynamicStateCount = 3,
- .pDynamicStates = dynamicStateEnables };
-
- VkPipelineViewportStateCreateInfo viewportState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
- .viewportCount = 1, .scissorCount = 1 };
-
- VkPipelineMultisampleStateCreateInfo multisampleState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
- .rasterizationSamples = VKVG_SAMPLES };
- if (VKVG_SAMPLES != VK_SAMPLE_COUNT_1_BIT){
- multisampleState.sampleShadingEnable = VK_TRUE;
- multisampleState.minSampleShading = 0.25f;
- multisampleState.alphaToCoverageEnable = VK_FALSE;
- multisampleState.alphaToOneEnable = VK_FALSE;
- }
- VkVertexInputBindingDescription vertexInputBinding = { .binding = 0,
- .stride = sizeof(Vertex),
- .inputRate = VK_VERTEX_INPUT_RATE_VERTEX };
-
- VkVertexInputAttributeDescription vertexInputAttributs[2] = {
- {0, 0, VK_FORMAT_R32G32_SFLOAT, 0},
- {1, 0, VK_FORMAT_R32G32B32_SFLOAT, sizeof(vec2)}
- };
-
- VkPipelineVertexInputStateCreateInfo vertexInputState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
- .vertexBindingDescriptionCount = 1,
- .pVertexBindingDescriptions = &vertexInputBinding,
- .vertexAttributeDescriptionCount = 2,
- .pVertexAttributeDescriptions = vertexInputAttributs };
-
- VkShaderModule modVert, modFrag;
- VkShaderModuleCreateInfo createInfo = { .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
- .pCode = triangle_vert_spv,
- .codeSize = triangle_vert_spv_len };
- VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modVert));
- createInfo.pCode = triangle_frag_spv;
- createInfo.codeSize = triangle_frag_spv_len;
- VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modFrag));
-
- VkPipelineShaderStageCreateInfo vertStage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
- .stage = VK_SHADER_STAGE_VERTEX_BIT,
- .module = modVert,
- .pName = "main",
- };
- VkPipelineShaderStageCreateInfo fragStage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
- .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
- .module = modFrag,
- .pName = "main",
- };
-
- // Use specialization constants to pass number of samples to the shader (used for MSAA resolve)
- VkSpecializationMapEntry specializationEntry = {
- .constantID = 0,
- .offset = 0,
- .size = sizeof(uint32_t)};
- uint32_t specializationData = VKVG_SAMPLES;
- VkSpecializationInfo specializationInfo = {
- .mapEntryCount = 1,
- .pMapEntries = &specializationEntry,
- .dataSize = sizeof(specializationData),
- .pData = &specializationData};
-
- VkPipelineShaderStageCreateInfo shaderStages[] = {vertStage,fragStage};
-
- pipelineCreateInfo.stageCount = 2;
- pipelineCreateInfo.pStages = shaderStages;
- pipelineCreateInfo.pVertexInputState = &vertexInputState;
- pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
- pipelineCreateInfo.pViewportState = &viewportState;
- pipelineCreateInfo.pRasterizationState = &rasterizationState;
- pipelineCreateInfo.pMultisampleState = &multisampleState;
- pipelineCreateInfo.pColorBlendState = &colorBlendState;
- pipelineCreateInfo.pDepthStencilState = &dsStateCreateInfo;
- pipelineCreateInfo.pDynamicState = &dynamicState;
- pipelineCreateInfo.layout = dev->pipelineLayout;
-
- VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineClipping));
-
- //dsStateCreateInfo.back.writeMask = dsStateCreateInfo.front.writeMask = 0;
- dsStateCreateInfo.back = dsStateCreateInfo.front = stencilOpState;
- blendAttachmentState.colorWriteMask=0xf;
- VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipeline));
-
- blendAttachmentState.alphaBlendOp = blendAttachmentState.colorBlendOp = VK_BLEND_OP_SUBTRACT;
- VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipeline_OP_SUB));
-
- inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
- rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
- VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineWired));
-
- rasterizationState.polygonMode = VK_POLYGON_MODE_FILL;
- inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
- VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineLineList));
-
- vkDestroyShaderModule(dev->vkDev, shaderStages[0].module, NULL);
- vkDestroyShaderModule(dev->vkDev, shaderStages[1].module, NULL);
-}
-
-void _createDescriptorSetLayout (VkvgDevice dev) {
-
- VkDescriptorSetLayoutBinding dsLayoutBinding =
- {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1,VK_SHADER_STAGE_FRAGMENT_BIT};
- VkDescriptorSetLayoutCreateInfo dsLayoutCreateInfo = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
- .bindingCount = 1,
- .pBindings = &dsLayoutBinding };
- VK_CHECK_RESULT(vkCreateDescriptorSetLayout(dev->vkDev, &dsLayoutCreateInfo, NULL, &dev->dslFont));
- VK_CHECK_RESULT(vkCreateDescriptorSetLayout(dev->vkDev, &dsLayoutCreateInfo, NULL, &dev->dslSrc));
-
- VkPushConstantRange pushConstantRange[] = {
- {VK_SHADER_STAGE_VERTEX_BIT,0,sizeof(push_constants)},
- //{VK_SHADER_STAGE_FRAGMENT_BIT,0,sizeof(push_constants)}
- };
- VkDescriptorSetLayout dsls[] = {dev->dslFont,dev->dslSrc};
-
- VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
- .pushConstantRangeCount = 1,
- .pPushConstantRanges = &pushConstantRange,
- .setLayoutCount = 2,
- .pSetLayouts = dsls };
- VK_CHECK_RESULT(vkCreatePipelineLayout(dev->vkDev, &pipelineLayoutCreateInfo, NULL, &dev->pipelineLayout));
-}
-
-
--- /dev/null
+#include "vkvg_device_internal.h"
+#include "vkvg_context_internal.h"
+#include "shaders.h"
+
+void _flush_all_contexes (VkvgDevice dev){
+ VkvgContext next = dev->lastCtx;
+ while (next != NULL){
+ _flush_cmd_buff(next);
+ next = next->pPrev;
+ }
+}
+void _init_all_contexes (VkvgDevice dev){
+ VkvgContext next = dev->lastCtx;
+ while (next != NULL){
+ _init_cmd_buff (next);
+ next = next->pPrev;
+ }
+}
+
+void _create_pipeline_cache(VkvgDevice dev){
+ VkPipelineCacheCreateInfo pipelineCacheCreateInfo = {.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO};
+ VK_CHECK_RESULT(vkCreatePipelineCache(dev->vkDev, &pipelineCacheCreateInfo, NULL, &dev->pipelineCache));
+}
+void _setupRenderPass(VkvgDevice dev)
+{
+ VkAttachmentDescription attColor = {
+ .format = FB_COLOR_FORMAT,
+ .samples = VKVG_SAMPLES,
+ .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
+ .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
+ .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
+ .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
+ .finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
+ VkAttachmentDescription attColorResolve = {
+ .format = FB_COLOR_FORMAT,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
+ .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ .finalLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL };
+ VkAttachmentDescription attDS = {
+ .format = VK_FORMAT_S8_UINT,
+ .samples = VKVG_SAMPLES,
+ .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
+ .storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
+ .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
+ .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
+ .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
+/* VkAttachmentDescription attDSResolve = {
+ .format = VK_FORMAT_S8_UINT,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
+ .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
+ .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };*/
+ VkAttachmentDescription attachments[] = {attColor,attColorResolve,attDS};
+ VkAttachmentReference colorRef = {
+ .attachment = 0,
+ .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
+ VkAttachmentReference colorResolveRef = {
+ .attachment = 1,
+ .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
+ VkAttachmentReference dsRef = {
+ .attachment = 2,
+ .layout = VK_IMAGE_LAYOUT_GENERAL };
+ /*VkAttachmentReference dsResolveRef = {
+ .attachment = 3,
+ .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };*/
+ VkSubpassDescription subpassDescription = { .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
+ .colorAttachmentCount = 1,
+ .pColorAttachments = &colorRef,
+ .pResolveAttachments = &colorResolveRef,
+ .pDepthStencilAttachment = &dsRef};
+ VkSubpassDependency dep0 = {
+ .srcSubpass = VK_SUBPASS_EXTERNAL,
+ .dstSubpass = 0,
+ .srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
+ .dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ .srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
+ .dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
+ .dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT };
+ VkSubpassDependency dep1 = {
+ .srcSubpass = 0,
+ .dstSubpass = VK_SUBPASS_EXTERNAL,
+ .srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ .dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
+ .srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
+ .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
+ .dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT };
+
+ VkSubpassDependency dependencies[] = {dep0,dep1};
+ VkRenderPassCreateInfo renderPassInfo = { .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
+ .attachmentCount = 3,
+ .pAttachments = attachments,
+ .subpassCount = 1,
+ .pSubpasses = &subpassDescription,
+ .dependencyCount = 2,
+ .pDependencies = dependencies };
+
+ VK_CHECK_RESULT(vkCreateRenderPass(dev->vkDev, &renderPassInfo, NULL, &dev->renderPass));
+}
+
+void _setupPipelines(VkvgDevice dev)
+{
+ VkGraphicsPipelineCreateInfo pipelineCreateInfo = { .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
+ .renderPass = dev->renderPass };
+
+ VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
+ .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST };
+
+ VkPipelineRasterizationStateCreateInfo rasterizationState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
+ .polygonMode = VK_POLYGON_MODE_FILL,
+ .cullMode = VK_CULL_MODE_NONE,
+ .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
+ .depthClampEnable = VK_FALSE,
+ .rasterizerDiscardEnable = VK_FALSE,
+ .depthBiasEnable = VK_FALSE,
+ .lineWidth = 1.0f };
+
+ VkPipelineColorBlendAttachmentState blendAttachmentState =
+ { .colorWriteMask = 0x0, .blendEnable = VK_TRUE,
+ .srcColorBlendFactor = VK_BLEND_FACTOR_ONE,
+ .dstColorBlendFactor= VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+ .colorBlendOp = VK_BLEND_OP_ADD,
+ .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
+ .dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
+ .alphaBlendOp = VK_BLEND_OP_ADD,
+ };
+
+ VkPipelineColorBlendStateCreateInfo colorBlendState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
+ .attachmentCount = 1,
+ .pAttachments = &blendAttachmentState };
+
+ /*failOp,passOp,depthFailOp,compareOp, compareMask, writeMask, reference;*/
+ VkStencilOpState clipingOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_INCREMENT_AND_CLAMP,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0x0,0xf,0};
+ VkStencilOpState stencilOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_REPLACE,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0xf,0x0,0};
+
+ VkPipelineDepthStencilStateCreateInfo dsStateCreateInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
+ .depthTestEnable = VK_FALSE,
+ .depthWriteEnable = VK_FALSE,
+ .depthCompareOp = VK_COMPARE_OP_ALWAYS,
+ .stencilTestEnable = VK_TRUE,
+ .front = clipingOpState,
+ .back = clipingOpState };
+
+ VkDynamicState dynamicStateEnables[] = {
+ VK_DYNAMIC_STATE_VIEWPORT,
+ VK_DYNAMIC_STATE_SCISSOR,
+ VK_DYNAMIC_STATE_STENCIL_REFERENCE,
+ };
+ VkPipelineDynamicStateCreateInfo dynamicState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
+ .dynamicStateCount = 3,
+ .pDynamicStates = dynamicStateEnables };
+
+ VkPipelineViewportStateCreateInfo viewportState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
+ .viewportCount = 1, .scissorCount = 1 };
+
+ VkPipelineMultisampleStateCreateInfo multisampleState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
+ .rasterizationSamples = VKVG_SAMPLES };
+ if (VKVG_SAMPLES != VK_SAMPLE_COUNT_1_BIT){
+ multisampleState.sampleShadingEnable = VK_TRUE;
+ multisampleState.minSampleShading = 0.25f;
+ multisampleState.alphaToCoverageEnable = VK_FALSE;
+ multisampleState.alphaToOneEnable = VK_FALSE;
+ }
+ VkVertexInputBindingDescription vertexInputBinding = { .binding = 0,
+ .stride = sizeof(Vertex),
+ .inputRate = VK_VERTEX_INPUT_RATE_VERTEX };
+
+ VkVertexInputAttributeDescription vertexInputAttributs[2] = {
+ {0, 0, VK_FORMAT_R32G32_SFLOAT, 0},
+ {1, 0, VK_FORMAT_R32G32B32_SFLOAT, sizeof(vec2)}
+ };
+
+ VkPipelineVertexInputStateCreateInfo vertexInputState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+ .vertexBindingDescriptionCount = 1,
+ .pVertexBindingDescriptions = &vertexInputBinding,
+ .vertexAttributeDescriptionCount = 2,
+ .pVertexAttributeDescriptions = vertexInputAttributs };
+
+ VkShaderModule modVert, modFrag;
+ VkShaderModuleCreateInfo createInfo = { .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
+ .pCode = triangle_vert_spv,
+ .codeSize = triangle_vert_spv_len };
+ VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modVert));
+ createInfo.pCode = triangle_frag_spv;
+ createInfo.codeSize = triangle_frag_spv_len;
+ VK_CHECK_RESULT(vkCreateShaderModule(dev->vkDev, &createInfo, NULL, &modFrag));
+
+ VkPipelineShaderStageCreateInfo vertStage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
+ .stage = VK_SHADER_STAGE_VERTEX_BIT,
+ .module = modVert,
+ .pName = "main",
+ };
+ VkPipelineShaderStageCreateInfo fragStage = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
+ .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
+ .module = modFrag,
+ .pName = "main",
+ };
+
+ // Use specialization constants to pass number of samples to the shader (used for MSAA resolve)
+ VkSpecializationMapEntry specializationEntry = {
+ .constantID = 0,
+ .offset = 0,
+ .size = sizeof(uint32_t)};
+ uint32_t specializationData = VKVG_SAMPLES;
+ VkSpecializationInfo specializationInfo = {
+ .mapEntryCount = 1,
+ .pMapEntries = &specializationEntry,
+ .dataSize = sizeof(specializationData),
+ .pData = &specializationData};
+
+ VkPipelineShaderStageCreateInfo shaderStages[] = {vertStage,fragStage};
+
+ pipelineCreateInfo.stageCount = 2;
+ pipelineCreateInfo.pStages = shaderStages;
+ pipelineCreateInfo.pVertexInputState = &vertexInputState;
+ pipelineCreateInfo.pInputAssemblyState = &inputAssemblyState;
+ pipelineCreateInfo.pViewportState = &viewportState;
+ pipelineCreateInfo.pRasterizationState = &rasterizationState;
+ pipelineCreateInfo.pMultisampleState = &multisampleState;
+ pipelineCreateInfo.pColorBlendState = &colorBlendState;
+ pipelineCreateInfo.pDepthStencilState = &dsStateCreateInfo;
+ pipelineCreateInfo.pDynamicState = &dynamicState;
+ pipelineCreateInfo.layout = dev->pipelineLayout;
+
+ VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineClipping));
+
+ //dsStateCreateInfo.back.writeMask = dsStateCreateInfo.front.writeMask = 0;
+ dsStateCreateInfo.back = dsStateCreateInfo.front = stencilOpState;
+ blendAttachmentState.colorWriteMask=0xf;
+ VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipeline));
+
+ blendAttachmentState.alphaBlendOp = blendAttachmentState.colorBlendOp = VK_BLEND_OP_SUBTRACT;
+ VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipeline_OP_SUB));
+
+ inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
+ rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
+ VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineWired));
+
+ rasterizationState.polygonMode = VK_POLYGON_MODE_FILL;
+ inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
+ VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineLineList));
+
+ vkDestroyShaderModule(dev->vkDev, shaderStages[0].module, NULL);
+ vkDestroyShaderModule(dev->vkDev, shaderStages[1].module, NULL);
+}
+
+void _createDescriptorSetLayout (VkvgDevice dev) {
+
+ VkDescriptorSetLayoutBinding dsLayoutBinding =
+ {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1,VK_SHADER_STAGE_FRAGMENT_BIT};
+ VkDescriptorSetLayoutCreateInfo dsLayoutCreateInfo = { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
+ .bindingCount = 1,
+ .pBindings = &dsLayoutBinding };
+ VK_CHECK_RESULT(vkCreateDescriptorSetLayout(dev->vkDev, &dsLayoutCreateInfo, NULL, &dev->dslFont));
+ VK_CHECK_RESULT(vkCreateDescriptorSetLayout(dev->vkDev, &dsLayoutCreateInfo, NULL, &dev->dslSrc));
+
+ VkPushConstantRange pushConstantRange[] = {
+ {VK_SHADER_STAGE_VERTEX_BIT,0,sizeof(push_constants)},
+ //{VK_SHADER_STAGE_FRAGMENT_BIT,0,sizeof(push_constants)}
+ };
+ VkDescriptorSetLayout dsls[] = {dev->dslFont,dev->dslSrc};
+
+ VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
+ .pushConstantRangeCount = 1,
+ .pPushConstantRanges = &pushConstantRange,
+ .setLayoutCount = 2,
+ .pSetLayouts = dsls };
+ VK_CHECK_RESULT(vkCreatePipelineLayout(dev->vkDev, &pipelineLayoutCreateInfo, NULL, &dev->pipelineLayout));
+}
+
+void _wait_device_fence (VkvgDevice dev) {
+ vkWaitForFences (dev->vkDev, 1, &dev->fence, VK_TRUE, UINT64_MAX);
+ vkResetFences (dev->vkDev, 1, &dev->fence);
+}
VkvgContext lastCtx; //double linked list last elmt
}vkvg_device;
-void _flush_all_contexes (VkvgDevice dev);
-void _init_all_contexes (VkvgDevice dev);
+void _create_pipeline_cache (VkvgDevice dev);
+void _setupRenderPass (VkvgDevice dev);
+void _setupPipelines (VkvgDevice dev);
+void _createDescriptorSetLayout (VkvgDevice dev);
+void _flush_all_contexes (VkvgDevice dev);
+void _init_all_contexes (VkvgDevice dev);
+void _wait_device_fence (VkvgDevice dev);
#endif
int defaultFontCharSize = 12<<6;
void _init_fonts_cache (VkvgDevice dev){
- _font_cache_t* cache = (_font_cache_t*)malloc(sizeof(_font_cache_t));
- memset (cache, 0, sizeof(_font_cache_t));
+ _font_cache_t* cache = (_font_cache_t*)calloc(1, sizeof(_font_cache_t));
cache->config = FcInitLoadConfigAndFonts();
VkvgContext next = dev->lastCtx;
while (next != NULL){
- _update_source_descriptor_set (next);
+ _update_descriptor_set (next, next->source, next->dsSrc);
next = next->pPrev;
}
#include "vkvg_surface_internal.h"
#include "vkvg_device_internal.h"
+#include "vkvg_context_internal.h"
+#define STB_IMAGE_IMPLEMENTATION
+#include "stb_image.h"
void _clear_stencil (VkvgSurface surf)
{
VkvgDevice dev = surf->dev;
VkCommandBuffer cmd = dev->cmd;
- vkWaitForFences (dev->vkDev, 1, &dev->fence, VK_TRUE, UINT64_MAX);
- vkResetFences (dev->vkDev, 1, &dev->fence);
+ _wait_device_fence (dev);
vkh_cmd_begin (cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
vkh_cmd_submit (dev->queue, &cmd, dev->fence);
}
-VkvgSurface vkvg_surface_create(VkvgDevice dev, uint32_t width, uint32_t height){
- VkvgSurface surf = (vkvg_surface*)calloc(1,sizeof(vkvg_surface));
-
- surf->dev = dev;
- surf->width = width;
- surf->height = height;
-
- surf->img = vkh_image_create(dev,FB_COLOR_FORMAT,width,height,VK_IMAGE_TILING_LINEAR,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+void _init_surface (VkvgSurface surf) {
+ surf->format = FB_COLOR_FORMAT;//force bgra internally
+ surf->img = vkh_image_create(surf->dev,surf->format,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);
- surf->imgMS = vkh_image_ms_create(dev,FB_COLOR_FORMAT,VKVG_SAMPLES,width,height,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ surf->imgMS = vkh_image_ms_create(surf->dev,surf->format,VKVG_SAMPLES,surf->width,surf->height,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
- surf->stencilMS = vkh_image_ms_create(dev,VK_FORMAT_S8_UINT,VKVG_SAMPLES,width,height,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ surf->stencilMS = vkh_image_ms_create(surf->dev,VK_FORMAT_S8_UINT,VKVG_SAMPLES,surf->width,surf->height,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
vkh_image_create_descriptor(surf->img, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
vkh_image_get_view (surf->stencilMS),
};
VkFramebufferCreateInfo frameBufferCreateInfo = { .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
- .renderPass = dev->renderPass,
+ .renderPass = surf->dev->renderPass,
.attachmentCount = 3,
.pAttachments = attachments,
- .width = width,
- .height = height,
+ .width = surf->width,
+ .height = surf->height,
.layers = 1 };
VK_CHECK_RESULT(vkCreateFramebuffer(surf->dev->vkDev, &frameBufferCreateInfo, NULL, &surf->fb));
_clear_stencil(surf);
+}
+VkvgSurface vkvg_surface_create(VkvgDevice dev, uint32_t width, uint32_t height){
+ VkvgSurface surf = (vkvg_surface*)calloc(1,sizeof(vkvg_surface));
+
+ surf->dev = dev;
+ surf->width = width;
+ surf->height = height;
+
+ _init_surface (surf);
+
+ return surf;
+}
+
+VkvgSurface vkvg_surface_create_from_image (VkvgDevice dev, const char* filePath) {
+ int w = 0,
+ h = 0,
+ channels = 0;
+ unsigned char *img = stbi_load(filePath, &w, &h, &channels, 4);//force 4 components per pixel
+ if (img == NULL){
+ fprintf (stderr, "Could not load texture from %s, %s\n", filePath, stbi_failure_reason());
+ return NULL;
+ }
+
+ VkvgSurface surf = (vkvg_surface*)calloc(1,sizeof(vkvg_surface));
+
+ surf->dev = dev;
+ surf->width = w;
+ surf->height = h;
+
+ _init_surface (surf);
+
+ uint32_t imgSize = w * h * 4;
+ VkImageSubresourceLayers imgSubResLayers = {VK_IMAGE_ASPECT_COLOR_BIT,0,0,1};
+ //original format image
+ VkhImage stagImg= vkh_image_create (surf->dev,VK_FORMAT_R8G8B8A8_UNORM,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+ VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);
+ //bgra bliting target
+ VkhImage tmpImg = vkh_image_create (surf->dev,surf->format,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);
+ vkh_image_create_descriptor (tmpImg, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT,
+ VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
+ //staging buffer
+ VkhBuffer buff = vkh_buffer_create (dev, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, imgSize);
+ VK_CHECK_RESULT (vkh_buffer_map (buff));
+ memcpy (vkh_buffer_get_mapped_pointer (buff), img, imgSize);
+
+ VkCommandBuffer cmd = dev->cmd;
+
+ _wait_device_fence (dev);
+
+ vkh_cmd_begin (cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
+ vkh_image_set_layout (cmd, stagImg, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
+
+
+ VkBufferImageCopy bufferCopyRegion = { .imageSubresource = imgSubResLayers,
+ .imageExtent = {surf->width,surf->height,1}};
+
+ vkCmdCopyBufferToImage(cmd, vkh_buffer_get_vkbuffer (buff),
+ vkh_image_get_vkimage (stagImg), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &bufferCopyRegion);
+
+ vkh_image_set_layout (cmd, stagImg, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
+ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
+ vkh_image_set_layout (cmd, tmpImg, VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
+ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
+
+ VkImageBlit blit = {
+ .srcSubresource = imgSubResLayers,
+ .srcOffsets[1] = {surf->width, surf->height, 1},
+ .dstSubresource = imgSubResLayers,
+ .dstOffsets[1] = {surf->width, surf->height, 1},
+ };
+ vkCmdBlitImage (cmd,
+ vkh_image_get_vkimage (stagImg), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
+ vkh_image_get_vkimage (tmpImg), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_LINEAR);
+
+ vkh_cmd_end (cmd);
+ vkh_cmd_submit (dev->queue, &cmd, dev->fence);
+
+ _wait_device_fence (dev);
+
+ vkh_buffer_unmap (buff);
+ vkh_buffer_destroy (buff);
+ vkh_image_destroy (stagImg);
+
+ //create tmp context with rendering pipeline to create the multisample img
+ VkvgContext ctx = vkvg_create (surf);
+ vec4 srcRect = {0,0,surf->width,surf->height};
+ ctx->pushConsts.source = srcRect;
+ ctx->pushConsts.srcType = VKVG_SRC_PATTERN;
+ vkCmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout,
+ VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(push_constants), &ctx->pushConsts);
+
+ _update_descriptor_set (ctx, tmpImg, ctx->dsSrc);
+
+ vkvg_paint (ctx);
+ vkvg_destroy (ctx);
+ vkh_image_destroy (tmpImg);
return surf;
}
VkvgDevice dev;
uint32_t width;
uint32_t height;
+ VkFormat format;
VkFramebuffer fb;
VkhImage img;
VkhImage imgMS;
-#define STB_IMAGE_IMPLEMENTATION
-#include "stb_image.h"
+//#define STB_IMAGE_IMPLEMENTATION
+//#include "stb_image.h"
#include "vke.h"
//#include "compute.h"
return VK_SAMPLE_COUNT_1_BIT;
}
-void vkengine_DumpInfos (VkEngine* e){
+void vkengine_dump_Infos (VkEngine* e){
printf("max samples = %d\n", getMaxUsableSampleCount(e->gpu_props.limits.framebufferColorSampleCounts));
printf("max tex2d size = %d\n", e->gpu_props.limits.maxImageDimension2D);
printf("max tex array layers = %d\n", e->gpu_props.limits.maxImageArrayLayers);
vkvg_fill(ctx);
}
+void vkvg_test_curves (VkvgContext ctx) {
+ vkvg_set_rgba (ctx, 1.0,1.0,1.0,1.0);
+ vkvg_set_linewidth(ctx, 10);
+
+ /*
+ vkvg_move_to (ctx, 100, 400);
+ vkvg_curve_to (ctx, 100, 100, 600,700,600,400);
+ */
+ //vkvg_move_to (ctx, 100, 100);
+ //vkvg_curve_to (ctx, 1000, 100, 100, 800, 1000, 800);
+ vkvg_move_to (ctx, 100, 100);
+ vkvg_curve_to (ctx, 1000, 500, 700, 500, 700, 100);
+
+ vkvg_stroke (ctx);
+}
+
void vkvg_rectangle(VkvgContext ctx, float x, float y, float width, float height){
vkvg_move_to(ctx,x,y);
vkvg_line_to(ctx,x+width,y);
vkvg_stroke(ctx);
}
-
-
-int main(int argc, char *argv[]) {
- dumpLayerExts();
-
- VkEngine e = {};
-
- EngineInit(&e);
-
- device = vkvg_device_create(e.phy, e.dev, e.renderer.queue, e.renderer.qFam);
-
- surf = vkvg_surface_create (device,1024,800);
-
- vkeCheckPhyPropBlitSource (&e);
- glfwSetKeyCallback(e.renderer.window, key_callback);
-
- vke_swapchain_create(&e);
-
- VkvgSurface surf2 = vkvg_surface_create (device,1024,800);;
- VkvgContext ctx = vkvg_create(surf2);
- VkvgContext ctx2 = vkvg_create(surf);
- vkvg_destroy(ctx2);
- /*vkvg_destroy(ctx);
- ctx = vkvg_create(surf);
- vkvg_destroy(ctx);
-
-
- ctx = vkvg_create(surf);*/
- vkvg_set_rgba(ctx,0.5,0,0,1);
- vkvg_rectangle(ctx,0,0,1024,800);
- vkvg_fill (ctx);
-
- vkvg_set_rgba(ctx,1,1,0,1);
- vkvg_rectangle(ctx,200,200,400,400);
- vkvg_fill (ctx);
- vkvg_set_rgba(ctx,0,0,1,1);
- vkvg_rectangle(ctx,300,300,400,400);
- vkvg_stroke(ctx);
- //vkvg_clip_preserve(ctx);
- //vkvg_clip(ctx);
- //vkvg_fill_preserve(ctx);
- //vkvg_set_rgba(ctx,1,0,1,1);
-
-
- //vkvg_select_font_face(ctx, "/usr/local/share/fonts/DroidSansMono.ttf");
-
- //vkvg_select_font_face(ctx, "/usr/share/fonts/truetype/unifont/unifont.ttf");
-
+void test_text (VkvgContext ctx) {
int size = 19;
int penY = 50;
int penX = 10;
/*vkvg_rectangle(ctx,30,0,100,400);
vkvg_clip(ctx);*/
+ //vkvg_select_font_face(ctx, "/usr/local/share/fonts/DroidSansMono.ttf");
+ //vkvg_select_font_face(ctx, "/usr/share/fonts/truetype/unifont/unifont.ttf");
+
vkvg_set_font_size(ctx,size-10);
vkvg_select_font_face(ctx, "droid");
vkvg_move_to(ctx, penX,penY);
vkvg_move_to(ctx, penX,penY);
vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
penY+=size;
+ vkvg_move_to(ctx, penX,penY);
+ vkvg_show_text (ctx,"this is a test");
+ penY+=size;
+ vkvg_move_to(ctx, penX,penY);
+ vkvg_show_text (ctx,"this is another test to see if label is working");
+ penY+=size;
vkvg_select_font_face(ctx, "mono");
vkvg_move_to(ctx, penX,penY);
vkvg_show_text (ctx,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
penY+=size;
+ vkvg_move_to(ctx, 80,400);
+ vkvg_show_text (ctx,"Ленивый рыжий кот");
+
+
+ /*vkvg_move_to(ctx, 150,250);
+ vkvg_show_text (ctx,"test string é€");
+ vkvg_move_to(ctx, 150,300);
+ vkvg_show_text (ctx,"كسول الزنجبيل القط");
+ vkvg_move_to(ctx, 150,350);
+ vkvg_show_text (ctx,"懶惰的姜貓");*/
//vkvg_show_text (ctx,"ABCDABCD");
//vkvg_show_text (ctx,"j");
+}
- vkvg_test_fill(ctx);
+void test_img_surface (VkvgContext ctx) {
+ VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "/mnt/data/images/blason.png");
+ //VkvgSurface imgSurf = vkvg_surface_create_from_image(device, "/mnt/data/images/2000px-Tux.svg.png");
+ //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_paint(ctx);
+ vkvg_flush(ctx);
+ vkvg_surface_destroy(imgSurf);
+}
- //vkvg_rectangle(ctx,300,300,400,400);
- //vkvg_clip(ctx);
+int main(int argc, char *argv[]) {
+ dumpLayerExts();
+ VkEngine e = {};
- vkvg_test_stroke(ctx);
+ EngineInit(&e);
- //vkvg_reset_clip(ctx);
- /*vkvg_set_rgba(ctx,1.0,0.0,0.0,0.1);
- vkvg_move_to(ctx, 80,400);
- vkvg_show_text (ctx,"Ленивый рыжий кот");*/
+ device = vkvg_device_create(e.phy, e.dev, e.renderer.queue, e.renderer.qFam);
+ surf = vkvg_surface_create (device,1024,800);
- /*vkvg_move_to(ctx, 150,250);
- vkvg_show_text (ctx,"test string é€");
- vkvg_move_to(ctx, 150,300);
- vkvg_show_text (ctx,"كسول الزنجبيل القط");
- vkvg_move_to(ctx, 150,350);
- vkvg_show_text (ctx,"懶惰的姜貓");*/
+ vkeCheckPhyPropBlitSource (&e);
+ glfwSetKeyCallback(e.renderer.window, key_callback);
+ vke_swapchain_create(&e);
- vkvg_destroy(ctx);
+ VkvgSurface surf2 = vkvg_surface_create (device,1024,800);;
+ VkvgContext ctx = vkvg_create(surf);
+
+ vkvg_set_rgba(ctx,0.01,0.01,0.1,1);
+ //vkvg_paint(ctx);
+ vkvg_rectangle(ctx,0,0,1024,800);
+ vkvg_fill (ctx);
- ctx = vkvg_create(surf);
+ vkvg_test_fill(ctx);
+ vkvg_test_stroke(ctx);
+ vkvg_test_curves(ctx);
+ test_text(ctx);
- vkvg_set_rgba(ctx,0.0,0.0,0.3,1);
- vkvg_paint(ctx);
+ //test_img_surface(ctx);
- vkvg_set_source_surface(ctx, surf2, 0, 0);
+ //vkvg_destroy(ctx);
+ //ctx = vkvg_create(surf);
- //vkvg_set_rgba(ctx,0.0,1.0,1.0,1);
- //vkvg_set_rgba(ctx,1.0,1.0,0,1);
- //vkvg_rectangle(ctx,0,0,400,400);
+ //vkvg_set_rgba(ctx,0.0,0.0,0.0,1);
+ //vkvg_paint(ctx);
- //vkvg_fill (ctx);
- vkvg_paint(ctx);
+ //vkvg_set_source_surface(ctx, surf2, 0, 0);
+ //vkvg_paint(ctx);
vkvg_destroy(ctx);
-Subproject commit e5333027ccbb7bb1c1e11e1164329530eac1da96
+Subproject commit 11a3c034e013251ae11e39d1bce38119b376db47