-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.html
395 lines (322 loc) · 11.6 KB
/
index.html
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
<!doctype html>
<!--
Copyright (c) 2014, Brandon Jones. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Texture Format Tester</title>
<style>
head, body {
font-family: Verdana, sans-serif;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background: #888888;
}
h1 {
text-align: left;
font-size: 1.1em;
left: 1em;
right: 1em;
margin: 1em 1em 0 1em;
border-bottom: 1px solid black;
}
h3.error {
text-align: center;
color: #CC0000;
background: #440000;
padding: 0.5em;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
#header {
margin: 1em;
}
#header p {
margin-left: 2em;
margin-right: 2em;
}
#main {
margin: 1em;
}
#footer {
text-align: right;
margin: 1em;
font-size: 0.8em;
}
.texture {
display: inline-block;
width: 256px;
height: 256px;
margin: 0.5em;
background: #333333;
background-size: 100% 100%;
position: relative;
border: 2px solid #444444;
}
.texture h2 {
font-size: 0.9em;
text-shadow: 2px 2px #000000;
color: #EDEDED;
padding: 0;
margin: 1em;]
position: absolute;
top: 0;
left: 0;
}
.texture .stats {
opacity: 0.0;
border-radius: 5px;
font-size: 0.8em;
color: #FFFFFF;
background: #000000;
margin: 0.5em;
padding: 0.5em;
list-style: none;
transition: opacity 0.2s;
position: absolute;
top: 3em;
left: 0;
}
.texture .stats li {
margin: 0;
padding: 0;
}
.texture:hover .stats,
.texture:focus .stats {
opacity: 0.8;
}
.texture.error {
background: #440000;
}
.texture.error .errorText {
font-size: 0.8em;
color: #CC0000;
padding: 0;
margin: 1em;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
</style>
<script src="js/webgl-util.js"></script>
<script src="js/webgl-texture-util.js"></script>
<script id="default-vs" type="x-shader/x-vertex">
precision mediump float;
attribute vec2 Position;
attribute vec2 TexCoord;
varying vec2 vTexCoord;
void main(void) {
vTexCoord = TexCoord;
gl_Position = vec4(Position, 1.0, 1.0);
}
</script>
<script id="default-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec2 vTexCoord;
uniform sampler2D diffuse;
void main(void) {
gl_FragColor = texture2D(diffuse, vTexCoord);
}
</script>
</head>
<body>
<section id="header">
<h1>WebGL Texture Tester</h1>
<p>This page attempts to load one of every texture format supported by
WebGL (excluding videos). It is intended to quickly show which formats
your browser/device supports, and give browser vendors a quick way to
sanity-check their implementations.</p>
<p>It is expected that multiple textures on this page will fail to load
due to lack of hardware support. (For example: DXT formats are usually
only supported on Desktops while PVRTC is typically only available on
mobile devices with PowerVR chipsets.) Your hardware may support other
formats beyond what is shown here, but only the following formats have had
WebGL extensions specified for their use.</p>
<p>The source code used to load all of these formats can be found
<a href="https://github.com/toji/texture-tester/blob/master/js/webgl-texture-util.js">here</a>.
</p>
</section>
<section id="main">
<h1>Browser Native Formats (Uncompressed)</h1>
<div class="texture" x-src="textures/shannon.jpg" x-size-bytes="99488">
<h2>JPEG</h2>
</div>
<div class="texture" x-src="textures/shannon.png" x-size-bytes="463987">
<h2>PNG</h2>
</div>
<div class="texture" x-src="textures/shannon.gif" x-size-bytes="133577">
<h2>GIF</h2>
</div>
<div class="texture" x-src="textures/shannon.bmp" x-size-bytes="786488">
<h2>BMP</h2>
</div>
<div class="texture" x-src="textures/shannon.webp" x-size-bytes="33378">
<h2>WEBP</h2>
</div>
<h1>
<a href="http://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/">
WEBGL_compressed_texture_s3tc
</a>
</h1>
<div class="texture" x-src="textures/shannon-dxt1.dds" x-size-bytes="174904">
<h2>DXT1</h2>
</div>
<div class="texture" x-src="textures/shannon-dxt3.dds" x-size-bytes="262272">
<h2>DXT3</h2>
</div>
<div class="texture" x-src="textures/shannon-dxt5.dds" x-size-bytes="349680">
<h2>DXT5</h2>
</div>
<h1>
<a href="http://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_s3tc/">
WEBGL_compressed_texture_s3tc
</a> with
<a href="https://code.google.com/p/crunch/">
Crunch Compression
</a>
</h1>
<div class="texture" x-src="textures/shannon-dxt1.crn" x-size-bytes="63186">
<h2>DXT1 (Crunch)</h2>
</div>
<div class="texture" x-src="textures/shannon-dxt5.crn" x-size-bytes="71722">
<h2>DXT5 (Crunch)</h2>
</div>
<h1>
<a href="http://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_pvrtc/">
WEBGL_compressed_texture_pvrtc
</a>
</h1>
<div class="texture" x-src="textures/shannon-pvrtc-2bpp-rgb.pvr" x-size-bytes="87555">
<h2>PVRTC (2BPP RGB)</h2>
</div>
<div class="texture" x-src="textures/shannon-pvrtc-2bpp-rgba.pvr" x-size-bytes="87555">
<h2>PVRTC (2BPP RGBA)</h2>
</div>
<div class="texture" x-src="textures/shannon-pvrtc-4bpp-rgb.pvr" x-size-bytes="174915">
<h2>PVRTC (4BPP RGB)</h2>
</div>
<div class="texture" x-src="textures/shannon-pvrtc-4bpp-rgba.pvr" x-size-bytes="174915">
<h2>PVRTC (4BPP RGBA)</h2>
</div>
<h1>
<a href="http://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_atc/">
WEBGL_compressed_texture_atc
</a>
</h1>
<div class="texture" x-src="textures/shannon-atc-rgb.dds" x-size-bytes="131200">
<h2>ATC (RGB)</h2>
</div>
<div class="texture" x-src="textures/shannon-atc-rgba-explicit.dds" x-size-bytes="262272">
<h2>ATC (RGBA, Explicit)</h2>
</div>
<div class="texture" x-src="textures/shannon-atc-rgba-interpolated.dds" x-size-bytes="262272">
<h2>ATC (RGBA, Interpolated)</h2>
</div>
<h1>
<a href="http://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc1/">
WEBGL_compressed_texture_etc1
</a>
</h1>
<div class="texture" x-src="textures/shannon-etc1.pvr" x-size-bytes="174843">
<h2>ETC1</h2>
</div>
</section>
<section id="footer">
Image credit: Shannon Jones
</section>
<script>
var canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
var gl = WebGLUtil.getContext(canvas);
if (gl) {
var textureUtil = new WebGLTextureUtil(gl, true);
var shader = WebGLUtil.createProgramFromTags(gl, "#default-vs", "#default-fs");
gl.useProgram(shader.program);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
var quadBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
-1, 1, 0, 0,
1, 1, 1, 0,
1, -1, 1, 1,
-1, 1, 0, 0,
1, -1, 1, 1,
-1, -1, 0, 1,
]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(shader.attribute.Position);
gl.enableVertexAttribArray(shader.attribute.TexCoord);
gl.vertexAttribPointer(shader.attribute.Position, 2, gl.FLOAT, false, 16, 0);
gl.vertexAttribPointer(shader.attribute.TexCoord, 2, gl.FLOAT, false, 16, 8);
gl.uniform1i(shader.uniform.diffuse, 0);
function loadTexture(texElem) {
var textureSrc = texElem.getAttribute("x-src");
texElem.tabIndex = 0;
var textureSize = texElem.getAttribute("x-size-bytes");
var statsList = document.createElement("ul");
statsList.classList.add("stats");
texElem.appendChild(statsList);
function addStat(name, value) {
var stat = document.createElement("li");
stat.innerHTML = "<b>" + name + ":</b> " + value;
statsList.appendChild(stat);
}
addStat("File Size", Math.floor(textureSize / 1024) + " Kb");
textureUtil.loadTexture(textureSrc, null, function(texture, error, stats) {
if (stats != null) {
addStat("Size in memory (Lvl 0)", Math.floor(stats.levelZeroSize / 1024) + " Kb");
addStat("Dimensions", stats.width + " x " + stats.height);
addStat("Upload time", Math.floor(stats.uploadTime) + " ms");
}
if (!error) {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.drawArrays(gl.TRIANGLES, 0, 6);
var dataUrl = canvas.toDataURL();
texElem.style.backgroundImage = "url(" + dataUrl + ")";
} else {
var errorElem = document.createElement("div");
errorElem.classList.add("errorText");
errorElem.innerHTML = error;
texElem.appendChild(errorElem);
texElem.classList.add("error");
}
});
}
var textures = document.querySelectorAll(".texture");
for (var i = 0; i < textures.length; ++i) {
loadTexture(textures[i]);
}
} else {
var main = document.getElementById("main");
main.innerHTML = "<h3 class='error'>WebGL not Supported</h3>";
}
</script>
</body>
</html>