Skip to content

Commit

Permalink
virtual textures preview
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Aug 3, 2023
1 parent 6ed335d commit 5dc90e6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion FModel/Creator/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static SKBitmap GetBitmap(UMaterialInstanceConstant material)
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)
Expand Down
2 changes: 1 addition & 1 deletion FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ public void ExtractAndScroll(CancellationToken cancellationToken, string fullPat
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;
Expand Down
8 changes: 4 additions & 4 deletions FModel/Views/Snooper/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ public void SelectMorph(int index, Model model)
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;
}
Expand Down
9 changes: 5 additions & 4 deletions FModel/Views/Snooper/Shading/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OpenTK.Graphics.OpenGL4;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SkiaSharp;

namespace FModel.Views.Snooper.Shading;

Expand Down Expand Up @@ -78,7 +79,7 @@ public Texture(int width, int height) : this(TextureType.Framebuffer)
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;
Expand All @@ -87,11 +88,11 @@ public Texture(byte[] data, int width, int height, UTexture2D texture2D) : this(
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);
Expand Down

0 comments on commit 5dc90e6

Please sign in to comment.