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.
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>
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;
29 gl_Position = a_position;
34 <script id=
"fs_texture_3d" type=
"x-shader/x-fragment">#version
300 es
35 precision mediump float;
37 uniform mediump sampler3D u_sampler;
40 o_color = texture(u_sampler, vec3(v_coord,
0.0));
44 <script id=
"fs_texture_2d_array" type=
"x-shader/x-fragment">#version
300 es
45 precision mediump float;
47 uniform mediump sampler2DArray u_sampler;
50 o_color = texture(u_sampler, vec3(v_coord,
0.0));
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");
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
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";
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]);
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
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
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
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
137 testFailed("Fail to get 1st WebGL2 context");
141 testFailed("Fail to get 2nd WebGL2 context");
145 var successfullyParsed
= true;
147 <script src=
"../../js/js-test-post.js"></script>