Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / canvas / webgl / point-size.html
blob616abe4b3d7a4f6f2367c04b85366ba93968833b
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 pos;
7 attribute vec4 colorIn;
8 uniform float pointSize;
9 varying vec4 color;
11 void main()
13 gl_PointSize = pointSize;
14 color = colorIn;
15 gl_Position = vec4(pos.xyz, 3.0);
17 </script>
19 <script id="fshader" type="x-shader/x-fragment">
20 #ifdef GL_ES
21 precision mediump float;
22 #endif
23 varying vec4 color;
25 void main()
27 gl_FragColor = color;
29 </script>
31 <script>
32 function runTest()
34 var gl = initWebGL('testbed', 'vshader', 'fshader', ['pos', 'colorIn'], [0, 0, 0, 1], 1, { antialias: false });
35 if (!gl) {
36 testFailed('initWebGL(..) failed');
37 return false;
39 gl.disable(gl.BLEND);
40 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
42 // The choice of (0.4, 0.4) ensures that the centers of the surrounding
43 // pixels are not contained within the point when it is of size 1, but
44 // that they definitely are when it is of size 2.
45 var vertices = new Float32Array([
46 0.4, 0.4, 0.0]);
47 var colors = new Uint8Array([
48 255, 0, 0, 255]);
50 var colorOffset = vertices.byteLength;
52 var vbo = gl.createBuffer();
53 gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
54 gl.bufferData(gl.ARRAY_BUFFER, colorOffset + colors.byteLength, gl.STATIC_DRAW);
55 gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
56 gl.bufferSubData(gl.ARRAY_BUFFER, colorOffset, colors);
58 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
59 gl.enableVertexAttribArray(0);
60 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, colorOffset);
61 gl.enableVertexAttribArray(1);
63 var locPointSize = gl.getUniformLocation(gl.program, 'pointSize');
65 debug('Draw a point of size 1 and verify it does not touch any other pixels.');
67 gl.uniform1f(locPointSize, 1.0);
68 gl.drawArrays(gl.POINTS, 0, vertices.length / 3);
69 var buf = new Uint8Array(2 * 2 * 4);
70 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
71 var index = 0;
72 for (var y = 0; y < 2; ++y) {
73 for (var x = 0; x < 2; ++x) {
74 var correctColor = [0, 0, 0];
75 if (x == 1 && y == 1)
76 correctColor[0] = 255;
77 if (buf[index] != correctColor[0] || buf[index + 1] != correctColor[1] || buf[index + 2] != correctColor[2]) {
78 testFailed('Drawing a point of size 1 touched pixels that should not be touched');
79 return false;
81 index += 4;
84 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
86 debug('Draw a point of size 2 and verify it fills the appropriate region.');
88 var pointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
89 if (pointSizeRange < 2.0)
90 return true;
92 gl.uniform1f(locPointSize, 2.0);
93 gl.drawArrays(gl.POINTS, 0, vertices.length / 3);
94 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
95 index = 0;
96 for (var y = 0; y < 2; ++y) {
97 for (var x = 0; x < 2; ++x) {
98 var correctColor = [255, 0, 0];
99 if (buf[index] != correctColor[0] || buf[index + 1] != correctColor[1] || buf[index + 2] != correctColor[2]) {
100 testFailed('Drawing a point of size 2 failed to fill the appropriate region');
101 return false;
103 index += 4;
107 return true;
109 </script>
110 </head>
111 <body>
112 <canvas id="testbed" width="2px" height="2px"></canvas>
113 <div id="description"></div>
114 <div id="console"></div>
115 <script>
116 description('Verify GL_VERTEX_PROGRAM_POINT_SIZE is enabled in WebGL');
118 if (runTest())
119 testPassed("");
120 </script>
123 </body>
124 </html>