Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: conformance/rendering/point-size.html

Issue 8342021: Add webgl conformance tests r15841. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « conformance/rendering/more-than-65536-indices.html ('k') | conformance/rendering/triangle.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 <!--
2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style license that can be
4 found in the LICENSE file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
11 <script src="../../resources/js-test-pre.js"></script>
12 <script src="../resources/webgl-test.js"></script>
13 <script id="vshader" type="x-shader/x-vertex">
14 attribute vec3 pos;
15 attribute vec4 colorIn;
16 uniform float pointSize;
17 varying vec4 color;
18
19 void main()
20 {
21 gl_PointSize = pointSize;
22 color = colorIn;
23 gl_Position = vec4(pos.xyz, 3.0);
24 }
25 </script>
26
27 <script id="fshader" type="x-shader/x-fragment">
28 precision mediump float;
29 varying vec4 color;
30
31 void main()
32 {
33 gl_FragColor = color;
34 }
35 </script>
36
37 <script>
38 function runTest()
39 {
40 var gl = initWebGL('testbed', 'vshader', 'fshader', ['pos', 'colorIn'], [0, 0, 0, 1], 1, { antialias: false });
41 if (!gl) {
42 testFailed('initWebGL(..) failed');
43 return false;
44 }
45 gl.disable(gl.BLEND);
46 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
47
48 // The choice of (0.4, 0.4) ensures that the centers of the surrounding
49 // pixels are not contained within the point when it is of size 1, but
50 // that they definitely are when it is of size 2.
51 var vertices = new Float32Array([
52 0.4, 0.4, 0.0]);
53 var colors = new Uint8Array([
54 255, 0, 0, 255]);
55
56 var colorOffset = vertices.byteLength;
57
58 var vbo = gl.createBuffer();
59 gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
60 gl.bufferData(gl.ARRAY_BUFFER, colorOffset + colors.byteLength, gl.STATIC_DR AW);
61 gl.bufferSubData(gl.ARRAY_BUFFER, 0, vertices);
62 gl.bufferSubData(gl.ARRAY_BUFFER, colorOffset, colors);
63
64 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
65 gl.enableVertexAttribArray(0);
66 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, colorOffset);
67 gl.enableVertexAttribArray(1);
68
69 var locPointSize = gl.getUniformLocation(gl.program, 'pointSize');
70
71 debug('Draw a point of size 1 and verify it does not touch any other pixels. ');
72
73 gl.uniform1f(locPointSize, 1.0);
74 gl.drawArrays(gl.POINTS, 0, vertices.length / 3);
75 var buf = new Uint8Array(2 * 2 * 4);
76 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
77 var index = 0;
78 for (var y = 0; y < 2; ++y) {
79 for (var x = 0; x < 2; ++x) {
80 var correctColor = [0, 0, 0];
81 if (x == 1 && y == 1)
82 correctColor[0] = 255;
83 if (buf[index] != correctColor[0] || buf[index + 1] != correctColor[ 1] || buf[index + 2] != correctColor[2]) {
84 testFailed('Drawing a point of size 1 touched pixels that should not be touched');
85 return false;
86 }
87 index += 4;
88 }
89 }
90 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
91
92 debug('Draw a point of size 2 and verify it fills the appropriate region.');
93
94 var pointSizeRange = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
95 if (pointSizeRange < 2.0)
96 return true;
97
98 gl.uniform1f(locPointSize, 2.0);
99 gl.drawArrays(gl.POINTS, 0, vertices.length / 3);
100 gl.readPixels(0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, buf);
101 index = 0;
102 for (var y = 0; y < 2; ++y) {
103 for (var x = 0; x < 2; ++x) {
104 var correctColor = [255, 0, 0];
105 if (buf[index] != correctColor[0] || buf[index + 1] != correctColor[ 1] || buf[index + 2] != correctColor[2]) {
106 testFailed('Drawing a point of size 2 failed to fill the appropr iate region');
107 return false;
108 }
109 index += 4;
110 }
111 }
112
113 return true;
114 }
115 </script>
116 </head>
117 <body>
118 <canvas id="testbed" width="2px" height="2px"></canvas>
119 <div id="description"></div>
120 <div id="console"></div>
121 <script>
122 description('Verify GL_VERTEX_PROGRAM_POINT_SIZE is enabled in WebGL');
123
124 if (runTest())
125 testPassed("");
126
127 successfullyParsed = true;
128 </script>
129
130 <script src="../../resources/js-test-post.js"></script>
131
132 </body>
133 </html>
OLDNEW
« no previous file with comments | « conformance/rendering/more-than-65536-indices.html ('k') | conformance/rendering/triangle.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698