Zinggi/elm-glsl-generator/1.0.0

GLSL

This package helps to combine GLSL code snippets.

This package is build around functions of type Generator -> Generator. They are all meant to be used in a pipeline (|>) or by composing them (>>).

A type that describes a fragment shader

This starts a fragment shader pipeline

Starts a vertex shader

Shaders usually start by defining variables and functions

emptyFragmentShader
    |> defineUniform "vec3" "color"
    |> define glslCodeDefiningAFunction
type alias GLSLType =
String
defineAttribute : GLSLType -> String -> Generator -> Generator
defineUniform : GLSLType -> String -> Generator -> Generator
defineVarying : GLSLType -> String -> Generator -> Generator
define : String -> Generator -> Generator

Then you define the code for main using code snippets and possibly some more variables. Variables used here will be automatically declared in the genrated code.

code
    |> (s "vec4 c = vec4(color * " >> uniform "float" "colorScale" >> ", 1.0);")
    |> s "gl_FragColor = c;"
s : String -> Generator -> Generator

Adds some lines of code to main

attribute : GLSLType -> String -> Generator -> Generator
uniform : GLSLType -> String -> Generator -> Generator
varying : GLSLType -> String -> Generator -> Generator

Then you take a finished Generator and generate code from it:

Transform a generator into the finished GLSL code

generateElm : String -> Generator -> String

Transform a generator into the finished elm code