diff options
-rw-r--r-- | chickadee/graphics/gpu.scm | 13 | ||||
-rw-r--r-- | chickadee/graphics/viewport.scm | 27 |
2 files changed, 18 insertions, 22 deletions
diff --git a/chickadee/graphics/gpu.scm b/chickadee/graphics/gpu.scm index 44ffa7b..93aac87 100644 --- a/chickadee/graphics/gpu.scm +++ b/chickadee/graphics/gpu.scm @@ -26,6 +26,7 @@ #:use-module (gl) #:use-module (ice-9 match) #:use-module (rnrs bytevectors) + #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (system foreign) #:export (blend-mode? @@ -216,6 +217,7 @@ set-gpu-texture! gpu-gc gpu-reset! + gpu-clear-viewport gpu-draw gpu-draw/indexed gpu-draw/instanced @@ -1193,6 +1195,17 @@ (when divisor (gl-vertex-attrib-divisor index divisor))) +(define (gpu-clear-viewport flags) + (gl-clear + (fold (lambda (flag result) + (logior (match flag + ('depth-buffer 256) + ('accum-buffer 512) + ('stencil-buffer 1024) + ('color-buffer 16384)) + result)) + 0 flags))) + (define (gpu-draw gpu mode count offset) (gl-draw-arrays (symbol->begin-mode mode) offset count)) diff --git a/chickadee/graphics/viewport.scm b/chickadee/graphics/viewport.scm index 4258e05..9d93c0e 100644 --- a/chickadee/graphics/viewport.scm +++ b/chickadee/graphics/viewport.scm @@ -22,12 +22,10 @@ (define-module (chickadee graphics viewport) #:use-module (ice-9 match) #:use-module (srfi srfi-9) - #:use-module (gl) #:use-module (chickadee utils) #:use-module (chickadee graphics color) #:use-module (chickadee graphics engine) #:use-module (chickadee graphics gpu) - #:use-module (chickadee graphics gl) #:export (make-viewport viewport? viewport-rect @@ -40,12 +38,11 @@ %default-clear-color)) (define-record-type <viewport> - (%make-viewport rect clear-color clear-flags clear-mask) + (%make-viewport rect clear-color clear-flags) viewport? (rect viewport-rect) (clear-color viewport-clear-color) - (clear-flags viewport-clear-flags) - (clear-mask viewport-clear-mask)) + (clear-flags viewport-clear-flags)) (define %default-clear-flags '(color-buffer depth-buffer stencil-buffer)) ;; Just a fun color from the Dawnbringer 32-color palette instead of @@ -57,19 +54,6 @@ n (error "expecting non-negative integer:" n))) -;; TODO: This is gross. Get rid of it. -(define clear-buffer-mask - (memoize - (lambda (flags) - (apply logior - ;; Map symbols to OpenGL constants. - (map (match-lambda - ('depth-buffer 256) - ('accum-buffer 512) - ('stencil-buffer 1024) - ('color-buffer 16384)) - flags))))) - (define* (make-viewport x y width height #:key (clear-color %default-clear-color) (clear-flags %default-clear-flags)) @@ -84,8 +68,7 @@ CLEAR-FLAGS are 'color-buffer', 'depth-buffer', 'accum-buffer', and (assert-non-negative-integer width) (assert-non-negative-integer height)) clear-color - clear-flags - (clear-buffer-mask clear-flags))) + clear-flags)) (define null-viewport (make-viewport 0 0 0 0)) @@ -95,7 +78,7 @@ CLEAR-FLAGS are 'color-buffer', 'depth-buffer', 'accum-buffer', and (clear-color (viewport-clear-color viewport))) body ...))) -;; TODO: Add clear buffer mask to managed gpu state. +;; TODO: Use current viewport's clear flags. (define (clear-viewport) (graphics-engine-commit! (current-graphics-engine)) - (gl-clear (clear-buffer-mask %default-clear-flags))) + (gpu-clear-viewport %default-clear-flags)) |