on master help sign in
added support for a few more uniform types. took out some console crap
commitf53004095c11ee4217f5cf7552802bb92d85df9c authorJohn P Mayer Jr <john.p.mayer.jr@gmail.com> dateWed 5 Feb 2014, 00:30 (13 years ago) parent9efd173
4 files changed+25−11
compiler/Parse/Helpers.hs+6−3 compiler/SourceSyntax/Literal.hs+4−1 libraries/Graphics/WebGL.elm−1 libraries/Native/Graphics/WebGL.js+15−6
compiler/Parse/Helpers.hs+6−3
@@ -9,7 +9,7 @@ import Data.Char (isUpper)
99import qualified Data.Set as Set
1010import qualified Data.Map as Map
1111import qualified Language.GLSL.Parser as GLP
12−import Language.GLSL.Syntax
12+import Language.GLSL.Syntax as GLS
1313import Text.Parsec hiding (newline,spaces,State)
1414import Text.Parsec.Indent
1515import qualified Text.Parsec.Token as T
@@ -349,8 +349,11 @@ glSource src =
349349 Declaration (InitDeclaration (TypeDeclarator (FullType (Just (TypeQualSto qual)) (TypeSpec _prec (TypeSpecNoPrecision tipe _mexpr1)))) [InitDecl name _mexpr2 _mexpr3]) ->
350350 if elem qual [Attribute, Varying, Uniform]
351351 then case tipe of
352− Vec3 -> return (qual,V3,name)
353− Mat4 -> return (qual,M4,name)
352+ GLS.Int -> return (qual,Literal.Int,name)
353+ GLS.Float -> return (qual,Literal.Float,name)
354+ GLS.Vec3 -> return (qual,V3,name)
355+ GLS.Vec4 -> return (qual,V4,name)
356+ GLS.Mat4 -> return (qual,M4,name)
354357 _ -> []
355358 else []
356359 _ -> []
compiler/SourceSyntax/Literal.hs+4−1
@@ -21,10 +21,13 @@ instance Pretty Literal where
2121 Str s -> PP.text . show $ s
2222 Boolean bool -> PP.text (show bool)
2323
24−data GLTipe = V3 | M4
24+data GLTipe = Int | Float | V3 | V4 | M4
2525
2626glTipeName :: GLTipe -> String
27+glTipeName Int = "Int"
28+glTipeName Float = "Float"
2729glTipeName V3 = "MJS.V3"
30+glTipeName V4 = "MJS.V4"
2831glTipeName M4 = "MJS.M4x4"
2932
3033data GLShaderTipe = GLShaderTipe
libraries/Graphics/WebGL.elm−1
@@ -4,7 +4,6 @@ module Graphics.WebGL (link, mapTriangle, zipTriangle, bind, encapsulate, webgl)
44
55import Graphics.Element (Element)
66import Native.Graphics.WebGL
7−import Signal (Signal)
87
98data Shader a u v = Dummy_Shader
109data Program a u = Dummy_Program
libraries/Native/Graphics/WebGL.js+15−6
@@ -31,7 +31,7 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
3131
3232 var guid = Utils.guid();
3333
34− console.log("Wrapped program #" + guid);
34+ //console.log("Wrapped program #" + guid);
3535
3636 return program = {
3737 guid: guid,
@@ -61,7 +61,7 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
6161 var vshader = createShader(vSrc, gl.VERTEX_SHADER);
6262 var fshader = createShader(fSrc, gl.FRAGMENT_SHADER);
6363 var program = gl.createProgram();
64− console.log("Created shaders and program");
64+ //console.log("Created shaders and program");
6565
6666 gl.attachShader(program, vshader);
6767 gl.attachShader(program, fshader);
@@ -78,7 +78,7 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
7878
7979 var guid = Utils.guid();
8080
81− console.log("Wrapped buffer #" + guid);
81+ //console.log("Wrapped buffer #" + guid);
8282
8383 return buffer = {
8484 guid: guid,
@@ -115,7 +115,7 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
115115 var array = new Float32Array(data);
116116
117117 var buffer = gl.createBuffer();
118− console.log("Created attribute buffer " + attribute.name);
118+ //console.log("Created attribute buffer " + attribute.name);
119119 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
120120 gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW);
121121
@@ -132,7 +132,7 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
132132
133133 var numIndices = 3 * List.length(bufferElems);
134134 var indices = List.toArray(List.range(0, numIndices - 1));
135− console.log("Created index buffer");
135+ //console.log("Created index buffer");
136136 var indexBuffer = gl.createBuffer();
137137 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
138138 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);
@@ -153,7 +153,7 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
153153
154154 gl.viewport(0, 0, model.w, model.h);
155155 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
156− console.log("Drawing");
156+ //console.log("Drawing");
157157
158158 function drawModel(m) {
159159
@@ -170,6 +170,15 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
170170 var uniform = gl.getActiveUniform(program, i);
171171 var uniformLocation = gl.getUniformLocation(program, uniform.name);
172172 switch (uniform.type) {
173+ case gl.INT:
174+ gl.uniform1i(uniformLocation, m.uniforms[uniform.name]);
175+ break;
176+ case gl.FLOAT:
177+ gl.uniform1f(uniformLocation, m.uniforms[uniform.name]);
178+ break;
179+ case gl.FLOAT_VEC3:
180+ gl.uniform3fv(uniformLocation, m.uniforms[uniform.name]);
181+ break;
173182 case gl.FLOAT_MAT4:
174183 gl.uniformMatrix4fv(uniformLocation, false, m.uniforms[uniform.name]);
175184 break;