From 22779208ca8dafd8a995573afd428fb40dac9cef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Fri, 20 Apr 2018 23:39:09 +0200 Subject: [PATCH] arc neg, set solid black as default source in push csts --- src/vkvg_context.c | 75 ++++++++++++++++++++++--------------- src/vkvg_context_internal.c | 10 +---- tests/test1.c | 28 ++++++++++++++ 3 files changed, 75 insertions(+), 38 deletions(-) diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 3939173..45c055b 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -45,7 +45,7 @@ VkvgContext vkvg_create(VkvgSurface surf) ctx->pSurf = surf; push_constants pc = { - {}, + {0,0,0,1}, {(float)ctx->pSurf->width,(float)ctx->pSurf->height}, VKVG_PATTERN_TYPE_SOLID, 0, @@ -209,7 +209,7 @@ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, floa }else _set_current_point(ctx, v); - if (a2 - a1 == 0) + if (a2 == a1) return; if (_current_path_is_empty (ctx)) @@ -232,7 +232,41 @@ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, floa _add_point_cp_update(ctx,v.x,v.y); } void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2) { + while (a2 > a1) + a2 -= 2*M_PI; + vec2 v = {cos(a1)*radius + xc, sin(a1)*radius + yc}; + + float step = M_PI/radius; + float a = a1; + + if (ctx->curPosExists){ + vkvg_line_to(ctx, v.x, v.y); + a+=step; + }else + _set_current_point(ctx, v); + + if (a2 == a1) + return; + + if (_current_path_is_empty (ctx)) + _start_sub_path (ctx); + + while(a > a2){ + v.x = cos(a)*radius + xc; + v.y = sin(a)*radius + yc; + _add_point (ctx,v.x,v.y); + a-=step; + } + + a = a2; + vec2 lastP = v; + v.x = cos(a)*radius + xc; + v.y = sin(a)*radius + yc; + if (vec2_equ (v,lastP)) + _set_current_point(ctx, v); + else + _add_point_cp_update(ctx,v.x,v.y); } void vkvg_rel_move_to (VkvgContext ctx, float x, float y) { @@ -523,42 +557,23 @@ void vkvg_paint (VkvgContext ctx){ void vkvg_set_source_rgba (VkvgContext ctx, float r, float g, float b, float a) { - if (ctx->pushConsts.patternType == VKVG_PATTERN_TYPE_SURFACE){ - _flush_cmd_buff (ctx); - _reset_src_descriptor_set (ctx); - _init_cmd_buff (ctx); - } + uint32_t lastPat = ctx->pushConsts.patternType; vec4 c = {r,g,b,a}; ctx->pushConsts.source = c; ctx->pushConsts.patternType = VKVG_PATTERN_TYPE_SOLID; - _update_push_constants (ctx); + if (lastPat == VKVG_PATTERN_TYPE_SURFACE){ + _flush_cmd_buff (ctx); + _reset_src_descriptor_set (ctx); + _init_cmd_buff (ctx);//push csts updated by init + }else + _update_push_constants (ctx); ctx->curRGBA.x = r; ctx->curRGBA.y = g; ctx->curRGBA.z = b; ctx->curRGBA.w = a; - /* - _flush_cmd_buff(ctx); - - vkh_cmd_begin (ctx->cmd,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); - - VkClearColorValue clr = {r,g,b,a}; - VkImageSubresourceRange range = {VK_IMAGE_ASPECT_COLOR_BIT,0,1,0,1}; - - set_image_layout (ctx->cmd, ctx->source->image, VK_IMAGE_ASPECT_COLOR_BIT, - VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); - vkCmdClearColorImage (ctx->cmd, ctx->source->image,VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,&clr,1,&range); - set_image_layout (ctx->cmd, ctx->source->image, VK_IMAGE_ASPECT_COLOR_BIT, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); - vkh_cmd_end (ctx->cmd); - - _submit_wait_and_reset_cmd (ctx); - _init_cmd_buff (ctx); - */ } void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y){ _flush_cmd_buff(ctx); @@ -580,12 +595,12 @@ void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y } _update_descriptor_set (ctx, ctx->source, ctx->dsSrc); - _init_cmd_buff (ctx); vec4 srcRect = {x,y,surf->width,surf->height}; ctx->pushConsts.source = srcRect; ctx->pushConsts.patternType = VKVG_PATTERN_TYPE_SURFACE; - _update_push_constants (ctx); + + _init_cmd_buff (ctx); } void vkvg_set_source (VkvgContext ctx, VkvgPattern pat){ if (pat->type == VKVG_PATTERN_TYPE_SOLID){ diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index f2ea584..dee4686 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -214,14 +214,6 @@ void _init_cmd_buff (VkvgContext ctx){ VkRect2D scissor = {{0,0},{ctx->pSurf->width,ctx->pSurf->height}}; vkCmdSetScissor(ctx->cmd, 0, 1, &scissor); - /*push_constants pc = { - {(float)ctx->pSurf->width,(float)ctx->pSurf->height}, - {2.0f/(float)ctx->pSurf->width,2.0f/(float)ctx->pSurf->height}, - {-1.f,-1.f}, - };*/ - - _update_push_constants (ctx); - VkDescriptorSet dss[] = {ctx->dsFont,ctx->dsSrc,ctx->dsGrad}; vkCmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineLayout, 0, 3, dss, 0, NULL); @@ -230,6 +222,8 @@ void _init_cmd_buff (VkvgContext ctx){ vkCmdBindIndexBuffer(ctx->cmd, ctx->indices.buffer, 0, VK_INDEX_TYPE_UINT32); vkCmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipeline); vkCmdSetStencilReference(ctx->cmd,VK_STENCIL_FRONT_AND_BACK, ctx->stencilRef); + + _update_push_constants (ctx); } inline void _update_push_constants (VkvgContext ctx) { vkCmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout, diff --git a/tests/test1.c b/tests/test1.c index f9dc0fc..f9c1157 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -798,6 +798,32 @@ void multi_test1 () { vkvg_surface_destroy(surf2); } +void cairo_print_arc_neg (VkvgContext cr){ + float xc = 128.0; + float yc = 128.0; + float radius = 100.0; + float angle1 = 45.0 * (M_PI/180.0); /* angles are specified */ + float angle2 = 180.0 * (M_PI/180.0); /* in radians */ + + vkvg_set_source_rgba(cr, 0, 0, 0, 1); + vkvg_set_line_width (cr, 10.0); + vkvg_arc_negative (cr, xc, yc, radius, angle1, angle2); + vkvg_stroke (cr); + + /* draw helping lines */ + vkvg_set_source_rgba (cr, 1, 0.2, 0.2, 0.6); + vkvg_set_line_width (cr, 6.0); + + vkvg_arc (cr, xc, yc, 10.0, 0, 2*M_PI); + vkvg_fill (cr); + + vkvg_arc (cr, xc, yc, radius, angle1, angle1); + vkvg_line_to (cr, xc, yc); + vkvg_arc (cr, xc, yc, radius, angle2, angle2); + //vkvg_line_to (cr, xc, yc); + vkvg_stroke (cr); + +} void cairo_print_arc (VkvgContext cr) { float xc = 128.0; float yc = 128.0; @@ -828,6 +854,8 @@ void cairo_tests () { vkvg_set_source_rgba(ctx,0.7,0.7,0.7,1); vkvg_paint(ctx); cairo_print_arc(ctx); + vkvg_translate(ctx,200,0); + cairo_print_arc_neg(ctx); vkvg_destroy(ctx); } -- 2.47.3