1Elm.Native.Graphics.WebGL = {};
2Elm.Native.Graphics.WebGL.make = function(elm) {
4 elm.Native = elm.Native || {};
5 elm.Native.Graphics = elm.Native.Graphics || {};
6 elm.Native.Graphics.WebGL = elm.Native.Graphics.WebGL || {};
7 if (elm.Native.Graphics.WebGL.values) return elm.Native.Graphics.WebGL.values;
9 //var Render = ElmRuntime.use(ElmRuntime.Render.Element);
10 var newNode = ElmRuntime.use(ElmRuntime.Render.Utils).newElement;
12 //var Signal = Elm.Signal.make(elm);
13 var newElement = Elm.Graphics.Element.make(elm).newElement;
14 //var JS = Elm.Native.JavaScript.make(elm);
15 //var Utils = Elm.Native.Utils.make(elm);
16 //var Tuple2 = Utils.Tuple2;
18 function createShader(gl, str, type) {
19 var shader = gl.createShader(type);
20 gl.shaderSource(shader, str);
21 gl.compileShader(shader);
23 if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
24 throw gl.getShaderInfoLog(shader);
30 function linkProgram(gl, program) {
31 var vshader = createShader(gl, program.vshaderSource, gl.VERTEX_SHADER);
32 var fshader = createShader(gl, program.fshaderSource, gl.FRAGMENT_SHADER);
33 gl.attachShader(program, vshader);
34 gl.attachShader(program, fshader);
35 gl.linkProgram(program);
36 if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
37 throw gl.getProgramInfoLog(program);
41 function createProgram(gl, vstr, fstr) {
42 var program = gl.createProgram();
43 var vshader = createShader(gl, vstr, gl.VERTEX_SHADER);
44 var fshader = createShader(gl, fstr, gl.FRAGMENT_SHADER);
45 gl.attachShader(program, vshader);
46 gl.attachShader(program, fshader);
47 gl.linkProgram(program);
49 if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
50 throw gl.getProgramInfoLog(program);
56 var geoVert = "attribute vec3 aVertexPosition;\
57 attribute vec4 aVertexColor;\
59 uniform mat4 uMMatrix;\
60 uniform mat4 uPMatrix;\
61 uniform mat4 uVMatrix;\
63 varying vec4 vVertexColor;\
66 gl_Position = uPMatrix * uVMatrix * uMMatrix * vec4(aVertexPosition, 1.0);\
67 vVertexColor = aVertexColor;\
70 var geoFrag = "precision mediump float;\
72 varying vec4 vVertexColor;\
75 gl_FragColor = vVertexColor;\
78 function drawGL(model) {
79 var scene = model.scene;
84 * Called for new node, caches lots of stuff
86 function render(model) {
87 var canvas = newNode('canvas');
88 var gl = canvas.getContext("webgl");
89 var program = createProgram(gl, geoVert, geoFrag);
99 * Called at existing node
101 function update(canvasNode, oldModel, newModel) {
102 newModel.cache = oldModel.cache;
106 function glContext(w,h,scene) {
108 return A3(newElement, w, h, {
113 model: {scene:scene},
118 return elm.Native.Graphics.WebGL.values = {
119 glContext:F3(glContext),
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