:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/Texture2D.xml. .. _class_Texture2D: Texture2D ========= **Inherits:** :ref:`Texture` **<** :ref:`Resource` **<** :ref:`RefCounted` **<** :ref:`Object` **Inherited By:** :ref:`AnimatedTexture`, :ref:`AtlasTexture`, :ref:`CameraTexture`, :ref:`CanvasTexture`, :ref:`CompressedTexture2D`, :ref:`CurveTexture`, :ref:`CurveXYZTexture`, :ref:`GradientTexture1D`, :ref:`GradientTexture2D`, :ref:`ImageTexture`, :ref:`MeshTexture`, :ref:`NoiseTexture2D`, :ref:`PlaceholderTexture2D`, :ref:`PortableCompressedTexture2D`, :ref:`ViewportTexture` Texture for 2D and 3D. .. rst-class:: classref-introduction-group Description ----------- A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D :ref:`Sprite2D` or GUI :ref:`Control`. Textures are often created by loading them from a file. See :ref:`@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. .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_draw` **(** :ref:`RID` to_canvas_item, :ref:`Vector2` pos, :ref:`Color` modulate, :ref:`bool` transpose **)** |virtual| |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_draw_rect` **(** :ref:`RID` to_canvas_item, :ref:`Rect2` rect, :ref:`bool` tile, :ref:`Color` modulate, :ref:`bool` transpose **)** |virtual| |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`_draw_rect_region` **(** :ref:`RID` to_canvas_item, :ref:`Rect2` rect, :ref:`Rect2` src_rect, :ref:`Color` modulate, :ref:`bool` transpose, :ref:`bool` clip_uv **)** |virtual| |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`_get_height` **(** **)** |virtual| |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`_get_width` **(** **)** |virtual| |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`_has_alpha` **(** **)** |virtual| |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`_is_pixel_opaque` **(** :ref:`int` x, :ref:`int` y **)** |virtual| |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Resource` | :ref:`create_placeholder` **(** **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`draw` **(** :ref:`RID` canvas_item, :ref:`Vector2` position, :ref:`Color` modulate=Color(1, 1, 1, 1), :ref:`bool` transpose=false **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`draw_rect` **(** :ref:`RID` canvas_item, :ref:`Rect2` rect, :ref:`bool` tile, :ref:`Color` modulate=Color(1, 1, 1, 1), :ref:`bool` transpose=false **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`draw_rect_region` **(** :ref:`RID` canvas_item, :ref:`Rect2` rect, :ref:`Rect2` src_rect, :ref:`Color` modulate=Color(1, 1, 1, 1), :ref:`bool` transpose=false, :ref:`bool` clip_uv=true **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_height` **(** **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Image` | :ref:`get_image` **(** **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_size` **(** **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_width` **(** **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_alpha` **(** **)** |const| | +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_Texture2D_method__draw: .. rst-class:: classref-method void **_draw** **(** :ref:`RID` to_canvas_item, :ref:`Vector2` pos, :ref:`Color` modulate, :ref:`bool` transpose **)** |virtual| |const| Called when the entire **Texture2D** is requested to be drawn over a :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method__draw_rect: .. rst-class:: classref-method void **_draw_rect** **(** :ref:`RID` to_canvas_item, :ref:`Rect2` rect, :ref:`bool` tile, :ref:`Color` modulate, :ref:`bool` transpose **)** |virtual| |const| Called when the **Texture2D** is requested to be drawn onto :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method__draw_rect_region: .. rst-class:: classref-method void **_draw_rect_region** **(** :ref:`RID` to_canvas_item, :ref:`Rect2` rect, :ref:`Rect2` src_rect, :ref:`Color` modulate, :ref:`bool` transpose, :ref:`bool` clip_uv **)** |virtual| |const| Called when a part of the **Texture2D** specified by ``src_rect``'s coordinates is requested to be drawn onto :ref:`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. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method__get_height: .. rst-class:: classref-method :ref:`int` **_get_height** **(** **)** |virtual| |const| Called when the **Texture2D**'s height is queried. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method__get_width: .. rst-class:: classref-method :ref:`int` **_get_width** **(** **)** |virtual| |const| Called when the **Texture2D**'s width is queried. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method__has_alpha: .. rst-class:: classref-method :ref:`bool` **_has_alpha** **(** **)** |virtual| |const| Called when the presence of an alpha channel in the **Texture2D** is queried. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method__is_pixel_opaque: .. rst-class:: classref-method :ref:`bool` **_is_pixel_opaque** **(** :ref:`int` x, :ref:`int` y **)** |virtual| |const| Called when a pixel's opaque state in the **Texture2D** is queried at the specified ``(x, y)`` position. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_create_placeholder: .. rst-class:: classref-method :ref:`Resource` **create_placeholder** **(** **)** |const| Creates a placeholder version of this resource (:ref:`PlaceholderTexture2D`). .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_draw: .. rst-class:: classref-method void **draw** **(** :ref:`RID` canvas_item, :ref:`Vector2` position, :ref:`Color` modulate=Color(1, 1, 1, 1), :ref:`bool` transpose=false **)** |const| Draws the texture using a :ref:`CanvasItem` with the :ref:`RenderingServer` API at the specified ``position``. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_draw_rect: .. rst-class:: classref-method void **draw_rect** **(** :ref:`RID` canvas_item, :ref:`Rect2` rect, :ref:`bool` tile, :ref:`Color` modulate=Color(1, 1, 1, 1), :ref:`bool` transpose=false **)** |const| Draws the texture using a :ref:`CanvasItem` with the :ref:`RenderingServer` API. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_draw_rect_region: .. rst-class:: classref-method void **draw_rect_region** **(** :ref:`RID` canvas_item, :ref:`Rect2` rect, :ref:`Rect2` src_rect, :ref:`Color` modulate=Color(1, 1, 1, 1), :ref:`bool` transpose=false, :ref:`bool` clip_uv=true **)** |const| Draws a part of the texture using a :ref:`CanvasItem` with the :ref:`RenderingServer` API. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_get_height: .. rst-class:: classref-method :ref:`int` **get_height** **(** **)** |const| Returns the texture height in pixels. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_get_image: .. rst-class:: classref-method :ref:`Image` **get_image** **(** **)** |const| Returns an :ref:`Image` that is a copy of data from this **Texture2D** (a new :ref:`Image` is created each time). :ref:`Image`\ s can be accessed and manipulated directly. \ **Note:** This will fetch the texture data from the GPU, which might cause performance problems when overused. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_get_size: .. rst-class:: classref-method :ref:`Vector2` **get_size** **(** **)** |const| Returns the texture size in pixels. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_get_width: .. rst-class:: classref-method :ref:`int` **get_width** **(** **)** |const| Returns the texture width in pixels. .. rst-class:: classref-item-separator ---- .. _class_Texture2D_method_has_alpha: .. rst-class:: classref-method :ref:`bool` **has_alpha** **(** **)** |const| Returns ``true`` if this **Texture2D** has an alpha channel. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`