#include "vectors.h"
-// init float vector
-inline vec2 vec2_create (float x, float y) {
- vec2 v = {x,y};
- return v;
-}
// compute normal direction vector from line defined by 2 points in double precision
vec2d vec2d_line_norm(vec2d a, vec2d b)
{
vec2 vec2_line_norm(vec2 a, vec2 b)
{
vec2 d = {b.x - a.x, b.y - a.y};
- float md = sqrt (d.x*d.x + d.y*d.y);
+ float md = sqrtf (d.x*d.x + d.y*d.y);
d.x/=md;
d.y/=md;
return d;
}
// compute length of double vector 2d
-double vec2d_length(vec2d v){
+inline double vec2d_length(vec2d v){
return sqrt (v.x*v.x + v.y*v.y);
}
// compute length of float vector 2d
-float vec2_length(vec2 v){
- return sqrt (v.x*v.x + v.y*v.y);
+inline float vec2_length(vec2 v){
+ return sqrtf (v.x*v.x + v.y*v.y);
}
// normalize float vector
vec2 vec2_norm(vec2 a)
{
- float m = sqrt (a.x*a.x + a.y*a.y);
- vec2 d = {a.x/m, a.y/m};
- return d;
+ float m = sqrtf (a.x*a.x + a.y*a.y);
+ return (vec2){a.x/m, a.y/m};
}
// normalize double vector
vec2d vec2d_norm(vec2d a)
{
double m = sqrt (a.x*a.x + a.y*a.y);
- vec2d d = {a.x/m, a.y/m};
- return d;
+ return (vec2d){a.x/m, a.y/m};
}
// multiply 2d vector by scalar
-vec2d vec2d_mult(vec2d a, double m){
- vec2d r = {a.x*m,a.y*m};
- return r;
+inline vec2d vec2d_mult(vec2d a, double m){
+ return (vec2d){a.x*m,a.y*m};
}
// multiply 2d vector by scalar
-vec2 vec2_mult(vec2 a, float m){
- vec2 r = {a.x*m,a.y*m};
- return r;
+inline vec2 vec2_mult(vec2 a, float m){
+ return (vec2){a.x*m,a.y*m};
}
// compute perpendicular vector
-vec2d vec2d_perp (vec2d a){
- vec2d vp = {a.y, -a.x};
- return vp;
+inline vec2d vec2d_perp (vec2d a){
+ return (vec2d){a.y, -a.x};
}
// compute perpendicular vector
-vec2 vec2_perp (vec2 a){
- vec2 vp = {a.y, -a.x};
- return vp;
+inline vec2 vec2_perp (vec2 a){
+ return (vec2){a.y, -a.x};
}
// convert double precision vector to single precision
-vec2 vec2d_to_vec2(vec2d vd){
- vec2 v = {vd.x,vd.y};
- return v;
+inline vec2 vec2d_to_vec2(vec2d vd){
+ return (vec2){(float)vd.x,(float)vd.y};
}
// compute sum of two single precision vectors
-vec2 vec2_add (vec2 a, vec2 b){
- vec2 r = {a.x + b.x, a.y + b.y};
- return r;
+inline vec2 vec2_add (vec2 a, vec2 b){
+ return (vec2){a.x + b.x, a.y + b.y};
}
// compute sum of two double precision vectors
-vec2d vec2d_add (vec2d a, vec2d b){
- vec2d r = {a.x + b.x, a.y + b.y};
- return r;
+inline vec2d vec2d_add (vec2d a, vec2d b){
+ return (vec2d){a.x + b.x, a.y + b.y};
}
// compute subbstraction of two single precision vectors
-vec2 vec2_sub (vec2 a, vec2 b){
- vec2 r = {a.x - b.x, a.y - b.y};
- return r;
+inline vec2 vec2_sub (vec2 a, vec2 b){
+ return (vec2){a.x - b.x, a.y - b.y};
}
// compute subbstraction of two double precision vectors
-vec2d vec2d_sub (vec2d a, vec2d b){
- vec2d r = {a.x - b.x, a.y - b.y};
- return r;
+inline vec2d vec2d_sub (vec2d a, vec2d b){
+ return (vec2d){a.x - b.x, a.y - b.y};
}
// test equality of two single precision vectors
bool vec2_equ (vec2 a, vec2 b){
}vec2i16;
float vec2_length (vec2 v);
-vec2 vec2_create (float x, float y);
vec2 vec2_norm (vec2 a);
vec2 vec2_perp (vec2 a);
vec2 vec2_add (vec2 a, vec2 b);
#endif
static VkClearValue clearValues[3] = {
- { 0.0f, 0.0f, 0.0f, 0.0f },
+ { 0 },
{ 1.0f, 0 },
- { 0.0f, 0.0f, 0.0f, 0.0f }
+ { 0 }
};
/**
return;
_flush_cmd_buff(ctx);
-
- vkWaitForFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT);
+ _wait_flush_fence(ctx);
LOG(LOG_INFO, "DESTROY Context: ctx = %lu; surf = %lu\n", (ulong)ctx, (ulong)ctx->pSurf);
LOG(LOG_INFO, "CLIP: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2);
- if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)//flush if vk buff is full
- _flush_cmd_buff(ctx);
+ _check_flush_needed (ctx);
+
if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){
_check_cmd_buff_state(ctx);
LOG(LOG_INFO, "FILL: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2);
- if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)//flush if vk buff is full
- _flush_cmd_buff(ctx);
-
- _check_cmd_buff_state(ctx);
+ _check_flush_needed (ctx);
+ _check_cmd_buff_state (ctx);
if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){
_poly_fill (ctx);
LOG(LOG_INFO, "STROKE: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2);
- if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)
- _flush_cmd_buff(ctx);
+ _check_flush_needed (ctx);
- Vertex v = {};
+ Vertex v = {0};
v.uv.z = -1;
float hw = ctx->lineWidth / 2.0f;
while (ptrPath < ctx->pathPtr){
uint ptrCurve = 0;
- uint32_t firstIdx = ctx->vertCount;
+ VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)ctx->vertCount;
i = ctx->pathes[ptrPath]&PATH_ELT_MASK;
LOG(LOG_INFO_PATH, "\tPATH: start = %d; ", ctx->pathes[ptrPath]&PATH_ELT_MASK, ctx->pathes[ptrPath+1]&PATH_ELT_MASK);
i++;
}else{
- iR = ctx->pathes[ptrPath]&PATH_ELT_MASK;
- _build_vb_step(ctx,v,hw,iL,i,iR, false);
+ iR = ctx->pathes[ptrPath] & PATH_ELT_MASK;
+ _build_vb_step (ctx,v,hw,iL,i,iR, false);
VKVG_IBO_INDEX_TYPE* inds = &ctx->indexCache [ctx->indCount-6];
VKVG_IBO_INDEX_TYPE ii = firstIdx;
_record_draw_cmd(ctx);
}
void vkvg_paint (VkvgContext ctx){
- _check_cmd_buff_state(ctx);
- _draw_full_screen_quad(ctx,true);
+ _check_cmd_buff_state (ctx);
+ _draw_full_screen_quad (ctx, true);
}
inline void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) {
vkvg_set_source_rgba (ctx, r, g, b, 1);
_bind_draw_pipeline (ctx);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
-
sav->lineWidth = ctx->lineWidth;
sav->curOperator= ctx->curOperator;
sav->lineCap = ctx->lineCap;
CmdSetStencilCompareMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
_flush_cmd_buff (ctx);
+ _wait_flush_fence (ctx);
uint8_t curSaveStencil = ctx->curSavBit / 6;
if (ctx->curSavBit > 0 && ctx->curSavBit % 6 == 0){//addtional save/restore stencil image have to be copied back to surf stencil first
VK_CHECK_RESULT(vkEndCommandBuffer(ctx->cmd));
_wait_and_submit_cmd (ctx);
-
+ _wait_flush_fence (ctx);
vkh_image_destroy (savStencil);
}
#include "vkh_queue.h"
#include "vkh_image.h"
-void _check_cmd_buff_state (VkvgContext ctx) {
+void _check_flush_needed (VkvgContext ctx) {
if (!ctx->cmdStarted)
- _start_cmd_for_render_pass(ctx);
- else if (ctx->pushCstDirty)
- _update_push_constants(ctx);
+ return;
+ if (ctx->pointCount * 4 < ctx->sizeIndices - ctx->indCount)
+ return;
+ _flush_cmd_buff(ctx);
}
void _check_vbo_size (VkvgContext ctx) {
if (ctx->sizeVertices - ctx->vertCount > VKVG_ARRAY_THRESHOLD)
if (ctx->sizeIndices - ctx->indCount > VKVG_ARRAY_THRESHOLD)
return;
ctx->sizeIndices += VKVG_IBO_SIZE;
- ctx->indexCache = (VKVG_IBO_INDEX_TYPE*) realloc (ctx->vertexCache, ctx->sizeVertices * sizeof(VKVG_IBO_INDEX_TYPE));
+ ctx->indexCache = (VKVG_IBO_INDEX_TYPE*) realloc (ctx->indexCache, ctx->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE));
}
void _check_pathes_array (VkvgContext ctx){
if (ctx->sizePathes - ctx->pathPtr - ctx->curvePtr > VKVG_ARRAY_THRESHOLD)
void _create_vertices_buff (VkvgContext ctx){
ctx->vertexCache = (Vertex*)malloc(ctx->sizeVertices * sizeof(Vertex));
- ctx->indexCache = (VKVG_IBO_INDEX_TYPE*)malloc(ctx->sizeVertices * sizeof(VKVG_IBO_INDEX_TYPE));
+ ctx->indexCache = (VKVG_IBO_INDEX_TYPE*)malloc(ctx->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE));
vkvg_buffer_create (ctx->pSurf->dev,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
_add_tri_indices_for_rect(ctx, firstIdx);
}
-
+void _check_cmd_buff_state (VkvgContext ctx) {
+ if (!ctx->cmdStarted)
+ _start_cmd_for_render_pass(ctx);
+ else if (ctx->pushCstDirty)
+ _update_push_constants(ctx);
+}
void _create_cmd_buff (VkvgContext ctx){
vkh_cmd_buffs_create((VkhDevice)ctx->pSurf->dev, ctx->cmdPool,VK_COMMAND_BUFFER_LEVEL_PRIMARY, 2, ctx->cmdBuffers);
#if defined(DEBUG) && defined(ENABLE_VALIDATION)
inline void _wait_flush_fence (VkvgContext ctx) {
vkWaitForFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT);
}
+inline void _reset_flush_fence (VkvgContext ctx) {
+ vkResetFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence);
+}
void _wait_and_submit_cmd (VkvgContext ctx){
if (!ctx->cmdStarted)
return;
_wait_flush_fence (ctx);
- vkResetFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence);
+ _reset_flush_fence(ctx);
_submit_cmd (ctx->pSurf->dev, &ctx->cmd, ctx->flushFence);
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
}*/
-
+//this func expect cmdStarted to be true, so that vert and ind count are > 0
void _end_render_pass (VkvgContext ctx) {
_record_draw_cmd (ctx);
LOG(LOG_INFO, "END RENDER PASS: ctx = %lu;\n", ctx);
CmdEndRenderPass (ctx->cmd);
ctx->renderPassBeginInfo.renderPass = ctx->pSurf->dev->renderPass;
+
+ //copy vertex and index caches to the vbo and ibo vkbuffers
+ _wait_flush_fence (ctx);
+
+ memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->vertCount * sizeof (Vertex));
+ memcpy(ctx->indices.allocInfo.pMappedData, ctx->indexCache, ctx->indCount * sizeof (VKVG_IBO_INDEX_TYPE));
+
+ ctx->vertCount = 0;
+ ctx->indCount = 0;
+ ctx->curIndStart = 0;
}
void _flush_cmd_buff (VkvgContext ctx){
if (!ctx->cmdStarted)
return;
- memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->vertCount * sizeof (Vertex));
- memcpy(ctx->indices.allocInfo.pMappedData, ctx->indexCache, ctx->indCount * sizeof (VKVG_IBO_INDEX_TYPE));
-
- _end_render_pass (ctx);
- vkh_cmd_end (ctx->cmd);
+ _end_render_pass (ctx);
+ vkh_cmd_end (ctx->cmd);
LOG(LOG_INFO, "FLUSH CTX: ctx = %lu; vertices = %d; indices = %d\n", ctx, ctx->vertCount, ctx->indCount);
_wait_and_submit_cmd(ctx);
-
- ctx->vertCount = 0;
- ctx->indCount = 0;
- ctx->curIndStart = 0;
}
//bind correct draw pipeline depending on current OPERATOR
#include "vkvg_fonts.h"
#define VKVG_PTS_SIZE 4096
-#define VKVG_VBO_SIZE 4096 * 8
+#define VKVG_VBO_SIZE VKVG_PTS_SIZE * 8
#define VKVG_IBO_SIZE VKVG_VBO_SIZE * 6
#define VKVG_PATHES_SIZE 16
#define VKVG_ARRAY_THRESHOLD 4
struct _ear_clip_point* next;
}ear_clip_point;
-bool _current_path_is_empty (VkvgContext ctx);
-void _start_sub_path (VkvgContext ctx, float x, float y);
+void _check_flush_needed (VkvgContext ctx);
void _check_vbo_size (VkvgContext ctx);
void _check_ibo_size (VkvgContext ctx);
void _check_pathes_array (VkvgContext ctx);
+
+bool _current_path_is_empty (VkvgContext ctx);
+void _start_sub_path (VkvgContext ctx, float x, float y);
void _finish_path (VkvgContext ctx);
void _clear_path (VkvgContext ctx);
bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath);
void _flush_cmd_buff (VkvgContext ctx);
void _record_draw_cmd (VkvgContext ctx);
void _wait_flush_fence (VkvgContext ctx);
+void _reset_flush_fence (VkvgContext ctx);
void _wait_and_submit_cmd (VkvgContext ctx);
void _update_push_constants (VkvgContext ctx);
void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat);
.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.stencilLoadOp = stencilLoadOp,
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
- .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ .initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
VkAttachmentDescription attachments[] = {attColor,attDS};
.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
.stencilLoadOp = stencilLoadOp,
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
- .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ .initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL };
VkAttachmentDescription attachments[] = {attColorResolve,attDS,attColor};
vkengine_set_cursor_pos_callback(e, mouse_move_callback);
vkengine_set_scroll_callback(e, scroll_callback);
- bool deferredResolve = true;
+ bool deferredResolve = false;
- device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_4_BIT, deferredResolve);
+ device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_1_BIT, deferredResolve);
vkvg_device_set_dpy(device, 96, 96);
vkengine_set_cursor_pos_callback(e, mouse_move_callback);
vkengine_set_scroll_callback(e, scroll_callback);
- bool deferredResolve = false;
+ bool deferredResolve = true;
device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_4_BIT, deferredResolve);
vkDestroyFence (e->dev->dev, fences[i], NULL);
fences[i] = NULL;
}
- vkvg_surface_destroy(surfaces[i]);
- surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]);
+ vkvg_surface_destroy (surfaces[i]);
}
vkDestroyFence (e->dev->dev, fence, NULL);
+ vkh_presenter_create_swapchain (r);
+ for (uint i=0; i < r->imgCount;i++)
+ surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]);
}else{
surf = surfaces[r->currentScBufferIndex];
if (fences[r->currentScBufferIndex] != NULL){
.pSwapchains = &r->swapChain,
.pImageIndices = &r->currentScBufferIndex };
- /* Make sure command buffer is finished before presenting */
- VK_CHECK_RESULT(vkQueuePresentKHR(r->queue, &present));
+ vkQueuePresentKHR(r->queue, &present);
}
#else
testfunc();
vkvg_device_destroy (device);
vkengine_destroy (e);
-
}
-Subproject commit 4824a7ec5b113892f2fdac0059f0e0f88a490625
+Subproject commit bced7146e49377256b4e4ab8856e02a7b3a50355