Table of Contents

Class Texture2D

Texture for 2D and 3D.

Inheritance
Texture2D
Derived

Remarks

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.

Methods

_draw(RID, Vector2, Color, bool)

Qualifiers: virtualconst

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.

void _draw(RID to_canvas_item, Vector2 pos, Color modulate, bool transpose)

Parameters

to_canvas_item RID
pos Vector2
modulate Color
transpose bool

_draw_rect(RID, Rect2, bool, Color, bool)

Qualifiers: virtualconst

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.

void _draw_rect(RID to_canvas_item, Rect2 rect, bool tile, Color modulate, bool transpose)

Parameters

to_canvas_item RID
rect Rect2
tile bool
modulate Color
transpose bool

_draw_rect_region(RID, Rect2, Rect2, Color, bool, bool)

Qualifiers: virtualconst

Called when a part of the Texture2D specified by src_rect'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.

void _draw_rect_region(RID to_canvas_item, Rect2 rect, Rect2 src_rect, Color modulate, bool transpose, bool clip_uv)

Parameters

to_canvas_item RID
rect Rect2
src_rect Rect2
modulate Color
transpose bool
clip_uv bool

_get_height

Qualifiers: virtualconst

Called when the Texture2D's height is queried.

int _get_height

_get_width

Qualifiers: virtualconst

Called when the Texture2D's width is queried.

int _get_width

_has_alpha

Qualifiers: virtualconst

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

bool _has_alpha

_is_pixel_opaque(int, int)

Qualifiers: virtualconst

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

bool _is_pixel_opaque(int x, int y)

Parameters

x int
y int

create_placeholder

Qualifiers: const

Creates a placeholder version of this resource (PlaceholderTexture2D).

Resource create_placeholder

draw(RID, Vector2, Color, bool)

Qualifiers: const

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

void draw(RID canvas_item, Vector2 position, Color modulate, bool transpose)

Parameters

canvas_item RID
position Vector2
modulate Color
transpose bool

draw_rect(RID, Rect2, bool, Color, bool)

Qualifiers: const

Draws the texture using a CanvasItem with the RenderingServer API.

void draw_rect(RID canvas_item, Rect2 rect, bool tile, Color modulate, bool transpose)

Parameters

canvas_item RID
rect Rect2
tile bool
modulate Color
transpose bool

draw_rect_region(RID, Rect2, Rect2, Color, bool, bool)

Qualifiers: const

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

void draw_rect_region(RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate, bool transpose, bool clip_uv)

Parameters

canvas_item RID
rect Rect2
src_rect Rect2
modulate Color
transpose bool
clip_uv bool

get_height

Qualifiers: const

Returns the texture height in pixels.

int get_height

get_image

Qualifiers: const

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. Avoid calling get_image every frame, especially on large textures.

Image get_image

get_size

Qualifiers: const

Returns the texture size in pixels.

Vector2 get_size

get_width

Qualifiers: const

Returns the texture width in pixels.

int get_width

has_alpha

Qualifiers: const

Returns true if this Texture2D has an alpha channel.

bool has_alpha