gpu: implement Sampler
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
1563fc7246
commit
b29fa9e13d
5 changed files with 63 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ const ShaderModule = @import("ShaderModule.zig");
|
|||
const SwapChain = @import("SwapChain.zig");
|
||||
const TextureView = @import("TextureView.zig");
|
||||
const Texture = @import("Texture.zig");
|
||||
const Sampler = @import("Sampler.zig");
|
||||
|
||||
const TextureUsage = @import("enums.zig").TextureUsage;
|
||||
const TextureFormat = @import("enums.zig").TextureFormat;
|
||||
|
|
@ -539,6 +540,26 @@ const texture_vtable = Texture.VTable{
|
|||
}).release,
|
||||
};
|
||||
|
||||
fn wrapSampler(sampler: c.WGPUSampler) Sampler {
|
||||
return .{
|
||||
.ptr = sampler.?,
|
||||
.vtable = &sampler_vtable,
|
||||
};
|
||||
}
|
||||
|
||||
const sampler_vtable = Sampler.VTable{
|
||||
.reference = (struct {
|
||||
pub fn reference(ptr: *anyopaque) void {
|
||||
c.wgpuSamplerReference(@ptrCast(c.WGPUSampler, ptr));
|
||||
}
|
||||
}).reference,
|
||||
.release = (struct {
|
||||
pub fn release(ptr: *anyopaque) void {
|
||||
c.wgpuSamplerRelease(@ptrCast(c.WGPUSampler, ptr));
|
||||
}
|
||||
}).release,
|
||||
};
|
||||
|
||||
test "syntax" {
|
||||
_ = wrap;
|
||||
_ = interface_vtable;
|
||||
|
|
@ -554,4 +575,5 @@ test "syntax" {
|
|||
_ = wrapSwapChain;
|
||||
_ = wrapTextureView;
|
||||
_ = wrapTexture;
|
||||
_ = wrapSampler;
|
||||
}
|
||||
|
|
|
|||
27
gpu/src/Sampler.zig
Normal file
27
gpu/src/Sampler.zig
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const Sampler = @This();
|
||||
|
||||
/// The type erased pointer to the Sampler implementation
|
||||
/// Equal to c.WGPUSampler 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 wgpuSamplerSetLabel(WGPUSampler sampler, char const * label);
|
||||
};
|
||||
|
||||
pub inline fn reference(sampler: Sampler) void {
|
||||
sampler.vtable.reference(sampler.ptr);
|
||||
}
|
||||
|
||||
pub inline fn release(sampler: Sampler) void {
|
||||
sampler.vtable.release(sampler.ptr);
|
||||
}
|
||||
|
||||
test "syntax" {
|
||||
_ = VTable;
|
||||
_ = reference;
|
||||
_ = release;
|
||||
}
|
||||
|
|
@ -21,3 +21,9 @@ pub inline fn reference(texture: Texture) void {
|
|||
pub inline fn release(texture: Texture) void {
|
||||
texture.vtable.release(texture.ptr);
|
||||
}
|
||||
|
||||
test "syntax" {
|
||||
_ = VTable;
|
||||
_ = reference;
|
||||
_ = release;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,3 +19,9 @@ pub inline fn reference(texture_view: TextureView) void {
|
|||
pub inline fn release(texture_view: TextureView) void {
|
||||
texture_view.vtable.release(texture_view.ptr);
|
||||
}
|
||||
|
||||
test "syntax" {
|
||||
_ = VTable;
|
||||
_ = reference;
|
||||
_ = release;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ 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 Sampler = @import("Sampler.zig");
|
||||
|
||||
pub const Feature = @import("enums.zig").Feature;
|
||||
pub const TextureUsage = @import("enums.zig").TextureUsage;
|
||||
|
|
@ -98,6 +99,7 @@ test "syntax" {
|
|||
_ = SwapChain;
|
||||
_ = TextureView;
|
||||
_ = Texture;
|
||||
_ = Sampler;
|
||||
|
||||
_ = Feature;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue