OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html><head> | |
3 <meta charset="utf-8"> | |
4 <link rel="stylesheet" type="text/css" href="../unit.css" /> | |
5 <script type="application/x-javascript" src="../unit.js"></script> | |
6 <script type="application/x-javascript" src="../util.js"></script> | |
7 <script type="application/x-javascript"> | |
8 | |
9 Tests.startUnit = function () { | |
10 var canvas = document.getElementById('gl'); | |
11 var gl = wrapGLContext(canvas.getContext(GL_CONTEXT_ID)); | |
12 return [gl]; | |
13 } | |
14 | |
15 Tests.testUniformArray = function(gl) { | |
16 var sh = new Filter(gl, 'foobar-vert', 'foobar-frag'); | |
17 sh.apply(function(f){ | |
18 var uniV4 = f.uniform('uniV4'); | |
19 var uniFloat = f.uniform('uniFloat'); | |
20 assertOk("1fv on 1fv", | |
21 function(){gl.uniform1fv(uniFloat, [2]);}); | |
22 assertOk("5 values on 1fv", | |
23 function(){gl.uniform1fv(uniFloat, [2,3,4,5,6]);}); | |
24 assertOk("4fv on 4fv", | |
25 function(){gl.uniform4fv(uniV4, [1, 2, 3, 4]);}); | |
26 assertOk("8 values on 4fv", | |
27 function(){gl.uniform4fv(uniV4, [1, 2, 3, 4, 5, 6, 7, 8]);}); | |
28 | |
29 var uniformsFound = 0; | |
30 var numUniforms = gl.getProgramParameter(f.shader.program, gl.ACTIVE_UNI
FORMS); | |
31 for (var i = 0; i < numUniforms; ++i) { | |
32 var uniformName = gl.getActiveUniform(f.shader.program, i).name; | |
33 if (uniformName.indexOf('uniV4') == 0 || uniformName.indexOf('un
iFloat') == 0) { | |
34 assert("Uniform array of length 1 ends with [0]", unifor
mName.indexOf("[0]") != -1); | |
35 ++uniformsFound; | |
36 } | |
37 } | |
38 assert("Both uniforms found", uniformsFound == 2); | |
39 | |
40 uniV4 = f.uniform('uniV4[0]'); | |
41 uniFloat = f.uniform('uniFloat[0]'); | |
42 assertOk("1fv on 1fv", | |
43 function(){gl.uniform1fv(uniFloat, [2]);}); | |
44 assertOk("5 values on 1fv", | |
45 function(){gl.uniform1fv(uniFloat, [2,3,4,5,6]);}); | |
46 assertOk("4fv on 4fv", | |
47 function(){gl.uniform4fv(uniV4, [1, 2, 3, 4]);}); | |
48 assertOk("8 values on 4fv", | |
49 function(){gl.uniform4fv(uniV4, [1, 2, 3, 4, 5, 6, 7, 8]);}); | |
50 | |
51 }); | |
52 var d = new Uint8Array(4); | |
53 gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, d); | |
54 assertArrayEquals([1,2,3,8], d); | |
55 sh.destroy(); | |
56 throwError(gl); | |
57 } | |
58 | |
59 Tests.endUnit = function(gl) { | |
60 } | |
61 | |
62 </script> | |
63 <script id="foobar-vert" type="x-shader/x-vertex"> | |
64 attribute vec3 Vertex; | |
65 attribute vec2 Tex; | |
66 | |
67 uniform float uniFloat[1]; | |
68 | |
69 varying vec4 texCoord0; | |
70 void main() | |
71 { | |
72 texCoord0 = vec4(Tex.s, 1.0-Tex.t, uniFloat[0], 0.0); | |
73 gl_Position = vec4(Vertex, 1.0); | |
74 } | |
75 </script> | |
76 <script id="foobar-frag" type="x-shader/x-fragment"> | |
77 precision mediump float; | |
78 | |
79 uniform vec4 uniV4[1]; | |
80 | |
81 varying vec4 texCoord0; | |
82 void main() | |
83 { | |
84 gl_FragColor = vec4( | |
85 uniV4[0].r/256.0, | |
86 uniV4[0].g/256.0, | |
87 uniV4[0].b/256.0, | |
88 uniV4[0].a*texCoord0.z/256.0); | |
89 } | |
90 </script> | |
91 <style>canvas{ position:absolute; }</style> | |
92 </head><body> | |
93 <canvas id="gl" width="16" height="16"></canvas> | |
94 </body></html> | |
OLD | NEW |