summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/extra/webgl-info.html
blob: 86b4d0c05b9aa471d96709b17426ebbcae6b3613 (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
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
<!--

/*
** Copyright (c) 2012 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>
<meta charset="utf-8">
<title>WebGL Information</title>
<style type="text/css">
th, td {
    padding: 4pt;
}
th {
    text-align: right;
    min-width: 22em;
}
</style>
<script src="../js/webgl-test-utils.js"> </script>
<script>
"use strict";
window.onload = main;

function createCell(txt, isTh) {
  var str = txt.toString();
  if (typeof txt != 'string') {
    if (txt.length !== undefined) {
      str = "";
      for (var ii = 0; ii < txt.length; ++ii) {
        str += (ii == 0 ? "" : ", ") + txt[ii];
      }
    }
  }
  var t = document.createTextNode(str);
  var d = document.createElement("div");
  var td;
  if (isTh) {
    td = document.createElement("th");
  } else {
    td = document.createElement("td");
  }
  d.appendChild(t);
  td.appendChild(d);
  return td;
}

function createRow(values) {
  var tr = document.createElement("tr");
  for (var i = 0; i < values.length; ++i) {
    var td = createCell(values[i], i == 0);
    tr.appendChild(td);
  }
  return tr;
}

function main() {
  var wtu = WebGLTestUtils;

  var canvas = document.getElementById("example");
  var gl = wtu.create3DContext(canvas);
  if (!gl) {
    return;
  }

  var debugRendererInfoRows = function() {
    var rows = [];
    var debugExt =  wtu.getExtensionWithKnownPrefixes(gl, 'WEBGL_debug_renderer_info');
    if (debugExt) {
      var extPnames = [
        'UNMASKED_VENDOR_WEBGL',
        'UNMASKED_RENDERER_WEBGL'
      ];
      for (var ii = 0; ii < extPnames.length; ++ii) {
        var pname = extPnames[ii];
        var value = gl.getParameter(debugExt[pname]);
        rows.push([pname, value]);
      }
    }
    return rows;
  };

  var precisionRows = function() {
    var rows = [];

    var addPrecisionRow = function(shaderType, precision) {
        var typeStr = shaderType === gl.FRAGMENT_SHADER ? 'fragment' : 'vertex';
        var precisionStr = 'highp';
        if (precision == gl.MEDIUM_FLOAT) {
            precisionStr = 'mediump';
        } else if (precision == gl.LOW_FLOAT) {
            precisionStr = 'lowp';
        }
        rows.push([typeStr + ' shader ' + precisionStr + ' float', gl.getShaderPrecisionFormat(shaderType, precision).precision + ' mantissa bits']);
    };

    var fSource = 'precision highp float; uniform float r; void main() { gl_FragColor = vec4(r, 0.0, 0.0, 1.0); }'
    var f = wtu.loadShader(gl, fSource, gl.FRAGMENT_SHADER);
    if (!f) {
        rows.push(['fragment shader highp float', 'not supported']);
    } else {
        addPrecisionRow(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
    }
    addPrecisionRow(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT);
    addPrecisionRow(gl.FRAGMENT_SHADER, gl.LOW_FLOAT);
    addPrecisionRow(gl.VERTEX_SHADER, gl.HIGH_FLOAT);
    addPrecisionRow(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT);
    addPrecisionRow(gl.VERTEX_SHADER, gl.LOW_FLOAT);
    return rows;
  };

  var renderTargetRows = function() {
    var rows = [];
    var oesTextureFloat = wtu.getExtensionWithKnownPrefixes(gl, 'OES_texture_float');
    var oesTextureHalfFloat = wtu.getExtensionWithKnownPrefixes(gl, 'OES_texture_half_float');
    var formatsToTest = [
      {
        description: 'RGBA UNSIGNED_BYTE',
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE
      },
      {
        description: 'RGB UNSIGNED_BYTE',
        format: gl.RGB,
        type: gl.UNSIGNED_BYTE
      }
    ];
    if (oesTextureFloat) {
      formatsToTest.push({
        description: 'RGBA FLOAT',
        format: gl.RGBA,
        type: gl.FLOAT
      });
      formatsToTest.push({
        description: 'RGB FLOAT (deprecated)',
        format: gl.RGB,
        type: gl.FLOAT
      });
    }
    if (oesTextureHalfFloat) {
      formatsToTest.push({
        description: 'RGBA HALF_FLOAT_OES',
        format: gl.RGBA,
        type: oesTextureHalfFloat.HALF_FLOAT_OES
      });
      formatsToTest.push({
        description: 'RGB HALF_FLOAT_OES',
        format: gl.RGB,
        type: oesTextureHalfFloat.HALF_FLOAT_OES
      });
    }
    for (var ii = 0; ii < formatsToTest.length; ++ii) {
      var fb = gl.createFramebuffer();
      gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
      var format = formatsToTest[ii];
      var tex = gl.createTexture();
      gl.bindTexture(gl.TEXTURE_2D, tex);
      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
      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, format.format, 256, 256, 0, format.format, format.type, null);
      gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
      if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
        rows.push([format.description, 'supported']);
      } else {
        rows.push([format.description, 'not supported']);
      }
      gl.deleteFramebuffer(fb);
      gl.deleteTexture(tex);
    }
    return rows;
  };

  var info = [
    {
      title: 'Renderer',
      pnames: [
        'VERSION',
        'VENDOR',
        'RENDERER'
      ],
      genRows: debugRendererInfoRows
    },
    {
      title: 'Textures and Viewport',
      pnames: [
        'MAX_TEXTURE_SIZE',
        'MAX_CUBE_MAP_TEXTURE_SIZE',
        'MAX_RENDERBUFFER_SIZE',
        'MAX_VIEWPORT_DIMS'
      ]
    },
    {
      title: 'Shader Variables',
      pnames: [
        'MAX_VARYING_VECTORS',
        'MAX_VERTEX_ATTRIBS',
        'MAX_VERTEX_UNIFORM_VECTORS',
        'MAX_FRAGMENT_UNIFORM_VECTORS',
        'MAX_VERTEX_TEXTURE_IMAGE_UNITS',
        'MAX_TEXTURE_IMAGE_UNITS',
        'MAX_COMBINED_TEXTURE_IMAGE_UNITS'
      ]
    },
    {
      title: 'Shader Precision',
      genRows: precisionRows
    },
    {
      title: 'Framebuffer Texture Attachment Support',
      genRows: renderTargetRows
    }
  ];

  // TODO: max anisotropy, framebuffer depth bits, MSAA samples, max multiple render targets buffers, point size, line width

  for (var jj = 0; jj < info.length; ++jj) {
    var table = document.createElement("table");
    var tb = document.createElement("tbody");
    if (info[jj].pnames) {
      var pnames = info[jj].pnames;
      for (var ii = 0; ii < pnames.length; ++ii) {
        var pname = pnames[ii];
        var value = gl.getParameter(gl[pname]);
        tb.appendChild(createRow([pname, value]));
      }
    }
    if (info[jj].genRows) {
      var genRows = info[jj].genRows();
      for (var ii = 0; ii < genRows.length; ++ii) {
        tb.appendChild(createRow(genRows[ii]));
      }
    }
    table.appendChild(tb);
    var header = document.createElement("h2");
    header.textContent = info[jj].title;
    document.getElementById("info").appendChild(header);
    document.getElementById("info").appendChild(table);
  }
  var extensionList = document.createElement('ul');
  var exts = gl.getSupportedExtensions();
  var extsWithPrefixes = [];
  while (exts.length > 0) {
    var prefixedNames = wtu.getExtensionPrefixedNames(exts[0]);
    var supportedPrefixedNames = [];
    for (var ii = 0; ii < prefixedNames.length; ++ii) {
      var index = exts.indexOf(prefixedNames[ii]);
      if (index >= 0) {
        supportedPrefixedNames.push(exts[index]);
        exts.splice(index, 1);
      }
    }
    extsWithPrefixes.push(supportedPrefixedNames.join(" / "));
  }
  extsWithPrefixes.sort();
  for (var ii = 0; ii < extsWithPrefixes.length; ++ii) {
    var li = document.createElement('li');
    li.appendChild(document.createTextNode(extsWithPrefixes[ii]));
    extensionList.appendChild(li);
  }
  document.getElementById('extensions').appendChild(extensionList);
}
</script>
</head>
<body>
<h1>WebGL Info</h1>
<div id="info"></div>
<h2>WebGL Extensions</h2>
<div id="extensions"></div>
<canvas id="example" width="256" height="16" style="width: 256px; height: 48px;"></canvas>
</body>
</html>