diff options
author | David Thompson <dthompson2@worcester.edu> | 2020-10-11 23:34:40 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2020-10-12 08:39:45 -0400 |
commit | 138cda7381fbf691e99741428e0b575e1de00a55 (patch) | |
tree | 971fdfb30c5db828479c9b51b8d5454aa7d576b1 | |
parent | f7f60d94cba951d9731b288d75ca7c54c2ee53eb (diff) |
graphics: Add color mask support.
-rw-r--r-- | chickadee/graphics.scm | 16 | ||||
-rw-r--r-- | chickadee/graphics/color.scm | 38 | ||||
-rw-r--r-- | chickadee/graphics/gpu.scm | 17 |
3 files changed, 64 insertions, 7 deletions
diff --git a/chickadee/graphics.scm b/chickadee/graphics.scm index bfa1139..10ff18f 100644 --- a/chickadee/graphics.scm +++ b/chickadee/graphics.scm @@ -25,6 +25,7 @@ #:use-module (chickadee math matrix) #:use-module (chickadee graphics gpu) #:use-module (chickadee graphics blend) + #:use-module (chickadee graphics color) #:use-module (chickadee graphics framebuffer) #:use-module (chickadee graphics shader) #:use-module (chickadee graphics texture) @@ -39,6 +40,7 @@ current-texture current-projection current-multisample + current-color-mask with-viewport with-framebuffer with-blend-mode @@ -47,6 +49,7 @@ with-texture with-projection with-multisample + with-color-mask clear-screen gpu-apply gpu-apply* @@ -55,7 +58,8 @@ (define-record-type <render-context> (make-render-context viewport framebuffer blend-mode depth-test - stencil-test projection multisample? textures) + stencil-test projection multisample? color-mask + textures) render-context? (viewport render-context-viewport set-render-context-viewport!) (framebuffer render-context-framebuffer set-render-context-framebuffer!) @@ -64,6 +68,7 @@ (stencil-test render-context-stencil-test set-render-context-stencil-test!) (projection render-context-projection set-render-context-projection!) (multisample? render-context-multisample? set-render-context-multisample!) + (color-mask render-context-color-mask set-render-context-color-mask!) (textures render-context-textures)) (define render-context @@ -74,6 +79,7 @@ #f (make-identity-matrix4) #f + default-color-mask (make-vector 32 null-texture))) (define (current-viewport) @@ -100,6 +106,9 @@ (define (current-multisample) (render-context-multisample? render-context)) +(define (current-color-mask) + (render-context-color-mask render-context)) + (define-syntax-rule (with (getter setter value) body ...) (let ((prev (getter render-context))) (setter render-context value) @@ -154,6 +163,10 @@ (with (render-context-multisample? set-render-context-multisample! multisample?) body ...)) +(define-syntax-rule (with-color-mask color-mask body ...) + (with (render-context-color-mask set-render-context-color-mask! color-mask) + body ...)) + (define (keyword->string kw) (symbol->string (keyword->symbol kw))) @@ -179,6 +192,7 @@ (set-gpu-depth-test! gpu (current-depth-test)) (set-gpu-stencil-test! gpu (current-stencil-test)) (set-gpu-multisample! gpu (current-multisample)) + (set-gpu-color-mask! gpu (current-color-mask)) (set-gpu-shader! gpu shader) (let loop ((i 0)) (when (< i 32) diff --git a/chickadee/graphics/color.scm b/chickadee/graphics/color.scm index 497ecd3..2e1bf43 100644 --- a/chickadee/graphics/color.scm +++ b/chickadee/graphics/color.scm @@ -22,10 +22,11 @@ ;;; Code: (define-module (chickadee graphics color) + #:use-module (chickadee graphics gl) + #:use-module (chickadee math) #:use-module (ice-9 match) #:use-module (srfi srfi-9) #:use-module (srfi srfi-1) - #:use-module (chickadee math) #:export (make-color color? color-r color-g color-b color-a @@ -41,7 +42,17 @@ tango-light-plum tango-plum tango-dark-plum tango-light-scarlet-red tango-scarlet-red tango-dark-scarlet-red tango-aluminium-1 tango-aluminium-2 tango-aluminium-3 - tango-aluminium-4 tango-aluminium-5 tango-aluminium-6)) + tango-aluminium-4 tango-aluminium-5 tango-aluminium-6 + + make-color-mask + default-color-mask + null-color-mask + color-mask? + color-mask-red? + color-mask-green? + color-mask-blue? + color-mask-alpha? + apply-color-mask)) (define-record-type <color> (wrap-color bv) @@ -171,6 +182,7 @@ a color object." (color+ (color* start (- 1.0 alpha)) (color* end alpha))) + ;;; ;;; Pre-defined Colors ;;; @@ -215,3 +227,25 @@ a color object." (define tango-aluminium-4 (rgb #x888a85)) (define tango-aluminium-5 (rgb #x555753)) (define tango-aluminium-6 (rgb #x2e3436)) + + +;;; +;;; Color Masks +;;; + +(define-record-type <color-mask> + (make-color-mask red? green? blue? alpha?) + color-mask? + (red? color-mask-red?) + (green? color-mask-green?) + (blue? color-mask-blue?) + (alpha? color-mask-alpha?)) + +(define default-color-mask (make-color-mask #t #t #t #t)) +(define null-color-mask (make-color-mask #f #f #f #f)) + +(define (apply-color-mask mask) + (gl-color-mask (color-mask-red? mask) + (color-mask-green? mask) + (color-mask-blue? mask) + (color-mask-alpha? mask))) diff --git a/chickadee/graphics/gpu.scm b/chickadee/graphics/gpu.scm index 7a70d7e..16f5554 100644 --- a/chickadee/graphics/gpu.scm +++ b/chickadee/graphics/gpu.scm @@ -47,6 +47,7 @@ gpu-vertex-array gpu-viewport gpu-multisample + gpu-color-mask set-gpu-blend-mode! set-gpu-depth-test! set-gpu-stencil-test! @@ -56,7 +57,8 @@ set-gpu-vertex-buffer! set-gpu-vertex-array! set-gpu-viewport! - set-gpu-multisample!)) + set-gpu-multisample! + set-gpu-color-mask!)) ;;; @@ -114,7 +116,8 @@ from the GPU's memory." vertex-buffer vertex-array viewport - multisample) + multisample + color-mask) gpu? (gl-context gpu-gl-context) (gl-version gpu-gl-version) @@ -129,7 +132,8 @@ from the GPU's memory." (vertex-buffer %gpu-vertex-buffer) (vertex-array %gpu-vertex-array) (viewport %gpu-viewport) - (multisample %gpu-multisample)) + (multisample %gpu-multisample) + (color-mask %gpu-color-mask)) (define current-gpu (make-parameter #f)) @@ -157,6 +161,7 @@ from the GPU's memory." (shader-module (resolve-interface '(chickadee graphics shader))) (texture-module (resolve-interface '(chickadee graphics texture))) (viewport-module (resolve-interface '(chickadee graphics viewport))) + (color-module (resolve-interface '(chickadee graphics color))) (gl-version (extract-version (string-name version))) (glsl-version (extract-version (version-2-0 shading-language-version)))) ;; Create state for 32 texture units. @@ -187,7 +192,9 @@ from the GPU's memory." (module-ref buffer-module 'null-vertex-array)) (make-gpu-state (module-ref viewport-module 'apply-viewport) (module-ref viewport-module 'null-viewport)) - (make-gpu-state apply-multisample #f)))) + (make-gpu-state apply-multisample #f) + (make-gpu-state (module-ref color-module 'apply-color-mask) + (module-ref color-module 'default-color-mask))))) (define-syntax-rule (define-gpu-getter name ref) (define (name gpu) @@ -202,6 +209,7 @@ from the GPU's memory." (define-gpu-getter gpu-vertex-array %gpu-vertex-array) (define-gpu-getter gpu-viewport %gpu-viewport) (define-gpu-getter gpu-multisample %gpu-multisample) +(define-gpu-getter gpu-color-mask %gpu-color-mask) (define-syntax-rule (define-gpu-setter name ref) (define (name gpu x) @@ -216,6 +224,7 @@ from the GPU's memory." (define-gpu-setter set-gpu-vertex-array! %gpu-vertex-array) (define-gpu-setter set-gpu-viewport! %gpu-viewport) (define-gpu-setter set-gpu-multisample! %gpu-multisample) +(define-gpu-setter set-gpu-color-mask! %gpu-color-mask) (define (gpu-texture gpu texture-unit) (gpu-state-ref (vector-ref (gpu-textures gpu) texture-unit))) |