OLD | NEW |
| (Empty) |
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; | |
10 | |
11 void main() | |
12 { | |
13 gl_PointSize = pointSize; | |
14 color = colorIn; | |
15 gl_Position = vec4(pos.xyz, 3.0); | |
16 } | |
17 </script> | |
18 | |
19 <script id="fshader" type="x-shader/x-fragment"> | |
20 #ifdef GL_ES | |
21 precision mediump float; | |
22 #endif | |
23 varying vec4 color; | |
24 | |
25 void main() | |
26 { | |
27 gl_FragColor = color; | |
28 } | |
29 </script> | |
30 | |
31 <script> | |
32 function runTest() | |
33 { | |
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; | |
38 } | |
39 gl.disable(gl.BLEND); | |
40 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
41 | |
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]); | |
49 | |
50 var colorOffset = vertices.byteLength; | |
51 | |
52 var vbo = gl.createBuffer(); | |
53 gl.bindBuffer(gl.ARRAY_BUFFER, vbo); | |
54 gl.bufferData(gl.ARRAY_BUFFER, colorOffset + colors.byteLength, gl.STATIC_DR
AW); | |
55 gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices); | |
56 gl.bufferSubData(gl.ARRAY_BUFFER, colorOffset, colors); | |
57 | |
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); | |
62 | |
63 var locPointSize = gl.getUniformLocation(gl.program, 'pointSize'); | |
64 | |
65 debug('Draw a point of size 1 and verify it does not touch any other pixels.
'); | |
66 | |
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; | |
80 } | |
81 index += 4; | |
82 } | |
83 } | |
84 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
85 | |
86 debug('Draw a point of size 2 and verify it fills the appropriate region.'); | |
87 | |
88 var pointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE); | |
89 if (pointSizeRange < 2.0) | |
90 return true; | |
91 | |
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 appropr
iate region'); | |
101 return false; | |
102 } | |
103 index += 4; | |
104 } | |
105 } | |
106 | |
107 return true; | |
108 } | |
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'); | |
117 | |
118 if (runTest()) | |
119 testPassed(""); | |
120 </script> | |
121 | |
122 | |
123 </body> | |
124 </html> | |
OLD | NEW |