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