Texture2D

Inherits: Texture < Resource < RefCounted < Object

Inherited By: AnimatedTexture, AtlasTexture, CameraTexture, CanvasTexture, CompressedTexture2D, CurveTexture, CurveXYZTexture, GradientTexture1D, GradientTexture2D, ImageTexture, MeshTexture, NoiseTexture, PlaceholderTexture2D, PortableCompressedTexture2D, ProxyTexture, ViewportTexture

Texture for 2D and 3D.

Description

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

void

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

void

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

void

_draw_rect_region ( RID tp_canvas_item, Rect2 rect, Rect2 src_rect, Color modulate, bool transpose, bool clip_uv ) virtual const

int

_get_height ( ) virtual const

int

_get_width ( ) virtual const

bool

_has_alpha ( ) virtual const

bool

_is_pixel_opaque ( int x, int y ) virtual const

void

draw ( RID canvas_item, Vector2 position, Color modulate=Color(1, 1, 1, 1), bool transpose=false ) const

void

draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color(1, 1, 1, 1), bool transpose=false ) const

void

draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color(1, 1, 1, 1), bool transpose=false, bool clip_uv=true ) const

int

get_height ( ) const

Image

get_image ( ) const

Vector2

get_size ( ) const

int

get_width ( ) const

bool

has_alpha ( ) const

Method Descriptions


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


  • void _draw_rect_region ( RID tp_canvas_item, Rect2 rect, Rect2 src_rect, Color modulate, bool transpose, bool clip_uv ) virtual const


  • int _get_height ( ) virtual const


  • int _get_width ( ) virtual const


  • bool _has_alpha ( ) virtual const


  • bool _is_pixel_opaque ( int x, int y ) virtual const


  • void draw ( RID canvas_item, Vector2 position, Color modulate=Color(1, 1, 1, 1), bool transpose=false ) const

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


  • void draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color(1, 1, 1, 1), bool transpose=false ) const

Draws the texture using a CanvasItem with the RenderingServer API.


  • void draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color(1, 1, 1, 1), bool transpose=false, bool clip_uv=true ) const

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


  • int get_height ( ) const

Returns the texture height.


  • Image get_image ( ) 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 fetch the texture data from the GPU, which might cause performance problems when overused.


Returns the texture size.


  • int get_width ( ) const

Returns the texture width.


  • bool has_alpha ( ) const

Returns true if this Texture2D has an alpha channel.