Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / rendering / clearbuffer-sub-source.html
blob616d2bda4caf787e617f6cc31c471261332d19f3
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>Test clearBuffer functions with optional srcOffset argument</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <div id="console"></div>
19 <canvas id="canvas" width="20" height="20"> </canvas>
20 <script>
21 "use strict";
22 description("This tests clearBuffer* functions with optional srcOffset argument");
24 function verifyOnePixel(readFormat, readType, arrayType, expectedColor) {
25 var buffer = new arrayType(4);
26 gl.readPixels(0, 0, 1, 1, readFormat, readType, buffer);
27 if (buffer[0] == expectedColor[0] &&
28 buffer[1] == expectedColor[1] &&
29 buffer[2] == expectedColor[2] &&
30 buffer[3] == expectedColor[3]) {
31 testPassed("clearBuffer sets the renderbuffer with the correct data");
32 } else {
33 testFailed("clearBuffer fails to work. Expected: " + expectedColor + ", got: " + buffer);
37 function testClearBuffer(func, format, arrayType, readFormat, readType) {
38 debug("");
39 debug("Testing " + func);
41 var fb = gl.createFramebuffer();
42 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
44 var renderbuffer = gl.createRenderbuffer();
45 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
46 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, renderbuffer);
47 gl.renderbufferStorage(gl.RENDERBUFFER, format, canvas.width, canvas.height);
48 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
50 var srcData = new arrayType([1, 2, 3, 4, 5, 6]);
51 gl[func](gl.COLOR, 0, srcData);
52 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "clearBuffer with no srcOffset should succeed");
53 verifyOnePixel(readFormat, readType, arrayType, [1,2,3,4]);
55 gl[func](gl.COLOR, 0, srcData, 0);
56 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "clearBuffer with srcOffset = 0 should succeed");
57 verifyOnePixel(readFormat, readType, arrayType, [1,2,3,4]);
59 gl[func](gl.COLOR, 0, srcData, 2);
60 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "clearBuffer with srcOffset = 2 should succeed");
61 verifyOnePixel(readFormat, readType, arrayType, [3,4, 5, 6]);
63 gl[func](gl.COLOR, 0, srcData, 4);
64 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "clearBuffer with srcOffset = 4 should fail: out of bounds");
66 gl.deleteFramebuffer(fb);
67 gl.deleteRenderbuffer(renderbuffer);
70 var wtu = WebGLTestUtils;
71 var canvas = document.getElementById("canvas");
72 var gl = wtu.create3DContext(canvas, undefined, 2);
73 if (!gl) {
74 testFailed("context does not exist");
75 } else {
76 testPassed("context exists");
78 var testCases = [
80 func: "clearBufferiv", format: gl.RGBA32I, arrayType: Int32Array,
81 readFormat: gl.RGBA_INTEGER, readType: gl.INT,
84 func: "clearBufferuiv", format: gl.RGBA32UI, arrayType: Uint32Array,
85 readFormat: gl.RGBA_INTEGER, readType: gl.UNSIGNED_INT,
88 func: "clearBufferfv", format: gl.RGBA32F, arrayType: Float32Array,
89 readFormat: gl.RGBA, readType: gl.FLOAT,
90 extension: "EXT_color_buffer_float",
94 for (var tt = 0; tt < testCases.length; ++tt) {
95 var test = testCases[tt];
96 if (test.extension && !gl.getExtension(test.extension))
97 continue;
98 testClearBuffer(test.func, test.format, test.arrayType, test.readFormat, test.readType);
102 debug("");
103 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no error");
104 var successfullyParsed = true;
106 </script>
107 <script src="../../js/js-test-post.js"></script>
109 </body>
110 </html>