]> O.S.I.I.S - jp/vkvg.git/commitdiff
some code clean and comments
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 21 Apr 2018 03:40:12 +0000 (05:40 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 21 Apr 2018 03:40:12 +0000 (05:40 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
tests/test1.c

index a6d6abef08b31ac3e556f0d1c0ae94336e49dce7..cd59d27a5322fce86d3fc4b0116feab6ed282aa7 100644 (file)
@@ -155,7 +155,6 @@ void vkvg_destroy (VkvgContext ctx)
     free(ctx);
 }
 
-
 void vkvg_close_path (VkvgContext ctx){
     if (ctx->pathPtr % 2 == 0)//current path is empty
         return;
@@ -335,46 +334,39 @@ void vkvg_clip (VkvgContext ctx){
 void vkvg_fill_preserve (VkvgContext ctx){
     if (ctx->pathPtr == 0)      //nothing to fill
         return;
-    if (ctx->pathPtr % 2 != 0)  //current path is no close
+    if (ctx->pathPtr % 2 != 0)  //current path is not finished, close it
         vkvg_close_path(ctx);
-    if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)
+    if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)//flush if vk buff is full
         vkvg_flush(ctx);
 
-    uint32_t lastPathPointIdx, i = 0, ptrPath = 0;;
+    uint32_t ptrPath = 0;;
     Vertex v = {};
     v.uv.z = -1;
 
     while (ptrPath < ctx->pathPtr){
-        if (!_path_is_closed(ctx,ptrPath)){
-            ptrPath+=2;
-            continue;
-        }
+        if (!_path_is_closed(ctx, ptrPath))
+            //close path
+            ctx->pathes[ptrPath+1] = ctx->pathes[ptrPath];
+
         uint32_t firstPtIdx = ctx->pathes[ptrPath];
-        lastPathPointIdx = _get_last_point_of_closed_path (ctx, ptrPath);
-        uint32_t pathPointCount = lastPathPointIdx - ctx->pathes[ptrPath] + 1;
+        uint32_t lastPtIdx = _get_last_point_of_closed_path (ctx, ptrPath);
+        uint32_t pathPointCount = lastPtIdx - ctx->pathes[ptrPath] + 1;
         uint32_t firstVertIdx = ctx->vertCount;
 
         ear_clip_point ecps[pathPointCount];
         uint32_t ecps_count = pathPointCount;
-        i = 0;
+        uint32_t i = 0;
 
+        //init points link list
         while (i < pathPointCount-1){
             v.pos = ctx->points[i+firstPtIdx];
-            ear_clip_point ecp = {
-                v.pos,
-                i+firstVertIdx,
-                &ecps[i+1]
-            };
+            ear_clip_point ecp = {v.pos, i+firstVertIdx, &ecps[i+1]};
             ecps[i] = ecp;
             _add_vertex(ctx, v);
             i++;
         }
         v.pos = ctx->points[i+firstPtIdx];
-        ear_clip_point ecp = {
-            v.pos,
-            i+firstVertIdx,
-            ecps
-        };
+        ear_clip_point ecp = {v.pos, i+firstVertIdx, ecps};
         ecps[i] = ecp;
         _add_vertex(ctx, v);
 
@@ -390,22 +382,21 @@ void vkvg_fill_preserve (VkvgContext ctx){
             ear_clip_point* vP = v2->next;
             bool isEar = true;
             while (vP!=v1){
-                if (ptInTriangle(vP->pos,v0->pos,v2->pos,v1->pos)){
+                if (ptInTriangle (vP->pos, v0->pos, v2->pos, v1->pos)){
                     isEar = false;
                     break;
                 }
                 vP = vP->next;
             }
             if (isEar){
-                _add_triangle_indices(ctx, v0->idx,v1->idx,v2->idx);
+                _add_triangle_indices (ctx, v0->idx, v1->idx, v2->idx);
                 v1->next = v2;
                 ecps_count --;
             }else
                 ecp_current = ecp_current->next;
         }
-        if (ecps_count == 3){
-            _add_triangle_indices(ctx, ecp_current->next->idx,ecp_current->idx,ecp_current->next->next->idx);
-        }
+        if (ecps_count == 3)
+            _add_triangle_indices(ctx, ecp_current->next->idx, ecp_current->idx, ecp_current->next->next->idx);
 
         ptrPath+=2;
     }
index e8131aec521262fbf7314ac78f1effdd56f25625..3af9c4ecb8ad6ad76f767d549b1884b2b838c4d2 100644 (file)
@@ -250,7 +250,7 @@ void _clear_path (VkvgContext ctx){
     ctx->pointCount = 0;
     ctx->curPosExists = false;
 }
-bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath){
+inline bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath){
     return (ctx->pathes[ptrPath] == ctx->pathes[ptrPath+1]);
 }
 uint32_t _get_last_point_of_closed_path(VkvgContext ctx, uint32_t ptrPath){
index ec38078ab1bc2051277473e748a41b6bf71ce072..f3abb747bbd7d92a6f7abfa8ea58900dbb86da87 100644 (file)
@@ -108,15 +108,15 @@ typedef struct _vkvg_context_t {
     vkvg_buff  uboGrad;//uniform buff obj holdings gradient infos
 
     //vk buffers, holds data until flush
-    vkvg_buff  indices;
-    size_t             sizeIndices;
-    uint32_t   indCount;
+    vkvg_buff  indices;        //index buffer with persistent map memory
+    size_t             sizeIndices;    //reserved size
+    uint32_t   indCount;       //current indice count
 
     uint32_t   curIndStart;
 
-    vkvg_buff  vertices;
-    size_t             sizeVertices;
-    uint32_t   vertCount;
+    vkvg_buff  vertices;       //vertex buffer with persistent mapped memory
+    size_t             sizeVertices;   //reserved size
+    uint32_t   vertCount;      //effective vertices count
 
     //pathes, exists until stroke of fill
     vec2*              points;     //points array
@@ -124,12 +124,16 @@ typedef struct _vkvg_context_t {
     uint32_t   pointCount; //effective points count
 
     uint32_t   pathPtr;
+    //pathes array is a list of couple (start,end) point idx refering to point array
+    //it split points list in subpathes and tell if path is closed.
+    //if path is closed, end index is the same as start.
+    //(I should use a boolean instead to keep last point in array)
     uint32_t*  pathes;
     size_t             sizePathes;
 
-    vec2               curPos;
+    vec2               curPos;     //current position handling
     bool        curPosExists;
-    vec4               curRGBA;
+    vec4               curRGBA;    //is store in pushConsts => may be removed.
     float              lineWidth;
 
     vkvg_line_cap_t     lineCap;
index 023bf7726a49c018e12bd983d5ad43e5ae9d2662..91c917acdfc611587ec3095cf4ab70e28d5feed3 100644 (file)
@@ -453,19 +453,19 @@ void vkvg_test_fill_and_stroke (VkvgContext ctx){
     vkvg_move_to (ctx, 100, 100);
     vkvg_rel_line_to (ctx, 50, -80);
     vkvg_rel_line_to (ctx, 50, 80);
-    vkvg_close_path (ctx);
+    //vkvg_close_path (ctx);
 
-    /*vkvg_move_to (ctx, 300, 100);
+    vkvg_move_to (ctx, 300, 100);
     vkvg_rel_line_to (ctx, 50, -80);
     vkvg_rel_line_to (ctx, 50, 80);
-    vkvg_close_path (ctx);*/
+    vkvg_close_path (ctx);
 
     vkvg_set_line_width (ctx, 10.0);
     vkvg_set_source_rgb (ctx, 0, 0, 1);
-    //vkvg_fill_preserve (ctx);
-    vkvg_fill(ctx);
-    //vkvg_set_source_rgb (ctx, 0, 0, 0);
-    //vkvg_stroke (ctx);
+    vkvg_fill_preserve (ctx);
+    //vkvg_fill(ctx);
+    vkvg_set_source_rgb (ctx, 0, 0, 0);
+    vkvg_stroke (ctx);
 }
 void vkvg_test_curves2 (VkvgContext ctx) {
     vkvg_set_source_rgba   (ctx, 0.5,0.0,1.0,0.5);