function log(msg) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(msg));
document.body.appendChild(div);
}
function glEnum(gl, v) {
for (var key in gl) {
if (gl[key] === v) {
return key;
}
}
return "0x" + v.toString(16);
}
// Get A WebGL context
var canvas = document.getElementById("c");
var gl = canvas.getContext("webgl");
if (gl) {
function getExt(name) {
var ext = gl.getExtension(name);
log("Extension " + name + " is " + (ext ? "" : "NOT ") + "supported");
return ext;
}
function checkError(test) {
var err = gl.getError();
if (err === 0)
log(test + ": successful");
else
log(test + ": flagged error " + err + " = gl." + glEnum(gl, err));
}
var floatExt = getExt("OES_texture_float");
getExt("OES_texture_float_linear");
if (floatExt) {
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.FLOAT, null);
checkError("Create gl.FLOAT texture with NULL buffer");
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.FLOAT, new Float32Array([0, 0, 0, 0]));
checkError("Create gl.FLOAT texture with Float32Array buffer");
}
var halfExt = getExt("OES_texture_half_float");
getExt("OES_texture_half_float_linear");
if (halfExt) {
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, halfExt.HALF_FLOAT_OES, null);
checkError("Create halfExt.HALF_FLOAT_OES texture with NULL buffer");
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, halfExt.HALF_FLOAT_OES, new Uint16Array([0, 0, 0, 0]));
checkError("Create halfExt.HALF_FLOAT_OES texture with UInt16Array buffer");
}
}
<canvas id="c" width=100 height=100 style="border:solid black 1px;"></canvas>