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>WebGL2
3D texture mipmap level conformance 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 <canvas id=
"example" width=
"2" height=
"2" style=
"width: 2px; height: 2px;"></canvas>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
20 <script id=
"vshader_texsize" type=
"x-shader/x-vertex">#version
300 es
24 gl_Position = vPosition;
28 <script id=
"fshader_texsize_3d" type=
"x-shader/x-fragment">#version
300 es
29 precision mediump float;
30 uniform highp sampler3D tex;
32 uniform ivec3 texSize;
36 fragColor = (textureSize(tex, lod) == texSize ? vec4(
255,
0,
0,
255) : vec4(
0,
0,
0,
255));
43 description(document
.title
);
44 var wtu
= WebGLTestUtils
;
45 var gl
= wtu
.create3DContext("example", undefined, 2);
47 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors from setup.");
49 // This test fails on Intel Mesa, see crbug.com/666384.
52 debug("Test textureSize should work correctly with non-zero base level for texStorage3D");
53 var program
= wtu
.setupProgram(
54 gl
, ['vshader_texsize', 'fshader_texsize_3d'], ['vPosition'], [0]);
55 wtu
.setupUnitQuad(gl
, 0, 1);
57 gl
.uniform1i(gl
.getUniformLocation(program
, "tex"), 0);
58 gl
.uniform1i(gl
.getUniformLocation(program
, "lod"), 1);
59 gl
.uniform3i(gl
.getUniformLocation(program
, "texSize"), 8, 4, 2);
60 var tex3d
= gl
.createTexture();
61 gl
.bindTexture(gl
.TEXTURE_3D
, tex3d
);
62 gl
.texParameteri(gl
.TEXTURE_3D
, gl
.TEXTURE_MAG_FILTER
, gl
.LINEAR
);
63 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "texParameter(TEXTURE_MAG_FILTER) should succeed");
64 gl
.texParameteri(gl
.TEXTURE_3D
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR
);
65 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "texParameter(TEXTURE_MIN_FILTER) should succeed");
66 gl
.texParameteri(gl
.TEXTURE_3D
, gl
.TEXTURE_BASE_LEVEL
, 1);
67 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "texParameter(TEXTURE_BASE_LEVEL) should succeed");
68 gl
.texStorage3D(gl
.TEXTURE_3D
, 4, gl
.RGBA8
, 32, 16, 8);
69 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "texStorage3D should succeed");
70 wtu
.clearAndDrawUnitQuad(gl
);
71 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "clearAndDrawQuad should succeed");
72 wtu
.checkCanvas(gl
, [255, 0, 0, 255], "should draw with [255, 0, 0, 255]");
73 gl
.deleteTexture(tex3d
);
76 var successfullyParsed
= true;
79 <script src=
"../../../js/js-test-post.js"></script>