natiny_shader_reload
C
int natiny_shader_reload(NatinyShader shader, NatinyResource nsl_source);
Replaces the source of an existing shader. The handle does not change.
Parameters
| Name |
Type |
Description |
shader |
NatinyShader |
Live shader handle from natiny_shader_load |
nsl_source |
NatinyResource |
Resource handle containing the new .nsl source |
Returns
| Type |
Description |
int |
1 on success, 0 on failure |
Example
C
NatinyShader shader = natiny_shader_load(source);
NatinyMaterial material = natiny_material_create(shader);
NatinyResource replacement = natiny_resource_load("shaders/water.nsl");
/* Edit the .nsl, load it again, and the material draws with the new code. */
if (!natiny_shader_reload(shader, replacement)) {
/* The shader still contains its previous compiled code. */
}
natiny_resource_destroy(replacement);
Notes
- The new source must declare the same uniforms, textures, samplers, vertex
inputs and render targets as the old one, in the same order. Source that
moves, adds or removes one is refused; the shader body may change.
- Returns
0 if shader is not live, the source does not compile or its
declarations changed. A failure leaves the shader exactly as it was.