haikuwebkit/LayoutTests/fast/canvas/webgl/getBufferSubData-webgl1.html

68 lines
2.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<canvas id="canvas" width="40" height="40"></canvas>
<script>
description("Make sure that getBufferSubData() doesn't work on WebGL 1 contexts");
if (window.internals)
internals.settings.setWebGL2Enabled(true);
var arrayBuffer = new ArrayBuffer(40);
var fullArrayView = new Float32Array(arrayBuffer); // [15, 16, 17, 18, 19, 20, 21, 22, 23, 24], 40 bytes
var receiver = new Float32Array(20); // 20 floats, 80 bytes
for (var i = 0; i < 10; ++i)
fullArrayView[i] = 15 + i;
var canvas = document.getElementById("canvas");
var context = canvas.getContext("webgl2");
trySuccessUploadDownload();
canvas = document.createElement("canvas");
canvas.width = 40;
canvas.height = 40;
context = canvas.getContext("webgl");
tryFailUploadDownload();
if (window.internals)
internals.settings.setWebGL2Enabled(false);
canvas = document.createElement("canvas");
canvas.width = 40;
canvas.height = 40;
context = canvas.getContext("webgl2");
shouldBeNull("context");
function trySuccessUploadDownload() {
var buffer = context.createBuffer();
shouldBe("context.getError()", "context.NO_ERROR");
context.bindBuffer(context.ARRAY_BUFFER, buffer);
shouldBe("context.getError()", "context.NO_ERROR");
context.bufferData(context.ARRAY_BUFFER, arrayBuffer, context.STATIC_DRAW);
shouldBe("context.getError()", "context.NO_ERROR");
context.getBufferSubData(context.ARRAY_BUFFER, 0, receiver, 0, 10);
shouldBe("context.getError()", "context.NO_ERROR");
for (var i = 0; i < 10; ++i)
shouldBe("receiver[" + i + "]", "fullArrayView[" + i + "]");
context.deleteBuffer(buffer);
shouldBe("context.getError()", "context.NO_ERROR");
}
function tryFailUploadDownload() {
var buffer = context.createBuffer();
shouldBe("context.getError()", "context.NO_ERROR");
context.bindBuffer(context.ARRAY_BUFFER, buffer);
shouldBe("context.getError()", "context.NO_ERROR");
context.bufferData(context.ARRAY_BUFFER, arrayBuffer, context.STATIC_DRAW);
shouldBe("context.getError()", "context.NO_ERROR");
shouldThrow("context.getBufferSubData(context.ARRAY_BUFFER, 0, receiver, 0, 10)");
context.deleteBuffer(buffer);
shouldBe("context.getError()", "context.NO_ERROR");
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>