Texture2D
Inherits: Texture < Resource < Shared < Object
Inherited by: AtlasTexture, BakedLightmapTexture2D, CameraTexture, CanvasTexture, CompressedTexture2D, CurveTexture, CurveXYZTexture, DPITexture, DrawableTexture2D, ExternalTexture, GradientTexture1D, GradientTexture2D, ImageTexture, MeshTexture, NoiseTexture2D, PixelArt, PlaceholderTexture2D, PortableCompressedTexture2D, ViewportTexture
Texture for 2D and 3D.
Description
Section titled “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. In Grost, take a texture file with use texture::.
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
Section titled “Methods”| Returns | Method |
|---|---|
| void | _draw(to_canvas_item, pos, modulate, transpose) |
| void | _draw_rect(to_canvas_item, rect, tile, modulate, transpose) |
| void | _draw_rect_region(to_canvas_item, rect, src_rect, modulate, transpose, clip_uv) |
| Image.Format | _get_format() |
| int | _get_height() |
| Image | _get_image() |
| int | _get_mipmap_count() |
| int | _get_width() |
| bool | _has_alpha() |
| bool | _has_mipmaps() |
| bool | _is_pixel_opaque(x, y) |
| Resource | create_placeholder() |
| void | draw(canvas_item, position, modulate, transpose) |
| void | draw_rect(canvas_item, rect, tile, modulate, transpose) |
| void | draw_rect_region(canvas_item, rect, src_rect, modulate, transpose, clip_uv) |
| Image.Format | get_format() |
| int | get_height() |
| Image | get_image() |
| int | get_mipmap_count() |
| Vector2 | get_size() |
| int | get_width() |
| bool | has_alpha() |
| bool | has_mipmaps() |
Method descriptions
Section titled “Method descriptions”void _draw(to_canvas_item: RID, pos: Vector2, modulate: Color, transpose: bool) virtual const
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.
_draw_rect
Section titled “_draw_rect”void _draw_rect(to_canvas_item: RID, rect: Rect2, tile: bool, modulate: Color, transpose: bool) virtual const
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.
_draw_rect_region
Section titled “_draw_rect_region”void _draw_rect_region(to_canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color, transpose: bool, clip_uv: bool) virtual const
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.
_get_format
Section titled “_get_format”Image.Format _get_format() virtual const
Called when get_format() is called.
_get_height
Section titled “_get_height”int _get_height() virtual required const
Called when the Texture2D’s height is queried.
_get_image
Section titled “_get_image”Image _get_image() virtual const
Called when get_image() is called.
_get_mipmap_count
Section titled “_get_mipmap_count”int _get_mipmap_count() virtual const
Called when get_mipmap_count() is called.
_get_width
Section titled “_get_width”int _get_width() virtual required const
Called when the Texture2D’s width is queried.
_has_alpha
Section titled “_has_alpha”bool _has_alpha() virtual const
Called when the presence of an alpha channel in the Texture2D is queried.
_has_mipmaps
Section titled “_has_mipmaps”bool _has_mipmaps() virtual const
Called when has_mipmaps() is called.
_is_pixel_opaque
Section titled “_is_pixel_opaque”bool _is_pixel_opaque(x: int, y: int) virtual const
Called when a pixel’s opaque state in the Texture2D is queried at the specified (x, y) position.
create_placeholder
Section titled “create_placeholder”Resource create_placeholder() const
Creates a placeholder version of this resource (PlaceholderTexture2D).
void draw(canvas_item: RID, position: Vector2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false) const
Draws the texture using a CanvasItem with the Render API at the specified position.
draw_rect
Section titled “draw_rect”void draw_rect(canvas_item: RID, rect: Rect2, tile: bool, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false) const
Draws the texture using a CanvasItem with the Render API.
draw_rect_region
Section titled “draw_rect_region”void draw_rect_region(canvas_item: RID, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false, clip_uv: bool = true) const
Draws a part of the texture using a CanvasItem with the Render API.
get_format
Section titled “get_format”Image.Format get_format() const
Returns the image format of the texture.
get_height
Section titled “get_height”int get_height() const
Returns the texture height in pixels.
get_image
Section titled “get_image”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 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.
get_mipmap_count
Section titled “get_mipmap_count”int get_mipmap_count() const
Returns the number of mipmaps of the texture.
get_size
Section titled “get_size”Vector2 get_size() const
Returns the texture size in pixels.
get_width
Section titled “get_width”int get_width() const
Returns the texture width in pixels.
has_alpha
Section titled “has_alpha”bool has_alpha() const
Returns true if this Texture2D has an alpha channel.
has_mipmaps
Section titled “has_mipmaps”bool has_mipmaps() const
Returns true if the texture has mipmaps.