diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-01-05 18:24:47 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-01-05 18:24:47 +0100 |
| commit | 720d8e33af0b0862df7c8163533228917e837f8b (patch) | |
| tree | 132123d732a22087ed3d4058bf28feca3712fb6a /src | |
| parent | 13bad923adf6ffba5be990bfd98e2af054270e01 (diff) | |
pattern transform, opacity, debug getarcsteps (abs)
Diffstat (limited to 'src')
| -rw-r--r-- | src/vkvg_context.c | 24 | ||||
| -rw-r--r-- | src/vkvg_context_internal.c | 46 | ||||
| -rw-r--r-- | src/vkvg_context_internal.h | 8 | ||||
| -rw-r--r-- | src/vkvg_pattern.c | 10 | ||||
| -rw-r--r-- | src/vkvg_pattern.h | 2 | ||||
| -rw-r--r-- | src/vkvg_surface.c | 2 |
6 files changed, 71 insertions, 21 deletions
diff --git a/src/vkvg_context.c b/src/vkvg_context.c index b16d2a4..72c7916 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -66,10 +66,10 @@ VkvgContext vkvg_create(VkvgSurface surf) ctx->bounds = (VkRect2D) {{0,0},{ctx->pSurf->width,ctx->pSurf->height}}; ctx->pushConsts = (push_constants) { - {.height=1}, + {.a = 1}, {(float)ctx->pSurf->width,(float)ctx->pSurf->height}, VKVG_PATTERN_TYPE_SOLID, - 0, + 1.0f, VKVG_IDENTITY_MATRIX, VKVG_IDENTITY_MATRIX }; @@ -286,6 +286,20 @@ void vkvg_destroy (VkvgContext ctx) free(ctx); } +void vkvg_set_opacity (VkvgContext ctx, float opacity) { + if (ctx->status) + return; + + if (EQUF(ctx->pushConsts.opacity, opacity)) + return; + + _emit_draw_cmd_undrawn_vertices (ctx); + ctx->pushConsts.opacity = opacity; + ctx->pushCstDirty = true; +} +float vkvg_get_opacity (VkvgContext ctx) { + return ctx->pushConsts.opacity; +} vkvg_status_t vkvg_status (VkvgContext ctx) { return ctx->status; } @@ -506,8 +520,8 @@ void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, flo //compute dyn distanceTolerance depending on current transform float dx = 1, dy = 1; - vkvg_matrix_transform_distance (&ctx->pushConsts.mat, &dx, &dy); - float distanceTolerance = 0.02f / fmaxf(dx,dy); + vkvg_matrix_transform_point (&ctx->pushConsts.mat, &dx, &dy); + float distanceTolerance = fabs(0.02f / fmaxf(dx,dy)); _recursive_bezier (ctx, distanceTolerance, cp.x, cp.y, x1, y1, x2, y2, x3, y3, 0); /*cp.x = x3; @@ -862,9 +876,9 @@ void vkvg_set_source_rgba (VkvgContext ctx, float r, float g, float b, float a) void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y){ if (ctx->status) return; - _update_cur_pattern (ctx, vkvg_pattern_create_for_surface(surf)); ctx->pushConsts.source.x = x; ctx->pushConsts.source.y = y; + _update_cur_pattern (ctx, vkvg_pattern_create_for_surface(surf)); ctx->pushCstDirty = true; } void vkvg_set_source (VkvgContext ctx, VkvgPattern pat){ diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 8b2e6ef..5d0d649 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -160,6 +160,7 @@ void _finish_path (VkvgContext ctx){ ctx->pathes[ctx->pathPtr] = 0; ctx->segmentPtr = 0; + ctx->subpathCount++; } //clear path datas in context void _clear_path (VkvgContext ctx){ @@ -167,6 +168,7 @@ void _clear_path (VkvgContext ctx){ ctx->pathes [ctx->pathPtr] = 0; ctx->pointCount = 0; ctx->segmentPtr = 0; + ctx->subpathCount = 0; } void _remove_last_point (VkvgContext ctx){ ctx->pathes[ctx->pathPtr]--; @@ -208,7 +210,7 @@ float _normalizeAngle(float a) float _get_arc_step (VkvgContext ctx, float radius) { float dx = radius, dy = radius; vkvg_matrix_transform_distance (&ctx->pushConsts.mat, &dx, &dy); - float r = fmaxf(dx,dy); + float r = fabsf(fmaxf(dx,dy)); if (r < 3.0f) return asinf (1.0f / r) * 0.25f; return asinf (1.0f / r) * 1.5f * sqrtf(r); @@ -639,8 +641,12 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) { _update_descriptor_set (ctx, ctx->source, ctx->dsSrc); - vec4 srcRect = {{0},{0},{(float)surf->width},{(float)surf->height}}; - ctx->pushConsts.source = srcRect; + if (pat->hasMatrix) { + + } + + ctx->pushConsts.source.width = (float)surf->width; + ctx->pushConsts.source.height = (float)surf->height; break; } case VKVG_PATTERN_TYPE_LINEAR: @@ -663,15 +669,30 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) { ctx->status = VKVG_STATUS_PATTERN_INVALID_GRADIENT; return; } + vkvg_matrix_t mat; + if (pat->hasMatrix) { + vkvg_pattern_get_matrix (pat, &mat); + if (vkvg_matrix_invert (&mat) != VKVG_STATUS_SUCCESS) + mat = VKVG_IDENTITY_MATRIX; + } + if (pat->hasMatrix) + vkvg_matrix_transform_point (&mat, &grad.cp[0].x, &grad.cp[0].y); + vkvg_matrix_transform_point (&ctx->pushConsts.mat, &grad.cp[0].x, &grad.cp[0].y); if (pat->type == VKVG_PATTERN_TYPE_LINEAR) { - vkvg_matrix_transform_point (&ctx->pushConsts.mat, &grad.cp[0].x, &grad.cp[0].y); + if (pat->hasMatrix) + vkvg_matrix_transform_point (&mat, &grad.cp[0].z, &grad.cp[0].w); vkvg_matrix_transform_point (&ctx->pushConsts.mat, &grad.cp[0].z, &grad.cp[0].w); } else { - //centers - vkvg_matrix_transform_point (&ctx->pushConsts.mat, &grad.cp[0].x, &grad.cp[0].y); + if (pat->hasMatrix) + vkvg_matrix_transform_point (&mat, &grad.cp[1].x, &grad.cp[1].y); vkvg_matrix_transform_point (&ctx->pushConsts.mat, &grad.cp[1].x, &grad.cp[1].y); + //radii + if (pat->hasMatrix) { + vkvg_matrix_transform_distance (&mat, &grad.cp[0].z, &grad.cp[0].w); + vkvg_matrix_transform_distance (&mat, &grad.cp[1].z, &grad.cp[0].w); + } vkvg_matrix_transform_distance (&ctx->pushConsts.mat, &grad.cp[0].z, &grad.cp[0].w); vkvg_matrix_transform_distance (&ctx->pushConsts.mat, &grad.cp[1].z, &grad.cp[0].w); } @@ -680,7 +701,7 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) { vkvg_buffer_flush(&ctx->uboGrad); break; } - ctx->pushConsts.patternType = newPatternType; + ctx->pushConsts.fsq_patternType = (ctx->pushConsts.fsq_patternType & FULLSCREEN_BIT) + newPatternType; ctx->pushCstDirty = true; if (lastPat) vkvg_pattern_destroy (lastPat); @@ -1433,7 +1454,7 @@ void _vkvg_path_extents (VkvgContext ctx, bool transformed, float *x1, float *y1 while (ptrPath < ctx->pathPtr){ uint32_t pathPointCount = ctx->pathes[ptrPath] & PATH_ELT_MASK; - for (uint32_t i = firstPtIdx; i < firstPtIdx + pathPointCount - 1; i++){ + for (uint32_t i = firstPtIdx; i < firstPtIdx + pathPointCount; i++){ vec2 p = ctx->points[i]; if (transformed) vkvg_matrix_transform_point (&ctx->pushConsts.mat, &p.x, &p.y); @@ -1462,8 +1483,7 @@ void _vkvg_path_extents (VkvgContext ctx, bool transformed, float *x1, float *y1 *y1 = yMin; *y2 = yMax; } -static const uint32_t one = 1; -static const uint32_t zero = 0; + void _draw_full_screen_quad (VkvgContext ctx, bool useScissor) { #if defined(DEBUG) && defined (VKVG_DBG_UTILS) vkh_cmd_label_start(ctx->cmd, "_draw_full_screen_quad", DBG_LAB_COLOR_FSQ); @@ -1486,11 +1506,13 @@ void _draw_full_screen_quad (VkvgContext ctx, bool useScissor) { _add_vertexf (ctx, -1, 3); ctx->curVertOffset = ctx->vertCount; + ctx->pushConsts.fsq_patternType |= FULLSCREEN_BIT; CmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout, - VK_SHADER_STAGE_VERTEX_BIT, 28, 4,&one); + VK_SHADER_STAGE_VERTEX_BIT, 24, 4,&ctx->pushConsts.fsq_patternType); CmdDraw (ctx->cmd,3,1,firstVertIdx,0); + ctx->pushConsts.fsq_patternType &= ~FULLSCREEN_BIT; CmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout, - VK_SHADER_STAGE_VERTEX_BIT, 28, 4,&zero); + VK_SHADER_STAGE_VERTEX_BIT, 24, 4,&ctx->pushConsts.fsq_patternType); if (us) CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds); diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 69ae574..69cb9ec 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -49,7 +49,8 @@ #define VKVG_VK_INDEX_TYPE VK_INDEX_TYPE_UINT32 #endif - +#define FULLSCREEN_BIT 0x10000000 +#define SRCTYPE_MASK 0x000000FF #define CreateRgba(r, g, b, a) ((a << 24) | (r << 16) | (g << 8) | b) #ifdef VKVG_PREMULT_ALPHA @@ -67,8 +68,8 @@ typedef struct{ typedef struct { vec4 source; vec2 size; - uint32_t patternType; - uint32_t fullScreenQuad; + uint32_t fsq_patternType; + float opacity; vkvg_matrix_t mat; vkvg_matrix_t matInv; }push_constants; @@ -155,6 +156,7 @@ typedef struct _vkvg_context_t { uint32_t sizePathes; uint32_t segmentPtr; //current segment count in current path having curves + uint32_t subpathCount; //store count of subpath, not straight forward to retrieve from segmented path array float lineWidth; uint32_t dashCount; //value count in dash array, 0 if dash not set. diff --git a/src/vkvg_pattern.c b/src/vkvg_pattern.c index 06ae0b7..5536d1e 100644 --- a/src/vkvg_pattern.c +++ b/src/vkvg_pattern.c @@ -177,6 +177,16 @@ vkvg_status_t vkvg_pattern_get_color_stop_rgba (VkvgPattern pat, uint32_t index, *a = c.a; return VKVG_STATUS_SUCCESS; } +void vkvg_pattern_set_matrix (VkvgPattern pat, const vkvg_matrix_t* matrix) { + pat->matrix = *matrix; + pat->hasMatrix = true; +} +void vkvg_pattern_get_matrix (VkvgPattern pat, vkvg_matrix_t* matrix) { + if (pat->hasMatrix) + *matrix = pat->matrix; + else + *matrix = VKVG_IDENTITY_MATRIX; +} void vkvg_pattern_destroy(VkvgPattern pat) { diff --git a/src/vkvg_pattern.h b/src/vkvg_pattern.h index e437030..bc5fb76 100644 --- a/src/vkvg_pattern.h +++ b/src/vkvg_pattern.h @@ -30,6 +30,8 @@ typedef struct _vkvg_pattern_t { vkvg_pattern_type_t type; vkvg_extend_t extend; vkvg_filter_t filter; + vkvg_matrix_t matrix; + bool hasMatrix; void* data; uint32_t references; }vkvg_pattern_t; diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c index 04325bc..c059136 100644 --- a/src/vkvg_surface.c +++ b/src/vkvg_surface.c @@ -157,7 +157,7 @@ VkvgSurface vkvg_surface_create_from_bitmap (VkvgDevice dev, unsigned char* img, vec4 srcRect = {.x=0,.y=0,.width=(float)surf->width,.height=(float)surf->height}; ctx->pushConsts.source = srcRect; - ctx->pushConsts.patternType = VKVG_PATTERN_TYPE_SURFACE; + ctx->pushConsts.fsq_patternType = (ctx->pushConsts.fsq_patternType & FULLSCREEN_BIT) + VKVG_PATTERN_TYPE_SURFACE; //_update_push_constants (ctx); _update_descriptor_set (ctx, tmpImg, ctx->dsSrc); |