From: Jean-Philippe Bruyère Date: Mon, 2 Sep 2019 02:43:52 +0000 (+0200) Subject: compute bounds with current matrix for scissor, use for paint, not clipping X-Git-Tag: v0.1-alpha~64 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=e9122a2a77847d471e640bb191cac4bf48c65963;p=jp%2Fvkvg.git compute bounds with current matrix for scissor, use for paint, not clipping --- diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 2e4c641..1c80d37 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -513,7 +513,7 @@ void vkvg_clip_preserve (VkvgContext ctx){ CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT); CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_ALL_BIT); } - _draw_full_screen_quad(ctx); + _draw_full_screen_quad(ctx,false); //should test current operator to bind correct pipeline _bind_draw_pipeline (ctx); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); @@ -534,7 +534,7 @@ void vkvg_fill_preserve (VkvgContext ctx){ _poly_fill (ctx); _bind_draw_pipeline (ctx); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT); - _draw_full_screen_quad(ctx); + _draw_full_screen_quad(ctx,true); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); }else{ //CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT); @@ -695,7 +695,7 @@ void vkvg_stroke_preserve (VkvgContext ctx) } void vkvg_paint (VkvgContext ctx){ _check_cmd_buff_state(ctx); - _draw_full_screen_quad(ctx); + _draw_full_screen_quad(ctx,true); } inline void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) { vkvg_set_source_rgba (ctx, r, g, b, 1); @@ -842,7 +842,7 @@ void vkvg_save (VkvgContext ctx){ CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, curSaveBit); - _draw_full_screen_quad(ctx); + _draw_full_screen_quad(ctx,false); _bind_draw_pipeline (ctx); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); @@ -900,7 +900,7 @@ void vkvg_restore (VkvgContext ctx){ CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, curSaveBit); CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); - _draw_full_screen_quad(ctx); + _draw_full_screen_quad(ctx,false); _bind_draw_pipeline (ctx); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 5a01542..7290d99 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -104,12 +104,17 @@ inline bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath){ return ctx->pathes[ptrPath] & PATH_CLOSED_BIT; } void _resetMinMax (VkvgContext ctx) { - ctx->xMin = FLT_MAX; - ctx->xMax = FLT_MIN; - ctx->yMin = FLT_MAX; - ctx->yMax = FLT_MIN; + ctx->xMin = ctx->yMin = FLT_MAX; + ctx->xMax = ctx->yMax = FLT_MIN; } void _add_point (VkvgContext ctx, float x, float y){ + ctx->points[ctx->pointCount] = (vec2){x,y}; + ctx->pointCount++; + + //bounds are computed here to scissor the painting operation + //that speed up fill drastically. + vkvg_matrix_transform_point (&ctx->pushConsts.mat, &x, &y); + if (x < ctx->xMin) ctx->xMin = x; if (x > ctx->xMax) @@ -118,12 +123,6 @@ void _add_point (VkvgContext ctx, float x, float y){ ctx->yMin = y; if (y > ctx->yMax) ctx->yMax = y; - ctx->points[ctx->pointCount] = (vec2){x,y}; - ctx->pointCount++; -} -void _add_point_vec2(VkvgContext ctx, vec2 v){ - ctx->points[ctx->pointCount] = v; - ctx->pointCount++; } float _normalizeAngle(float a) { @@ -980,13 +979,18 @@ void _fill_ec (VkvgContext ctx){ static const uint32_t one = 1; static const uint32_t zero = 0; -void _draw_full_screen_quad (VkvgContext ctx) { - VkRect2D r = {ctx->xMin, ctx->yMin, ctx->xMax - ctx->xMin, ctx->yMax - ctx->xMin}; - CmdSetScissor(ctx->cmd, 0, 1, &r); +void _draw_full_screen_quad (VkvgContext ctx, bool useScissor) { + if (ctx->xMin < 0 || ctx->yMin < 0) + useScissor = false; + if (useScissor && ctx->xMin < FLT_MAX) { + VkRect2D r = {ctx->xMin, ctx->yMin, ctx->xMax - ctx->xMin, ctx->yMax - ctx->yMin}; + CmdSetScissor(ctx->cmd, 0, 1, &r); + } CmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 28, 4,&one); CmdDraw (ctx->cmd,3,1,0,0); CmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 28, 4,&zero); - CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds); + if (useScissor && ctx->xMin < FLT_MAX) + CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds); } diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index fd08c70..4cadb57 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -31,7 +31,7 @@ #define VKVG_PTS_SIZE 4096 #define VKVG_VBO_SIZE 4096 * 8 #define VKVG_IBO_SIZE VKVG_VBO_SIZE * 6 -#define VKVG_PATHES_SIZE 16 +#define VKVG_PATHES_SIZE 32 #define VKVG_ARRAY_THRESHOLD 4 typedef struct{ @@ -166,13 +166,12 @@ float _normalizeAngle (float a); vec2 _get_current_position (VkvgContext ctx); void _add_point (VkvgContext ctx, float x, float y); -void _add_point_vec2 (VkvgContext ctx, vec2 v); void _resetMinMax (VkvgContext ctx); void _poly_fill (VkvgContext ctx); void _fill_ec (VkvgContext ctx);//earclipping fill -void _draw_full_screen_quad (VkvgContext ctx); +void _draw_full_screen_quad (VkvgContext ctx, bool useScissor); void _create_gradient_buff (VkvgContext ctx); void _create_vertices_buff (VkvgContext ctx);