         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: ->

        @loaded = true # bind_texture requires this
        @context.render_manager.bind_texture @
        gl_linear_nearest = if @filter then gl.LINEAR else gl.NEAREST
        gl.texParameteri gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl_linear_nearest
        # TODO: add mipmap options to the GUI
        if @use_mipmap
            gl_linear_nearest_mipmap = if @filter then gl.LINEAR_MIPMAP_LINEAR
            else gl.NEAREST_MIPMAP_NEAREST
            gl.texParameteri gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
                gl_linear_nearest_mipmap
        else
            gl.texParameteri gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
                gl_linear_nearest
        # TODO: detect which textures need this (mostly walls, floors...)
        # and add a global switch

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