addMapTile :: WebGLRenderingContext
           -> DataFrame Float '[4,4] -- ^ four vertices
           -> TexImageSource
           -> RenderMTilesProgram
           -> IO RenderMTilesProgram
addMapTile gl vertices tileImg rmtProg = do

    mtVertexBuffer <- createBuffer gl
    verticesIO <- unsafeArrayThaw vertices
    bindBuffer gl gl_ARRAY_BUFFER $ Just mtVertexBuffer
    bufferData' gl gl_ARRAY_BUFFER verticesIO gl_STATIC_DRAW

    mtTexture <- createTexture gl
    bindTexture gl gl_TEXTURE_2D $ Just mtTexture
    pixelStorei gl gl_UNPACK_FLIP_Y_WEBGL 1
    texImage2DImg gl gl_TEXTURE_2D 0 gl_RGBA gl_RGBA gl_UNSIGNED_BYTE tileImg
    setTexParameters gl
    bindTexture gl gl_TEXTURE_2D Nothing

    return rmtProg { rmtTiles = MapTile {..} : rmtTiles rmtProg }

-- | Clear tiles only. Keeps the program itself
addMapTile :: WebGLRenderingContext
           -> DataFrame Float '[4,4] -- ^ four vertices
           -> TexImageSource
           -> RenderMTilesProgram
           -> IO RenderMTilesProgram
addMapTile gl vertices tileImg rmtProg = do

    mtVertexBuffer <- createBuffer gl
    verticesIO <- unsafeArrayThaw vertices
    bindBuffer gl gl_ARRAY_BUFFER $ Just mtVertexBuffer
    bufferData' gl gl_ARRAY_BUFFER verticesIO gl_STATIC_DRAW

    mtTexture <- createTexture gl
    bindTexture gl gl_TEXTURE_2D $ Just mtTexture
    pixelStorei gl gl_UNPACK_FLIP_Y_WEBGL 1
    texImage2DImg gl gl_TEXTURE_2D 0 gl_RGBA gl_RGBA gl_UNSIGNED_BYTE tileImg
    setTexParameters gl
    bindTexture gl gl_TEXTURE_2D Nothing

    return rmtProg { rmtTiles = MapTile {..} : rmtTiles rmtProg }

-- | Clear tiles only. Keeps the program itself
addMapTile gl vertices tileImg rmtProg = do

    mtVertexBuffer <- createBuffer gl
    verticesIO <- unsafeArrayThaw vertices
    bindBuffer gl gl_ARRAY_BUFFER $ Just mtVertexBuffer
    bufferData' gl gl_ARRAY_BUFFER verticesIO gl_STATIC_DRAW

    mtTexture <- createTexture gl
    bindTexture gl gl_TEXTURE_2D $ Just mtTexture
    pixelStorei gl gl_UNPACK_FLIP_Y_WEBGL 1
    texImage2DImg gl gl_TEXTURE_2D 0 gl_RGBA gl_RGBA gl_UNSIGNED_BYTE tileImg
    setTexParameters gl
    bindTexture gl gl_TEXTURE_2D Nothing

    return rmtProg { rmtTiles = MapTile {..} : rmtTiles rmtProg }

-- | Clear tiles only. Keeps the program itself