diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/canvas/test/webgl-conf/checkout/conformance/textures/misc/texparameter-test.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance/textures/misc/texparameter-test.html')
-rw-r--r-- | dom/canvas/test/webgl-conf/checkout/conformance/textures/misc/texparameter-test.html | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/textures/misc/texparameter-test.html b/dom/canvas/test/webgl-conf/checkout/conformance/textures/misc/texparameter-test.html new file mode 100644 index 0000000000..e6e33874cf --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/textures/misc/texparameter-test.html @@ -0,0 +1,129 @@ +<!-- +Copyright (c) 2019 The Khronos Group Inc. +Use of this source code is governed by an MIT-style license that can be +found in the LICENSE.txt file. +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>WebGL TexParameter conformance test.</title> +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> +<script src="../../../js/js-test-pre.js"></script> +<script src="../../../js/webgl-test-utils.js"></script> +</head> +<body> +<canvas id="canvas_drawing" width="12" height="12"></canvas> +<canvas id="canvas_texture" width="2" height="2"></canvas> +<div id="description"></div> +<div id="console"></div> +<script> +"use strict"; +description("Tests TexParameter works as expected"); +debug(""); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("canvas_drawing"); +var canvas_texture = null; +var texParam = [ + gl.REPEAT, + gl.CLAMP_TO_EDGE, + gl.MIRRORED_REPEAT, +]; +var color = [200, 0, 254, 255]; +var textures = []; + +if (!gl) { + testFailed("WebGL context does not exist"); +} else { + testPassed("WebGL context exists"); + + wtu.setupTexturedQuadWithTexCoords(gl, [-2.5, -2.5], [3.5, 3.5]); + + setupCanvasTexture(); + setupTextures(); + for (var ii = 0; ii < texParam.length; ++ii) { + runDrawingTest(textures[ii], texParam[ii]); + } + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); +} + +function setupCanvasTexture() { + canvas_texture = document.getElementById("canvas_texture"); + var ctx2d = canvas_texture.getContext("2d"); + ctx2d.fillStyle = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ")"; + ctx2d.fillRect(0, 0, 1, 1); +} + +function setupTextures() { + for (var ii = 0; ii < texParam.length; ++ii) { + var texture = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas_texture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, texParam[ii]); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, texParam[ii]); + textures[ii] = texture; + } +} + +function runDrawingTest(texture, param) { + gl.clearColor(1, 1, 1, 1); + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.drawArrays(gl.TRIANGLES, 0, 6); + + checkPixels(param); +} + +function checkPixels(param) { + var buf = new Uint8Array(12 * 12 * 4); + gl.readPixels(0, 0, 12, 12, gl.RGBA, gl.UNSIGNED_BYTE, buf); + var passed = true; + for (var yy = 0; yy < 12; ++yy) { + for (var xx = 0; xx < 12; ++xx) { + var ec = [0, 0, 0, 0]; + switch (param) { + case gl.REPEAT: + if (xx % 2 == 1 && yy % 2 == 1) { + ec = color; + } + break; + case gl.CLAMP_TO_EDGE: + if (xx < 6 && yy < 6) { + ec = color; + } + break; + case gl.MIRRORED_REPEAT: + if (xx % 4 < 2 && yy % 4 < 2) { + ec = color; + } + break; + } + var off = (yy * 12 + xx) * 4; + if (buf[off + 0] != ec[0] || buf[off + 1] != ec[1] || + buf[off + 2] != ec[2] || buf[off + 3] != ec[3]) { + var msg = 'at (' + xx + ', ' + yy + ') expected: ' + + ec[0] + ', ' + ec[1] + ', ' + ec[2] + ', ' + ec[3] + ' found: ' + + buf[off + 0] + ', ' + buf[off + 1] + ', ' + buf[off + 2] + ', ' + buf[off + 3]; + testFailed(msg); + passed = false; + } + } + } + if (passed) { + testPassed("Drawing with wrap " + wtu.glEnumToString(gl, param) + " as expected"); + } +} + +var successfullyParsed = true; +</script> +<script src="../../../js/js-test-post.js"></script> + +</body> +</html> + |