diff options
author | David Thompson <dthompson2@worcester.edu> | 2018-12-10 07:52:41 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2018-12-10 07:54:11 -0500 |
commit | a9fab8b732cadac7f3cb305a4fbf845d050587b1 (patch) | |
tree | 63981c40657bc2a1a4d440d5c26522ef1a803c37 | |
parent | c2f9c9615e28fb009f1e0537704645526549b15f (diff) |
render: framebuffer: Add default projection matrix for convenience.
* chickadee/render/framebuffer.scm (<framebuffer>)[projection]: New
field.
(make-framebuffer): Use an orthographic projection the same size as
the framebuffer as the default projection matrix.
* chickadee/render.scm (with-framebuffer): Apply default projection
matrix.
-rw-r--r-- | chickadee/render.scm | 10 | ||||
-rw-r--r-- | chickadee/render/framebuffer.scm | 22 |
2 files changed, 20 insertions, 12 deletions
diff --git a/chickadee/render.scm b/chickadee/render.scm index 140ec66..5b95d1b 100644 --- a/chickadee/render.scm +++ b/chickadee/render.scm @@ -84,11 +84,13 @@ (define-syntax-rule (with-framebuffer framebuffer body ...) (with (*current-framebuffer* framebuffer) - ;; As a convenience, initialize the viewport as well so that - ;; the user doesn't have to explicitly make a viewport unless - ;; they actually want to do fancy viewport manipulations. + ;; As a convenience, initialize the viewport and projection + ;; matrix as well so that the user doesn't have to explicitly + ;; make a viewport and/or projection matrix unless they + ;; actually want to do fancy viewport manipulations. (with-viewport (framebuffer-viewport framebuffer) - body ...))) + (with-projection (framebuffer-projection framebuffer) + body ...)))) (define-syntax-rule (with-blend-mode blend-mode body ...) (with (*current-blend-mode* blend-mode) body ...)) diff --git a/chickadee/render/framebuffer.scm b/chickadee/render/framebuffer.scm index a4c98f7..86fc417 100644 --- a/chickadee/render/framebuffer.scm +++ b/chickadee/render/framebuffer.scm @@ -28,6 +28,7 @@ #:use-module (system foreign) #:use-module (gl) #:use-module (gl enums) + #:use-module (chickadee math matrix) #:use-module (chickadee render gl) #:use-module (chickadee render gpu) #:use-module ((chickadee render texture) #:select (make-texture null-texture)) @@ -36,6 +37,7 @@ framebuffer? framebuffer-texture framebuffer-viewport + framebuffer-projection null-framebuffer apply-framebuffer *framebuffer-state*)) @@ -53,15 +55,16 @@ (u32vector-ref bv 0))) (define-record-type <framebuffer> - (%make-framebuffer id renderbuffer-id texture viewport) + (%make-framebuffer id renderbuffer-id texture viewport projection) framebuffer? (id framebuffer-id) (renderbuffer-id framebuffer-renderbuffer-id) (texture framebuffer-texture) - (viewport framebuffer-viewport)) + (viewport framebuffer-viewport) + (projection framebuffer-projection)) (define null-framebuffer - (%make-framebuffer 0 0 null-texture null-viewport)) + (%make-framebuffer 0 0 null-texture null-viewport (make-identity-matrix4))) (define <<framebuffer>> (class-of null-framebuffer)) @@ -99,15 +102,18 @@ dimensions WIDTH x HEIGHT." #:mag-filter mag-filter #:wrap-s wrap-s #:wrap-t wrap-t)) - ;; It is convenient to make a default viewport for the - ;; framebuffer so that the rendering engine can set it - ;; whenever it changes to this framebuffer, saving users - ;; the trouble of having to this tedious task themselves. + ;; It is convenient to make a default viewport and + ;; projection matrix for the framebuffer so that the + ;; rendering engine can set it whenever it changes to + ;; this framebuffer, saving users the trouble of having + ;; to this tedious task themselves. (viewport (make-viewport 0 0 width height)) + (projection (orthographic-projection 0 width height 0 0 1)) (framebuffer (%make-framebuffer framebuffer-id renderbuffer-id texture - viewport))) + viewport + projection))) (gpu-state-set! *framebuffer-state* framebuffer) ;; Setup depth buffer. (gl-bind-renderbuffer (version-3-0 renderbuffer) |