 #= require_tree "./material"
 
 class Jax.Material
-  constructor: (options, name = "generic") ->
-    @shader = new Jax.Shader2.Program name
+  constructor: (options, @name = "generic") ->
+    @shader = new Jax.Shader2.Program @name
     @layers = []
     @assigns = {}
     options = Jax.Util.normalizeOptions options, {}

  
  addLayer: (options) ->
    Klass = Jax.Material[options.type]
    throw new Error "Material layer type #{options.type} could not be found" unless Klass
    options = Jax.Util.normalizeOptions options, shader: Klass.shader || Jax.Util.underscore options.type
    layer = new Klass options, this
    if layer instanceof Jax.Material
      throw new Error """
        Custom material layers now inherit from Jax.Material.Layer instead of Jax.Material.
        Please also note that the constructor takes two arguments: the classic `options` hash, and a
        reference to the layer's parent instance of `Jax.Material`, which should be passed to `super`.
        Please see the documentation for more information.

      context.gl.drawElements mesh.draw_mode, buffer.length, buffer.dataType, 0
    else if (buffer = mesh.getVertexBuffer()) && buffer.length
      context.gl.drawArrays mesh.draw_mode, 0, buffer.length
  
  @instances: {}
  @resources: {}
