From 0325613238e4c778c185e922e857a8aa2b875f36 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 23 Oct 2019 08:05:48 -0400 Subject: render: shader: Convert camel case uniform names to lispy snake case. --- chickadee/render/shader.scm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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))) -- cgit v1.2.3