Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / samplers / multi-context-sampler-test.html
blob05e0f2048011d72deda5b60f824107ccc0a4f875
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL Multi-Context Sampler Test</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <canvas id="canvas_drawing" width="12" height="12"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script>
21 "use strict";
22 description("Tests that samplers' state doesn't leak across contexts");
23 debug("");
24 debug('Regression test for <a href="http://crbug.com/713127">http://crbug.com/713127</a>');
26 function runTest() {
27 var wtu = WebGLTestUtils;
28 var gl = wtu.create3DContext("canvas_drawing", undefined, 2);
29 var texture = null;
30 var color = [0, 255, 0, 255];
32 if (!gl) {
33 testFailed("WebGL context does not exist");
34 return;
37 testPassed("WebGL context exists");
39 wtu.setupTexturedQuad(gl);
40 texture = gl.createTexture();
41 // Create a texture bigger than 1x1 so that it would need mipmaps in
42 // order to be complete.
43 wtu.fillTexture(gl, texture, 2, 2, color, 0,
44 gl.RGBA, gl.UNSIGNED_BYTE, gl.RGBA8);
45 // Set texture parameters so that this texture is complete.
46 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
47 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
49 // Set up a secondary context with a sampler bound to texture unit
50 // 0. This should not interfere with the primary context.
51 var altGL = wtu.create3DContext(undefined, undefined, 2);
52 if (!altGL) {
53 testFailed("Error creating secondary WebGL context");
54 return;
57 var sampler = altGL.createSampler();
58 // Note that the sampler's default TEXTURE_MIN_FILTER is
59 // NEAREST_MIPMAP_LINEAR.
60 altGL.bindSampler(0, sampler);
61 altGL.clearColor(1, 0, 0, 1);
62 altGL.clear(altGL.COLOR_BUFFER_BIT);
63 wtu.checkCanvasRect(altGL, 0, 0, 1, 1, [ 255, 0, 0, 255 ],
64 "should be red");
66 // Now switch back to the main context and draw the texture.
67 gl.clearColor(1, 1, 1, 1);
68 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
69 wtu.drawUnitQuad(gl);
70 // The presence of the sampler on the other context should not
71 // have interfered with the completeness of the texture.
72 wtu.checkCanvasRect(gl, 0, 0, 1, 1, color,
73 "should be green");
75 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
78 runTest();
79 var successfullyParsed = true;
80 </script>
81 <script src="../../js/js-test-post.js"></script>
83 </body>
84 </html>