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 HD-DPI issues texture conformance test.
</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>
23 var wtu
= WebGLTestUtils
;
24 var gl
= wtu
.create3DContext("example");
25 var program
= wtu
.setupTexturedQuad(gl
);
27 function fillInMips(gl
, size
) {
35 var numBytes
= size
* size
* 4;
36 var pixels
= new Uint8Array(numBytes
);
37 for (var jj
= 0; jj
< numBytes
; jj
+= 4) {
43 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, size
, size
, 0, gl
.RGBA
, gl
.UNSIGNED_BYTE
, pixels
);
47 function testCanvas(size
) {
49 debug("testing 2D canvas size " + size
+ ", " + size
);
51 var canvas
= document
.createElement("canvas");
54 var ctx
= canvas
.getContext("2d");
55 ctx
.fillStyle
= "rgb(0,255,0)";
56 ctx
.fillRect(0, 0, size
, size
);
58 var tex
= gl
.createTexture();
59 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
60 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas
);
64 // Draw. If this an HD-DPI device and the 2d canvas is double res or larger
65 // the implementation must scale to CSS pixels (ie, canvas.width, canvas.height)(
66 // when doing the copy in texImage2D. If it has not scaled and instead done
67 // a direct copy of the larger texture this test will not have created enough mips
68 // and will therefore not be "texture complete" and will render in black.
69 wtu
.clearAndDrawUnitQuad(gl
);
70 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "should be green");
73 function testWebGL(size
) {
75 debug("testing WebGL canvas size " + size
+ ", " + size
);
77 var canvas
= document
.createElement("canvas");
80 var gl2
= wtu
.create3DContext(canvas
);
81 gl2
.clearColor(0,1,0,1);
82 gl2
.clear(gl
.COLOR_BUFFER_BIT
);
84 var tex
= gl
.createTexture();
85 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
86 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas
);
90 // Draw. If this an HD-DPI device check for 2 possible bugs.
92 // 1) the WebGL canvas is double res or larger. That's just a bug period and
93 // is checked for in another test but would also fail here.
95 // 2) the WebGL canvas is single res but the code the scales a double res
96 // 2d canvas also mistakenly scales a single res WebGL canvas.
98 // If it has been scaled then we'll have the wrong kind of mips chain here.
99 // Level 0 will be half resolution. Level 1 will be the same resolution
100 // and will therefore not be "texture complete" and will render in black.
101 wtu
.clearAndDrawUnitQuad(gl
);
102 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "should be green");
109 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "Should be no errors");
111 var successfullyParsed
= true;
113 <script src=
"../../../js/js-test-post.js"></script>