export class BufferUtil {

    public static createVertexBuffer(device: GPUDevice, data: Float32Array ): GPUBuffer {
        
        const buffer = device.createBuffer({
          size: data.byteLength,
          usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.VERTEX,
          mappedAtCreation: true,
        });

        new Float32Array(buffer.getMappedRange()).set(data);
        buffer.unmap();

        return buffer;
    }

    public static createIndexBuffer(device: GPUDevice, data: Uint16Array): GPUBuffer {
        
        const buffer = device.createBuffer({
          size: data.byteLength,          
          usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.INDEX,
          mappedAtCreation: true,
        });

        new Uint16Array(buffer.getMappedRange()).set(data);
        buffer.unmap();

        return buffer;
    }
}