pub struct Texture {
pub name: String,
pub width: u32,
pub height: u32,
pub format: u32,
pub number_of_images: u32,
pub data: Vec<u8>,
pub min_lod: f32,
pub max_lod: f32,
}Expand description
Holds a hardware-encoded image. Potentially may store multiple mip levels in a hierarchy. See https://en.wikipedia.org/wiki/Mipmap#Mechanism.
Fields§
§name: StringName of this resource.
width: u32Valid in range [1, 1024]. Hardware register is only 10 bits–you cannot exceed this limitation, even on emulator.
height: u32Valid in range [1, 1024]. Hardware register is only 10 bits–you cannot exceed this limitation, even on emulator.
format: u32GPU texture format to be directly loaded into VRAM. Most commonly CMPR a.k.a. BC1 a.k.a. DXT1 (tex.format == 14).
Full enum (from gctex):
pub enum TextureFormat {
I4 = 0,
I8,
IA4,
IA8,
RGB565,
RGB5A3,
RGBA8,
C4 = 0x8,
C8,
C14X2,
CMPR = 0xE,
};With gctex, use gctex::TextureFormat::from_u32(...) on this field.
number_of_images: u32Set to 1 for no mipmaps. Valid in range [1, 11]. More tightly bounded above by 1 + floor(log2(min(width, height))).
data: Vec<u8>Raw GPU texture data. Use gctex or similar to decode.
§Examples
use gctex;
let tex = brres::Texture {
name: "Example".to_string(),
width: 8,
height: 8,
format: 14,
number_of_images: 1,
data: vec![0xF7, 0xBE, 0x6B, 0x0D, 0x34, 0x0E, 0x0D, 0x02, 0xF7, 0x7D, 0x52, 0x4A, 0x20, 0x28, 0xD8, 0xE0,
0xFF, 0xDF, 0x08, 0x25, 0x00, 0xAA, 0xDE, 0xFC, 0xEF, 0x5C, 0x31, 0x07, 0x00, 0xF8, 0x5C, 0x9C],
min_lod: 0.0,
max_lod: 0.0,
};
let texture_format = gctex::TextureFormat::from_u32(tex.format).unwrap();
let raw_rgba_buffer = gctex::decode(&tex.data, tex.width, tex.height, texture_format, &[0], 0);
assert_eq!(raw_rgba_buffer,
[0xF7, 0xF7, 0xF7, 0xFF, 0x9F, 0x99, 0x9F, 0xFF, 0x6B, 0x61, 0x6B, 0xFF, 0xF7, 0xF7, 0xF7, 0xFF,
0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F, 0xEB, 0xE7, 0xFF,
0x64, 0x60, 0x79, 0xFF, 0x08, 0x04, 0x29, 0xFF, 0x64, 0x60, 0x79, 0xFF, 0xA2, 0x9E, 0xAE, 0xFF,
0x31, 0x20, 0x39, 0xFF, 0x31, 0x20, 0x39, 0xFF, 0x78, 0x6C, 0x7A, 0xFF, 0xEF, 0xEB, 0xE7, 0xFF,
0x64, 0x60, 0x79, 0xFF, 0x64, 0x60, 0x79, 0xFF, 0x64, 0x60, 0x79, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF,
0xA7, 0x9E, 0xA5, 0xFF, 0x31, 0x20, 0x39, 0xFF, 0x78, 0x6C, 0x7A, 0xFF, 0xEF, 0xEB, 0xE7, 0xFF]);min_lod: f32Always recomputed on save (currently).
Set to 0.0.
max_lod: f32Always recomputed on save (currently).
Set to (tex.number_of_images - 1) as f32.