From 81301ea2c156ce30b2db188cd121ff53a47a1a10 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 11 Jul 2022 08:50:37 -0700 Subject: [PATCH] gpu: add ColorWriteMask flagset Signed-off-by: Stephen Gutekanst --- gpu/TODO-webgpu.h | 11 ----------- gpu/src/types.zig | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/gpu/TODO-webgpu.h b/gpu/TODO-webgpu.h index 48de99df..bf985f9d 100644 --- a/gpu/TODO-webgpu.h +++ b/gpu/TODO-webgpu.h @@ -1,16 +1,5 @@ typedef uint32_t WGPUFlags; -typedef enum WGPUColorWriteMask { - WGPUColorWriteMask_None = 0x00000000, - WGPUColorWriteMask_Red = 0x00000001, - WGPUColorWriteMask_Green = 0x00000002, - WGPUColorWriteMask_Blue = 0x00000004, - WGPUColorWriteMask_Alpha = 0x00000008, - WGPUColorWriteMask_All = 0x0000000F, - WGPUColorWriteMask_Force32 = 0x7FFFFFFF -} WGPUColorWriteMask; -typedef WGPUFlags WGPUColorWriteMaskFlags; - typedef enum WGPUMapMode { WGPUMapMode_None = 0x00000000, WGPUMapMode_Read = 0x00000001, diff --git a/gpu/src/types.zig b/gpu/src/types.zig index 705696e6..ec74ab4a 100644 --- a/gpu/src/types.zig +++ b/gpu/src/types.zig @@ -295,6 +295,35 @@ pub const VertexStepMode = enum(u32) { vertex_buffer_not_used = 0x00000002, }; +pub const ColorWriteMask = packed struct { + red: bool = false, + green: bool = false, + blue: bool = false, + alpha: bool = false, + + _pad0: u4 = 0, + _pad1: u8 = 0, + _pad2: u16 = 0, + + comptime { + std.debug.assert( + @sizeOf(@This()) == @sizeOf(u32) and + @bitSizeOf(@This()) == @bitSizeOf(u32), + ); + } + + pub const all = ColorWriteMask{ + .red = true, + .green = true, + .blue = true, + .alpha = true, + }; + + pub fn equal(a: ColorWriteMask, b: ColorWriteMask) bool { + return @bitCast(a, u32) == @bitCast(b, u32); + } +}; + test "BackendType name" { try testing.expectEqualStrings("Vulkan", BackendType.vulkan.name()); }