Source: dependencies/pixi-gl-core/shader/extractAttributes.js

dependencies/pixi-gl-core/shader/extractAttributes.js

  1. var mapType = require('./mapType');
  2. var mapSize = require('./mapSize');
  3. /**
  4. * Extracts the attributes
  5. * @class
  6. * @memberof PIXI.glCore.shader
  7. * @param gl {WebGLRenderingContext} The current WebGL rendering context
  8. * @param program {WebGLProgram} The shader program to get the attributes from
  9. * @return attributes {Object}
  10. */
  11. var extractAttributes = function(gl, program)
  12. {
  13. var attributes = {};
  14. var totalAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  15. for (var i = 0; i < totalAttributes; i++)
  16. {
  17. var attribData = gl.getActiveAttrib(program, i);
  18. var type = mapType(gl, attribData.type);
  19. attributes[attribData.name] = {
  20. type:type,
  21. size:mapSize(type),
  22. location:gl.getAttribLocation(program, attribData.name),
  23. //TODO - make an attribute object
  24. pointer: pointer
  25. };
  26. }
  27. return attributes;
  28. };
  29. var pointer = function(type, normalized, stride, start){
  30. // console.log(this.location)
  31. gl.vertexAttribPointer(this.location,this.size, type || gl.FLOAT, normalized || false, stride || 0, start || 0);
  32. };
  33. module.exports = extractAttributes;