summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-10-26 20:28:03 -0400
committerDavid Thompson <dthompson2@worcester.edu>2019-10-26 20:28:03 -0400
commit747da5e07351ed46c125fdf05bcf86499a973e97 (patch)
tree6fd03f0448b1a9db7495c8f363a89e3aeaa64a87
parent86c9c009b09ed690a6b9d58f36a394f9fedfcceb (diff)
render: shader: Fix bug where default values for local fields didn't work.
-rw-r--r--chickadee/render/shader.scm26
1 files changed, 18 insertions, 8 deletions
diff --git a/chickadee/render/shader.scm b/chickadee/render/shader.scm
index 1f97a0d..050a81c 100644
--- a/chickadee/render/shader.scm
+++ b/chickadee/render/shader.scm
@@ -279,13 +279,17 @@
(define (shader-struct-default vtable field)
(match (assq-ref (shader-struct-fields vtable) field)
((_ type size)
- (let ((default (if (eq? (struct-vtable type) <shader-struct>)
- (apply make-struct/no-tail type
- (map (match-lambda
- ((sub-field _ _ _)
- (shader-struct-default type sub-field)))
- (shader-struct-fields type)))
- (shader-primitive-type-null type))))
+ (let ((default (cond
+ ((eq? type local-field)
+ #f)
+ ((eq? (struct-vtable type) <shader-struct>)
+ (apply make-struct/no-tail type
+ (map (match-lambda
+ ((sub-field _ _ _)
+ (shader-struct-default type sub-field)))
+ (shader-struct-fields type))))
+ (else
+ (shader-primitive-type-null type)))))
(if (= size 1)
default
(make-vector size default))))))
@@ -749,7 +753,13 @@ shader program."
(if (shader-struct? value)
(uniform-namespace-for-each
(lambda (key uniform)
- (traverse uniform (shader-struct-ref value key)))
+ ;; Samplers are opaque types and you cannot pass them
+ ;; into the shader as uniform values like you can with
+ ;; most other values. In the case of samplers, they are
+ ;; mapped to OpenGL's "texture units", so we need to
+ ;; ignore them here.
+ (unless (eq? (uniform-type uniform) sampler-2d)
+ (traverse uniform (shader-struct-ref value key))))
uniform)
(error "expected shader struct" x)))
;; A nested array namespace indicates that this must be an array