Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / textures / tex-image-webgl.html
1 <!--
2
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
31 <meta charset="utf-8">
32 <title>WebGL texImage2D from WebGL conformance test.</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test-utils.js"> </script>
36 </head>
37 <body>
38 <canvas id="example" width="256" height="16" style="width: 256px; height: 48px;"></canvas>
39 <canvas id="source" width="256" height="16" style="width: 256px; height: 48px;"></canvas>
40 <div id="description"></div>
41 <div id="console"></div>
42 <script>
43 "use strict";
44 description("Test texImage2D from a webgl canvas.");
45 var wtu = WebGLTestUtils;
46 var gl = wtu.create3DContext("example");
47 gl.disable(gl.DITHER);
48 var program = wtu.setupTexturedQuad(gl);
49 var gl1 = wtu.create3DContext("source");
50 gl1.disable(gl.DITHER);
51 gl1.disable(gl.BLEND);
52 gl1.disable(gl.DEPTH_TEST);
53
54 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors from setup.");
55 wtu.glErrorShouldBe(gl1, gl1.NO_ERROR, "Should be no errors from setup.");
56
57 gl.disable(gl.BLEND);
58 gl.disable(gl.DEPTH_TEST);
59
60 gl1.clearColor(1.0, 0.0, 0.0, 1.0);
61 gl1.clear(gl1.COLOR_BUFFER_BIT);
62
63 var tex = gl.createTexture();
64 gl.bindTexture(gl.TEXTURE_2D, tex);
65 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, gl1.canvas);
66 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
67 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
68 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
69 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
70 wtu.clearAndDrawUnitQuad(gl);
71
72 wtu.checkCanvas(gl, [255, 0, 0, 255], "Canvas should be red");
73
74 gl1.clearColor(0.0, 1.0, 0.0, 1.0);
75 gl1.clear(gl1.COLOR_BUFFER_BIT);
76
77 var program1 = wtu.setupTexturedQuad(gl1);
78 var tex1 = gl1.createTexture();
79 gl1.bindTexture(gl.TEXTURE_2D, tex1);
80 gl1.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, 1, 1, 0, gl.RGB, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 255]));
81
82 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, gl1.canvas);
83 wtu.clearAndDrawUnitQuad(gl);
84
85 wtu.checkCanvas(gl, [0, 255, 0, 255], "Canvas should be green");
86
87 // Test a scenario from Chrome where a WebGL context would lose its active texture binding when its
88 // canvas was used as the texture source for another WebGL context.
89 wtu.clearAndDrawUnitQuad(gl1);
90
91 wtu.checkCanvas(gl1, [0, 0, 255, 255], "Canvas should be blue");
92
93 debug("");
94 var successfullyParsed = true;
95 </script>
96 <script src="../../resources/js-test-post.js"></script>
97 </body>
98 </html>
99