gpu: implement Texture
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
13b4a93a87
commit
1563fc7246
4 changed files with 47 additions and 7 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
23
gpu/src/Texture.zig
Normal file
23
gpu/src/Texture.zig
Normal file
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue