     set_data: (data=[null,null,null,null,null,null]) ->
         {gl} = @context.render_manager
         i = gl.TEXTURE_CUBE_MAP_POSITIVE_X
-        gl.texImage2D(i++, 0, @internal_format, @size, @size, 0, @format, @type, data[0])
-        gl.texImage2D(i++, 0, @internal_format, @size, @size, 0, @format, @type, data[1])
-        gl.texImage2D(i++, 0, @internal_format, @size, @size, 0, @format, @type, data[2])
-        gl.texImage2D(i++, 0, @internal_format, @size, @size, 0, @format, @type, data[3])
-        gl.texImage2D(i++, 0, @internal_format, @size, @size, 0, @format, @type, data[4])
-        gl.texImage2D(i++, 0, @internal_format, @size, @size, 0, @format, @type, data[5])
+        gl.texImage2D(i++, 0, @gl_internal_format, @size, @size, 0, @gl_format, @gl_type, data[0])
+        gl.texImage2D(i++, 0, @gl_internal_format, @size, @size, 0, @gl_format, @gl_type, data[1])
+        gl.texImage2D(i++, 0, @gl_internal_format, @size, @size, 0, @gl_format, @gl_type, data[2])
+        gl.texImage2D(i++, 0, @gl_internal_format, @size, @size, 0, @gl_format, @gl_type, data[3])
+        gl.texImage2D(i++, 0, @gl_internal_format, @size, @size, 0, @gl_format, @gl_type, data[4])
+        gl.texImage2D(i++, 0, @gl_internal_format, @size, @size, 0, @gl_format, @gl_type, data[5])
         if @use_mipmap?
             gl.generateMipmap gl.TEXTURE_CUBE_MAP
         return @

        @bound_unit = -1
        return @

    destroy: ->
        if @gl_tex
            @context.render_manager.gl.deleteTexture @gl_tex
        @gl_tex = null
        @loaded = false

module.exports = {Cubemap}


{vec2} = require 'gl-matrix'

_temp_framebuffers = {}

# TODO: Inherit from abstract texture class?
class Cubemap
    type: 'TEXTURE'
    texture_type: 'cubemap'
    # Size of each face of the cubemap
    size: 128
    # GL texture type (default: gl.UNSIGNED_BYTE)
    gl_type: 0

    constructor: (@context, options={}) ->
        {gl} = @context.render_manager
        {
            @size=128
            @gl_type=gl.UNSIGNED_BYTE
            @gl_internal_format=gl.RGBA
            @gl_format=gl.RGBA
            @use_filter=true
            @use_mipmap=true
            @color
