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/conformance2/uniforms/draw-with-uniform-blocks.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/conformance2/uniforms/draw-with-uniform-blocks.html')
-rw-r--r-- | dom/canvas/test/webgl-conf/checkout/conformance2/uniforms/draw-with-uniform-blocks.html | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-conf/checkout/conformance2/uniforms/draw-with-uniform-blocks.html b/dom/canvas/test/webgl-conf/checkout/conformance2/uniforms/draw-with-uniform-blocks.html new file mode 100644 index 0000000000..3fa7949eac --- /dev/null +++ b/dom/canvas/test/webgl-conf/checkout/conformance2/uniforms/draw-with-uniform-blocks.html @@ -0,0 +1,120 @@ +<!-- +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 draw with uniform blocks 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> +<script id="vshader" type="x-shader/x-vertex">#version 300 es +in vec4 a_vertex; +void main(void) { + gl_Position = a_vertex; +} +</script> +<script id="fshader" type="x-shader/x-fragment">#version 300 es +precision mediump float; +layout (std140) uniform color_ubo { + vec4 color; +}; +out vec4 fragColor; +void main(void) { + fragColor = color; +} +</script> +</head> +<body> +<canvas id="example" width="100", height="100"></canvas> +<div id="description"></div> +<div id="console"></div> +<script> +"use strict"; +debug(""); +description("Regression test for crbug.com/793307 and https://bugzilla.mozilla.org/show_bug.cgi?id=1424258"); + +var wtu = WebGLTestUtils; +var gl = wtu.create3DContext("example", undefined, 2); + +function runTest() { + var program = wtu.setupProgram(gl, ['vshader', 'fshader'], ['a_vertex']); + var uboIndex = gl.INVALID_INDEX; + if (program) + uboIndex = gl.getUniformBlockIndex(program, "color_ubo"); + if (!program || uboIndex == gl.INVALID_INDEX) { + testFailed("Loading program failed"); + return; + } + testPassed("Loading program succeeded"); + + var vertices = new Float32Array([ + -1, -1, 0, + 1, -1, 0, + -1, 1, 0, + 1, 1, 0 + ]); + var vertexBuf = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuf); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); + gl.enableVertexAttribArray(0); + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); + + var indexBuf = gl.createBuffer(); + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuf); + gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Int16Array([ 0, 1, 2, 2, 1, 3 ]), gl.STATIC_DRAW); + + var uboDataSize = gl.getActiveUniformBlockParameter( + program, uboIndex, gl.UNIFORM_BLOCK_DATA_SIZE); + if (uboDataSize == 0) { + testFailed("uniform block data size invalid"); + return; + } + + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No errors from setup"); + + debug("draw lower triangle - should be red"); + var uboBuf1 = gl.createBuffer(); + gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, uboBuf1); + gl.bufferData(gl.UNIFORM_BUFFER, uboDataSize, gl.STATIC_DRAW); + gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([ 1, 0, 0, 1 ])); + gl.uniformBlockBinding(program, uboIndex, 0); + gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No errors from draw"); + + debug("draw upper triangle - should be green"); + var uboBuf2 = gl.createBuffer(); + gl.bindBufferBase(gl.UNIFORM_BUFFER, 1, uboBuf2); + gl.bufferData(gl.UNIFORM_BUFFER, uboDataSize, gl.STATIC_DRAW); + gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([ 0, 1, 0, 1 ])); + gl.uniformBlockBinding(program, uboIndex, 1); + gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 6); + wtu.glErrorShouldBe(gl, gl.NO_ERROR, "No errors from draw"); + + var width = 100, height = 100; + wtu.checkCanvasRectColor(gl, 0, 0, width/2-5, height/2-5, [255, 0, 0, 255], 2, + function() { testPassed("lower left should be red"); }, + function() { testFailed("lower left should be red"); }); + wtu.checkCanvasRectColor(gl, width/2+5, height/2+5, width/2-5, height/2-5, [0, 255, 0, 255], 2, + function() { testPassed("top right should be green"); }, + function() { testFailed("top right should be green"); }); +} + +if (!gl) { + testFailed("WebGL context creation failed"); +} else { + testPassed("WebGL context creation succeeded"); + runTest(); +} + +debug(""); +var successfullyParsed = true; +</script> +<script src="../../js/js-test-post.js"></script> + +</body> +</html> |