diff options
| author | Valentin Popov <valentin@popov.link> | 2026-02-19 04:19:18 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-02-19 04:19:18 +0300 |
| commit | a281ffa32ea615670d369503692f057b2dc60e6f (patch) | |
| tree | 321bcc1bfc489e2e7d0ff10dae620864ab08d054 /crates/texm/src/tests.rs | |
| parent | 18d4c6cf9fabc18282b29d103c8d30024f66e49b (diff) | |
| download | fparkan-a281ffa32ea615670d369503692f057b2dc60e6f.tar.xz fparkan-a281ffa32ea615670d369503692f057b2dc60e6f.zip | |
feat: Enhance model and texture loading with improved error handling and new features
- Introduced `LoadedModel` and `LoadedTexture` structs for better encapsulation of model and texture data.
- Added functions to load models and textures from archives, including support for resolving textures based on materials and wear entries.
- Implemented error handling for missing textures, materials, and wear entries.
- Updated the rendering pipeline to support texture loading and binding, including command-line arguments for texture customization.
- Enhanced the `texm` crate with new decoding capabilities for various pixel formats, including indexed textures.
- Added tests for texture decoding and loading to ensure reliability and correctness.
- Updated documentation to reflect changes in the material and texture resolution process.
Diffstat (limited to 'crates/texm/src/tests.rs')
| -rw-r--r-- | crates/texm/src/tests.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/crates/texm/src/tests.rs b/crates/texm/src/tests.rs index d021346..3d990bf 100644 --- a/crates/texm/src/tests.rs +++ b/crates/texm/src/tests.rs @@ -116,6 +116,26 @@ fn texm_parse_minimal_argb8888_no_page() { } #[test] +fn texm_decode_minimal_argb8888_no_page() { + let mut payload = Vec::new(); + payload.extend_from_slice(&TEXM_MAGIC.to_le_bytes()); + payload.extend_from_slice(&1u32.to_le_bytes()); // width + payload.extend_from_slice(&1u32.to_le_bytes()); // height + payload.extend_from_slice(&1u32.to_le_bytes()); // mip_count + payload.extend_from_slice(&0u32.to_le_bytes()); // flags4 + payload.extend_from_slice(&0u32.to_le_bytes()); // flags5 + payload.extend_from_slice(&0u32.to_le_bytes()); // unk6 + payload.extend_from_slice(&8888u32.to_le_bytes()); // format + payload.extend_from_slice(&[0x40, 0x11, 0x22, 0x33]); // A,R,G,B in little-endian order + + let parsed = parse_texm(&payload).expect("failed to parse minimal texm"); + let decoded = decode_mip_rgba8(&parsed, &payload, 0).expect("failed to decode mip"); + assert_eq!(decoded.width, 1); + assert_eq!(decoded.height, 1); + assert_eq!(decoded.rgba8, vec![0x11, 0x22, 0x33, 0x40]); +} + +#[test] fn texm_parse_indexed_with_page_chunk() { let mut payload = Vec::new(); payload.extend_from_slice(&TEXM_MAGIC.to_le_bytes()); @@ -148,3 +168,28 @@ fn texm_parse_indexed_with_page_chunk() { } ); } + +#[test] +fn texm_decode_indexed_with_palette() { + let mut payload = Vec::new(); + payload.extend_from_slice(&TEXM_MAGIC.to_le_bytes()); + payload.extend_from_slice(&2u32.to_le_bytes()); // width + payload.extend_from_slice(&1u32.to_le_bytes()); // height + payload.extend_from_slice(&1u32.to_le_bytes()); // mip_count + payload.extend_from_slice(&0u32.to_le_bytes()); // flags4 + payload.extend_from_slice(&0u32.to_le_bytes()); // flags5 + payload.extend_from_slice(&0u32.to_le_bytes()); // unk6 + payload.extend_from_slice(&0u32.to_le_bytes()); // format indexed8 + + let mut palette = [0u8; 1024]; + palette[4..8].copy_from_slice(&[10, 20, 30, 255]); // index 1 + palette[8..12].copy_from_slice(&[40, 50, 60, 200]); // index 2 + payload.extend_from_slice(&palette); + payload.extend_from_slice(&[1u8, 2u8]); // two pixels + + let parsed = parse_texm(&payload).expect("failed to parse indexed texm"); + let decoded = decode_mip_rgba8(&parsed, &payload, 0).expect("failed to decode indexed texm"); + assert_eq!(decoded.width, 2); + assert_eq!(decoded.height, 1); + assert_eq!(decoded.rgba8, vec![10, 20, 30, 255, 40, 50, 60, 200]); +} |
