forked from KhronosGroup/WebGL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webgl-get-buffer-sub-data-async-stress.html
111 lines (102 loc) · 4.03 KB
/
webgl-get-buffer-sub-data-async-stress.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!--
/*
** Copyright (c) 2016 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WEBGL_get_buffer_sub_data_async stress 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>
<div id="description"></div>
<canvas id="canvas" width="1" height="1"></canvas>
<div id="console"></div>
<script>
"use strict";
description("This test makes sure that getBufferSubDataAsync acts under stress as expected governed by WebGL 2.");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, undefined, 2);
var WEBGL_get_buffer_sub_data_async = gl.getExtension("WEBGL_get_buffer_sub_data_async");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
if (!WEBGL_get_buffer_sub_data_async) {
testPassed("No WEBGL_get_buffer_sub_data_async support -- this is legal");
finishTest();
} else {
testPassed("Successfully enabled WEBGL_get_buffer_sub_data_async extension");
runTests();
}
function runTests() {
var pbo = gl.createBuffer();
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, pbo);
gl.bufferData(gl.PIXEL_PACK_BUFFER, 4, gl.DYNAMIC_READ);
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
var readbackBuffer = new Uint8Array(4);
var TEST_COUNT = 300;
var lastCounter = -1;
var promises = [];
debug("kicking off " + TEST_COUNT + " getBufferSubDataAsync calls");
for (var i = 0; i < TEST_COUNT; i++) {
(function() {
var counter = i;
var color = [counter & 0xff, (counter >> 8) & 0xff, (counter >> 16) & 0xff, 255];
gl.clearColor(color[0] / 255, color[1] / 255, color[2] / 255, color[3] / 255);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, pbo);
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, 0);
var promise = WEBGL_get_buffer_sub_data_async.getBufferSubDataAsync(gl.PIXEL_PACK_BUFFER, 0, readbackBuffer);
gl.bindBuffer(gl.PIXEL_PACK_BUFFER, null);
promise = promise.then(function(buf) {
if (buf[0] == color[0] &&
buf[1] == color[1] &&
buf[2] == color[2] &&
buf[3] == color[3]) {
testPassed("color readback #" + counter + " was correct");
} else {
testFailed("color readback #" + counter + " was incorrect: was " +
buf + " but expected " + color);
}
if (counter == lastCounter + 1) {
testPassed(" and its Promise resolved in order after " + lastCounter);
} else {
testFailed(" and its Promise resolved out of order order after " + lastCounter);
}
lastCounter = counter;
}, function(e) {
testFailed(e.toString());
});
promises.push(promise);
})();
}
Promise.all(promises).catch(function(e) {
testFailed(e.toString());
}).then(finishTest);
}
var successfullyParsed = true;
</script>
</body>
</html>