         if @context.MYOU_PARAMS.anisotropic_filter and ext
             # TODO: detect max anisotropy, make configurable
             # ext.TEXTURE_MAX_ANISOTROPY_EXT == 0x84FE
-            gl.texParameterf gl.TEXTURE_2D, 0x84FE, 4
+            gl.texParameterf @gl_target, 0x84FE, 4
         wrap_const = switch @wrap
             when 'C' then gl.CLAMP_TO_EDGE
             when 'R' then gl.REPEAT
             when 'M' then gl.MIRRORED_REPEAT
             else gl.REPEAT
-        gl.texParameteri gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap_const
-        gl.texParameteri gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap_const
+        gl.texParameteri @gl_target, gl.TEXTURE_WRAP_S, wrap_const
+        gl.texParameteri @gl_target, gl.TEXTURE_WRAP_T, wrap_const
         return @
 
     destroy: ->

        switch @texture_type
            when 'arrays'
                for array, i in @arrays
                    gl.texImage2D(gl.TEXTURE_2D, i, @gl_internal_format,
                        @width>>i, @height>>i, 0, @gl_format, @gl_type,
                        array)
                if @arrays.length == 1 and @use_mipmap
                    gl.generateMipmap gl.TEXTURE_2D
            when 'compressed'
                upload_task_id = ++@upload_task_id
                self = this

                    console.error "Compressed texture #{@name}
                        doesn't have requested mipmaps."
            when 'image'
                if @image.pixels
                    gl.texImage2D(@gl_target, i, gl.RGBA,
                        @width, @height, 0, gl.RGBA, gl.UNSIGNED_BYTE,
                        @image.pixels)
                else
                    gl.pixelStorei gl.UNPACK_FLIP_Y_WEBGL, true
                    if @use_alpha
                        internal = gl.RGBA
                        format = gl.RGBA
                        type = gl.UNSIGNED_BYTE
                    else if @context.is_webgl2
                        internal = gl.RGB565
                        format = gl.RGB
                        type = gl.UNSIGNED_SHORT_5_6_5
                    else
                        internal = gl.RGB
                        format = gl.RGB
                        type = gl.UNSIGNED_BYTE
                    gl.texImage2D @gl_target, 0, internal, format, type, @image
                if @use_mipmap
                    gl.generateMipmap @gl_target
            when 'video'
                # TODO: Is this inefficient to do every frame?
                # Should UVs be inverted instead?
                gl.pixelStorei gl.UNPACK_FLIP_Y_WEBGL, true
                # TODO: Use gl.RGB?
                gl.texImage2D @gl_target, 0, gl.RGBA, gl.RGBA,
                    gl.UNSIGNED_BYTE, @video
                if @use_mipmap
                    gl.generateMipmap @gl_target
        return

    # Unloads all texture data that has been generated with load()
