diff --git a/.gitattributes b/.gitattributes index 2da5fc0..1ea9363 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ *.ktx2 filter=lfs diff=lfs merge=lfs -text vendor/basis_universal/**/* filter=lfs diff=lfs merge=lfs -text *.wasm filter=lfs diff=lfs merge=lfs -text +original_assets/**/* filter=lfs diff=lfs merge=lfs -text diff --git a/CHANGELOG.md b/CHANGELOG.md index d8e7a0e..421de74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- +- Update basis universal to v2.1.0 ## v0.4.2 diff --git a/Cargo.toml b/Cargo.toml old mode 100644 new mode 100755 index 5da4a69..3ca969b --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,8 @@ repository = "https://github.com/beicause/bevy_basisu_loader" license = "MIT OR Apache-2.0" [dependencies] +bevy_basisu_loader_sys = { version = "0.4", path = "crates/basisu_sys" } + bevy = { version = "0.18", default-features = false, features = [ "bevy_asset", "bevy_image", @@ -22,7 +24,6 @@ bevy = { version = "0.18", default-features = false, features = [ serde = { version = "1", features = ["derive"] } thiserror = { version = "2", default-features = false } log = { version = "0.4", default-features = false } -bevy_basisu_loader_sys = { version = "0.4", path = "crates/basisu_sys" } [workspace] members = ["crates/*", "examples/test_scene"] diff --git a/README.md b/README.md index fc1b736..0fef0da 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ For web, it contains a tool to build vendored basisu using Emscripten and produc | `bevy` | `bevy_basisu_loader` | `basis_universal` | | ------ | -------------------- | ----------------- | -| 0.18 | 0.3, 0.4 | v2_0_2 | +| 0.18 | 0.3, 0.4 | v2_1_0 | | 0.17 | 0.1, 0.2 | v1_60_snapshot | ## License diff --git a/assets/alpha0_etc1s.basisu.ktx2 b/assets/alpha0_etc1s.basisu.ktx2 deleted file mode 100644 index 8a28378..0000000 --- a/assets/alpha0_etc1s.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0f465f87625313a395c196e3e4401609b0503f2ae4c9a0900a5724c88cfa44d4 -size 895 diff --git a/assets/alpha0_etc1s_mips.basisu.ktx2 b/assets/alpha0_etc1s_mips.basisu.ktx2 new file mode 100644 index 0000000..3ede08a --- /dev/null +++ b/assets/alpha0_etc1s_mips.basisu.ktx2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a20e88c6c7f5b919d7f7dea7c8f2aff36a20a288e943e6fd695d690d0df0cb1e +size 2703 diff --git a/assets/desk_uastc_hdr_4x4.basisu.ktx2 b/assets/desk_uastc_hdr_4x4.basisu.ktx2 new file mode 100644 index 0000000..9920f7a --- /dev/null +++ b/assets/desk_uastc_hdr_4x4.basisu.ktx2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7f836174bfd19da0bfc74a0559ec8aa936d5a58144eb2c92059aafc47cf2f0e +size 529656 diff --git a/assets/desk_uastc_hdr_4x4_mips_10.basisu.ktx2 b/assets/desk_uastc_hdr_4x4_mips_10.basisu.ktx2 deleted file mode 100644 index 51ec002..0000000 --- a/assets/desk_uastc_hdr_4x4_mips_10.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bbdeaccabb5d94c66ca3915a01adcd4220da960825be06dbe5c4d043474adb43 -size 706010 diff --git a/assets/desk_uastc_hdr_6x6_mips.basisu.ktx2 b/assets/desk_uastc_hdr_6x6_mips.basisu.ktx2 new file mode 100644 index 0000000..b144eb4 --- /dev/null +++ b/assets/desk_uastc_hdr_6x6_mips.basisu.ktx2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e972c4c97de561e0fd8b562f9ecb2bb65beef7791408077887ef5b8e4d65d798 +size 307302 diff --git a/assets/desk_uastc_hdr_6x6_mips_10.basisu.ktx2 b/assets/desk_uastc_hdr_6x6_mips_10.basisu.ktx2 deleted file mode 100644 index 4a692e4..0000000 --- a/assets/desk_uastc_hdr_6x6_mips_10.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:97391ab639d8318359d723e67ccaec483af063818ea2698401e169393881f6f4 -size 324849 diff --git a/assets/gl_skybox_etc1s_cubemap_mips_12.basisu.ktx2 b/assets/gl_skybox_etc1s_cubemap_mips_12.basisu.ktx2 deleted file mode 100644 index 47db29c..0000000 --- a/assets/gl_skybox_etc1s_cubemap_mips_12.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:816e6392e4424564f813e161dd70c541c7c2b27659ddf6184267f9835a57716a -size 2008831 diff --git a/assets/gl_skybox_uastc_cubemap_mips_12.basisu.ktx2 b/assets/gl_skybox_uastc_cubemap_mips_12.basisu.ktx2 deleted file mode 100644 index 2812f52..0000000 --- a/assets/gl_skybox_uastc_cubemap_mips_12.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:92ceb057b61864abb03a7c75b1c332f39b7468277673b075d39494afc7eb7ced -size 19848120 diff --git a/assets/kodim20_astc_ldr_8x8.basisu.ktx2 b/assets/kodim20_astc_ldr_8x8.basisu.ktx2 deleted file mode 100644 index 7ae0f37..0000000 --- a/assets/kodim20_astc_ldr_8x8.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:cfdb672799ea2269d57dcaee05c65a78eed4e3f2a895044950db4c202135331d -size 77096 diff --git a/assets/kodim20_astc_ldr_8x8_mips.basisu.ktx2 b/assets/kodim20_astc_ldr_8x8_mips.basisu.ktx2 new file mode 100644 index 0000000..31df61e --- /dev/null +++ b/assets/kodim20_astc_ldr_8x8_mips.basisu.ktx2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66bfcf215a1f85723cc5fc512b492ab64f1ef2e094a764a7961895f306ada337 +size 104728 diff --git a/assets/skybox_xuastc_ldr_8x8_cubemap_mips.basisu.ktx2 b/assets/skybox_xuastc_ldr_8x8_cubemap_mips.basisu.ktx2 new file mode 100644 index 0000000..682aada --- /dev/null +++ b/assets/skybox_xuastc_ldr_8x8_cubemap_mips.basisu.ktx2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0fb708860a7b2e795f2b060fd6499431b440a28f0f5fbba8608937c7998ff18 +size 5550277 diff --git a/assets/tough_uastc_ldr_4x4.basisu.ktx2 b/assets/tough_uastc_ldr_4x4.basisu.ktx2 new file mode 100644 index 0000000..7f4384c --- /dev/null +++ b/assets/tough_uastc_ldr_4x4.basisu.ktx2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d68d26cf89099eebd52201b1dc353042a6d00a563731adea0daccab86e2a4bde +size 716194 diff --git a/assets/tough_uastc_ldr_4x4_mips_11.basisu.ktx2 b/assets/tough_uastc_ldr_4x4_mips_11.basisu.ktx2 deleted file mode 100644 index e504ef8..0000000 --- a/assets/tough_uastc_ldr_4x4_mips_11.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:0653667aee2587fae2862406a8ef766581004d4fabe5c97d39a288ff5bf4ffde -size 1062432 diff --git a/assets/wikipedia_xuastc_ldr_6x6.basisu.ktx2 b/assets/wikipedia_xuastc_ldr_6x6.basisu.ktx2 deleted file mode 100644 index 673c2c7..0000000 --- a/assets/wikipedia_xuastc_ldr_6x6.basisu.ktx2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d96379a8469d388af5fa45b000d69007a10b82f58642c202639b7ed815adbd8f -size 208564 diff --git a/assets/wikipedia_xuastc_ldr_6x6_mips.basisu.ktx2 b/assets/wikipedia_xuastc_ldr_6x6_mips.basisu.ktx2 new file mode 100644 index 0000000..203f6cd --- /dev/null +++ b/assets/wikipedia_xuastc_ldr_6x6_mips.basisu.ktx2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9e1b0c2fdfb4d97c064b163edfefd9411f5ce255a5671084b7050d4ec5dc565 +size 314666 diff --git a/crates/basisu_sys/build.rs b/crates/basisu_sys/build.rs index 8b12870..d4596a5 100644 --- a/crates/basisu_sys/build.rs +++ b/crates/basisu_sys/build.rs @@ -1,4 +1,5 @@ const FLAGS: &[&str] = &[ + "-Werror", "-fno-exceptions", "-Wno-unused-function", "-Wno-unused-const-variable", @@ -7,6 +8,7 @@ const FLAGS: &[&str] = &[ "-Wno-unused-value", "-Wno-deprecated", "-Wno-type-limits", + "-Wno-stringop-overflow", ]; // Disable PVRTC1/2, ATC, FXT1 as wgpu does not support them. const DEFINES: &[(&str, &str)] = &[ @@ -54,12 +56,19 @@ fn bindgen() { .use_core() .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .allowlist_type("Transcoder") - .allowlist_type("TextureTranscodedFormat") + .allowlist_type("TranscodedTextureFormat") + .allowlist_type("BasisTextureFormat") .allowlist_type("SupportedTextureCompressionMethods") + .allowlist_type("ChannelType") + .opaque_type("Transcoder") + .rustified_enum("TranscodedTextureFormat") + .rustified_enum("BasisTextureFormat") + .bitfield_enum("SupportedTextureCompressionMethods") + .rustified_enum("ChannelType") .allowlist_function("c_basisu_transcoder_init") .allowlist_function("c_ktx2_transcoder_new") .allowlist_function("c_ktx2_transcoder_delete") - .allowlist_function("c_ktx2_transcoder_transcode_image") + .allowlist_function("c_ktx2_transcoder_transcode_image_alloc_dst") .allowlist_function("c_ktx2_transcoder_get_r_dst_buf") .allowlist_function("c_ktx2_transcoder_get_r_dst_buf_len") .allowlist_function("c_ktx2_transcoder_get_r_width") @@ -68,11 +77,10 @@ fn bindgen() { .allowlist_function("c_ktx2_transcoder_get_r_layers") .allowlist_function("c_ktx2_transcoder_get_r_faces") .allowlist_function("c_ktx2_transcoder_get_r_target_format") + .allowlist_function("c_ktx2_transcoder_get_r_basis_format") .allowlist_function("c_ktx2_transcoder_get_r_is_srgb") - .opaque_type("Transcoder") - .bitfield_enum("SupportedTextureCompressionMethods") - .rustified_enum("TextureTranscodedFormat") - .rustified_enum("ChannelType") + .allowlist_function("c_ktx2_transcoder_transcode_image_get_info") + .allowlist_function("c_ktx2_transcoder_transcode_image_write_buffer") .generate() .expect("Unable to generate bindings") .write_to_file(binding_file) @@ -93,6 +101,9 @@ fn compile_basisu_static() { for (define, value) in DEFINES { build.define(define, *value); } + // FIXME: This works around a bug. + // With -O2 or -O3, the transcoded astc/uastc -> bcn textures have many artifacts, especially when -mipmap is enabled. But with -Os the results are much better. + build.opt_level_str("s"); build.files(SRCS).compile("basisu_vendor"); } @@ -103,11 +114,11 @@ fn gen_wasm_build_cmd() { "-sINCOMING_MODULE_JS_API=wasmBinary", "-sALLOW_MEMORY_GROWTH", "-sEXPORTED_RUNTIME_METHODS=HEAPU8", - "-sEXPORTED_FUNCTIONS=_malloc,_free,_c_basisu_transcoder_init,_c_ktx2_transcoder_new,_c_ktx2_transcoder_delete,_c_ktx2_transcoder_transcode_image,_c_ktx2_transcoder_get_r_dst_buf,_c_ktx2_transcoder_get_r_dst_buf_len,_c_ktx2_transcoder_get_r_width,_c_ktx2_transcoder_get_r_height,_c_ktx2_transcoder_get_r_levels,_c_ktx2_transcoder_get_r_layers,_c_ktx2_transcoder_get_r_faces,_c_ktx2_transcoder_get_r_target_format,_c_ktx2_transcoder_get_r_is_srgb", + "-sEXPORTED_FUNCTIONS=_malloc,_free,_c_basisu_transcoder_init,_c_ktx2_transcoder_new,_c_ktx2_transcoder_delete,_c_ktx2_transcoder_transcode_image_alloc_dst,_c_ktx2_transcoder_get_r_dst_buf,_c_ktx2_transcoder_get_r_dst_buf_len,_c_ktx2_transcoder_get_r_width,_c_ktx2_transcoder_get_r_height,_c_ktx2_transcoder_get_r_levels,_c_ktx2_transcoder_get_r_layers,_c_ktx2_transcoder_get_r_faces,_c_ktx2_transcoder_get_r_target_format,_c_ktx2_transcoder_get_r_basis_format,_c_ktx2_transcoder_get_r_is_srgb", ]; let mut cmd = std::process::Command::new("em++"); cmd.args(["-xc++", "-std=c++17"]) - .args(FLAGS) + .args(FLAGS.iter().filter(|f| **f != "-Wno-stringop-overflow")) .args( DEFINES .iter() diff --git a/crates/basisu_sys/src/lib.rs b/crates/basisu_sys/src/lib.rs index 01d65b3..bcb4cbc 100644 --- a/crates/basisu_sys/src/lib.rs +++ b/crates/basisu_sys/src/lib.rs @@ -13,23 +13,18 @@ extern crate alloc; non_camel_case_types, reason = "Generated code is OK to have non upper case globals or non camel case enums" )] -#[cfg_attr( - all( - target_arch = "wasm32", - target_vendor = "unknown", - target_os = "unknown" - ), - expect( - unused, - reason = "On wasm32 we use js bindings thus native functions are expected to be unused" - ) +#[expect( + unused, + reason = "On wasm32 we use js bindings thus all native functions are expected to be unused. \ + On native `c_ktx2_transcoder_transcode_image_alloc_dst` and `c_ktx2_transcoder_get_r_dst_buf` are unused" )] mod transcoding { include!(concat!(env!("OUT_DIR"), "/transcoding.rs")); } +use alloc::vec::Vec; pub use transcoding::{ - ChannelType, SupportedTextureCompressionMethods, TextureTranscodedFormat, Transcoder, + BasisTextureFormat, ChannelType, SupportedTextureCompressionMethods, TranscodedTextureFormat, }; #[cfg(not(all( @@ -43,7 +38,7 @@ mod native; target_vendor = "unknown", target_os = "unknown", )))] -pub use native::*; +use native::*; #[cfg(all( target_arch = "wasm32", @@ -56,4 +51,98 @@ mod web; target_vendor = "unknown", target_os = "unknown", ))] -pub use web::*; +use web::*; + +/// Init basisu global data. Must be called before transcoding. +pub async fn basisu_init() { + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown", + ))] + basisu_sys_init_vendor().await; + unsafe { + basisu_transcoder_init(); + } +} + +pub struct TranscodeResult { + pub data: Vec, + pub width: u32, + pub height: u32, + pub levels: u32, + pub layers: u32, + pub faces: u32, + pub is_srgb: bool, + pub basis_format: BasisTextureFormat, + pub target_format: TranscodedTextureFormat, +} + +/// Transcode the basisu ktx2 data. +pub fn basisu_transcode( + data: Vec, + supported_compressed_formats: SupportedTextureCompressionMethods, + channel_type_hint: ChannelType, + force_transcode_target: TranscodedTextureFormat, +) -> Option { + unsafe { + let transcoder = ktx2_transcoder_new(); + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown", + ))] + let result = { + let success = ktx2_transcoder_transcode_image_alloc_dst( + transcoder, + data, + supported_compressed_formats, + channel_type_hint, + force_transcode_target, + ); + if !success { + ktx2_transcoder_delete(transcoder); + return None; + } + ktx2_transcoder_get_r_dst_buf(transcoder) + }; + + #[cfg(not(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown", + )))] + let result = { + let success = ktx2_transcoder_transcode_image_get_info( + transcoder, + data.as_ptr(), + u32::try_from(data.len()).unwrap(), + supported_compressed_formats, + channel_type_hint, + force_transcode_target, + ); + if !success { + ktx2_transcoder_delete(transcoder); + return None; + } + let mut buffer = + alloc::vec![0u8; ktx2_transcoder_get_r_dst_buf_len(transcoder) as usize]; + ktx2_transcoder_transcode_image_write_buffer(transcoder, buffer.as_mut_ptr()); + buffer + }; + + let res = Some(TranscodeResult { + data: result, + width: ktx2_transcoder_get_r_width(transcoder), + height: ktx2_transcoder_get_r_height(transcoder), + levels: ktx2_transcoder_get_r_levels(transcoder), + layers: ktx2_transcoder_get_r_layers(transcoder), + faces: ktx2_transcoder_get_r_faces(transcoder), + is_srgb: ktx2_transcoder_get_r_is_srgb(transcoder), + target_format: ktx2_transcoder_get_r_target_format(transcoder), + basis_format: ktx2_transcoder_get_r_basis_format(transcoder), + }); + ktx2_transcoder_delete(transcoder); + res + } +} diff --git a/crates/basisu_sys/src/native.rs b/crates/basisu_sys/src/native.rs index 75045b5..7ee4351 100644 --- a/crates/basisu_sys/src/native.rs +++ b/crates/basisu_sys/src/native.rs @@ -1,14 +1,7 @@ -#![expect(clippy::missing_safety_doc, reason = "TODO")] - -use alloc::{vec, vec::Vec}; - -use crate::ChannelType; -use crate::SupportedTextureCompressionMethods; -use crate::TextureTranscodedFormat; -use crate::Transcoder; - pub use crate::transcoding::c_basisu_transcoder_init as basisu_transcoder_init; pub use crate::transcoding::c_ktx2_transcoder_delete as ktx2_transcoder_delete; +pub use crate::transcoding::c_ktx2_transcoder_get_r_basis_format as ktx2_transcoder_get_r_basis_format; +pub use crate::transcoding::c_ktx2_transcoder_get_r_dst_buf_len as ktx2_transcoder_get_r_dst_buf_len; pub use crate::transcoding::c_ktx2_transcoder_get_r_faces as ktx2_transcoder_get_r_faces; pub use crate::transcoding::c_ktx2_transcoder_get_r_height as ktx2_transcoder_get_r_height; pub use crate::transcoding::c_ktx2_transcoder_get_r_is_srgb as ktx2_transcoder_get_r_is_srgb; @@ -17,30 +10,5 @@ pub use crate::transcoding::c_ktx2_transcoder_get_r_levels as ktx2_transcoder_ge pub use crate::transcoding::c_ktx2_transcoder_get_r_target_format as ktx2_transcoder_get_r_target_format; pub use crate::transcoding::c_ktx2_transcoder_get_r_width as ktx2_transcoder_get_r_width; pub use crate::transcoding::c_ktx2_transcoder_new as ktx2_transcoder_new; - -pub unsafe fn ktx2_transcoder_transcode_image( - transcoder: *mut Transcoder, - data: Vec, - supported_compressed_formats: SupportedTextureCompressionMethods, - channel_type_hint: ChannelType, - force_transcode_target: TextureTranscodedFormat, -) -> bool { - unsafe { - crate::transcoding::c_ktx2_transcoder_transcode_image( - transcoder, - data.as_ptr(), - u32::try_from(data.len()).unwrap(), - supported_compressed_formats, - channel_type_hint, - force_transcode_target, - ) - } -} - -pub unsafe fn ktx2_transcoder_get_r_dst_buf(transcoder: *mut Transcoder) -> Vec { - let ptr = unsafe { crate::transcoding::c_ktx2_transcoder_get_r_dst_buf(transcoder) }; - let len = unsafe { crate::transcoding::c_ktx2_transcoder_get_r_dst_buf_len(transcoder) }; - let mut ret = vec![0; len as usize]; - unsafe { core::ptr::copy_nonoverlapping(ptr, ret.as_mut_ptr(), len as usize) }; - ret -} +pub use crate::transcoding::c_ktx2_transcoder_transcode_image_get_info as ktx2_transcoder_transcode_image_get_info; +pub use crate::transcoding::c_ktx2_transcoder_transcode_image_write_buffer as ktx2_transcoder_transcode_image_write_buffer; diff --git a/crates/basisu_sys/src/web.rs b/crates/basisu_sys/src/web.rs index 8e7ae39..2d7d5ef 100644 --- a/crates/basisu_sys/src/web.rs +++ b/crates/basisu_sys/src/web.rs @@ -1,22 +1,22 @@ -#![expect(clippy::missing_safety_doc, reason = "TODO")] - use std::cell::OnceCell; use js_sys::Object; use js_sys::Reflect; use js_sys::Uint8Array; +use crate::BasisTextureFormat; use crate::ChannelType; use crate::SupportedTextureCompressionMethods; -use crate::TextureTranscodedFormat; -use crate::Transcoder; +use crate::TranscodedTextureFormat; +use crate::transcoding::Transcoder; mod bindings_sys { use super::Transcoder; use js_sys::Uint8Array; use wasm_bindgen::prelude::wasm_bindgen; type SupportedTextureCompressionMethodsRepr = u8; - type TextureTranscodedFormatRepr = u32; + type TranscodedTextureFormatRepr = i32; + type BasisTextureFormatRepr = i32; type ChannelTypeRepr = u8; #[wasm_bindgen] @@ -37,15 +37,15 @@ mod bindings_sys { pub fn js_ktx2_transcoder_new(this: &BasisuVendor) -> *mut Transcoder; #[wasm_bindgen(method,js_name=_c_ktx2_transcoder_delete)] pub fn js_ktx2_transcoder_delete(this: &BasisuVendor, transcoder: *mut Transcoder); - #[wasm_bindgen(method,js_name=_c_ktx2_transcoder_transcode_image)] - pub fn js_ktx2_transcoder_transcode_image( + #[wasm_bindgen(method,js_name=_c_ktx2_transcoder_transcode_image_alloc_dst)] + pub fn js_ktx2_transcoder_transcode_image_alloc_dst( this: &BasisuVendor, transcoder: *mut Transcoder, data: usize, data_len: u32, supported_compressed_formats: SupportedTextureCompressionMethodsRepr, channel_type_hint: ChannelTypeRepr, - force_transcode_target: TextureTranscodedFormatRepr, + force_transcode_target: TranscodedTextureFormatRepr, ) -> bool; #[wasm_bindgen(method,js_name=_c_ktx2_transcoder_get_r_dst_buf)] pub fn js_ktx2_transcoder_get_r_dst_buf( @@ -86,7 +86,12 @@ mod bindings_sys { pub fn js_ktx2_transcoder_get_r_target_format( this: &BasisuVendor, transcoder: *mut Transcoder, - ) -> TextureTranscodedFormatRepr; + ) -> TranscodedTextureFormatRepr; + #[wasm_bindgen(method,js_name=_c_ktx2_transcoder_get_r_basis_format)] + pub fn js_ktx2_transcoder_get_r_basis_format( + this: &BasisuVendor, + transcoder: *mut Transcoder, + ) -> BasisTextureFormatRepr; #[wasm_bindgen(method,js_name=_c_ktx2_transcoder_get_r_is_srgb)] pub fn js_ktx2_transcoder_get_r_is_srgb( this: &BasisuVendor, @@ -167,8 +172,8 @@ pub unsafe fn ktx2_transcoder_get_r_levels(transcoder: *mut Transcoder) -> u32 { } pub unsafe fn ktx2_transcoder_get_r_target_format( transcoder: *mut Transcoder, -) -> TextureTranscodedFormat { - // SAFETY: Both repr are u32 +) -> TranscodedTextureFormat { + // SAFETY: Both repr are i32 unsafe { core::mem::transmute(BASISU_VENDOR_INSTANCE.with(|inst| { let inst = inst.get().unwrap(); @@ -176,6 +181,17 @@ pub unsafe fn ktx2_transcoder_get_r_target_format( })) } } +pub unsafe fn ktx2_transcoder_get_r_basis_format( + transcoder: *mut Transcoder, +) -> BasisTextureFormat { + // SAFETY: Both repr are i32 + unsafe { + core::mem::transmute(BASISU_VENDOR_INSTANCE.with(|inst| { + let inst = inst.get().unwrap(); + inst.js_ktx2_transcoder_get_r_basis_format(transcoder) + })) + } +} pub unsafe fn ktx2_transcoder_get_r_width(transcoder: *mut Transcoder) -> u32 { BASISU_VENDOR_INSTANCE.with(|inst| { let inst = inst.get().unwrap(); @@ -189,12 +205,12 @@ pub unsafe fn ktx2_transcoder_new() -> *mut Transcoder { }) } -pub unsafe fn ktx2_transcoder_transcode_image( +pub unsafe fn ktx2_transcoder_transcode_image_alloc_dst( transcoder: *mut Transcoder, data: Vec, supported_compressed_formats: SupportedTextureCompressionMethods, channel_type_hint: ChannelType, - force_transcode_target: TextureTranscodedFormat, + force_transcode_target: TranscodedTextureFormat, ) -> bool { BASISU_VENDOR_INSTANCE.with(|inst| { let inst = inst.get().unwrap(); @@ -202,14 +218,14 @@ pub unsafe fn ktx2_transcoder_transcode_image( let ptr = inst.js_basisu_malloc(len as usize); let heap = inst.js_basisu_heapu8(); heap.set(&data.into(), ptr as u32); - let result = inst.js_ktx2_transcoder_transcode_image( + let result = inst.js_ktx2_transcoder_transcode_image_alloc_dst( transcoder, ptr, len, supported_compressed_formats.0, // SAFETY: Both repr are u8 unsafe { core::mem::transmute(channel_type_hint) }, - // SAFETY: Both repr are u32 + // SAFETY: Both repr are i32 unsafe { core::mem::transmute(force_transcode_target) }, ); inst.js_basisu_free(ptr); diff --git a/encode_assets.sh b/encode_assets.sh new file mode 100755 index 0000000..5fd5697 --- /dev/null +++ b/encode_assets.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +$BASISU_TOOL -etc1s -mipmap ./original_assets/alpha0.png -output_file ./assets/alpha0_etc1s_mips.basisu.ktx2 +$BASISU_TOOL -uastc_hdr_4x4 ./original_assets/Desk_fixed_6x6.exr -output_file ./assets/desk_uastc_hdr_4x4.basisu.ktx2 +$BASISU_TOOL -uastc_hdr_6x6 -mipmap ./original_assets/Desk_fixed_6x6.exr -output_file ./assets/desk_uastc_hdr_6x6_mips.basisu.ktx2 +$BASISU_TOOL -xuastc_ldr_8x8 -mipmap -cubemap ./original_assets/skybox/right.jpg ./original_assets/skybox/left.jpg ./original_assets/skybox/top.jpg ./original_assets/skybox/bottom.jpg ./original_assets/skybox/front.jpg ./original_assets/skybox/back.jpg -output_file ./assets/skybox_xuastc_ldr_8x8_cubemap_mips.basisu.ktx2 +$BASISU_TOOL -astc_ldr_8x8 -mipmap ./original_assets/kodim20.png -output_file ./assets/kodim20_astc_ldr_8x8_mips.basisu.ktx2 +$BASISU_TOOL -uastc_ldr_4x4 ./original_assets/tough_fixed.png -output_file ./assets/tough_uastc_ldr_4x4.basisu.ktx2 +$BASISU_TOOL -xuastc_ldr_6x6 -mipmap ./original_assets/wikipedia_fixed_6x6.png -output_file ./assets/wikipedia_xuastc_ldr_6x6_mips.basisu.ktx2 diff --git a/examples/test_scene/src/lib.rs b/examples/test_scene/src/lib.rs index 6ab8900..85e929d 100644 --- a/examples/test_scene/src/lib.rs +++ b/examples/test_scene/src/lib.rs @@ -8,6 +8,14 @@ use bevy::{ }; use bevy_basisu_loader::{BasisuLoaderPlugin, BasisuLoaderSettings}; +const IMAGE_PATH_ALPHA0: &str = "alpha0_etc1s_mips.basisu.ktx2"; +const IMAGE_PATH_DESK1: &str = "desk_uastc_hdr_4x4.basisu.ktx2"; +const IMAGE_PATH_DESK2: &str = "desk_uastc_hdr_6x6_mips.basisu.ktx2"; +const IMAGE_PATH_KODIM20: &str = "kodim20_astc_ldr_8x8_mips.basisu.ktx2"; +const IMAGE_PATH_SKYBOX: &str = "skybox_xuastc_ldr_8x8_cubemap_mips.basisu.ktx2"; +const IMAGE_PATH_TOUGH: &str = "tough_uastc_ldr_4x4.basisu.ktx2"; +const IMAGE_PATH_WIKIPEDIA: &str = "wikipedia_xuastc_ldr_6x6_mips.basisu.ktx2"; + #[bevy_main] pub fn main() { App::new() @@ -43,7 +51,7 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { - let skybox_handle = asset_server.load("gl_skybox_etc1s_cubemap_mips_12.basisu.ktx2"); + let skybox_handle = asset_server.load(IMAGE_PATH_SKYBOX); // camera commands.spawn(( Camera3d::default(), @@ -60,7 +68,7 @@ fn setup( commands.spawn(( Mesh3d(meshes.add(Rectangle::new(1.0, 1.0).mesh().build())), MeshMaterial3d(materials.add(StandardMaterial { - base_color_texture: Some(asset_server.load("tough_uastc_ldr_4x4_mips_11.basisu.ktx2")), + base_color_texture: Some(asset_server.load(IMAGE_PATH_TOUGH)), unlit: true, ..Default::default() })), @@ -70,7 +78,7 @@ fn setup( commands.spawn(( Mesh3d(meshes.add(Rectangle::new(0.644 * 3.0, 0.874 * 3.0).mesh().build())), MeshMaterial3d(materials.add(StandardMaterial { - base_color_texture: Some(asset_server.load("desk_uastc_hdr_6x6_mips_10.basisu.ktx2")), + base_color_texture: Some(asset_server.load(IMAGE_PATH_DESK1)), unlit: true, ..Default::default() })), @@ -82,7 +90,7 @@ fn setup( MeshMaterial3d(materials.add(StandardMaterial { uv_transform: Affine2::from_scale(Vec2::new(2., 2.)), base_color_texture: Some(asset_server.load_with_settings( - "desk_uastc_hdr_4x4_mips_10.basisu.ktx2", + IMAGE_PATH_DESK2, |s: &mut BasisuLoaderSettings| { s.force_transcode_target = Some(TextureFormat::Rgb9e5Ufloat); s.sampler = @@ -103,7 +111,7 @@ fn setup( Mesh3d(meshes.add(Rectangle::new(1.0, 1.0).mesh().build())), MeshMaterial3d(materials.add(StandardMaterial { base_color_texture: Some(asset_server.load_with_settings( - "alpha0_etc1s.basisu.ktx2", + IMAGE_PATH_ALPHA0, |s: &mut BasisuLoaderSettings| { s.channel_type_hint = bevy_basisu_loader::ChannelType::Rg; }, @@ -130,11 +138,11 @@ fn setup( }, children![ ImageNode { - image: asset_server.load("wikipedia_xuastc_ldr_6x6.basisu.ktx2"), + image: asset_server.load(IMAGE_PATH_WIKIPEDIA), ..Default::default() }, ImageNode { - image: asset_server.load("kodim20_astc_ldr_8x8.basisu.ktx2"), + image: asset_server.load(IMAGE_PATH_KODIM20), ..Default::default() }, ], diff --git a/original_assets/Desk_fixed_6x6.exr b/original_assets/Desk_fixed_6x6.exr new file mode 100644 index 0000000..5eaa8d1 --- /dev/null +++ b/original_assets/Desk_fixed_6x6.exr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9e8d0d6c9931293ffacc51025e547ab6944b2e752a2e84f25ccb42a762d88c92 +size 2277440 diff --git a/original_assets/alpha0.png b/original_assets/alpha0.png new file mode 100644 index 0000000..dbe1b4e --- /dev/null +++ b/original_assets/alpha0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d449ea4dfe2542192d6e45bbb526909818a10a10c1520b8c2731e4b565acf64e +size 977 diff --git a/original_assets/kodim20.png b/original_assets/kodim20.png new file mode 100644 index 0000000..6cb1858 --- /dev/null +++ b/original_assets/kodim20.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b46c71e3b92a563820ba32936be8330c586c41f938efd94be938386aae4328a +size 492462 diff --git a/original_assets/skybox/back.jpg b/original_assets/skybox/back.jpg new file mode 100644 index 0000000..0166e68 --- /dev/null +++ b/original_assets/skybox/back.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da4938039f6a536c7db3fba35ffdd905861ce36608ceadf4412479c5fcacd138 +size 740068 diff --git a/original_assets/skybox/bottom.jpg b/original_assets/skybox/bottom.jpg new file mode 100644 index 0000000..47253e1 --- /dev/null +++ b/original_assets/skybox/bottom.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:088f074272f731abdc9da601cf925aeb80060d048ef33d2a60dd1b215d41feec +size 280589 diff --git a/original_assets/skybox/front.jpg b/original_assets/skybox/front.jpg new file mode 100644 index 0000000..2b99520 --- /dev/null +++ b/original_assets/skybox/front.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd6f9d8bb04466c06387e8dc736eb453bcb92a09750be520b8d5e00e8bd484fe +size 473329 diff --git a/original_assets/skybox/left.jpg b/original_assets/skybox/left.jpg new file mode 100644 index 0000000..62ce923 --- /dev/null +++ b/original_assets/skybox/left.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:087df0cdc2d28b7e9f5f6b2d82795aa6b10684ce51d3104e8dd3c128b485a960 +size 601885 diff --git a/original_assets/skybox/right.jpg b/original_assets/skybox/right.jpg new file mode 100644 index 0000000..804ed5c --- /dev/null +++ b/original_assets/skybox/right.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4a1b6fd9daffdfb6c42d0dc169cffba7129a8d7da3fab52531e4df4a203191d +size 538038 diff --git a/original_assets/skybox/top.jpg b/original_assets/skybox/top.jpg new file mode 100644 index 0000000..9ea52e6 --- /dev/null +++ b/original_assets/skybox/top.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff0aa54d15b7c69fc6fae738f943854950a67afd7b1a4e297809668b2380e055 +size 346139 diff --git a/original_assets/tough_fixed.png b/original_assets/tough_fixed.png new file mode 100644 index 0000000..7e3c0b3 --- /dev/null +++ b/original_assets/tough_fixed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c17c28372e0c9409fca39fb3f595f9c48887d8cca0f9650cfb8b3eb1fc6461c5 +size 1255156 diff --git a/original_assets/wikipedia_fixed_6x6.png b/original_assets/wikipedia_fixed_6x6.png new file mode 100644 index 0000000..97f035b --- /dev/null +++ b/original_assets/wikipedia_fixed_6x6.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e51c6758750fb34f9c26b5cce73bec1e1957aa5f48170d730bd3bda4bffe1d7 +size 883606 diff --git a/src/lib.rs b/src/lib.rs index 46c573e..9060eec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,8 +49,7 @@ impl Plugin for BasisuLoaderPlugin { let r = ready.clone(); bevy::tasks::IoTaskPool::get() .spawn_local(async move { - bevy_basisu_loader_sys::basisu_sys_init_vendor().await; - unsafe { bevy_basisu_loader_sys::basisu_transcoder_init() }; + bevy_basisu_loader_sys::basisu_init().await; r.store(true, Ordering::Release); bevy::log::debug!("Basisu wasm initialized") }) @@ -62,9 +61,7 @@ impl Plugin for BasisuLoaderPlugin { target_vendor = "unknown", target_os = "unknown", )))] - unsafe { - bevy_basisu_loader_sys::basisu_transcoder_init() - }; + bevy::tasks::block_on(bevy_basisu_loader_sys::basisu_init()); app.preregister_asset_loader::(&["basisu.ktx2"]); } diff --git a/src/loader.rs b/src/loader.rs index 6d14e9a..cc84503 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -6,7 +6,7 @@ use bevy::render::render_resource::{ TextureFormat, TextureUsages, TextureViewDescriptor, TextureViewDimension, WgpuFeatures as Features, }; -use bevy_basisu_loader_sys::{SupportedTextureCompressionMethods, TextureTranscodedFormat}; +use bevy_basisu_loader_sys::{SupportedTextureCompressionMethods, TranscodedTextureFormat}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -106,9 +106,8 @@ impl AssetLoader for BasisuLoader { ) -> Result { let mut data = Vec::new(); reader.read_to_end(&mut data).await?; - - // SAFETY: Ensure the transcoding code is correct. - let (out_data, out_format, extent, levels, view_dimension) = unsafe { + let src_bytes = data.len(); + let (out_data, out_format, extent, levels, view_dimension) = { let _span = bevy::log::info_span!("Transcoding BasisU Texture").entered(); let time = if log::STATIC_MAX_LEVEL >= log::LevelFilter::Debug { Some(bevy::platform::time::Instant::now()) @@ -116,74 +115,62 @@ impl AssetLoader for BasisuLoader { None }; - let transcoder = bevy_basisu_loader_sys::ktx2_transcoder_new(); - if transcoder.is_null() { - return Err(BasisuLoaderError::TranscodingError("ktx2_transcoder_new")); - } - if !bevy_basisu_loader_sys::ktx2_transcoder_transcode_image( - transcoder, + let Some(result) = bevy_basisu_loader_sys::basisu_transcode( data, self.supported_compressed_formats, channel_type_to_channel_type_sys(settings.channel_type_hint), texture_bevy_format_to_transcode_format(settings.force_transcode_target), - ) { - return Err(BasisuLoaderError::TranscodingError( - "ktx2_transcoder_transcode_image", - )); - } - - let is_srgb = - settings - .is_srgb - .unwrap_or(bevy_basisu_loader_sys::ktx2_transcoder_get_r_is_srgb( - transcoder, - )); - let target_format = - bevy_basisu_loader_sys::ktx2_transcoder_get_r_target_format(transcoder); - - let width = bevy_basisu_loader_sys::ktx2_transcoder_get_r_width(transcoder); - let height = bevy_basisu_loader_sys::ktx2_transcoder_get_r_height(transcoder); - let levels = bevy_basisu_loader_sys::ktx2_transcoder_get_r_levels(transcoder); - let layers = bevy_basisu_loader_sys::ktx2_transcoder_get_r_layers(transcoder); - let faces = bevy_basisu_loader_sys::ktx2_transcoder_get_r_faces(transcoder); - let dst_bytes = bevy_basisu_loader_sys::ktx2_transcoder_get_r_dst_buf(transcoder); + ) else { + return Err(BasisuLoaderError::TranscodingError("basisu_transcode")); + }; - let view_dimension = if layers == 0 { - if faces == 1 { + let view_dimension = if result.layers == 0 { + if result.faces == 1 { TextureViewDimension::D2 - } else if faces == 6 { + } else if result.faces == 6 { TextureViewDimension::Cube } else { unreachable!() } - } else if faces == 1 { + } else if result.faces == 1 { TextureViewDimension::D2Array - } else if faces == 6 { + } else if result.faces == 6 { TextureViewDimension::CubeArray } else { unreachable!() }; let extent = Extent3d { - width, - height, - depth_or_array_layers: layers.max(1) * faces, + width: result.width, + height: result.height, + depth_or_array_layers: result.layers.max(1) * result.faces, }; - bevy_basisu_loader_sys::ktx2_transcoder_delete(transcoder); - let out_format = texture_transcode_format_to_bevy_format(target_format, is_srgb); + let out_format = texture_transcode_format_to_bevy_format( + result.target_format, + settings.is_srgb.unwrap_or(result.is_srgb), + ); + if log::STATIC_MAX_LEVEL >= log::LevelFilter::Debug { bevy::log::debug!( - "Transcoded a basisu texture with dst_bytes: {:?}, dst_format: {:?}, extent: {:?}, levels: {:?}, view_dimension: {:?}, in {:?}", - dst_bytes.len(), + "Transcoded a basisu texture with src_bytes: {:?}, src_format: {:?}, dst_bytes: {:?}, dst_format: {:?}, extent: {:?}, levels: {:?}, view_dimension: {:?}, in {:?}", + src_bytes, + result.basis_format, + result.data.len(), out_format, extent, - levels, + result.levels, view_dimension, - time.unwrap_unchecked().elapsed() + time.unwrap().elapsed() ); } - (dst_bytes, out_format, extent, levels, view_dimension) + ( + result.data, + out_format, + extent, + result.levels, + view_dimension, + ) }; let mut image = Image { data: None, @@ -229,100 +216,100 @@ impl AssetLoader for BasisuLoader { } fn texture_transcode_format_to_bevy_format( - transcoded: TextureTranscodedFormat, + transcoded: TranscodedTextureFormat, is_srgb: bool, ) -> TextureFormat { let mut fmt = match transcoded { - TextureTranscodedFormat::cTFETC1_RGB => TextureFormat::Etc2Rgb8Unorm, - TextureTranscodedFormat::cTFETC2_RGBA => TextureFormat::Etc2Rgba8Unorm, - TextureTranscodedFormat::cTFBC1_RGB => TextureFormat::Bc1RgbaUnorm, - TextureTranscodedFormat::cTFBC3_RGBA => TextureFormat::Bc3RgbaUnorm, - TextureTranscodedFormat::cTFBC4_R => TextureFormat::Bc4RUnorm, - TextureTranscodedFormat::cTFBC5_RG => TextureFormat::Bc5RgUnorm, - TextureTranscodedFormat::cTFBC7_RGBA => TextureFormat::Bc7RgbaUnorm, - TextureTranscodedFormat::cTFPVRTC1_4_RGB => unreachable!(), - TextureTranscodedFormat::cTFPVRTC1_4_RGBA => unreachable!(), - TextureTranscodedFormat::cTFASTC_4x4_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFETC1_RGB => TextureFormat::Etc2Rgb8Unorm, + TranscodedTextureFormat::cTFETC2_RGBA => TextureFormat::Etc2Rgba8Unorm, + TranscodedTextureFormat::cTFBC1_RGB => TextureFormat::Bc1RgbaUnorm, + TranscodedTextureFormat::cTFBC3_RGBA => TextureFormat::Bc3RgbaUnorm, + TranscodedTextureFormat::cTFBC4_R => TextureFormat::Bc4RUnorm, + TranscodedTextureFormat::cTFBC5_RG => TextureFormat::Bc5RgUnorm, + TranscodedTextureFormat::cTFBC7_RGBA => TextureFormat::Bc7RgbaUnorm, + TranscodedTextureFormat::cTFPVRTC1_4_RGB => unreachable!(), + TranscodedTextureFormat::cTFPVRTC1_4_RGBA => unreachable!(), + TranscodedTextureFormat::cTFASTC_4x4_RGBA => TextureFormat::Astc { block: AstcBlock::B4x4, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFATC_RGB => unreachable!(), - TextureTranscodedFormat::cTFATC_RGBA => unreachable!(), - TextureTranscodedFormat::cTFFXT1_RGB => unreachable!(), - TextureTranscodedFormat::cTFPVRTC2_4_RGB => unreachable!(), - TextureTranscodedFormat::cTFPVRTC2_4_RGBA => unreachable!(), - TextureTranscodedFormat::cTFETC2_EAC_R11 => TextureFormat::EacR11Unorm, - TextureTranscodedFormat::cTFETC2_EAC_RG11 => TextureFormat::EacRg11Unorm, - TextureTranscodedFormat::cTFBC6H => TextureFormat::Bc6hRgbUfloat, - TextureTranscodedFormat::cTFASTC_HDR_4x4_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFATC_RGB => unreachable!(), + TranscodedTextureFormat::cTFATC_RGBA => unreachable!(), + TranscodedTextureFormat::cTFFXT1_RGB => unreachable!(), + TranscodedTextureFormat::cTFPVRTC2_4_RGB => unreachable!(), + TranscodedTextureFormat::cTFPVRTC2_4_RGBA => unreachable!(), + TranscodedTextureFormat::cTFETC2_EAC_R11 => TextureFormat::EacR11Unorm, + TranscodedTextureFormat::cTFETC2_EAC_RG11 => TextureFormat::EacRg11Unorm, + TranscodedTextureFormat::cTFBC6H => TextureFormat::Bc6hRgbUfloat, + TranscodedTextureFormat::cTFASTC_HDR_4x4_RGBA => TextureFormat::Astc { block: AstcBlock::B4x4, channel: AstcChannel::Hdr, }, - TextureTranscodedFormat::cTFRGBA32 => TextureFormat::Rgba8Unorm, - TextureTranscodedFormat::cTFRGB565 => unreachable!(), - TextureTranscodedFormat::cTFBGR565 => unreachable!(), - TextureTranscodedFormat::cTFRGBA4444 => unreachable!(), - TextureTranscodedFormat::cTFRGB_HALF => unreachable!(), - TextureTranscodedFormat::cTFRGBA_HALF => TextureFormat::Rgba16Float, - TextureTranscodedFormat::cTFRGB_9E5 => TextureFormat::Rgb9e5Ufloat, - TextureTranscodedFormat::cTFASTC_HDR_6x6_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFRGBA32 => TextureFormat::Rgba8Unorm, + TranscodedTextureFormat::cTFRGB565 => unreachable!(), + TranscodedTextureFormat::cTFBGR565 => unreachable!(), + TranscodedTextureFormat::cTFRGBA4444 => unreachable!(), + TranscodedTextureFormat::cTFRGB_HALF => unreachable!(), + TranscodedTextureFormat::cTFRGBA_HALF => TextureFormat::Rgba16Float, + TranscodedTextureFormat::cTFRGB_9E5 => TextureFormat::Rgb9e5Ufloat, + TranscodedTextureFormat::cTFASTC_HDR_6x6_RGBA => TextureFormat::Astc { block: AstcBlock::B6x6, channel: AstcChannel::Hdr, }, - TextureTranscodedFormat::cTFASTC_LDR_5x4_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_5x4_RGBA => TextureFormat::Astc { block: AstcBlock::B5x4, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_5x5_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_5x5_RGBA => TextureFormat::Astc { block: AstcBlock::B5x5, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_6x5_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_6x5_RGBA => TextureFormat::Astc { block: AstcBlock::B6x5, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_6x6_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_6x6_RGBA => TextureFormat::Astc { block: AstcBlock::B6x6, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_8x5_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_8x5_RGBA => TextureFormat::Astc { block: AstcBlock::B8x5, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_8x6_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_8x6_RGBA => TextureFormat::Astc { block: AstcBlock::B8x6, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_10x5_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_10x5_RGBA => TextureFormat::Astc { block: AstcBlock::B10x5, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_10x6_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_10x6_RGBA => TextureFormat::Astc { block: AstcBlock::B10x6, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_8x8_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_8x8_RGBA => TextureFormat::Astc { block: AstcBlock::B8x8, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_10x8_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_10x8_RGBA => TextureFormat::Astc { block: AstcBlock::B10x8, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_10x10_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_10x10_RGBA => TextureFormat::Astc { block: AstcBlock::B10x10, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_12x10_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_12x10_RGBA => TextureFormat::Astc { block: AstcBlock::B12x10, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFASTC_LDR_12x12_RGBA => TextureFormat::Astc { + TranscodedTextureFormat::cTFASTC_LDR_12x12_RGBA => TextureFormat::Astc { block: AstcBlock::B12x12, channel: AstcChannel::Unorm, }, - TextureTranscodedFormat::cTFTotalTextureFormats => unreachable!(), - TextureTranscodedFormat::cTFBC7_ALT => unreachable!(), + TranscodedTextureFormat::cTFTotalTextureFormats => unreachable!(), + TranscodedTextureFormat::cTFBC7_ALT => unreachable!(), }; if is_srgb { fmt = fmt.add_srgb_suffix(); @@ -332,37 +319,37 @@ fn texture_transcode_format_to_bevy_format( fn texture_bevy_format_to_transcode_format( format: Option, -) -> TextureTranscodedFormat { +) -> TranscodedTextureFormat { let Some(format) = format else { - return TextureTranscodedFormat::cTFTotalTextureFormats; + return TranscodedTextureFormat::cTFTotalTextureFormats; }; let format = format.remove_srgb_suffix(); match format { - TextureFormat::Etc2Rgb8Unorm => TextureTranscodedFormat::cTFETC1_RGB, - TextureFormat::Etc2Rgba8Unorm => TextureTranscodedFormat::cTFETC2_RGBA, - TextureFormat::Bc1RgbaUnorm => TextureTranscodedFormat::cTFBC1_RGB, - TextureFormat::Bc3RgbaUnorm => TextureTranscodedFormat::cTFBC3_RGBA, - TextureFormat::Bc4RUnorm => TextureTranscodedFormat::cTFBC4_R, - TextureFormat::Bc5RgUnorm => TextureTranscodedFormat::cTFBC5_RG, - TextureFormat::Bc7RgbaUnorm => TextureTranscodedFormat::cTFBC7_RGBA, + TextureFormat::Etc2Rgb8Unorm => TranscodedTextureFormat::cTFETC1_RGB, + TextureFormat::Etc2Rgba8Unorm => TranscodedTextureFormat::cTFETC2_RGBA, + TextureFormat::Bc1RgbaUnorm => TranscodedTextureFormat::cTFBC1_RGB, + TextureFormat::Bc3RgbaUnorm => TranscodedTextureFormat::cTFBC3_RGBA, + TextureFormat::Bc4RUnorm => TranscodedTextureFormat::cTFBC4_R, + TextureFormat::Bc5RgUnorm => TranscodedTextureFormat::cTFBC5_RG, + TextureFormat::Bc7RgbaUnorm => TranscodedTextureFormat::cTFBC7_RGBA, TextureFormat::Astc { block: AstcBlock::B4x4, channel: AstcChannel::Unorm, - } => TextureTranscodedFormat::cTFASTC_4x4_RGBA, - TextureFormat::EacR11Unorm => TextureTranscodedFormat::cTFETC2_EAC_R11, - TextureFormat::EacRg11Unorm => TextureTranscodedFormat::cTFETC2_EAC_RG11, - TextureFormat::Bc6hRgbUfloat => TextureTranscodedFormat::cTFBC6H, + } => TranscodedTextureFormat::cTFASTC_4x4_RGBA, + TextureFormat::EacR11Unorm => TranscodedTextureFormat::cTFETC2_EAC_R11, + TextureFormat::EacRg11Unorm => TranscodedTextureFormat::cTFETC2_EAC_RG11, + TextureFormat::Bc6hRgbUfloat => TranscodedTextureFormat::cTFBC6H, TextureFormat::Astc { block: AstcBlock::B4x4, channel: AstcChannel::Hdr, - } => TextureTranscodedFormat::cTFASTC_HDR_4x4_RGBA, - TextureFormat::Rgba8Unorm => TextureTranscodedFormat::cTFRGBA32, - TextureFormat::Rgba16Float => TextureTranscodedFormat::cTFRGBA_HALF, - TextureFormat::Rgb9e5Ufloat => TextureTranscodedFormat::cTFRGB_9E5, + } => TranscodedTextureFormat::cTFASTC_HDR_4x4_RGBA, + TextureFormat::Rgba8Unorm => TranscodedTextureFormat::cTFRGBA32, + TextureFormat::Rgba16Float => TranscodedTextureFormat::cTFRGBA_HALF, + TextureFormat::Rgb9e5Ufloat => TranscodedTextureFormat::cTFRGB_9E5, TextureFormat::Astc { block: AstcBlock::B6x6, channel: AstcChannel::Hdr, - } => TextureTranscodedFormat::cTFASTC_HDR_6x6_RGBA, + } => TranscodedTextureFormat::cTFASTC_HDR_6x6_RGBA, _ => unreachable!(), } } diff --git a/vendor/basis_universal/LICENSE b/vendor/basis_universal/LICENSE index 500c277..f43afa4 100644 --- a/vendor/basis_universal/LICENSE +++ b/vendor/basis_universal/LICENSE @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a9dfe3795e7bdcf240626d70d72de2933964f8ff482c75e68f29253ee2e79b1b +oid sha256:065fcf48d6af21c0b75e23be5ed5753aee75c892e1c2cf178fa6736305614a5c size 11347 diff --git a/vendor/basis_universal/transcoder/basisu_astc_hdr_core.h b/vendor/basis_universal/transcoder/basisu_astc_hdr_core.h index 3b1de47..8bb4c75 100644 --- a/vendor/basis_universal/transcoder/basisu_astc_hdr_core.h +++ b/vendor/basis_universal/transcoder/basisu_astc_hdr_core.h @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:397e9cfd0a81c473e9220e1d6fbb2aa003c02181263eeb1202368fce142ed4e2 -size 6217 +oid sha256:4d1e2b68275c7f402623ab0824722d7e8d6e85adc2fc747a44c07e5321b366d4 +size 6425 diff --git a/vendor/basis_universal/transcoder/basisu_astc_helpers.h b/vendor/basis_universal/transcoder/basisu_astc_helpers.h index 6baa1c7..d81bb20 100644 --- a/vendor/basis_universal/transcoder/basisu_astc_helpers.h +++ b/vendor/basis_universal/transcoder/basisu_astc_helpers.h @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:59e9315f1da3c0518b7f98725e64f4c4c7d4785165140e792cbd0f8081101cb8 -size 147388 +oid sha256:a5f86db332fe2c9060dd77889203aa4c01cf8d0bea6a8754fc11939018c6c553 +size 147819 diff --git a/vendor/basis_universal/transcoder/basisu_transcoder.cpp b/vendor/basis_universal/transcoder/basisu_transcoder.cpp index 7b78238..0752961 100644 --- a/vendor/basis_universal/transcoder/basisu_transcoder.cpp +++ b/vendor/basis_universal/transcoder/basisu_transcoder.cpp @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fa6059dbe2e73f0c35e101bd94faae41a4ffc6b2ac03841cb7651e38e21bd579 -size 1541100 +oid sha256:cfcde5c02ac0a881ca32fa1bafca52db347b2abb0351c7898a429dfd4c6e749f +size 1544939 diff --git a/vendor/basis_universal/transcoder/basisu_transcoder.h b/vendor/basis_universal/transcoder/basisu_transcoder.h index 4423ec7..059f3a3 100644 --- a/vendor/basis_universal/transcoder/basisu_transcoder.h +++ b/vendor/basis_universal/transcoder/basisu_transcoder.h @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cb30b8a9e4c317c6262483162b9d2b05e25aa5dd665631d79f16663f0c652651 -size 66900 +oid sha256:217b2e545c597e40b963123a900ba6f338ad20fb79cf2d6811ada2240483a122 +size 67649 diff --git a/vendor/basis_universal/transcoder/basisu_transcoder_internal.h b/vendor/basis_universal/transcoder/basisu_transcoder_internal.h index be48c7d..229f2eb 100644 --- a/vendor/basis_universal/transcoder/basisu_transcoder_internal.h +++ b/vendor/basis_universal/transcoder/basisu_transcoder_internal.h @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1b30f5ea5d7a6bedeb2771023cfbd3f24026dccf4bc725040682c4e056f365b9 -size 86399 +oid sha256:d58cebb526fdfeb9820d1f585cec4d1c42101a768b682f882bd2c0d3157ff9dc +size 86604 diff --git a/vendor/transcoding_wrapper.cpp b/vendor/transcoding_wrapper.cpp index 0b61ecb..3d2974a 100644 --- a/vendor/transcoding_wrapper.cpp +++ b/vendor/transcoding_wrapper.cpp @@ -32,16 +32,17 @@ void c_ktx2_transcoder_delete(Transcoder *transcoder) { delete transcoder; } -static bool c_ktx2_transcoder_get_texture_info(Transcoder *transcoder, TextureTranscodedFormat target_format, unsigned int *r_width, unsigned int *r_height, unsigned int *r_levels, unsigned int *r_layers, unsigned int *r_faces, unsigned int *r_total_bytes) { +static bool c_ktx2_transcoder_get_texture_info(Transcoder *transcoder, TranscodedTextureFormat target_format, BasisTextureFormat *r_basis_format, unsigned int *r_width, unsigned int *r_height, unsigned int *r_levels, unsigned int *r_layers, unsigned int *r_faces, unsigned int *r_total_bytes) { basist::ktx2_transcoder *inner = transcoder->inner; + *r_basis_format = static_cast(inner->get_basis_tex_format()); *r_width = inner->get_width(); *r_height = inner->get_height(); *r_levels = inner->get_levels(); *r_layers = inner->get_layers(); *r_faces = inner->get_faces(); - const basist::transcoder_texture_format transcode_format = static_cast(static_cast(target_format)); + const basist::transcoder_texture_format transcode_format = static_cast(target_format); uint32_t total_bytes = 0; uint32_t total_layers = basisu::maximumu(inner->get_layers(), 1u); @@ -62,7 +63,7 @@ static bool c_ktx2_transcoder_get_texture_info(Transcoder *transcoder, TextureTr return true; } -static void c_ktx2_transcoder_get_target_format(Transcoder *transcoder, SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, bool *r_is_srgb, TextureTranscodedFormat *r_format) { +static void c_ktx2_transcoder_get_target_format(Transcoder *transcoder, SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, bool *r_is_srgb, TranscodedTextureFormat *r_format) { basist::ktx2_transcoder *inner = transcoder->inner; basist::ktx2_df_channel_id channel_id0 = inner->get_dfd_channel_id0(); @@ -71,29 +72,32 @@ static void c_ktx2_transcoder_get_target_format(Transcoder *transcoder, Supporte ChannelType channel_type = channel_type_hint != CHANNEL_UNDEFINED ? channel_type_hint : channel_id_to_type(inner->is_uastc(), channel_id0, channel_id1); basist::transcoder_texture_format target_format = get_target_texture_format(basis_format, channel_type, supported_compressed_formats); *r_is_srgb = inner->get_dfd_transfer_func() == basist::KTX2_KHR_DF_TRANSFER_SRGB; - *r_format = static_cast(static_cast(target_format)); + *r_format = static_cast(target_format); } -bool c_ktx2_transcoder_transcode_image( - Transcoder *transcoder, const unsigned char *data, unsigned int data_size, - SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, TextureTranscodedFormat force_transcode_target) { +bool c_ktx2_transcoder_transcode_image_get_info(Transcoder *transcoder, const unsigned char *data, unsigned int data_size, + SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, TranscodedTextureFormat force_transcode_target) { basist::ktx2_transcoder *inner = transcoder->inner; inner->init(data, data_size); inner->start_transcoding(); c_ktx2_transcoder_get_target_format(transcoder, supported_compressed_formats, channel_type_hint, &transcoder->r_is_srgb, &transcoder->r_target_format); - if (force_transcode_target != TextureTranscodedFormat::cTFTotalTextureFormats) { + if (force_transcode_target != TranscodedTextureFormat::cTFTotalTextureFormats) { transcoder->r_target_format = force_transcode_target; } - basist::transcoder_texture_format transcode_format = static_cast(static_cast(transcoder->r_target_format)); - if (!c_ktx2_transcoder_get_texture_info(transcoder, transcoder->r_target_format, &transcoder->r_width, &transcoder->r_height, &transcoder->r_levels, &transcoder->r_layers, &transcoder->r_faces, &transcoder->r_dst_buf_len)) { + if (!c_ktx2_transcoder_get_texture_info(transcoder, transcoder->r_target_format, &transcoder->r_basis_format, &transcoder->r_width, &transcoder->r_height, &transcoder->r_levels, &transcoder->r_layers, &transcoder->r_faces, &transcoder->r_dst_buf_len)) { return false; } - transcoder->r_dst_buf = (unsigned char *)malloc(transcoder->r_dst_buf_len); + return true; +} + +bool c_ktx2_transcoder_transcode_image_write_buffer(Transcoder *transcoder, unsigned char *dst_buffer) { + basist::ktx2_transcoder *inner = transcoder->inner; + basist::transcoder_texture_format transcode_format = static_cast(transcoder->r_target_format); uint32_t total_layers = basisu::maximumu(inner->get_layers(), 1u); - uint8_t *out = transcoder->r_dst_buf; + uint8_t *out = dst_buffer; for (uint32_t level_index = 0; level_index < inner->get_levels(); level_index++) { for (uint32_t layer_index = 0; layer_index < total_layers; layer_index++) { for (uint32_t face_index = 0; face_index < inner->get_faces(); face_index++) { @@ -102,30 +106,31 @@ bool c_ktx2_transcoder_transcode_image( return false; } - uint32_t total_dst_blocks_or_pixels; - if (basist::basis_transcoder_format_is_uncompressed(transcode_format)) { - total_dst_blocks_or_pixels = level_info.m_orig_width * level_info.m_orig_height; - } else { - const uint32_t dst_block_width = basist::basis_get_block_width(transcode_format); - const uint32_t dst_block_height = basist::basis_get_block_height(transcode_format); - - // Take into account the destination format's block width/height. - const uint32_t num_dst_blocks_x = (level_info.m_orig_width + dst_block_width - 1) / dst_block_width; - const uint32_t num_dst_blocks_y = (level_info.m_orig_height + dst_block_height - 1) / dst_block_height; - total_dst_blocks_or_pixels = num_dst_blocks_x * num_dst_blocks_y; - } - - if (!inner->transcode_image_level(level_index, layer_index, face_index, out, total_dst_blocks_or_pixels, transcode_format)) { + const uint32_t total_bytes = basist::basis_compute_transcoded_image_size_in_bytes(transcode_format, level_info.m_orig_width, level_info.m_orig_height); + const uint32_t bytes_per_block = basist::basis_get_bytes_per_block_or_pixel(transcode_format); + const uint32_t total_blocks = total_bytes / bytes_per_block; + if (!inner->transcode_image_level(level_index, layer_index, face_index, out, total_blocks, transcode_format)) { return false; } - uint32_t total_bytes = basist::basis_compute_transcoded_image_size_in_bytes(transcode_format, level_info.m_orig_width, level_info.m_orig_height); out += total_bytes; } } } transcoder->inner->clear(); + return true; +} +bool c_ktx2_transcoder_transcode_image_alloc_dst( + Transcoder *transcoder, const unsigned char *data, unsigned int data_size, + SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, TranscodedTextureFormat force_transcode_target) { + if (!c_ktx2_transcoder_transcode_image_get_info(transcoder, data, data_size, supported_compressed_formats, channel_type_hint, force_transcode_target)) { + return false; + } + transcoder->r_dst_buf = (unsigned char *)malloc(transcoder->r_dst_buf_len); + if (!c_ktx2_transcoder_transcode_image_write_buffer(transcoder, transcoder->r_dst_buf)) { + return false; + } return true; } } @@ -427,9 +432,12 @@ unsigned int c_ktx2_transcoder_get_r_layers(Transcoder *transcoder) { unsigned int c_ktx2_transcoder_get_r_faces(Transcoder *transcoder) { return transcoder->r_faces; } -TextureTranscodedFormat c_ktx2_transcoder_get_r_target_format(Transcoder *transcoder) { +TranscodedTextureFormat c_ktx2_transcoder_get_r_target_format(Transcoder *transcoder) { return transcoder->r_target_format; } +BasisTextureFormat c_ktx2_transcoder_get_r_basis_format(Transcoder *transcoder) { + return transcoder->r_basis_format; +} bool c_ktx2_transcoder_get_r_is_srgb(Transcoder *transcoder) { return transcoder->r_is_srgb; } diff --git a/vendor/transcoding_wrapper.hpp b/vendor/transcoding_wrapper.hpp index 540a1ab..12e5dc9 100644 --- a/vendor/transcoding_wrapper.hpp +++ b/vendor/transcoding_wrapper.hpp @@ -14,7 +14,7 @@ enum ChannelType : unsigned char { }; // This enum must be in sync with the `basist::transcoder_texture_format`. -enum TextureTranscodedFormat : unsigned int { +enum TranscodedTextureFormat : int { // Compressed formats // ETC1-2 @@ -107,6 +107,58 @@ enum TextureTranscodedFormat : unsigned int { cTFASTC_4x4_RGBA = cTFASTC_LDR_4x4_RGBA }; +// This enum must be in sync with the `basist::basis_tex_format`. +enum class BasisTextureFormat : int { + // Original LDR formats + cETC1S = 0, + cUASTC_LDR_4x4 = 1, + + // HDR formats + cUASTC_HDR_4x4 = 2, + cASTC_HDR_6x6 = 3, + cUASTC_HDR_6x6_INTERMEDIATE = 4, // TODO: rename to UASTC_HDR_6x6 + + // XUASTC (supercompressed) LDR variants (the standard ASTC block sizes) + cXUASTC_LDR_4x4 = 5, + cXUASTC_LDR_5x4 = 6, + cXUASTC_LDR_5x5 = 7, + cXUASTC_LDR_6x5 = 8, + + cXUASTC_LDR_6x6 = 9, + cXUASTC_LDR_8x5 = 10, + cXUASTC_LDR_8x6 = 11, + cXUASTC_LDR_10x5 = 12, + + cXUASTC_LDR_10x6 = 13, + cXUASTC_LDR_8x8 = 14, + cXUASTC_LDR_10x8 = 15, + cXUASTC_LDR_10x10 = 16, + + cXUASTC_LDR_12x10 = 17, + cXUASTC_LDR_12x12 = 18, + + // Standard (non-supercompressed) ASTC LDR variants (the standard ASTC block sizes) + cASTC_LDR_4x4 = 19, + cASTC_LDR_5x4 = 20, + cASTC_LDR_5x5 = 21, + cASTC_LDR_6x5 = 22, + + cASTC_LDR_6x6 = 23, + cASTC_LDR_8x5 = 24, + cASTC_LDR_8x6 = 25, + cASTC_LDR_10x5 = 26, + + cASTC_LDR_10x6 = 27, + cASTC_LDR_8x8 = 28, + cASTC_LDR_10x8 = 29, + cASTC_LDR_10x10 = 30, + + cASTC_LDR_12x10 = 31, + cASTC_LDR_12x12 = 32, + + cTotalFormats +}; + enum SupportedTextureCompressionMethods : unsigned char { NONE = 0, ASTC_LDR = 1 << 0, @@ -126,7 +178,8 @@ struct Transcoder { unsigned int r_levels; unsigned int r_layers; unsigned int r_faces; - TextureTranscodedFormat r_target_format; + BasisTextureFormat r_basis_format; + TranscodedTextureFormat r_target_format; bool r_is_srgb; }; @@ -136,8 +189,8 @@ Transcoder *c_ktx2_transcoder_new(); void c_ktx2_transcoder_delete(Transcoder *transcoder); -bool c_ktx2_transcoder_transcode_image(Transcoder *transcoder, const unsigned char *data, unsigned int data_size, - SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, TextureTranscodedFormat force_transcode_target); +bool c_ktx2_transcoder_transcode_image_alloc_dst(Transcoder *transcoder, const unsigned char *data, unsigned int data_size, + SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, TranscodedTextureFormat force_transcode_target); unsigned char *c_ktx2_transcoder_get_r_dst_buf(Transcoder *transcoder); unsigned int c_ktx2_transcoder_get_r_dst_buf_len(Transcoder *transcoder); @@ -146,6 +199,12 @@ unsigned int c_ktx2_transcoder_get_r_height(Transcoder *transcoder); unsigned int c_ktx2_transcoder_get_r_levels(Transcoder *transcoder); unsigned int c_ktx2_transcoder_get_r_layers(Transcoder *transcoder); unsigned int c_ktx2_transcoder_get_r_faces(Transcoder *transcoder); -TextureTranscodedFormat c_ktx2_transcoder_get_r_target_format(Transcoder *transcoder); +TranscodedTextureFormat c_ktx2_transcoder_get_r_target_format(Transcoder *transcoder); +BasisTextureFormat c_ktx2_transcoder_get_r_basis_format(Transcoder *transcoder); bool c_ktx2_transcoder_get_r_is_srgb(Transcoder *transcoder); + +bool c_ktx2_transcoder_transcode_image_get_info(Transcoder *transcoder, const unsigned char *data, unsigned int data_size, + SupportedTextureCompressionMethods supported_compressed_formats, ChannelType channel_type_hint, TranscodedTextureFormat force_transcode_target); + +bool c_ktx2_transcoder_transcode_image_write_buffer(Transcoder *transcoder, unsigned char *dst_buffer); } diff --git a/vendor/update-basis-universal.sh b/vendor/update-basis-universal.sh old mode 100644 new mode 100755 index 9627077..336b7dc --- a/vendor/update-basis-universal.sh +++ b/vendor/update-basis-universal.sh @@ -3,7 +3,7 @@ rm -r ./basis_universal mkdir ./basis_universal -git clone --depth 1 https://github.com/BinomialLLC/basis_universal --branch v2_0_2 basis_universal_repo +git clone --depth 1 https://github.com/BinomialLLC/basis_universal --branch v2_1_0 basis_universal_repo cp -r ./basis_universal_repo/transcoder/ ./basis_universal/ cp -r ./basis_universal_repo/zstd/ ./basis_universal/ cp ./basis_universal_repo/LICENSE ./basis_universal/