Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / webgl / copy-tex-image-and-sub-image-2d.html
blobc7926456be6c59943d85840b1ffae24df54c1615
1 <html>
2 <head>
3 <script src="../../../resources/js-test.js"></script>
4 <script src="resources/webgl-test.js"></script>
5 <script id="vshader" type="x-shader/x-vertex">
6 attribute vec3 g_Position;
7 attribute vec2 g_TexCoord0;
9 varying vec2 texCoord;
11 void main()
13 gl_Position = vec4(g_Position.x, g_Position.y, g_Position.z, 1.0);
14 texCoord = g_TexCoord0;
16 </script>
18 <script id="fshader" type="x-shader/x-fragment">
19 #ifdef GL_ES
20 precision mediump float;
21 #endif
22 uniform sampler2D tex;
23 varying vec2 texCoord;
24 void main()
26 gl_FragColor = texture2D(tex, texCoord);
28 </script>
30 <script>
32 function init()
34 if (window.initNonKhronosFramework) {
35 window.initNonKhronosFramework(true);
38 description('Verify copyTexImage2D and copyTexSubImage2D');
40 runTest();
43 // These two declarations need to be global for "shouldBe" to see them
44 var pixel = [0, 0, 0];
45 var correctColor = null;
46 var gl = null;
48 function runTestIteration(antialias)
50 if (antialias)
51 gl = initWebGL("antialiasOn", "vshader", "fshader", [ "g_Position", "g_TexCoord0" ], [ 0, 0, 0, 1 ], 1);
52 else
53 gl = initWebGL("antialiasOff", "vshader", "fshader", [ "g_Position", "g_TexCoord0" ], [ 0, 0, 0, 1 ], 1, { antialias: false });
55 var textureLoc = gl.getUniformLocation(gl.program, "tex");
57 var vertices = new Float32Array([
58 1.0, 1.0, 0.0,
59 -1.0, 1.0, 0.0,
60 -1.0, -1.0, 0.0,
61 1.0, 1.0, 0.0,
62 -1.0, -1.0, 0.0,
63 1.0, -1.0, 0.0]);
64 var texCoords = new Float32Array([
65 1.0, 1.0,
66 0.0, 1.0,
67 0.0, 0.0,
68 1.0, 1.0,
69 0.0, 0.0,
70 1.0, 0.0]);
71 var texCoordOffset = vertices.byteLength;
73 var vbo = gl.createBuffer();
74 gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
75 gl.bufferData(gl.ARRAY_BUFFER,
76 texCoordOffset + texCoords.byteLength,
77 gl.STATIC_DRAW);
78 gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
79 gl.bufferSubData(gl.ARRAY_BUFFER, texCoordOffset, texCoords);
81 gl.enableVertexAttribArray(0);
82 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
83 gl.enableVertexAttribArray(1);
84 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, texCoordOffset);
86 gl.colorMask(1, 1, 1, 0);
87 gl.disable(gl.BLEND);
88 debug('Testing copyTexImage2D');
90 // Red canvas
91 gl.clearColor(1, 0, 0, 1);
92 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
94 var texture = gl.createTexture();
95 // Bind the texture to texture unit 0
96 gl.bindTexture(gl.TEXTURE_2D, texture);
97 // Set up texture
98 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
99 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
100 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
102 glErrorShouldBe(gl, gl.NO_ERROR);
103 gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 2, 2, 0);
104 glErrorShouldBe(gl, gl.NO_ERROR);
106 // Green canvas
107 gl.clearColor(0, 1, 0, 1);
108 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
110 // Point the uniform sampler to texture unit 0
111 gl.uniform1i(textureLoc, 0);
112 // Draw the triangles
113 gl.drawArrays(gl.TRIANGLES, 0, 6);
115 // Read back the rendering results, should be red
116 var buf = new Uint8Array(2 * 2 * 4);
117 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
118 var idx = 0;
119 correctColor = [255, 0, 0];
120 for (var y = 0; y < 2; y++) {
121 for (var x = 0; x < 2; x++) {
122 idx = (y * 2 + x) * 4;
123 pixel[0] = buf[idx];
124 pixel[1] = buf[idx + 1];
125 pixel[2] = buf[idx + 2];
126 shouldBe("pixel", "correctColor");
130 debug('Testing copyTexSubImage2D');
132 // Green canvas
133 gl.clearColor(0, 1, 0, 1);
134 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
136 glErrorShouldBe(gl, gl.NO_ERROR);
137 gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 2, 2);
138 glErrorShouldBe(gl, gl.NO_ERROR);
140 // Blue canvas
141 gl.clearColor(0, 0, 1, 1);
142 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
144 // Draw the triangles
145 gl.drawArrays(gl.TRIANGLES, 0, 6);
147 // Read back the rendering results, should be green
148 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
149 correctColor = [0, 255, 0];
150 for (var y = 0; y < 2; y++) {
151 for (var x = 0; x < 2; x++) {
152 idx = (y * 2 + x) * 4;
153 pixel[0] = buf[idx];
154 pixel[1] = buf[idx + 1];
155 pixel[2] = buf[idx + 2];
156 shouldBe("pixel", "correctColor");
161 function runTest(antialias)
163 debug("Testing with antialias on");
164 runTestIteration(true);
165 debug("Testing with antialias off");
166 runTestIteration(false);
167 finishJSTest();
169 </script>
170 </head>
171 <body onload="init()">
172 <canvas id="antialiasOn" width="2px" height="2px"></canvas>
173 <canvas id="antialiasOff" width="2px" height="2px"></canvas>
174 <div id="description"></div>
175 <div id="console"></div>
176 </body>
177 </html>