glsl/shaders
src/glsl/shaders.tur
defn
glsl-input
(glsl-input [name :cstr type :cstr location :int] :cstr)
build a vertex input declaration with a layout location.
Parameters
| name | attribute name | |
| type | type keyword, e.g. ":vec3" | |
| location | layout location index |
Returns
GLSL input declaration string, e.g. "layout(location = 0) in vec3 aPos;"
Example
(glsl-input "aPos" ":vec3" 0) ; => "layout(location = 0) in vec3 aPos;"
Since: v0.1.0
defn
glsl-output
(glsl-output [name :cstr type :cstr] :cstr)
build an output variable declaration.
Parameters
| name | variable name | |
| type | type keyword, e.g. ":vec4" |
Returns
GLSL output declaration string, e.g. "out vec4 FragColor;"
Example
(glsl-output "FragColor" ":vec4") ; => "out vec4 FragColor;"
Since: v0.1.0
defn
glsl-uniform
(glsl-uniform [name :cstr type :cstr] :cstr)
build a uniform variable declaration.
Parameters
| name | uniform name | |
| type | type keyword, e.g. ":mat4" |
Returns
GLSL uniform declaration string, e.g. "uniform mat4 model;"
Example
(glsl-uniform "model" ":mat4") ; => "uniform mat4 model;"
Since: v0.1.0
defn
glsl-vertex-shader
(glsl-vertex-shader [version :cstr decls :int main-body :cstr] :cstr)
build a complete vertex shader source string.
Parameters
| version | GLSL version string, e.g. "330 core" | |
| decls | Vec[cstr] of declaration strings (inputs, outputs, uniforms), | |
| built with (vec-of ...). Pass (vec-of) for none. | ||
| main-body | body of void main(), built with glsl-stmts |
Returns
Complete vertex shader GLSL source string.
Example
(glsl-vertex-shader "330 core"
(vec-of (glsl-input "aPos" ":vec3" 0)
(glsl-uniform "model" ":mat4"))
(glsl-set! "gl_Position" "model * vec4(aPos, 1.0)"))
Since: v0.1.0
defn
glsl-fragment-shader
(glsl-fragment-shader [version :cstr decls :int main-body :cstr] :cstr)
build a complete fragment shader source string.
Parameters
| version | GLSL version string, e.g. "330 core" | |
| decls | Vec[cstr] of declaration strings (inputs, outputs, uniforms), | |
| built with (vec-of ...). Pass (vec-of) for none. | ||
| main-body | body of void main(), built with glsl-stmts |
Returns
Complete fragment shader GLSL source string.
Example
(glsl-fragment-shader "330 core"
(vec-of (glsl-input "ourColor" ":vec3" 0)
(glsl-output "FragColor" ":vec4"))
(glsl-set! "FragColor" "vec4(ourColor, 1.0)"))
Since: v0.1.0
defn
glsl-compute-shader
(glsl-compute-shader [version :cstr wg-x :int wg-y :int wg-z :int decls :int main-body :cstr] :cstr)
build a compute shader source with a work-group layout.
Parameters
| version | GLSL version string, e.g. "450 core" | |
| wg-x | local_size_x | |
| wg-y | local_size_y | |
| wg-z | local_size_z | |
| decls | cons list of declaration strings | |
| main-body | body of void main() |
Returns
Complete compute shader GLSL source string.
Example
(glsl-compute-shader "450 core" 16 16 1 (vec-of) body)
Since: v0.1.0
defn
glsl-geometry-shader
(glsl-geometry-shader [version :cstr input-layout :cstr output-layout :cstr max-vertices :int decls :int main-body :cstr] :cstr)
Returns:
Example
(glsl-geometry-shader "330 core" ":points" ":triangle-strip" 4 (vec-of) body)
Since: v0.1.0
Internal definitions
__build-shader-- internal helper: assemble a complete shader source.__prim-keyword-- build a geometry shader source string.