summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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