WebGPUUniformBuffer.js 798 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import WebGPUBinding from './WebGPUBinding.js';
  2. import { getFloatLength } from './WebGPUBufferUtils.js';
  3. import { GPUBindingType } from './constants.js';
  4. class WebGPUUniformBuffer extends WebGPUBinding {
  5. constructor( name, buffer = null ) {
  6. super( name );
  7. this.bytesPerElement = Float32Array.BYTES_PER_ELEMENT;
  8. this.type = GPUBindingType.UniformBuffer;
  9. this.visibility = GPUShaderStage.VERTEX;
  10. this.usage = GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST;
  11. this.buffer = buffer;
  12. this.bufferGPU = null; // set by the renderer
  13. }
  14. getByteLength() {
  15. return getFloatLength( this.buffer.byteLength );
  16. }
  17. getBuffer() {
  18. return this.buffer;
  19. }
  20. update() {
  21. return true;
  22. }
  23. }
  24. WebGPUUniformBuffer.prototype.isUniformBuffer = true;
  25. export default WebGPUUniformBuffer;