From 258db701a7a825db05976e6157344f02161639f0 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Wed, 9 Mar 2022 01:14:40 -0700 Subject: [PATCH] gpu: add SwapChain.configure Signed-off-by: Stephen Gutekanst --- gpu/src/NativeInstance.zig | 11 +++++++++++ gpu/src/SwapChain.zig | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index e67dd1cd..ce24609e 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -484,6 +484,17 @@ const swap_chain_vtable = SwapChain.VTable{ c.wgpuSwapChainRelease(@ptrCast(c.WGPUSwapChain, ptr)); } }).release, + .configure = (struct { + pub fn configure(ptr: *anyopaque, format: TextureFormat, allowed_usage: TextureUsage, width: u32, height: u32) void { + c.wgpuSwapChainConfigure( + @ptrCast(c.WGPUSwapChain, ptr), + @enumToInt(format), + @enumToInt(allowed_usage), + width, + height, + ); + } + }).configure, }; test "syntax" { diff --git a/gpu/src/SwapChain.zig b/gpu/src/SwapChain.zig index 576fe3dc..ac772f38 100644 --- a/gpu/src/SwapChain.zig +++ b/gpu/src/SwapChain.zig @@ -13,8 +13,8 @@ vtable: *const VTable, pub const VTable = struct { reference: fn (ptr: *anyopaque) void, release: fn (ptr: *anyopaque) void, + configure: fn (ptr: *anyopaque, format: TextureFormat, allowed_usage: TextureUsage, width: u32, height: u32) void, // TODO: - // WGPU_EXPORT void wgpuSwapChainConfigure(WGPUSwapChain swapChain, WGPUTextureFormat format, WGPUTextureUsageFlags allowedUsage, uint32_t width, uint32_t height); // WGPU_EXPORT WGPUTextureView wgpuSwapChainGetCurrentTextureView(WGPUSwapChain swapChain); // WGPU_EXPORT void wgpuSwapChainPresent(WGPUSwapChain swapChain); }; @@ -27,6 +27,16 @@ pub inline fn release(swap_chain: SwapChain) void { swap_chain.vtable.release(swap_chain.ptr); } +pub inline fn configure( + swap_chain: SwapChain, + format: TextureFormat, + allowed_usage: TextureUsage, + width: u32, + height: u32, +) void { + swap_chain.vtable.configure(swap_chain.ptr, format, allowed_usage, width, height); +} + pub const Descriptor = struct { label: ?[]const u8 = null, usage: TextureUsage,