summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/00_test_list.txt4
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2d-bias.html101
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dlod.html109
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dproj.html116
-rw-r--r--dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dprojlod.html162
5 files changed, 492 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/00_test_list.txt
new file mode 100644
index 0000000000..c0f612d81d
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/00_test_list.txt
@@ -0,0 +1,4 @@
+glsl-function-texture2d-bias.html
+glsl-function-texture2dlod.html
+glsl-function-texture2dproj.html
+--min-version 1.0.3 glsl-function-texture2dprojlod.html
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2d-bias.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2d-bias.html
new file mode 100644
index 0000000000..073276615f
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2d-bias.html
@@ -0,0 +1,101 @@
+<!--
+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 texture2D GLSL conformance test.</title>
+<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
+<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
+<script src="../../../js/js-test-pre.js"></script>
+<script src="../../../js/webgl-test-utils.js"> </script>
+</head>
+<body>
+<canvas id="example" width="256" height="256" style="width: 16px; height: 16px;"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+<script id="vshader2d" type="x-shader/x-vertex">
+attribute vec4 vPosition;
+attribute vec2 texCoord0;
+varying vec2 texCoord;
+void main() {
+ gl_Position = vPosition;
+ texCoord = texCoord0;
+}
+</script>
+<script id="fshader2d" type="x-shader/x-fragment">
+precision mediump float;
+uniform sampler2D tex;
+uniform float bias;
+varying vec2 texCoord;
+void main() {
+ gl_FragData[0] = texture2D(tex, texCoord, bias);
+}
+</script>
+<script>
+"use strict";
+description("tests GLSL texture2D function with bias");
+
+var wtu = WebGLTestUtils;
+var canvas = document.getElementById("example");
+
+shouldBe("canvas.width", "256");
+shouldBe("canvas.height", "256");
+
+var gl = wtu.create3DContext(canvas);
+var program = wtu.setupProgram(
+ gl, ['vshader2d', 'fshader2d'], ['vPosition', 'texCoord0'], [0, 1]);
+wtu.setupUnitQuad(gl, 0, 1);
+
+var colors = [
+ {name: 'red', color:[255, 0, 0, 255]},
+ {name: 'green', color:[0, 255, 0, 255]},
+ {name: 'blue', color:[0, 0, 255, 255]},
+ {name: 'yellow', color:[255, 255, 0, 255]},
+ {name: 'magenta', color:[255, 0, 255, 255]},
+ {name: 'cyan', color:[0, 255, 255, 255]},
+ {name: 'pink', color:[255, 128, 128, 255]},
+ {name: 'gray', color:[128, 128, 128, 255]},
+ {name: 'light green', color:[128, 255, 128, 255]},
+];
+
+shouldBe("colors.length", "9");
+
+var tex = gl.createTexture();
+gl.bindTexture(gl.TEXTURE_2D, tex);
+gl.texParameteri(
+ gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
+gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
+gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+
+for (var ii = 0; ii < colors.length; ++ii) {
+ var color = colors[ii];
+ var size = Math.pow(2, colors.length - ii - 1);
+ wtu.fillTexture(gl, tex, size, size, color.color, ii);
+}
+
+var loc = gl.getUniformLocation(program, "bias");
+
+for (var ii = 0; ii < colors.length; ++ii) {
+ gl.uniform1f(loc, ii);
+ var color = colors[ii];
+ wtu.clearAndDrawUnitQuad(gl);
+ wtu.checkCanvas(
+ gl, color.color,
+ "256x256 texture drawn to 256x256 dest with bias = " + ii +
+ " should be " + color.name);
+}
+wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
+
+var successfullyParsed = true;
+
+</script>
+<script src="../../../js/js-test-post.js"></script>
+
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dlod.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dlod.html
new file mode 100644
index 0000000000..41387bca15
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dlod.html
@@ -0,0 +1,109 @@
+<!--
+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 texture2D GLSL conformance test.</title>
+<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
+<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
+<script src="../../../js/js-test-pre.js"></script>
+<script src="../../../js/webgl-test-utils.js"> </script>
+</head>
+<body>
+<canvas id="example" width="256" height="256" style="width: 16px; height: 16px;"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+<script id="vshader2d" type="x-shader/x-vertex">
+attribute vec4 vPosition;
+attribute vec2 texCoord0;
+varying vec4 color;
+uniform sampler2D tex;
+uniform float lod;
+void main() {
+ gl_Position = vPosition;
+ color = texture2DLod(tex, texCoord0, lod);
+}
+</script>
+<script id="fshader2d" type="x-shader/x-fragment">
+precision mediump float;
+varying vec4 color;
+void main() {
+ gl_FragData[0] = color;
+}
+</script>
+<script>
+"use strict";
+description("tests GLSL texture2DLod function");
+
+var wtu = WebGLTestUtils;
+var canvas = document.getElementById("example");
+
+shouldBe("canvas.width", "256");
+shouldBe("canvas.height", "256");
+
+var colors = [
+ {name: 'red', color:[255, 0, 0, 255]},
+ {name: 'green', color:[0, 255, 0, 255]},
+ {name: 'blue', color:[0, 0, 255, 255]},
+ {name: 'yellow', color:[255, 255, 0, 255]},
+ {name: 'magenta', color:[255, 0, 255, 255]},
+ {name: 'cyan', color:[0, 255, 255, 255]},
+ {name: 'pink', color:[255, 128, 128, 255]},
+ {name: 'gray', color:[128, 128, 128, 255]},
+ {name: 'light green', color:[128, 255, 128, 255]},
+];
+
+var gl = wtu.create3DContext(canvas);
+if (gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0) {
+ runTest();
+} else {
+ testPassed("MAX_VERTEX_TEXTURE_IMAGE_UNITS == 0, this is okay.");
+}
+
+function runTest() {
+ var program = wtu.setupProgram(
+ gl, ['vshader2d', 'fshader2d'], ['vPosition', 'texCoord0'], [0, 1]);
+ wtu.setupUnitQuad(gl, 0, 1);
+
+ shouldBe("colors.length", "9");
+
+ var tex = gl.createTexture();
+ gl.bindTexture(gl.TEXTURE_2D, tex);
+ gl.texParameteri(
+ gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+
+ for (var ii = 0; ii < colors.length; ++ii) {
+ var color = colors[ii];
+ var size = Math.pow(2, colors.length - ii - 1);
+ wtu.fillTexture(gl, tex, size, size, color.color, ii);
+ }
+
+ var loc = gl.getUniformLocation(program, "lod");
+
+ for (var ii = 0; ii < colors.length; ++ii) {
+ gl.uniform1f(loc, ii);
+ var color = colors[ii];
+ wtu.clearAndDrawUnitQuad(gl);
+ wtu.checkCanvas(
+ gl, color.color,
+ "256x256 texture drawn to 256x256 dest with lod = " + ii +
+ " should be " + color.name);
+ }
+ wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
+}
+
+var successfullyParsed = true;
+
+</script>
+<script src="../../../js/js-test-post.js"></script>
+
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dproj.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dproj.html
new file mode 100644
index 0000000000..c9e042f9a9
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dproj.html
@@ -0,0 +1,116 @@
+<!--
+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 texture2D GLSL conformance test.</title>
+<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
+<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
+<script src="../../../js/js-test-pre.js"></script>
+<script src="../../../js/webgl-test-utils.js"> </script>
+</head>
+<body>
+<canvas id="example" width="32" height="32"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+<script id="vshader0" type="x-shader/x-vertex">
+attribute vec4 vPosition;
+attribute vec2 texCoord0;
+varying vec2 texCoord;
+void main() {
+ gl_Position = vPosition;
+ texCoord = texCoord0;
+}
+</script>
+<script id="fshader0" type="x-shader/x-fragment">
+precision mediump float;
+uniform sampler2D tex;
+uniform float divisor;
+varying vec2 texCoord;
+void main() {
+ gl_FragData[0] = texture2DProj(tex, vec3(texCoord, divisor));
+}
+</script>
+<script id="vshader1" type="x-shader/x-vertex">
+attribute vec4 vPosition;
+attribute vec2 texCoord0;
+varying vec2 texCoord;
+void main() {
+ gl_Position = vPosition;
+ texCoord = texCoord0;
+}
+</script>
+<script id="fshader1" type="x-shader/x-fragment">
+precision mediump float;
+uniform sampler2D tex;
+uniform float divisor;
+varying vec2 texCoord;
+void main() {
+ gl_FragData[0] = texture2DProj(tex, vec4(texCoord, 123.0, divisor));
+}
+</script>
+<script>
+"use strict";
+description("tests GLSL texture2DProj function with");
+
+var wtu = WebGLTestUtils;
+var gl = wtu.create3DContext("example", {antialias: false});
+
+wtu.setupUnitQuad(gl, 0, 1);
+var tex = gl.createTexture();
+gl.bindTexture(gl.TEXTURE_2D, tex);
+gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
+gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+
+var c = document.createElement("canvas");
+c.width = 16;
+c.height = 16;
+var ctx = c.getContext("2d");
+ctx.fillStyle = "rgb(0,255,0)";
+ctx.fillRect(0, 0, 16, 16);
+ctx.fillStyle = "rgb(0,0,255)";
+ctx.fillRect(0, 0, 8, 8);
+ctx.fillRect(8, 8, 8, 8);
+
+gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
+
+for (var ss = 0; ss < 2; ++ss) {
+ debug("");
+ debug(ss ? "testing vec4 version" : "testing vec3 version");
+ var program = wtu.setupProgram(
+ gl, ['vshader' + ss, 'fshader' + ss],
+ ['vPosition', 'texCoord0'], [0, 1]);
+ gl.useProgram(program);
+ var loc = gl.getUniformLocation(program, "divisor");
+
+ for (var ii = 0; ii < 3; ++ii) {
+ var denominator = Math.pow(2, ii);
+ gl.uniform1f(loc, 1 / denominator);
+ wtu.clearAndDrawUnitQuad(gl);
+ var size = 16 / denominator;
+ for (var yy = 0; yy < 32; yy += size) {
+ for (var xx = 0; xx < 32; xx += size) {
+ var odd = (xx / size + yy / size) % 2;
+ var color = odd ? [0, 255, 0, 255] : [0, 0, 255, 255];
+ var msg = "" + xx + ", " + yy + ", " + size + ", " + size + " should be " + (odd ? "green" : "blue");
+ wtu.checkCanvasRect(gl, xx, yy, size, size, color, msg);
+ }
+ }
+ }
+}
+wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
+
+var successfullyParsed = true;
+
+</script>
+<script src="../../../js/js-test-post.js"></script>
+
+</body>
+</html>
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dprojlod.html b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dprojlod.html
new file mode 100644
index 0000000000..c7c091ee8e
--- /dev/null
+++ b/dom/canvas/test/webgl-conf/checkout/conformance/glsl/samplers/glsl-function-texture2dprojlod.html
@@ -0,0 +1,162 @@
+<!--
+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 texture2D GLSL conformance test.</title>
+<link rel="stylesheet" href="../../../resources/js-test-style.css"/>
+<link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
+<script src="../../../js/js-test-pre.js"></script>
+<script src="../../../js/webgl-test-utils.js"> </script>
+</head>
+<body>
+<canvas id="example" width="256" height="256" style="width: 16px; height: 16px;"></canvas>
+<div id="description"></div>
+<div id="console"></div>
+<script id="vshader2dvec3" type="x-shader/x-vertex">
+attribute vec4 vPosition;
+varying vec4 color;
+uniform sampler2D tex;
+uniform float divisor;
+uniform float lod;
+void main() {
+ gl_Position = vPosition;
+ color = texture2DProjLod(tex, vec3(0.75 * divisor, 0.25 * divisor, divisor), lod);
+}
+</script>
+<script id="vshader2dvec4" type="x-shader/x-vertex">
+attribute vec4 vPosition;
+varying vec4 color;
+uniform sampler2D tex;
+uniform float divisor;
+uniform float lod;
+void main() {
+ gl_Position = vPosition;
+ color = texture2DProjLod(tex, vec4(0.75 * divisor, 0.25 * divisor, 123.0, divisor), lod);
+}
+</script>
+<script id="fshader2d" type="x-shader/x-fragment">
+precision mediump float;
+varying vec4 color;
+void main() {
+ gl_FragData[0] = color;
+}
+</script>
+<script>
+"use strict";
+description("tests GLSL texture2DProjLod function");
+
+var wtu = WebGLTestUtils;
+var canvas = document.getElementById("example");
+
+shouldBe("canvas.width", "256");
+shouldBe("canvas.height", "256");
+
+var colors = [
+ {name: 'red', color:[255, 0, 0, 255]},
+ {name: 'green', color:[0, 255, 0, 255]},
+ {name: 'blue', color:[0, 0, 255, 255]},
+ {name: 'yellow', color:[255, 255, 0, 255]},
+ {name: 'magenta', color:[255, 0, 255, 255]},
+ {name: 'cyan', color:[0, 255, 255, 255]},
+ {name: 'pink', color:[255, 128, 128, 255]},
+ {name: 'gray', color:[128, 128, 128, 255]},
+ {name: 'light green', color:[128, 255, 128, 255]},
+];
+var contextTypes = ["2d", "webgl"];
+var vectorTypes = ["vec3", "vec4"];
+
+var gl = wtu.create3DContext(canvas);
+if (gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0) {
+ runTest();
+} else {
+ testPassed("MAX_VERTEX_TEXTURE_IMAGE_UNITS == 0, this is okay.");
+}
+
+
+function runTest() {
+ // Avoid creating a WebGL context for every test, as it causes:
+ // Too many active WebGL contexts. Oldest context will be lost.
+ var canvasWebGL = document.createElement("canvas");
+ var ctxWebGL = canvasWebGL.getContext("webgl");
+
+ // Might as well do the same for canvas 2d
+ var canvas2d = document.createElement("canvas");
+ var ctx2d = canvas2d.getContext("2d");
+
+ shouldBe("colors.length", "9");
+ contextTypes.forEach((context) => {
+ vectorTypes.forEach((vectorType) => {
+ debug("");
+ debug(`testing ${context} context with ${vectorType} vertex shader`);
+ var program = wtu.setupProgram(
+ gl, ['vshader2d' + vectorType, 'fshader2d'], ['vPosition', 'texCoord0'], [0, 1]);
+ wtu.setupUnitQuad(gl, 0, 1);
+
+ var tex = gl.createTexture();
+ gl.bindTexture(gl.TEXTURE_2D, tex);
+ gl.texParameteri(
+ gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+
+ // Fill the top right quadrant of each texture level with one of the colors
+ for (var ii = 0; ii < colors.length; ++ii) {
+ var color = colors[ii];
+ var size = Math.pow(2, colors.length - ii - 1);
+
+ if (context === "2d") {
+ canvas2d.width = size;
+ canvas2d.height = size;
+ ctx2d.fillStyle = "rgb(0,0,0)";
+ ctx2d.fillRect(0, 0, size, size);
+ ctx2d.fillStyle = "rgb(" + color.color[0] + "," + color.color[1] + "," + color.color[2] + ")";
+ ctx2d.fillRect(size / 2, 0, size / 2, size / 2);
+ gl.texImage2D(gl.TEXTURE_2D, ii, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
+ } else if (context === "webgl") {
+ canvasWebGL.width = canvasWebGL.height = size;
+ ctxWebGL.clearColor(0, 0, 0, 1);
+ ctxWebGL.clear(gl.COLOR_BUFFER_BIT);
+ ctxWebGL.enable(gl.SCISSOR_TEST);
+ ctxWebGL.scissor(size/2, size/2, size/2, size/2)
+ ctxWebGL.clearColor(color.color[0]/255, color.color[1]/255, color.color[2]/255, 1)
+ ctxWebGL.clear(gl.COLOR_BUFFER_BIT);
+ gl.texImage2D(gl.TEXTURE_2D, ii, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvasWebGL);
+ }
+ }
+
+ var lodLoc = gl.getUniformLocation(program, "lod");
+ var divLoc = gl.getUniformLocation(program, "divisor");
+
+ for (var div = 1; div < 4; ++div) {
+ for (var ii = 0; ii < colors.length - 1; ++ii) {
+ gl.uniform1f(lodLoc, ii);
+ gl.uniform1f(divLoc, div);
+ var lodColor = colors[ii];
+ var size = Math.pow(2, colors.length - ii - 1);
+ wtu.clearAndDrawUnitQuad(gl);
+ wtu.checkCanvas(
+ gl, lodColor.color,
+ "sampling with lod = " + ii +
+ " divider = " + div +
+ " should be " + lodColor.name);
+ }
+ }
+ });
+ });
+ wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
+}
+
+var successfullyParsed = true;
+
+</script>
+<script src="../../../js/js-test-post.js"></script>
+
+</body>
+</html>