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">
7 attribute vec4 colorIn;
8 uniform float pointSize;
13 gl_PointSize = pointSize;
15 gl_Position = vec4(pos.xyz,
3.0);
19 <script id=
"fshader" type=
"x-shader/x-fragment">
21 precision mediump float;
34 var gl
= initWebGL('testbed', 'vshader', 'fshader', ['pos', 'colorIn'], [0, 0, 0, 1], 1, { antialias
: false });
36 testFailed('initWebGL(..) failed');
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([
47 var colors
= new Uint8Array([
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
);
72 for (var y
= 0; y
< 2; ++y
) {
73 for (var x
= 0; x
< 2; ++x
) {
74 var correctColor
= [0, 0, 0];
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');
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)
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
);
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');
112 <canvas id=
"testbed" width=
"2px" height=
"2px"></canvas>
113 <div id=
"description"></div>
114 <div id=
"console"></div>
116 description('Verify GL_VERTEX_PROGRAM_POINT_SIZE is enabled in WebGL');