Interface ITextureImageLoader
Creates a Texture2D from raw, usually compressed image data.
Namespace: GLTFast
Assembly: glTFast.dll
Syntax
public interface ITextureImageLoader
Methods
IsAbleToLoad(TextureBase, out int)
Determines if this loader can load the given texture, and if so, returns the corresponding image index. The typical use-case is a glTF texture extension that adds support for a new image format, e.g. EXT_texture_webp. The loader may also update the image index to point to a different image, e.g. if the extension adds support for a new image format that is stored in a different image than the one referenced by the texture.
Declaration
bool IsAbleToLoad(TextureBase texture, out int imageIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureBase | texture | glTF texture. |
| int | imageIndex | Corresponding, potentially updated glTF image index. |
Returns
| Type | Description |
|---|---|
| bool | True if the texture image loader supports loading that texture, false otherwise. |
IsAbleToLoad(ReadOnlySpan<byte>)
Implement this to support content-based image format detection. This is optional, but fixes loading of glTF images where the type could not be derived from the mime type or file extension.
Declaration
bool IsAbleToLoad(ReadOnlySpan<byte> data)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | Image data. |
Returns
| Type | Description |
|---|---|
| bool | True if the image loader supports loading that data, false otherwise. |
LoadImage(ReadOnly, bool, bool, bool, CancellationToken)
Creates an image from the input data.
Declaration
Task<ImageResult> LoadImage(NativeArray<byte>.ReadOnly data, bool linear, bool readable, bool generateMipMaps, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeArray<byte>.ReadOnly | data | Raw, compressed image data. |
| bool | linear | If true, the texture being created is in linear space. If false, it is in sRGB space. |
| bool | readable | If true, the resulting texture should remain readable (UnityEngine.Texture2D.isReadable). |
| bool | generateMipMaps | If true, mipmap levels should get generated. |
| CancellationToken | cancellationToken | Token to submit cancellation requests. The default value is None. |
Returns
| Type | Description |
|---|---|
| Task<ImageResult> | An image texture result |
Remarks
glTFast governs where this method's await continuations resume, keeping the main thread responsive
without the loader consulting the IDeferAgent. Write plain asynchronous code: decode on a
worker thread with Task.Run and create the texture after awaiting the result. The method is also
entered with main-thread time available, so short work needs no yielding at all.
Two rules apply. Do not use ConfigureAwait(false), which escapes to the thread pool where Unity's
API is unavailable; and never block the main thread on a task with Task.Result or Task.Wait,
which deadlocks.
Split long stretches of synchronous main-thread work with await Task.Yield(); each yield resumes once
main-thread time is available. Unity's Awaitable and AsyncOperation bypass this: code after
awaiting one runs ungoverned for the rest of the method, so prefer Task-based APIs.