Bug 1287682 - Add test case for CopyTexImage2D with legacy format, r?mtseng draft
authorpeter chang <pchang@mozilla.com>
Thu, 04 Aug 2016 17:22:59 +0800
changeset 397087 cd71de81850c52e8cfac5431f63d4c64575cfe26
parent 396719 c3dc332642f377a81756538ad29a0036df2dee6d
child 397088 27282d020265f4d3512e8ab98b4d2ae8a4f14d21
push id25201
push userbmo:howareyou322@gmail.com
push dateFri, 05 Aug 2016 06:28:23 +0000
reviewersmtseng
bugs1287682
milestone51.0a1
Bug 1287682 - Add test case for CopyTexImage2D with legacy format, r?mtseng MozReview-Commit-ID: 1eYTIT6RO3U
dom/canvas/test/webgl-mochitest/mochitest.ini
dom/canvas/test/webgl-mochitest/test_webgl2_copyteximage2d_with_legacy_format.html
--- a/dom/canvas/test/webgl-mochitest/mochitest.ini
+++ b/dom/canvas/test/webgl-mochitest/mochitest.ini
@@ -90,10 +90,12 @@ skip-if = toolkit == 'android' #bug 8654
 [test_webgl_request_mismatch.html]
 skip-if = toolkit == 'android' #bug 865443- seperate suite - the non_conf* tests pass except for one on armv6 tests
 [test_webgl2_not_exposed.html]
 skip-if = toolkit == 'android' #bug 865443- seperate suite - the non_conf* tests pass except for one on armv6 tests
 [test_webgl2_invalidate_framebuffer.html]
 skip-if = toolkit == 'android' #bug 865443- seperate suite - the non_conf* tests pass except for one on armv6 tests
 [test_webgl2_alpha_luminance.html]
 skip-if = toolkit == 'android' #bug 865443- seperate suite - the non_conf* tests pass except for one on armv6 tests
+[test_webgl2_copyteximage2d_with_legacy_format.html]
+skip-if = toolkit == 'android' #bug 865443- seperate suite - the non_conf* tests pass except for one on armv6 tests
 [test_fuzzing_bugs.html]
 [test_webglcontextcreationerror.html]
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-mochitest/test_webgl2_copyteximage2d_with_legacy_format.html
@@ -0,0 +1,125 @@
+<!DOCTYPE HTML>
+<meta http-equiv="content-type" content="text/html; charset=utf-8" />
+<title>WebGL2 test: Alpha and Luminance Textures</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+<script src="driver-info.js"></script>
+<script src="webgl-util.js"></script>
+<script id="vs" type="x-shader/x-vertex"
+>#version 300 es
+
+in vec2 aTexCoord;
+out vec2 vTexCoord;
+
+void main() {
+  vec2 pos = vec2(2.0)*aTexCoord - vec2(1.0);
+  gl_Position = vec4(pos, 0.0, 1.0);
+  vTexCoord = aTexCoord;
+}
+</script>
+<script id="fs" type="x-shader/x-fragment"
+>#version 300 es
+precision mediump float;
+
+in vec2 vTexCoord;
+uniform sampler2D uTex;
+out vec4 oFragColor;
+
+void main() {
+  oFragColor = texture(uTex, vTexCoord);
+}
+</script>
+<body>
+<canvas id="c" width="32" height="32"></canvas>
+<script>
+  WebGLUtil.withWebGL2('c', function(gl) {
+
+    function testPixel(x, y, refData, infoPrefix) {
+      var pixel = new Uint8Array(4);
+      gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixel);
+
+      var pixelMatches = (pixel[0] == refData[0] &&
+                          pixel[1] == refData[1] &&
+                          pixel[2] == refData[2] &&
+                          pixel[3] == refData[3]);
+      var expectedStr = '[' + refData.join(', ') + ']';
+      var actualStr   = '[' +   pixel.join(', ') + ']';
+
+      if (pixelMatches) {
+        ok(true, infoPrefix + 'Expected ' + expectedStr + '.');
+      } else {
+        ok(false, infoPrefix + 'Expected ' + expectedStr + ', was ' + actualStr + '.');
+      }
+    }
+
+    function testTexture(details, prog) {
+      prog.aTexCoord = gl.getAttribLocation(prog, "aTexCoord");
+      ok(prog.aTexCoord >= 0, '`aTexCoord` should be valid.');
+
+      var tex = gl.createTexture();
+      gl.bindTexture(gl.TEXTURE_2D, tex);
+      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0,
+                    gl.RGBA, gl.UNSIGNED_BYTE, null);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+
+
+
+      // Create a framebuffer and attach the texture.
+      var fb = gl.createFramebuffer();
+      gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
+      gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
+
+      gl.clearColor(1, 0, 0, 1);
+      gl.clear(gl.COLOR_BUFFER_BIT);
+
+      var dstTex = gl.createTexture();
+      gl.bindTexture(gl.TEXTURE_2D, dstTex);
+      gl.copyTexImage2D(gl.TEXTURE_2D, 0, details.format, 0, 0, 1, 1, 0);
+
+      gl.bindFramebuffer(gl.FRAMEBUFFER, null);
+      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
+
+      testPixel(0, 0, details.result, details.info + ': ');
+
+      gl.deleteFramebuffer(fb);
+      return true;
+    }
+
+    var prog = WebGLUtil.createProgramByIds(gl, 'vs', 'fs');
+    if (!prog) {
+      ok(false, 'Program linking should succeed.');
+      return false;
+    }
+
+    gl.disable(gl.DEPTH_TEST);
+
+    var vertData = gl.createBuffer();
+    gl.bindBuffer(gl.ARRAY_BUFFER, vertData);
+    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0, 0, 1, 0, 0, 1, 1, 1 ]), gl.STATIC_DRAW);
+
+    gl.useProgram(prog);
+    gl.vertexAttribPointer(prog.aTexCoord, 2, gl.FLOAT, false, 0, 0);
+    gl.enableVertexAttribArray(prog.aTexCoord);
+
+    var details = [
+      { info: 'Luminance8', format: gl.LUMINANCE, result: [255, 255, 255, 255] },
+      { info: 'Alpha8', format: gl.ALPHA, result: [0, 0, 0, 255] },
+      { info: 'Luminance8Alpha8', format: gl.LUMINANCE_ALPHA, result: [255, 255, 255, 255] },
+    ];
+
+    for (var i = 0; i < details.length; i++) {
+      if (!testTexture(details[i], prog)) {
+        return;
+      }
+    }
+
+    ok(true, 'Test complete.');
+  }, function() {
+    SimpleTest.finish();
+  });
+
+  SimpleTest.waitForExplicitFinish();
+</script>