]> O.S.I.I.S - jp/vkvg.git/commitdiff
using scissor speed up full screen quad
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 2 Sep 2019 00:33:10 +0000 (02:33 +0200)
committerj-p <jp_bruyere@hotmail.com>
Tue, 3 Sep 2019 18:36:09 +0000 (20:36 +0200)
README.md
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h

index 521d4bd502666b11f4907861498a149922cd5df8..89c6dc2b191fd81bab7ab815bb4fb43cec8fe808 100644 (file)
--- a/README.md
+++ b/README.md
@@ -27,7 +27,8 @@ For API documentation and usage, please refer to the [Cairo](https://www.cairogr
 
 ### Current status:
 
-- Fill (with stencil even-odd technic) and Stroke functional.
+- Fill (stencil even-odd, non-zero with ear clipping).
+- Stroke.
 - Basic painting operation.
 - Font system with caching operational.
 - Linear Gradients.
@@ -73,15 +74,15 @@ make                                                    # Run Make
 
 ### To Do
 
+- [ ] Use Scissor where possible.
+- [ ] Improve stroke algorithms.
 - [ ] Radial gradients.
 - [ ] Dashed lines.
 - [ ] Operators.
-- [ ] Improve stroke algorithms.
-- [ ] Offscreen pattern building.
 - [x] Optimize vulkan memory allocations by sub-allocating from a single shared memory chunk per type.
 - [ ] Optimize command submissions.
-- [ ] Test SDF font rendering.
-- [ ] Avoid line joins inside curves and arc.
+- [x] Test SDF font rendering.
+- [x] Avoid line joins inside curves and arc.
 - [ ] Structured unit testing.
 - [ ] Perf and memory checks.
 - [ ] Code clean and comment.
index a0a12ee72d17f0228327ae3144f1bd828c3b256c..2e4c641f9573ce4a7117ae19d46c0c28340666ed 100644 (file)
@@ -69,6 +69,9 @@ VkvgContext vkvg_create(VkvgSurface surf)
     ctx->indCount       = 0;
     ctx->curIndStart    = 0;
 
+    VkRect2D scissor = {{0,0},{ctx->pSurf->width,ctx->pSurf->height}};
+    ctx->bounds        = scissor;
+
     ctx->savedStencils = malloc(0);
 
     push_constants pc = {
index c28a20f8ca40d6a23d5b5d7dcd6690961f78a20d..5a015427733ea4e9ea390d142b57fc2380336976 100644 (file)
@@ -98,13 +98,27 @@ void _clear_path (VkvgContext ctx){
     ctx->pathPtr = 0;
     ctx->pointCount = 0;
     ctx->curvePtr = 0;
+    _resetMinMax(ctx);
 }
 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;
+}
 void _add_point (VkvgContext ctx, float x, float y){
-    vec2 v = {x,y};
-    ctx->points[ctx->pointCount] = v;
+    if (x < ctx->xMin)
+        ctx->xMin = x;
+    if (x > ctx->xMax)
+        ctx->xMax = x;
+    if (y < ctx->yMin)
+        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){
@@ -303,8 +317,8 @@ void _start_cmd_for_render_pass (VkvgContext ctx) {
     CmdBeginRenderPass (ctx->cmd, &ctx->renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
     VkViewport viewport = {0,0,ctx->pSurf->width,ctx->pSurf->height,0,1};
     CmdSetViewport(ctx->cmd, 0, 1, &viewport);
-    VkRect2D scissor = {{0,0},{ctx->pSurf->width,ctx->pSurf->height}};
-    CmdSetScissor(ctx->cmd, 0, 1, &scissor);
+
+    CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds);
 
     VkDescriptorSet dss[] = {ctx->dsFont,ctx->dsSrc,ctx->dsGrad};
     CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineLayout,
@@ -843,7 +857,7 @@ void _poly_fill (VkvgContext ctx){
         uint32_t firstVertIdx = ctx->vertCount;
 
         if (_path_has_curves(ctx, ptrPath)) {
-            int i=0;
+            uint i=0;
             while (i < pathPointCount) {
                 if (ptrPath + ptrCurve < ctx->pathPtr && ctx->pathes[ptrPath+2+ptrCurve] == i+firstPtIdx){
                     while (i < ctx->pathes[ptrPath+3+ptrCurve] && i < pathPointCount){
@@ -859,7 +873,7 @@ void _poly_fill (VkvgContext ctx){
                 }
             }
         }else{
-            for (int i = 0; i < pathPointCount; i++) {
+            for (uint i = 0; i < pathPointCount; i++) {
                 v.pos = ctx->points[i+firstPtIdx];
                 _add_vertex(ctx, v);
             }
@@ -967,9 +981,12 @@ 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);
     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);
 }
index 54cd41e098e4ee28663fcab40b0090e23be9ec3c..fd08c709f3724283de61f4760ce975e1f8a2f5ec 100644 (file)
@@ -84,6 +84,13 @@ typedef struct _vkvg_context_t {
     VkDescriptorSet     dsSrc;      //source ds
     VkDescriptorSet     dsGrad;     //gradient uniform buffer
 
+    VkRect2D            bounds;
+
+    float xMin;
+    float xMax;
+    float yMin;
+    float yMax;
+
     vkvg_buff  uboGrad;        //uniform buff obj holdings gradient infos
 
     //vk buffers, holds data until flush
@@ -161,6 +168,8 @@ 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);