summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2021-04-07 17:05:03 -0400
committerDavid Thompson <dthompson2@worcester.edu>2021-04-07 17:07:19 -0400
commit42f3ce0e79f0fe488c6844a8819fab1659177a01 (patch)
treee073a17d0e660cdab56b9efbf7307234019ec9c2
parent7b9a06ee3e57ce1a9d7bc91cdbb5894e234fde34 (diff)
graphics: shader: Allow rects to be bound to vec4 uniforms.
-rw-r--r--chickadee/graphics/shader.scm25
1 files changed, 15 insertions, 10 deletions
diff --git a/chickadee/graphics/shader.scm b/chickadee/graphics/shader.scm
index 1ce0c45..80acd02 100644
--- a/chickadee/graphics/shader.scm
+++ b/chickadee/graphics/shader.scm
@@ -30,6 +30,7 @@
#:use-module (gl)
#:use-module (chickadee math matrix)
#:use-module (chickadee math vector)
+ #:use-module (chickadee math rect)
#:use-module (chickadee graphics buffer)
#:use-module (chickadee graphics color)
#:use-module (chickadee graphics engine)
@@ -195,18 +196,22 @@
(define-shader-primitive-type float-vec4
#:name 'float-vec4
#:size 16 ; 16 bytes = 4 floats = 1 vec4
- #:validator color?
+ #:validator (lambda (x) (or (rect? x) (color? x)))
#:serializer
- (lambda (bv i v)
- ;; As of now, there is no vec4 Scheme type, but we do want to
- ;; accept colors as vec4s since there is no special color type in
- ;; GLSL.
- (bytevector-ieee-single-native-set! bv i (color-r v))
- (bytevector-ieee-single-native-set! bv (+ i 4) (color-g v))
- (bytevector-ieee-single-native-set! bv (+ i 8) (color-b v))
- (bytevector-ieee-single-native-set! bv (+ i 12) (color-a v)))
+ (let ((unwrap-rect (@@ (chickadee math rect) unwrap-rect)))
+ (lambda (bv i v)
+ ;; As of now, there is no vec4 Scheme type, but we do want to
+ ;; accept colors and rects as vec4s since there is no special
+ ;; color or rect type in GLSL.
+ (if (rect? v)
+ (bytevector-copy! (unwrap-rect v) 0 bv i 16)
+ (begin
+ (bytevector-ieee-single-native-set! bv i (color-r v))
+ (bytevector-ieee-single-native-set! bv (+ i 4) (color-g v))
+ (bytevector-ieee-single-native-set! bv (+ i 8) (color-b v))
+ (bytevector-ieee-single-native-set! bv (+ i 12) (color-a v))))))
#:setter gl-uniform4fv
- #:null black)
+ #:null (make-null-rect))
(define-shader-primitive-type mat4
#:name 'mat4