Overview
TheITextureProvider service grants you access to textures you may render via ImGui. It provides methods to create textures from various sources and retrieve shared textures from game resources.
Namespace: Dalamud.Plugin.Services
Assembly: Dalamud.dll
Create functions will return a new texture, and the returned instance of
IDalamudTextureWrap must be disposed after use.Get functions will return a shared texture, and the returned instance of ISharedImmediateTexture do not require calling Dispose(), unless a new reference has been created by calling RentAsync().The
debugName parameter can be used to name your textures, to aid debugging resource leaks.Create Methods
These methods create new texture instances that must be disposed after use.CreateEmpty
Creates an empty texture.Parameters:
specs(RawImageSpecification) - Texture specifications.cpuRead(bool) - Whether to support reading from CPU, while disabling reading from GPU.cpuWrite(bool) - Whether to support writing from CPU, while disabling writing from GPU.debugName(string?) - Name for debug display purposes.
CreateDrawListTexture
Creates a texture that can be drawn from an
ImDrawList or an ImDrawData.Parameters:debugName(string?) - Name for debug display purposes.
No new resource is allocated upfront; it will be done when
IDrawListTextureWrap.Size is set with positive values for both components.CreateFromExistingTextureAsync
Creates a texture from the given existing texture, cropping and converting pixel format as needed.Parameters:
wrap(IDalamudTextureWrap) - The source texture wrap. The passed value may be disposed once this function returns, without having to wait for the completion of the returnedTask.args(TextureModificationArgs) - The texture modification arguments. Default:defaultleaveWrapOpen(bool) - Whether to leavewrapnon-disposed when the returnedTaskcompletes. Default:falsedebugName(string?) - Name for debug display purposes.cancellationToken(CancellationToken) - The cancellation token.
Task containing the copied texture on success. Dispose after use.CreateFromImGuiViewportAsync
Creates a texture from an ImGui viewport.Parameters:
args(ImGuiViewportTextureArgs) - The arguments for creating a texture.debugName(string?) - Name for debug display purposes.cancellationToken(CancellationToken) - The cancellation token.
Task containing the copied texture on success. Dispose after use.Use
ImGui.GetMainViewport().ID to capture the game screen with Dalamud rendered.CreateFromImageAsync
Gets a texture from the given bytes or stream, trying to interpret it as a .tex file or other well-known image files, such as .png.Overloads:From bytes:
bytes(ReadOnlyMemory<byte>) - The bytes to load.debugName(string?) - Name for debug display purposes.cancellationToken(CancellationToken) - The cancellation token.
stream(Stream) - The stream to load data from.leaveOpen(bool) - Whether to leave the stream open once the task completes. Default:falsedebugName(string?) - Name for debug display purposes.cancellationToken(CancellationToken) - The cancellation token.
Task containing the loaded texture on success. Dispose after use.CreateFromRaw / CreateFromRawAsync
Gets a texture from the given bytes, interpreting it as a raw bitmap.Parameters:
specs(RawImageSpecification) - The specifications for the raw bitmap.bytes(ReadOnlySpan<byte> or ReadOnlyMemory<byte>) - The bytes to load.debugName(string?) - Name for debug display purposes.
stream(Stream) - The stream to load data from.leaveOpen(bool) - Whether to leave the stream open once the task completes.cancellationToken(CancellationToken) - The cancellation token.
CreateFromTexFile / CreateFromTexFileAsync
Get a texture handle for the specified Lumina
TexFile.Parameters:file(TexFile) - The texture to obtain a handle to.debugName(string?) - Name for debug display purposes (async only).cancellationToken(CancellationToken) - The cancellation token (async only).
CreateFromTexFile is an alias for fetching Task.Result from CreateFromTexFileAsync.CreateFromClipboardAsync
Creates a texture from clipboard.Parameters:
debugName(string?) - Name for debug display purposes.cancellationToken(CancellationToken) - The cancellation token.
Task containing the texture from clipboard.CreateTextureFromSeString
Creates a texture by drawing a SeString onto it.Parameters:
text(ReadOnlySpan<byte>) - SeString to render.drawParams(in SeStringDrawParams) - Parameters for drawing. Default:defaultdebugName(string?) - Name for debug display purposes.
Get Methods (Shared Textures)
These methods return shared textures that do not need to be disposed (unless you callRentAsync()).
GetFromGameIcon
Gets a shared texture corresponding to the given game resource icon specifier.Parameters:
lookup(in GameIconLookup) - A game icon specifier.
This function is under the effect of
ITextureSubstitutionProvider.GetSubstitutedPath.Caching the returned object is not recommended. Performance benefit will be minimal.
Gets a shared texture corresponding to the given game resource icon specifier.Parameters:
lookup(in GameIconLookup) - A game icon specifier.texture(out ISharedImmediateTexture?) - The resultingISharedImmediateTexture.
This function does not throw exceptions.
GetFromGame
Gets a shared texture corresponding to the given path to a game resource.Parameters:
path(string) - A path to a game resource.
This function is under the effect of
ITextureSubstitutionProvider.GetSubstitutedPath.This function does not throw exceptions. Caching the returned object is not recommended.
GetFromFile
Gets a shared texture corresponding to the given file on the filesystem.Overloads:
path(string) - A path to a file on the filesystem.file(FileInfo) - The file on the filesystem to load.
This function does not throw exceptions. Caching the returned object is not recommended.
GetFromFileAbsolute
Gets a shared texture corresponding to the given file on the filesystem.Parameters:
fullPath(string) - The file on the filesystem to load. Requires a full path.
This function does not throw exceptions. Caching the returned object is not recommended.
GetFromManifestResource
Gets a shared texture corresponding to the given file of the assembly manifest resources.Parameters:
assembly(Assembly) - The assembly containing manifest resources.name(string) - The case-sensitive name of the manifest resource being requested.
This function does not throw exceptions. Caching the returned object is not recommended.
Utility Methods
GetIconPath / TryGetIconPath
Get a path for a specific icon’s .tex file.Parameters:
lookup(in GameIconLookup) - The icon lookup.
FileNotFoundException if a corresponding file could not be found.Gets the path of an icon.Parameters:
lookup(in GameIconLookup) - The icon lookup.path(out string?) - The resolved path.
true if the corresponding file exists and path has been set.This function does not throw exceptions.
HasClipboardImage
Gets a value indicating whether the current desktop clipboard contains an image that can be attempted to read using
CreateFromClipboardAsync().Returns: true if it is the case.GetSupportedImageDecoderInfos
Gets the supported bitmap decoders.Returns: The supported bitmap decoders.The following functions support the files of the container types pointed by yielded values:
GetFromFileGetFromManifestResourceCreateFromImageAsync
IsDxgiFormatSupported
Determines whether the system supports the given DXGI format. For use with
RawImageSpecification.DxgiFormat.Parameters:dxgiFormat(int) - The DXGI format.
true if supported.This function does not throw exceptions.
Determines whether the system supports the given DXGI format for use with
CreateFromExistingTextureAsync.Parameters:dxgiFormat(int) - The DXGI format.
true if supported.This function does not throw exceptions.
ConvertToKernelTexture
Converts an existing
IDalamudTextureWrap instance to a new instance of FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Texture which can be used to supply a custom texture onto an in-game addon (UI element).Parameters:wrap(IDalamudTextureWrap) - Instance ofIDalamudTextureWrapto convert.leaveWrapOpen(bool) - Whether to leavewrapnon-disposed when the returnedTaskcompletes. Default:false
FFXIVClientStructs.FFXIV.Client.Graphics.Kernel.Texture.Usage Example
Related Types
ISharedImmediateTexture
A texture with a backing instance ofIDalamudTextureWrap that is shared across multiple requesters.
Key Methods:
GetWrapOrEmpty()- Gets the texture for use with the current frame, or an empty texture if unavailable.GetWrapOrDefault(defaultWrap)- Gets the texture or a specified default.TryGetWrap(out texture, out exception)- Attempts to get the texture for use with the current frame.RentAsync(cancellationToken)- Creates a new instance holding a new reference. Must be disposed.
See Also
- IUiBuilder - UI builder interface
- Texture Guide - Guide on using textures in Dalamud