on b2e83cc help sign in
68 lines 1.8 kB history raw
1module Graphics.WebGL (mapTriangle, zipTriangle, loadTex, model, webgl) where
3{-| The WebGL API is for high performance drawing.
5# Triangle Convenience Functions
6@docs Triangle, mapTriangle, zipTriangle
8# Shaders
9Shaders are created using glsl blocks.
11```haskell
12vertex : Shader { a | pos : V3 } {} {}
13vertex = [glsl|
15attribute vec3 pos;
17void main () {
18 gl_Position = vec4(pos,1.0);
21\]
22```
24# WebGL Element
25@docs loadTex, model, webgl
27-}
29import Graphics.Element (Element)
30import Http (Response)
31import Native.Graphics.WebGL
32import Signal (Signal)
34unsafeCoerceGLSL : String -> Shader attr unif vary
35unsafeCoerceGLSL = Native.Graphics.WebGL.unsafeCoerceGLSL
37{-| Triangles are only homogenous 3-tuples. Each element describes something about each vertex, and must be a record to be used with GLSL shaders.
38-}
39type Triangle a = (a,a,a)
41{-| Apply a function to each vertex -}
42mapTriangle : (a -> b) -> Triangle a -> Triangle b
43mapTriangle f (x,y,z) = (f x, f y, f z)
45{-| Apply an arity-2 function element-wise on 2 triangles -}
46zipTriangle : (a -> b -> c) -> Triangle a -> Triangle b -> Triangle c
47zipTriangle f (x,y,z) (x',y',z') = (f x x', f y y', f z z')
49{-| Opaque Shader Type -}
50data Shader attr unif vary = Shader
52{-| Opaque Texture Type -}
53data Texture = Texture
55{-| Load an image url as a texture -}
56loadTex : String -> Signal (Response Texture)
57loadTex = Native.Graphics.WebGL.loadTex
59{-| Opaque Model Type -}
60data Model = Model
62{-| A model is a collection of a fragment shader, a vertex shader, attribute data, and uniform data. -}
63model : Shader attr unif vary -> Shader {} unif vary -> [Triangle attr] -> unif -> Model
64model = Native.Graphics.WebGL.model
66{-| Render a WebGL scene with the given dimensions and models -}
67webgl : (Int,Int) -> [Model] -> Element
68webgl = Native.Graphics.WebGL.webgl