'use strict' module.exports = createAttributeWrapper var GLError = require("./GLError") function ShaderAttribute( gl , wrapper , index , locations , dimension , constFunc) { this._gl = gl this._wrapper = wrapper this._index = index this._locations = locations this._dimension = dimension this._constFunc = constFunc } var proto = ShaderAttribute.prototype proto.pointer = function setAttribPointer( type , normalized , stride , offset) { var self = this var gl = self._gl var location = self._locations[self._index] gl.vertexAttribPointer( location , self._dimension , type || gl.FLOAT , !!normalized , stride || 0 , offset || 0) gl.enableVertexAttribArray(location) } proto.set = function(x0, x1, x2, x3) { return this._constFunc(this._locations[this._index], x0, x1, x2, x3) } Object.defineProperty(proto, 'location', { get: function() { return this._locations[this._index] } , set: function(v) { if(v !== this._locations[this._index]) { this._locations[this._index] = v|0 this._wrapper.program = null } return v|0 } }) //Adds a vector attribute to obj function addVectorAttribute( gl , wrapper , index , locations , dimension , obj , name) { //Construct constant function var constFuncArgs = [ 'gl', 'v' ] var varNames = [] for(var i=0; i= 0) { var d = type.charCodeAt(type.length-1) - 48 if(d < 2 || d > 4) { throw new GLError('', 'Invalid data type for attribute ' + name + ': ' + type) } addVectorAttribute( gl , wrapper , locs[0] , locations , d , obj , name) } else if(type.indexOf('mat') >= 0) { var d = type.charCodeAt(type.length-1) - 48 if(d < 2 || d > 4) { throw new GLError('', 'Invalid data type for attribute ' + name + ': ' + type) } addMatrixAttribute( gl , wrapper , locs , locations , d , obj , name) } else { throw new GLError('', 'Unknown data type for attribute ' + name + ': ' + type) } break } } return obj }