Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file modified assets/environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2
Binary file not shown.
Binary file modified assets/environment_maps/pisa_specular_rgb9e5_zstd.ktx2
Binary file not shown.
Binary file modified assets/lightmaps/CornellBox-Box.zstd.ktx2
Binary file not shown.
Binary file modified assets/lightmaps/CornellBox-Large.zstd.ktx2
Binary file not shown.
Binary file modified assets/lightmaps/CornellBox-Small.zstd.ktx2
Binary file not shown.
Binary file modified assets/lightmaps/MixedLightingExample-Baked.zstd.ktx2
Binary file not shown.
Binary file modified assets/lightmaps/MixedLightingExample-MixedDirect.zstd.ktx2
Binary file not shown.
Binary file modified assets/lightmaps/MixedLightingExample-MixedIndirect.zstd.ktx2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified assets/textures/Ryfjallet_cubemap_astc4x4.ktx2
Binary file not shown.
Binary file modified assets/textures/Ryfjallet_cubemap_bc7.ktx2
Binary file not shown.
Binary file modified assets/textures/Ryfjallet_cubemap_etc2.ktx2
Binary file not shown.
Binary file modified crates/bevy_anti_alias/src/smaa/SMAAAreaLUT.ktx2
Binary file not shown.
Binary file modified crates/bevy_anti_alias/src/smaa/SMAASearchLUT.ktx2
Binary file not shown.
Binary file not shown.
Binary file modified crates/bevy_core_pipeline/src/tonemapping/luts/Blender_-11_12.ktx2
Binary file not shown.
Binary file modified crates/bevy_core_pipeline/src/tonemapping/luts/tony_mc_mapface.ktx2
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/bevy_image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ futures-lite = "2.0.1"
guillotiere = "0.6.0"
rectangle-pack = "0.4"
ddsfile = { version = "0.5.2", optional = true }
ktx2 = { version = "0.4.0", optional = true }
ktx2 = { version = "0.5.0", optional = true }
# For ktx2 supercompression
flate2 = { version = "1.0.22", optional = true }
zstd = { version = "0.13.3", optional = true }
Expand Down
33 changes: 12 additions & 21 deletions crates/bevy_image/src/ktx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use bevy_utils::default;
#[cfg(any(feature = "flate2", feature = "zstd_rust", feature = "zstd_c"))]
use ktx2::SupercompressionScheme;
use ktx2::{
ChannelTypeQualifiers, ColorModel, DfdBlockBasic, DfdBlockHeaderBasic, DfdHeader, Header,
SampleInformation,
dfd::{Basic, Block, ChannelTypeQualifiers, SampleInformation},
ColorModel, Header,
};
use wgpu_types::{
AstcBlock, AstcChannel, Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor,
Expand Down Expand Up @@ -402,17 +402,8 @@ pub fn ktx2_get_texture_format<Data: AsRef<[u8]>>(
}

for data_format_descriptor in ktx2.dfd_blocks() {
if data_format_descriptor.header == DfdHeader::BASIC {
let basic_data_format_descriptor = DfdBlockBasic::parse(data_format_descriptor.data)
.map_err(|err| TextureError::InvalidData(format!("KTX2: {err:?}")))?;
let sample_information = basic_data_format_descriptor
.sample_information()
.collect::<Vec<_>>();
return ktx2_dfd_header_to_texture_format(
&basic_data_format_descriptor.header,
&sample_information,
is_srgb,
);
if let Block::Basic(basic_data_format_descriptor) = data_format_descriptor {
return ktx2_dfd_header_to_texture_format(basic_data_format_descriptor, is_srgb);
}
}

Expand Down Expand Up @@ -485,11 +476,11 @@ fn sample_information_to_data_type(
/// Returns an error for invalid or unsupported texture formats.
#[cfg(feature = "ktx2")]
pub fn ktx2_dfd_header_to_texture_format(
data_format_descriptor: &DfdBlockHeaderBasic,
sample_information: &[SampleInformation],
basic_data_format_descriptor: &Basic,
is_srgb: bool,
) -> Result<TextureFormat, TextureError> {
Ok(match data_format_descriptor.color_model {
let sample_information = &basic_data_format_descriptor.sample_information;
Ok(match basic_data_format_descriptor.color_model {
Some(ColorModel::RGBSDA) => {
match sample_information.len() {
1 => {
Expand Down Expand Up @@ -898,13 +889,13 @@ pub fn ktx2_dfd_header_to_texture_format(
| Some(ColorModel::CIEXYY) => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"{:?}",
data_format_descriptor.color_model
basic_data_format_descriptor.color_model
)));
}
Some(ColorModel::XYZW) => {
// Same number of channels in both texel block dimensions and sample info descriptions
assert_eq!(
data_format_descriptor.texel_block_dimensions[0].get() as usize,
basic_data_format_descriptor.texel_block_dimensions[0].get() as usize,
sample_information.len()
);
match sample_information.len() {
Expand Down Expand Up @@ -1132,8 +1123,8 @@ pub fn ktx2_dfd_header_to_texture_format(
},
Some(ColorModel::ASTC) => TextureFormat::Astc {
block: match (
data_format_descriptor.texel_block_dimensions[0].get(),
data_format_descriptor.texel_block_dimensions[1].get(),
basic_data_format_descriptor.texel_block_dimensions[0].get(),
basic_data_format_descriptor.texel_block_dimensions[1].get(),
) {
(4, 4) => AstcBlock::B4x4,
(5, 4) => AstcBlock::B5x4,
Expand Down Expand Up @@ -1199,7 +1190,7 @@ pub fn ktx2_dfd_header_to_texture_format(
_ => {
return Err(TextureError::UnsupportedTextureFormat(format!(
"Unknown KTX2 color model: {:?}",
data_format_descriptor.color_model
basic_data_format_descriptor.color_model
)));
}
})
Expand Down