From 61ced8aa1946cc32de4328cc75b5faf6b77723be Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 14 Feb 2026 14:03:58 +0100 Subject: Refactor: add gpu_create_texture_view_2d helper Reduces WGPUTextureViewDescriptor boilerplate from 5-7 lines to 1-2. Helper supports optional mip_levels parameter (defaults to 1). Updated 17 call sites across gpu/, tests/, and tools/. Net: -82 lines. All tests passing (34/34). Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/gpu.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/gpu/gpu.cc') diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index cf5d85d..535de67 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -98,6 +98,20 @@ WGPUTextureView gpu_create_mip_view(WGPUTexture texture, return wgpuTextureCreateView(texture, &view_desc); } +WGPUTextureView gpu_create_texture_view_2d(WGPUTexture texture, + WGPUTextureFormat format, + uint32_t mip_levels) { + const WGPUTextureViewDescriptor view_desc = { + .format = format, + .dimension = WGPUTextureViewDimension_2D, + .baseMipLevel = 0, + .mipLevelCount = mip_levels, + .baseArrayLayer = 0, + .arrayLayerCount = 1, + }; + return wgpuTextureCreateView(texture, &view_desc); +} + RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, const char* shader_code, ResourceBinding* bindings, int num_bindings) { -- cgit v1.2.3