| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <meta charset="utf-8"> | |
| 5 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
| 6 <script src="../resources/js-test-pre.js"></script> | |
| 7 <script src="resources/webgl-test.js"></script> | |
| 8 <script src="resources/webgl-test-utils.js"></script> | |
| 9 <script> | |
| 10 var wtu; | |
| 11 var canvas; | |
| 12 var gl; | |
| 13 var shouldGenerateGLError; | |
| 14 var extension_name = "WEBKIT_lose_context"; | |
| 15 var extension; | |
| 16 | |
| 17 var buffer; | |
| 18 var framebuffer; | |
| 19 var program; | |
| 20 var renderbuffer; | |
| 21 var shader; | |
| 22 var texture; | |
| 23 var uniformLocation; | |
| 24 var arrayBuffer; | |
| 25 var arrayBufferView | |
| 26 var image; | |
| 27 var video; | |
| 28 var canvas2d; | |
| 29 var ctx2d; | |
| 30 var imageData; | |
| 31 var float32array; | |
| 32 var int32array; | |
| 33 | |
| 34 function init() | |
| 35 { | |
| 36 wtu = WebGLTestUtils; | |
| 37 canvas = document.getElementById("canvas"); | |
| 38 gl = wtu.create3DContext(canvas); | |
| 39 shouldGenerateGLError = wtu.shouldGenerateGLError; | |
| 40 | |
| 41 description("Tests behavior under a lost context"); | |
| 42 | |
| 43 if (window.initNonKhronosFramework) { | |
| 44 window.initNonKhronosFramework(true); | |
| 45 } | |
| 46 | |
| 47 // call testValidContext() before checking for the extension, because this i
s where we check | |
| 48 // for the isContextLost() method, which we want to do regardless of the ext
ension's presence. | |
| 49 testValidContext(); | |
| 50 | |
| 51 extension = gl.getExtension(extension_name); | |
| 52 if (!extension) { | |
| 53 debug(extension_name + " extension not found."); | |
| 54 finish(); | |
| 55 return; | |
| 56 } | |
| 57 | |
| 58 canvas.addEventListener("webglcontextlost", testLostContext, false); | |
| 59 | |
| 60 loseContext(); | |
| 61 } | |
| 62 | |
| 63 function loseContext() | |
| 64 { | |
| 65 debug(""); | |
| 66 debug("Lose context"); | |
| 67 shouldGenerateGLError(gl, gl.NO_ERROR, "extension.loseContext()"); | |
| 68 debug(""); | |
| 69 } | |
| 70 | |
| 71 function testValidContext() | |
| 72 { | |
| 73 debug("Test valid context"); | |
| 74 | |
| 75 shouldBeFalse("gl.isContextLost()"); | |
| 76 | |
| 77 arrayBuffer = new ArrayBuffer(4); | |
| 78 arrayBufferView = new Int8Array(arrayBuffer); | |
| 79 | |
| 80 // Generate resources for testing. | |
| 81 buffer = gl.createBuffer(); | |
| 82 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); | |
| 83 framebuffer = gl.createFramebuffer(); | |
| 84 gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); | |
| 85 program = wtu.setupSimpleTextureProgram(gl); | |
| 86 renderbuffer = gl.createRenderbuffer(); | |
| 87 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); | |
| 88 shader = gl.createShader(gl.VERTEX_SHADER); | |
| 89 texture = gl.createTexture(); | |
| 90 gl.bindTexture(gl.TEXTURE_2D, texture); | |
| 91 shouldBe("gl.getError()", "gl.NO_ERROR"); | |
| 92 | |
| 93 // Test is queries that will later be false | |
| 94 shouldGenerateGLError(gl, gl.NO_ERROR, "gl.enable(gl.BLEND)"); | |
| 95 shouldBeTrue("gl.isBuffer(buffer)"); | |
| 96 shouldBeTrue("gl.isEnabled(gl.BLEND)"); | |
| 97 shouldBeTrue("gl.isFramebuffer(framebuffer)"); | |
| 98 shouldBeTrue("gl.isProgram(program)"); | |
| 99 shouldBeTrue("gl.isRenderbuffer(renderbuffer)"); | |
| 100 shouldBeTrue("gl.isShader(shader)"); | |
| 101 shouldBeTrue("gl.isTexture(texture)"); | |
| 102 } | |
| 103 | |
| 104 function testLostContext() | |
| 105 { | |
| 106 debug("Test lost context"); | |
| 107 | |
| 108 // Functions with special return values. | |
| 109 shouldBeTrue("gl.isContextLost()"); | |
| 110 shouldBe("gl.getError()", "gl.CONTEXT_LOST_WEBGL"); | |
| 111 shouldBe("gl.getError()", "gl.NO_ERROR"); | |
| 112 shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_UNSUPP
ORTED"); | |
| 113 shouldBe("gl.getAttribLocation(program, 'u_modelViewProjMatrix')", "-1"); | |
| 114 shouldBe("gl.getVertexAttribOffset(0, gl.VERTEX_ATTRIB_ARRAY_POINTER)", "0")
; | |
| 115 | |
| 116 // Test the extension itself. | |
| 117 shouldGenerateGLError(gl, gl.INVALID_OPERATION, "extension.loseContext()"); | |
| 118 | |
| 119 image = document.createElement("image"); | |
| 120 video = document.createElement("video"); | |
| 121 canvas2d = document.createElement("canvas"); | |
| 122 ctx2d = canvas2d.getContext("2d"); | |
| 123 imageData = ctx2d.createImageData(1, 1); | |
| 124 float32array = new Float32Array(1); | |
| 125 int32array = new Int32Array(1); | |
| 126 | |
| 127 // Functions returning void should return immediately. | |
| 128 // This is untestable, but we can at least be sure they cause no errors | |
| 129 // and the codepaths are exercised. | |
| 130 var voidTests = [ | |
| 131 "gl.activeTexture(gl.TEXTURE0)", | |
| 132 "gl.attachShader(program, shader)", | |
| 133 "gl.bindBuffer(gl.ARRAY_BUFFER, buffer)", | |
| 134 "gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer)", | |
| 135 "gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer)", | |
| 136 "gl.bindTexture(gl.TEXTURE_2D, texture)", | |
| 137 "gl.blendColor(1.0, 1.0, 1.0, 1.0)", | |
| 138 "gl.blendEquation(gl.FUNC_ADD)", | |
| 139 "gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD)", | |
| 140 "gl.blendFunc(gl.ONE, gl.ONE)", | |
| 141 "gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE)", | |
| 142 "gl.bufferData(gl.ARRAY_BUFFER, 0, gl.STATIC_DRAW)", | |
| 143 "gl.bufferData(gl.ARRAY_BUFFER, arrayBufferView, gl.STATIC_DRAW)", | |
| 144 "gl.bufferData(gl.ARRAY_BUFFER, arrayBuffer, gl.STATIC_DRAW)", | |
| 145 "gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBufferView)", | |
| 146 "gl.bufferSubData(gl.ARRAY_BUFFRE, 0, arrayBuffer)", | |
| 147 "gl.clear(gl.COLOR_BUFFER_BIT)", | |
| 148 "gl.clearColor(1, 1, 1, 1)", | |
| 149 "gl.clearDepth(1)", | |
| 150 "gl.clearStencil(0)", | |
| 151 "gl.colorMask(1, 1, 1, 1)", | |
| 152 "gl.compileShader(shader)", | |
| 153 "gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, 0, 0)", | |
| 154 "gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 0, 0)", | |
| 155 "gl.cullFace(gl.FRONT)", | |
| 156 "gl.deleteBuffer(buffer)", | |
| 157 "gl.deleteFramebuffer(framebuffer)", | |
| 158 "gl.deleteProgram(program)", | |
| 159 "gl.deleteRenderbuffer(renderbuffer)", | |
| 160 "gl.deleteShader(shader)", | |
| 161 "gl.deleteTexture(texture)", | |
| 162 "gl.depthFunc(gl.NEVER)", | |
| 163 "gl.depthMask(0)", | |
| 164 "gl.depthRange(0, 1)", | |
| 165 "gl.detachShader(program, shader)", | |
| 166 "gl.disable(gl.BLEND)", | |
| 167 "gl.disableVertexAttribArray(0)", | |
| 168 "gl.drawArrays(gl.POINTS, 0, 0)", | |
| 169 "gl.drawElements(gl.POINTS, 0, gl.UNSIGNED_SHORT, 0)", | |
| 170 "gl.enable(gl.BLEND)", | |
| 171 "gl.enableVertexAttribArray(0)", | |
| 172 "gl.finish()", | |
| 173 "gl.flush()", | |
| 174 "gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.REN
DERBUFFER, renderbuffer)", | |
| 175 "gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTUR
E_2D, texture, 0)", | |
| 176 "gl.frontFace(gl.CW)", | |
| 177 "gl.generateMipmap(gl.TEXTURE_2D)", | |
| 178 "gl.hint(gl.GENERATE_MIPMAP_HINT, gl.FASTEST)", | |
| 179 "gl.lineWidth(0)", | |
| 180 "gl.linkProgram(program)", | |
| 181 "gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0)", | |
| 182 "gl.polygonOffset(0, 0)", | |
| 183 "gl.readPixels(0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, arrayBufferView)", | |
| 184 "gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, 0, 0)", | |
| 185 "gl.sampleCoverage(0, 0)", | |
| 186 "gl.scissor(0, 0, 0, 0)", | |
| 187 "gl.shaderSource(shader, '')", | |
| 188 "gl.stencilFunc(gl.NEVER, 0, 0)", | |
| 189 "gl.stencilFuncSeparate(gl.FRONT, gl.NEVER, 0, 0)", | |
| 190 "gl.stencilMask(0)", | |
| 191 "gl.stencilMaskSeparate(gl.FRONT, 0)", | |
| 192 "gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP)", | |
| 193 "gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP)", | |
| 194 "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 0, gl.RGBA, gl.UNSIGNED_
BYTE, arrayBufferView)", | |
| 195 "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, ima
geData)", | |
| 196 "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, ima
ge)", | |
| 197 "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, can
vas)", | |
| 198 "gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, vid
eo)", | |
| 199 "gl.texParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)", | |
| 200 "gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)", | |
| 201 "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYT
E, arrayBufferView)", | |
| 202 "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, ima
geData)", | |
| 203 "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, ima
ge)", | |
| 204 "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, can
vas)", | |
| 205 "gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, vid
eo)", | |
| 206 "gl.uniform1f(uniformLocation, 0)", | |
| 207 "gl.uniform1fv(uniformLocation, float32array)", | |
| 208 "gl.uniform1fv(uniformLocation, [0])", | |
| 209 "gl.uniform1i(uniformLocation, 0)", | |
| 210 "gl.uniform1iv(uniformLocation, int32array)", | |
| 211 "gl.uniform1iv(uniformLocation, [0])", | |
| 212 "gl.uniform2f(uniformLocation, 0, 0)", | |
| 213 "gl.uniform2fv(uniformLocation, float32array)", | |
| 214 "gl.uniform2fv(uniformLocation, [0, 0])", | |
| 215 "gl.uniform2i(uniformLocation, 0, 0)", | |
| 216 "gl.uniform2iv(uniformLocation, int32array)", | |
| 217 "gl.uniform2iv(uniformLocation, [0, 0])", | |
| 218 "gl.uniform3f(uniformLocation, 0, 0, 0)", | |
| 219 "gl.uniform3fv(uniformLocation, float32array)", | |
| 220 "gl.uniform3fv(uniformLocation, [0, 0, 0])", | |
| 221 "gl.uniform3i(uniformLocation, 0, 0, 0)", | |
| 222 "gl.uniform3iv(uniformLocation, int32array)", | |
| 223 "gl.uniform3iv(uniformLocation, [0, 0, 0])", | |
| 224 "gl.uniform4f(uniformLocation, 0, 0, 0, 0)", | |
| 225 "gl.uniform4fv(uniformLocation, float32array)", | |
| 226 "gl.uniform4fv(uniformLocation, [0, 0, 0, 0])", | |
| 227 "gl.uniform4i(uniformLocation, 0, 0, 0, 0)", | |
| 228 "gl.uniform4iv(uniformLocation, int32array)", | |
| 229 "gl.uniform4iv(uniformLocation, [0, 0, 0, 0])", | |
| 230 "gl.uniformMatrix2fv(uniformLocation, false, float32array)", | |
| 231 "gl.uniformMatrix2fv(uniformLocation, false, [0, 0, 0, 0])", | |
| 232 "gl.uniformMatrix3fv(uniformLocation, false, float32array)", | |
| 233 "gl.uniformMatrix3fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0]
)", | |
| 234 "gl.uniformMatrix4fv(uniformLocation, false, float32array)", | |
| 235 "gl.uniformMatrix4fv(uniformLocation, false, [0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0])", | |
| 236 "gl.useProgram(program)", | |
| 237 "gl.validateProgram(program)", | |
| 238 "gl.vertexAttrib1f(0, 0)", | |
| 239 "gl.vertexAttrib1fv(0, float32array)", | |
| 240 "gl.vertexAttrib1fv(0, [0])", | |
| 241 "gl.vertexAttrib2f(0, 0, 0)", | |
| 242 "gl.vertexAttrib2fv(0, float32array)", | |
| 243 "gl.vertexAttrib2fv(0, [0, 0])", | |
| 244 "gl.vertexAttrib3f(0, 0, 0, 0)", | |
| 245 "gl.vertexAttrib3fv(0, float32array)", | |
| 246 "gl.vertexAttrib3fv(0, [0, 0, 0])", | |
| 247 "gl.vertexAttrib4f(0, 0, 0, 0, 0)", | |
| 248 "gl.vertexAttrib4fv(0, float32array)", | |
| 249 "gl.vertexAttrib4fv(0, [0, 0, 0, 0])", | |
| 250 "gl.vertexAttribPointer(0, 0, gl.FLOAT, false, 0, 0)", | |
| 251 "gl.viewport(0, 0, 0, 0)", | |
| 252 ]; | |
| 253 for (var i = 0; i < voidTests.length; ++i) { | |
| 254 shouldGenerateGLError(gl, gl.NO_ERROR, voidTests[i]); | |
| 255 } | |
| 256 | |
| 257 // Functions return nullable values should all return null. | |
| 258 var nullTests = [ | |
| 259 "gl.createBuffer()", | |
| 260 "gl.createFramebuffer()", | |
| 261 "gl.createProgram()", | |
| 262 "gl.createRenderbuffer()", | |
| 263 "gl.createShader(gl.GL_VERTEX_SHADER)", | |
| 264 "gl.createTexture()", | |
| 265 "gl.getActiveAttrib(program, 0)", | |
| 266 "gl.getActiveUniform(program, 0)", | |
| 267 "gl.getAttachedShaders(program)", | |
| 268 "gl.getBufferParameter(gl.ARRAY_BUFFER, gl.BUFFER_SIZE)", | |
| 269 "gl.getContextAttributes()", | |
| 270 "gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl.COLOR_ATTACHMEN
T0, gl.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME)", | |
| 271 "gl.getParameter(gl.CURRENT_PROGRAM)", | |
| 272 "gl.getProgramInfoLog(program)", | |
| 273 "gl.getProgramParameter(program, gl.LINK_STATUS)", | |
| 274 "gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_WIDTH)", | |
| 275 "gl.getShaderInfoLog(shader)", | |
| 276 "gl.getShaderParameter(shader, gl.SHADER_TYPE)", | |
| 277 "gl.getShaderSource(shader)", | |
| 278 "gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)", | |
| 279 "gl.getUniform(program, uniformLocation)", | |
| 280 "gl.getUniformLocation(program, 'vPosition')", | |
| 281 "gl.getVertexAttrib(0, gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING)", | |
| 282 "gl.getSupportedExtensions()", | |
| 283 "gl.getExtension('" + extension_name + "')", | |
| 284 ]; | |
| 285 for (var i = 0; i < nullTests.length; ++i) { | |
| 286 shouldBeNull(nullTests[i]); | |
| 287 } | |
| 288 | |
| 289 // "Is" queries should all return false. | |
| 290 shouldBeFalse("gl.isBuffer(buffer)"); | |
| 291 shouldBeFalse("gl.isEnabled(gl.BLEND)"); | |
| 292 shouldBeFalse("gl.isFramebuffer(framebuffer)"); | |
| 293 shouldBeFalse("gl.isProgram(program)"); | |
| 294 shouldBeFalse("gl.isRenderbuffer(renderbuffer)"); | |
| 295 shouldBeFalse("gl.isShader(shader)"); | |
| 296 shouldBeFalse("gl.isTexture(texture)"); | |
| 297 | |
| 298 shouldBe("gl.getError()", "gl.NO_ERROR"); | |
| 299 | |
| 300 finish(); | |
| 301 } | |
| 302 | |
| 303 function finish() { | |
| 304 successfullyParsed = true; | |
| 305 var epilogue = document.createElement("script"); | |
| 306 epilogue.onload = function() { | |
| 307 if (window.nonKhronosFrameworkNotifyDone) | |
| 308 window.nonKhronosFrameworkNotifyDone(); | |
| 309 }; | |
| 310 epilogue.src = "../resources/js-test-post.js"; | |
| 311 document.body.appendChild(epilogue); | |
| 312 } | |
| 313 </script> | |
| 314 </head> | |
| 315 <body onload="init()"> | |
| 316 <div id="description"></div> | |
| 317 <div id="console"></div> | |
| 318 <canvas id="canvas"> | |
| 319 </body> | |
| 320 </html> | |
| OLD | NEW |