Skip to content

Commit

Permalink
Bug 1724535 - Update WebGL CTS checkout. r=lsalzman
Browse files Browse the repository at this point in the history
  • Loading branch information
kdashg committed Aug 23, 2021
1 parent 674a314 commit 980e4a9
Show file tree
Hide file tree
Showing 199 changed files with 8,199 additions and 1,175 deletions.
2 changes: 1 addition & 1 deletion dom/canvas/test/webgl-conf/MERGE_BASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master
main
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@
componentSize: 4,
normalize: false,
},
{ data: new Float32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
type: gl.FLOAT,
componentSize: 4,
normalize: false,
},
{ data: new Uint16Array([ 0, 32767, 0, 32767, 0, 0, 0, 0, 0 ]),
{ data: new Uint16Array([ 0, 32767, 0, 32767, 0, 0, 0, 0, 0]),
type: gl.SHORT,
componentSize: 2,
normalize: true,
Expand Down Expand Up @@ -99,6 +94,41 @@
}
];

if (wtu.getDefault3DContextVersion() >= 2) {
tests.push(...[
{ data: new Int32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0]),
type: gl.INT,
componentSize: 4,
normalize: false,
},
{ data: new Int32Array([ 0, 2147483647, 0, 2147483647, 0, 0, 0, 0, 0]),
type: gl.INT,
componentSize: 4,
normalize: true,
},
{ data: new Uint32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0]),
type: gl.UNSIGNED_INT,
componentSize: 4,
normalize: false,
},
{ data: new Uint32Array([ 0, 4294967295, 0, 4294967295, 0, 0, 0, 0, 0]),
type: gl.UNSIGNED_INT,
componentSize: 4,
normalize: true,
},
{ data: new Uint16Array([ 0, 0b11110000000000, 0, 0b11110000000000, 0, 0, 0, 0, 0]),
type: gl.HALF_FLOAT,
componentSize: 2,
normalize: false,
},
{ data: new Uint16Array([ 0, 0b11110000000000, 0, 0b11110000000000, 0, 0, 0, 0, 0]),
type: gl.HALF_FLOAT,
componentSize: 2,
normalize: false,
}
]);
}

var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
gl.vertexAttribPointer(0, 1, gl.UNSIGNED_INT, 0, 0, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM,
"vertexAttribPointer should not support UNSIGNED_INT");
gl.vertexAttribPointer(0, 1, gl.FIXED, 0, 0, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM,
"vertexAttribPointer should not support FIXED");
}
gl.vertexAttribPointer(0, 1, gl.FIXED, 0, 0, 0);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM,
"vertexAttribPointer should not support FIXED");

var checkVertexAttribPointer = function(
gl, err, reason, size, type, normalize, stride, offset) {
Expand Down Expand Up @@ -100,6 +100,16 @@
{ type:gl.FLOAT, bytesPerComponent: 4 },
];

if (wtu.getDefault3DContextVersion() >= 2) {
types.push(...[
{ type:gl.INT, bytesPerComponent: 4 },
{ type:gl.UNSIGNED_INT, bytesPerComponent: 4 },
{ type:gl.HALF_FLOAT, bytesPerComponent: 2 },
{ type:gl.INT_2_10_10_10_REV, bytesPerComponent: 4, minSize: 4 },
{ type:gl.UNSIGNED_INT_2_10_10_10_REV, bytesPerComponent: 4, minSize: 4 },
]);
}

for (var ii = 0; ii < types.length; ++ii) {
var info = types[ii];
debug("");
Expand Down Expand Up @@ -128,17 +138,21 @@
reason = "because stride is bad";
err = gl.INVALID_OPERATION;
}
if (size < info.minSize) {
reason = "because size < minSize";
err = gl.INVALID_OPERATION;
}
checkVertexAttribPointer(
gl, err, reason, size, info.type, false, stride, offset);
}
var stride = Math.floor(255 / info.bytesPerComponent) * info.bytesPerComponent;

if (offset == 0) {
checkVertexAttribPointer(
gl, gl.NO_ERROR, "at stride limit",
gl, size < info.minSize ? gl.INVALID_OPERATION : gl.NO_ERROR, "at stride limit",
size, info.type, false, stride, offset);
checkVertexAttribPointer(
gl, gl.INVALID_VALUE, "over stride limit",
gl, size < info.minSize ? [gl.INVALID_OPERATION, gl.INVALID_VALUE] : gl.INVALID_VALUE, "over stride limit",
size, info.type, false,
stride + info.bytesPerComponent, offset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,24 @@

{ parameter: new ArrayBuffer(0), expectedBufferSize: 0 },
{ parameter: new ArrayBuffer(4), expectedBufferSize: 4 },
{ parameter: new Uint8Array(new ArrayBuffer(5)), expectedBufferSize: 5 },
{ parameter: new DataView(new ArrayBuffer(7)), expectedBufferSize: 7 },

{ parameter: "WebGL Rocks!", expectedBufferSize: 0 },
{ parameter: { mystring: "WebGL Rocks!" }, expectedBufferSize: 0 },
];

if (window.SharedArrayBuffer) {
bufferDataParams.push(
{ parameter: new SharedArrayBuffer(3), expectedBufferSize: 3 },
{ parameter: new Uint8Array(new SharedArrayBuffer(6)), expectedBufferSize: 6 },
{ parameter: new DataView(new SharedArrayBuffer(8)), expectedBufferSize: 8 }
);
}

bufferDataParams.forEach(function (bufferDataParam) {
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);

gl.bufferData(gl.ARRAY_BUFFER, bufferDataParam.parameter, gl.STATIC_DRAW);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Passing " + bufferDataParam.parameter + " to bufferData");

Expand Down Expand Up @@ -154,6 +163,18 @@
shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 0, { mynumber: 42});");
shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, null)");
shouldThrow("gl.bufferSubData(gl.ARRAY_BUFFER, 10, undefined)");

if (window.SharedArrayBuffer) {
const validDatas = [
'new SharedArrayBuffer(3)',
'new Uint8Array(new SharedArrayBuffer(3))',
'new DataView(new SharedArrayBuffer(3))',
];
for (const x of validDatas) {
shouldNotThrow(`gl.bufferSubData(gl.ARRAY_BUFFER, 0, ${x})`);
}
}

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should generate no GL error");

// -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ drawingbuffer-test.html
--min-version 1.0.4 render-after-resize-test.html
--min-version 1.0.2 texture-bindings-unaffected-on-resize.html
--min-version 1.0.2 to-data-url-test.html
--min-version 1.0.4 to-data-url-after-composite.html
viewport-unchanged-upon-resize.html
--min-version 1.0.4 webgl-to-2d-canvas.html

Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
// different results. Sometimes wrong, sometimes correct.
const LARGE = 1200;

function render() {

}

gl.uniform4fv(colorLocation, [0.0, 1.0, 0.0, 1.0]);

// -
Expand All @@ -64,6 +60,19 @@

wtu.checkCanvasRect(gl, 0, 0, 1, 1, [ 0, 255, 0, 255 ]);

debug('\nCause a GL error, then resize and render.');
gl.depthFunc(0); // Causes INVALID_ENUM
gl.canvas.width = gl.canvas.height = LARGE;
gl.clear(gl.COLOR_BUFFER_BIT);
gl.canvas.width = gl.canvas.height = SMALL;

gl.clear(gl.COLOR_BUFFER_BIT);
wtu.drawUnitQuad(gl);

wtu.checkCanvasRect(gl, 0, 0, 1, 1, [ 0, 255, 0, 255 ]);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);

// -

debug('\nRender, no-op resize, then depth-fail render.');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--
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 toDataURL after composite 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 width="20" height="20" style="border: 1px solid black; width: 128px; height: 128px" id="c3d"></canvas>
<canvas width="20" height="20" style="border: 1px solid black; width: 128px; height: 128px" id="c2d"></canvas>
<div id="description"></div>
<div id="console"></div>
<script type="application/javascript">
const wtu = WebGLTestUtils;
let gl;
let ctx;

function main() {
description();
const c2d = document.getElementById("c2d");
ctx = c2d.getContext("2d");
gl = wtu.create3DContext("c3d", { preserveDrawingBuffer: true });

// Clear to green
gl.clearColor(0.0, 1.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);

wtu.waitForComposite(() => {
// Performs gl.canvas.toDataURL() internally
let img = wtu.makeImageFromCanvas(gl.canvas, function() {
ctx.drawImage(img, 0, 0);
wtu.checkCanvas(ctx, [0, 255, 0], "toDataURL loaded into image, drawn into 2D context, should be green", 5);
finishTest();
});
});

};

main();
var successfullyParsed = true;
</script>
</body>
</html>

Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,53 @@
var main = function() {
description();
ctx = document.getElementById("c2d").getContext("2d");
gl = wtu.create3DContext("c3d");

if (!gl) {
testFailed("can't create 3d context");
finishTest();
return;
}
var updateCanvas = function(width, height, attributes) {
var canvas = document.getElementById("c3d");

if (gl && (gl.attributes !== attributes)) {
// Attributes changed, recreate the canvas
var newCanvas = canvas.cloneNode();
canvas.parentNode.replaceChild(newCanvas, canvas);
canvas = newCanvas;
gl = undefined;
}

canvas.width = width;
canvas.height = height;

if (!gl) {
gl = wtu.create3DContext(canvas, attributes);

if (!gl) {
testFailed("can't create 3d context");
return;
}

gl.attributes = attributes;
}

return gl;
};

var clearRect = function(gl, x, y, width, height, color) {
gl.clearColor(color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255);
gl.scissor(x, y, width, height);
gl.clear(gl.COLOR_BUFFER_BIT);
};

var testSize = function(gl, width, height, callback) {
debug("testing " + width + " by " + height);
gl.canvas.width = width;
gl.canvas.height = height;
var testSize = function(width, height, attributes, callback) {
let attributesDebugMessage = "";
if (attributes) {
attributesDebugMessage = " attributes: " + JSON.stringify(attributes);
}
debug("testing " + width + " by " + height + attributesDebugMessage);
var gl = updateCanvas(width, height, attributes);
if (!gl) {
callback();
return;
}

gl.viewport(0, 0, width, height);
gl.enable(gl.SCISSOR_TEST);

Expand Down Expand Up @@ -71,6 +100,9 @@
});
};

const premultipliedAlphaAttributes = {
premultipliedAlpha: false,
};
var tests = [
{ width: 16 , height: 16 , },
{ width: 16 - 1, height: 16 , },
Expand All @@ -87,6 +119,7 @@
{ width: 512 - 1, height: 512 - 1, },
{ width: 512 + 1, height: 512 - 1, },
{ width: 512 - 1, height: 512 + 1, },
{ width: 16 , height: 16 , attributes: premultipliedAlphaAttributes},
];
var testIndex = 0;
var runNextTest = function() {
Expand All @@ -95,7 +128,7 @@
return;
}
var test = tests[testIndex++];
testSize(gl, test.width, test.height, function() {
testSize(test.width, test.height, test.attributes, function() {
setTimeout(runNextTest, 0);
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ context-attributes-alpha-depth-stencil-antialias.html
context-lost-restored.html
context-lost.html
--max-version 1.9.9 context-type-test.html
--min-version 1.0.4 deleted-object-behavior.html
incorrect-context-object-behaviour.html
--max-version 1.9.9 methods.html
premultiplyalpha-test.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
display: inline-block;
}
canvas {
width:50px;
height:50px;
width:10px;
height:10px;
}
.square {
display:inline-block;
width:50px;
height:50px;
width:10px;
height:10px;
background-color:red;
}
</style>
Expand Down
Loading

0 comments on commit 980e4a9

Please sign in to comment.