This commit is contained in:
Soreepeong 2024-02-28 21:17:50 +09:00
parent cc756c243c
commit ca986b46a2
6 changed files with 69 additions and 67 deletions

View file

@ -343,7 +343,7 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid
cancellationToken);
/// <inheritdoc/>
public bool SupportsDxgiFormat(int dxgiFormat)
public bool IsDxgiFormatSupported(int dxgiFormat)
{
if (this.interfaceManager.Scene is not { } scene)
{
@ -516,7 +516,7 @@ internal sealed class TextureManager : IServiceType, IDisposable, ITextureProvid
var buffer = file.TextureBuffer;
var (dxgiFormat, conversion) = TexFile.GetDxgiFormatFromTextureFormat(file.Header.Format, false);
if (conversion != TexFile.DxgiFormatConversion.NoConversion || !this.SupportsDxgiFormat(dxgiFormat))
if (conversion != TexFile.DxgiFormatConversion.NoConversion || !this.IsDxgiFormatSupported(dxgiFormat))
{
dxgiFormat = (int)Format.B8G8R8A8_UNorm;
buffer = buffer.Filter(0, 0, TexFile.TextureFormat.B8G8R8A8);

View file

@ -107,31 +107,31 @@ internal class TexWidget : IDataWindowWidget
ImGui.PopID();
}
if (ImGui.CollapsingHeader("Load Game File by Icon ID", ImGuiTreeNodeFlags.DefaultOpen))
if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromGameIcon), ImGuiTreeNodeFlags.DefaultOpen))
{
ImGui.PushID(nameof(this.DrawIconInput));
this.DrawIconInput();
ImGui.PushID(nameof(this.DrawGetFromGameIcon));
this.DrawGetFromGameIcon();
ImGui.PopID();
}
if (ImGui.CollapsingHeader("Load Game File by Path", ImGuiTreeNodeFlags.DefaultOpen))
if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromGame), ImGuiTreeNodeFlags.DefaultOpen))
{
ImGui.PushID(nameof(this.DrawGamePathInput));
this.DrawGamePathInput();
ImGui.PushID(nameof(this.DrawGetFromGame));
this.DrawGetFromGame();
ImGui.PopID();
}
if (ImGui.CollapsingHeader("Load File", ImGuiTreeNodeFlags.DefaultOpen))
if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromFile), ImGuiTreeNodeFlags.DefaultOpen))
{
ImGui.PushID(nameof(this.DrawFileInput));
this.DrawFileInput();
ImGui.PushID(nameof(this.DrawGetFromFile));
this.DrawGetFromFile();
ImGui.PopID();
}
if (ImGui.CollapsingHeader("Load Assembly Manifest Resource", ImGuiTreeNodeFlags.DefaultOpen))
if (ImGui.CollapsingHeader(nameof(ITextureProvider.GetFromManifestResource), ImGuiTreeNodeFlags.DefaultOpen))
{
ImGui.PushID(nameof(this.DrawAssemblyManifestResourceInput));
this.DrawAssemblyManifestResourceInput();
ImGui.PushID(nameof(this.DrawGetFromManifestResource));
this.DrawGetFromManifestResource();
ImGui.PopID();
}
@ -308,7 +308,7 @@ internal class TexWidget : IDataWindowWidget
ImGuiHelpers.ScaledDummy(10);
}
private void DrawIconInput()
private void DrawGetFromGameIcon()
{
ImGui.InputText("Icon ID", ref this.iconId, 32);
ImGui.Checkbox("HQ Item", ref this.hq);
@ -342,7 +342,7 @@ internal class TexWidget : IDataWindowWidget
ImGuiHelpers.ScaledDummy(10);
}
private void DrawGamePathInput()
private void DrawGetFromGame()
{
ImGui.InputText("Tex Path", ref this.inputTexPath, 255);
@ -362,7 +362,7 @@ internal class TexWidget : IDataWindowWidget
ImGuiHelpers.ScaledDummy(10);
}
private void DrawFileInput()
private void DrawGetFromFile()
{
ImGui.InputText("File Path", ref this.inputFilePath, 255);
@ -382,7 +382,7 @@ internal class TexWidget : IDataWindowWidget
ImGuiHelpers.ScaledDummy(10);
}
private void DrawAssemblyManifestResourceInput()
private void DrawGetFromManifestResource()
{
if (this.inputManifestResourceAssemblyCandidateNames is null ||
this.inputManifestResourceAssemblyCandidates is null)

View file

@ -580,7 +580,7 @@ internal sealed partial class FontAtlasFactory
var buf = Array.Empty<byte>();
try
{
var use4 = this.factory.TextureManager.SupportsDxgiFormat((int)Format.B4G4R4A4_UNorm);
var use4 = this.factory.TextureManager.IsDxgiFormatSupported((int)Format.B4G4R4A4_UNorm);
var bpp = use4 ? 2 : 4;
var width = this.NewImAtlas.TexWidth;
var height = this.NewImAtlas.TexHeight;

View file

@ -353,7 +353,7 @@ internal sealed partial class FontAtlasFactory
var numPixels = texFile.Header.Width * texFile.Header.Height;
_ = Service<InterfaceManager.InterfaceManagerWithScene>.Get();
var targetIsB4G4R4A4 = this.TextureManager.SupportsDxgiFormat((int)Format.B4G4R4A4_UNorm);
var targetIsB4G4R4A4 = this.TextureManager.IsDxgiFormatSupported((int)Format.B4G4R4A4_UNorm);
var bpp = targetIsB4G4R4A4 ? 2 : 4;
var buffer = ArrayPool<byte>.Shared.Rent(numPixels * bpp);
try

View file

@ -4,6 +4,8 @@ using Dalamud.Interface;
using Dalamud.Interface.Internal;
using Dalamud.Utility;
using Lumina.Data.Files;
namespace Dalamud.Plugin.Services;
/// <summary>
@ -96,4 +98,13 @@ public partial interface ITextureProvider
[Obsolete($"Use {nameof(GetFromFile)}.")]
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
public IDalamudTextureWrap? GetTextureFromFile(FileInfo file, bool keepAlive = false);
/// <summary>
/// Get a texture handle for the specified Lumina <see cref="TexFile"/>.
/// </summary>
/// <param name="file">The texture to obtain a handle to.</param>
/// <returns>A texture wrap that can be used to render the texture. Dispose after use.</returns>
[Obsolete($"Use {nameof(CreateFromTexFile)}.")]
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
IDalamudTextureWrap GetTexture(TexFile file) => this.CreateFromTexFile(file);
}

View file

@ -27,27 +27,6 @@ namespace Dalamud.Plugin.Services;
/// </remarks>
public partial interface ITextureProvider
{
/// <summary>Gets a shared texture corresponding to the given game resource icon specifier.</summary>
/// <param name="lookup">A game icon specifier.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromGameIcon(in GameIconLookup lookup);
/// <summary>Gets a shared texture corresponding to the given path to a game resource.</summary>
/// <param name="path">A path to a game resource.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromGame(string path);
/// <summary>Gets a shared texture corresponding to the given file on the filesystem.</summary>
/// <param name="path">A path to a file on the filesystem.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromFile(string path);
/// <summary>Gets a shared texture corresponding to the given file of the assembly manifest resources.</summary>
/// <param name="assembly">The assembly containing manifest resources.</param>
/// <param name="name">The case-sensitive name of the manifest resource being requested.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromManifestResource(Assembly assembly, string name);
/// <summary>Gets a texture from the given bytes, trying to interpret it as a .tex file or other well-known image
/// files, such as .png.</summary>
/// <param name="bytes">The bytes to load.</param>
@ -102,31 +81,6 @@ public partial interface ITextureProvider
bool leaveOpen = false,
CancellationToken cancellationToken = default);
/// <summary>
/// Get a path for a specific icon's .tex file.
/// </summary>
/// <param name="lookup">The icon lookup.</param>
/// <returns>The path to the icon.</returns>
/// <exception cref="FileNotFoundException">If a corresponding file could not be found.</exception>
string GetIconPath(in GameIconLookup lookup);
/// <summary>
/// Gets the path of an icon.
/// </summary>
/// <param name="lookup">The icon lookup.</param>
/// <param name="path">The resolved path.</param>
/// <returns><c>true</c> if the corresponding file exists and <paramref name="path"/> has been set.</returns>
bool TryGetIconPath(in GameIconLookup lookup, [NotNullWhen(true)] out string? path);
/// <summary>
/// Get a texture handle for the specified Lumina <see cref="TexFile"/>.
/// Alias for fetching <see cref="Task{TResult}.Result"/> from <see cref="CreateFromTexFileAsync"/>.
/// </summary>
/// <param name="file">The texture to obtain a handle to.</param>
/// <returns>A texture wrap that can be used to render the texture. Dispose after use.</returns>
/// <remarks>Alias for <see cref="CreateFromTexFile"/>.</remarks>
IDalamudTextureWrap GetTexture(TexFile file) => this.CreateFromTexFile(file);
/// <summary>
/// Get a texture handle for the specified Lumina <see cref="TexFile"/>.
/// Alias for fetching <see cref="Task{TResult}.Result"/> from <see cref="CreateFromTexFileAsync"/>.
@ -145,11 +99,48 @@ public partial interface ITextureProvider
TexFile file,
CancellationToken cancellationToken = default);
/// <summary>Gets a shared texture corresponding to the given game resource icon specifier.</summary>
/// <param name="lookup">A game icon specifier.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromGameIcon(in GameIconLookup lookup);
/// <summary>Gets a shared texture corresponding to the given path to a game resource.</summary>
/// <param name="path">A path to a game resource.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromGame(string path);
/// <summary>Gets a shared texture corresponding to the given file on the filesystem.</summary>
/// <param name="path">A path to a file on the filesystem.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromFile(string path);
/// <summary>Gets a shared texture corresponding to the given file of the assembly manifest resources.</summary>
/// <param name="assembly">The assembly containing manifest resources.</param>
/// <param name="name">The case-sensitive name of the manifest resource being requested.</param>
/// <returns>The shared texture that you may use to obtain the loaded texture wrap and load states.</returns>
ISharedImmediateTexture GetFromManifestResource(Assembly assembly, string name);
/// <summary>
/// Get a path for a specific icon's .tex file.
/// </summary>
/// <param name="lookup">The icon lookup.</param>
/// <returns>The path to the icon.</returns>
/// <exception cref="FileNotFoundException">If a corresponding file could not be found.</exception>
string GetIconPath(in GameIconLookup lookup);
/// <summary>
/// Gets the path of an icon.
/// </summary>
/// <param name="lookup">The icon lookup.</param>
/// <param name="path">The resolved path.</param>
/// <returns><c>true</c> if the corresponding file exists and <paramref name="path"/> has been set.</returns>
bool TryGetIconPath(in GameIconLookup lookup, [NotNullWhen(true)] out string? path);
/// <summary>
/// Determines whether the system supports the given DXGI format.
/// For use with <see cref="RawImageSpecification.DxgiFormat"/>.
/// </summary>
/// <param name="dxgiFormat">The DXGI format.</param>
/// <returns><c>true</c> if supported.</returns>
bool SupportsDxgiFormat(int dxgiFormat);
bool IsDxgiFormatSupported(int dxgiFormat);
}