1module Graphics.WebGL (mapTriangle, zipTriangle, unsafeCoerceGLSL, loadTex, model, webgl) where
3{-| The WebGL API is for high performance drawing.
5# Triangle Convenience Functions
6@docs Triangle, mapTriangle, zipTriangle
11Shaders are created using inline GLSL blocks. The type of the Shader is determined by the top-level attribute, uniform, and varying declarations of the parsed GLSL source code. The type parameters to Shader are records with field names matching the names of the declarations.
14vertex : Shader { a | pos : V3 } { b | model : M4x4 } {}
21 gl_Position = model * vec4(pos,1.0);
27GLSL attribute variables are per-vertex values. For example, it could hold the position or color of a specific vertex of a specific triangle in your model.
29GLSL uniform variables are global values which will be applied for all vertices of all triangles of the model.
31GLSL varying variables are shared between stages; they are output variables for vertex shaders, and input variables for fragment shaders.
46import Graphics.Element (Element)
48import Native.Graphics.WebGL
51{-| Triangles are only homogenous 3-tuples. Each element describes something about each vertex, and must be a record to be used with GLSL shaders.
53type Triangle a = (a,a,a)
55{-| Apply a function to each vertex -}
56mapTriangle : (a -> b) -> Triangle a -> Triangle b
57mapTriangle f (x,y,z) = (f x, f y, f z)
59{-| Apply an arity-2 function element-wise on 2 triangles -}
60zipTriangle : (a -> b -> c) -> Triangle a -> Triangle b -> Triangle c
61zipTriangle f (x,y,z) (x',y',z') = (f x x', f y y', f z z')
63data Shader attr unif vary = Shader
65{-| Libary writers can use this function to create shader combinators. -}
66unsafeCoerceGLSL : String -> Shader attribute uniform varying
67unsafeCoerceGLSL = Native.Graphics.WebGL.unsafeCoerceGLSL
71{-| Loads a texture from the given url. PNG and JPEG are the preferred and tested-compatible source image format. -}
72loadTex : String -> Signal (Response Texture)
73loadTex = Native.Graphics.WebGL.loadTex
77{-| Packages a vertex shader, a fragment shader, triangle data, and uniform variables as a opaque Model.
78This is a simple container; however, externally there is no type information.
80model : Shader attribute uniform varying -> Shader {} uniform varying -> [Triangle attribute] -> uniform -> Model
81model = Native.Graphics.WebGL.model
83{-| Render a WebGL scene with the given dimensions and models -}
84webgl : (Int,Int) -> [Model] -> Element
85webgl = Native.Graphics.WebGL.webgl
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list