 
     @canvas.addEventListener "webglcontextcreationerror", (event) =>
       @trace.error event.statusMessage
+
+    @canvas.addEventListener "webglcontextlost", => @_handleContextLost()
+    @canvas.addEventListener "webglcontextrestored", => @_handleContextRestored()
+
 
     @_createContext()
 

    unless browserSupportsRequiredFeatures()
      throw new Error "This browser does not support WebGL"

    @_contextRequiresSetup = true
    @_fragmentShaderIsDirty = false
    @_vertexShaderIsDirty = false
    @_geometryIsDirty = false
    @_renderIsDirty = false

    # The number of vertices drawn
    @vertexCount = 4



    @debugContext = WebGLDebugUtils.makeDebugContext @nativeContext, null, throwErrorOnUndefinedArgument, null

    @_contextRequiresSetup = true

    @gl = if @_debugMode then @debugContext else @nativeContext

