gpu: implement TextureView

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-09 11:38:41 -07:00 committed by Stephen Gutekanst
parent 6338300fb3
commit 13b4a93a87
3 changed files with 45 additions and 0 deletions

View file

@ -20,6 +20,7 @@ const Queue = @import("Queue.zig");
const CommandBuffer = @import("CommandBuffer.zig");
const ShaderModule = @import("ShaderModule.zig");
const SwapChain = @import("SwapChain.zig");
const TextureView = @import("TextureView.zig");
const TextureUsage = @import("enums.zig").TextureUsage;
const TextureFormat = @import("enums.zig").TextureFormat;
@ -497,6 +498,26 @@ const swap_chain_vtable = SwapChain.VTable{
}).configure,
};
fn wrapTextureView(texture_view: c.WGPUTextureView) TextureView {
return .{
.ptr = texture_view.?,
.vtable = &texture_view_vtable,
};
}
const texture_view_vtable = TextureView.VTable{
.reference = (struct {
pub fn reference(ptr: *anyopaque) void {
c.wgpuTextureViewReference(@ptrCast(c.WGPUTextureView, ptr));
}
}).reference,
.release = (struct {
pub fn release(ptr: *anyopaque) void {
c.wgpuTextureViewRelease(@ptrCast(c.WGPUTextureView, ptr));
}
}).release,
};
test "syntax" {
_ = wrap;
_ = interface_vtable;
@ -510,4 +531,5 @@ test "syntax" {
_ = wrapQueue;
_ = wrapShaderModule;
_ = wrapSwapChain;
_ = wrapTextureView;
}

21
gpu/src/TextureView.zig Normal file
View file

@ -0,0 +1,21 @@
const TextureView = @This();
/// The type erased pointer to the TextureView implementation
/// Equal to c.WGPUTextureView for NativeInstance.
ptr: *anyopaque,
vtable: *const VTable,
pub const VTable = struct {
reference: fn (ptr: *anyopaque) void,
release: fn (ptr: *anyopaque) void,
// TODO:
// WGPU_EXPORT void wgpuTextureViewSetLabel(WGPUTextureView textureView, char const * label);
};
pub inline fn reference(texture_view: TextureView) void {
texture_view.vtable.reference(texture_view.ptr);
}
pub inline fn release(texture_view: TextureView) void {
texture_view.vtable.release(texture_view.ptr);
}

View file

@ -35,6 +35,7 @@ pub const Queue = @import("Queue.zig");
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 Feature = @import("enums.zig").Feature;
pub const TextureUsage = @import("enums.zig").TextureUsage;
@ -94,6 +95,7 @@ test "syntax" {
_ = CommandBuffer;
_ = ShaderModule;
_ = SwapChain;
_ = TextureView;
_ = Feature;
}