   _index_data: () ->
     @_xy_index()
 
-  _map_data: () ->
-    if @_gl?
-        return  # performance
+  _render: (ctx, indices, {sx, sy}) ->
+    drawing = false
+    @visuals.line.set_value(ctx)  # Set before gl, because it uses it too
 
-  _set_data: () ->
-    @_data_changed = true  # notify gl, lazy upload
-
-  _render: (ctx, indices, {sx, sy}) ->
-    
-    @visuals.line.set_value(ctx)  # Set before gl, because it uses it too
-    
-    if ctx.glcanvas
-        if not @_render_gl(ctx, indices)
-          return
-
-    drawing = false
     for i in indices
       if !isFinite(sx[i]+sy[i]) and drawing
         ctx.stroke()


    if drawing
      ctx.stroke()

  _render_gl: (ctx, indices) ->    
    gl = ctx.glcanvas.gl
    if not @_gl?
      @_gl = setup_gl(gl)

    # Get transform, and verify that its linear
    if (Math.abs((dx[1] - dx[0]) - (dx[2] - dx[1])) > 1e-6 ||
        Math.abs((dy[1] - dy[0]) - (dy[2] - dy[1])) > 1e-6)   
      return true 
    
    # No gl if line has features that we do no support
    # If we implement agg quality lines with shaders we can probably also add
    # stippling and caps (Nicolas Rougier has done much work on this stuff)
    console.log(@visuals.line.dash.value())
    if @visuals.line.dash.value().length
      return true
    if ctx.lineCap != 'butt'
      return true

    if @_data_changed
      @_data_changed = false
      @_gl.vbo_x.set_size(@x.length * 4)  # size in bytes
      @_gl.vbo_y.set_size(@y.length * 4)
      @_gl.vbo_x.set_data(0, new Float32Array(@x))
      @_gl.vbo_y.set_data(0, new Float32Array(@y))      
    
    # Get RGBA as a tuple
    # We query this (and other) values from the ctx, so we have the appropriate
    # defaults, and colors like "red" will be transformed to hex.
    colorparts = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(ctx.strokeStyle)
    color = [parseInt(colorparts[1], 16)/255, parseInt(colorparts[2], 16)/255, parseInt(colorparts[3], 16)/255]
    color.push(ctx.globalAlpha)
    
    # Set line width - note that only width 1 is guaranteed to be supported
    # We make width-1 lines a bit wider, otherwise they turn vague due to aa
    lineWidth = if ctx.lineWidth > 1 then ctx.lineWidth else ctx.lineWidth + 0.15
    ctx.glcanvas.gl.lineWidth(lineWidth)
    
    @_gl.prog.set_uniform('u_color', 'vec4', color)
    @_gl.prog.set_uniform('u_canvas_size', 'vec2', [ctx.glcanvas.width, ctx.glcanvas.height])
    @_gl.prog.set_uniform('u_offset', 'vec2', [dx[0], dy[0]])
    @_gl.prog.set_uniform('u_scale', 'vec2', [dx[1]-dx[0], dy[1]-dy[0]])

    # todo: use indices
    console.log(indices)
    @_gl.prog.draw(gl.LINE_STRIP, [0, @x.length])

  _hit_point: (geometry) ->
    ### Check if the point geometry hits this line glyph and return an object

_ = require "underscore"
Glyph = require "./glyph"
hittest = require "../../common/hittest"

