AttributeNode.js 810 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import Node from './Node.js';
  2. import VaryNode from './VaryNode.js';
  3. class AttributeNode extends Node {
  4. constructor( attributeName, nodeType ) {
  5. super( nodeType );
  6. this._attributeName = attributeName;
  7. }
  8. getHash( builder ) {
  9. return this.getAttributeName( builder );
  10. }
  11. setAttributeName( attributeName ) {
  12. this._attributeName = attributeName;
  13. return this;
  14. }
  15. getAttributeName( /*builder*/ ) {
  16. return this._attributeName;
  17. }
  18. generate( builder ) {
  19. const attribute = builder.getAttribute( this.getAttributeName( builder ), this.getNodeType( builder ) );
  20. if ( builder.isShaderStage( 'vertex' ) ) {
  21. return attribute.name;
  22. } else {
  23. const nodeVary = new VaryNode( this );
  24. return nodeVary.build( builder, attribute.type );
  25. }
  26. }
  27. }
  28. export default AttributeNode;