]> O.S.I.I.S - jp/vkvg.git/commitdiff
compute bounds with current matrix for scissor, use for paint, not clipping
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 2 Sep 2019 02:43:52 +0000 (04:43 +0200)
committerj-p <jp_bruyere@hotmail.com>
Tue, 3 Sep 2019 18:36:09 +0000 (20:36 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h

index 2e4c641f9573ce4a7117ae19d46c0c28340666ed..1c80d37298a5b4541083a8023bed257ab68abe83 100644 (file)
@@ -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);
index 5a015427733ea4e9ea390d142b57fc2380336976..7290d993cfb1ec22ada91d1069a8b56e50e9164b 100644 (file)
@@ -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);
 }
index fd08c709f3724283de61f4760ce975e1f8a2f5ec..4cadb57c7035b740c1b493c91ee2f1b2ce35ed39 100644 (file)
@@ -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);