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