diff options
author | David Thompson <dthompson2@worcester.edu> | 2020-11-19 08:54:10 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2020-11-19 08:54:10 -0500 |
commit | 5f5d94c63f1f45ebfaca0d454fc73faab57b4114 (patch) | |
tree | b46550238b1522248def754767c154e7d99d6b18 | |
parent | 2dab8e9ce698f5cf80d64ded6511181331ca4731 (diff) |
graphics: path: Allow model-view matrix to be applied to rendered path.
Every other type of rendering operation supports this, so paths should
be no different. This type of transformation, unlike a transformation
applied at the canvas or painter level, can cause a non-smooth output
the matrix scales the result since it's transforming the geometry
as-is rather than building new geometry with all path points
transformed.
-rw-r--r-- | chickadee/graphics/path.scm | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/chickadee/graphics/path.scm b/chickadee/graphics/path.scm index 6eca4ab..3500c15 100644 --- a/chickadee/graphics/path.scm +++ b/chickadee/graphics/path.scm @@ -76,6 +76,7 @@ canvas? set-canvas-painter! set-canvas-matrix! + draw-canvas* draw-canvas)) @@ -1229,12 +1230,14 @@ #:function 'not-equal)) (define *debug?* #f) +(define *mvp* (make-null-matrix4)) ;; TODO: gradients -(define* (draw-filled-path filled-path) +(define* (draw-filled-path filled-path matrix) (let ((counts (filled-path-counts filled-path)) (offsets (filled-path-offsets filled-path)) (n (filled-path-count filled-path))) + (matrix4-mult! *mvp* matrix (current-projection)) ;; Wireframe debug mode. (when *debug?* (begin @@ -1270,7 +1273,7 @@ (filled-path-stencil-vertex-array filled-path) (u32vector-ref offsets i) (u32vector-ref counts i) - #:mvp (current-projection) + #:mvp *mvp* #:mode 0) (loop (+ i 1)))))) ;; Render a quad with the stencil applied. The quad is the size @@ -1280,19 +1283,20 @@ (with-blend-mode (filled-path-blend-mode filled-path) (gpu-apply (force path-shader) (filled-path-quad-vertex-array filled-path) - #:mvp (current-projection) + #:mvp *mvp* #:mode 0 #:color (filled-path-color filled-path))))))) ;; TODO: dashed stroke ;; TODO: miter styles and miter limit -(define* (draw-stroked-path stroked-path) +(define* (draw-stroked-path stroked-path matrix) + (matrix4-mult! *mvp* matrix (current-projection)) (with-blend-mode (stroked-path-blend-mode stroked-path) (gpu-apply* (force path-shader) (stroked-path-vertex-array stroked-path) 0 (stroked-path-index-count stroked-path) - #:mvp (current-projection) + #:mvp *mvp* #:color (stroked-path-color stroked-path) #:mode 1 #:feather (stroked-path-feather stroked-path) @@ -1547,9 +1551,14 @@ (set-canvas-painter! canvas painter) canvas)) -(define (draw-canvas canvas) +(define (draw-canvas* canvas matrix) (array-list-for-each (lambda (i tesselation) (if (filled-path? tesselation) - (draw-filled-path tesselation) - (draw-stroked-path tesselation))) + (draw-filled-path tesselation matrix) + (draw-stroked-path tesselation matrix))) (canvas-tesselated-paths canvas))) + +(define %identity-matrix (make-identity-matrix4)) + +(define (draw-canvas canvas) + (draw-canvas* canvas %identity-matrix)) |