OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ** Copyright (c) 2012 The Khronos Group Inc. |
| 3 ** |
| 4 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 5 ** copy of this software and/or associated documentation files (the |
| 6 ** "Materials"), to deal in the Materials without restriction, including |
| 7 ** without limitation the rights to use, copy, modify, merge, publish, |
| 8 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 9 ** permit persons to whom the Materials are furnished to do so, subject to |
| 10 ** the following conditions: |
| 11 ** |
| 12 ** The above copyright notice and this permission notice shall be included |
| 13 ** in all copies or substantial portions of the Materials. |
| 14 ** |
| 15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 22 */ |
| 23 |
| 24 // ArgGenerators contains argument generators for WebGL functions. |
| 25 // The argument generators are used for running random tests against the WebGL |
| 26 // functions. |
| 27 // |
| 28 // ArgGenerators is an object consisting of functionName : argGen -properties. |
| 29 // |
| 30 // functionName is a WebGL context function name and the argGen is an argument |
| 31 // generator object that encapsulates the requirements to run |
| 32 // randomly generated tests on the WebGL function. |
| 33 // |
| 34 // An argGen object has the following methods: |
| 35 // - setup -- set up state for testing the GL function, returns values |
| 36 // that need cleanup in teardown. Run once before entering a |
| 37 // test loop. |
| 38 // - teardown -- do cleanup on setup's return values after testing is complete |
| 39 // - generate -- generate a valid set of random arguments for the GL function |
| 40 // - returnValueCleanup -- do cleanup on value returned by the tested GL funct
ion |
| 41 // - cleanup -- do cleanup on generated arguments from generate |
| 42 // - checkArgValidity -- check if passed args are valid. Has a call signature |
| 43 // that matches generate's return value. Returns true |
| 44 // if args are valid, false if not. |
| 45 // |
| 46 // Example test loop that demonstrates how the function args and return |
| 47 // values flow together: |
| 48 // |
| 49 // var setupArgs = argGen.setup(); |
| 50 // for (var i=0; i<numberOfTests; i++) { |
| 51 // var generatedArgs = argGen.generate.apply(argGen, setupArgs); |
| 52 // var validArgs = argGen.checkArgValidity.apply(argGen, generatedArgs); |
| 53 // var rv = call the GL function with generatedArgs; |
| 54 // argGen.returnValueCleanup(rv); |
| 55 // argGen.cleanup.apply(argGen, generatedArgs); |
| 56 // } |
| 57 // argGen.teardown.apply(argGen, setupArgs); |
| 58 // |
| 59 ArgGenerators = { |
| 60 |
| 61 // GL functions in alphabetical order |
| 62 |
| 63 // S-2 |
| 64 |
| 65 stencilMaskSeparate : { |
| 66 generate : function() { return [cullFace.random(), randomInt(0xffffffff)]; }
, |
| 67 checkArgValidity : function(face, mask) { |
| 68 return cullFace.has(face); |
| 69 }, |
| 70 teardown : function() { GL.stencilMask(0xffffffff); } |
| 71 }, |
| 72 stencilOp : { |
| 73 generate : function() { |
| 74 return [stencilOp.random(), stencilOp.random(), stencilOp.random()]; |
| 75 }, |
| 76 checkArgValidity : function(sfail, dpfail, dppass) { |
| 77 return stencilOp.has(sfail) && stencilOp.has(dpfail) && stencilOp.has(dppa
ss); |
| 78 }, |
| 79 teardown : function() { GL.stencilOp(GL.KEEP, GL.KEEP, GL.KEEP); } |
| 80 }, |
| 81 stencilOpSeparate : { |
| 82 generate : function() { |
| 83 return [cullFace.random(), stencilOp.random(), stencilOp.random(), stencil
Op.random()]; |
| 84 }, |
| 85 checkArgValidity : function(face, sfail, dpfail, dppass) { |
| 86 return cullFace.has(face) && stencilOp.has(sfail) && |
| 87 stencilOp.has(dpfail) && stencilOp.has(dppass); |
| 88 }, |
| 89 teardown : function() { GL.stencilOp(GL.KEEP, GL.KEEP, GL.KEEP); } |
| 90 }, |
| 91 |
| 92 // T |
| 93 texImage2D : { |
| 94 noAlreadyTriedCheck : true, // Object.toSource is very slow here |
| 95 setup : function() { |
| 96 var tex = GL.createTexture(); |
| 97 var tex2 = GL.createTexture(); |
| 98 GL.bindTexture(GL.TEXTURE_2D, tex); |
| 99 GL.bindTexture(GL.TEXTURE_CUBE_MAP, tex2); |
| 100 return [tex, tex2]; |
| 101 }, |
| 102 generate : function() { |
| 103 var format = texImageFormat.random(); |
| 104 if (Math.random() < 0.5) { |
| 105 var img = randomImage(16,16); |
| 106 var a = [ texImageTarget.random(), 0, format, format, GL.UNSIGNED_BYTE,
img ]; |
| 107 return a; |
| 108 } else { |
| 109 var pix = null; |
| 110 if (Math.random > 0.5) { |
| 111 pix = new Uint8Array(16*16*4); |
| 112 } |
| 113 return [ |
| 114 texImageTarget.random(), 0, |
| 115 format, 16, 16, 0, |
| 116 format, GL.UNSIGNED_BYTE, pix |
| 117 ]; |
| 118 } |
| 119 }, |
| 120 checkArgValidity : function(target, level, internalformat, width, height, bo
rder, format, type, data) { |
| 121 // or : function(target, level, internalformat, format, type, ima
ge) |
| 122 if (!texImageTarget.has(target) || castToInt(level) < 0) |
| 123 return false; |
| 124 if (arguments.length <= 6) { |
| 125 var xformat = width; |
| 126 var xtype = height; |
| 127 var ximage = border; |
| 128 if ((ximage instanceof HTMLImageElement || |
| 129 ximage instanceof HTMLVideoElement || |
| 130 ximage instanceof HTMLCanvasElement || |
| 131 ximage instanceof ImageData) && |
| 132 texImageInternalFormat.has(internalformat) && |
| 133 texImageFormat.has(xformat) && |
| 134 texImageType.has(xtype) && |
| 135 internalformat == xformat) |
| 136 return true; |
| 137 return false; |
| 138 } |
| 139 var w = castToInt(width), h = castToInt(height), b = castToInt(border); |
| 140 return texImageInternalFormat.has(internalformat) && w >= 0 && h >= 0 && |
| 141 b == 0 && (data == null || data.byteLength == w*h*4) && |
| 142 texImageFormat.has(format) && texImageType.has(type) |
| 143 && internalformat == format; |
| 144 }, |
| 145 teardown : function(tex, tex2) { |
| 146 GL.bindTexture(GL.TEXTURE_2D, null); |
| 147 GL.bindTexture(GL.TEXTURE_CUBE_MAP, null); |
| 148 GL.deleteTexture(tex); |
| 149 GL.deleteTexture(tex2); |
| 150 } |
| 151 }, |
| 152 texParameterf : { |
| 153 generate : function() { |
| 154 var pname = texParameterPname.random(); |
| 155 var param = texParameterParam[pname].random(); |
| 156 return [bindTextureTarget.random(), pname, param]; |
| 157 }, |
| 158 checkArgValidity : function(target, pname, param) { |
| 159 if (!bindTextureTarget.has(target)) |
| 160 return false; |
| 161 if (!texParameterPname.has(pname)) |
| 162 return false; |
| 163 return texParameterParam[pname].has(param); |
| 164 } |
| 165 }, |
| 166 texParameteri : { |
| 167 generate : function() { |
| 168 var pname = texParameterPname.random(); |
| 169 var param = texParameterParam[pname].random(); |
| 170 return [bindTextureTarget.random(), pname, param]; |
| 171 }, |
| 172 checkArgValidity : function(target, pname, param) { |
| 173 if (!bindTextureTarget.has(target)) |
| 174 return false; |
| 175 if (!texParameterPname.has(pname)) |
| 176 return false; |
| 177 return texParameterParam[pname].has(param); |
| 178 } |
| 179 }, |
| 180 texSubImage2D : {}, // FIXME |
| 181 |
| 182 // U |
| 183 |
| 184 uniform1f : {}, // FIXME |
| 185 uniform1fv : {}, // FIXME |
| 186 uniform1i : {}, // FIXME |
| 187 uniform1iv : {}, // FIXME |
| 188 uniform2f : {}, // FIXME |
| 189 uniform2fv : {}, // FIXME |
| 190 uniform2i : {}, // FIXME |
| 191 uniform2iv : {}, // FIXME |
| 192 uniform3f : {}, // FIXME |
| 193 uniform3fv : {}, // FIXME |
| 194 uniform3i : {}, // FIXME |
| 195 uniform3iv : {}, // FIXME |
| 196 uniform4f : {}, // FIXME |
| 197 uniform4fv : {}, // FIXME |
| 198 uniform4i : {}, // FIXME |
| 199 uniform4iv : {}, // FIXME |
| 200 uniformMatrix2fv : {}, // FIXME |
| 201 uniformMatrix3fv : {}, // FIXME |
| 202 uniformMatrix4fv : {}, // FIXME |
| 203 useProgram : {}, // FIXME |
| 204 |
| 205 // V |
| 206 |
| 207 validateProgram : {}, // FIXME |
| 208 vertexAttrib1f : {}, // FIXME |
| 209 vertexAttrib1fv : {}, // FIXME |
| 210 vertexAttrib2f : {}, // FIXME |
| 211 vertexAttrib2fv : {}, // FIXME |
| 212 vertexAttrib3f : {}, // FIXME |
| 213 vertexAttrib3fv : {}, // FIXME |
| 214 vertexAttrib4f : {}, // FIXME |
| 215 vertexAttrib4fv : {}, // FIXME |
| 216 vertexAttribPointer : {}, // FIXME |
| 217 viewport : { |
| 218 generate : function() { |
| 219 return [randomInt(3000)-1500, randomInt(3000)-1500, randomIntFromRange(0,3
000), randomIntFromRange(0,3000)]; |
| 220 }, |
| 221 checkArgValidity : function(x,y,w,h) { |
| 222 return castToInt(w) >= 0 && castToInt(h) >= 0; |
| 223 }, |
| 224 teardown : function() { |
| 225 GL.viewport(0,0,GL.canvas.width, GL.canvas.height); |
| 226 } |
| 227 } |
| 228 |
| 229 }; |
OLD | NEW |