StorageBufferNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import BufferNode from './BufferNode.js';
  2. import { bufferAttribute } from './BufferAttributeNode.js';
  3. import { addNodeClass } from '../core/Node.js';
  4. import { nodeObject } from '../shadernode/ShaderNode.js';
  5. import { varying } from '../core/VaryingNode.js';
  6. class StorageBufferNode extends BufferNode {
  7. constructor( value, bufferType, bufferCount = 0 ) {
  8. super( value, bufferType, bufferCount );
  9. this.isStorageBufferNode = true;
  10. this._attribute = null;
  11. this._varying = null;
  12. }
  13. getInputType( /*builder*/ ) {
  14. return 'storageBuffer';
  15. }
  16. generate( builder ) {
  17. if ( builder.isAvailable( 'storageBuffer' ) ) return super.generate( builder );
  18. const nodeType = this.getNodeType( builder );
  19. if ( this._attribute === null ) {
  20. this._attribute = bufferAttribute( this.value );
  21. this._varying = varying( this._attribute );
  22. }
  23. const output = this._varying.build( builder, nodeType );
  24. builder.registerTransform( output, this._attribute );
  25. return output;
  26. }
  27. }
  28. export default StorageBufferNode;
  29. export const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) );
  30. addNodeClass( 'StorageBufferNode', StorageBufferNode );