         @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
+        gl.texParameteri @gl_target, 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.texParameteri @gl_target, gl.TEXTURE_MIN_FILTER,
                 gl_linear_nearest_mipmap
         else
-            gl.texParameteri gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,
+            gl.texParameteri @gl_target, gl.TEXTURE_MIN_FILTER,
                 gl_linear_nearest
         # TODO: detect which textures need this (mostly walls, floors...)
         # and add a global switch

        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
        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
        return @

    destroy: ->

                return @promise
            @promised_data = raw_pixels
            @promise = new Promise (resolve, reject) =>
                {@width=0, @height=0, pixels, format, internal_format} = raw_pixels
                if @width==0 or @height==0
                    reject "Texture #{name} has no width or height."
                buffer = pixels.buffer or (new Uint8Array(pixels)).buffer
                @texture_type = 'arrays'
                @gl_format = @gl_internal_format = gl.RGBA
                if format
                    @gl_format = gl[format]
                if internal_format
                    @gl_internal_format = gl[internal_format]
                @gl_type = gl.UNSIGNED_BYTE
                if pixels.constructor == Float32Array
                    @gl_type = gl.FLOAT
