summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-mochitest/test_tex_large_uploads.html
blob: c2fd554843fc694d9e991e812c838d90d9b3954d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML>
<html>
  <head>
    <meta charset='UTF-8'>
    <script src='/tests/SimpleTest/SimpleTest.js'></script>
    <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
  </head>
  <body>
    <img id='e_blank_15000x10000' src='blank_15000x10000.png'>
    <script>

function shouldBe(testStr, refStr) {
  ok(testStr == refStr, 'Expected "' + refStr + '", was "' + testStr + '".');
}

function getErrorStr(gl, err) {
  if (!err) return "NO_ERROR";
  for (const k in gl) {
    const v = gl[k];
    if (v == err) {
      return k;
    }
  }
  return `<${err}>`;
}

function glErrorShouldBe(gl, expected, opt_info) {
  if (opt_info) {
    opt_info = opt_info + ': '
  } else {
    opt_info = '';
  }

  if (!expected.length) {
    expected = [expected];
  }
  expected = expected.map(x => getErrorStr(gl, x));
  let was = gl.getError();
  was = getErrorStr(gl, was);
  ok(expected.includes(was),
    `${opt_info}Expected gl.getError() in [${expected}], was ${was}.`);
}
SimpleTest.waitForExplicitFinish();
(async () => {
  const gl = document.createElement('canvas').getContext('webgl2');
  window.gl = gl;
  if (!gl) {
    todo(false, 'No webgl2, skipping...');
    return;
  }
  const tex = gl.createTexture();
  gl.bindTexture(gl.TEXTURE_2D, tex);

  const TESTS = [
    //{w: 16000, h: 8000}, // TODO: This asserts.
    //{w: 8000, h: 16000}, // TODO: This asserts.
    {w: 8000, h: 4000},
    {w: 4000, h: 8000},
    {w: 4000, h: 4000},
  ];
  const src = document.createElement('canvas').getContext('webgl',
    {antialias:false, depth:false});
  const maxTexSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
  for (const t of TESTS) {
    ok(true, 'canvas: ' + JSON.stringify(t));
    if (t.w > maxTexSize || t.h > maxTexSize) {
      ok(true, `Larger than MAX_TEXTURE_SIZE of ${maxTexSize}`);
      continue;
    }
    src.canvas.width = t.w;
    src.canvas.height = t.h;
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE,
                  src.canvas);

    glErrorShouldBe(gl, [0, gl.OUT_OF_MEMORY], `after texImage(${JSON.stringify(t)})`);

    src.canvas.width = src.canvas.height = 1;
  }

  if (15000 > maxTexSize) {
    ok(true, `e_blank_15000x10000 larger than MAX_TEXTURE_SIZE of ${maxTexSize}, skipping.`);
  } else {
    await e_blank_15000x10000.decode(); // Otherwise it will not have loaded yet.
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE,
                  e_blank_15000x10000);
    glErrorShouldBe(gl, [0, gl.OUT_OF_MEMORY], `after texImage(e_blank_15000x10000)`);
    ok(!gl.isContextLost(), '!gl.isContextLost()');
  }

  SimpleTest.finish();
})();
    </script>
  </body>
</html>