constructor(gl){
        this.outputTexture = null;
        this.program = null;
        this.disposed = false;
        this.itemsToPoll = [];
        const glVersion = (0, _tfjsCore.env)().getNumber("WEBGL_VERSION");
        if (gl != null) {
            this.gl = gl;
            (0, _canvasUtil.setWebGLContext)(glVersion, gl);
        } else this.gl = (0, _canvasUtil.getWebGLContext)(glVersion);
        gl = this.gl;
        if ((0, _tfjsCore.env)().getNumber("WEBGL_VERSION") === 2) {
            const gl2 = gl;
            this.createVertexArray = ()=>{
                return _webglUtil.callAndCheck(gl2, ()=>gl2.createVertexArray());
            };
            this.bindVertexArray = (vao)=>{
                return _webglUtil.callAndCheck(gl2, ()=>gl2.bindVertexArray(vao));
            };
            this.deleteVertexArray = (vao)=>{
                return _webglUtil.callAndCheck(gl2, ()=>gl2.deleteVertexArray(vao));
            };
            this.getVertexArray = ()=>{
                return _webglUtil.callAndCheck(gl2, ()=>gl2.getParameter(gl2.VERTEX_ARRAY_BINDING));
            };
        } else if (gl != null) {
            const ext = gl.getExtension("OES_vertex_array_object");
            if (ext == null) throw new Error("All WebGL1 implementations are expected to offer OES_vertex_array_object.");
            this.createVertexArray = ()=>{
                return _webglUtil.callAndCheck(gl, ()=>ext.createVertexArrayOES());
            };
            this.bindVertexArray = (vao)=>{
                return _webglUtil.callAndCheck(gl, ()=>ext.bindVertexArrayOES(vao));
            };
            this.deleteVertexArray = (vao)=>{
                return _webglUtil.callAndCheck(gl, ()=>ext.deleteVertexArrayOES(vao));
            };
            this.getVertexArray = ()=>{
                return _webglUtil.callAndCheck(gl, ()=>gl.getParameter(ext.VERTEX_ARRAY_BINDING_OES));
            };
        }
        // WebGL 2.0 enables texture floats without an extension.
        let COLOR_BUFFER_FLOAT = "WEBGL_color_buffer_float";
        const COLOR_BUFFER_HALF_FLOAT = "EXT_color_buffer_half_float";
        this.parallelCompilationExtension = this.gl.getExtension("KHR_parallel_shader_compile");
        if ((0, _tfjsCore.env)().getNumber("WEBGL_VERSION") === 1) {
            const TEXTURE_FLOAT = "OES_texture_float";
            const TEXTURE_HALF_FLOAT = "OES_texture_half_float";
            this.textureFloatExtension = _webglUtil.getExtensionOrThrow(this.gl, TEXTURE_FLOAT);
            if (_webglUtil.hasExtension(this.gl, TEXTURE_HALF_FLOAT)) this.textureHalfFloatExtension = _webglUtil.getExtensionOrThrow(this.gl, TEXTURE_HALF_FLOAT);
            else if ((0, _tfjsCore.env)().get("WEBGL_FORCE_F16_TEXTURES")) throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");
            this.colorBufferFloatExtension = this.gl.getExtension(COLOR_BUFFER_FLOAT);
            if (_webglUtil.hasExtension(this.gl, COLOR_BUFFER_HALF_FLOAT)) this.colorBufferHalfFloatExtension = _webglUtil.getExtensionOrThrow(this.gl, COLOR_BUFFER_HALF_FLOAT);
            else if ((0, _tfjsCore.env)().get("WEBGL_FORCE_F16_TEXTURES")) throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");
        } else {
            COLOR_BUFFER_FLOAT = "EXT_color_buffer_float";
            if (_webglUtil.hasExtension(this.gl, COLOR_BUFFER_FLOAT)) this.colorBufferFloatExtension = this.gl.getExtension(COLOR_BUFFER_FLOAT);
            else if (_webglUtil.hasExtension(this.gl, COLOR_BUFFER_HALF_FLOAT)) this.colorBufferHalfFloatExtension = this.gl.getExtension(COLOR_BUFFER_HALF_FLOAT);
            else throw new Error("GL context does not support color renderable floats");
        }
        this.vertexBuffer = _gpgpuUtil.createVertexBuffer(this.gl);
        this.indexBuffer = _gpgpuUtil.createIndexBuffer(this.gl);
        this.framebuffer = _webglUtil.createFramebuffer(this.gl);
        this.textureConfig = _texUtil.getTextureConfig(this.gl, this.textureHalfFloatExtension);
    }
Finds the index of the last true element using linear search.
Note: We can't do binary search because Chrome expects us to explicitly
test all fences before download:
https://github.com/tensorflow/tfjs/issues/1145