4 <script src=
"../resources/runner.js"></script>
5 <script src=
"resources/canvas_runner.js"></script>
8 var canvas2D
= document
.createElement("canvas");
9 var ctx2D
= canvas2D
.getContext("2d");
10 var canvas3D
= document
.createElement('canvas');
11 var gl
= canvas3D
.getContext('webgl');
13 CanvasRunner
.logFatalError("\nWebGL is not supported or enabled on this platform!\n");
16 function setSize(width
, height
) {
17 canvas2D
.width
= width
;
18 canvas2D
.height
= height
;
19 canvas3D
.width
= width
;
20 canvas3D
.height
= height
;
23 function rand(range
) {
24 return Math
.floor(Math
.random() * range
);
27 function fillCanvas(ctx2d
, canvas2d
) {
28 ctx2d
.fillStyle
= "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
29 ctx2d
.fillRect(0, 0, canvas2d
.width
, canvas2d
.height
);
33 tex
= gl
.createTexture();
34 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
38 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas2D
);
41 function ensureComplete() {
42 gl
.readPixels(0, 0, 1, 1, gl
.RGBA
, gl
.UNSIGNED_BYTE
, new Uint8Array(4));
46 gl
.deleteTexture(tex
);
49 window
.onload = function () {
51 fillCanvas(ctx2D
, canvas2D
);
53 description
: "This bench test checks the speed on uploading 2d Canvas(1024x1024) to Webgl Texture(1024x1024).",
56 ensureComplete
: ensureComplete
,