_init_descriptor_sets (ctx);
_update_descriptor_set (ctx, ctx->pSurf->dev->fontCache->cacheTex, ctx->dsFont);
_update_gradient_desc_set(ctx);
+
+ //add full screen quad at the beginning, recurently used
+ _vkvg_fill_rectangle (ctx,0,0,ctx->pSurf->width,ctx->pSurf->height);
+
_init_cmd_buff (ctx);
_clear_path (ctx);
if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)//flush if vk buff is full
vkvg_flush(ctx);
+ vkCmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelinePolyFill);
+
uint32_t ptrPath = 0;;
Vertex v = {};
v.uv.z = -1;
uint32_t pathPointCount = lastPtIdx - ctx->pathes[ptrPath] + 1;
uint32_t firstVertIdx = ctx->vertCount;
- ear_clip_point ecps[pathPointCount];
- uint32_t ecps_count = pathPointCount;
- 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]};
- ecps[i] = ecp;
- _add_vertex(ctx, v);
- i++;
+ for (int i = 0; i < pathPointCount; i++) {
+ v.pos = ctx->points[i+firstPtIdx];
+ _add_vertex(ctx, v);
}
- v.pos = ctx->points[i+firstPtIdx];
- ear_clip_point ecp = {v.pos, i+firstVertIdx, ecps};
- ecps[i] = ecp;
- _add_vertex(ctx, v);
-
- ear_clip_point* ecp_current = ecps;
-
- while (ecps_count > 3) {
- ear_clip_point* v0 = ecp_current->next,
- *v1 = ecp_current, *v2 = ecp_current->next->next;
- if (ecp_zcross (v0, v2, v1)<0){
- ecp_current = ecp_current->next;
- continue;
- }
- ear_clip_point* vP = v2->next;
- bool isEar = true;
- while (vP!=v1){
- 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);
- 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);
+
+ vkCmdDraw (ctx->cmd,pathPointCount,1,firstVertIdx,0);
ptrPath+=2;
}
- _record_draw_cmd(ctx);
+
+ vkCmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipeline);
+ vkCmdSetStencilReference(ctx->cmd,VK_STENCIL_FRONT_AND_BACK, 0xff);
+ vkCmdDrawIndexed (ctx->cmd,6,1,0,0,0);
+ vkCmdSetStencilReference(ctx->cmd,VK_STENCIL_FRONT_AND_BACK, 0x0);
}
void vkvg_fill (VkvgContext ctx){
vkvg_fill_preserve(ctx);
}
void vkvg_paint (VkvgContext ctx){
_vkvg_fill_rectangle (ctx, 0, 0, ctx->pSurf->width, ctx->pSurf->height);
- _record_draw_cmd (ctx);
+ _record_draw_cmd(ctx);
}
inline void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) {
}
void _flush_cmd_buff (VkvgContext ctx){
- if (ctx->indCount == 0){
- vkResetCommandBuffer(ctx->cmd,0);
- return;
- }
_record_draw_cmd (ctx);
vkCmdEndRenderPass (ctx->cmd);
//_explicit_ms_resolve (ctx);
_submit_wait_and_reset_cmd(ctx);
}
void _init_cmd_buff (VkvgContext ctx){
- ctx->vertCount = ctx->indCount = ctx->curIndStart = 0;
+ //full surf quad triangles is at the beginning
+ ctx->vertCount = 4;
+ ctx->indCount = 6;
+ ctx->curIndStart = 6;
//VkClearValue clearValues[2];
//clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 1.0f } };
//clearValues[1].depthStencil = { 1.0f, 0 };
vkDestroyDescriptorSetLayout (dev->vkDev, dev->dslFont,NULL);
vkDestroyDescriptorSetLayout (dev->vkDev, dev->dslSrc, NULL);
+ vkDestroyPipeline (dev->vkDev, dev->pipelinePolyFill, NULL);
vkDestroyPipeline (dev->vkDev, dev->pipeline, NULL);
vkDestroyPipeline (dev->vkDev, dev->pipelineClipping, NULL);
vkDestroyPipeline (dev->vkDev, dev->pipeline_OP_SUB, NULL);
.renderPass = dev->renderPass };
VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
- .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST };
+ .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN };
VkPipelineRasterizationStateCreateInfo rasterizationState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
.polygonMode = VK_POLYGON_MODE_FILL,
.pAttachments = &blendAttachmentState };
/*failOp,passOp,depthFailOp,compareOp, compareMask, writeMask, reference;*/
+ VkStencilOpState polyFillOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_INVERT,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0x0,0xf,0};
VkStencilOpState clipingOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_INCREMENT_AND_CLAMP,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0x0,0xf,0};
- VkStencilOpState stencilOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_REPLACE,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0xf,0x0,0};
+ VkStencilOpState stencilOpState = {VK_STENCIL_OP_KEEP,VK_STENCIL_OP_ZERO,VK_STENCIL_OP_KEEP,VK_COMPARE_OP_EQUAL,0xf,0xf,0};
VkPipelineDepthStencilStateCreateInfo dsStateCreateInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
.depthTestEnable = VK_FALSE,
VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelineClipping));
+ dsStateCreateInfo.back = dsStateCreateInfo.front = polyFillOpState;
+ VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipelinePolyFill));
+
//dsStateCreateInfo.back.writeMask = dsStateCreateInfo.front.writeMask = 0;
dsStateCreateInfo.back = dsStateCreateInfo.front = stencilOpState;
blendAttachmentState.colorWriteMask=0xf;
+ inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
VK_CHECK_RESULT(vkCreateGraphicsPipelines(dev->vkDev, dev->pipelineCache, 1, &pipelineCreateInfo, NULL, &dev->pipeline));
blendAttachmentState.alphaBlendOp = blendAttachmentState.colorBlendOp = VK_BLEND_OP_SUBTRACT;
VkFence fence;
VkPipeline pipeline;
+ VkPipeline pipelinePolyFill;
VkPipeline pipelineClipping;
VkPipeline pipeline_OP_SUB;
VkPipeline pipelineWired;