basisu: use @bitCast for casting bit fields
This commit is contained in:
parent
1572ed7fc6
commit
b5e6fb6c4f
2 changed files with 8 additions and 68 deletions
|
|
@ -94,11 +94,11 @@ pub const CompressorParams = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getPackUASTCFlags(self: CompressorParams) PackUASTCFlags {
|
pub fn getPackUASTCFlags(self: CompressorParams) PackUASTCFlags {
|
||||||
return PackUASTCFlags.from(b.compressor_params_get_pack_uastc_flags(self.handle));
|
return @bitCast(PackUASTCFlags, b.compressor_params_get_pack_uastc_flags(self.handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setPackUASTCFlags(self: CompressorParams, flags: PackUASTCFlags) void {
|
pub fn setPackUASTCFlags(self: CompressorParams, flags: PackUASTCFlags) void {
|
||||||
b.compressor_params_set_pack_uastc_flags(self.handle, flags.cast());
|
b.compressor_params_set_pack_uastc_flags(self.handle, @bitCast(u32, flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setBasisFormat(self: CompressorParams, format: BasisTextureFormat) void {
|
pub fn setBasisFormat(self: CompressorParams, format: BasisTextureFormat) void {
|
||||||
|
|
@ -209,48 +209,14 @@ pub const PackUASTCFlags = packed struct {
|
||||||
default: bool = false,
|
default: bool = false,
|
||||||
slower: bool = false,
|
slower: bool = false,
|
||||||
verySlow: bool = false,
|
verySlow: bool = false,
|
||||||
mask: bool = false,
|
|
||||||
favor_uastc_error: bool = false,
|
favor_uastc_error: bool = false,
|
||||||
favor_bc7_error: bool = false,
|
favor_bc7_error: bool = false,
|
||||||
|
_padding: u1 = 0,
|
||||||
etc1_faster_hints: bool = false,
|
etc1_faster_hints: bool = false,
|
||||||
etc1_fastest_hints: bool = false,
|
etc1_fastest_hints: bool = false,
|
||||||
etc1_disable_flip_and_individual: bool = false,
|
etc1_disable_flip_and_individual: bool = false,
|
||||||
favor_simpler_modes: bool = false,
|
favor_simpler_modes: bool = false,
|
||||||
|
_padding0: u20 = 0,
|
||||||
pub const Flag = enum(u32) {
|
|
||||||
fastest = 0,
|
|
||||||
faster = 1,
|
|
||||||
default = 2,
|
|
||||||
slower = 3,
|
|
||||||
verySlow = 4,
|
|
||||||
mask = 0xF,
|
|
||||||
favor_uastc_error = 8,
|
|
||||||
favor_bc7_error = 16,
|
|
||||||
etc1_faster_hints = 64,
|
|
||||||
etc1_fastest_hints = 128,
|
|
||||||
etc1_disable_flip_and_individual = 256,
|
|
||||||
favor_simpler_modes = 512,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn from(bits: u32) PackUASTCFlags {
|
|
||||||
var value = PackUASTCFlags{};
|
|
||||||
inline for (comptime std.meta.fieldNames(Flag)) |field_name| {
|
|
||||||
if (bits & (@enumToInt(@field(Flag, field_name))) != 0) {
|
|
||||||
@field(value, field_name) = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cast(self: PackUASTCFlags) u32 {
|
|
||||||
var value: u32 = 0;
|
|
||||||
inline for (comptime std.meta.fieldNames(Flag)) |field_name| {
|
|
||||||
if (@field(self, field_name)) {
|
|
||||||
value |= @enumToInt(@field(Flag, field_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ColorSpace = enum {
|
pub const ColorSpace = enum {
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ pub const Transcoder = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const TranscodeParams = struct {
|
pub const TranscodeParams = struct {
|
||||||
decode_flags: ?DecodeFlags = null,
|
decode_flags: DecodeFlags = .{},
|
||||||
/// Output row pitch in blocks or pixels.
|
/// Output row pitch in blocks or pixels.
|
||||||
/// Should be at least the image level's total_blocks (num_blocks_x * num_blocks_y),
|
/// Should be at least the image level's total_blocks (num_blocks_x * num_blocks_y),
|
||||||
/// or the total number of output pixels if fmt==cTFRGBA32.
|
/// or the total number of output pixels if fmt==cTFRGBA32.
|
||||||
|
|
@ -104,7 +104,7 @@ pub const Transcoder = struct {
|
||||||
image_index,
|
image_index,
|
||||||
level_index,
|
level_index,
|
||||||
@enumToInt(format),
|
@enumToInt(format),
|
||||||
if (params.decode_flags) |f| f.cast() else 0,
|
@bitCast(u32, params.decode_flags),
|
||||||
params.output_row_pitch orelse 0,
|
params.output_row_pitch orelse 0,
|
||||||
params.output_rows orelse 0,
|
params.output_rows orelse 0,
|
||||||
)) return error.Unknown;
|
)) return error.Unknown;
|
||||||
|
|
@ -117,39 +117,13 @@ pub const Transcoder = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DecodeFlags = packed struct {
|
pub const DecodeFlags = packed struct {
|
||||||
|
_padding: u1 = 0,
|
||||||
pvrtc_decode_to_next_pow_2: bool = false,
|
pvrtc_decode_to_next_pow_2: bool = false,
|
||||||
transcode_alpha_data_to_opaque_formats: bool = false,
|
transcode_alpha_data_to_opaque_formats: bool = false,
|
||||||
bc1_forbid_three_color_blocks: bool = false,
|
bc1_forbid_three_color_blocks: bool = false,
|
||||||
output_has_alpha_indices: bool = false,
|
output_has_alpha_indices: bool = false,
|
||||||
high_quality: bool = false,
|
high_quality: bool = false,
|
||||||
|
_padding0: u26 = 0,
|
||||||
pub const Flag = enum(u32) {
|
|
||||||
pvrtc_decode_to_next_pow_2 = 2,
|
|
||||||
transcode_alpha_data_to_opaque_formats = 4,
|
|
||||||
bc1_forbid_three_color_blocks = 8,
|
|
||||||
output_has_alpha_indices = 16,
|
|
||||||
high_quality = 32,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn from(bits: u32) DecodeFlags {
|
|
||||||
var value = DecodeFlags{};
|
|
||||||
inline for (comptime std.meta.fieldNames(Flag)) |field_name| {
|
|
||||||
if (bits & (@enumToInt(@field(Flag, field_name))) != 0) {
|
|
||||||
@field(value, field_name) = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cast(self: DecodeFlags) u32 {
|
|
||||||
var value: u32 = 0;
|
|
||||||
inline for (comptime std.meta.fieldNames(Flag)) |field_name| {
|
|
||||||
if (@field(self, field_name)) {
|
|
||||||
value |= @enumToInt(@field(Flag, field_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const TextureFormat = enum(u5) {
|
pub const TextureFormat = enum(u5) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue