function setTextureFromElement(gl, tex, element, options) {
	    options = options || defaults.textureOptions;
	    var target = options.target || gl.TEXTURE_2D;
	    var width = element.width;
	    var height = element.height;
	    var internalFormat = options.internalFormat || options.format || gl.RGBA;
	    var formatType = getFormatAndTypeForInternalFormat(internalFormat);
	    var format = options.format || formatType.format;
	    var type = options.type || formatType.type;
	    savePackState(gl, options);
	    gl.bindTexture(target, tex);
	    if (target === gl.TEXTURE_CUBE_MAP) {
	      // guess the parts
	      var imgWidth = element.width;
	      var imgHeight = element.height;
	      var size;
	      var slices;
	      if (imgWidth / 6 === imgHeight) {
	        // It's 6x1
	        size = imgHeight;
	        slices = [0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0];
	      } else if (imgHeight / 6 === imgWidth) {
	        // It's 1x6
	        size = imgWidth;
	        slices = [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5];
	      } else if (imgWidth / 3 === imgHeight / 2) {
	        // It's 3x2
	        size = imgWidth / 3;
	        slices = [0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1];
	      } else if (imgWidth / 2 === imgHeight / 3) {
	        // It's 2x3
	        size = imgWidth / 2;
	        slices = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
	      } else {
	        throw "can't figure out cube map from element: " + (element.src ? element.src : element.nodeName);
	      }
	      ctx.canvas.width = size;
	      ctx.canvas.height = size;
	      width = size;
	      height = size;
	      getCubeFacesWithNdx(gl, options).forEach(function (f) {
	        var xOffset = slices[f.ndx * 2 + 0] * size;
	        var yOffset = slices[f.ndx * 2 + 1] * size;
	        ctx.drawImage(element, xOffset, yOffset, size, size, 0, 0, size, size);
	        gl.texImage2D(f.face, 0, internalFormat, format, type, ctx.canvas);
	      });
	      // Free up the canvas memory
	      ctx.canvas.width = 1;
	      ctx.canvas.height = 1;
	    } else if (target === gl.TEXTURE_3D) {
	      var smallest = Math.min(element.width, element.height);
	      var largest = Math.max(element.width, element.height);
	      var depth = largest / smallest;
	      if (depth % 1 !== 0) {
	        throw "can not compute 3D dimensions of element";
	      }
	      var xMult = element.width === largest ? 1 : 0;
	      var yMult = element.height === largest ? 1 : 0;
	      gl.texImage3D(target, 0, internalFormat, smallest, smallest, smallest, 0, format, type, null);
	      // remove this is texSubImage3D gets width and height arguments
	      ctx.canvas.width = smallest;
	      ctx.canvas.height = smallest;
	      for (var d = 0; d < depth; ++d) {
	        //        gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, d * smallest);
	        //        gl.texSubImage3D(target, 0, 0, 0, d, format, type, element);
	        var srcX = d * smallest * xMult;
	        var srcY = d * smallest * yMult;
	        var srcW = smallest;
	        var srcH = smallest;
	        var dstX = 0;
	        var dstY = 0;
	        var dstW = smallest;
	        var dstH = smallest;
	        ctx.drawImage(element, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH);
	        gl.texSubImage3D(target, 0, 0, 0, d, smallest, smallest, 1, format, type, ctx.canvas);
	      }
	      ctx.canvas.width = 0;
	      ctx.canvas.height = 0;
	      // FIX (save state)
	      //      gl.pixelStorei(gl.UNPACK_SKIP_PIXELS, 0);
	    } else {
	      gl.texImage2D(target, 0, internalFormat, format, type, element);
	    }
	    restorePackState(gl, options);
	    if (options.auto !== false) {
	      setTextureFilteringForSize(gl, tex, options, width, height, internalFormat, type);
	    }
	    setTextureParameters(gl, tex, options);
	  }
Set a texture from the contents of an element. Will also set
texture filtering or generate mips based on the dimensions of the element
unless `options.auto === false`. If `target === gl.TEXTURE_CUBE_MAP` will
attempt to slice image into 1x6, 2x3, 3x2, or 6x1 images, one for each face.
@param {WebGLRenderingContext} gl the WebGLRenderingContext
@param {WebGLTexture} tex the WebGLTexture to set parameters for
@param {HTMLElement} element a canvas, img, or video element.
@param {module:twgl.TextureOptions} [options] A TextureOptions object with whatever parameters you want set.
  This is often the same options you passed in when you created the texture.
@memberOf module:twgl/textures
@kind function