diff options
-rw-r--r-- | chickadee/graphics/framebuffer.scm | 35 | ||||
-rw-r--r-- | chickadee/graphics/gpu.scm | 29 |
2 files changed, 33 insertions, 31 deletions
diff --git a/chickadee/graphics/framebuffer.scm b/chickadee/graphics/framebuffer.scm index f4f3100..2af7edd 100644 --- a/chickadee/graphics/framebuffer.scm +++ b/chickadee/graphics/framebuffer.scm @@ -23,12 +23,9 @@ #:use-module (ice-9 match) #:use-module (srfi srfi-9) #:use-module (system foreign) - #:use-module (gl) - #:use-module (gl enums) #:use-module (chickadee math matrix) #:use-module (chickadee graphics color) #:use-module (chickadee graphics engine) - #:use-module (chickadee graphics gl) #:use-module (chickadee graphics gpu) #:use-module (chickadee graphics pixbuf) #:use-module ((chickadee graphics texture) #:select (make-texture null-texture)) @@ -39,7 +36,6 @@ framebuffer-viewport framebuffer-projection null-framebuffer - g:framebuffer current-framebuffer with-framebuffer)) @@ -56,7 +52,6 @@ (%make-framebuffer 0 0 null-texture null-viewport (make-identity-matrix4))) (define %clear-color (transparency 0.0)) -(define %draw-buffers (bytevector->pointer (u32vector (version-3-0 color-attachment0)))) (define* (make-framebuffer width height #:key (min-filter 'linear) (mag-filter 'linear) (wrap-s 'repeat) (wrap-t 'repeat)) @@ -71,6 +66,8 @@ dimensions WIDTH x HEIGHT." #:mag-filter mag-filter #:wrap-s wrap-s #:wrap-t wrap-t)) + (texture-id ((@@ (chickadee graphics texture) texture-id) + texture)) ;; 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 @@ -83,32 +80,8 @@ dimensions WIDTH x HEIGHT." texture viewport projection))) - (set-gpu-renderbuffer! gpu renderbuffer-id) - (set-gpu-framebuffer! gpu framebuffer-id) - ;; Setup depth buffer. - (gl-bind-renderbuffer (version-3-0 renderbuffer) - renderbuffer-id) - (gl-renderbuffer-storage (version-3-0 renderbuffer) - (arb-framebuffer-object depth24-stencil8) - width - height) - (gl-bind-renderbuffer (version-3-0 renderbuffer) 0) - (gl-framebuffer-renderbuffer (version-3-0 framebuffer) - (arb-framebuffer-object depth-stencil-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")) + (gpu-framebuffer-init gpu framebuffer-id renderbuffer-id texture-id + width height) framebuffer)) (define-syntax-rule (with-framebuffer framebuffer body ...) diff --git a/chickadee/graphics/gpu.scm b/chickadee/graphics/gpu.scm index 93aac87..ef12d10 100644 --- a/chickadee/graphics/gpu.scm +++ b/chickadee/graphics/gpu.scm @@ -113,6 +113,7 @@ free-gpu-framebuffer gpu-framebuffer? gpu-framebuffer-id + gpu-framebuffer-init gpu-framebuffer:null fresh-gpu-renderbuffer @@ -1132,6 +1133,34 @@ (set-active-texture-unit! 0) (gl-generate-mipmap (gpu-texture-target texture))) +(define %draw-buffers + (bytevector->pointer (u32vector (version-3-0 color-attachment0)))) + +(define (gpu-framebuffer-init gpu framebuffer renderbuffer texture width height) + (set-gpu-framebuffer! gpu framebuffer) + ;; Setup depth buffer. + (set-gpu-renderbuffer! gpu renderbuffer) + (gl-renderbuffer-storage (version-3-0 renderbuffer) + (arb-framebuffer-object depth24-stencil8) + width + height) + (set-gpu-renderbuffer! gpu gpu-renderbuffer:null) + (gl-framebuffer-renderbuffer (version-3-0 framebuffer) + (arb-framebuffer-object depth-stencil-attachment) + (version-3-0 renderbuffer) + renderbuffer) + ;; Setup framebuffer texture. + (gl-framebuffer-texture-2d (version-3-0 framebuffer) + (version-3-0 color-attachment0) + (texture-target texture-2d) + (gpu-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"))) + (define (gpu-buffer-upload gpu buffer usage data length offset) (set-gpu-buffer! gpu buffer) (gl-buffer-data (gpu-buffer-target buffer) |