natiny_texture_update
C
int natiny_texture_update(NatinyTexture texture, NatinyResource resource);
Replaces the image inside an existing texture. The handle does not change.
Parameters
| Name |
Type |
Description |
texture |
NatinyTexture |
Live texture handle from natiny_texture_create |
resource |
NatinyResource |
Resource handle containing encoded image data |
Returns
| Type |
Description |
int |
1 on success, 0 on failure |
Example
C
NatinyTexture texture = natiny_texture_create(image_resource);
natiny_material_set_texture(material, "albedo", texture,
NATINY_FILTER_LINEAR, NATINY_FILTER_LINEAR);
NatinyResource replacement = natiny_resource_load("textures/winter.png");
/* Later, with a different picture: the material is not touched again. */
if (!natiny_texture_update(texture, replacement)) {
/* The texture still shows its previous image. */
}
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.
- Returns
0 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.