 # The presence (and not-being-false) of the ctx.glcanvas attribute is the
 # marker that we use throughout that determines whether we have gl support. 
 
+global_gl_canvas = null
+
 
 class PlotView extends ContinuumView
   className: "bk-plot"

      ctx.drawImage(ctx.glcanvas, 0.1, 0.1)
      for prefix in ['image', 'mozImage', 'webkitImage','msImage']
         ctx[prefix + 'SmoothingEnabled'] = true
      console.log('drawing with WebGL')

    @_render_levels(ctx, ['overlay', 'tool'])



    # We use a global invisible canvas and gl context. By having a global context,
    # we avoid the limitation of max 16 contexts that most browsers have. 
    glcanvas = global_gl_canvas
    if not glcanvas?
      global_gl_canvas = glcanvas = document.createElement('canvas')
      opts = {'premultipliedAlpha': true}  # premultipliedAlpha is true by default
      glcanvas.gl = glcanvas.getContext("webgl", opts) || glcanvas.getContext("experimental-webgl", opts)

