diff options
author | David Thompson <dthompson2@worcester.edu> | 2017-01-19 11:14:19 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2017-01-19 11:14:19 -0500 |
commit | 6a913492a2c08ad6bf6bf6c4b3e5d902f4d189c8 (patch) | |
tree | 9971151f1ea33ae49ee3c4235c033cdbbb28bb5d | |
parent | 20c3c95f0fa01bb674d63354de1042c0be4ca6f8 (diff) |
render: framebuffer: Create and use a default viewport.
-rw-r--r-- | chickadee/render.scm | 7 | ||||
-rw-r--r-- | chickadee/render/framebuffer.scm | 17 |
2 files changed, 19 insertions, 5 deletions
diff --git a/chickadee/render.scm b/chickadee/render.scm index 9588a95..cf8a672 100644 --- a/chickadee/render.scm +++ b/chickadee/render.scm @@ -82,7 +82,12 @@ (with (*current-viewport* viewport) body ...)) (define-syntax-rule (with-framebuffer framebuffer body ...) - (with (*current-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. + (with-viewport (framebuffer-viewport 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 39e4bfa..f96d6ba 100644 --- a/chickadee/render/framebuffer.scm +++ b/chickadee/render/framebuffer.scm @@ -31,9 +31,11 @@ #:use-module (chickadee render gl) #:use-module (chickadee render gpu) #:use-module ((chickadee render texture) #:select (make-texture null-texture)) + #:use-module (chickadee render viewport) #:export (make-framebuffer framebuffer? framebuffer-texture + framebuffer-viewport null-framebuffer apply-framebuffer *framebuffer-state*)) @@ -51,14 +53,15 @@ (u32vector-ref bv 0))) (define-record-type <framebuffer> - (%make-framebuffer id renderbuffer-id texture) + (%make-framebuffer id renderbuffer-id texture viewport) framebuffer? (id framebuffer-id) (renderbuffer-id framebuffer-renderbuffer-id) - (texture framebuffer-texture)) + (texture framebuffer-texture) + (viewport framebuffer-viewport)) (define null-framebuffer - (%make-framebuffer 0 0 null-texture)) + (%make-framebuffer 0 0 null-texture null-viewport)) (define <<framebuffer>> (class-of null-framebuffer)) @@ -95,9 +98,15 @@ 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. + (viewport (make-viewport 0 0 width height)) (framebuffer (%make-framebuffer framebuffer-id renderbuffer-id - texture))) + texture + viewport))) (gpu-state-set! *framebuffer-state* framebuffer) ;; Setup depth buffer. (gl-bind-renderbuffer (version-3-0 renderbuffer) |