mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-20 11:47:46 +00:00
Parse texture attribute and formats
This commit is contained in:
parent
214e5495fe
commit
0210479fd3
3 changed files with 86 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -441,6 +441,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"binrw",
|
"binrw",
|
||||||
"bitfield-struct",
|
"bitfield-struct",
|
||||||
|
"bitflags",
|
||||||
"crc",
|
"crc",
|
||||||
"criterion",
|
"criterion",
|
||||||
"glam",
|
"glam",
|
||||||
|
|
|
@ -50,3 +50,6 @@ sha1_smol = "1.0.0"
|
||||||
|
|
||||||
# needed for deconstructing skeleton pose matrices
|
# needed for deconstructing skeleton pose matrices
|
||||||
glam = "0.21.3"
|
glam = "0.21.3"
|
||||||
|
|
||||||
|
# needed for c-style bitflags used in some formats (such as tex files)
|
||||||
|
bitflags = "1.3"
|
83
src/tex.rs
83
src/tex.rs
|
@ -2,12 +2,91 @@ use std::io::Cursor;
|
||||||
use binrw::binread;
|
use binrw::binread;
|
||||||
use crate::gamedata::MemoryBuffer;
|
use crate::gamedata::MemoryBuffer;
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
// Attributes and Format are adapted from Lumina (https://github.com/NotAdam/Lumina/blob/master/src/Lumina/Data/Files/TexFile.cs)
|
||||||
|
bitflags! {
|
||||||
|
#[binread]
|
||||||
|
struct TextureAttribute : u32 {
|
||||||
|
const DiscardPerFrame = 0x1;
|
||||||
|
const DiscardPerMap = 0x2;
|
||||||
|
|
||||||
|
const Managed = 0x4;
|
||||||
|
const UserManaged = 0x8;
|
||||||
|
const CpuRead = 0x10;
|
||||||
|
const LocationMain = 0x20;
|
||||||
|
const NoGpuRead = 0x40;
|
||||||
|
const AlignedSize = 0x80;
|
||||||
|
const EdgeCulling = 0x100;
|
||||||
|
const LocationOnion = 0x200;
|
||||||
|
const ReadWrite = 0x400;
|
||||||
|
const Immutable = 0x800;
|
||||||
|
|
||||||
|
const TextureRenderTarget = 0x100000;
|
||||||
|
const TextureDepthStencil = 0x200000;
|
||||||
|
const TextureType1D = 0x400000;
|
||||||
|
const TextureType2D = 0x800000;
|
||||||
|
const TextureType3D = 0x1000000;
|
||||||
|
const TextureTypeCube = 0x2000000;
|
||||||
|
const TextureTypeMask = 0x3C00000;
|
||||||
|
const TextureSwizzle = 0x4000000;
|
||||||
|
const TextureNoTiled = 0x8000000;
|
||||||
|
const TextureNoSwizzle = 0x80000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
#[binread]
|
||||||
|
struct TextureFormat : u32 {
|
||||||
|
const TypeShift = 0xC;
|
||||||
|
const TypeMask = 0xF000;
|
||||||
|
const ComponentShift = 0x8;
|
||||||
|
const ComponentMask = 0xF00;
|
||||||
|
const BppShift = 0x4;
|
||||||
|
const BppMask = 0xF0;
|
||||||
|
const EnumShift = 0x0;
|
||||||
|
const EnumMask = 0xF;
|
||||||
|
const TypeInteger = 0x1;
|
||||||
|
const TypeFloat = 0x2;
|
||||||
|
const TypeDxt = 0x3;
|
||||||
|
const TypeBc123 = 0x3;
|
||||||
|
const TypeDepthStencil = 0x4;
|
||||||
|
const TypeSpecial = 0x5;
|
||||||
|
const TypeBc57 = 0x6;
|
||||||
|
|
||||||
|
const L8 = 0x1130;
|
||||||
|
const A8 = 0x1131;
|
||||||
|
const B4G4R4A4 = 0x1440;
|
||||||
|
const B5G5R5A1 = 0x1441;
|
||||||
|
const B8G8R8A8 = 0x1450;
|
||||||
|
const B8G8R8X8 = 0x1451;
|
||||||
|
|
||||||
|
const R32F = 0x2150;
|
||||||
|
const R16G16F = 0x2250;
|
||||||
|
const R32G32F = 0x2260;
|
||||||
|
const R16G16B16A16F = 0x2460;
|
||||||
|
const R32G32B32A32F = 0x2470;
|
||||||
|
|
||||||
|
const BC1 = 0x3420;
|
||||||
|
const BC2 = 0x3430;
|
||||||
|
const BC3 = 0x3431;
|
||||||
|
const BC5 = 0x6230;
|
||||||
|
const BC7 = 0x6432;
|
||||||
|
|
||||||
|
const D16 = 0x4140;
|
||||||
|
const D24S8 = 0x4250;
|
||||||
|
|
||||||
|
const Null = 0x5100;
|
||||||
|
const Shadow16 = 0x5140;
|
||||||
|
const Shadow24 = 0x5150;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[binread]
|
#[binread]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct TexHeader {
|
struct TexHeader {
|
||||||
attribute : u32,
|
attribute : TextureAttribute,
|
||||||
format: u32,
|
format: TextureFormat,
|
||||||
|
|
||||||
width : u16,
|
width : u16,
|
||||||
height : u16,
|
height : u16,
|
||||||
|
|
Loading…
Add table
Reference in a new issue