Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / limits / gl-max-texture-dimensions.html
bloba9c585022511700855b2d893c09378403462a227
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL the max advertized texture size is supported.</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"> </script>
15 </head>
16 <body>
17 <canvas id="example" width="4" height="4" style="width: 40px; height: 30px;"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script id="vshader" type="x-shader/x-vertex">
21 attribute vec4 vPosition;
22 attribute vec2 texCoord0;
23 varying vec2 texCoord;
24 void main()
26 gl_Position = vPosition;
27 texCoord = texCoord0;
29 </script>
31 <script id="fshader" type="x-shader/x-fragment">
32 precision mediump float;
33 uniform samplerCube tex;
34 varying vec2 texCoord;
35 void main()
37 gl_FragColor = textureCube(tex, normalize(vec3(texCoord, 1)));
39 </script>
40 <script>
41 "use strict";
42 description(document.title);
43 var wtu = WebGLTestUtils;
44 var gl = wtu.create3DContext("example");
45 var program = wtu.setupTexturedQuad(gl);
47 function shouldBePowerOfTwo(n, name) {
48 var power = Math.round(Math.log(n) / Math.log(2));
49 if (Math.pow(2, power) == n) {
50 testPassed(name + ' is a power of two.');
51 } else {
52 testFailed(name + ' should be a power of two, but was ' + n);
56 // Note: It seems like a reasonable assuption that a 1xN texture size should
57 // work. Even 1 by 128k is only 512k
58 var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
59 debug("advertised max size: " + maxSize);
60 debug("verifying max size is power-of-two (implied by GLES 2.0 section 3.7.1)");
61 shouldBePowerOfTwo(maxSize, 'Max size');
62 var testSize = Math.min(maxSize, 128 * 1024);
63 var pixels = new Uint8Array(testSize * 4);
64 for (var ii = 0; ii < testSize; ++ii) {
65 var off = ii * 4;
66 pixels[off + 0] = 0;
67 pixels[off + 1] = 255;
68 pixels[off + 2] = 128;
69 pixels[off + 3] = 255;
71 var tex = gl.createTexture();
72 gl.bindTexture(gl.TEXTURE_2D, tex);
74 debug("test " + testSize + "x1");
75 gl.texImage2D(
76 gl.TEXTURE_2D, 0, gl.RGBA, testSize, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
77 pixels);
78 gl.generateMipmap(gl.TEXTURE_2D);
80 wtu.clearAndDrawUnitQuad(gl);
81 wtu.checkCanvas(gl, [0, 255, 128, 255],
82 "Should be 0, 255, 128, 255");
83 debug("test 1x" + testSize);
84 gl.texImage2D(
85 gl.TEXTURE_2D, 0, gl.RGBA, 1, testSize, 0, gl.RGBA, gl.UNSIGNED_BYTE,
86 pixels);
87 gl.generateMipmap(gl.TEXTURE_2D);
89 wtu.clearAndDrawUnitQuad(gl);
90 wtu.checkCanvas(gl, [0, 255, 128, 255],
91 "Should be 0, 255, 128, 255");
93 var program = wtu.setupProgram(
94 gl, ['vshader', 'fshader'], ['vPosition', 'texCoord0'], [0, 1]);
96 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
98 // NOTE: We can't easily test cube maps because they require width == height
99 // and we might not have enough memory for maxSize by maxSize texture.
101 var successfullyParsed = true;
103 </script>
104 <script src="../../js/js-test-post.js"></script>
106 </body>
107 </html>