summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/extra/texture-sizing.html
blob: 4cdcf64a1b0b977df7b5662307f9fc1b41242f9a (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!--

/*
** Copyright (c) 2015 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/

-->
<!DOCTYPE html>
<html>
<head>
<title>Testing resolution of texture uploads</title>
<style>

.result {
    margin-bottom: 20px;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: row;
    flex-direction: row;
}

.description, .element, .render, .log {
    border: 1px solid black;
    margin: 5px;
    width: 200px;
    height: 200px;
    max-width: 200px;
    max-height: 200px;
}

.render canvas {
    width: 200px;
    height: 200px;
}

p {
    margin: 0;
    padding: 5px 10px;
}
.viacss {
    width: 200px;
    height: 200px;
}
</style>
<script src="../js/webgl-test-utils.js"> </script>
<script>

var outOfPageSVG = new Image();
outOfPageSVG.src = "sample.svg";

function runTest() {
  var wtu = WebGLTestUtils;
  var results = document.querySelectorAll(".result");
  for (var i = 0; i < results.length; i++) {
    var result = results[i];
    var img = result.querySelector("img");
    if (result.classList.contains("out-of-page")) {
      img = outOfPageSVG;
    }
    if (result.classList.contains("set-dimensions")) {
      img.width = 200;
      img.height = 200;
    }
    var out = result.querySelector(".output");
    out.innerHTML = "img.width = " + img.width + "<br>img.height = " + img.height + "<br>img.naturalWidth = " + img.naturalWidth + "<br>img.naturalHeight = " + img.naturalHeight;

    var canvas = document.createElement("canvas");
    canvas.width = 200 * window.devicePixelRatio;
    canvas.height = 200 * window.devicePixelRatio;
    result.querySelector(".render").appendChild(canvas);
    var gl = wtu.create3DContext(canvas);
    gl.enable(gl.BLEND);
    gl.disable(gl.DEPTH_TEST);

    var program = wtu.setupSimpleTextureProgram(gl, 0, 1);
    var buffers = wtu.setupUnitQuad(gl, 0, 1);
    var tex = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex);
    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
    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);
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
    var loc = gl.getUniformLocation(program, "tex");
    gl.uniform1i(loc, 0);

    wtu.clearAndDrawUnitQuad(gl, [0, 255, 0, 255]);
  }
}

window.addEventListener("load", function () {
  runTest();
}, false);
</script>
</head>
<body>
<div class="result">
  <div class="description">
    <p>IMG to SVG with 200x200 attributes</p>
  </div>
  <div class="element">
    <img src="sample.svg" width="200" height="200">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result">
  <div class="description">
    <p>IMG to 100x100 PNG with 200x200 attributes</p>
  </div>
  <div class="element">
    <img src="sample-100.png" width="200" height="200">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result">
  <div class="description">
    <p>IMG to 200x200 PNG with 200x200 attributes</p>
  </div>
  <div class="element">
    <img src="sample-200.png" width="200" height="200">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result">
  <div class="description">
    <p>IMG to 400x400 PNG with 200x200 attributes</p>
  </div>
  <div class="element">
    <img src="sample-400.png" width="200" height="200">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result">
  <div class="description">
    <p>IMG SRCSET to multiple PNGs with 200x200 attributes</p>
  </div>
  <div class="element">
    <img src="sample-100.png" srcset="sample-200.png 1x, sample-400.png 2x" width="200" height="200">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result">
  <div class="description">
    <p>IMG to SVG with no attributes - 200x200 sizing via CSS</p>
  </div>
  <div class="element">
    <img src="sample.svg" class="viacss">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result">
  <div class="description">
    <p>IMG to 400x400 PNG with no attributes - 200x200 sizing via CSS</p>
  </div>
  <div class="element">
    <img src="sample-400.png" class="viacss">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result">
  <div class="description">
    <p>
      IMG to SVG with no attributes and no sizing via CSS<br>
      (although the width and height of the container set a size)
    </p>
  </div>
  <div class="element">
    <img src="sample.svg">
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result out-of-page">
  <div class="description">
    <p>Out of page SVG with no dimensions</p>
  </div>
  <div class="element">
    Not a child of document
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>
<div class="result out-of-page set-dimensions">
  <div class="description">
    <p>Out of page SVG with 200x200 specified</p>
  </div>
  <div class="element">
    Not a child of document
  </div>
  <div class="render">
  </div>
  <div class="log">
    <p class="output"></p>
  </div>
</div>

</body>
</html>