gpu: make Texture an enum with methods

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-15 00:25:36 -07:00 committed by Stephen Gutekanst
parent 2a65690ffc
commit 05f153009d
2 changed files with 158 additions and 154 deletions

View file

@ -1,29 +1,32 @@
const std = @import("std"); const std = @import("std");
ptr: *anyopaque, pub const Texture = enum(usize) {
_,
pub const Aspect = enum(u32) { pub const none: Texture = @intToEnum(Texture, 0);
pub const Aspect = enum(u32) {
all = 0x00000000, all = 0x00000000,
stencil_only = 0x00000001, stencil_only = 0x00000001,
depth_only = 0x00000002, depth_only = 0x00000002,
plane0_only = 0x00000003, plane0_only = 0x00000003,
plane1_only = 0x00000004, plane1_only = 0x00000004,
}; };
pub const ComponentType = enum(u32) { pub const ComponentType = enum(u32) {
float = 0x00000000, float = 0x00000000,
sint = 0x00000001, sint = 0x00000001,
uint = 0x00000002, uint = 0x00000002,
depth_comparison = 0x00000003, depth_comparison = 0x00000003,
}; };
pub const Dimension = enum(u32) { pub const Dimension = enum(u32) {
dimension_1d = 0x00000000, dimension_1d = 0x00000000,
dimension_2d = 0x00000001, dimension_2d = 0x00000001,
dimension_3d = 0x00000002, dimension_3d = 0x00000002,
}; };
pub const Format = enum(u32) { pub const Format = enum(u32) {
undef = 0x00000000, undef = 0x00000000,
r8_unorm = 0x00000001, r8_unorm = 0x00000001,
r8_snorm = 0x00000002, r8_snorm = 0x00000002,
@ -120,18 +123,18 @@ pub const Format = enum(u32) {
astc12x12_unorm = 0x0000005d, astc12x12_unorm = 0x0000005d,
astc12x12_unorm_srgb = 0x0000005e, astc12x12_unorm_srgb = 0x0000005e,
r8_bg8_biplanar420_unorm = 0x0000005f, r8_bg8_biplanar420_unorm = 0x0000005f,
}; };
pub const SampleType = enum(u32) { pub const SampleType = enum(u32) {
undef = 0x00000000, undef = 0x00000000,
float = 0x00000001, float = 0x00000001,
unfilterable_float = 0x00000002, unfilterable_float = 0x00000002,
depth = 0x00000003, depth = 0x00000003,
sint = 0x00000004, sint = 0x00000004,
uint = 0x00000005, uint = 0x00000005,
}; };
pub const Usage = packed struct { pub const Usage = packed struct {
copy_src: bool = false, copy_src: bool = false,
copy_dst: bool = false, copy_dst: bool = false,
texture_binding: bool = false, texture_binding: bool = false,
@ -153,4 +156,5 @@ pub const Usage = packed struct {
pub fn equal(a: Usage, b: Usage) bool { pub fn equal(a: Usage, b: Usage) bool {
return @truncate(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b)); return @truncate(u6, @bitCast(u32, a)) == @truncate(u6, @bitCast(u32, b));
} }
};
}; };

View file

@ -31,7 +31,7 @@ pub const Sampler = @import("sampler.zig").Sampler;
pub const ShaderModule = @import("shader_module.zig").ShaderModule; pub const ShaderModule = @import("shader_module.zig").ShaderModule;
pub const Surface = @import("surface.zig").Surface; pub const Surface = @import("surface.zig").Surface;
pub const SwapChain = @import("swap_chain.zig").SwapChain; pub const SwapChain = @import("swap_chain.zig").SwapChain;
pub const Texture = @import("Texture.zig"); pub const Texture = @import("texture.zig").Texture;
pub const TextureView = @import("TextureView.zig"); pub const TextureView = @import("TextureView.zig");
pub const AlphaMode = @import("types.zig").AlphaMode; pub const AlphaMode = @import("types.zig").AlphaMode;
@ -59,7 +59,7 @@ test {
refAllDecls(@import("shader_module.zig")); refAllDecls(@import("shader_module.zig"));
refAllDecls(@import("surface.zig")); refAllDecls(@import("surface.zig"));
refAllDecls(@import("swap_chain.zig")); refAllDecls(@import("swap_chain.zig"));
refAllDecls(@import("Texture.zig")); refAllDecls(@import("texture.zig"));
refAllDecls(@import("TextureView.zig")); refAllDecls(@import("TextureView.zig"));
refAllDecls(@import("types.zig")); refAllDecls(@import("types.zig"));
} }