@@ -10,8 +10,8 @@ use bevy_utils::default;
10
10
#[ cfg( any( feature = "flate2" , feature = "ruzstd" ) ) ]
11
11
use ktx2:: SupercompressionScheme ;
12
12
use ktx2:: {
13
- BasicDataFormatDescriptor , ChannelTypeQualifiers , ColorModel , DataFormatDescriptorHeader ,
14
- Header , SampleInformation ,
13
+ ChannelTypeQualifiers , ColorModel , DfdBlockBasic , DfdBlockHeaderBasic , DfdHeader , Header ,
14
+ SampleInformation ,
15
15
} ;
16
16
use wgpu_types:: {
17
17
AstcBlock , AstcChannel , Extent3d , TextureDimension , TextureFormat , TextureViewDescriptor ,
@@ -45,28 +45,28 @@ pub fn ktx2_buffer_to_image(
45
45
// Handle supercompression
46
46
let mut levels = Vec :: new ( ) ;
47
47
if let Some ( supercompression_scheme) = supercompression_scheme {
48
- for ( _level , _level_data ) in ktx2. levels ( ) . enumerate ( ) {
48
+ for ( level_index , level ) in ktx2. levels ( ) . enumerate ( ) {
49
49
match supercompression_scheme {
50
50
#[ cfg( feature = "flate2" ) ]
51
51
SupercompressionScheme :: ZLIB => {
52
- let mut decoder = flate2:: bufread:: ZlibDecoder :: new ( _level_data ) ;
52
+ let mut decoder = flate2:: bufread:: ZlibDecoder :: new ( level . data ) ;
53
53
let mut decompressed = Vec :: new ( ) ;
54
54
decoder. read_to_end ( & mut decompressed) . map_err ( |err| {
55
55
TextureError :: SuperDecompressionError ( format ! (
56
- "Failed to decompress {supercompression_scheme:?} for mip {_level }: {err:?}" ,
56
+ "Failed to decompress {supercompression_scheme:?} for mip {level_index }: {err:?}" ,
57
57
) )
58
58
} ) ?;
59
59
levels. push ( decompressed) ;
60
60
}
61
61
#[ cfg( feature = "ruzstd" ) ]
62
62
SupercompressionScheme :: Zstandard => {
63
- let mut cursor = std:: io:: Cursor :: new ( _level_data ) ;
63
+ let mut cursor = std:: io:: Cursor :: new ( level . data ) ;
64
64
let mut decoder = ruzstd:: decoding:: StreamingDecoder :: new ( & mut cursor)
65
65
. map_err ( |err| TextureError :: SuperDecompressionError ( err. to_string ( ) ) ) ?;
66
66
let mut decompressed = Vec :: new ( ) ;
67
67
decoder. read_to_end ( & mut decompressed) . map_err ( |err| {
68
68
TextureError :: SuperDecompressionError ( format ! (
69
- "Failed to decompress {supercompression_scheme:?} for mip {_level }: {err:?}" ,
69
+ "Failed to decompress {supercompression_scheme:?} for mip {level_index }: {err:?}" ,
70
70
) )
71
71
} ) ?;
72
72
levels. push ( decompressed) ;
@@ -79,7 +79,7 @@ pub fn ktx2_buffer_to_image(
79
79
}
80
80
}
81
81
} else {
82
- levels = ktx2. levels ( ) . map ( < [ u8 ] > :: to_vec) . collect ( ) ;
82
+ levels = ktx2. levels ( ) . map ( |level| level . data . to_vec ( ) ) . collect ( ) ;
83
83
}
84
84
85
85
// Identify the format
@@ -397,16 +397,15 @@ pub fn ktx2_get_texture_format<Data: AsRef<[u8]>>(
397
397
return ktx2_format_to_texture_format ( format, is_srgb) ;
398
398
}
399
399
400
- for data_format_descriptor in ktx2. data_format_descriptors ( ) {
401
- if data_format_descriptor. header == DataFormatDescriptorHeader :: BASIC {
402
- let basic_data_format_descriptor =
403
- BasicDataFormatDescriptor :: parse ( data_format_descriptor. data )
404
- . map_err ( |err| TextureError :: InvalidData ( format ! ( "KTX2: {err:?}" ) ) ) ?;
400
+ for data_format_descriptor in ktx2. dfd_blocks ( ) {
401
+ if data_format_descriptor. header == DfdHeader :: BASIC {
402
+ let basic_data_format_descriptor = DfdBlockBasic :: parse ( data_format_descriptor. data )
403
+ . map_err ( |err| TextureError :: InvalidData ( format ! ( "KTX2: {err:?}" ) ) ) ?;
405
404
let sample_information = basic_data_format_descriptor
406
405
. sample_information ( )
407
406
. collect :: < Vec < _ > > ( ) ;
408
- return ktx2_dfd_to_texture_format (
409
- & basic_data_format_descriptor,
407
+ return ktx2_dfd_header_to_texture_format (
408
+ & basic_data_format_descriptor. header ,
410
409
& sample_information,
411
410
is_srgb,
412
411
) ;
@@ -476,8 +475,8 @@ fn sample_information_to_data_type(
476
475
}
477
476
478
477
#[ cfg( feature = "ktx2" ) ]
479
- pub fn ktx2_dfd_to_texture_format (
480
- data_format_descriptor : & BasicDataFormatDescriptor ,
478
+ pub fn ktx2_dfd_header_to_texture_format (
479
+ data_format_descriptor : & DfdBlockHeaderBasic ,
481
480
sample_information : & [ SampleInformation ] ,
482
481
is_srgb : bool ,
483
482
) -> Result < TextureFormat , TextureError > {
@@ -495,7 +494,7 @@ pub fn ktx2_dfd_to_texture_format(
495
494
496
495
let sample = & sample_information[ 0 ] ;
497
496
let data_type = sample_information_to_data_type ( sample, false ) ?;
498
- match sample. bit_length {
497
+ match sample. bit_length . get ( ) {
499
498
8 => match data_type {
500
499
DataType :: Unorm => TextureFormat :: R8Unorm ,
501
500
DataType :: UnormSrgb => {
@@ -577,7 +576,7 @@ pub fn ktx2_dfd_to_texture_format(
577
576
578
577
let sample = & sample_information[ 0 ] ;
579
578
let data_type = sample_information_to_data_type ( sample, false ) ?;
580
- match sample. bit_length {
579
+ match sample. bit_length . get ( ) {
581
580
8 => match data_type {
582
581
DataType :: Unorm => TextureFormat :: Rg8Unorm ,
583
582
DataType :: UnormSrgb => {
@@ -635,27 +634,27 @@ pub fn ktx2_dfd_to_texture_format(
635
634
}
636
635
3 => {
637
636
if sample_information[ 0 ] . channel_type == 0
638
- && sample_information[ 0 ] . bit_length == 11
637
+ && sample_information[ 0 ] . bit_length . get ( ) == 11
639
638
&& sample_information[ 1 ] . channel_type == 1
640
- && sample_information[ 1 ] . bit_length == 11
639
+ && sample_information[ 1 ] . bit_length . get ( ) == 11
641
640
&& sample_information[ 2 ] . channel_type == 2
642
- && sample_information[ 2 ] . bit_length == 10
641
+ && sample_information[ 2 ] . bit_length . get ( ) == 10
643
642
{
644
643
TextureFormat :: Rg11b10Ufloat
645
644
} else if sample_information[ 0 ] . channel_type == 0
646
- && sample_information[ 0 ] . bit_length == 9
645
+ && sample_information[ 0 ] . bit_length . get ( ) == 9
647
646
&& sample_information[ 1 ] . channel_type == 1
648
- && sample_information[ 1 ] . bit_length == 9
647
+ && sample_information[ 1 ] . bit_length . get ( ) == 9
649
648
&& sample_information[ 2 ] . channel_type == 2
650
- && sample_information[ 2 ] . bit_length == 9
649
+ && sample_information[ 2 ] . bit_length . get ( ) == 9
651
650
{
652
651
TextureFormat :: Rgb9e5Ufloat
653
652
} else if sample_information[ 0 ] . channel_type == 0
654
- && sample_information[ 0 ] . bit_length == 8
653
+ && sample_information[ 0 ] . bit_length . get ( ) == 8
655
654
&& sample_information[ 1 ] . channel_type == 1
656
- && sample_information[ 1 ] . bit_length == 8
655
+ && sample_information[ 1 ] . bit_length . get ( ) == 8
657
656
&& sample_information[ 2 ] . channel_type == 2
658
- && sample_information[ 2 ] . bit_length == 8
657
+ && sample_information[ 2 ] . bit_length . get ( ) == 8
659
658
{
660
659
return Err ( TextureError :: FormatRequiresTranscodingError (
661
660
TranscodeFormat :: Rgb8 ,
@@ -681,10 +680,10 @@ pub fn ktx2_dfd_to_texture_format(
681
680
assert_eq ! ( sample_information[ 3 ] . channel_type, 15 ) ;
682
681
683
682
// Handle one special packed format
684
- if sample_information[ 0 ] . bit_length == 10
685
- && sample_information[ 1 ] . bit_length == 10
686
- && sample_information[ 2 ] . bit_length == 10
687
- && sample_information[ 3 ] . bit_length == 2
683
+ if sample_information[ 0 ] . bit_length . get ( ) == 10
684
+ && sample_information[ 1 ] . bit_length . get ( ) == 10
685
+ && sample_information[ 2 ] . bit_length . get ( ) == 10
686
+ && sample_information[ 3 ] . bit_length . get ( ) == 2
688
687
{
689
688
return Ok ( TextureFormat :: Rgb10a2Unorm ) ;
690
689
}
@@ -708,7 +707,7 @@ pub fn ktx2_dfd_to_texture_format(
708
707
709
708
let sample = & sample_information[ 0 ] ;
710
709
let data_type = sample_information_to_data_type ( sample, is_srgb) ?;
711
- match sample. bit_length {
710
+ match sample. bit_length . get ( ) {
712
711
8 => match data_type {
713
712
DataType :: Unorm => {
714
713
if is_rgba {
@@ -896,7 +895,7 @@ pub fn ktx2_dfd_to_texture_format(
896
895
Some ( ColorModel :: XYZW ) => {
897
896
// Same number of channels in both texel block dimensions and sample info descriptions
898
897
assert_eq ! (
899
- data_format_descriptor. texel_block_dimensions[ 0 ] as usize ,
898
+ data_format_descriptor. texel_block_dimensions[ 0 ] . get ( ) as usize ,
900
899
sample_information. len( )
901
900
) ;
902
901
match sample_information. len ( ) {
@@ -935,7 +934,7 @@ pub fn ktx2_dfd_to_texture_format(
935
934
936
935
let sample = & sample_information[ 0 ] ;
937
936
let data_type = sample_information_to_data_type ( sample, false ) ?;
938
- match sample. bit_length {
937
+ match sample. bit_length . get ( ) {
939
938
8 => match data_type {
940
939
DataType :: Unorm => TextureFormat :: Rgba8Unorm ,
941
940
DataType :: UnormSrgb => {
@@ -1124,8 +1123,8 @@ pub fn ktx2_dfd_to_texture_format(
1124
1123
} ,
1125
1124
Some ( ColorModel :: ASTC ) => TextureFormat :: Astc {
1126
1125
block : match (
1127
- data_format_descriptor. texel_block_dimensions [ 0 ] ,
1128
- data_format_descriptor. texel_block_dimensions [ 1 ] ,
1126
+ data_format_descriptor. texel_block_dimensions [ 0 ] . get ( ) ,
1127
+ data_format_descriptor. texel_block_dimensions [ 1 ] . get ( ) ,
1129
1128
) {
1130
1129
( 4 , 4 ) => AstcBlock :: B4x4 ,
1131
1130
( 5 , 4 ) => AstcBlock :: B5x4 ,
0 commit comments