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.testUniformf = function(gl) { |
| 16 var sh = new Filter(gl, 'foobar-vert', 'foobar-frag'); |
| 17 sh.apply(function(f){ |
| 18 var foo = f.uniform('foo'); |
| 19 var bar = f.uniform('bar'); |
| 20 gl.uniform4iv(foo, [1,2,3,4]); |
| 21 gl.uniform1iv(bar, [2]); |
| 22 }); |
| 23 var d = new Uint8Array(4); |
| 24 gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, d); |
| 25 assertEquals([1,2,3,8], [d[0], d[1], d[2], d[3]]); |
| 26 sh.apply(function(f){ |
| 27 var foo = f.uniform('foo'); |
| 28 var bar = f.uniform('bar'); |
| 29 gl.uniform4i(foo, 2,2,3,4); |
| 30 gl.uniform1i(bar, 3); |
| 31 }); |
| 32 gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, d); |
| 33 assertEquals([2,2,3,12], [d[0], d[1], d[2], d[3]]); |
| 34 sh.destroy(); |
| 35 } |
| 36 |
| 37 Tests.endUnit = function(gl) { |
| 38 } |
| 39 |
| 40 </script> |
| 41 <script id="foobar-vert" type="x-shader/x-vertex"> |
| 42 attribute vec3 Vertex; |
| 43 attribute vec2 Tex; |
| 44 |
| 45 uniform int bar; |
| 46 |
| 47 varying vec4 texCoord0; |
| 48 void main() |
| 49 { |
| 50 texCoord0 = vec4(Tex.s, 1.0-Tex.t, float(bar), 0.0); |
| 51 gl_Position = vec4(Vertex, 1.0); |
| 52 } |
| 53 </script> |
| 54 <script id="foobar-frag" type="x-shader/x-fragment"> |
| 55 precision mediump float; |
| 56 |
| 57 uniform ivec4 foo; |
| 58 |
| 59 varying vec4 texCoord0; |
| 60 void main() |
| 61 { |
| 62 gl_FragColor = vec4(float(foo.r)/256.0, float(foo.g)/256.0, float(foo.b)/256
.0, float(foo.a)*texCoord0.z/256.0); |
| 63 } |
| 64 </script> |
| 65 <style>canvas{ position:absolute; }</style> |
| 66 </head><body> |
| 67 <canvas id="gl" width="16" height="16"></canvas> |
| 68 </body></html> |
OLD | NEW |