AttributeNode.js 739 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. setAttributeName( attributeName ) {
  9. this._attributeName = attributeName;
  10. return this;
  11. }
  12. getAttributeName( /*builder*/ ) {
  13. return this._attributeName;
  14. }
  15. generate( builder ) {
  16. const attribute = builder.getAttribute( this.getAttributeName( builder ), this.getNodeType( builder ) );
  17. if ( builder.isShaderStage( 'vertex' ) ) {
  18. return attribute.name;
  19. } else {
  20. const nodeVary = new VaryNode( this );
  21. return nodeVary.build( builder, attribute.type );
  22. }
  23. }
  24. }
  25. export default AttributeNode;