reckfellENGINE

Texture2D

Base two-dimensional texture resource for UI, 2D and 3D materials.

On this page
class Texture2DReckfellSharpInherits Texture

Texture2D defines a shared texture contract rather than loading a file through its constructor. Use ResourceLoader.Load<Texture2D> for imported assets, ImageTexture for generated pixels, and DpiTexture for SVG. Multiple objects can share a resource; modifying it affects all users.

GetSize returns logical size. GetImage reads data supplied by the concrete implementation; its resolution can differ from GetSize after a size override. HasAlpha does not prove transparent pixels exist. Current ImageTexture HasMipmaps/GetMipmapCount can report false/0 despite a GetImage mipmap chain; this is a confirmed limitation of that implementation.

Draw, DrawRect and DrawRectRegion submit 2D CanvasItem commands. They do not assign a texture to a 3D material. transpose swaps axes; srcRect uses texture coordinates rather than normalized UVs. Underscored methods are implementation hooks for custom resources; public methods and hooks have different roles.

Virtual dispatch, draw arguments, placeholders and resource queries were checked in Windows Forward+/Vulkan. Visual transpose/tile/clip output, arbitrary subclasses and 3D use were not established by those checks. Maximum size and memory usage depend on backend, GPU and format; a single number does not guarantee allocation.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

Texture2DConstructor
# Texture2D
C#
public Texture2D();

Creates a base Texture2D resource without loading an image or supplying a ready pixel texture. Normally use a concrete subclass or ResourceLoader.Load<Texture2D>. Implement the required size and data methods in a custom subclass.

Methods23

CreatePlaceholderResource
# CreatePlaceholder
C#
public Resource CreatePlaceholder();

Creates a separate PlaceholderTexture2D with the current logical size. Source pixels, format and mipmap chain are not copied. Use it as a resource stand-in rather than a smaller image copy.

Returns Resource

Resource whose concrete type is PlaceholderTexture2D, with original logical size but no source pixels.

Drawvoid
# Draw
C#
public void Draw(Rid canvasItem, Vector2 position, Color? modulate = default, bool transpose = false);

Draws the entire texture at top-left position using its logical size. modulate multiplies color; C# null means white. transpose swaps axes; do not treat it as a general 90-degree rotation. Use a valid CanvasItem RID, such as GetCanvasItem() inside your Entity2D/Control _Draw. Request QueueRedraw on the CanvasItem after state changes. This is a 2D command rather than 3D material assignment.

Parameters
NameTypeDefault
canvasItemRid—
positionVector2—
modulateColor?default
transposeboolfalse
canvasItem

Borrowed valid target CanvasItem RID, not the texture RID.

position

Top-left position in the target CanvasItem local coordinates.

modulate

RGBA multiplier; null in a public C# nullable parameter means white, while the hook receives a concrete Color.

transpose

Swap axes when drawing; not an arbitrary rotation angle.

DrawRectvoid
# DrawRect
C#
public void DrawRect(Rid canvasItem, Rect2 rect, bool tile, Color? modulate = default, bool transpose = false);

Draws the texture in rect. With tile = false it stretches; with true it repeats to fill the area. modulate multiplies color; transpose swaps axes rather than specifying an arbitrary angle. Use a valid CanvasItem RID, such as GetCanvasItem() inside your Entity2D/Control _Draw. Request QueueRedraw on the CanvasItem after state changes. This is a 2D command rather than 3D material assignment.

Parameters
NameTypeDefault
canvasItemRid—
rectRect2—
tilebool—
modulateColor?default
transposeboolfalse
canvasItem

Borrowed valid target CanvasItem RID, not the texture RID.

rect

Destination rectangle in CanvasItem local coordinates.

tile

Repeat the texture rather than stretching it over rect.

modulate

RGBA multiplier; null in a public C# nullable parameter means white, while the hook receives a concrete Color.

transpose

Swap axes when drawing; not an arbitrary rotation angle.

DrawRectRegionvoid
# DrawRectRegion
C#
public void DrawRectRegion(Rid canvasItem, Rect2 rect, Rect2 srcRect, Color? modulate = default, bool transpose = false, bool clipUV = true);

Draws srcRect into rect. Source coordinates are texture coordinates rather than normalized 0…1 UVs. clipUV restricts sampling to the source region; it is not CanvasItem geometry clipping. Default modulate is white. Use a valid CanvasItem RID, such as GetCanvasItem() inside your Entity2D/Control _Draw. Request QueueRedraw on the CanvasItem after state changes. This is a 2D command rather than 3D material assignment.

Parameters
NameTypeDefault
canvasItemRid—
rectRect2—
srcRectRect2—
modulateColor?default
transposeboolfalse
clipUVbooltrue
canvasItem

Borrowed valid target CanvasItem RID, not the texture RID.

rect

Destination rectangle in CanvasItem local coordinates.

srcRect

Source rectangle in texture coordinates, not 0…1 UVs.

modulate

RGBA multiplier; null in a public C# nullable parameter means white, while the hook receives a concrete Color.

transpose

Swap axes when drawing; not an arbitrary rotation angle.

clipUV

Restrict sampling to the source region; defaults to true on the public method.

GetFormatImage.Format
# GetFormat
C#
public Image.Format GetFormat();

Returns the image format supplied by the texture implementation. Without _GetFormat, the base result Image.Format.Max indicates no concrete format; do not use it as a new Image format. Format alone does not specify material color space.

Returns Image.Format

Implementation format, or Image.Format.Max without a provider.

GetHeightint
# GetHeight
C#
public int GetHeight();

Returns logical texture height; a size override can make it differ from GetImage height. A custom subclass supplies the value through _GetHeight.

Returns int

Logical height in texture units.

GetImageImage
# GetImage
C#
public Image GetImage();

Obtains an Image with texture data when supplied by the implementation. For imported CompressedTexture2D this is a snapshot that may require GPU readback: editing it does not update the original texture. Avoid unnecessary per-frame readback.

Returns Image

Image with available data, or null if the implementation does not supply an image. Do not assume the format is always uncompressed RGBA8.

GetMipmapCountint
# GetMipmapCount
C#
public int GetMipmapCount();

Returns the implementation count of additional mipmap levels, excluding the base level. Without _GetMipmapCount, the base result is 0. Current ImageTexture can still report 0 while GetImage contains mipmaps. Do not derive storage size from an unverified result.

Returns int

Implementation additional-level count; 0 for the base contract.

GetSizeVector2
# GetSize
C#
public Vector2 GetSize();

Returns a Vector2 composed of GetWidth and GetHeight in logical texture units. This is not Sprite2D world size, Control size or necessarily physical GetImage resolution after an override.

Returns Vector2

Vector2 containing current logical width and height.

GetWidthint
# GetWidth
C#
public int GetWidth();

Returns logical texture width. For a resource with a size override, it can differ from GetImage width. A custom subclass supplies it through _GetWidth; do not infer GPU storage resolution from this method alone.

Returns int

Logical width in texture units.

HasAlphabool
# HasAlpha
C#
public bool HasAlpha();

Returns the implementation alpha-support flag rather than scanning pixels for transparency. The base result without _HasAlpha is true. Therefore true does not prove that any pixel is transparent.

Returns bool

Alpha-support flag, not proof of transparent pixels.

HasMipmapsbool
# HasMipmaps
C#
public bool HasMipmaps();

Returns the implementation mipmap flag; the base result without _HasMipmaps is false. Current ImageTexture can return false despite a GetImage mipmap chain because it does not override the native method. Do not use this as the sole pixel-data check for every texture type.

Returns bool

Implementation value; false for the base contract.

_Drawvoid
# _Draw
C#
public virtual void _Draw(Rid toCanvasItem, Vector2 pos, Color modulate, bool transpose);

Override for a custom Texture2D Draw. When the hook handles the call, the base drawing command is not automatically appended; submit the required commands yourself. Do not call the same method on this from the hook: that recurses. Draws the entire texture at top-left position using its logical size. modulate multiplies color; C# null means white. transpose swaps axes; do not treat it as a general 90-degree rotation. Use a valid CanvasItem RID, such as GetCanvasItem() inside your Entity2D/Control _Draw. Request QueueRedraw on the CanvasItem after state changes. This is a 2D command rather than 3D material assignment.

Parameters
NameTypeDefault
toCanvasItemRid—
posVector2—
modulateColor—
transposebool—
toCanvasItem

Valid CanvasItem RID supplied by the native call.

pos

Top-left position in the target CanvasItem local coordinates.

modulate

RGBA multiplier; null in a public C# nullable parameter means white, while the hook receives a concrete Color.

transpose

Swap axes when drawing; not an arbitrary rotation angle.

_DrawRectvoid
# _DrawRect
C#
public virtual void _DrawRect(Rid toCanvasItem, Rect2 rect, bool tile, Color modulate, bool transpose);

Override for a custom Texture2D DrawRect. When the hook handles the call, the base drawing command is not automatically appended; submit the required commands yourself. Do not call the same method on this from the hook: that recurses. Draws the texture in rect. With tile = false it stretches; with true it repeats to fill the area. modulate multiplies color; transpose swaps axes rather than specifying an arbitrary angle. Use a valid CanvasItem RID, such as GetCanvasItem() inside your Entity2D/Control _Draw. Request QueueRedraw on the CanvasItem after state changes. This is a 2D command rather than 3D material assignment.

Parameters
NameTypeDefault
toCanvasItemRid—
rectRect2—
tilebool—
modulateColor—
transposebool—
toCanvasItem

Valid CanvasItem RID supplied by the native call.

rect

Destination rectangle in CanvasItem local coordinates.

tile

Repeat the texture rather than stretching it over rect.

modulate

RGBA multiplier; null in a public C# nullable parameter means white, while the hook receives a concrete Color.

transpose

Swap axes when drawing; not an arbitrary rotation angle.

_DrawRectRegionvoid
# _DrawRectRegion
C#
public virtual void _DrawRectRegion(Rid toCanvasItem, Rect2 rect, Rect2 srcRect, Color modulate, bool transpose, bool clipUV);

Override for a custom Texture2D DrawRectRegion. When the hook handles the call, the base drawing command is not automatically appended; submit the required commands yourself. Do not call the same method on this from the hook: that recurses. Draws srcRect into rect. Source coordinates are texture coordinates rather than normalized 0…1 UVs. clipUV restricts sampling to the source region; it is not CanvasItem geometry clipping. Default modulate is white. Use a valid CanvasItem RID, such as GetCanvasItem() inside your Entity2D/Control _Draw. Request QueueRedraw on the CanvasItem after state changes. This is a 2D command rather than 3D material assignment.

Parameters
NameTypeDefault
toCanvasItemRid—
rectRect2—
srcRectRect2—
modulateColor—
transposebool—
clipUVbool—
toCanvasItem

Valid CanvasItem RID supplied by the native call.

rect

Destination rectangle in CanvasItem local coordinates.

srcRect

Source rectangle in texture coordinates, not 0…1 UVs.

modulate

RGBA multiplier; null in a public C# nullable parameter means white, while the hook receives a concrete Color.

transpose

Swap axes when drawing; not an arbitrary rotation angle.

clipUV

Restrict sampling to the source region; defaults to true on the public method.

_GetFormatImage.Format
# _GetFormat
C#
public virtual Image.Format _GetFormat();

Format provider for a custom Texture2D. Return the concrete Image.Format matching the supplied image; without an implementation, base GetFormat returns Max. It does not automatically change GPU texture format.

Returns Image.Format

Concrete format of supplied image data.

_GetHeightint
# _GetHeight
C#
public virtual int _GetHeight();

Override for a custom Texture2D to return logical height. Native GetHeight and GetSize use this contract. Keep dimensions consistent with custom drawing.

Returns int

Custom texture logical height.

_GetImageImage
# _GetImage
C#
public virtual Image _GetImage();

Image provider for a custom Texture2D. Return available data or null if readback is unsupported. The tested subclass returns independent images; the base API does not force every subclass to copy data identically. Do not release the returned resource before passing it to the caller.

Returns Image

Image with available data, or null.

_GetMipmapCountint
# _GetMipmapCount
C#
public virtual int _GetMipmapCount();

Provider of a custom Texture2D additional mipmap-level count, excluding the base level. Keep it consistent with _HasMipmaps and actual data. Without an implementation the base result is 0.

Returns int

Additional-level count, excluding the base level.

_GetWidthint
# _GetWidth
C#
public virtual int _GetWidth();

Override for a custom Texture2D to return logical width. Native GetWidth and GetSize use this contract. It is a data query rather than a place to reload a resource every frame.

Returns int

Custom texture logical width.

_HasAlphabool
# _HasAlpha
C#
public virtual bool _HasAlpha();

Alpha-support provider for a custom Texture2D. This declares implementation capability rather than scanning pixels. Without an override, base HasAlpha returns true.

Returns bool

Custom resource alpha-support flag.

_HasMipmapsbool
# _HasMipmaps
C#
public virtual bool _HasMipmaps();

Mipmap-flag provider for a custom Texture2D; keep it consistent with _GetMipmapCount and _GetImage data. The base result without an override is false; creating a chain in a separate Image does not automatically change this contract.

Returns bool

Whether supplied data includes a mipmap chain.

_IsPixelOpaquebool
# _IsPixelOpaque
C#
public virtual bool _IsPixelOpaque(int x, int y);

Custom Texture2D pixel-opacity hook used by native consumers such as Sprite2D.IsPixelOpaque. Coordinates are texture-local rather than screen coordinates. Handle bounds in your implementation. The base result without an override is true. This does not automatically create physics collision.

Parameters
NameTypeDefault
xint—
yint—
x

Integer horizontal texture-pixel coordinate.

y

Integer vertical texture-pixel coordinate.

Returns bool

true for a pixel your implementation considers opaque; otherwise false.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.