OLD | NEW |
(Empty) | |
| 1 // ArgGenerators contains argument generators for WebGL functions. |
| 2 // The argument generators are used for running random tests against the WebGL |
| 3 // functions. |
| 4 // |
| 5 // ArgGenerators is an object consisting of functionName : argGen -properties. |
| 6 // |
| 7 // functionName is a WebGL context function name and the argGen is an argument |
| 8 // generator object that encapsulates the requirements to run |
| 9 // randomly generated tests on the WebGL function. |
| 10 // |
| 11 // An argGen object has the following methods: |
| 12 // - setup -- set up state for testing the GL function, returns values |
| 13 // that need cleanup in teardown. Run once before entering a |
| 14 // test loop. |
| 15 // - teardown -- do cleanup on setup's return values after testing is complete |
| 16 // - generate -- generate a valid set of random arguments for the GL function |
| 17 // - returnValueCleanup -- do cleanup on value returned by the tested GL funct
ion |
| 18 // - cleanup -- do cleanup on generated arguments from generate |
| 19 // - checkArgValidity -- check if passed args are valid. Has a call signature |
| 20 // that matches generate's return value. Returns true |
| 21 // if args are valid, false if not. |
| 22 // |
| 23 // Example test loop that demonstrates how the function args and return |
| 24 // values flow together: |
| 25 // |
| 26 // var setupArgs = argGen.setup(); |
| 27 // for (var i=0; i<numberOfTests; i++) { |
| 28 // var generatedArgs = argGen.generate.apply(argGen, setupArgs); |
| 29 // var validArgs = argGen.checkArgValidity.apply(argGen, generatedArgs); |
| 30 // var rv = call the GL function with generatedArgs; |
| 31 // argGen.returnValueCleanup(rv); |
| 32 // argGen.cleanup.apply(argGen, generatedArgs); |
| 33 // } |
| 34 // argGen.teardown.apply(argGen, setupArgs); |
| 35 // |
| 36 ArgGenerators = { |
| 37 |
| 38 // GL functions in alphabetical order |
| 39 |
| 40 // S-2 |
| 41 |
| 42 stencilMaskSeparate : { |
| 43 generate : function() { return [cullFace.random(), randomInt(0xffffffff)]; }
, |
| 44 checkArgValidity : function(face, mask) { |
| 45 return cullFace.has(face); |
| 46 }, |
| 47 teardown : function() { GL.stencilMask(0xffffffff); } |
| 48 }, |
| 49 stencilOp : { |
| 50 generate : function() { |
| 51 return [stencilOp.random(), stencilOp.random(), stencilOp.random()]; |
| 52 }, |
| 53 checkArgValidity : function(sfail, dpfail, dppass) { |
| 54 return stencilOp.has(sfail) && stencilOp.has(dpfail) && stencilOp.has(dppa
ss); |
| 55 }, |
| 56 teardown : function() { GL.stencilOp(GL.KEEP, GL.KEEP, GL.KEEP); } |
| 57 }, |
| 58 stencilOpSeparate : { |
| 59 generate : function() { |
| 60 return [cullFace.random(), stencilOp.random(), stencilOp.random(), stencil
Op.random()]; |
| 61 }, |
| 62 checkArgValidity : function(face, sfail, dpfail, dppass) { |
| 63 return cullFace.has(face) && stencilOp.has(sfail) && |
| 64 stencilOp.has(dpfail) && stencilOp.has(dppass); |
| 65 }, |
| 66 teardown : function() { GL.stencilOp(GL.KEEP, GL.KEEP, GL.KEEP); } |
| 67 }, |
| 68 |
| 69 // T |
| 70 texImage2D : { |
| 71 noAlreadyTriedCheck : true, // Object.toSource is very slow here |
| 72 setup : function() { |
| 73 var tex = GL.createTexture(); |
| 74 var tex2 = GL.createTexture(); |
| 75 GL.bindTexture(GL.TEXTURE_2D, tex); |
| 76 GL.bindTexture(GL.TEXTURE_CUBE_MAP, tex2); |
| 77 return [tex, tex2]; |
| 78 }, |
| 79 generate : function() { |
| 80 var format = texImageFormat.random(); |
| 81 if (Math.random() < 0.5) { |
| 82 var img = randomImage(16,16); |
| 83 var a = [ texImageTarget.random(), 0, format, format, GL.UNSIGNED_BYTE,
img ]; |
| 84 return a; |
| 85 } else { |
| 86 var pix = null; |
| 87 if (Math.random > 0.5) { |
| 88 pix = new Uint8Array(16*16*4); |
| 89 } |
| 90 return [ |
| 91 texImageTarget.random(), 0, |
| 92 format, 16, 16, 0, |
| 93 format, GL.UNSIGNED_BYTE, pix |
| 94 ]; |
| 95 } |
| 96 }, |
| 97 checkArgValidity : function(target, level, internalformat, width, height, bo
rder, format, type, data) { |
| 98 // or : function(target, level, internalformat, format, type, ima
ge) |
| 99 if (!texImageTarget.has(target) || castToInt(level) < 0) |
| 100 return false; |
| 101 if (arguments.length <= 6) { |
| 102 var xformat = width; |
| 103 var xtype = height; |
| 104 var ximage = border; |
| 105 if ((ximage instanceof HTMLImageElement || |
| 106 ximage instanceof HTMLVideoElement || |
| 107 ximage instanceof HTMLCanvasElement || |
| 108 ximage instanceof ImageData) && |
| 109 texImageInternalFormat.has(internalformat) && |
| 110 texImageFormat.has(xformat) && |
| 111 texImageType.has(xtype) && |
| 112 internalformat == xformat) |
| 113 return true; |
| 114 return false; |
| 115 } |
| 116 var w = castToInt(width), h = castToInt(height), b = castToInt(border); |
| 117 return texImageInternalFormat.has(internalformat) && w >= 0 && h >= 0 && |
| 118 b == 0 && (data == null || data.byteLength == w*h*4) && |
| 119 texImageFormat.has(format) && texImageType.has(type) |
| 120 && internalformat == format; |
| 121 }, |
| 122 teardown : function(tex, tex2) { |
| 123 GL.bindTexture(GL.TEXTURE_2D, null); |
| 124 GL.bindTexture(GL.TEXTURE_CUBE_MAP, null); |
| 125 GL.deleteTexture(tex); |
| 126 GL.deleteTexture(tex2); |
| 127 } |
| 128 }, |
| 129 texParameterf : { |
| 130 generate : function() { |
| 131 var pname = texParameterPname.random(); |
| 132 var param = texParameterParam[pname].random(); |
| 133 return [bindTextureTarget.random(), pname, param]; |
| 134 }, |
| 135 checkArgValidity : function(target, pname, param) { |
| 136 if (!bindTextureTarget.has(target)) |
| 137 return false; |
| 138 if (!texParameterPname.has(pname)) |
| 139 return false; |
| 140 return texParameterParam[pname].has(param); |
| 141 } |
| 142 }, |
| 143 texParameteri : { |
| 144 generate : function() { |
| 145 var pname = texParameterPname.random(); |
| 146 var param = texParameterParam[pname].random(); |
| 147 return [bindTextureTarget.random(), pname, param]; |
| 148 }, |
| 149 checkArgValidity : function(target, pname, param) { |
| 150 if (!bindTextureTarget.has(target)) |
| 151 return false; |
| 152 if (!texParameterPname.has(pname)) |
| 153 return false; |
| 154 return texParameterParam[pname].has(param); |
| 155 } |
| 156 }, |
| 157 texSubImage2D : {}, // FIXME |
| 158 |
| 159 // U |
| 160 |
| 161 uniform1f : {}, // FIXME |
| 162 uniform1fv : {}, // FIXME |
| 163 uniform1i : {}, // FIXME |
| 164 uniform1iv : {}, // FIXME |
| 165 uniform2f : {}, // FIXME |
| 166 uniform2fv : {}, // FIXME |
| 167 uniform2i : {}, // FIXME |
| 168 uniform2iv : {}, // FIXME |
| 169 uniform3f : {}, // FIXME |
| 170 uniform3fv : {}, // FIXME |
| 171 uniform3i : {}, // FIXME |
| 172 uniform3iv : {}, // FIXME |
| 173 uniform4f : {}, // FIXME |
| 174 uniform4fv : {}, // FIXME |
| 175 uniform4i : {}, // FIXME |
| 176 uniform4iv : {}, // FIXME |
| 177 uniformMatrix2fv : {}, // FIXME |
| 178 uniformMatrix3fv : {}, // FIXME |
| 179 uniformMatrix4fv : {}, // FIXME |
| 180 useProgram : {}, // FIXME |
| 181 |
| 182 // V |
| 183 |
| 184 validateProgram : {}, // FIXME |
| 185 vertexAttrib1f : {}, // FIXME |
| 186 vertexAttrib1fv : {}, // FIXME |
| 187 vertexAttrib2f : {}, // FIXME |
| 188 vertexAttrib2fv : {}, // FIXME |
| 189 vertexAttrib3f : {}, // FIXME |
| 190 vertexAttrib3fv : {}, // FIXME |
| 191 vertexAttrib4f : {}, // FIXME |
| 192 vertexAttrib4fv : {}, // FIXME |
| 193 vertexAttribPointer : {}, // FIXME |
| 194 viewport : { |
| 195 generate : function() { |
| 196 return [randomInt(3000)-1500, randomInt(3000)-1500, randomIntFromRange(0,3
000), randomIntFromRange(0,3000)]; |
| 197 }, |
| 198 checkArgValidity : function(x,y,w,h) { |
| 199 return castToInt(w) >= 0 && castToInt(h) >= 0; |
| 200 }, |
| 201 teardown : function() { |
| 202 GL.viewport(0,0,GL.canvas.width, GL.canvas.height); |
| 203 } |
| 204 } |
| 205 |
| 206 }; |
OLD | NEW |