From c66e3c62e889cba02bbed68da8ec173429d9f54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renaud=20Casenave-P=C3=A9r=C3=A9?= Date: Sat, 4 Apr 2015 23:38:01 +0200 Subject: [PATCH] Transform common-lisp symbols into glsl compliant variable names --- src/render/shader/glsl.lisp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/render/shader/glsl.lisp b/src/render/shader/glsl.lisp index 3ce93c4..b852d5a 100644 --- a/src/render/shader/glsl.lisp +++ b/src/render/shader/glsl.lisp @@ -28,6 +28,14 @@ "Configure the verbosity of the compiler. if non-nil, the dsl will be printed in comments together with the glsl code.") +(defvar *glsl-symbols* '(gl-position "gl_Position") + "Keep a table of reserved glsl symbols.") + +(defun glsl-name (cl-name) + "Convert a variable name in common-lisp convention to a glsl compliant name." + (or (getf *glsl-symbols* cl-name) + (string-downcase (substitute #\_ #\- (symbol-name cl-name))))) + (defmacro noop-handler (body) `(format nil "/* ~((~{~a~^ ~})~) */~%" ,body)) @@ -69,7 +77,7 @@ the forms comprised of these keywords will be printed in comments." (let ((vars (loop for s in pairs by #'cddr collect s))) (let ((expanded (loop for n in vars for r in (rest pairs) by #'cddr - collect n collect (walk-1 r)))) + collect (glsl-name n) collect (walk-1 r)))) (format nil "~@[~vt~]~{~(~a~) = ~(~a~)~^;~%~}" (when (> *current-indent* 0) *current-indent*) @@ -77,10 +85,14 @@ the forms comprised of these keywords will be printed in comments." (defhandler (+ - * / %) (op &rest body) "Handle the standard infix operations." - (flet ((oper (a b) + (labels ((expand (a) + (cond + ((listp a) (format nil "(~a)" (walk-1 a))) + ((symbolp a) (glsl-name a)) + (t a))) + (oper (a b) (format nil "~a ~(~a~) ~a" - (if (listp a) (format t "(~a)" (walk-1 a)) a) op - (if (listp b) (format nil "(~a)" (walk-1 b)) b)))) + (expand a) op (expand b)))) (reduce #'oper body))) (defun default-handler (first &rest rest)