commit f3beb23e472b8e1e352a2d50c88ba31df3fd91ba
parent 86d1429ba7f6f766b881147453130004f2084bea
Author: Christian Ermann <christianermann@gmail.com>
Date: Wed, 7 May 2025 18:56:28 -0700
Configure surface
Diffstat:
3 files changed, 163 insertions(+), 1 deletion(-)
diff --git a/src/main.zig b/src/main.zig
@@ -105,4 +105,16 @@ pub fn main() !void {
const queue = device.getQueue();
defer queue.release();
+
+ surface.configure(&.{
+ .device = device,
+ .format = .bgra8_unorm,
+ .usage = .{ .render_attachment = true },
+ .view_format_count = 0,
+ .view_formats = null,
+ .alpha_mode = .auto,
+ .width = 640,
+ .height = 480,
+ .present_mode = .fifo,
+ });
}
diff --git a/src/surface.zig b/src/surface.zig
@@ -1,5 +1,22 @@
const c = @import("c.zig").c;
const ChainedStruct = @import("common.zig").ChainedStruct;
+const Device = @import("device.zig").Device;
+const texture = @import("texture.zig");
+
+const CompositeAlphaMode = enum(u32) {
+ auto = 0x00000000,
+ @"opaque" = 0x00000001,
+ premultiplied = 0x00000002,
+ unpremultiplied = 0x00000003,
+ inherit = 0x00000004,
+};
+
+const PresentMode = enum(u32) {
+ fifo = 0x00000000,
+ fifo_relaxed = 0x00000001,
+ immediate = 0x00000002,
+ mailbox = 0x00000003,
+};
// WGPUSurface
// WGPUSurfaceDescriptor
@@ -86,11 +103,27 @@ pub const Surface = opaque {
window: u64,
};
+ pub const Configuration = extern struct {
+ next: ?*const ChainedStruct = null,
+ device: *Device,
+ format: texture.Texture.Format,
+ usage: texture.Texture.Usage,
+ view_format_count: u64,
+ view_formats: ?[*]texture.Texture.Format,
+ alpha_mode: CompositeAlphaMode,
+ width: u32,
+ height: u32,
+ present_mode: PresentMode,
+ };
+
pub fn release(surface: *Surface) void {
c.wgpuSurfaceRelease(@ptrCast(surface));
}
- // configure(...)
+ pub fn configure(surface: *Surface, config: *const Configuration) void {
+ c.wgpuSurfaceConfigure(@ptrCast(surface), @ptrCast(config));
+ }
+
// getCapabilities(...)
// getCurrentTexture(...)
// present(...)
diff --git a/src/texture.zig b/src/texture.zig
@@ -0,0 +1,117 @@
+const c = @import("c.zig").c;
+
+pub const Texture = opaque {
+ pub const Aspect = enum(u32) {
+ all = 0x00000000,
+ stencil_only = 0x00000001,
+ depth_only = 0x00000002,
+ };
+
+ pub const Format = enum(u32) {
+ undefined = 0x00000000,
+ r8_unorm = 0x00000001,
+ r8_snorm = 0x00000002,
+ r8_uint = 0x00000003,
+ r8_sint = 0x00000004,
+ r16_uint = 0x00000005,
+ r16_sint = 0x00000006,
+ r16_float = 0x00000007,
+ rg8_unorm = 0x00000008,
+ rg8_snorm = 0x00000009,
+ rg8_uint = 0x0000000A,
+ rg8_sint = 0x0000000B,
+ r32_float = 0x0000000C,
+ r32_uint = 0x0000000D,
+ r32_sint = 0x0000000E,
+ rg16_uint = 0x0000000F,
+ rg16_sint = 0x00000010,
+ rg16_float = 0x00000011,
+ rgba8_unorm = 0x00000012,
+ rgba8_unorm_srgb = 0x00000013,
+ rgba8_snorm = 0x00000014,
+ rgba8_uint = 0x00000015,
+ rgba8_sint = 0x00000016,
+ bgra8_unorm = 0x00000017,
+ bgra8_unorm_srgb = 0x00000018,
+ rgb10a2_uint = 0x00000019,
+ rgb10a2_unorm = 0x0000001A,
+ rg11b10_ufloat = 0x0000001B,
+ rgb9e5_ufloat = 0x0000001C,
+ rg32_float = 0x0000001D,
+ rg32_uint = 0x0000001E,
+ rg32_sint = 0x0000001F,
+ rgba16_uint = 0x00000020,
+ rgba16_sint = 0x00000021,
+ rgba16_float = 0x00000022,
+ rgba32_float = 0x00000023,
+ rgba32_uint = 0x00000024,
+ rgba32_sint = 0x00000025,
+ stencil8 = 0x00000026,
+ depth16_unorm = 0x00000027,
+ depth24_plus = 0x00000028,
+ depth24_plus_stencil8 = 0x00000029,
+ depth32_float = 0x0000002A,
+ depth32_float_stencil8 = 0x0000002B,
+ bc1rgba_unorm = 0x0000002C,
+ bc1rgba_unorm_srgb = 0x0000002D,
+ bc2rgba_unorm = 0x0000002E,
+ bc2rgba_unorm_srgb = 0x0000002F,
+ bc3rgba_unorm = 0x00000030,
+ bc3rgba_unorm_srgb = 0x00000031,
+ bc4r_unorm = 0x00000032,
+ bc4r_snorm = 0x00000033,
+ bc5rg_unorm = 0x00000034,
+ bc5rg_snorm = 0x00000035,
+ bc6hrgb_ufloat = 0x00000036,
+ bc6hrgb_float = 0x00000037,
+ bc7rgba_unorm = 0x00000038,
+ bc7rgba_unorm_srgb = 0x00000039,
+ etc2rgb8_unorm = 0x0000003A,
+ etc2rgb8_unorm_srgb = 0x0000003B,
+ etc2rgb8a1_unorm = 0x0000003C,
+ etc2rgb8a1_unorm_srgb = 0x0000003D,
+ etc2rgba8_unorm = 0x0000003E,
+ etc2rgba8_unorm_srgb = 0x0000003F,
+ eacr11_unorm = 0x00000040,
+ eacr11_snorm = 0x00000041,
+ eacrg11_unorm = 0x00000042,
+ eacrg11_snorm = 0x00000043,
+ astc4x4_unorm = 0x00000044,
+ astc4x4_unorm_srgb = 0x00000045,
+ astc5x4_unorm = 0x00000046,
+ astc5x4_unorm_srgb = 0x00000047,
+ astc5x5_unorm = 0x00000048,
+ astc5x5_unorm_srgb = 0x00000049,
+ astc6x5_unorm = 0x0000004A,
+ astc6x5_unorm_srgb = 0x0000004B,
+ astc6x6_unorm = 0x0000004C,
+ astc6x6_unorm_srgb = 0x0000004D,
+ astc8x5_unorm = 0x0000004E,
+ astc8x5_unorm_srgb = 0x0000004F,
+ astc8x6_unorm = 0x00000050,
+ astc8x6_unorm_srgb = 0x00000051,
+ astc8x8_unorm = 0x00000052,
+ astc8x8_unorm_srgb = 0x00000053,
+ astc10x5_unorm = 0x00000054,
+ astc10x5_unorm_srgb = 0x00000055,
+ astc10x6_unorm = 0x00000056,
+ astc10x6_unorm_srgb = 0x00000057,
+ astc10x8_unorm = 0x00000058,
+ astc10x8_unorm_srgb = 0x00000059,
+ astc10x10_unorm = 0x0000005A,
+ astc10x10_unorm_srgb = 0x0000005B,
+ astc12x10_unorm = 0x0000005C,
+ astc12x10_unorm_srgb = 0x0000005D,
+ astc12x12_unorm = 0x0000005E,
+ astc12x12_unorm_srgb = 0x0000005F,
+ };
+
+ pub const Usage = packed struct(u32) {
+ copy_src: bool = false,
+ copy_dst: bool = false,
+ texture_binding: bool = false,
+ storage_binding: bool = false,
+ render_attachment: bool = false,
+ _padding: u27 = 0,
+ };
+};