### 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.
### 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.
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){
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,
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){
}
}
}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);
}
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);
}
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
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);