glsl/core
glsl-let
(glsl-let [name :cstr type :cstr init :cstr] :cstr)
declare a typed local variable.
| name | variable name | |
| type | Turmeric type keyword, e.g. ":float" | |
| init | initializer expression string |
GLSL declaration statement, e.g. "float x = 1.0;"
(glsl-let "x" ":float" "1.0") ; => "float x = 1.0;"
Since: v0.1.0
glsl-set!
(glsl-set! [name :cstr value :cstr] :cstr)
assign to a variable.
| name | variable name or field expression | |
| value | right-hand side expression string |
GLSL assignment statement, e.g. "fragColor = result;"
(glsl-set! "fragColor" "vec4(1.0)") ; => "fragColor = vec4(1.0);"
Since: v0.1.0
glsl-return
(glsl-return [expr :cstr] :cstr)
return statement.
| expr | expression string to return |
"return expr;"
(glsl-return "(x * x)") ; => "return (x * x);"
Since: v0.1.0
glsl-discard
(glsl-discard :cstr)
discard the current fragment.
"discard;"
(glsl-discard) ; => "discard;"
Since: v0.1.0
glsl-inc!
(glsl-inc! [name :cstr] :cstr)
post-increment statement.
| name | variable name |
"name++;"
(glsl-inc! "i") ; => "i++;"
Since: v0.1.0
glsl-dec!
(glsl-dec! [name :cstr] :cstr)
post-decrement statement.
| name | variable name |
"name--;"
(glsl-dec! "i") ; => "i--;"
Since: v0.1.0
glsl-binop
(glsl-binop [op :cstr left :cstr right :cstr] :cstr)
binary infix operation.
| op | operator string, e.g. "+" | |
| left | left-hand expression string | |
| right | right-hand expression string |
Parenthesized expression, e.g. "(a + b)"
(glsl-binop "+" "a" "b") ; => "(a + b)"
Since: v0.1.0
glsl-if
(glsl-if [cond :cstr then-body :cstr else-body :cstr] :cstr)
if/else statement.
| cond | condition expression string | |
| then-body | body executed when cond is true | |
| else-body | body executed when cond is false |
GLSL if/else statement string.
(glsl-if "(x > 0.0)" (glsl-return "1.0") (glsl-return "-1.0"))
Since: v0.1.0
glsl-if-only
(glsl-if-only [cond :cstr body :cstr] :cstr)
if statement without else.
| cond | condition expression string | |
| body | statement body string |
GLSL if statement string.
(glsl-if-only "(alpha < 0.01)" (glsl-discard))
Since: v0.1.0
glsl-for
(glsl-for [init :cstr cond :cstr step :cstr body :cstr] :cstr)
for loop with a pre-built init clause.
| init | init clause string, e.g. "int i = 0" | |
| cond | loop condition, e.g. "i < 10" | |
| step | step expression, e.g. "i++" | |
| body | loop body string |
GLSL for loop statement string.
(glsl-for "int i = 0" "i < 4" "i++" (glsl-set! "sum" "(sum + arr[i])"))
Since: v0.1.0
glsl-for1
(glsl-for1 [name :cstr type :cstr init :cstr cond :cstr step :cstr body :cstr] :cstr)
for loop with a typed loop variable.
| name | loop variable name | |
| type | type keyword, e.g. ":int" | |
| init | initial value expression, e.g. "0" | |
| cond | loop condition, e.g. "i < 4" | |
| step | step expression, e.g. "i++" | |
| body | loop body string |
GLSL for loop statement string.
(glsl-for1 "i" ":int" "0" "i < 4" "i++" body)
Since: v0.1.0
glsl-param
(glsl-param [name :cstr type :cstr] :cstr)
build a single function parameter string.
| name | parameter name | |
| type | type keyword |
GLSL parameter string, e.g. "vec3 normal"
(glsl-param "normal" ":vec3") ; => "vec3 normal"
Since: v0.1.0
glsl-defn
(glsl-defn [name :cstr params :int ret :cstr body :cstr] :cstr)
define a GLSL function.
| name | function name | |
| params | cons list of parameter strings from glsl-param | |
| ret | return type keyword | |
| body | function body string, typically built with glsl-stmts |
Complete GLSL function definition string.
(glsl-defn "square"
(cons (glsl-param "x" ":float") 0)
":float"
(glsl-return "(x * x)"))
Since: v0.1.0