gpu: implement Texture.createView

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-03-15 21:14:57 -07:00 committed by Stephen Gutekanst
parent 9fae887555
commit 856c98c4c1
2 changed files with 24 additions and 2 deletions

View file

@ -786,6 +786,25 @@ const texture_vtable = Texture.VTable{
c.wgpuTextureDestroy(@ptrCast(c.WGPUTexture, ptr)); c.wgpuTextureDestroy(@ptrCast(c.WGPUTexture, ptr));
} }
}).destroy, }).destroy,
.createView = (struct {
pub fn createView(ptr: *anyopaque, descriptor: *const TextureView.Descriptor) TextureView {
const desc = c.WGPUTextureViewDescriptor{
.nextInChain = null,
.label = if (descriptor.label) |l| l else "",
.format = @enumToInt(descriptor.format),
.dimension = @enumToInt(descriptor.dimension),
.baseMipLevel = descriptor.base_mip_level,
.mipLevelCount = descriptor.mip_level_count,
.baseArrayLayer = descriptor.base_array_layer,
.arrayLayerCount = descriptor.array_layer_count,
.aspect = @enumToInt(descriptor.aspect),
};
return wrapTextureView(c.wgpuTextureCreateView(
@ptrCast(c.WGPUTexture, ptr),
&desc,
));
}
}).createView,
}; };
fn wrapSampler(sampler: c.WGPUSampler) Sampler { fn wrapSampler(sampler: c.WGPUSampler) Sampler {

View file

@ -12,10 +12,9 @@ vtable: *const VTable,
pub const VTable = struct { pub const VTable = struct {
reference: fn (ptr: *anyopaque) void, reference: fn (ptr: *anyopaque) void,
release: fn (ptr: *anyopaque) void, release: fn (ptr: *anyopaque) void,
// TODO:
// WGPU_EXPORT WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, WGPUTextureViewDescriptor const * descriptor);
destroy: fn (ptr: *anyopaque) void, destroy: fn (ptr: *anyopaque) void,
setLabel: fn (ptr: *anyopaque, label: [:0]const u8) void, setLabel: fn (ptr: *anyopaque, label: [:0]const u8) void,
createView: fn (ptr: *anyopaque, descriptor: *const TextureView.Descriptor) TextureView,
}; };
pub inline fn reference(texture: Texture) void { pub inline fn reference(texture: Texture) void {
@ -34,6 +33,10 @@ pub inline fn destroy(texture: Texture) void {
texture.vtable.destroy(texture.ptr); texture.vtable.destroy(texture.ptr);
} }
pub inline fn createView(texture: Texture, descriptor: *const TextureView.Descriptor) TextureView {
return texture.vtable.createView(texture.ptr, descriptor);
}
pub const Descriptor = struct { pub const Descriptor = struct {
label: ?[*:0]const u8 = null, label: ?[*:0]const u8 = null,
usage: Usage, usage: Usage,