3 <script src=
"../../../resources/js-test.js"></script>
4 <script src=
"resources/webgl-test.js"></script>
5 <script src=
"resources/webgl-test-utils.js"> </script>
8 description("Checks that copying canvas results to a WebGL texture functions without error.");
10 var wtu
= WebGLTestUtils
;
12 if (window
.testRunner
) {
13 testRunner
.dumpAsText();
14 testRunner
.waitUntilDone();
23 ctx
.fillStyle
= "rgb(200, 0, 0)";
24 ctx
.fillRect(0, 0, 256, 256);
25 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas2d
);
28 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [200, 0, 0, 255], "Should have rendered red.", 1);
30 ctx
.fillStyle
= "rgb(0, 0, 200)";
31 ctx
.fillRect(0, 0, 256, 256);
32 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas2d
);
33 ctx
.fillStyle
= "rgb(200, 0, 0)";
34 ctx
.fillRect(0, 0, 256, 256);
37 wtu
.checkCanvasRect(gl
, 0, 0, 1, 1, [0, 0, 200, 255], "Should have rendered blue.", 1);
39 if (window
.testRunner
)
40 testRunner
.notifyDone();
43 window
.onload = function()
45 if (window
.initNonKhronosFramework
)
46 window
.initNonKhronosFramework(false);
48 canvas
= document
.getElementById("webgl-canvas");
49 gl
= create3DContext(canvas
);
51 canvas2d
= document
.getElementById("canvas-2d");
53 // Set a size that ensures a hardware-accelerated canvas.
55 canvas2d
.height
= 256;
56 ctx
= canvas2d
.getContext("2d");
58 var program
= wtu
.setupTexturedQuad(gl
);
59 var bufferObjects
= wtu
.setupUnitQuad(gl
);
61 var texture
= gl
.createTexture();
62 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
63 gl
.texParameteri(gl
.TEXTURE_2D
, gl
.TEXTURE_MIN_FILTER
, gl
.LINEAR
);
65 gl
.uniform1i(gl
.getUniformLocation(program
, "tex"), 0);
66 gl
.viewport(0, 0, canvas
.width
, canvas
.height
);
68 // Ensure that the compositor has become active.
73 <div id=
"description"></div>
74 <div id=
"console"></div>
75 <canvas id=
"webgl-canvas" width=
"32px" height=
"32px"></canvas>
76 <canvas id=
"canvas-2d" style=
"transform: translateZ(0);"></canvas>