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/buffers/index-validation.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/buffers/index-validation.html')
-rw-r--r-- | dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation.html | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation.html b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation.html new file mode 100644 index 0000000000..0aa7e78781 --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance/buffers/index-validation.html @@ -0,0 +1,119 @@ +<!-- +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"> +<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("Tests that index validation verifies the correct number of indices"); + +function sizeInBytes(type) { + switch (type) { + case gl.BYTE: + case gl.UNSIGNED_BYTE: + return 1; + case gl.SHORT: + case gl.UNSIGNED_SHORT: + return 2; + case gl.INT: + case gl.UNSIGNED_INT: + case gl.FLOAT: + return 4; + default: + throw "unknown type"; + } +} + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext(); +var program = wtu.loadStandardProgram(gl); + +// 3 vertices => 1 triangle, interleaved data +var dataComplete = new Float32Array([0, 0, 0, 1, + 0, 0, 1, + 1, 0, 0, 1, + 0, 0, 1, + 1, 1, 1, 1, + 0, 0, 1]); +var dataIncomplete = new Float32Array([0, 0, 0, 1, + 0, 0, 1, + 1, 0, 0, 1, + 0, 0, 1, + 1, 1, 1, 1]); +var indices = new Uint16Array([0, 1, 2]); + +debug("Testing with valid indices"); + +var bufferComplete = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete); +gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW); +var elements = gl.createBuffer(); +gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements); +gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); +gl.useProgram(program); +var vertexLoc = gl.getAttribLocation(program, "a_vertex"); +var normalLoc = gl.getAttribLocation(program, "a_normal"); +gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0); +gl.enableVertexAttribArray(vertexLoc); +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT)); +gl.enableVertexAttribArray(normalLoc); +shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE'); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); + +debug("Testing with out-of-range indices"); + +var bufferIncomplete = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete); +gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW); +gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0); +gl.enableVertexAttribArray(vertexLoc); +gl.disableVertexAttribArray(normalLoc); +debug("Enable vertices, valid"); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +debug("Enable normals, out-of-range"); +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT)); +gl.enableVertexAttribArray(normalLoc); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, [gl.INVALID_OPERATION, gl.NO_ERROR]); + +debug("Test with enabled attribute that does not belong to current program"); + +gl.disableVertexAttribArray(normalLoc); +var extraLoc = Math.max(vertexLoc, normalLoc) + 1; +gl.enableVertexAttribArray(extraLoc); +debug("Enable an extra attribute with null"); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION); +debug("Enable an extra attribute with insufficient data buffer"); +gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT)); +wtu.glErrorShouldBe(gl, gl.NO_ERROR); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); +debug("Pass large negative index to vertexAttribPointer"); +gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), -2000000000 * sizeInBytes(gl.FLOAT)); +wtu.glErrorShouldBe(gl, gl.INVALID_VALUE); +shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); + +var successfullyParsed = true; +</script> + +<script src="../../js/js-test-post.js"></script> +</body> +</html> |