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 uniIV4 = f.uniform('uniIV4'); |
| 19 var uniInt = f.uniform('uniInt'); |
| 20 assertThrowNoGLError(gl, "number as location", |
| 21 function(){gl.uniform4iv(58882929, [1,2,3,4]);}); |
| 22 assertThrowNoGLError(gl, "negative number as location", |
| 23 function(){gl.uniform4iv(-58882929, [1,2,3,4]);}); |
| 24 assertGLError(gl, gl.INVALID_OPERATION, "more than 1 value to 1iv", |
| 25 function(){gl.uniform1iv(uniInt, [2,3,4,5,6]);}); |
| 26 assertGLError(gl, gl.INVALID_OPERATION, "4iv on int", |
| 27 function(){gl.uniform4iv(uniInt, [2,3,4,5]);}); |
| 28 assertOk("4iv on 4iv", |
| 29 function(){gl.uniform4iv(uniIV4, [1, 2, 3, 4]);}); |
| 30 assertGLError(gl, gl.INVALID_VALUE, "5 values on 4iv", |
| 31 function(){gl.uniform4iv(uniIV4, [1, 2, 3, 4, 5]);}); |
| 32 assertGLError(gl, gl.INVALID_OPERATION, "8 values on 4iv", |
| 33 function(){gl.uniform4iv(uniIV4, [1, 2, 3, 4, 5, 6, 7, 8]);}); |
| 34 assertGLError(gl, gl.INVALID_OPERATION, "3iv on int", |
| 35 function(){gl.uniform3iv(uniInt, [2,3,4]);}); |
| 36 assertGLError(gl, gl.INVALID_OPERATION, "2iv on int", |
| 37 function(){gl.uniform2iv(uniInt, [2,3]);}); |
| 38 assertGLError(gl, gl.INVALID_OPERATION, "3iv on 4iv", |
| 39 function(){gl.uniform3iv(uniIV4, [4,5,6]);}); |
| 40 assertGLError(gl, gl.INVALID_OPERATION, "2iv on 4iv", |
| 41 function(){gl.uniform2iv(uniIV4, [5,6]);}); |
| 42 assertGLError(gl, gl.INVALID_OPERATION, "1iv on 4iv", |
| 43 function(){gl.uniform1iv(uniIV4, [6]);}); |
| 44 assertGLError(gl, gl.INVALID_VALUE, "not enough values", |
| 45 function(){gl.uniform1iv(uniInt, []);}); |
| 46 assertGLError(gl, gl.INVALID_OPERATION, "1fv on int", |
| 47 function(){gl.uniform1fv(uniInt, [2]);}); |
| 48 assertGLError(gl, gl.INVALID_OPERATION, "4fv on ivec4", |
| 49 function(){gl.uniform4fv(uniIV4, [2,3,4,5]);}); |
| 50 gl.uniform1iv(uniInt, [2]); |
| 51 gl.uniform4iv(uniIV4, [1, 2, 3, 4]); |
| 52 }); |
| 53 var d = new Uint8Array(4); |
| 54 gl.readPixels(0,0,1,1,gl.RGBA, gl.UNSIGNED_BYTE, d); |
| 55 assertArrayEquals([1,2,3,8], d); |
| 56 sh.destroy(); |
| 57 throwError(gl); |
| 58 } |
| 59 |
| 60 Tests.endUnit = function(gl) { |
| 61 } |
| 62 |
| 63 </script> |
| 64 <script id="foobar-vert" type="x-shader/x-vertex"> |
| 65 attribute vec3 Vertex; |
| 66 attribute vec2 Tex; |
| 67 |
| 68 uniform int uniInt; |
| 69 |
| 70 varying vec4 texCoord0; |
| 71 void main() |
| 72 { |
| 73 texCoord0 = vec4(Tex.s, 1.0-Tex.t, float(uniInt), 0.0); |
| 74 gl_Position = vec4(Vertex, 1.0); |
| 75 } |
| 76 </script> |
| 77 <script id="foobar-frag" type="x-shader/x-fragment"> |
| 78 precision mediump float; |
| 79 |
| 80 uniform ivec4 uniIV4; |
| 81 |
| 82 varying vec4 texCoord0; |
| 83 void main() |
| 84 { |
| 85 gl_FragColor = vec4( |
| 86 float(uniIV4.x)/256.0, |
| 87 float(uniIV4.y)/256.0, |
| 88 float(uniIV4.z)/256.0, |
| 89 float(uniIV4.a)*texCoord0.z/256.0); |
| 90 } |
| 91 </script> |
| 92 <style>canvas{ position:absolute; }</style> |
| 93 </head><body> |
| 94 <canvas id="gl" width="16" height="16"></canvas> |
| 95 </body></html> |
OLD | NEW |