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 TexParameter 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=
"canvas_drawing" width=
"12" height=
"12"></canvas>
18 <canvas id=
"canvas_texture" width=
"2" height=
"2"></canvas>
19 <div id=
"description"></div>
20 <div id=
"console"></div>
23 description("Tests TexParameter works as expected");
26 var wtu
= WebGLTestUtils
;
27 var gl
= wtu
.create3DContext("canvas_drawing");
28 var canvas_texture
= null;
34 var color
= [200, 0, 254, 255];
38 testFailed("WebGL context does not exist");
40 testPassed("WebGL context exists");
42 wtu
.setupTexturedQuadWithTexCoords(gl
, [-2.5, -2.5], [3.5, 3.5]);
46 for (var ii
= 0; ii
< texParam
.length
; ++ii
) {
47 runDrawingTest(textures
[ii
], texParam
[ii
]);
50 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "there should be no errors");
53 function setupCanvasTexture() {
54 canvas_texture
= document
.getElementById("canvas_texture");
55 var ctx2d
= canvas_texture
.getContext("2d");
56 ctx2d
.fillStyle
= "rgba(" + color
[0] + "," + color
[1] + "," + color
[2] + "," + color
[3] + ")";
57 ctx2d
.fillRect(0, 0, 1, 1);
60 function setupTextures() {
61 for (var ii
= 0; ii
< texParam
.length
; ++ii
) {
62 var texture
= gl
.createTexture();
63 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
64 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas_texture
);
65 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MAG_FILTER
, gl
.NEAREST
);
66 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.NEAREST
);
67 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_S
, texParam
[ii
]);
68 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_WRAP_T
, texParam
[ii
]);
69 textures
[ii
] = texture
;
73 function runDrawingTest(texture
, param
) {
74 gl
.clearColor(1, 1, 1, 1);
75 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
77 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
78 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
83 function checkPixels(param
) {
84 var buf
= new Uint8Array(12 * 12 * 4);
85 gl
.readPixels(0, 0, 12, 12, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
87 for (var yy
= 0; yy
< 12; ++yy
) {
88 for (var xx
= 0; xx
< 12; ++xx
) {
89 var ec
= [0, 0, 0, 0];
92 if (xx
% 2 == 1 && yy
% 2 == 1) {
96 case gl
.CLAMP_TO_EDGE
:
97 if (xx
< 6 && yy
< 6) {
101 case gl
.MIRRORED_REPEAT
:
102 if (xx
% 4 < 2 && yy
% 4 < 2) {
107 var off
= (yy
* 12 + xx
) * 4;
108 if (buf
[off
+ 0] != ec
[0] || buf
[off
+ 1] != ec
[1] ||
109 buf
[off
+ 2] != ec
[2] || buf
[off
+ 3] != ec
[3]) {
110 var msg
= 'at (' + xx
+ ', ' + yy
+ ') expected: ' +
111 ec
[0] + ', ' + ec
[1] + ', ' + ec
[2] + ', ' + ec
[3] + ' found: ' +
112 buf
[off
+ 0] + ', ' + buf
[off
+ 1] + ', ' + buf
[off
+ 2] + ', ' + buf
[off
+ 3];
119 testPassed("Drawing with wrap " + wtu
.glEnumToString(gl
, param
) + " as expected");
123 var successfullyParsed
= true;
125 <script src=
"../../../js/js-test-post.js"></script>