1 <!DOCTYPE html> 2 <html> 3 <body> 4 <script src="../resources/runner.js"></script> 5 <script> 6 7 var sourceCanvas3D = document.createElement('canvas'); 8 var sourceCtx = sourceCanvas3D.getContext('experimental-webgl'); 9 var destCanvas3D = document.createElement('canvas'); 10 var destCtx = destCanvas3D.getContext('experimental-webgl'); 11 if (!sourceCtx || !destCtx) 12 PerfTestRunner.log("\nWebGL is not supported or enabled on this platform!\n"); 13 var MEASURE_DRAW_TIMES = 100; 14 var MAX_COUNT = 60000; 15 var count = 0; 16 17 function setSize(width, height) { 18 sourceCanvas3D.width = width; 19 sourceCanvas3D.height = height; 20 destCanvas3D.width = width; 21 destCanvas3D.height = height; 22 } 23 24 function rand(range) { 25 return Math.floor(Math.random() * range); 26 } 27 28 function 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 37 function 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 59 function onCompletedRun() { 60 count = MAX_COUNT; 61 } 62 63 window.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