diff options
author | David Thompson <dthompson2@worcester.edu> | 2020-04-11 22:55:30 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2020-04-11 22:55:30 -0400 |
commit | d150acec04ddff321caae0cff88f6cc26161417c (patch) | |
tree | 69f0d388254983e065140cc1a09d189dc01f4c2f | |
parent | 94823dc194ac805939f91a68ca01d9c778f56b2b (diff) |
render: viewport: Decouple screen clearing from viewport switching.
This makes it possible to a apply a viewport multiple times in a frame
without clearing each time and wiping out part of your work.
-rw-r--r-- | chickadee.scm | 4 | ||||
-rw-r--r-- | chickadee/render.scm | 6 | ||||
-rw-r--r-- | chickadee/render/viewport.scm | 7 |
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))))) |