summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-03-05 08:09:04 -0500
committerDavid Thompson <dthompson2@worcester.edu>2021-03-05 08:09:27 -0500
commit99565fd881b722599d43e515d80bc3df8d249e45 (patch)
tree3d532f053efae6841c1a71d9e93d9dd27cc61d9b
parentbab0bc161e1ecd9ad89e6c3fb9ba646e75b1f594 (diff)
graphics: framebuffer: Refactor make-framebuffer.
Removes unnecessary let-over-lambda.
-rw-r--r--chickadee/graphics/framebuffer.scm103
1 files changed, 51 insertions, 52 deletions
diff --git a/chickadee/graphics/framebuffer.scm b/chickadee/graphics/framebuffer.scm
index 5a8be8d..da99223 100644
--- a/chickadee/graphics/framebuffer.scm
+++ b/chickadee/graphics/framebuffer.scm
@@ -94,60 +94,59 @@
#:bind bind-framebuffer)
(define %clear-color (transparency 0.0))
+(define %draw-buffers (bytevector->pointer (u32vector (version-3-0 color-attachment0))))
-(define make-framebuffer
- (let ((draw-buffers (u32vector (version-3-0 color-attachment0))))
- (lambda* (width height #:key (min-filter 'linear) (mag-filter 'linear)
- (wrap-s 'repeat) (wrap-t 'repeat))
- "Create a new framebuffer that renders to a texture with
+(define* (make-framebuffer width height #:key (min-filter 'linear) (mag-filter 'linear)
+ (wrap-s 'repeat) (wrap-t 'repeat))
+ "Create a new framebuffer that renders to a texture with
dimensions WIDTH x HEIGHT."
- (assert-current-graphics-engine)
- (let* ((framebuffer-id (generate-framebuffer))
- (renderbuffer-id (generate-renderbuffer))
- (texture (make-texture #f width height
- #:flip? #t
- #:min-filter min-filter
- #:mag-filter mag-filter
- #:wrap-s wrap-s
- #:wrap-t wrap-t))
- ;; 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 #:clear-color %clear-color))
- (projection (orthographic-projection 0 width height 0 0 1))
- (framebuffer (%make-framebuffer framebuffer-id
- renderbuffer-id
- texture
- viewport
- projection)))
- (graphics-engine-guard! framebuffer)
- (with-graphics-state! ((framebuffer framebuffer))
- ;; Setup depth buffer.
- (gl-bind-renderbuffer (version-3-0 renderbuffer)
- renderbuffer-id)
- (gl-renderbuffer-storage (version-3-0 renderbuffer)
- (pixel-format depth-component)
- width
- height)
- (gl-framebuffer-renderbuffer (version-3-0 framebuffer)
- (arb-framebuffer-object depth-attachment)
- (version-3-0 renderbuffer)
- renderbuffer-id)
- ;; Setup framebuffer.
- (gl-framebuffer-texture-2d (version-3-0 framebuffer)
- (version-3-0 color-attachment0)
- (texture-target texture-2d)
- ((@@ (chickadee graphics texture) texture-id)
- texture)
- 0)
- (gl-draw-buffers 1 (bytevector->pointer draw-buffers)))
- ;; Check for errors.
- (unless (= (gl-check-framebuffer-status (version-3-0 framebuffer))
- (version-3-0 framebuffer-complete))
- (error "Framebuffer cannot be created"))
- framebuffer))))
+ (assert-current-graphics-engine)
+ (let* ((framebuffer-id (generate-framebuffer))
+ (renderbuffer-id (generate-renderbuffer))
+ (texture (make-texture #f width height
+ #:flip? #t
+ #:min-filter min-filter
+ #:mag-filter mag-filter
+ #:wrap-s wrap-s
+ #:wrap-t wrap-t))
+ ;; 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 #:clear-color %clear-color))
+ (projection (orthographic-projection 0 width height 0 0 1))
+ (framebuffer (%make-framebuffer framebuffer-id
+ renderbuffer-id
+ texture
+ viewport
+ projection)))
+ (graphics-engine-guard! framebuffer)
+ (with-graphics-state! ((framebuffer framebuffer))
+ ;; Setup depth buffer.
+ (gl-bind-renderbuffer (version-3-0 renderbuffer)
+ renderbuffer-id)
+ (gl-renderbuffer-storage (version-3-0 renderbuffer)
+ (pixel-format depth-component)
+ width
+ height)
+ (gl-framebuffer-renderbuffer (version-3-0 framebuffer)
+ (arb-framebuffer-object depth-attachment)
+ (version-3-0 renderbuffer)
+ renderbuffer-id)
+ ;; Setup framebuffer.
+ (gl-framebuffer-texture-2d (version-3-0 framebuffer)
+ (version-3-0 color-attachment0)
+ (texture-target texture-2d)
+ ((@@ (chickadee graphics texture) texture-id)
+ texture)
+ 0)
+ (gl-draw-buffers 1 %draw-buffers))
+ ;; Check for errors.
+ (unless (= (gl-check-framebuffer-status (version-3-0 framebuffer))
+ (version-3-0 framebuffer-complete))
+ (error "Framebuffer cannot be created"))
+ framebuffer))
(define-syntax-rule (with-framebuffer framebuffer body ...)
;; As a convenience, initialize the viewport and projection matrix