summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-10-23 08:05:48 -0400
committerDavid Thompson <dthompson2@worcester.edu>2019-10-23 08:06:53 -0400
commit0325613238e4c778c185e922e857a8aa2b875f36 (patch)
tree719d4fc4c6b4795274535df576d1e28f27b9e722
parent63117fe7feb0dffe23a7baddd52b819556eb9805 (diff)
render: shader: Convert camel case uniform names to lispy snake case.
-rw-r--r--chickadee/render/shader.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/chickadee/render/shader.scm b/chickadee/render/shader.scm
index 9d5bc51..5442097 100644
--- a/chickadee/render/shader.scm
+++ b/chickadee/render/shader.scm
@@ -532,13 +532,23 @@ them into a GPU shader program."
((= type (version-2-0 sampler-2d)) sampler-2d)
(else
(error "unsupported OpenGL type" type))))
+ (define (camel->snake str)
+ (list->string
+ (let loop ((i 0))
+ (if (< i (string-length str))
+ (let ((c (string-ref str i)))
+ (if (char-set-contains? char-set:upper-case c)
+ (cons* #\- (char-downcase c) (loop (+ i 1)))
+ (cons c (loop (+ i 1)))))
+ '()))))
(define (uniform-name->symbol name)
;; array uniform names have a suffix like "[0]" that needs to be
;; removed to produce the actual uniform variable name that our
;; shader interface will recognize.
(string->symbol
(let ((i (string-contains name "[")))
- (if i (substring name 0 i) name))))
+ (camel->snake
+ (if i (substring name 0 i) name)))))
(define (parse-array-index name)
(let* ((start (string-contains name "["))
(end (- (string-length name) 1)))