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

Side by Side Diff: conformance/glsl/variables/gl-pointcoord.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/glsl/variables/gl-frontfacing.html ('k') | conformance/limits/00_test_list.txt » ('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:executable
+ *
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 <title>gl-pointcoord Test</title>
11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
12 <script src="../../../resources/js-test-pre.js"></script>
13 <script src="../../resources/webgl-test.js"> </script>
14 <script src="../../resources/webgl-test-utils.js"> </script>
15 </head>
16 <body>
17 <canvas id="example" width="256" height="256">
18 </canvas>
19 <div id="description"></div>
20 <div id="console"></div>
21 <script id="vshader" type="x-shader/x-vertex">
22 attribute vec4 vPosition;
23 uniform float uPointSize;
24 void main()
25 {
26 gl_PointSize = uPointSize;
27 gl_Position = vPosition;
28 }
29 </script>
30
31 <script id="fshader" type="x-shader/x-fragment">
32 precision mediump float;
33 void main()
34 {
35 gl_FragColor = vec4(
36 gl_PointCoord.x,
37 gl_PointCoord.y,
38 0,
39 1);
40 }
41 </script>
42
43 <script>
44 function init()
45 {
46 if (window.initNonKhronosFramework) {
47 window.initNonKhronosFramework(false);
48 }
49
50 description("Checks gl_PointCoord and gl_PointSize");
51 debug("");
52
53 // NOTE: I'm not 100% confident in this test. I think it is correct.
54
55 wtu = WebGLTestUtils;
56 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
57
58 canvas = gl.canvas;
59 width = canvas.width;
60 height = canvas.height;
61 shouldBeTrue("width == height");
62
63 maxPointSize = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE)[1];
64 shouldBeTrue("maxPointSize >= 1");
65 shouldBeTrue("maxPointSize % 1 == 0");
66
67 maxPointSize = Math.min(maxPointSize, 64);
68 pointWidth = maxPointSize / width;
69 pointStep = Math.floor(maxPointSize / 4);
70 pointStep = Math.max(1, pointStep);
71
72 program = gl.program;
73 pointSizeLoc = gl.getUniformLocation(program, "uPointSize");
74 gl.uniform1f(pointSizeLoc, maxPointSize);
75
76 var pixelOffset = (maxPointSize % 2) ? (1 / width) : 0;
77 var vertexObject = gl.createBuffer();
78 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
79 gl.bufferData(
80 gl.ARRAY_BUFFER,
81 new Float32Array(
82 [-0.5 + pixelOffset, -0.5 + pixelOffset,
83 0.5 + pixelOffset, -0.5 + pixelOffset,
84 -0.5 + pixelOffset, 0.5 + pixelOffset,
85 0.5 + pixelOffset, 0.5 + pixelOffset]),
86 gl.STATIC_DRAW);
87 gl.enableVertexAttribArray(0);
88 gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
89
90 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
91
92 gl.drawArrays(gl.POINTS, 0, 4);
93 function s2p(s) {
94 return (s + 1.0) * 0.5 * width;
95 }
96
97 //function print(x, y) {
98 // var b = new Uint8Array(4);
99 // gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, b);
100 // debug("" + x + "," + y + ": " + b[0] + "," + b[1] + "," + b[2]);
101 //}
102 //
103 //for (var ii = 0; ii < 100; ++ii) {
104 // print(ii, ii);
105 //}
106
107 for (var py = 0; py < 2; ++py) {
108 for (var px = 0; px < 2; ++px) {
109 debug("");
110 var pointX = -0.5 + px + pixelOffset;
111 var pointY = -0.5 + py + pixelOffset;
112 for (var yy = 0; yy < maxPointSize; yy += pointStep) {
113 for (var xx = 0; xx < maxPointSize; xx += pointStep) {
114 // formula for s and t from OpenGL ES 2.0 spec section 3.3
115 var xw = s2p(pointX);
116 var yw = s2p(pointY);
117 //debug("xw: " + xw + " yw: " + yw);
118 var u = xx / maxPointSize * 2 - 1;
119 var v = yy / maxPointSize * 2 - 1;
120 var xf = Math.floor(s2p(pointX + u * pointWidth));
121 var yf = Math.floor(s2p(pointY + v * pointWidth));
122 //debug("xf: " + xf + " yf: " + yf);
123 var s = 0.5 + (xf + 0.5 - xw) / maxPointSize;
124 var t = 0.5 + (yf + 0.5 - yw) / maxPointSize;
125 //debug("s: " + s + " t: " + t);
126 var color = [Math.floor(s * 255), Math.floor((1 - t) * 255), 0];
127 var msg = "pixel " + xf + "," + yf + " should be " + color;
128 wtu.checkCanvasRect(gl, xf, yf, 1, 1, color, msg, 4);
129 }
130 }
131 }
132 }
133 }
134
135 init();
136 successfullyParsed = true;
137 </script>
138 <script src="../../../resources/js-test-post.js"></script>
139
140 </body>
141 </html>
OLDNEW
« no previous file with comments | « conformance/glsl/variables/gl-frontfacing.html ('k') | conformance/limits/00_test_list.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698