InputNode.js 992 B

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