class_texture2d.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Texture2D.xml.
  6. .. _class_Texture2D:
  7. Texture2D
  8. =========
  9. **Inherits:** :ref:`Texture<class_Texture>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`AnimatedTexture<class_AnimatedTexture>`, :ref:`AtlasTexture<class_AtlasTexture>`, :ref:`CameraTexture<class_CameraTexture>`, :ref:`CanvasTexture<class_CanvasTexture>`, :ref:`CompressedTexture2D<class_CompressedTexture2D>`, :ref:`CurveTexture<class_CurveTexture>`, :ref:`CurveXYZTexture<class_CurveXYZTexture>`, :ref:`GradientTexture1D<class_GradientTexture1D>`, :ref:`GradientTexture2D<class_GradientTexture2D>`, :ref:`ImageTexture<class_ImageTexture>`, :ref:`MeshTexture<class_MeshTexture>`, :ref:`NoiseTexture2D<class_NoiseTexture2D>`, :ref:`PlaceholderTexture2D<class_PlaceholderTexture2D>`, :ref:`PortableCompressedTexture2D<class_PortableCompressedTexture2D>`, :ref:`Texture2DRD<class_Texture2DRD>`, :ref:`ViewportTexture<class_ViewportTexture>`
  11. Texture for 2D and 3D.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. A texture works by registering an image in the video hardware, which then can be used in 3D models or 2D :ref:`Sprite2D<class_Sprite2D>` or GUI :ref:`Control<class_Control>`.
  16. Textures are often created by loading them from a file. See :ref:`@GDScript.load<class_@GDScript_method_load>`.
  17. \ **Texture2D** is a base for other resources. It cannot be used directly.
  18. \ **Note:** The maximum texture size is 16384×16384 pixels due to graphics hardware limitations. Larger textures may fail to import.
  19. .. rst-class:: classref-reftable-group
  20. Methods
  21. -------
  22. .. table::
  23. :widths: auto
  24. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`_draw<class_Texture2D_private_method__draw>` **(** :ref:`RID<class_RID>` to_canvas_item, :ref:`Vector2<class_Vector2>` pos, :ref:`Color<class_Color>` modulate, :ref:`bool<class_bool>` transpose **)** |virtual| |const| |
  26. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`_draw_rect<class_Texture2D_private_method__draw_rect>` **(** :ref:`RID<class_RID>` to_canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate, :ref:`bool<class_bool>` transpose **)** |virtual| |const| |
  28. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`_draw_rect_region<class_Texture2D_private_method__draw_rect_region>` **(** :ref:`RID<class_RID>` to_canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate, :ref:`bool<class_bool>` transpose, :ref:`bool<class_bool>` clip_uv **)** |virtual| |const| |
  30. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`int<class_int>` | :ref:`_get_height<class_Texture2D_private_method__get_height>` **(** **)** |virtual| |const| |
  32. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`_get_width<class_Texture2D_private_method__get_width>` **(** **)** |virtual| |const| |
  34. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`_has_alpha<class_Texture2D_private_method__has_alpha>` **(** **)** |virtual| |const| |
  36. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`_is_pixel_opaque<class_Texture2D_private_method__is_pixel_opaque>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |virtual| |const| |
  38. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Resource<class_Resource>` | :ref:`create_placeholder<class_Texture2D_method_create_placeholder>` **(** **)** |const| |
  40. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`draw<class_Texture2D_method_draw>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`bool<class_bool>` transpose=false **)** |const| |
  42. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`draw_rect<class_Texture2D_method_draw_rect>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`bool<class_bool>` transpose=false **)** |const| |
  44. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`draw_rect_region<class_Texture2D_method_draw_rect_region>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`bool<class_bool>` transpose=false, :ref:`bool<class_bool>` clip_uv=true **)** |const| |
  46. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`int<class_int>` | :ref:`get_height<class_Texture2D_method_get_height>` **(** **)** |const| |
  48. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Image<class_Image>` | :ref:`get_image<class_Texture2D_method_get_image>` **(** **)** |const| |
  50. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Vector2<class_Vector2>` | :ref:`get_size<class_Texture2D_method_get_size>` **(** **)** |const| |
  52. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`int<class_int>` | :ref:`get_width<class_Texture2D_method_get_width>` **(** **)** |const| |
  54. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`bool<class_bool>` | :ref:`has_alpha<class_Texture2D_method_has_alpha>` **(** **)** |const| |
  56. +---------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. .. rst-class:: classref-section-separator
  58. ----
  59. .. rst-class:: classref-descriptions-group
  60. Method Descriptions
  61. -------------------
  62. .. _class_Texture2D_private_method__draw:
  63. .. rst-class:: classref-method
  64. void **_draw** **(** :ref:`RID<class_RID>` to_canvas_item, :ref:`Vector2<class_Vector2>` pos, :ref:`Color<class_Color>` modulate, :ref:`bool<class_bool>` transpose **)** |virtual| |const|
  65. Called when the entire **Texture2D** is requested to be drawn over a :ref:`CanvasItem<class_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).
  66. \ **Note:** This is only used in 2D rendering, not 3D.
  67. .. rst-class:: classref-item-separator
  68. ----
  69. .. _class_Texture2D_private_method__draw_rect:
  70. .. rst-class:: classref-method
  71. void **_draw_rect** **(** :ref:`RID<class_RID>` to_canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate, :ref:`bool<class_bool>` transpose **)** |virtual| |const|
  72. Called when the **Texture2D** is requested to be drawn onto :ref:`CanvasItem<class_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).
  73. \ **Note:** This is only used in 2D rendering, not 3D.
  74. .. rst-class:: classref-item-separator
  75. ----
  76. .. _class_Texture2D_private_method__draw_rect_region:
  77. .. rst-class:: classref-method
  78. void **_draw_rect_region** **(** :ref:`RID<class_RID>` to_canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate, :ref:`bool<class_bool>` transpose, :ref:`bool<class_bool>` clip_uv **)** |virtual| |const|
  79. Called when a part of the **Texture2D** specified by ``src_rect``'s coordinates is requested to be drawn onto :ref:`CanvasItem<class_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).
  80. \ **Note:** This is only used in 2D rendering, not 3D.
  81. .. rst-class:: classref-item-separator
  82. ----
  83. .. _class_Texture2D_private_method__get_height:
  84. .. rst-class:: classref-method
  85. :ref:`int<class_int>` **_get_height** **(** **)** |virtual| |const|
  86. Called when the **Texture2D**'s height is queried.
  87. .. rst-class:: classref-item-separator
  88. ----
  89. .. _class_Texture2D_private_method__get_width:
  90. .. rst-class:: classref-method
  91. :ref:`int<class_int>` **_get_width** **(** **)** |virtual| |const|
  92. Called when the **Texture2D**'s width is queried.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_Texture2D_private_method__has_alpha:
  96. .. rst-class:: classref-method
  97. :ref:`bool<class_bool>` **_has_alpha** **(** **)** |virtual| |const|
  98. Called when the presence of an alpha channel in the **Texture2D** is queried.
  99. .. rst-class:: classref-item-separator
  100. ----
  101. .. _class_Texture2D_private_method__is_pixel_opaque:
  102. .. rst-class:: classref-method
  103. :ref:`bool<class_bool>` **_is_pixel_opaque** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |virtual| |const|
  104. Called when a pixel's opaque state in the **Texture2D** is queried at the specified ``(x, y)`` position.
  105. .. rst-class:: classref-item-separator
  106. ----
  107. .. _class_Texture2D_method_create_placeholder:
  108. .. rst-class:: classref-method
  109. :ref:`Resource<class_Resource>` **create_placeholder** **(** **)** |const|
  110. Creates a placeholder version of this resource (:ref:`PlaceholderTexture2D<class_PlaceholderTexture2D>`).
  111. .. rst-class:: classref-item-separator
  112. ----
  113. .. _class_Texture2D_method_draw:
  114. .. rst-class:: classref-method
  115. void **draw** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Vector2<class_Vector2>` position, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`bool<class_bool>` transpose=false **)** |const|
  116. Draws the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`RenderingServer<class_RenderingServer>` API at the specified ``position``.
  117. .. rst-class:: classref-item-separator
  118. ----
  119. .. _class_Texture2D_method_draw_rect:
  120. .. rst-class:: classref-method
  121. void **draw_rect** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`bool<class_bool>` tile, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`bool<class_bool>` transpose=false **)** |const|
  122. Draws the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`RenderingServer<class_RenderingServer>` API.
  123. .. rst-class:: classref-item-separator
  124. ----
  125. .. _class_Texture2D_method_draw_rect_region:
  126. .. rst-class:: classref-method
  127. void **draw_rect_region** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Color<class_Color>` modulate=Color(1, 1, 1, 1), :ref:`bool<class_bool>` transpose=false, :ref:`bool<class_bool>` clip_uv=true **)** |const|
  128. Draws a part of the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`RenderingServer<class_RenderingServer>` API.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_Texture2D_method_get_height:
  132. .. rst-class:: classref-method
  133. :ref:`int<class_int>` **get_height** **(** **)** |const|
  134. Returns the texture height in pixels.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_Texture2D_method_get_image:
  138. .. rst-class:: classref-method
  139. :ref:`Image<class_Image>` **get_image** **(** **)** |const|
  140. Returns an :ref:`Image<class_Image>` that is a copy of data from this **Texture2D** (a new :ref:`Image<class_Image>` is created each time). :ref:`Image<class_Image>`\ s can be accessed and manipulated directly.
  141. \ **Note:** This will fetch the texture data from the GPU, which might cause performance problems when overused.
  142. .. rst-class:: classref-item-separator
  143. ----
  144. .. _class_Texture2D_method_get_size:
  145. .. rst-class:: classref-method
  146. :ref:`Vector2<class_Vector2>` **get_size** **(** **)** |const|
  147. Returns the texture size in pixels.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_Texture2D_method_get_width:
  151. .. rst-class:: classref-method
  152. :ref:`int<class_int>` **get_width** **(** **)** |const|
  153. Returns the texture width in pixels.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_Texture2D_method_has_alpha:
  157. .. rst-class:: classref-method
  158. :ref:`bool<class_bool>` **has_alpha** **(** **)** |const|
  159. Returns ``true`` if this **Texture2D** has an alpha channel.
  160. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  161. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  162. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  163. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  164. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  165. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  166. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`