diff options
Diffstat (limited to 'dom/canvas/test/webgl-conf/checkout/conformance2/programs')
5 files changed, 443 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/programs/00_test_list.txt b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/00_test_list.txt new file mode 100644 index 0000000000..c88d255dab --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/00_test_list.txt @@ -0,0 +1,4 @@ +active-built-in-attribs.html +--min-version 2.0.1 get-uniform-indices.html +gl-get-frag-data-location.html +--min-version 2.0.1 sampler-uniforms.html diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/programs/active-built-in-attribs.html b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/active-built-in-attribs.html new file mode 100644 index 0000000000..68b62cdcf2 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/active-built-in-attribs.html @@ -0,0 +1,86 @@ +<!-- +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 Conformance Tests: Verify validation for active built-in attribs</title> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/desktop-gl-constants.js"></script> +<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: 64px; height: 64px;"> </canvas> +<div id="console"></div> +<script id="vs" type="x-shader/x-vertex">#version 300 es +void main() { + gl_Position = vec4(gl_VertexID % 2, (gl_VertexID/2) % 2, 0, 1); +} +</script> + +<script id="fs" type="x-shader/x-fragment">#version 300 es +precision mediump float; +out vec4 fragColor; +void main() { + fragColor = vec4(0, 1, 0, 1); +} +</script> + +<script> +"use strict"; +description("This test verifies validation for active built-in attribs."); + +debug(""); + +var wtu = WebGLTestUtils; +var canvas = document.getElementById("canvas"); +var gl = wtu.create3DContext(canvas, null, 2); + +if (!gl) { + testFailed("WebGL context does not exist"); +} else { + testPassed("WebGL context exists"); + runTests(); +} + +var activeInfo, attribLoc; + +function runTests() { + var prog = wtu.setupProgram(gl, ["vs", "fs"]); + if (!prog) { + testFailed("Set up program failed"); + return; + } + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from set up"); + + var numActive = gl.getProgramParameter(prog, gl.ACTIVE_ATTRIBUTES); + if (numActive != 1) { + testFailed('ACTIVE_ATTRIBUTES should be 1.'); + return; + } + testPassed('ACTIVE_ATTRIBUTES should be 1.'); + + activeInfo = gl.getActiveAttrib(prog, 0); + if (!activeInfo) { + testFailed('getActiveAttrib should return an info object.'); + return; + } + + shouldBe('activeInfo.name', '"gl_VertexID"'); + attribLoc = gl.getAttribLocation(prog, 'gl_VertexID'); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be able to request the location of a built-in."); + shouldBe('attribLoc', '-1'); +} + +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/programs/get-uniform-indices.html b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/get-uniform-indices.html new file mode 100644 index 0000000000..d42add065c --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/get-uniform-indices.html @@ -0,0 +1,121 @@ +<!-- +Copyright (c) 2022 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"> +<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> +<div id="console"></div> + +<script> +"use strict"; +description("This test verifies getUniformIndices behaviors."); + +debug(""); + +var wtu = WebGLTestUtils; + +const e_canvas = document.createElement('canvas'); +const gl = e_canvas.getContext('webgl2'); + +const VSRC = `\ + #version 300 es + precision mediump float; + uniform float u_vert_scalar; + uniform float u_vert_arr[3]; + uniform float u_both_scalar; + uniform float u_both_arr[3]; + void main() { + gl_Position = vec4(0, 0, 0, 1); + gl_Position.r += u_vert_scalar; + gl_Position.r += u_vert_arr[1]; + gl_Position.r += u_both_scalar; + gl_Position.r += u_both_arr[1]; + } +`; + +const FSRC = `\ + #version 300 es + precision mediump float; + uniform float u_frag_scalar; + uniform float u_frag_arr[3]; + uniform float u_both_scalar; + uniform float u_both_arr[3]; + out vec4 o_frag_color; + void main() { + o_frag_color = vec4(0, 0, 0, 1); + o_frag_color.r += u_frag_scalar; + o_frag_color.r += u_frag_arr[1]; + o_frag_color.r += u_both_scalar; + o_frag_color.r += u_both_arr[1]; + } +`; + +(() => { + if (!gl) { + testFailed("WebGL context does not exist"); + return; + } + + window.prog = wtu.setupProgram(gl, [VSRC, FSRC]); + if (!prog) { + testFailed("Setting up program failed"); + return; + } + let err = gl.getError(); + if (err) throw err; + + const IS_ACTIVE_BY_NAME = { + 'u_vert_scalar' : true, + 'u_vert_scalar[0]': false, + 'u_vert_arr' : true, + 'u_vert_arr[0]' : true, // Even if the [0] is unused, the name enumerated + // via getActiveUniforms for this array is 'u_vert_arr[0]'. + 'u_vert_arr[1]' : false, + + 'u_frag_scalar' : true, + 'u_frag_scalar[0]': false, + 'u_frag_arr' : true, + 'u_frag_arr[0]' : true, + 'u_frag_arr[1]' : false, + + 'u_both_scalar' : true, + 'u_both_scalar[0]': false, + 'u_both_arr' : true, + 'u_both_arr[0]' : true, + 'u_both_arr[1]' : false, + }; + const NAMES = Object.keys(IS_ACTIVE_BY_NAME); + const active_ids = gl.getUniformIndices(prog, NAMES); + + err = gl.getError(); + if (err) throw err; + + NAMES.forEach((name, i) => { + const active_id_was = active_ids[i]; + const is_active_expected = IS_ACTIVE_BY_NAME[name]; + const is_active_was = active_id_was != gl.INVALID_INDEX; + expectTrue(is_active_was == is_active_expected, + `getUniformIndices([, '${name}' ,]) -> [, ${active_id_was} ,], should be [, ${is_active_expected ? '0<=N<INVALID_INDEX' : 'INVALID_INDEX'} ,]`); + if (is_active_was) { + const info = gl.getActiveUniform(prog, active_id_was); + expectTrue(info.name.startsWith(name), `'${info.name}'.startsWith('${name}')`); + } + }); +})(); + +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/programs/gl-get-frag-data-location.html b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/gl-get-frag-data-location.html new file mode 100644 index 0000000000..1e006ebd28 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/gl-get-frag-data-location.html @@ -0,0 +1,121 @@ +<!-- +Copyright (c) 2021 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 Conformance Tests: Verify getFragDataLocation</title> +<link rel="stylesheet" href="../../resources/js-test-style.css"/> +<script src="../../js/desktop-gl-constants.js"></script> +<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: 4px; height: 4px;"> </canvas> +<div id="console"></div> +<script id="vs" type="x-shader/x-vertex">#version 300 es +void main() { + gl_Position = vec4(0, 0, 0, 1); +} +</script> + +<script id="fs" type="x-shader/x-fragment">#version 300 es +precision mediump float; +layout(location = 2) out vec4 fragColor0; +layout(location = 0) out vec4 fragColor1; +void main() { + fragColor0 = vec4(0, 1, 0, 1); + fragColor1 = vec4(1, 0, 0, 1); +} +</script> + +<script id="fs-array" type="x-shader/x-fragment">#version 300 es +precision mediump float; +out vec4 fragColor[2]; +void main() { + fragColor[0] = vec4(0, 1, 0, 1); + fragColor[1] = vec4(1, 0, 0, 1); +} +</script> + +<script id="vs-es2" type="x-shader/x-vertex"> +void main() { + gl_Position = vec4(0, 0, 0, 1); +} +</script> +<script id="fs-es2" type="x-shader/x-fragment"> +precision mediump float; +void main() { + gl_FragColor = vec4(0, 1, 0, 1); +} +</script> + +<script> +"use strict"; +description("This test verifies getFragDataLocation behaviors."); + +debug(""); + +var wtu = WebGLTestUtils; +var canvas = document.getElementById("canvas"); +var gl = wtu.create3DContext(canvas, null, 2); + +if (!gl) { + testFailed("WebGL context does not exist"); +} else { + testPassed("WebGL context exists"); + runTests(); +} + +function runTests() { + window.program = wtu.setupProgram(gl, ["vs", "fs"]); + window.programArray = wtu.setupProgram(gl, ["vs", "fs-array"]); + window.programEs2 = wtu.setupProgram(gl, ["vs-es2", "fs-es2"]); + if (!program || !programArray || !programEs2) { + testFailed("Set up program failed"); + return; + } + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from set up"); + + shouldBe("gl.getFragDataLocation(program, 'gl_FragColor')", "-1"); + shouldBe("gl.getFragDataLocation(programArray, 'gl_FragColor')", "-1"); + shouldBe("gl.getFragDataLocation(programEs2, 'gl_FragColor')", "-1"); + shouldBe("gl.getFragDataLocation(program, 'gl_FragData')", "-1"); + shouldBe("gl.getFragDataLocation(programArray, 'gl_FragData')", "-1"); + shouldBe("gl.getFragDataLocation(programEs2, 'gl_FragData')", "-1"); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from gl_* queries"); + + var loc0 = gl.getFragDataLocation(program, "fragColor0"); + var loc1 = gl.getFragDataLocation(program, "fragColor1"); + if (loc0 != 2 || loc1 != 0) { + testFailed("Fail to query scalar output variable locations, " + + "expected: fragColor0->2, fragColor1->0, " + + "got: fragColor0->" + loc0 + ", fragColor1->" + loc1); + } else { + testPassed("getFragDataLocation on scalar variables works fine"); + } + + var loc = gl.getFragDataLocation(programArray, "fragColor"); + loc0 = gl.getFragDataLocation(programArray, "fragColor[0]"); + loc1 = gl.getFragDataLocation(programArray, "fragColor[1]"); + if (loc < 0 || loc0 < 0 || loc1 < 0 || loc != loc0 || loc0 + 1 != loc1) { + testFailed("Fail to query scalar output variable locations, " + + "expected: fragColor->0, fragColor[0]->0, fragColor[1]->1, " + + "got: fragColor->" + loc + ", fragColor[0]->" + loc0 + ", fragColor[1]->" + loc1); + } else { + testPassed("getFragDataLocation on variable arrays works fine"); + } + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No GL error from testing"); +} + +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/programs/sampler-uniforms.html b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/sampler-uniforms.html new file mode 100644 index 0000000000..4df60d3ee3 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/programs/sampler-uniforms.html @@ -0,0 +1,111 @@ +<!-- +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>WebGL2 getActiveUniform 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="example" width="16" height="16"></canvas> +<div id="description"></div> +<div id="console"></div> +<script id="vshader" type="x-shader/x-vertex">#version 300 es +void main() +{ + gl_Position = vec4(0, 0, 0, 1); +} +</script> +<script id="fshader" type="x-shader/x-fragment">#version 300 es +precision mediump float; +uniform mediump $type uniform0; +out vec4 myFragColor; +void main() +{ + myFragColor = vec4(0,$access,0,1); +} +</script> +<script> +"use strict"; +description("Tests getActiveUniform for various types"); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("example", undefined, 2); + +var tests = [ + { glType: gl.SAMPLER_2D, size: 1, type: 'sampler2D', access: 'texture(uniform0, vec2(0,0)).x'}, + { glType: gl.SAMPLER_CUBE, size: 1, type: 'samplerCube', access: 'texture(uniform0, vec3(0,1,0)).x'}, + { glType: gl.SAMPLER_3D, size: 1, type: 'sampler3D', access: 'texture(uniform0, vec3(0,1,0)).x'}, + { glType: gl.SAMPLER_2D_ARRAY, size: 1, type: 'sampler2DArray', access: 'texture(uniform0, vec3(0,1,0)).x'}, + + { glType: gl.SAMPLER_2D_SHADOW, size: 1, type: 'sampler2DShadow', access: 'texture(uniform0, vec3(0,1,0))'}, + { glType: gl.SAMPLER_CUBE_SHADOW, size: 1, type: 'samplerCubeShadow', access: 'texture(uniform0, vec4(0,1,0,0))'}, + { glType: gl.SAMPLER_2D_ARRAY_SHADOW, size: 1, type: 'sampler2DArrayShadow', access: 'texture(uniform0, vec4(0,1,0,0))'}, + + { glType: gl.INT_SAMPLER_2D, size: 1, type: 'isampler2D', access: 'texture(uniform0, vec2(0,0)).x'}, + { glType: gl.INT_SAMPLER_CUBE, size: 1, type: 'isamplerCube', access: 'texture(uniform0, vec3(0,1,0)).x'}, + { glType: gl.INT_SAMPLER_3D, size: 1, type: 'isampler3D', access: 'texture(uniform0, vec3(0,1,0)).x'}, + { glType: gl.INT_SAMPLER_2D_ARRAY, size: 1, type: 'isampler2DArray', access: 'texture(uniform0, vec3(0,1,0)).x'}, + + { glType: gl.UNSIGNED_INT_SAMPLER_2D, size: 1, type: 'usampler2D', access: 'texture(uniform0, vec2(0,0)).x'}, + { glType: gl.UNSIGNED_INT_SAMPLER_CUBE, size: 1, type: 'usamplerCube', access: 'texture(uniform0, vec3(0,1,0)).x'}, + { glType: gl.UNSIGNED_INT_SAMPLER_3D, size: 1, type: 'usampler3D', access: 'texture(uniform0, vec3(0,1,0)).x'}, + { glType: gl.UNSIGNED_INT_SAMPLER_2D_ARRAY, size: 1, type: 'usampler2DArray', access: 'texture(uniform0, vec3(0,1,0)).x'}, +]; + +var vs = wtu.loadShaderFromScript(gl, 'vshader', gl.VERTEX_SHADER); +var source = document.getElementById('fshader').text; + +function createProgram(type, access) { + var fs = wtu.loadShader( + gl, + source.replace('$type', type).replace('$access', access), + gl.FRAGMENT_SHADER); + var program = wtu.setupProgram(gl, [vs, fs]); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup"); + return program; +} + +for (var tt = 0; tt < tests.length; ++tt) { + var t = tests[tt]; + debug(""); + debug("Testing uniform sampler type : " + t.type); + var program = createProgram(t.type, t.access); + var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS); + assertMsg(numUniforms >= 1, "at least 1 sampler uniform"); + var found = false; + for (var ii = 0; ii < numUniforms; ++ii) { + var info = gl.getActiveUniform(program, ii); + if (info.name == 'uniform0') { + found = true; + assertMsg(info.type == t.glType, + "type must be " + wtu.glEnumToString(gl, t.glType) + " was " + + wtu.glEnumToString(gl, info.type)); + assertMsg(info.size == t.size, + "size must be " + t.size + ' was ' + info.size); + } + } + assertMsg(found, "uniform 'uniform0' should exist"); + var loc = gl.getUniformLocation(program, 'uniform0'); + assertMsg(loc != null, "getUniformLocation must return non null"); + gl.uniform1i(loc, tt + 1); + var val = gl.getUniform(program, loc); + assertMsg(val == tt + 1, "getUniform must return set value"); +} + +debug(""); +wtu.glErrorShouldBe(gl, gl.NO_ERROR, "no errors running the tests"); + +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> |