Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move texture handling out of gui #12

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::io::{Cursor, Write};
use std::num::NonZeroU32;

use crate::package_manager::get_hash64;
use crate::texture::{Texture, TextureCache};
use crate::{package_manager::package_manager, tagtypes::TagType};

use super::texture::{Texture, TextureCache};
use super::TOASTS;

lazy_static! {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/external_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::gui::common::ResponseExt;
use crate::gui::tag::{
format_tag_entry, ExtendedScanResult, ExtendedTagHash, ScannedHashWithEntry,
};
use crate::gui::texture::TextureCache;
use crate::gui::ViewAction;
use crate::scanner;
use crate::scanner::ScannerContext;
use crate::tagtypes::TagType;
use crate::texture::TextureCache;
use eframe::egui;

pub struct ExternalFileScanView {
Expand Down
4 changes: 1 addition & 3 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod audio;
#[cfg(feature = "audio")]
mod audio_list;
mod common;
mod dxgi;
mod external_file;
mod hexview;
mod named_tags;
Expand All @@ -12,7 +11,6 @@ mod raw_strings;
mod strings;
mod style;
mod tag;
mod texture;
mod texturelist;

use std::cell::RefCell;
Expand Down Expand Up @@ -44,13 +42,13 @@ use self::packages::PackagesView;
use self::raw_strings::RawStringsView;
use self::strings::StringsView;
use self::tag::TagView;
use self::texture::TextureCache;
use self::texturelist::TexturesView;
use crate::classes;
use crate::gui::external_file::ExternalFileScanView;
use crate::gui::tag::TagHistory;
use crate::scanner::{fnv1, ScannerContext};
use crate::text::RawStringHashCache;
use crate::texture::TextureCache;
use crate::{
package_manager::package_manager,
scanner,
Expand Down
11 changes: 5 additions & 6 deletions src/gui/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ use destiny_pkg::package::UEntryHeader;
use destiny_pkg::{manager::PackagePath, TagHash};
use eframe::egui::{self, RichText};

use crate::gui::common::open_audio_file_in_default_application;
use crate::package_manager::get_hash64;
use crate::util::format_file_size;
use crate::{package_manager::package_manager, tagtypes::TagType};

use super::{
common::{dump_wwise_info, ResponseExt},
tag::format_tag_entry,
texture::TextureCache,
View, ViewAction,
};
use crate::gui::common::open_audio_file_in_default_application;
use crate::package_manager::get_hash64;
use crate::texture::TextureCache;
use crate::util::format_file_size;
use crate::{package_manager::package_manager, tagtypes::TagType};

pub struct PackagesView {
selected_package: u16,
Expand Down
6 changes: 4 additions & 2 deletions src/gui/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ use super::{
open_audio_file_in_default_application, open_tag_in_default_application, tag_context,
ResponseExt,
},
texture::TextureCache,
View, ViewAction,
};
use crate::classes::get_class_by_id;
use crate::gui::hexview::TagHexView;
use crate::package_manager::get_hash64;
use crate::scanner::ScannedHash;
use crate::util::ui_image_rotated;
use crate::{gui::texture::Texture, scanner::read_raw_string_blob, text::RawStringHashCache};
use crate::{
package_manager::package_manager,
scanner::{ScanResult, TagCache},
tagtypes::TagType,
text::StringCache,
};
use crate::{
scanner::read_raw_string_blob, text::RawStringHashCache, texture::Texture,
texture::TextureCache,
};
use binrw::{binread, BinReaderExt, Endian};
use destiny_pkg::{package::UEntryHeader, GameVersion, TagHash, TagHash64};
use eframe::egui::load::SizedTexture;
Expand Down
123 changes: 0 additions & 123 deletions src/gui/texture/swizzle_ps4.rs

This file was deleted.

9 changes: 6 additions & 3 deletions src/gui/texturelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use eframe::egui::{self, pos2, vec2, Color32, Pos2, RichText, Stroke, Ui, Vec2,
use eframe::emath::Rot2;
use std::fmt::{Display, Formatter};

use crate::gui::texture::{Texture, TextureDesc};
use crate::util::ui_image_rotated;
use crate::{package_manager::package_manager, tagtypes::TagType};
use crate::{
package_manager::package_manager,
tagtypes::TagType,
texture::{Texture, TextureCache, TextureDesc},
};

use super::{common::ResponseExt, texture::TextureCache, View, ViewAction};
use super::{common::ResponseExt, View, ViewAction};

pub struct TexturesView {
selected_package: u16,
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod panic_handler;
mod scanner;
mod tagtypes;
mod text;
mod texture;
mod util;

use std::sync::Arc;
Expand Down
122 changes: 122 additions & 0 deletions src/gui/dxgi.rs → src/texture/dxgi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,3 +903,125 @@ impl TryFrom<u8> for XenosSurfaceFormat {
})
}
}

#[allow(non_snake_case, non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(u8)]
#[allow(dead_code)]
pub enum GcmSurfaceFormat {
B8 = 0x81,
A1R5G5B5 = 0x82,
A4R4G4B4 = 0x83,
R5G6B5 = 0x84,
A8R8G8B8 = 0x85,
COMPRESSED_DXT1 = 0x86,
COMPRESSED_DXT23 = 0x87,
COMPRESSED_DXT45 = 0x88,
G8B8 = 0x8B,
COMPRESSED_B8R8_G8R8 = 0x8D,
COMPRESSED_R8B8_R8G8 = 0x8E,
R6G5B5 = 0x8F,
DEPTH24_D8 = 0x90,
DEPTH24_D8_FLOAT = 0x91,
DEPTH16 = 0x92,
DEPTH16_FLOAT = 0x93,
X16 = 0x94,
Y16_X16 = 0x95,
R5G5B5A1 = 0x97,
COMPRESSED_HILO8 = 0x98,
COMPRESSED_HILO_S8 = 0x99,
W16_Z16_Y16_X16_FLOAT = 0x9A,
W32_Z32_Y32_X32_FLOAT = 0x9B,
X32_FLOAT = 0x9C,
D1R5G5B5 = 0x9D,
D8R8G8B8 = 0x9E,
Y16_X16_FLOAT = 0x9F,
}

impl GcmSurfaceFormat {
pub fn to_wgpu(self) -> anyhow::Result<wgpu::TextureFormat> {
Ok(match self {
GcmSurfaceFormat::B8 => wgpu::TextureFormat::R8Unorm,
GcmSurfaceFormat::A8R8G8B8 => wgpu::TextureFormat::Rgba8UnormSrgb,
GcmSurfaceFormat::COMPRESSED_DXT1 => wgpu::TextureFormat::Bc1RgbaUnormSrgb,
GcmSurfaceFormat::COMPRESSED_DXT23 => wgpu::TextureFormat::Bc2RgbaUnormSrgb,
GcmSurfaceFormat::COMPRESSED_DXT45 => wgpu::TextureFormat::Bc3RgbaUnormSrgb,
GcmSurfaceFormat::G8B8 => wgpu::TextureFormat::Rg8Unorm,
GcmSurfaceFormat::DEPTH24_D8 => wgpu::TextureFormat::Depth24PlusStencil8,
GcmSurfaceFormat::DEPTH24_D8_FLOAT => wgpu::TextureFormat::Depth24PlusStencil8,
GcmSurfaceFormat::DEPTH16 => wgpu::TextureFormat::Depth16Unorm,
GcmSurfaceFormat::DEPTH16_FLOAT => wgpu::TextureFormat::Depth16Unorm,
GcmSurfaceFormat::X16 => wgpu::TextureFormat::R16Unorm,
GcmSurfaceFormat::Y16_X16 => wgpu::TextureFormat::Rg16Unorm,
GcmSurfaceFormat::W16_Z16_Y16_X16_FLOAT => wgpu::TextureFormat::Rgba16Float,
GcmSurfaceFormat::W32_Z32_Y32_X32_FLOAT => wgpu::TextureFormat::Rgba32Float,
GcmSurfaceFormat::X32_FLOAT => wgpu::TextureFormat::R32Float,
GcmSurfaceFormat::D8R8G8B8 => wgpu::TextureFormat::Rgba8UnormSrgb,
GcmSurfaceFormat::Y16_X16_FLOAT => wgpu::TextureFormat::Rg16Float,
u => anyhow::bail!("Unsupported GCM surface format conversion ({u:?} => ??)"),
})
}

pub fn bpp(&self) -> usize {
match self {
GcmSurfaceFormat::B8 => 8,
GcmSurfaceFormat::A1R5G5B5 => 16,
GcmSurfaceFormat::A4R4G4B4 => 16,
GcmSurfaceFormat::R5G6B5 => 16,
GcmSurfaceFormat::A8R8G8B8 => 32,
GcmSurfaceFormat::COMPRESSED_DXT1 => 4,
GcmSurfaceFormat::COMPRESSED_DXT23 | GcmSurfaceFormat::COMPRESSED_DXT45 => 8,
GcmSurfaceFormat::G8B8 => 16,
GcmSurfaceFormat::DEPTH24_D8 => 32,
GcmSurfaceFormat::DEPTH24_D8_FLOAT => 32,
GcmSurfaceFormat::DEPTH16 => 16,
GcmSurfaceFormat::DEPTH16_FLOAT => 16,
GcmSurfaceFormat::X16 => 16,
GcmSurfaceFormat::Y16_X16 => 32,
GcmSurfaceFormat::R5G5B5A1 => 16,
GcmSurfaceFormat::Y16_X16_FLOAT => 32,
u => unimplemented!("Unsupported GCM surface format bpp ({u:?} => ??)"),
}
}

pub fn block_size(&self) -> usize {
match self {
GcmSurfaceFormat::COMPRESSED_DXT1 => 8,
GcmSurfaceFormat::COMPRESSED_DXT23 | GcmSurfaceFormat::COMPRESSED_DXT45 => 16,
u => u.bpp() / 8,
}
}

pub fn pixel_block_size(&self) -> usize {
match self {
GcmSurfaceFormat::COMPRESSED_DXT1
| GcmSurfaceFormat::COMPRESSED_DXT23
| GcmSurfaceFormat::COMPRESSED_DXT45 => 4,
_ => 1,
}
}

pub fn is_compressed(&self) -> bool {
matches!(
self,
GcmSurfaceFormat::COMPRESSED_DXT1
| GcmSurfaceFormat::COMPRESSED_DXT23
| GcmSurfaceFormat::COMPRESSED_DXT45
| GcmSurfaceFormat::COMPRESSED_B8R8_G8R8
| GcmSurfaceFormat::COMPRESSED_R8B8_R8G8
| GcmSurfaceFormat::COMPRESSED_HILO8
| GcmSurfaceFormat::COMPRESSED_HILO_S8
)
}
}

impl TryFrom<u8> for GcmSurfaceFormat {
type Error = anyhow::Error;

fn try_from(value: u8) -> Result<Self, Self::Error> {
Ok(match value {
0x81..=0x9F => unsafe { transmute(value) },
e => return Err(anyhow::anyhow!("GCM format is out of range ({e:x})")),
})
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use binrw::BinRead;
use destiny_pkg::TagHash;

use crate::gui::dxgi::DxgiFormat;
use super::dxgi::DxgiFormat;

#[derive(Debug, BinRead)]
#[br(import(prebl: bool))]
Expand Down
Loading