JSFiddle - React, Tailwind, and code Playground
HTML
<pre id='g_log'></pre>
JavaScript
function log(...args) {
g_log.textContent += args.join(' ') + '\n';
}
for (const type of [['webgl',100], ['webgl2',100], ['webgl2',300]]) {
log('----\ntype', type);
const gl = document.createElement('canvas').getContext(type[0]);
if (!gl) {
log('Not supported: ' + type[0]);
continue;
}
let prefix = '';
if (type[1] == 300) {
prefix = '#version 300 es\n';
}
const vs = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vs, prefix + `
void main() {}
`.trim());
gl.compileShader(vs);
const fs = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fs, prefix + `
#if __VERSION__ == 300
#define TEXTURE texture
#else
#define TEXTURE texture2D
#endif
precision mediump float;
uniform sampler2D u_tex[2];
void main() {
for (int i = 0; i < 2; i++) {
vec4 color = TEXTURE(u_tex[i], vec2(0));
}
}
`.trim());
gl.compileShader(fs);
const p = gl.createProgram();
gl.attachShader(p, vs);
gl.attachShader(p, fs);
gl.linkProgram(p);
log('Program log: ' + gl.getProgramInfoLog(p));
log('Vert shader log: ' + gl.getShaderInfoLog(vs));
log('Frag shader log: ' + gl.getShaderInfoLog(fs));
}