Table of Contents

Class Texture2D

Namespace
Godot
Assembly
GodotSharp.dll

A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D Sprite2D or GUI Control.

Textures are often created by loading them from a file. See @GDScript.load.

Texture2D is a base for other resources. It cannot be used directly.

Note: The maximum texture size is 16384×16384 pixels due to graphics hardware limitations. Larger textures may fail to import.

public class Texture2D : Texture, IDisposable
Inheritance
Texture2D
Implements
Derived
Inherited Members

Constructors

Texture2D()

public Texture2D()

Methods

CreatePlaceholder()

Creates a placeholder version of this resource (PlaceholderTexture2D).

public Resource CreatePlaceholder()

Returns

Resource

Draw(Rid, Vector2, Color?, bool)

Draws the texture using a CanvasItem with the RenderingServer API at the specified position.

public void Draw(Rid canvasItem, Vector2 position, Color? modulate = null, bool transpose = false)

Parameters

canvasItem Rid
position Vector2
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

transpose bool

DrawRect(Rid, Rect2, bool, Color?, bool)

Draws the texture using a CanvasItem with the RenderingServer API.

public void DrawRect(Rid canvasItem, Rect2 rect, bool tile, Color? modulate = null, bool transpose = false)

Parameters

canvasItem Rid
rect Rect2
tile bool
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

transpose bool

DrawRectRegion(Rid, Rect2, Rect2, Color?, bool, bool)

Draws a part of the texture using a CanvasItem with the RenderingServer API.

public void DrawRectRegion(Rid canvasItem, Rect2 rect, Rect2 srcRect, Color? modulate = null, bool transpose = false, bool clipUV = true)

Parameters

canvasItem Rid
rect Rect2
srcRect Rect2
modulate Color?

If the parameter is null, then the default value is new Color(1, 1, 1, 1).

transpose bool
clipUV bool

GetHeight()

Returns the texture height in pixels.

public int GetHeight()

Returns

int

GetImage()

Returns an Image that is a copy of data from this Texture2D (a new Image is created each time). Images can be accessed and manipulated directly.

Note: This will return null if this Texture2D is invalid.

Note: This will fetch the texture data from the GPU, which might cause performance problems when overused.

public Image GetImage()

Returns

Image

GetSize()

Returns the texture size in pixels.

public Vector2 GetSize()

Returns

Vector2

GetWidth()

Returns the texture width in pixels.

public int GetWidth()

Returns

int

HasAlpha()

Returns true if this Texture2D has an alpha channel.

public bool HasAlpha()

Returns

bool

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

_Draw(Rid, Vector2, Color, bool)

Called when the entire Texture2D is requested to be drawn over a CanvasItem, with the top-left offset specified in pos. modulate specifies a multiplier for the colors being drawn, while transpose specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).

Note: This is only used in 2D rendering, not 3D.

public virtual void _Draw(Rid toCanvasItem, Vector2 pos, Color modulate, bool transpose)

Parameters

toCanvasItem Rid
pos Vector2
modulate Color
transpose bool

_DrawRect(Rid, Rect2, bool, Color, bool)

Called when the Texture2D is requested to be drawn onto CanvasItem's specified rect. modulate specifies a multiplier for the colors being drawn, while transpose specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).

Note: This is only used in 2D rendering, not 3D.

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

Parameters

toCanvasItem Rid
rect Rect2
tile bool
modulate Color
transpose bool

_DrawRectRegion(Rid, Rect2, Rect2, Color, bool, bool)

Called when a part of the Texture2D specified by srcRect's coordinates is requested to be drawn onto CanvasItem's specified rect. modulate specifies a multiplier for the colors being drawn, while transpose specifies whether drawing should be performed in column-major order instead of row-major order (resulting in 90-degree clockwise rotation).

Note: This is only used in 2D rendering, not 3D.

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

Parameters

toCanvasItem Rid
rect Rect2
srcRect Rect2
modulate Color
transpose bool
clipUV bool

_GetHeight()

Called when the Texture2D's height is queried.

public virtual int _GetHeight()

Returns

int

_GetWidth()

Called when the Texture2D's width is queried.

public virtual int _GetWidth()

Returns

int

_HasAlpha()

Called when the presence of an alpha channel in the Texture2D is queried.

public virtual bool _HasAlpha()

Returns

bool

_IsPixelOpaque(int, int)

Called when a pixel's opaque state in the Texture2D is queried at the specified (x, y) position.

public virtual bool _IsPixelOpaque(int x, int y)

Parameters

x int
y int

Returns

bool