2 ** Copyright (c) 2013 The Khronos Group Inc.
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:
12 ** The above copyright notice and this permission notice shall be included
13 ** in all copies or substantial portions of the Materials.
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.
23 IterableTest = (function() {
25 var wtu = WebGLTestUtils;
27 function run(test, iterations) {
28 var target = iterations || 10;
31 function doNextTest() {
33 debug("Test " + count + " of " + target);
35 if (count < target && success !== false) {
36 wtu.waitForComposite(doNextTest);
37 //setTimeout(doNextTest, 100);
46 // Creates a canvas and a texture then exits. There are
47 // no references to either so both should be garbage collected.
48 function createContextCreationAndDestructionTest() {
49 var textureSize = null;
52 var canvas = document.createElement("canvas");
53 // This is safe for any device. See drawingBufferWidth in spec.
56 var gl = wtu.create3DContext(canvas);
57 if (textureSize === null) {
58 var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
59 textureSize = Math.min(1024, maxTextureSize);
61 var tex = gl.createTexture();
62 gl.bindTexture(gl.TEXTURE_2D, tex);
63 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, textureSize, textureSize, 0, gl.RGBA, gl.UNSIGNED_BYTE,
65 gl.clear(gl.COLOR_BUFFER_BIT);
66 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
72 // Creates many small canvases and attaches them to the DOM.
73 // This tests an edge case discovered in Chrome where the creation of multiple
74 // WebGL contexts would eventually lead to context creation failure.
75 // (crbug.com/319265) The test does not require that old contexts remain
76 // valid, only that new ones can be created.
77 function createContextCreationTest() {
79 var canvas = document.createElement("canvas");
83 document.body.appendChild(canvas);
85 var gl = wtu.create3DContext(canvas);
90 gl.clear(gl.COLOR_BUFFER_BIT);
91 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors");
97 // Creates a canvas and a texture then exits. There are
98 // no references to either so both should be garbage collected.
99 function createMultisampleCorruptionTest(gl) {
100 var lastContext = null;
102 var program = wtu.loadStandardProgram(gl);
103 var uniforms = wtu.getUniformMap(gl, program);
104 gl.useProgram(program);
106 gl.clearColor(1.0, 0.0, 0.0, 1.0);
107 gl.clear(gl.COLOR_BUFFER_BIT);
109 var vertexObject = gl.createBuffer();
110 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
111 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,2.5,0, 1.5,1.5,0, 2.5,1.5,0 ]), gl.STATIC_DRAW);
112 gl.enableVertexAttribArray(0);
113 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
114 gl.vertexAttrib3f(1, 0.0, 0.0, 1.0);
116 var identityMat = new Float32Array([
123 gl.uniformMatrix4fv(uniforms.u_modelViewProjMatrix.location, false, identityMat);
126 var gl2 = wtu.create3DContext(null, {antialias: true});
128 gl2.canvas.width = gl2.canvas.height = 1024;
129 gl2.canvas.style.width = gl2.canvas.style.height = "1px";
130 document.body.appendChild(gl2.canvas);
132 gl2.clearColor(1.0, 0.0, 0.0, 1.0);
133 gl2.clear(gl2.COLOR_BUFFER_BIT);
136 gl.drawArrays(gl.TRIANGLES, 0, 3);
137 var msg = "Canvas should be red";
138 wtu.checkCanvasRectColor(gl,
139 0, 0, gl.canvas.width, gl.canvas.height,
140 [255, 0, 0, 255], null,
149 document.body.removeChild(lastContext.canvas);
156 // First pass does initialization
165 createContextCreationAndDestructionTest: createContextCreationAndDestructionTest,
166 createContextCreationTest: createContextCreationTest,
167 createMultisampleCorruptionTest: createMultisampleCorruptionTest