virtualx-engine-docs/_sources/classes/class_imagetexture.rst.txt
2024-10-23 09:41:33 -07:00

267 lines
13 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/ImageTexture.xml.
.. _class_ImageTexture:
ImageTexture
============
**Inherits:** :ref:`Texture<class_Texture>` **<** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
A :ref:`Texture<class_Texture>` based on an :ref:`Image<class_Image>`.
.. rst-class:: classref-introduction-group
Description
-----------
A :ref:`Texture<class_Texture>` based on an :ref:`Image<class_Image>`. For an image to be displayed, an **ImageTexture** has to be created from it using the :ref:`create_from_image<class_ImageTexture_method_create_from_image>` method:
::
var texture = ImageTexture.new()
var image = Image.new()
image.load("res://icon.png")
texture.create_from_image(image)
$Sprite.texture = texture
This way, textures can be created at run-time by loading images both from within the editor and externally.
\ **Warning:** Prefer to load imported textures with :ref:`@GDScript.load<class_@GDScript_method_load>` over loading them from within the filesystem dynamically with :ref:`Image.load<class_Image_method_load>`, as it may not work in exported projects:
::
var texture = load("res://icon.png")
$Sprite.texture = texture
This is because images have to be imported as :ref:`StreamTexture<class_StreamTexture>` first to be loaded with :ref:`@GDScript.load<class_@GDScript_method_load>`. If you'd still like to load an image file just like any other :ref:`Resource<class_Resource>`, import it as an :ref:`Image<class_Image>` resource instead, and then load it normally using the :ref:`@GDScript.load<class_@GDScript_method_load>` method.
But do note that the image data can still be retrieved from an imported texture as well using the :ref:`Texture.get_data<class_Texture_method_get_data>` method, which returns a copy of the data:
::
var texture = load("res://icon.png")
var image : Image = texture.get_data()
An **ImageTexture** is not meant to be operated from within the editor interface directly, and is mostly useful for rendering images on screen dynamically via code. If you need to generate images procedurally from within the editor, consider saving and importing images as custom texture resources implementing a new :ref:`EditorImportPlugin<class_EditorImportPlugin>`.
\ **Note:** The maximum texture size is 16384×16384 pixels due to graphics hardware limitations.
\ **Note:** Mipmap generation can fail with some graphics drivers (especially on Android), resulting in black textures. In these cases, consider either calling :ref:`Image.generate_mipmaps<class_Image_method_generate_mipmaps>`, or creating an **ImageTexture** without :ref:`Texture.FLAG_MIPMAPS<class_Texture_constant_FLAG_MIPMAPS>`.
.. rst-class:: classref-introduction-group
Tutorials
---------
- :doc:`Importing images <../tutorials/assets_pipeline/importing_images>`
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
| :ref:`int<class_int>` | flags | ``7`` (overrides :ref:`Texture<class_Texture_property_flags>`) |
+-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`lossy_quality<class_ImageTexture_property_lossy_quality>` | ``0.7`` |
+-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
| :ref:`Storage<enum_ImageTexture_Storage>` | :ref:`storage<class_ImageTexture_property_storage>` | ``0`` |
+-------------------------------------------+-----------------------------------------------------------------+----------------------------------------------------------------+
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`create<class_ImageTexture_method_create>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Format<enum_Image_Format>` format, :ref:`int<class_int>` flags=7 **)** |
+---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`create_from_image<class_ImageTexture_method_create_from_image>` **(** :ref:`Image<class_Image>` image, :ref:`int<class_int>` flags=7 **)** |
+---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Format<enum_Image_Format>` | :ref:`get_format<class_ImageTexture_method_get_format>` **(** **)** |const| |
+---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load<class_ImageTexture_method_load>` **(** :ref:`String<class_String>` path **)** |
+---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_data<class_ImageTexture_method_set_data>` **(** :ref:`Image<class_Image>` image **)** |
+---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_size_override<class_ImageTexture_method_set_size_override>` **(** :ref:`Vector2<class_Vector2>` size **)** |
+---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Enumerations
------------
.. _enum_ImageTexture_Storage:
.. rst-class:: classref-enumeration
enum **Storage**:
.. _class_ImageTexture_constant_STORAGE_RAW:
.. rst-class:: classref-enumeration-constant
:ref:`Storage<enum_ImageTexture_Storage>` **STORAGE_RAW** = ``0``
:ref:`Image<class_Image>` data is stored raw and unaltered.
.. _class_ImageTexture_constant_STORAGE_COMPRESS_LOSSY:
.. rst-class:: classref-enumeration-constant
:ref:`Storage<enum_ImageTexture_Storage>` **STORAGE_COMPRESS_LOSSY** = ``1``
:ref:`Image<class_Image>` data is compressed with a lossy algorithm. You can set the storage quality with :ref:`lossy_quality<class_ImageTexture_property_lossy_quality>`.
.. _class_ImageTexture_constant_STORAGE_COMPRESS_LOSSLESS:
.. rst-class:: classref-enumeration-constant
:ref:`Storage<enum_ImageTexture_Storage>` **STORAGE_COMPRESS_LOSSLESS** = ``2``
:ref:`Image<class_Image>` data is compressed with a lossless algorithm.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_ImageTexture_property_lossy_quality:
.. rst-class:: classref-property
:ref:`float<class_float>` **lossy_quality** = ``0.7``
.. rst-class:: classref-property-setget
- void **set_lossy_storage_quality** **(** :ref:`float<class_float>` value **)**
- :ref:`float<class_float>` **get_lossy_storage_quality** **(** **)**
The storage quality for :ref:`STORAGE_COMPRESS_LOSSY<class_ImageTexture_constant_STORAGE_COMPRESS_LOSSY>`.
.. rst-class:: classref-item-separator
----
.. _class_ImageTexture_property_storage:
.. rst-class:: classref-property
:ref:`Storage<enum_ImageTexture_Storage>` **storage** = ``0``
.. rst-class:: classref-property-setget
- void **set_storage** **(** :ref:`Storage<enum_ImageTexture_Storage>` value **)**
- :ref:`Storage<enum_ImageTexture_Storage>` **get_storage** **(** **)**
The storage type (raw, lossy, or compressed).
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_ImageTexture_method_create:
.. rst-class:: classref-method
void **create** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Format<enum_Image_Format>` format, :ref:`int<class_int>` flags=7 **)**
Create a new **ImageTexture** with ``width`` and ``height``.
\ ``format`` is a value from :ref:`Format<enum_Image_Format>`, ``flags`` is any combination of :ref:`Flags<enum_Texture_Flags>`.
.. rst-class:: classref-item-separator
----
.. _class_ImageTexture_method_create_from_image:
.. rst-class:: classref-method
void **create_from_image** **(** :ref:`Image<class_Image>` image, :ref:`int<class_int>` flags=7 **)**
Initializes the texture by allocating and setting the data from an :ref:`Image<class_Image>` with ``flags`` from :ref:`Flags<enum_Texture_Flags>`. An sRGB to linear color space conversion can take place, according to :ref:`Format<enum_Image_Format>`.
.. rst-class:: classref-item-separator
----
.. _class_ImageTexture_method_get_format:
.. rst-class:: classref-method
:ref:`Format<enum_Image_Format>` **get_format** **(** **)** |const|
Returns the format of the texture, one of :ref:`Format<enum_Image_Format>`.
.. rst-class:: classref-item-separator
----
.. _class_ImageTexture_method_load:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **load** **(** :ref:`String<class_String>` path **)**
Loads an image from a file path and creates a texture from it.
\ **Note:** This method is deprecated and will be removed in Godot 4.0, use :ref:`Image.load<class_Image_method_load>` and :ref:`create_from_image<class_ImageTexture_method_create_from_image>` instead.
.. rst-class:: classref-item-separator
----
.. _class_ImageTexture_method_set_data:
.. rst-class:: classref-method
void **set_data** **(** :ref:`Image<class_Image>` image **)**
Replaces the texture's data with a new :ref:`Image<class_Image>`.
\ **Note:** The texture has to be initialized first with the :ref:`create_from_image<class_ImageTexture_method_create_from_image>` method before it can be updated. The new image dimensions, format, and mipmaps configuration should match the existing texture's image configuration, otherwise it has to be re-created with the :ref:`create_from_image<class_ImageTexture_method_create_from_image>` method.
Use this method over :ref:`create_from_image<class_ImageTexture_method_create_from_image>` if you need to update the texture frequently, which is faster than allocating additional memory for a new texture each time.
.. rst-class:: classref-item-separator
----
.. _class_ImageTexture_method_set_size_override:
.. rst-class:: classref-method
void **set_size_override** **(** :ref:`Vector2<class_Vector2>` size **)**
Resizes the texture to the specified dimensions.
.. |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.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`