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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « conformance/glsl/variables/gl-frontfacing.html ('k') | conformance/limits/00_test_list.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: conformance/glsl/variables/gl-pointcoord.html
===================================================================
--- conformance/glsl/variables/gl-pointcoord.html (revision 0)
+++ conformance/glsl/variables/gl-pointcoord.html (revision 0)
@@ -0,0 +1,141 @@
+<!--
+Copyright (c) 2011 The Chromium Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+ -->
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+ <title>gl-pointcoord Test</title>
+ <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
+ <script src="../../../resources/js-test-pre.js"></script>
+ <script src="../../resources/webgl-test.js"> </script>
+ <script src="../../resources/webgl-test-utils.js"> </script>
+</head>
+<body>
+<canvas id="example" width="256" height="256">
+</canvas>
+<div id="description"></div>
+<div id="console"></div>
+ <script id="vshader" type="x-shader/x-vertex">
+ attribute vec4 vPosition;
+ uniform float uPointSize;
+ void main()
+ {
+ gl_PointSize = uPointSize;
+ gl_Position = vPosition;
+ }
+ </script>
+
+ <script id="fshader" type="x-shader/x-fragment">
+ precision mediump float;
+ void main()
+ {
+ gl_FragColor = vec4(
+ gl_PointCoord.x,
+ gl_PointCoord.y,
+ 0,
+ 1);
+ }
+ </script>
+
+ <script>
+ function init()
+ {
+ if (window.initNonKhronosFramework) {
+ window.initNonKhronosFramework(false);
+ }
+
+ description("Checks gl_PointCoord and gl_PointSize");
+ debug("");
+
+ // NOTE: I'm not 100% confident in this test. I think it is correct.
+
+ wtu = WebGLTestUtils;
+ gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
+
+ canvas = gl.canvas;
+ width = canvas.width;
+ height = canvas.height;
+ shouldBeTrue("width == height");
+
+ maxPointSize = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE)[1];
+ shouldBeTrue("maxPointSize >= 1");
+ shouldBeTrue("maxPointSize % 1 == 0");
+
+ maxPointSize = Math.min(maxPointSize, 64);
+ pointWidth = maxPointSize / width;
+ pointStep = Math.floor(maxPointSize / 4);
+ pointStep = Math.max(1, pointStep);
+
+ program = gl.program;
+ pointSizeLoc = gl.getUniformLocation(program, "uPointSize");
+ gl.uniform1f(pointSizeLoc, maxPointSize);
+
+ var pixelOffset = (maxPointSize % 2) ? (1 / width) : 0;
+ var vertexObject = gl.createBuffer();
+ gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
+ gl.bufferData(
+ gl.ARRAY_BUFFER,
+ new Float32Array(
+ [-0.5 + pixelOffset, -0.5 + pixelOffset,
+ 0.5 + pixelOffset, -0.5 + pixelOffset,
+ -0.5 + pixelOffset, 0.5 + pixelOffset,
+ 0.5 + pixelOffset, 0.5 + pixelOffset]),
+ gl.STATIC_DRAW);
+ gl.enableVertexAttribArray(0);
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
+
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ gl.drawArrays(gl.POINTS, 0, 4);
+ function s2p(s) {
+ return (s + 1.0) * 0.5 * width;
+ }
+
+ //function print(x, y) {
+ // var b = new Uint8Array(4);
+ // gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, b);
+ // debug("" + x + "," + y + ": " + b[0] + "," + b[1] + "," + b[2]);
+ //}
+ //
+ //for (var ii = 0; ii < 100; ++ii) {
+ // print(ii, ii);
+ //}
+
+ for (var py = 0; py < 2; ++py) {
+ for (var px = 0; px < 2; ++px) {
+ debug("");
+ var pointX = -0.5 + px + pixelOffset;
+ var pointY = -0.5 + py + pixelOffset;
+ for (var yy = 0; yy < maxPointSize; yy += pointStep) {
+ for (var xx = 0; xx < maxPointSize; xx += pointStep) {
+ // formula for s and t from OpenGL ES 2.0 spec section 3.3
+ var xw = s2p(pointX);
+ var yw = s2p(pointY);
+ //debug("xw: " + xw + " yw: " + yw);
+ var u = xx / maxPointSize * 2 - 1;
+ var v = yy / maxPointSize * 2 - 1;
+ var xf = Math.floor(s2p(pointX + u * pointWidth));
+ var yf = Math.floor(s2p(pointY + v * pointWidth));
+ //debug("xf: " + xf + " yf: " + yf);
+ var s = 0.5 + (xf + 0.5 - xw) / maxPointSize;
+ var t = 0.5 + (yf + 0.5 - yw) / maxPointSize;
+ //debug("s: " + s + " t: " + t);
+ var color = [Math.floor(s * 255), Math.floor((1 - t) * 255), 0];
+ var msg = "pixel " + xf + "," + yf + " should be " + color;
+ wtu.checkCanvasRect(gl, xf, yf, 1, 1, color, msg, 4);
+ }
+ }
+ }
+ }
+ }
+
+ init();
+ successfullyParsed = true;
+ </script>
+<script src="../../../resources/js-test-post.js"></script>
+
+</body>
+</html>
Property changes on: conformance/glsl/variables/gl-pointcoord.html
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
« 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