]> O.S.I.I.S - jp/vkvg.git/commitdiff
matrix operations on context
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 25 Apr 2018 16:02:18 +0000 (18:02 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 25 Apr 2018 16:02:18 +0000 (18:02 +0200)
include/vkvg.h
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h

index c7505916b0f0404509394e47165801d9fd2eba44..d1de356fa0bbc27e3ee54e7cdde00351157d9496 100644 (file)
@@ -181,6 +181,10 @@ void vkvg_restore           (VkvgContext ctx);
 void vkvg_translate         (VkvgContext ctx, float dx, float dy);
 void vkvg_scale             (VkvgContext ctx, float sx, float sy);
 void vkvg_rotate            (VkvgContext ctx, float radians);
+void vkvg_transform         (VkvgContext ctx, const vkvg_matrix_t* matrix);
+void vkvg_set_matrix        (VkvgContext ctx, const vkvg_matrix_t* matrix);
+void vkvg_get_matrix        (VkvgContext ctx, const vkvg_matrix_t* matrix);
+void vkvg_identity_matrix   (VkvgContext ctx);
 
 //pattern
 VkvgPattern vkvg_pattern_create             ();
index 6410c326d48f76e91ca6843c6dae40bc03ffcd01..6653777b45d0ef8824b0b92d3f628864c2ee5c50 100644 (file)
@@ -163,6 +163,10 @@ void vkvg_new_sub_path (VkvgContext ctx){
 void vkvg_new_path (VkvgContext ctx){
     _clear_path(ctx);
 }
+//path closing is done by setting the endpoint of the path to the same index
+//as the start point.
+//I'll test if closing by adding a new point with the same x,y as the start point
+//would not make more sense.
 void vkvg_close_path (VkvgContext ctx){
     if (_current_path_is_empty(ctx))
         return;
@@ -748,20 +752,31 @@ void vkvg_restore (VkvgContext ctx){
 
 void vkvg_translate (VkvgContext ctx, float dx, float dy){
     vkvg_matrix_translate (&ctx->pushConsts.mat, dx, dy);
-    ctx->pushConsts.matInv = ctx->pushConsts.mat;
-    vkvg_matrix_invert (&ctx->pushConsts.matInv);
-    _update_push_constants (ctx);
+    _set_mat_inv_and_vkCmdPush (ctx);
 }
 void vkvg_scale (VkvgContext ctx, float sx, float sy){
     vkvg_matrix_scale (&ctx->pushConsts.mat, sx, sy);
-    ctx->pushConsts.matInv = ctx->pushConsts.mat;
-    vkvg_matrix_invert (&ctx->pushConsts.matInv);
-    _update_push_constants (ctx);
+    _set_mat_inv_and_vkCmdPush (ctx);
 }
 void vkvg_rotate (VkvgContext ctx, float radians){
     vkvg_matrix_rotate (&ctx->pushConsts.mat, radians);
-    ctx->pushConsts.matInv = ctx->pushConsts.mat;
-    vkvg_matrix_invert (&ctx->pushConsts.matInv);
-    _update_push_constants (ctx);
+    _set_mat_inv_and_vkCmdPush (ctx);
+}
+void vkvg_transform (VkvgContext ctx, const vkvg_matrix_t* matrix) {
+    vkvg_matrix_t res;
+    vkvg_matrix_multiply (&res, &ctx->pushConsts.mat, matrix);
+    ctx->pushConsts.mat = res;
+    _set_mat_inv_and_vkCmdPush (ctx);
+}
+void vkvg_identity_matrix (VkvgContext ctx) {
+    vkvg_matrix_t im = VKVG_IDENTITY_MATRIX;
+    ctx->pushConsts.mat = im;
+    _set_mat_inv_and_vkCmdPush (ctx);
+}
+void vkvg_set_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){
+    ctx->pushConsts.mat = (*matrix);
+    _set_mat_inv_and_vkCmdPush (ctx);
+}
+void vkvg_get_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){
+    memcpy (matrix, &ctx->pushConsts.mat, sizeof(vkvg_matrix_t));
 }
-
index fe2669e1d93a1f4c3138922ec93e3c5ff38ba17d..5c3c3c571fba65430f5dfeb4198e64beebfad5a0 100644 (file)
@@ -248,6 +248,13 @@ void _init_cmd_buff (VkvgContext ctx){
 
     _update_push_constants  (ctx);
 }
+//compute inverse mat used in shader when context matrix has changed
+//then trigger push constants command
+void _set_mat_inv_and_vkCmdPush (VkvgContext ctx) {
+    ctx->pushConsts.matInv = ctx->pushConsts.mat;
+    vkvg_matrix_invert (&ctx->pushConsts.matInv);
+    _update_push_constants (ctx);
+}
 inline void _update_push_constants (VkvgContext ctx) {
     vkCmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout,
                        VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(push_constants),&ctx->pushConsts);
index 995dcf7e35002ea91df55b6096f19bb503971a9b..ba657f805b523d9f9bc3af95a7d24657bc6fe69a 100644 (file)
@@ -177,6 +177,7 @@ void _submit_wait_and_reset_cmd(VkvgContext ctx);
 void _submit_ctx_cmd        (VkvgContext ctx);
 void _wait_and_reset_ctx_cmd(VkvgContext ctx);
 void _update_push_constants (VkvgContext ctx);
+void _set_mat_inv_and_vkCmdPush (VkvgContext ctx);
 
 void _createDescriptorPool  (VkvgContext ctx);
 void _init_descriptor_sets  (VkvgContext ctx);