Bug 1426289 - Add test for vertexAttrib4f updates.
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 19 Dec 2017 22:54:41 -0800
changeset 396975 b22b826e89dcee1f63042b02e463933b568e93da
parent 396974 fb576536eafbc397e9dfccc49412bab4f078ce31
child 396976 a235bf4868ab9e48c7b2f4bf4cc9bd949ca23c35
child 396995 bba778f860d2a86dc3fb0fbd0d0d2576cdf06cd0
push id33117
push userebalazs@mozilla.com
push dateWed, 20 Dec 2017 09:47:43 +0000
treeherdermozilla-central@a235bf4868ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1426289
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1426289 - Add test for vertexAttrib4f updates. MozReview-Commit-ID: E2BqeuyafUg
dom/canvas/test/webgl-mochitest/mochitest.ini
dom/canvas/test/webgl-mochitest/test_vertexattrib4f_update.html
dom/canvas/test/webgl-mochitest/webgl-util.js
--- a/dom/canvas/test/webgl-mochitest/mochitest.ini
+++ b/dom/canvas/test/webgl-mochitest/mochitest.ini
@@ -104,8 +104,9 @@ skip-if = toolkit == 'android' #bug 8654
 [test_video_fastpath_mp4.html]
 [test_video_fastpath_theora.html]
 [test_video_fastpath_vp8.html]
 [test_video_fastpath_vp9.html]
 [test_webglcontextcreationerror.html]
 [test_webgl_fingerprinting_resistance.html]
 fail-if = (os == 'mac') # on try server, LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE = 512 on mac
 [test_without_index_validation.html]
+[test_vertexattrib4f_update.html]
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-mochitest/test_vertexattrib4f_update.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset='utf-8'>
+    <title>Bug 1426289 - vertexAttrib4f should actually update.</title>
+    <script src='/tests/SimpleTest/SimpleTest.js'></script>
+    <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
+    <script src='webgl-util.js'></script>
+  </head>
+  <body>
+    <script id='eVertSource' type='none'>
+attribute vec4 aColor;
+varying vec4 vColor;
+
+void main() {
+  gl_PointSize = 64.0;
+  gl_Position = vec4(vec3(0.0), 1.0);
+  vColor = aColor;
+}
+    </script>
+    <script id='eFragSource' type='none'>
+precision mediump float;
+varying vec4 vColor;
+
+void main() {
+  gl_FragColor = vColor;
+}
+    </script>
+    <script>
+const canvas = document.createElement('canvas');
+canvas.width = 1;
+canvas.height = 1;
+const gl = canvas.getContext('webgl');
+
+const prog = WebGLUtil.linkProgramByIds(gl, eVertSource, eFragSource);
+gl.useProgram(prog);
+
+function getRgb() {
+  const data = new Uint32Array(1);
+  gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(data.buffer));
+  return data[0] & 0xffffff;
+}
+
+gl.clearColor(0.0, 0.0, 0.0, 1.0);
+gl.clear(gl.COLOR_BUFFER_BIT);
+let was = getRgb();
+ok(was == 0x000000, '0x'+was.toString(16));
+
+gl.disableVertexAttribArray(prog.aColor);
+
+gl.vertexAttrib4f(prog.aColor, 1, 0, 0, 1);
+gl.drawArrays(gl.POINTS, 0, 1);
+was = getRgb();
+ok(was == 0x0000ff, '0x'+was.toString(16));
+
+gl.vertexAttrib4f(prog.aColor, 0, 1, 0, 1);
+gl.drawArrays(gl.POINTS, 0, 1);
+was = getRgb();
+ok(was == 0x00ff00, '0x'+was.toString(16));
+    </script>
+  </body>
+</html>
--- a/dom/canvas/test/webgl-mochitest/webgl-util.js
+++ b/dom/canvas/test/webgl-mochitest/webgl-util.js
@@ -161,10 +161,49 @@ WebGLUtil = (function() {
   return {
     setErrorFunc: setErrorFunc,
     setWarningFunc: setWarningFunc,
 
     getWebGL: getWebGL,
     withWebGL2: withWebGL2,
     createShaderById: createShaderById,
     createProgramByIds: createProgramByIds,
+
+
+    linkProgramByIds: function(gl, vertSrcElem, fragSrcElem) {
+      const prog = gl.createProgram();
+
+      function attachShaderById(type, srcElem) {
+        const shader = gl.createShader(type);
+        gl.shaderSource(shader, srcElem.innerHTML.trim() + '\n');
+        gl.compileShader(shader);
+        gl.attachShader(prog, shader);
+        prog[type] = shader;
+      }
+      attachShaderById(gl.VERTEX_SHADER, vertSrcElem);
+      attachShaderById(gl.FRAGMENT_SHADER, fragSrcElem);
+
+      gl.linkProgram(prog);
+      const success = gl.getProgramParameter(prog, gl.LINK_STATUS);
+      if (!success) {
+        console.error('Error linking program:');
+        console.error('\nLink log: ' + gl.getProgramInfoLog(prog));
+        console.error('\nVert shader log: ' + gl.getShaderInfoLog(prog[gl.VERTEX_SHADER]));
+        console.error('\nFrag shader log: ' + gl.getShaderInfoLog(prog[gl.FRAGMENT_SHADER]));
+        return null;
+      }
+      gl.deleteShader(prog[gl.VERTEX_SHADER]);
+      gl.deleteShader(prog[gl.FRAGMENT_SHADER]);
+
+      let count = gl.getProgramParameter(prog, gl.ACTIVE_ATTRIBUTES);
+      for (let i = 0; i < count; i++) {
+        const info = gl.getActiveAttrib(prog, i);
+        prog[info.name] = gl.getAttribLocation(prog, info.name);
+      }
+      count = gl.getProgramParameter(prog, gl.ACTIVE_UNIFORMS);
+      for (let i = 0; i < count; i++) {
+        const info = gl.getActiveUniform(prog, i);
+        prog[info.name] = gl.getUniformLocation(prog, info.name);
+      }
+      return prog;
+    },
   };
 })();