Bug 1268096 - Add regression test for tri-then-point drawing. - r=jrmuizel a=kwierso
☠☠ backed out by e58f50a265a1 ☠ ☠
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 19 May 2016 13:02:34 -0700
changeset 369239 7502d9ef870f1d86f5819177324cb623e741f0f3
parent 369237 30b83fcb0009b524cf3982a8aeb2bc0fc6d2d5b7
child 369240 66e13bb5f4c0f8437a280b9d603daadea89dba6c
push id18807
push userdholbert@mozilla.com
push dateFri, 20 May 2016 22:18:21 +0000
reviewersjrmuizel, kwierso
bugs1268096
milestone49.0a1
Bug 1268096 - Add regression test for tri-then-point drawing. - r=jrmuizel a=kwierso
dom/canvas/moz.build
dom/canvas/test/webgl-mochitest/mochitest.ini
dom/canvas/test/webgl-mochitest/regress/test_bug_1268096.html
--- a/dom/canvas/moz.build
+++ b/dom/canvas/moz.build
@@ -1,18 +1,18 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 TEST_DIRS += ['compiledtest']
 
-# Change the following line to avoid bug 1081323 (clobber after changing a manifest):
-# Add test for webglcontextcreationerror.
+# Change the following line(s) to avoid bug 1081323 (clobber after changing a manifest):
+# * Add a regression test for triangle-then-point rendering.
 
 MOCHITEST_MANIFESTS += [
     'test/crash/mochitest.ini',
     'test/crossorigin/mochitest.ini',
     'test/mochitest.ini',
     'test/webgl-conf/generated-mochitest.ini',
     'test/webgl-mochitest/mochitest.ini',
 ]
--- a/dom/canvas/test/webgl-mochitest/mochitest.ini
+++ b/dom/canvas/test/webgl-mochitest/mochitest.ini
@@ -41,16 +41,19 @@ fail-if = (os == 'android') || (os == 'l
 [ensure-exts/test_WEBGL_depth_texture.html]
 fail-if = (os == 'mac' && os_version == '10.6')
 [ensure-exts/test_WEBGL_draw_buffers.html]
 fail-if = (os == 'android') || (os == 'win' && os_version == '5.1')
 
 [ensure-exts/test_common.html]
 
 
+[regress/test_bug_1268096.html]
+
+
 [test_backends.html]
 [test_backbuffer_channels.html]
 fail-if = (os == 'b2g')
 [test_depth_readpixels.html]
 [test_capture.html]
 support-files = ../captureStream_common.js
 # Even though we use ../ here, in the test HTML, we need to omit this. Sub-CWD relative
 # paths are fine, but they locate the file and dump it in the current directory.
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-mochitest/regress/test_bug_1268096.html
@@ -0,0 +1,140 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <meta charset='UTF-8'/>
+    <script src='/tests/SimpleTest/SimpleTest.js'></script>
+    <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
+    <script src='webgl-util.js'></script>
+    <script id='vs' type='x-shader/x-vertex'>
+
+attribute vec2 aPosition;
+
+void main(void) {
+  gl_PointSize = 16.0;
+  gl_Position = vec4(aPosition, 0, 1);
+}
+
+    </script>
+    <script id='fs' type='x-shader/x-fragment'>
+
+precision mediump float;
+
+uniform vec4 uColor;
+
+void main(void) {
+  gl_FragColor = uColor;
+}
+
+    </script>
+  </head>
+  <body>
+    <script>
+
+function GetPixel(gl, x, y) {
+  var pixel = new Uint8Array(4);
+  gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
+  return pixel;
+}
+
+function ColorStr(arr) {
+  return '{' + arr.map(function(x) { return '' + x; }).join(', ') + '}';
+}
+
+function PixelShouldBe(gl, x, y, ref, prefix) {
+  if (prefix) {
+    prefix += ': ';
+  }
+
+  var test = GetPixel(gl, x, y);
+
+  var testStr = ColorStr(test);
+  var refStr = ColorStr(ref.map(x => x * 255));
+  ok(testStr == refStr, prefix + 'Should be ' + refStr + ', was ' + testStr + '.');
+}
+
+function GetProgram(gl) {
+  var prog = WebGLUtil.createProgramByIds(gl, 'vs', 'fs');
+
+  prog.aPosition = gl.getAttribLocation(prog, 'aPosition');
+  ok(prog.aPosition >= 0, '`aPosition` should be valid.');
+
+  prog.uColor = gl.getUniformLocation(prog, 'uColor');
+  ok(prog.uColor, '`uColor` should be valid.');
+
+  return prog;
+}
+
+// Give ourselves a scope to return early from:
+(function () {
+  var c = document.createElement('canvas');
+  document.body.appendChild(c);
+  var gl = c.getContext('webgl', { depth: false, antialias: false });
+  if (!gl) {
+    todo(false, 'WebGL is unavailable.');
+    return;
+  }
+
+  ////////
+
+  // With default culling, it works fine.
+  // The problem seems to be that the virtual quads generated from points are wound 'backwards'.
+  gl.enable(gl.CULL_FACE);
+  gl.cullFace(gl.BACK); // Cull back faces.
+
+  ////////
+
+  var vertArr = new Float32Array([
+    -1, -1,
+    +1, -1,
+    -1, +1,
+  ]);
+
+  var vbo = gl.createBuffer();
+  gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
+  gl.bufferData(gl.ARRAY_BUFFER, vertArr, gl.STATIC_DRAW);
+
+  ////////
+
+  var triProg = GetProgram(gl);
+  var pointProg = GetProgram(gl);
+  if (!triProg || !pointProg) {
+    ok(false, 'Program linking should succeed.');
+    return;
+  }
+
+  ok(triProg.aPosition == pointProg.aPosition, 'aPosition should match.');
+  gl.enableVertexAttribArray(triProg.aPosition);
+  gl.vertexAttribPointer(triProg.aPosition, 2, gl.FLOAT, false, 0, 0);
+
+  ////////
+
+  gl.useProgram(triProg);
+  var triColor = [1, 0, 0, 1];
+  gl.uniform4fv(triProg.uColor, triColor);
+
+  gl.useProgram(pointProg);
+  var pointColor = [0, 1, 0, 1];
+  gl.uniform4fv(pointProg.uColor, pointColor);
+
+  ////////
+
+  gl.clearColor(0, 0, 0, 1);
+  gl.clear(gl.COLOR_BUFFER_BIT);
+
+  gl.useProgram(triProg);
+  gl.drawArrays(gl.TRIANGLES, 0, 3);
+
+  gl.useProgram(pointProg);
+  gl.drawArrays(gl.POINTS, 0, 3);
+
+  ////////
+
+  PixelShouldBe(gl, 32, 32, triColor, 'Tri');
+  PixelShouldBe(gl, 0, 0, pointColor, 'Point');
+
+  ok(true, 'Test complete');
+})();
+
+    </script>
+  </body>
+</html>