InputNode.js 872 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Node from './Node.js';
  2. class InputNode extends Node {
  3. constructor( type ) {
  4. super( type );
  5. this.constant = false;
  6. Object.defineProperty( this, 'isInputNode', { value: true } );
  7. }
  8. setConst( value ) {
  9. this.constant = value;
  10. return this;
  11. }
  12. getConst() {
  13. return this.constant;
  14. }
  15. generateConst( builder ) {
  16. return builder.getConst( this.getType( builder ), this.value );
  17. }
  18. generate( builder, output ) {
  19. const type = this.getType( builder );
  20. if ( this.constant === true ) {
  21. return builder.format( this.generateConst( builder ), type, output );
  22. } else {
  23. const nodeUniform = builder.getUniformFromNode( this, builder.shaderStage, this.getType( builder ) );
  24. const propertyName = builder.getPropertyName( nodeUniform );
  25. return builder.format( propertyName, type, output );
  26. }
  27. }
  28. }
  29. export default InputNode;