From c53ee125786d3fcaa3a9ca5a38c20860aec9f0dc Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 6 Feb 2022 05:13:19 -0800 Subject: [PATCH] Add ability to check if DXT1/BC1 is supported, create a fake texture for the time being for hardware that doesn't support it --- Graphics/src/lib.rs | 5 +++++ Runtime/Graphics/CTextureBoo.cpp | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Graphics/src/lib.rs b/Graphics/src/lib.rs index dcaa79eb8..3c94bae75 100644 --- a/Graphics/src/lib.rs +++ b/Graphics/src/lib.rs @@ -110,6 +110,7 @@ mod ffi { fn get_args() -> Vec; fn get_window_size() -> WindowSize; fn set_window_title(title: &CxxString); + fn get_dxt_compression_supported() -> bool; fn get_backend() -> Backend; fn get_backend_string() -> &'static str; fn set_fullscreen(v: bool); @@ -326,6 +327,10 @@ fn get_backend() -> ffi::Backend { } } +fn get_dxt_compression_supported() -> bool { + return get_app().gpu.adapter.features().contains(wgpu::Features::TEXTURE_COMPRESSION_BC); +} + fn get_backend_string() -> &'static str { match get_app().gpu.backend { Backend::Vulkan => "Vulkan", diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp index 8f8c5a335..3c359b14f 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -754,7 +754,24 @@ CTexture::CTexture(std::unique_ptr&& in, u32 length, bool otex, const CTex BuildRGBA8FromGCN(r, label); break; case ETexelFormat::CMPR: - BuildDXT1FromGCN(r, label); + if (aurora::get_dxt_compression_supported()) { + BuildDXT1FromGCN(r, label); + } else { + Log.report(logvisor::Error, FMT_STRING("BC/DXT1 compression is not supported on your GPU, unable to load {}"), + label); + x0_fmt = ETexelFormat::RGBA8PC; + x8_mips = 1; + std::unique_ptr data= std::make_unique(x4_w * x6_h * 4); + /* Build a fake texture to use */ + for (u32 i = 0; i < (x4_w * x6_h) * 4; i += 4) { + data[i + 0] = 0xFF; + data[i + 1] = 0x00; + data[i + 2] = 0xFF; + data[i + 3] = 0xFF; + } + m_tex = aurora::new_static_texture_2d(x4_w, x6_h, x8_mips, aurora::shaders::TextureFormat::RGBA8, + {reinterpret_cast(data.get()), (x4_w * x6_h * 4ul)}, label); + } break; case ETexelFormat::RGBA8PC: BuildRGBA8(owned.get() + 12, length - 12, label);