natiny.texture.update
natiny.texture.update(texture, resource)
Replaces the image inside an existing texture. The handle does not change.
Parameters
| Name | Type | Description |
|---|---|---|
texture |
number |
Live texture handle from natiny.texture.create |
resource |
number |
Resource handle containing encoded image data |
Example
local texture = natiny.texture.create(image_resource)
natiny.material.set_texture(material, "albedo", texture)
local replacement = natiny.resource.load("textures/winter.png")
-- later, with a different picture: the material is not touched again
natiny.texture.update(texture, replacement)
natiny.resource.destroy(replacement)
Notes
- Everything already holding this handle - a material, a model part, the batcher - shows the new image without being re-assigned. That is the reason to update a texture rather than create a second one.
- The new size may differ from the old one.
- Raises an error if the handle is not a live texture, or if the image cannot be decoded. A failure leaves the texture showing what it showed.
- Image data is copied during the call, so the resource may be destroyed after a successful update.
- Supports the same formats as natiny.texture.create, and builds the same complete mip chain.