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.
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>
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;
26 gl_Position = vPosition;
31 <script id=
"fshader" type=
"x-shader/x-fragment">
32 precision mediump float;
33 uniform samplerCube tex;
34 varying vec2 texCoord;
37 gl_FragColor = textureCube(tex, normalize(vec3(texCoord,
1)));
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.');
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
) {
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");
76 gl
.TEXTURE_2D
, 0, gl
.RGBA
, testSize
, 1, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
,
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
);
85 gl
.TEXTURE_2D
, 0, gl
.RGBA
, 1, testSize
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
,
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;
104 <script src=
"../../js/js-test-post.js"></script>