diff --git a/gpu/src/NativeInstance.zig b/gpu/src/NativeInstance.zig index 6d2aaefc..58d45d1e 100644 --- a/gpu/src/NativeInstance.zig +++ b/gpu/src/NativeInstance.zig @@ -21,6 +21,7 @@ const CommandBuffer = @import("CommandBuffer.zig"); const ShaderModule = @import("ShaderModule.zig"); const SwapChain = @import("SwapChain.zig"); const TextureView = @import("TextureView.zig"); +const Texture = @import("Texture.zig"); const TextureUsage = @import("enums.zig").TextureUsage; const TextureFormat = @import("enums.zig").TextureFormat; @@ -518,6 +519,26 @@ const texture_view_vtable = TextureView.VTable{ }).release, }; +fn wrapTexture(texture: c.WGPUTexture) Texture { + return .{ + .ptr = texture.?, + .vtable = &texture_vtable, + }; +} + +const texture_vtable = Texture.VTable{ + .reference = (struct { + pub fn reference(ptr: *anyopaque) void { + c.wgpuTextureReference(@ptrCast(c.WGPUTexture, ptr)); + } + }).reference, + .release = (struct { + pub fn release(ptr: *anyopaque) void { + c.wgpuTextureRelease(@ptrCast(c.WGPUTexture, ptr)); + } + }).release, +}; + test "syntax" { _ = wrap; _ = interface_vtable; @@ -532,4 +553,5 @@ test "syntax" { _ = wrapShaderModule; _ = wrapSwapChain; _ = wrapTextureView; + _ = wrapTexture; } diff --git a/gpu/src/TODO b/gpu/src/TODO index dcac970a..053509d9 100644 --- a/gpu/src/TODO +++ b/gpu/src/TODO @@ -668,13 +668,6 @@ WGPU_EXPORT void wgpuSamplerSetLabel(WGPUSampler sampler, char const * label); WGPU_EXPORT void wgpuSamplerReference(WGPUSampler sampler); WGPU_EXPORT void wgpuSamplerRelease(WGPUSampler sampler); -// Methods of Texture -WGPU_EXPORT WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, WGPUTextureViewDescriptor const * descriptor); -WGPU_EXPORT void wgpuTextureDestroy(WGPUTexture texture); -WGPU_EXPORT void wgpuTextureSetLabel(WGPUTexture texture, char const * label); -WGPU_EXPORT void wgpuTextureReference(WGPUTexture texture); -WGPU_EXPORT void wgpuTextureRelease(WGPUTexture texture); - typedef enum WGPUSType { // webgpu.h upstream: WGPUSType_Invalid = 0x00000000, diff --git a/gpu/src/Texture.zig b/gpu/src/Texture.zig new file mode 100644 index 00000000..ec887184 --- /dev/null +++ b/gpu/src/Texture.zig @@ -0,0 +1,23 @@ +const Texture = @This(); + +/// The type erased pointer to the Texture implementation +/// Equal to c.WGPUTexture for NativeInstance. +ptr: *anyopaque, +vtable: *const VTable, + +pub const VTable = struct { + reference: fn (ptr: *anyopaque) void, + release: fn (ptr: *anyopaque) void, + // TODO: + // WGPU_EXPORT WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, WGPUTextureViewDescriptor const * descriptor); + // WGPU_EXPORT void wgpuTextureDestroy(WGPUTexture texture); + // WGPU_EXPORT void wgpuTextureSetLabel(WGPUTexture texture, char const * label); +}; + +pub inline fn reference(texture: Texture) void { + texture.vtable.reference(texture.ptr); +} + +pub inline fn release(texture: Texture) void { + texture.vtable.release(texture.ptr); +} diff --git a/gpu/src/main.zig b/gpu/src/main.zig index 20afd067..ed1c3799 100644 --- a/gpu/src/main.zig +++ b/gpu/src/main.zig @@ -36,6 +36,7 @@ pub const CommandBuffer = @import("CommandBuffer.zig"); pub const ShaderModule = @import("ShaderModule.zig"); pub const SwapChain = @import("SwapChain.zig"); pub const TextureView = @import("TextureView.zig"); +pub const Texture = @import("Texture.zig"); pub const Feature = @import("enums.zig").Feature; pub const TextureUsage = @import("enums.zig").TextureUsage; @@ -96,6 +97,7 @@ test "syntax" { _ = ShaderModule; _ = SwapChain; _ = TextureView; + _ = Texture; _ = Feature; }