// This file is part of the 64k demo project. // It provides a generic uniform buffer helper to reduce boilerplate. // Templated on uniform struct type for type safety and automatic sizing. #pragma once #include "gpu/gpu.h" #include // Generic uniform buffer helper // Usage: // UniformBuffer uniforms_; // uniforms_.init(device); // uniforms_.update(queue, my_data); template class UniformBuffer { public: UniformBuffer() = default; // Initialize the uniform buffer with the device void init(WGPUDevice device) { buffer_ = gpu_create_buffer(device, sizeof(T), WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); } // Update the uniform buffer with new data void update(WGPUQueue queue, const T& data) { wgpuQueueWriteBuffer(queue, buffer_.buffer, 0, &data, sizeof(T)); } // Get the underlying GpuBuffer (for bind group creation) GpuBuffer& get() { return buffer_; } const GpuBuffer& get() const { return buffer_; } private: GpuBuffer buffer_; };