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>WebGL Active TEXTURE1 Bug Tests
</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=
"canvas" width=
"64" height=
"64"> </canvas>
19 <div id=
"console"></div>
20 <script id=
"vshader" type=
"x-shader/x-vertex">#version
300 es
21 precision mediump float;
26 gl_Position = a_position;
30 <script id=
"fshader" type=
"x-shader/x-fragment">#version
300 es
31 precision mediump float;
33 uniform mediump sampler3D u_sampler;
36 o_color = texture(u_sampler, vec3(v_coord,
0.0));
41 description("Test for a MacOSX 10.12 with Intel GPUs driver crash bug activating TEXTURE1 for 3d texture");
44 var wtu
= WebGLTestUtils
;
45 var canvas
= document
.getElementById("canvas");
46 var gl
= wtu
.create3DContext(canvas
, null, 2);
49 function render(textureUnit
, width
, height
, expectedColor
, msg
) {
50 gl
.uniform1i(samplerLoc
, textureUnit
);
51 wtu
.setupUnitQuad(gl
, 0, 1);
52 wtu
.clearAndDrawUnitQuad(gl
);
53 wtu
.checkCanvasRect(gl
, 0, 0, width
, height
, expectedColor
, msg
);
56 function activeTextureTest() {
57 var texture
= gl
.createTexture();
58 var sampler
= gl
.createSampler();
62 var black
= [0, 0, 0, 255];
63 var size
= width
* height
* depth
* 4;
65 var buf
= new Uint8Array(size
);
66 for (var i
= 0; i
< size
; i
+= 4) {
73 var program
= wtu
.setupProgram(gl
, ["vshader", "fshader"], ['a_position', 'a_coord'], [0, 1]);
74 samplerLoc
= gl
.getUniformLocation(program
, "u_sampler");
76 gl
.viewport(0, 0, width
, height
);
78 gl
.bindTexture(gl
.TEXTURE_3D
, texture
);
79 gl
.texImage3D(gl
.TEXTURE_3D
, 0, gl
.RGBA
, width
, height
, depth
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
80 // texture is unbound from the default texture unit TEXTURE0,
81 // then a default black texture will be bound to TEXTURE0.
82 gl
.bindTexture(gl
.TEXTURE_3D
, null);
84 // Active TEXTURE1 and 3d texture are necessary to reproduce the crash bug.
85 gl
.activeTexture(gl
.TEXTURE1
);
87 gl
.bindSampler(0, sampler
);
88 gl
.samplerParameteri(sampler
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
89 gl
.samplerParameteri(sampler
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
90 gl
.bindTexture(gl
.TEXTURE_3D
, texture
);
91 gl
.texParameteri(gl
.TEXTURE_3D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
92 gl
.texParameteri(gl
.TEXTURE_3D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
94 // Render using sampler
95 // When rendering from texture unit 0, the black texture will be drawn.
96 render(0, width
, height
, black
, "Result pixels rendering from TEXTURE0 should be black");
98 gl
.bindSampler(0, null);
99 gl
.deleteSampler(sampler
);
101 // Render using texture
102 // When rendering from texture unit 0, the black texture will be drawn.
103 // Crash happens when calling gl.drawArrays during this rendering.
104 render(0, width
, height
, black
, "Result pixels rendering from TEXTURE0 should be black");
106 gl
.bindTexture(gl
.TEXTURE_3D
, null);
107 gl
.deleteTexture(texture
);
108 gl
.deleteProgram(program
);
112 testFailed("Fail to get a WebGL2 context");
114 testPassed("Created WebGL2 context successfully");
119 var successfullyParsed
= true;
121 <script src=
"../../../js/js-test-post.js"></script>