Sha256: 2fdf1184ef0a16e504369287acb09dfc196a3c6153263dd5c7b0673f3e49d3bc

Contents?: true

Size: 1.78 KB

Versions: 22

Compression:

Stored size: 1.78 KB

Contents

//= require "../delegator"

Jax.Shader.AttributeDelegator = (function() {
  return Jax.Class.create(Jax.Shader.Delegator, {
    initialize: function($super, context, program) {
      var numAttributes = context.glGetProgramParameter(program, GL_ACTIVE_ATTRIBUTES);
      var attributes = {};
      for (var i = 0; i < numAttributes; i++)
      {
        var attrib = context.glGetActiveAttrib(program, i);
        attributes[attrib.name] = {
          length:attrib.length,
          size:attrib.size,
          type:attrib.type,
          type_str:Jax.Util.enumName(attrib.type),
          location: context.glGetAttribLocation(program, attrib.name)
        };
      }
      $super(context, program, attributes);
    },
    
    set: function(name, value) {
      var v, c = this.context, i, variables = this.variables;
      
      function _set(name, value) {
        if (value == undefined) return;
//        if (value == undefined) throw new Error("Value is undefined for shader attribute "+JSON.stringify(name));
        
        if (v = variables[name]) {
          value.bind(c);
          c.glEnableVertexAttribArray(v.location);
          c.glVertexAttribPointer(v.location, value.itemSize, GL_FLOAT, false, 0, 0);
//        } else {
//          console.warn("skipping assignment of attribute %s (variables: %s)", name, JSON.stringify(variables));
        }
      }
      
      if (arguments.length == 1 && typeof(arguments[0]) == "object")
        for (i in arguments[0])
          _set(i, arguments[0][i]);
      else
        for (i = 0; i < arguments.length; i += 2)
          _set(arguments[i], arguments[i+1]);
    },
    
    disableAll: function() {
      for (var v in this.variables) {
        v = this.variables[v];
        this.context.glDisableVertexAttribArray(v.location);
      }
    }
  });
})();

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
jax-2.0.12 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.11 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.10 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.9 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.8 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.7 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.6 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.5 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.4 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.3 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.2 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.1 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-2.0.0 lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js
jax-0.0.0.9 src/jax/webgl/shader/delegator/attribute.js
jax-0.0.0.8 src/jax/webgl/shader/delegator/attribute.js
jax-0.0.0.7 src/jax/webgl/shader/delegator/attribute.js
jax-0.0.0.6 src/jax/webgl/shader/delegator/attribute.js
jax-0.0.0.5 src/jax/webgl/shader/delegator/attribute.js
jax-0.0.0.4 src/jax/webgl/shader/delegator/attribute.js
jax-0.0.0.3 src/jax/webgl/shader/delegator/attribute.js