SiegeEngine / ddsfile

DirectDraw Surface file format parser/composer
MIT License
12 stars 12 forks source link

Data size is wrong for cubemaps #12

Open expenses opened 2 years ago

expenses commented 2 years ago

I've been working on a ktx2 to dds converter, mostly because renderdoc works well as a dds viewer but doesn't handle ktx2 files currently. Currently the size of data in Dds structs files created with Dds::new_dxgi and is_cubemap set to true is only the size of one of the cubemap faces.

Luckily, the data field is public so you can manipulate it without using any crate functions. Here's what I'm doing to pub a ktx2 cubemap in the right format:

let face_count = header.face_count as usize;

let mut faces = vec![Vec::new(); face_count];

for level in ktx2.levels() {
    let size = level.bytes.len() / face_count;
    for (i, face) in faces.iter_mut().enumerate() {
        let slice = &level.bytes[i * size..(i + 1) * size];
        face.extend_from_slice(slice);
    }
}

dds.data = faces.concat();

It'd be cool to have a really flexible api for manipulating the dds data. I'm not 100% sure what that'd be like yet though.

mikedilger commented 2 years ago

Thanks for that info. I don't have time to maintain this crate that I wrote four years ago and don't myself use. But if you provide a PR I'll merge it, or if you want to take over let me know.