diff options
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance2/samplers')
4 files changed, 441 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/00_test_list.txt new file mode 100644 index 0000000000..eeca822298 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/00_test_list.txt @@ -0,0 +1,3 @@ +--min-version 2.0.1 multi-context-sampler-test.html +samplers.html +sampler-drawing-test.html diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/multi-context-sampler-test.html b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/multi-context-sampler-test.html new file mode 100644 index 0000000000..05e0f20480 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/multi-context-sampler-test.html @@ -0,0 +1,84 @@ +<!-- +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 Multi-Context Sampler 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> +<div id="description"></div> +<div id="console"></div> +<script> +"use strict"; +description("Tests that samplers' state doesn't leak across contexts"); +debug(""); +debug('Regression test for <a href="http://crbug.com/713127">http://crbug.com/713127</a>'); + +function runTest() { + var wtu = WebGLTestUtils; + var gl = wtu.create3DContext("canvas_drawing", undefined, 2); + var texture = null; + var color = [0, 255, 0, 255]; + + if (!gl) { + testFailed("WebGL context does not exist"); + return; + } + + testPassed("WebGL context exists"); + + wtu.setupTexturedQuad(gl); + texture = gl.createTexture(); + // Create a texture bigger than 1x1 so that it would need mipmaps in + // order to be complete. + wtu.fillTexture(gl, texture, 2, 2, color, 0, + gl.RGBA, gl.UNSIGNED_BYTE, gl.RGBA8); + // Set texture parameters so that this texture is complete. + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + + // Set up a secondary context with a sampler bound to texture unit + // 0. This should not interfere with the primary context. + var altGL = wtu.create3DContext(undefined, undefined, 2); + if (!altGL) { + testFailed("Error creating secondary WebGL context"); + return; + } + + var sampler = altGL.createSampler(); + // Note that the sampler's default TEXTURE_MIN_FILTER is + // NEAREST_MIPMAP_LINEAR. + altGL.bindSampler(0, sampler); + altGL.clearColor(1, 0, 0, 1); + altGL.clear(altGL.COLOR_BUFFER_BIT); + wtu.checkCanvasRect(altGL, 0, 0, 1, 1, [ 255, 0, 0, 255 ], + "should be red"); + + // Now switch back to the main context and draw the texture. + gl.clearColor(1, 1, 1, 1); + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + wtu.drawUnitQuad(gl); + // The presence of the sampler on the other context should not + // have interfered with the completeness of the texture. + wtu.checkCanvasRect(gl, 0, 0, 1, 1, color, + "should be green"); + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); +} + +runTest(); +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/sampler-drawing-test.html b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/sampler-drawing-test.html new file mode 100644 index 0000000000..ec6aa515ef --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/sampler-drawing-test.html @@ -0,0 +1,124 @@ +<!-- +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 Sampler Drawing 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 drawing with sampler works as expected"); +debug(""); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("canvas_drawing", null, 2); +var canvas_texture = null; +var samplerParam = [ + gl.REPEAT, + gl.CLAMP_TO_EDGE, + gl.MIRRORED_REPEAT, +]; +var color = [200, 0, 254, 255]; + +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(); + for (var ii = 0; ii < samplerParam.length; ++ii) { + runDrawingTest(samplerParam[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 runDrawingTest(param) { + 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); + + var sampler = gl.createSampler(); + gl.samplerParameteri(sampler, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.samplerParameteri(sampler, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_S, param); + gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_T, param); + + gl.clearColor(1,1,1,1); + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); + + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.bindSampler(0, sampler); + gl.drawArrays(gl.TRIANGLE_STRIP, 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> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/samplers.html b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/samplers.html new file mode 100644 index 0000000000..e6fbc69011 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/samplers/samplers.html @@ -0,0 +1,230 @@ +<!-- +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 Sampler Conformance Tests</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> +<div id="description"></div> +<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> +<div id="console"></div> +<script> +"use strict"; +description("This test verifies the functionality of the Sampler objects."); + +debug(""); + +var wtu = WebGLTestUtils; +var canvas = document.getElementById("canvas"); +var gl = wtu.create3DContext(canvas, null, 2); +var s = null; +var s1 = null; +var s2 = null; +var testCases = null; + +if (!gl) { + testFailed("WebGL context does not exist"); +} else { + testPassed("WebGL context exists"); + + runBindingTest(); + runObjectTest(); + runParameterTest(); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); +} + +function enumToString(value) { + return wtu.glEnumToString(gl, value); +} + +function runBindingTest() { + debug("Testing binding enum"); + + shouldBe("gl.SAMPLER_BINDING", "0x8919"); + + // Default value is null + shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)"); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "SAMPLER_BINDING query should succeed"); + + debug("Testing binding a Sampler object"); + s1 = gl.createSampler(); + s2 = gl.createSampler(); + gl.bindSampler(0, s1); + shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s1"); + gl.bindSampler(0, s2); + shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s2"); + + // Bindings should not affect other units. + gl.bindSampler(1, s1); + shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s2"); + gl.activeTexture(gl.TEXTURE1); + shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s1"); + gl.activeTexture(gl.TEXTURE0); + + // Should be able to bind a single sampler to multiple texture units. + gl.bindSampler(0, s1); + shouldBe("gl.getParameter(gl.SAMPLER_BINDING)", "s1"); + + // Deleting samplers should unbind them. + gl.deleteSampler(s1); + gl.deleteSampler(s2); + shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)"); + gl.activeTexture(gl.TEXTURE1); + shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)"); + gl.activeTexture(gl.TEXTURE0); + + // Shouldn't be able to bind a deleted sampler. + gl.bindSampler(0, s2); + wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "binding a deleted Sampler object"); + gl.bindSampler(0, null); + shouldBeNull("gl.getParameter(gl.SAMPLER_BINDING)"); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); +} + +function runObjectTest() { + debug("Testing object creation"); + + s1 = gl.createSampler(); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "createSampler should not set an error"); + shouldBeNonNull("s1"); + + // Expect true, even if never bound + shouldBeTrue("gl.isSampler(s1)"); + gl.bindSampler(0, s1); + shouldBeTrue("gl.isSampler(s1)"); + gl.bindSampler(0, null); + shouldBeTrue("gl.isSampler(s1)"); + gl.deleteSampler(s1); + shouldBeFalse("gl.isSampler(s1)"); + + shouldBeFalse("gl.isSampler(null)"); + + s1 = null; +} + +function runParameterTest() { + debug("Testing getSamplerParameter and samplerParameter[if]"); + + s = gl.createSampler(); + gl.bindSampler(0, s); + + debug("Checking default param for getSamplerParameter"); + + testCases = [ + { pname: gl.TEXTURE_WRAP_S, defaultParam: gl.REPEAT }, + { pname: gl.TEXTURE_WRAP_T, defaultParam: gl.REPEAT }, + { pname: gl.TEXTURE_WRAP_R, defaultParam: gl.REPEAT }, + { pname: gl.TEXTURE_MIN_FILTER, defaultParam: gl.NEAREST_MIPMAP_LINEAR }, + { pname: gl.TEXTURE_MAG_FILTER, defaultParam: gl.LINEAR }, + { pname: gl.TEXTURE_COMPARE_MODE, defaultParam: gl.NONE }, + { pname: gl.TEXTURE_COMPARE_FUNC, defaultParam: gl.LEQUAL }, + { pname: gl.TEXTURE_MIN_LOD, defaultParam: -1000 }, + { pname: gl.TEXTURE_MAX_LOD, defaultParam: 1000 }, + ]; + + for (var ii = 0; ii < testCases.length; ++ii) { + var pname = testCases[ii].pname; + var defaultParam = testCases[ii].defaultParam; + shouldBe("gl.getSamplerParameter(s, " + pname + ")", defaultParam.toString()); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + } + + debug("Checking valid pname and param for samplerParameteri"); + + testCases = [ + { pname: gl.TEXTURE_WRAP_S, param: gl.REPEAT }, + { pname: gl.TEXTURE_WRAP_S, param: gl.MIRRORED_REPEAT }, + { pname: gl.TEXTURE_WRAP_S, param: gl.CLAMP_TO_EDGE }, + { pname: gl.TEXTURE_WRAP_T, param: gl.REPEAT }, + { pname: gl.TEXTURE_WRAP_T, param: gl.MIRRORED_REPEAT }, + { pname: gl.TEXTURE_WRAP_T, param: gl.CLAMP_TO_EDGE }, + { pname: gl.TEXTURE_WRAP_R, param: gl.REPEAT }, + { pname: gl.TEXTURE_WRAP_R, param: gl.MIRRORED_REPEAT }, + { pname: gl.TEXTURE_WRAP_R, param: gl.CLAMP_TO_EDGE }, + { pname: gl.TEXTURE_MIN_FILTER, param: gl.NEAREST }, + { pname: gl.TEXTURE_MIN_FILTER, param: gl.LINEAR }, + { pname: gl.TEXTURE_MIN_FILTER, param: gl.NEAREST_MIPMAP_NEAREST }, + { pname: gl.TEXTURE_MIN_FILTER, param: gl.NEAREST_MIPMAP_LINEAR }, + { pname: gl.TEXTURE_MIN_FILTER, param: gl.LINEAR_MIPMAP_NEAREST }, + { pname: gl.TEXTURE_MIN_FILTER, param: gl.LINEAR_MIPMAP_LINEAR }, + { pname: gl.TEXTURE_MAG_FILTER, param: gl.NEAREST }, + { pname: gl.TEXTURE_MAG_FILTER, param: gl.LINEAR }, + { pname: gl.TEXTURE_COMPARE_MODE, param: gl.NONE }, + { pname: gl.TEXTURE_COMPARE_MODE, param: gl.COMPARE_REF_TO_TEXTURE }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.LEQUAL }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.GEQUAL }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.LESS }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.GREATER }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.EQUAL }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.NOTEQUAL }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.ALWAYS }, + { pname: gl.TEXTURE_COMPARE_FUNC, param: gl.NEVER }, + ]; + + for (var ii = 0; ii < testCases.length; ++ii) { + var pname = testCases[ii].pname; + var param = testCases[ii].param; + wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.samplerParameteri(s, " + pname + ", " + param + ")"); + shouldBe("gl.getSamplerParameter(s, " + pname + ")", param); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + } + + debug("Checking valid pname and param for samplerParameterf"); + testCases = [ + { pname: gl.TEXTURE_MIN_LOD, param: -500 }, + { pname: gl.TEXTURE_MIN_LOD, param: 0 }, + { pname: gl.TEXTURE_MIN_LOD, param: 10.0 }, + { pname: gl.TEXTURE_MAX_LOD, param: 500 }, + { pname: gl.TEXTURE_MAX_LOD, param: 0 }, + { pname: gl.TEXTURE_MAX_LOD, param: 10.0 }, + ]; + + for (var ii = 0; ii < testCases.length; ++ii) { + var pname = testCases[ii].pname; + var param = testCases[ii].param; + wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.samplerParameterf(s, " + pname + ", " + param + ")"); + shouldBe("gl.getSamplerParameter(s, " + pname + ")", param.toString()); + wtu.glErrorShouldBe(gl, gl.NO_ERROR); + } + + debug("Checking invalid pname and param"); + + testCases = [ + { pname: gl.TEXTURE_IMMUTABLE_FORMAT, param: null, expectedError: gl.INVALID_ENUM }, + { pname: gl.TEXTURE_BASE_LEVEL, param: null, expectedError: gl.INVALID_ENUM }, + { pname: gl.TEXTURE_MAX_LEVEL, param: null, expectedError: gl.INVALID_ENUM }, + { pname: gl.TEXTURE_WRAP_S, param: 0x812D,/* GL_CLAMP_TO_BORDER */ expectedError: gl.INVALID_ENUM }, + { pname: gl.TEXTURE_WRAP_T, param: 0x812D,/* GL_CLAMP_TO_BORDER */ expectedError: gl.INVALID_ENUM }, + { pname: gl.TEXTURE_MAG_FILTER, param: gl.LINEAR_MIPMAP_NEAREST, expectedError: gl.INVALID_ENUM }, + ]; + + for (var ii = 0; ii < testCases.length; ++ii) { + var pname = testCases[ii].pname; + var param = testCases[ii].param; + var expectedError = testCases[ii].expectedError; + if (param == null) { + wtu.shouldGenerateGLError(gl, expectedError, "gl.getSamplerParameter(s, " + pname + ")"); + } else { + wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.getSamplerParameter(s, " + pname + ")"); + } + wtu.shouldGenerateGLError(gl, expectedError, "gl.samplerParameteri(s, " + pname + ", " + param + ")"); + wtu.shouldGenerateGLError(gl, expectedError, "gl.samplerParameterf(s, " + pname + ", " + param + ")"); + } +} + +debug(""); +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> |