CompressedTexture2D
Texture2D backed by an imported texture file.
The ordinary path is ResourceLoader.Load<Texture2D>("asset://art/icon.png"): it applies import remapping and returns the appropriate resource type. CompressedTexture2D.Load reads an existing .ctex rather than importing PNG. The class name does not guarantee VRAM block compression: the checked Lossless import returns accessible pixel data.
This complete executed helper obtains an independent instance through CacheMode.Ignore. Use it for independent loading; retain resources rather than loading and reading back GPU data every frame:
using System;
using Reckfell;
public static class IndependentImportedTexture
{
public static CompressedTexture2D Load(string projectPath)
{
var texture = ResourceLoader.Load<Texture2D>(projectPath, cacheMode: ResourceLoader.CacheMode.Ignore);
if (texture is CompressedTexture2D imported) return imported;
texture?.Dispose();
throw new InvalidOperationException("Expected an imported CompressedTexture2D resource.");
}
}GetLoadPath/LoadPath identify the internal imported file; ResourcePath can remain the source-asset path. Direct Load does not assign ResourcePath. Successful reload preserves RID and emits Changed. The LoadPath setter does not expose Error; use the method for error handling. A valid RID can be a placeholder before loading.
Known current inconsistency: HasAlpha() returns false even for a checked transparent RGBA pixel. This defect was reproduced; the engine was not fixed. Do not use HasAlpha as the sole test of actual alpha. Alpha-cache reset on another Load works: Sprite2D.IsPixelOpaque correctly updated after replacing transparent data with opaque data. Loading a separate new instance also worked correctly.
Actual Lossless import, GPU readback, paths, notifications, RID and reload were checked on Windows/Vulkan. Shader drawing, graphics quality, VRAM/Basis/Lossy, mipmapped/streamed imports and other backends were not tested.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
CompressedTexture2DConstructor
public CompressedTexture2D();Creates an unloaded texture: width/height 0 and empty LoadPath. Before RID access GetImage returns null. GetRid can create a placeholder, so a valid RID alone does not establish successful file loading.
Properties1
LoadPathProperty
public string LoadPath { get; set; }Reading returns the imported path; assigning invokes Load but the setter does not return its Error. Call Load explicitly to handle the result. Expects .ctex, not a source PNG/JPEG. Do not base asset identity on changeable hashed import-cache paths.
Methods2
GetLoadPathstring
public string GetLoadPath();Returns the last successfully read imported-file path. Not necessarily the source PNG ResourcePath and not a new image import.
stringStored imported-file path, or empty before loading.
LoadError
public Error Load(string path);Reads imported-file data .ctex and updates this instance’s GPU data. Does not import arbitrary images: load ordinary project PNG/JPEG assets through ResourceLoader. Successful reload preserves the RID and emits Changed even for the same path. Does not reassign ResourcePath. Check the returned Error and diagnostics. The internal reader clears the alpha cache before reading; Sprite2D.IsPixelOpaque updating after image replacement was confirmed by the test.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathExisting matching imported-file path .ctex; not a source PNG path.
ErrorResult Error. Check Error.Ok and resource state; this is not a visual-quality test.