summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee.scm4
-rw-r--r--chickadee/render.scm6
-rw-r--r--chickadee/render/viewport.scm7
3 files changed, 12 insertions, 5 deletions
diff --git a/chickadee.scm b/chickadee.scm
index 4edeb03..e7fb443 100644
--- a/chickadee.scm
+++ b/chickadee.scm
@@ -321,10 +321,8 @@ border is disabled, otherwise it is enabled.")
;; Free any GPU resources that have been GC'd.
(gpu-reap!))
(define (render-sdl-opengl alpha)
- ;; Switch to the default viewport so we can clear the whole screen.
- (set-gpu-viewport! gpu default-viewport)
- (gl-clear clear-mask)
(with-viewport default-viewport
+ (clear-screen)
(with-projection default-projection
(draw alpha)))
(sdl2:swap-gl-window window))
diff --git a/chickadee/render.scm b/chickadee/render.scm
index 49244f9..04295e6 100644
--- a/chickadee/render.scm
+++ b/chickadee/render.scm
@@ -43,6 +43,7 @@
with-depth-test
with-texture
with-projection
+ clear-screen
gpu-apply
gpu-apply*
gpu-apply/instanced*
@@ -95,6 +96,11 @@
(with (render-context-viewport set-render-context-viewport! viewport)
body ...))
+(define (clear-screen)
+ (let ((viewport (current-viewport)))
+ (set-gpu-viewport! (current-gpu) viewport)
+ (clear-viewport viewport)))
+
(define-syntax-rule (with-framebuffer framebuffer body ...)
(with (render-context-framebuffer set-render-context-framebuffer! framebuffer)
;; As a convenience, initialize the viewport and projection
diff --git a/chickadee/render/viewport.scm b/chickadee/render/viewport.scm
index e61136d..91f50c1 100644
--- a/chickadee/render/viewport.scm
+++ b/chickadee/render/viewport.scm
@@ -39,6 +39,7 @@
viewport-clear-flags
null-viewport
apply-viewport
+ clear-viewport
%default-clear-flags
%default-clear-color))
@@ -92,6 +93,9 @@ CLEAR-FLAGS are 'color-buffer', 'depth-buffer', 'accum-buffer', and
('color-buffer 16384))
flags)))))
+(define (clear-viewport viewport)
+ (gl-clear (clear-buffer-mask (viewport-clear-flags viewport))))
+
(define (apply-viewport viewport)
"Set the OpenGL state for VIEWPORT. Clip rendering to the viewport
area, set the clear color, and clear necessary buffers."
@@ -104,5 +108,4 @@ area, set the clear color, and clear necessary buffers."
(gl-enable (enable-cap scissor-test))
(gl-viewport x y w h)
(gl-scissor x y w h)
- (gl-clear-color (color-r c) (color-g c) (color-b c) (color-a c))
- (gl-clear (clear-buffer-mask (viewport-clear-flags viewport))))))
+ (gl-clear-color (color-r c) (color-g c) (color-b c) (color-a c)))))