render: framebuffer: Add default projection matrix for convenience.
authorDavid Thompson <dthompson2@worcester.edu>
Mon, 10 Dec 2018 12:52:41 +0000 (07:52 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Mon, 10 Dec 2018 12:54:11 +0000 (07:54 -0500)
* 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.

chickadee/render.scm
chickadee/render/framebuffer.scm

index 140ec66..5b95d1b 100644 (file)
 
 (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 ...))
index a4c98f7..86fc417 100644 (file)
@@ -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*))
     (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)