free(ctx);
}
-
void vkvg_close_path (VkvgContext ctx){
if (ctx->pathPtr % 2 == 0)//current path is empty
return;
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);
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;
}
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){
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
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;
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);