From 5dc90e6ec836560257f71825ef6c87e4f39c9a45 Mon Sep 17 00:00:00 2001 From: Asval Date: Thu, 3 Aug 2023 04:39:15 +0200 Subject: [PATCH] virtual textures preview --- CUE4Parse | 2 +- FModel/Creator/Utils.cs | 2 +- FModel/ViewModels/CUE4ParseViewModel.cs | 2 +- FModel/Views/Snooper/Options.cs | 8 ++++---- FModel/Views/Snooper/Shading/Texture.cs | 9 +++++---- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CUE4Parse b/CUE4Parse index fdc0ff0f..f9bff17d 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit fdc0ff0f3b7c1578d083ed0f6b3ea7d0419e087a +Subproject commit f9bff17d172e72184678211c567f708e25bb3f68 diff --git a/FModel/Creator/Utils.cs b/FModel/Creator/Utils.cs index 0eeec083..57bc1213 100644 --- a/FModel/Creator/Utils.cs +++ b/FModel/Creator/Utils.cs @@ -112,7 +112,7 @@ public static class Utils public static SKBitmap GetB64Bitmap(string b64) => SKBitmap.Decode(new MemoryStream(Convert.FromBase64String(b64)) { Position = 0 }); public static SKBitmap GetBitmap(FSoftObjectPath softObjectPath) => GetBitmap(softObjectPath.AssetPathName.Text); public static SKBitmap GetBitmap(string fullPath) => TryLoadObject(fullPath, out UTexture2D texture) ? GetBitmap(texture) : null; - public static SKBitmap GetBitmap(UTexture2D texture) => texture.IsVirtual ? null : texture.Decode(UserSettings.Default.CurrentDir.TexturePlatform); + public static SKBitmap GetBitmap(UTexture2D texture) => texture.Decode(UserSettings.Default.CurrentDir.TexturePlatform); public static SKBitmap GetBitmap(byte[] data) => SKBitmap.Decode(data); public static SKBitmap ResizeWithRatio(this SKBitmap me, double width, double height) diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index d069b7e7..d97e85fb 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -873,7 +873,7 @@ public class CUE4ParseViewModel : ViewModel TabControl.SelectedTab.SetDocumentText(verseDigest.ReadableCode, false, false); return true; } - case UTexture { IsVirtual: false } texture when isNone || saveTextures: + case UTexture texture when isNone || saveTextures: { TabControl.SelectedTab.AddImage(texture, saveTextures, updateUi); return false; diff --git a/FModel/Views/Snooper/Options.cs b/FModel/Views/Snooper/Options.cs index cc4dd100..6194b175 100644 --- a/FModel/Views/Snooper/Options.cs +++ b/FModel/Views/Snooper/Options.cs @@ -180,13 +180,13 @@ public class Options public bool TryGetTexture(UTexture2D o, bool fix, out Texture texture) { var guid = o.LightingGuid; - if (!Textures.TryGetValue(guid, out texture) && o.GetMipByMaxSize(UserSettings.Default.PreviewMaxTextureSize) is { } mip) + if (!Textures.TryGetValue(guid, out texture) && + o.Decode(UserSettings.Default.PreviewMaxTextureSize, UserSettings.Default.CurrentDir.TexturePlatform) is { } bitmap) { - TextureDecoder.DecodeTexture(mip, o.Format, o.IsNormalMap, _platform, out var data, out _); - - texture = new Texture(data, mip.SizeX, mip.SizeY, o); + texture = new Texture(bitmap, o); if (fix) TextureHelper.FixChannels(_game, texture); Textures[guid] = texture; + bitmap.Dispose(); } return texture != null; } diff --git a/FModel/Views/Snooper/Shading/Texture.cs b/FModel/Views/Snooper/Shading/Texture.cs index 0cf871bf..692ed13a 100644 --- a/FModel/Views/Snooper/Shading/Texture.cs +++ b/FModel/Views/Snooper/Shading/Texture.cs @@ -8,6 +8,7 @@ using ImGuiNET; using OpenTK.Graphics.OpenGL4; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; +using SkiaSharp; namespace FModel.Views.Snooper.Shading; @@ -78,7 +79,7 @@ public class Texture : IDisposable GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, _target, _handle, 0); } - public Texture(byte[] data, int width, int height, UTexture2D texture2D) : this(TextureType.Normal) + public Texture(SKBitmap bitmap, UTexture2D texture2D) : this(TextureType.Normal) { Type = texture2D.ExportType; Guid = texture2D.LightingGuid; @@ -87,11 +88,11 @@ public class Texture : IDisposable Format = texture2D.Format; ImportedWidth = texture2D.ImportedSize.X; ImportedHeight = texture2D.ImportedSize.Y; - Width = width; - Height = height; + Width = bitmap.Width; + Height = bitmap.Height; Bind(TextureUnit.Texture0); - GL.TexImage2D(_target, 0, texture2D.SRGB ? PixelInternalFormat.Srgb : PixelInternalFormat.Rgb, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, data); + GL.TexImage2D(_target, 0, texture2D.SRGB ? PixelInternalFormat.Srgb : PixelInternalFormat.Rgb, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, bitmap.Bytes); GL.TexParameter(_target, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.LinearMipmapLinear); GL.TexParameter(_target, TextureParameterName.TextureMagFilter, (int) TextureMagFilter.Linear); GL.TexParameter(_target, TextureParameterName.TextureBaseLevel, 0);