diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-03-14 10:30:49 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-03-14 10:30:49 -0400 |
commit | 6c652d155fe6af7af0d151c5187b8c4ed8abba2b (patch) | |
tree | f2348002e504c5a1cf19c721b2736ce46d962401 | |
parent | 0c017ecd3491d062d63ffa2e87d9198f5fd392b2 (diff) |
graphics: Rewrite with-graphics-state to use state specs.
Treating the names inside the let-like form as just symbols caused
numerous bugs where a program would crash because it was trying to set
graphics state that was never defined due to the relevant module never
being imported. By changing with-graphics-state to require passing in
the <graphics-state-spec> object, much like how parameterize works
with parameter objects, it completely eliminates this type of bug. If
the module containing the spec variable isn't imported, there will be
an undefined variable error thrown early on.
Additionally, graphics state objects needed to have a stack added to
them to track previous values so that with-graphics-state could
restore them later. The old trick of using let to stash the previous
values no longer worked with the new macro implementation.
-rw-r--r-- | chickadee.scm | 2 | ||||
-rw-r--r-- | chickadee/graphics/blend.scm | 5 | ||||
-rw-r--r-- | chickadee/graphics/buffer.scm | 22 | ||||
-rw-r--r-- | chickadee/graphics/color.scm | 3 | ||||
-rw-r--r-- | chickadee/graphics/depth.scm | 3 | ||||
-rw-r--r-- | chickadee/graphics/engine.scm | 72 | ||||
-rw-r--r-- | chickadee/graphics/framebuffer.scm | 9 | ||||
-rw-r--r-- | chickadee/graphics/model.scm | 2 | ||||
-rw-r--r-- | chickadee/graphics/multisample.scm | 5 | ||||
-rw-r--r-- | chickadee/graphics/particles.scm | 5 | ||||
-rw-r--r-- | chickadee/graphics/path.scm | 15 | ||||
-rw-r--r-- | chickadee/graphics/pbr.scm | 2 | ||||
-rw-r--r-- | chickadee/graphics/phong.scm | 8 | ||||
-rw-r--r-- | chickadee/graphics/polygon.scm | 6 | ||||
-rw-r--r-- | chickadee/graphics/shader.scm | 5 | ||||
-rw-r--r-- | chickadee/graphics/sprite.scm | 8 | ||||
-rw-r--r-- | chickadee/graphics/stencil.scm | 3 | ||||
-rw-r--r-- | chickadee/graphics/texture.scm | 14 | ||||
-rw-r--r-- | chickadee/graphics/viewport.scm | 3 |
19 files changed, 124 insertions, 68 deletions
diff --git a/chickadee.scm b/chickadee.scm index 489fd0b..a8251f3 100644 --- a/chickadee.scm +++ b/chickadee.scm @@ -369,7 +369,7 @@ border is disabled, otherwise it is enabled.") ;; Free any GPU resources that have been GC'd. (graphics-engine-reap! gfx)) (define (render-sdl-opengl alpha) - (with-graphics-state! ((viewport (atomic-box-ref default-viewport))) + (with-graphics-state! ((g:viewport (atomic-box-ref default-viewport))) (clear-viewport) (with-projection (atomic-box-ref default-projection) (draw alpha))) diff --git a/chickadee/graphics/blend.scm b/chickadee/graphics/blend.scm index a189210..8901246 100644 --- a/chickadee/graphics/blend.scm +++ b/chickadee/graphics/blend.scm @@ -20,7 +20,8 @@ #:use-module (gl) #:use-module (chickadee graphics engine) #:use-module (chickadee graphics gl) - #:export (current-blend-mode)) + #:export (g:blend-mode + current-blend-mode)) (define (bind-blend-mode blend-mode) (if blend-mode @@ -62,7 +63,7 @@ (blending-factor-dest zero))))) (gl-disable (enable-cap blend)))) -(define-graphics-state blend-mode +(define-graphics-state g:blend-mode current-blend-mode #:default 'replace #:bind bind-blend-mode) diff --git a/chickadee/graphics/buffer.scm b/chickadee/graphics/buffer.scm index 37a77e4..3ce1d76 100644 --- a/chickadee/graphics/buffer.scm +++ b/chickadee/graphics/buffer.scm @@ -47,6 +47,7 @@ buffer-usage buffer-data null-buffer + g:buffer current-buffer map-buffer! unmap-buffer! @@ -85,6 +86,7 @@ vertex-array-attributes vertex-array-mode null-vertex-array + g:vertex-array current-vertex-array render-vertices render-vertices/instanced @@ -153,7 +155,7 @@ #:predicate buffer? #:free free-buffer) -(define-graphics-state buffer +(define-graphics-state g:buffer current-buffer #:default null-buffer #:bind bind-buffer) @@ -207,7 +209,7 @@ never sent to the GPU." (assert-current-graphics-engine) ;; Weird bugs will occur when creating a new vertex buffer while a ;; vertex array is bound. - (with-graphics-state! ((vertex-array null-vertex-array)) + (with-graphics-state! ((g:vertex-array null-vertex-array)) (let ((buffer (%make-buffer (generate-buffer-gl) name length @@ -216,7 +218,7 @@ never sent to the GPU." usage #f))) (graphics-engine-guard! buffer) - (with-graphics-state! ((buffer buffer)) + (with-graphics-state! ((g:buffer buffer)) (gl-buffer-data (buffer-target-gl buffer) length (if data @@ -237,7 +239,7 @@ vertex buffer data back to the GPU." (unless (buffer-mapped? buffer) ;; Don't map a buffer that is already mapped! (let ((target (buffer-target-gl buffer)) (length (buffer-length buffer))) - (with-graphics-state! ((buffer buffer)) + (with-graphics-state! ((g:buffer buffer)) (when (eq? (buffer-usage buffer) 'stream) ;; Orphan the buffer to avoid implicit synchronization. ;; See: https://www.opengl.org/wiki/Buffer_Object_Streaming#Buffer_re-specification @@ -250,7 +252,7 @@ vertex buffer data back to the GPU." (define (unmap-buffer! buffer) "Return the mapped vertex buffer data for BUFFER to the GPU." - (with-graphics-state! ((buffer buffer)) + (with-graphics-state! ((g:buffer buffer)) (gl-unmap-buffer (buffer-target-gl buffer)) (set-buffer-data! buffer #f))) @@ -484,7 +486,7 @@ element is used for 2 instances, and so on." ('double (data-type double)))) (define* (apply-buffer-view buffer-view #:optional attribute-index) - (with-graphics-state! ((buffer (buffer-view->buffer buffer-view))) + (with-graphics-state! ((g:buffer (buffer-view->buffer buffer-view))) ;; If there is no attribute-index, we assume this is being bound for ;; use as an index buffer. (when attribute-index @@ -540,7 +542,7 @@ element is used for 2 instances, and so on." #:predicate vertex-array? #:free free-vertex-array) -(define-graphics-state vertex-array +(define-graphics-state g:vertex-array current-vertex-array #:default null-vertex-array #:bind bind-vertex-array) @@ -568,7 +570,7 @@ argument may be overridden. The following values are supported: attributes mode))) (graphics-engine-guard! array) - (with-graphics-state! ((vertex-array array)) + (with-graphics-state! ((g:vertex-array array)) (for-each (match-lambda ((index . buffer-view) (apply-buffer-view buffer-view index))) @@ -589,7 +591,7 @@ argument may be overridden. The following values are supported: ('triangle-fan (begin-mode triangle-fan)))) (define* (render-vertices array #:key count (offset 0)) - (with-graphics-state! ((vertex-array array)) + (with-graphics-state! ((g:vertex-array array)) (let ((indices (vertex-array-indices array))) (if indices (begin @@ -602,7 +604,7 @@ argument may be overridden. The following values are supported: (gl-draw-arrays (vertex-array-mode-gl array) offset count))))) (define* (render-vertices/instanced array instances #:key count (offset 0)) - (with-graphics-state! ((vertex-array array)) + (with-graphics-state! ((g:vertex-array array)) (let ((indices (vertex-array-indices array))) (if indices (begin diff --git a/chickadee/graphics/color.scm b/chickadee/graphics/color.scm index e2766df..a43c7f0 100644 --- a/chickadee/graphics/color.scm +++ b/chickadee/graphics/color.scm @@ -116,6 +116,7 @@ default-color-mask null-color-mask + g:color-mask current-color-mask color-mask? color-mask-red? @@ -357,7 +358,7 @@ a color object." (color-mask-blue? mask) (color-mask-alpha? mask))) -(define-graphics-state color-mask +(define-graphics-state g:color-mask current-color-mask #:default default-color-mask #:bind bind-color-mask) diff --git a/chickadee/graphics/depth.scm b/chickadee/graphics/depth.scm index a67d079..8979997 100644 --- a/chickadee/graphics/depth.scm +++ b/chickadee/graphics/depth.scm @@ -27,6 +27,7 @@ depth-test-function depth-test-near depth-test-far + g:depth-test current-depth-test)) (define-record-type <depth-test> @@ -57,7 +58,7 @@ (gl-depth-range (depth-test-near depth-test) (depth-test-far depth-test))) (gl-disable (enable-cap depth-test)))) -(define-graphics-state depth-test +(define-graphics-state g:depth-test current-depth-test #:default #f #:bind bind-depth-test) diff --git a/chickadee/graphics/engine.scm b/chickadee/graphics/engine.scm index 631f792..75cd85f 100644 --- a/chickadee/graphics/engine.scm +++ b/chickadee/graphics/engine.scm @@ -1,4 +1,5 @@ (define-module (chickadee graphics engine) + #:use-module (chickadee array-list) #:use-module (chickadee graphics gl) #:use-module (chickadee math matrix) #:use-module (gl) @@ -51,21 +52,30 @@ (%make-graphics-state-spec name default bind)) (define-record-type <graphics-state> - (%make-graphics-state binder value bound-value dirty?) + (%make-graphics-state binder value bound-value dirty? stack) graphics-state? (binder graphics-state-binder) (value graphics-state-ref %graphics-state-set!) (bound-value graphics-state-bound-value set-graphics-state-bound-value!) - (dirty? graphics-state-dirty? set-graphics-state-dirty!)) + (dirty? graphics-state-dirty? set-graphics-state-dirty!) + (stack graphics-state-stack)) (define (make-graphics-state bind default) - (%make-graphics-state bind default default #f)) + (%make-graphics-state bind default default #f (make-array-list))) (define (graphics-state-set! state new-value) + (graphics-state-binder state) new-value (let ((current-value (graphics-state-bound-value state))) (%graphics-state-set! state new-value) (set-graphics-state-dirty! state (not (eq? new-value current-value))))) +(define (graphics-state-push! state new-value) + (array-list-push! (graphics-state-stack state) (graphics-state-ref state)) + (graphics-state-set! state new-value)) + +(define (graphics-state-pop! state) + (graphics-state-set! state (array-list-pop! (graphics-state-stack state)))) + (define (graphics-state-bind-maybe state) (when (graphics-state-dirty? state) (let ((x (graphics-state-ref state))) @@ -249,6 +259,27 @@ name #t))) +(define* (graphics-engine-state-push! spec value #:optional + (engine (current-graphics-engine))) + (if (graphics-state-spec? spec) + (let ((name (graphics-state-spec-name spec))) + (graphics-state-push! (hashq-ref (graphics-engine-states engine) name) + value) + (hashq-set! (graphics-engine-modified-states engine) + name + #t)) + (error "not a graphics state specification" spec))) + +(define* (graphics-engine-state-pop! spec #:optional + (engine (current-graphics-engine))) + (if (graphics-state-spec? spec) + (let ((name (graphics-state-spec-name spec))) + (graphics-state-pop! (hashq-ref (graphics-engine-states engine) name)) + (hashq-set! (graphics-engine-modified-states engine) + name + #t)) + (error "not a graphics state specification" spec))) + (define* (graphics-variable-ref var #:optional (engine (current-graphics-engine))) (hashq-ref (graphics-engine-variables engine) var)) @@ -282,18 +313,27 @@ (error "no finalizer for graphics engine object" obj)) (loop (guardian)))))) -(define-syntax-rule (with-graphics-state ((name value) ...) body ...) - (let ((thunk (lambda () - (graphics-engine-state-set! 'name value) ... - body ...)) - (name (graphics-engine-state-ref 'name)) - ...) - (let ((result (thunk))) - ;; Restore old values - (graphics-engine-state-set! 'name name) ... - result))) - -(define-syntax-rule (with-graphics-state! ((name value) ...) body ...) - (with-graphics-state ((name value) ...) +(define-syntax-rule (with-graphics-state ((spec value) ...) body ...) + (dynamic-wind + (lambda () + (graphics-engine-state-push! spec value) ...) + (lambda () + body ...) + (lambda () + (graphics-engine-state-pop! spec) ...))) + +;; (define-syntax-rule (with-graphics-state ((spec value) ...) body ...) +;; (let ((thunk (lambda () +;; (graphics-engine-state-set! (graphics-state-spec-name spec) value) ... +;; body ...)) +;; (spec (graphics-engine-state-ref (graphics-state-spec-name spec))) +;; ...) +;; (let ((result (thunk))) +;; ;; Restore old values +;; (graphics-engine-state-set! (graphics-state-spec-name spec) spec) ... +;; result))) + +(define-syntax-rule (with-graphics-state! ((spec value) ...) body ...) + (with-graphics-state ((spec value) ...) (graphics-engine-commit!) body ...)) diff --git a/chickadee/graphics/framebuffer.scm b/chickadee/graphics/framebuffer.scm index da99223..d030f41 100644 --- a/chickadee/graphics/framebuffer.scm +++ b/chickadee/graphics/framebuffer.scm @@ -39,6 +39,7 @@ framebuffer-viewport framebuffer-projection null-framebuffer + g:framebuffer current-framebuffer with-framebuffer)) @@ -88,7 +89,7 @@ #:predicate framebuffer? #:free free-framebuffer) -(define-graphics-state framebuffer +(define-graphics-state g:framebuffer current-framebuffer #:default null-framebuffer #:bind bind-framebuffer) @@ -122,7 +123,7 @@ dimensions WIDTH x HEIGHT." viewport projection))) (graphics-engine-guard! framebuffer) - (with-graphics-state! ((framebuffer framebuffer)) + (with-graphics-state! ((g:framebuffer framebuffer)) ;; Setup depth buffer. (gl-bind-renderbuffer (version-3-0 renderbuffer) renderbuffer-id) @@ -153,7 +154,7 @@ dimensions WIDTH x HEIGHT." ;; as well so that the user doesn't have to explicitly make a ;; viewport and/or projection matrix unless they actually want to do ;; fancy viewport manipulations. - (with-graphics-state ((framebuffer framebuffer) - (viewport (framebuffer-viewport framebuffer))) + (with-graphics-state ((g:framebuffer framebuffer) + (g:viewport (framebuffer-viewport framebuffer))) (with-projection (framebuffer-projection framebuffer) body ...))) diff --git a/chickadee/graphics/model.scm b/chickadee/graphics/model.scm index 0aff08d..201ef8c 100644 --- a/chickadee/graphics/model.scm +++ b/chickadee/graphics/model.scm @@ -176,7 +176,7 @@ (define %depth-test (make-depth-test)) (define (draw-model model model-matrix view-matrix) - (with-graphics-state ((depth-test %depth-test)) + (with-graphics-state ((g:depth-test %depth-test)) (let ((state (model-render-state model))) (render-state-reset! state) (render-state-view-matrix-mult! state view-matrix) diff --git a/chickadee/graphics/multisample.scm b/chickadee/graphics/multisample.scm index aa66d2e..50c00dd 100644 --- a/chickadee/graphics/multisample.scm +++ b/chickadee/graphics/multisample.scm @@ -24,14 +24,15 @@ (define-module (chickadee graphics multisample) #:use-module (chickadee graphics engine) #:use-module (gl) - #:export (current-multisample)) + #:export (g:multisample? + current-multisample)) (define (bind-multisample multisample?) (if multisample? (gl-enable (version-1-3 multisample)) (gl-disable (version-1-3 multisample)))) -(define-graphics-state multisample? +(define-graphics-state g:multisample? current-multisample #:default #f #:bind bind-multisample) diff --git a/chickadee/graphics/particles.scm b/chickadee/graphics/particles.scm index b19804c..d735572 100644 --- a/chickadee/graphics/particles.scm +++ b/chickadee/graphics/particles.scm @@ -26,6 +26,7 @@ #:use-module (chickadee math matrix) #:use-module (chickadee math rect) #:use-module (chickadee math vector) + #:use-module (chickadee graphics blend) #:use-module (chickadee graphics buffer) #:use-module (chickadee graphics color) #:use-module (chickadee graphics engine) @@ -432,8 +433,8 @@ default. (let ((shader (graphics-variable-ref particles-shader)) (mvp (graphics-variable-ref mvp-matrix)) (geometry (particles-geometry particles))) - (with-graphics-state ((blend-mode (particles-blend-mode particles)) - (texture-0 (particles-texture particles))) + (with-graphics-state ((g:blend-mode (particles-blend-mode particles)) + (g:texture-0 (particles-texture particles))) (shader-apply/instanced shader (geometry-vertex-array geometry) (particles-size particles) diff --git a/chickadee/graphics/path.scm b/chickadee/graphics/path.scm index 562f4a9..8a4edfd 100644 --- a/chickadee/graphics/path.scm +++ b/chickadee/graphics/path.scm @@ -39,7 +39,6 @@ #:use-module (chickadee math rect) #:use-module (chickadee math vector) #:use-module (chickadee utils) - #:use-module (gl) #:use-module (ice-9 match) #:use-module ((rnrs base) #:select (mod)) #:use-module (rnrs bytevectors) @@ -1113,7 +1112,7 @@ (matrix4-mult! mvp matrix (current-projection)) ;; Wireframe debug mode. (when *debug?* - (with-graphics-state ((polygon-mode line-polygon-mode)) + (with-graphics-state ((g:polygon-mode line-polygon-mode)) (for-range ((i n)) (shader-apply* shader (geometry-vertex-array stencil-geometry) @@ -1122,7 +1121,7 @@ #:mvp (current-projection) #:mode 0)))) ;; Anti-alias the edges of the fill. - (with-graphics-state ((multisample? #t)) + (with-graphics-state ((g:multisample? #t)) ;; Render fan to stencil buffer. Each time a triangle is ;; rasterized, it flips the values in the stencil buffer for ;; those fragments. So, the first time a triangle is rendered, @@ -1134,8 +1133,8 @@ ;; ;; For more information, see: ;; http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/opengl/gpupathrender.pdf - (with-graphics-state ((color-mask null-color-mask) - (stencil-test stencil-flip)) + (with-graphics-state ((g:color-mask null-color-mask) + (g:stencil-test stencil-flip)) (for-range ((i n)) (shader-apply* shader (geometry-vertex-array stencil-geometry) @@ -1146,8 +1145,8 @@ ;; Render a quad with the stencil applied. The quad is the size ;; of the path's bounding box. The stencil test will make it so ;; we only draw fragments that are part of the filled path. - (with-graphics-state ((stencil-test stencil-cover-and-clear) - (blend-mode (filled-path-blend-mode filled-path))) + (with-graphics-state ((g:stencil-test stencil-cover-and-clear) + (g:blend-mode (filled-path-blend-mode filled-path))) (shader-apply shader (geometry-vertex-array quad-geometry) #:mvp mvp @@ -1160,7 +1159,7 @@ (let ((shader (graphics-variable-ref path-shader)) (mvp (graphics-variable-ref mvp-matrix))) (matrix4-mult! mvp matrix (current-projection)) - (with-graphics-state ((blend-mode (stroked-path-blend-mode stroked-path))) + (with-graphics-state ((g:blend-mode (stroked-path-blend-mode stroked-path))) (let ((geometry (stroked-path-geometry stroked-path))) (shader-apply* shader (geometry-vertex-array geometry) diff --git a/chickadee/graphics/pbr.scm b/chickadee/graphics/pbr.scm index b28d594..78d1b10 100644 --- a/chickadee/graphics/pbr.scm +++ b/chickadee/graphics/pbr.scm @@ -139,7 +139,7 @@ void main (void) { (define (shader-apply/pbr vertex-array material model-matrix view-matrix) (let ((shader (graphics-variable-ref pbr-shader))) - (with-graphics-state ((texture-0 (pbr-material-base-color-texture material))) + (with-graphics-state ((g:texture-0 (pbr-material-base-color-texture material))) (shader-apply shader vertex-array #:model model-matrix #:view view-matrix diff --git a/chickadee/graphics/phong.scm b/chickadee/graphics/phong.scm index 150d6a1..acd238c 100644 --- a/chickadee/graphics/phong.scm +++ b/chickadee/graphics/phong.scm @@ -238,10 +238,10 @@ void main() { (define (shader-apply/phong vertex-array material model-matrix view-matrix) (let ((shader (graphics-variable-ref phong-shader))) - (with-graphics-state ((texture-0 (phong-material-ambient-map material)) - (texture-1 (phong-material-diffuse-map material)) - (texture-2 (phong-material-specular-map material)) - (texture-3 (phong-material-bump-map material))) + (with-graphics-state ((g:texture-0 (phong-material-ambient-map material)) + (g:texture-1 (phong-material-diffuse-map material)) + (g:texture-2 (phong-material-specular-map material)) + (g:texture-3 (phong-material-bump-map material))) (shader-apply shader vertex-array #:model model-matrix #:view view-matrix diff --git a/chickadee/graphics/polygon.scm b/chickadee/graphics/polygon.scm index 1b6a5a7..69d9f83 100644 --- a/chickadee/graphics/polygon.scm +++ b/chickadee/graphics/polygon.scm @@ -34,6 +34,7 @@ fill-polygon-mode line-polygon-mode point-polygon-mode + g:polygon-mode current-polygon-mode make-cull-face-mode @@ -44,6 +45,7 @@ back-cull-face-mode front-cull-face-mode front-and-back-cull-face-mode + g:cull-face-mode current-cull-face-mode)) (define-record-type <polygon-mode> @@ -70,7 +72,7 @@ (gl-polygon-mode (cull-face-mode front) (glmode front)) (gl-polygon-mode (cull-face-mode back) (glmode back)))))) -(define-graphics-state polygon-mode +(define-graphics-state g:polygon-mode current-polygon-mode #:default fill-polygon-mode #:bind bind-polygon-mode) @@ -102,7 +104,7 @@ (else (gl-disable (enable-cap cull-face)))))) -(define-graphics-state cull-face-mode +(define-graphics-state g:cull-face-mode current-cull-face-mode #:default back-cull-face-mode #:bind bind-cull-face-mode) diff --git a/chickadee/graphics/shader.scm b/chickadee/graphics/shader.scm index 9b2070b..1ce0c45 100644 --- a/chickadee/graphics/shader.scm +++ b/chickadee/graphics/shader.scm @@ -54,6 +54,7 @@ make-shader shader? null-shader + g:shader current-shader load-shader strings->shader @@ -481,7 +482,7 @@ #:predicate shader? #:free free-shader) -(define-graphics-state shader +(define-graphics-state g:shader current-shader #:default null-shader #:bind bind-shader) @@ -841,7 +842,7 @@ shader program." (uniform-apply shader rest))))))) (define-syntax-rule (shader-apply** shader* vertex-array uniforms exp) - (with-graphics-state! ((shader shader*)) + (with-graphics-state! ((g:shader shader*)) (uniform-apply shader* uniforms) ;; Sampler2D values aren't explicitly passed as uniform values via ;; shader-apply, so we have to bind them to the proper texture units diff --git a/chickadee/graphics/sprite.scm b/chickadee/graphics/sprite.scm index cdb0ed9..76ee94a 100644 --- a/chickadee/graphics/sprite.scm +++ b/chickadee/graphics/sprite.scm @@ -130,8 +130,8 @@ void main (void) { (x2 y2 s2 t1) (x1 y2 s1 t1)) (geometry-index-append! geometry 0 3 2 0 2 1))) - (with-graphics-state ((blend-mode blend-mode) - (texture-0 texture)) + (with-graphics-state ((g:blend-mode blend-mode) + (g:texture-0 texture)) (shader-apply shader (geometry-vertex-array geometry) #:tint tint @@ -341,8 +341,8 @@ may be specified via the TEXTURE-REGION argument." (mvp (graphics-variable-ref sprite-mvp-matrix))) (sprite-batch-flush! batch) (matrix4-mult! mvp matrix (current-projection)) - (with-graphics-state ((blend-mode blend-mode) - (texture-0 (sprite-batch-texture batch))) + (with-graphics-state ((g:blend-mode blend-mode) + (g:texture-0 (sprite-batch-texture batch))) (let ((geometry (sprite-batch-geometry batch))) (shader-apply* shader (geometry-vertex-array geometry) diff --git a/chickadee/graphics/stencil.scm b/chickadee/graphics/stencil.scm index e19307b..6003f93 100644 --- a/chickadee/graphics/stencil.scm +++ b/chickadee/graphics/stencil.scm @@ -38,6 +38,7 @@ stencil-test-on-pass-front stencil-test-on-pass-back default-stencil-test + g:stencil-test current-stencil-test)) (define-record-type <stencil-test> @@ -136,7 +137,7 @@ (symbol->op (stencil-test-on-pass-back stencil)))) (gl-disable (enable-cap stencil-test)))) -(define-graphics-state stencil-test +(define-graphics-state g:stencil-test current-stencil-test #:default default-stencil-test #:bind bind-stencil-test) diff --git a/chickadee/graphics/texture.scm b/chickadee/graphics/texture.scm index f056be8..3ced853 100644 --- a/chickadee/graphics/texture.scm +++ b/chickadee/graphics/texture.scm @@ -48,6 +48,10 @@ texture-gl-rect texture-gl-tex-rect null-texture + g:texture-0 + g:texture-1 + g:texture-2 + g:texture-3 current-texture-0 current-texture-1 current-texture-2 @@ -125,22 +129,22 @@ #:predicate texture? #:free free-texture) -(define-graphics-state texture-0 +(define-graphics-state g:texture-0 current-texture-0 #:default null-texture #:bind (make-bind-texture 0)) -(define-graphics-state texture-1 +(define-graphics-state g:texture-1 current-texture-1 #:default null-texture #:bind (make-bind-texture 1)) -(define-graphics-state texture-2 +(define-graphics-state g:texture-2 current-texture-2 #:default null-texture #:bind (make-bind-texture 2)) -(define-graphics-state texture-3 +(define-graphics-state g:texture-3 current-texture-3 #:default null-texture #:bind (make-bind-texture 3)) @@ -179,7 +183,7 @@ clamp-to-edge. FORMAT specifies the pixel format. Currently only (make-rect 0.0 1.0 1.0 -1.0) (make-rect 0.0 0.0 1.0 1.0))))) (graphics-engine-guard! texture) - (with-graphics-state ((texture-0 texture)) + (with-graphics-state ((g:texture-0 texture)) (graphics-engine-commit!) (gl-texture-parameter (texture-target texture-2d) (texture-parameter-name texture-min-filter) diff --git a/chickadee/graphics/viewport.scm b/chickadee/graphics/viewport.scm index b60a585..ba3b1e9 100644 --- a/chickadee/graphics/viewport.scm +++ b/chickadee/graphics/viewport.scm @@ -39,6 +39,7 @@ viewport-clear-flags null-viewport clear-viewport + g:viewport current-viewport %default-clear-flags %default-clear-color)) @@ -124,7 +125,7 @@ area, and set the clear color.." (gl-scissor x y w h) (gl-clear-color (color-r c) (color-g c) (color-b c) (color-a c))))) -(define-graphics-state viewport +(define-graphics-state g:viewport current-viewport #:default null-viewport #:bind bind-viewport) |