InputNode.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. getInputHash( builder ) {
  19. return this.getHash( builder );
  20. }
  21. generateConst( builder ) {
  22. return builder.getConst( this.getNodeType( builder ), this.value );
  23. }
  24. generate( builder, output ) {
  25. const type = this.getNodeType( builder );
  26. if ( this.constant === true ) {
  27. return builder.format( this.generateConst( builder ), type, output );
  28. } else {
  29. const inputHash = this.getInputHash( builder );
  30. let sharedNode = builder.getNodeFromHash( inputHash );
  31. if ( sharedNode === undefined ) {
  32. builder.setHashNode( this, inputHash );
  33. sharedNode = this;
  34. }
  35. const inputType = sharedNode.getInputType( builder );
  36. const nodeUniform = builder.getUniformFromNode( sharedNode, builder.shaderStage, inputType );
  37. const propertyName = builder.getPropertyName( nodeUniform );
  38. return builder.format( propertyName, type, output );
  39. }
  40. }
  41. }
  42. InputNode.prototype.isInputNode = true;
  43. export default InputNode;