Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / context / context-sharing-texture2darray-texture3d-data-bug.html
blob8ef6dd74b336e26d0ba9abbade1d6b93e2e28924
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>Multiple WebGL2 Context sharing texture2darray/texture3d data bug 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 <div id="description"></div>
18 <canvas id="canvas1" width="64" height="64"> </canvas>
19 <canvas id="canvas2" width="64" height="64"> </canvas>
20 <div id="console"></div>
22 <!-- WebGL 2 Shaders -->
23 <script id="vs" type="x-shader/x-vertex">#version 300 es
24 precision mediump float;
25 in vec4 a_position;
26 in vec2 a_coord;
27 out vec2 v_coord;
28 void main() {
29 gl_Position = a_position;
30 v_coord = a_coord;
32 </script>
34 <script id="fs_texture_3d" type="x-shader/x-fragment">#version 300 es
35 precision mediump float;
36 in vec2 v_coord;
37 uniform mediump sampler3D u_sampler;
38 out vec4 o_color;
39 void main () {
40 o_color = texture(u_sampler, vec3(v_coord, 0.0));
42 </script>
44 <script id="fs_texture_2d_array" type="x-shader/x-fragment">#version 300 es
45 precision mediump float;
46 in vec2 v_coord;
47 uniform mediump sampler2DArray u_sampler;
48 out vec4 o_color;
49 void main () {
50 o_color = texture(u_sampler, vec3(v_coord, 0.0));
52 </script>
54 <script>
55 "use strict";
56 description("This test verifies that 2 different contexts both using 2d array texture or 3d texture does not share the texture data among them due to context save/restore bug. https://bugs.chromium.org/p/chromium/issues/detail?id=788448");
57 debug("");
59 function render(gl, width, height, expectedColor, msg) {
60 wtu.setupUnitQuad(gl, 0, 1);
61 wtu.clearAndDrawUnitQuad(gl);
62 wtu.checkCanvasRect(gl, 0, 0, width, height, expectedColor, msg);
65 function StateSetup(gl, texture_type, texture_color, width, height) {
67 // create a buffer to hold texture data
68 const depth = 4;
69 var size = width * height * depth * 4;
70 var buf = new Uint8Array(size);
71 for (var i = 0; i < size; i += 4) {
72 buf[i + 0] = texture_color[0];
73 buf[i + 1] = texture_color[1];
74 buf[i + 2] = texture_color[2];
75 buf[i + 3] = texture_color[3];
77 gl.viewport(0, 0, width, height);
79 // choose texture type and fragment shader type
80 var tex_type = gl.TEXTURE_2D;
81 var fragment_shader = "", vertex_shader = "vs";
82 if(texture_type === "3d") {
83 tex_type = gl.TEXTURE_3D, fragment_shader = "fs_texture_3d";
84 } else if(texture_type === "2d_array") {
85 tex_type = gl.TEXTURE_2D_ARRAY, fragment_shader = "fs_texture_2d_array";
86 } else {
87 testFailed("Texture type must be 3d or 2darray");
90 var program = wtu.setupProgram(gl, [vertex_shader, fragment_shader], ['a_position', 'a_coord'], [0, 1]);
92 // create a texture
93 var texture = gl.createTexture();
94 gl.activeTexture(gl.TEXTURE0);
96 // program texture parameters
97 gl.activeTexture(gl.TEXTURE0);
98 gl.bindTexture(tex_type, texture);
99 gl.texImage3D(tex_type, 0, gl.RGBA, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, buf);
100 gl.texParameteri(tex_type, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
101 gl.texParameteri(tex_type, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
103 // bind sampler to the texture
104 var samplerLoc = gl.getUniformLocation(program, "u_sampler");
105 gl.uniform1i(samplerLoc, 0);
107 // flush all gl commands
108 gl.flush();
111 var wtu = WebGLTestUtils;
112 var canvas1 = document.getElementById("canvas1");
113 var gl1 = wtu.create3DContext(canvas1, null, 2); //context1
115 var canvas2 = document.getElementById("canvas2");
116 var gl2 = wtu.create3DContext(canvas2, null, 2); // context2
118 if (gl1 && gl2)
120 testPassed("Created 2 WebGL2 context successfully");
121 var red = [255, 0, 0, 255], green = [0,255,0,255], blue = [0,0,255,255];
122 var width = 64, height = 64;
123 var texture_type = "3d", texture_color = green;
124 StateSetup(gl1,texture_type, texture_color, width, height);// context1 state setup
125 texture_color = red;
126 StateSetup(gl2, texture_type, texture_color, width, height);// context2 state setup
127 render(gl1, width, height, green, "Result pixels rendering from context1 with 3d texture should be green");// render context1
129 texture_type = "2d_array", texture_color = blue;
130 StateSetup(gl1, texture_type, texture_color, width, height);// context1 state setup
131 texture_color = green;
132 StateSetup(gl2, texture_type, texture_color, width, height);// context2 state setup
133 render(gl1, width, height, blue, "Result pixels rendering from context1 with 2darray texture should be blue");//render context1
135 else if(!gl1)
137 testFailed("Fail to get 1st WebGL2 context");
139 else
141 testFailed("Fail to get 2nd WebGL2 context");
144 debug("");
145 var successfullyParsed = true;
146 </script>
147 <script src="../../js/js-test-post.js"></script>
149 </body>
150 </html>