class_texture.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Texture.xml.
  6. .. _class_Texture:
  7. Texture
  8. =======
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`AnimatedTexture<class_AnimatedTexture>`, :ref:`AtlasTexture<class_AtlasTexture>`, :ref:`CameraTexture<class_CameraTexture>`, :ref:`CurveTexture<class_CurveTexture>`, :ref:`ExternalTexture<class_ExternalTexture>`, :ref:`GradientTexture<class_GradientTexture>`, :ref:`GradientTexture2D<class_GradientTexture2D>`, :ref:`ImageTexture<class_ImageTexture>`, :ref:`LargeTexture<class_LargeTexture>`, :ref:`MeshTexture<class_MeshTexture>`, :ref:`NoiseTexture<class_NoiseTexture>`, :ref:`ProxyTexture<class_ProxyTexture>`, :ref:`StreamTexture<class_StreamTexture>`, :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:`Sprite<class_Sprite>` 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. \ **Texture** 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. Properties
  21. ----------
  22. .. table::
  23. :widths: auto
  24. +-----------------------+--------------------------------------------+-------+
  25. | :ref:`int<class_int>` | :ref:`flags<class_Texture_property_flags>` | ``4`` |
  26. +-----------------------+--------------------------------------------+-------+
  27. .. rst-class:: classref-reftable-group
  28. Methods
  29. -------
  30. .. table::
  31. :widths: auto
  32. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | void | :ref:`draw<class_Texture_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, :ref:`Texture<class_Texture>` normal_map=null **)** |const| |
  34. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`draw_rect<class_Texture_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, :ref:`Texture<class_Texture>` normal_map=null **)** |const| |
  36. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`draw_rect_region<class_Texture_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:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)** |const| |
  38. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Image<class_Image>` | :ref:`get_data<class_Texture_method_get_data>` **(** **)** |const| |
  40. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | :ref:`get_height<class_Texture_method_get_height>` **(** **)** |const| |
  42. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector2<class_Vector2>` | :ref:`get_size<class_Texture_method_get_size>` **(** **)** |const| |
  44. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`int<class_int>` | :ref:`get_width<class_Texture_method_get_width>` **(** **)** |const| |
  46. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`has_alpha<class_Texture_method_has_alpha>` **(** **)** |const| |
  48. +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. .. rst-class:: classref-section-separator
  50. ----
  51. .. rst-class:: classref-descriptions-group
  52. Enumerations
  53. ------------
  54. .. _enum_Texture_Flags:
  55. .. rst-class:: classref-enumeration
  56. enum **Flags**:
  57. .. _class_Texture_constant_FLAGS_DEFAULT:
  58. .. rst-class:: classref-enumeration-constant
  59. :ref:`Flags<enum_Texture_Flags>` **FLAGS_DEFAULT** = ``7``
  60. Default flags. :ref:`FLAG_MIPMAPS<class_Texture_constant_FLAG_MIPMAPS>`, :ref:`FLAG_REPEAT<class_Texture_constant_FLAG_REPEAT>` and :ref:`FLAG_FILTER<class_Texture_constant_FLAG_FILTER>` are enabled.
  61. .. _class_Texture_constant_FLAG_MIPMAPS:
  62. .. rst-class:: classref-enumeration-constant
  63. :ref:`Flags<enum_Texture_Flags>` **FLAG_MIPMAPS** = ``1``
  64. Generates mipmaps, which are smaller versions of the same texture to use when zoomed out, keeping the aspect ratio.
  65. .. _class_Texture_constant_FLAG_REPEAT:
  66. .. rst-class:: classref-enumeration-constant
  67. :ref:`Flags<enum_Texture_Flags>` **FLAG_REPEAT** = ``2``
  68. Repeats the texture (instead of clamp to edge).
  69. \ **Note:** Ignored when using an :ref:`AtlasTexture<class_AtlasTexture>` as these don't support repetition.
  70. .. _class_Texture_constant_FLAG_FILTER:
  71. .. rst-class:: classref-enumeration-constant
  72. :ref:`Flags<enum_Texture_Flags>` **FLAG_FILTER** = ``4``
  73. Uses a magnifying filter, to enable smooth zooming in of the texture.
  74. .. _class_Texture_constant_FLAG_ANISOTROPIC_FILTER:
  75. .. rst-class:: classref-enumeration-constant
  76. :ref:`Flags<enum_Texture_Flags>` **FLAG_ANISOTROPIC_FILTER** = ``8``
  77. Uses anisotropic mipmap filtering. Generates smaller versions of the same texture with different aspect ratios.
  78. This results in better-looking textures when viewed from oblique angles.
  79. .. _class_Texture_constant_FLAG_CONVERT_TO_LINEAR:
  80. .. rst-class:: classref-enumeration-constant
  81. :ref:`Flags<enum_Texture_Flags>` **FLAG_CONVERT_TO_LINEAR** = ``16``
  82. Converts the texture to the sRGB color space.
  83. .. _class_Texture_constant_FLAG_MIRRORED_REPEAT:
  84. .. rst-class:: classref-enumeration-constant
  85. :ref:`Flags<enum_Texture_Flags>` **FLAG_MIRRORED_REPEAT** = ``32``
  86. Repeats the texture with alternate sections mirrored.
  87. \ **Note:** Ignored when using an :ref:`AtlasTexture<class_AtlasTexture>` as these don't support repetition.
  88. .. _class_Texture_constant_FLAG_VIDEO_SURFACE:
  89. .. rst-class:: classref-enumeration-constant
  90. :ref:`Flags<enum_Texture_Flags>` **FLAG_VIDEO_SURFACE** = ``2048``
  91. Texture is a video surface.
  92. .. rst-class:: classref-section-separator
  93. ----
  94. .. rst-class:: classref-descriptions-group
  95. Property Descriptions
  96. ---------------------
  97. .. _class_Texture_property_flags:
  98. .. rst-class:: classref-property
  99. :ref:`int<class_int>` **flags** = ``4``
  100. .. rst-class:: classref-property-setget
  101. - void **set_flags** **(** :ref:`int<class_int>` value **)**
  102. - :ref:`int<class_int>` **get_flags** **(** **)**
  103. The texture's :ref:`Flags<enum_Texture_Flags>`. :ref:`Flags<enum_Texture_Flags>` are used to set various properties of the **Texture**.
  104. .. rst-class:: classref-section-separator
  105. ----
  106. .. rst-class:: classref-descriptions-group
  107. Method Descriptions
  108. -------------------
  109. .. _class_Texture_method_draw:
  110. .. rst-class:: classref-method
  111. 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, :ref:`Texture<class_Texture>` normal_map=null **)** |const|
  112. Draws the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`VisualServer<class_VisualServer>` API at the specified ``position``. Equivalent to :ref:`VisualServer.canvas_item_add_texture_rect<class_VisualServer_method_canvas_item_add_texture_rect>` with a rect at ``position`` and the size of this **Texture**.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_Texture_method_draw_rect:
  116. .. rst-class:: classref-method
  117. 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, :ref:`Texture<class_Texture>` normal_map=null **)** |const|
  118. Draws the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`VisualServer<class_VisualServer>` API. Equivalent to :ref:`VisualServer.canvas_item_add_texture_rect<class_VisualServer_method_canvas_item_add_texture_rect>`.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_Texture_method_draw_rect_region:
  122. .. rst-class:: classref-method
  123. 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:`Texture<class_Texture>` normal_map=null, :ref:`bool<class_bool>` clip_uv=true **)** |const|
  124. Draws a part of the texture using a :ref:`CanvasItem<class_CanvasItem>` with the :ref:`VisualServer<class_VisualServer>` API. Equivalent to :ref:`VisualServer.canvas_item_add_texture_rect_region<class_VisualServer_method_canvas_item_add_texture_rect_region>`.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_Texture_method_get_data:
  128. .. rst-class:: classref-method
  129. :ref:`Image<class_Image>` **get_data** **(** **)** |const|
  130. Returns an :ref:`Image<class_Image>` that is a copy of data from this **Texture**. :ref:`Image<class_Image>`\ s can be accessed and manipulated directly.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_Texture_method_get_height:
  134. .. rst-class:: classref-method
  135. :ref:`int<class_int>` **get_height** **(** **)** |const|
  136. Returns the texture height.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_Texture_method_get_size:
  140. .. rst-class:: classref-method
  141. :ref:`Vector2<class_Vector2>` **get_size** **(** **)** |const|
  142. Returns the texture size.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_Texture_method_get_width:
  146. .. rst-class:: classref-method
  147. :ref:`int<class_int>` **get_width** **(** **)** |const|
  148. Returns the texture width.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_Texture_method_has_alpha:
  152. .. rst-class:: classref-method
  153. :ref:`bool<class_bool>` **has_alpha** **(** **)** |const|
  154. Returns ``true`` if this **Texture** has an alpha channel.
  155. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  156. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  157. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  158. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`