• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html>
3<body>
4<script src="../resources/runner.js"></script>
5<script>
6
7var sourceCanvas3D = document.createElement('canvas');
8var sourceCtx = sourceCanvas3D.getContext('experimental-webgl');
9var destCanvas3D = document.createElement('canvas');
10var destCtx = destCanvas3D.getContext('experimental-webgl');
11if (!sourceCtx || !destCtx)
12    PerfTestRunner.log("\nWebGL is not supported or enabled on this platform!\n");
13var MEASURE_DRAW_TIMES = 100;
14var MAX_COUNT = 60000;
15var count = 0;
16
17function setSize(width, height) {
18    sourceCanvas3D.width = width;
19    sourceCanvas3D.height = height;
20    destCanvas3D.width = width;
21    destCanvas3D.height = height;
22}
23
24function rand(range) {
25    return Math.floor(Math.random() * range);
26}
27
28function renderWebGL(gl) {
29    gl.disable(gl.SCISSOR_TEST);
30    gl.clear(gl.COLOR_BUFER_BIT);
31    gl.enable(gl.SCISSOR_TEST);
32    gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024));
33    gl.clearColor(Math.random(), Math.random(), Math.random(), 1);
34    gl.clear(gl.COLOR_BUFFER_BIT);
35}
36
37function uploadWebGLToWebGLTexture() {
38    if (sourceCtx && destCtx) {
39        var tex = destCtx.createTexture();
40        destCtx.bindTexture(destCtx.TEXTURE_2D, tex);
41
42        var start = PerfTestRunner.now();
43
44        for (var i = 0; i < MEASURE_DRAW_TIMES; i++) {
45            destCtx.texImage2D(destCtx.TEXTURE_2D, 0, destCtx.RGBA, destCtx.RGBA, destCtx.UNSIGNED_BYTE, sourceCanvas3D);
46        }
47        destCtx.readPixels(0, 0, 1, 1, sourceCtx.RGBA, sourceCtx.UNSIGNED_BYTE, new Uint8Array(4));
48        destCtx.deleteTexture(tex);
49        count++;
50
51        var elapsedTime = PerfTestRunner.now() - start;
52        PerfTestRunner.measureValueAsync(MEASURE_DRAW_TIMES * 1000 / elapsedTime);
53    } else
54        PerfTestRunner.measureValueAsync(0);
55    if (count < MAX_COUNT)
56        requestAnimationFrame(uploadWebGLToWebGLTexture);
57}
58
59function onCompletedRun() {
60    count = MAX_COUNT;
61}
62
63window.onload = function () {
64    PerfTestRunner.prepareToMeasureValuesAsync({done: onCompletedRun, unit: 'runs/s',
65        description: "This benchmark checks the speed on uploading WebGL(1024x1024) to WebGL Texture(1024x1024)."});
66    setSize(1024, 1024);
67    if (sourceCtx)
68        renderWebGL(sourceCtx);
69    uploadWebGLToWebGLTexture();
70}
71
72</script>
73</body>
74</html>
75