{
const gl = canvas.getContext("webgl2");
let backend = tf.engine().findBackend("webgl");
if (backend === null) {
throw Error("WebGL backend is not available");
}
let gpgpu = backend.getGPGPUContext(gl);
tf.registerBackend("custom-webgl", () => {
return new tf.webgl.MathBackendWebGL(gpgpu);
});
tf.setBackend("custom-webgl");
function getTex(gl) {
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
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.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
return texture;
}
gl.clearColor(0.4, 1.0, 0.0, 1.0);
gl.clearDepth(1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.viewport(0, 0, canvas.width, canvas.height);
return tf.square(4).dataSync();
}