Cross-platform shader compiler and runtime library
Foundation header providing memory allocation hooks and binary format constants.
Enables custom memory allocators for embedded/game engines with strict memory requirements. Defines the binary format version for forward compatibility.
// Override before any nshader calls
nshader_set_memory_fns(my_malloc, my_free, my_calloc, my_realloc);
Default implementations use standard library functions. Override is not thread-safe; call once at startup before any nshader operations.
All internal allocations route through these functions:
nshader_malloc(size) - allocatenshader_free(ptr) - deallocatenshader_calloc(num, size) - allocate zeroednshader_realloc(ptr, new_size) - resize| Constant | Value | Description |
|---|---|---|
NSHADER_MAGIC |
0x5244534E |
“NSDR” in little-endian; file identifier |
NSHADER_VERSION |
1 |
Binary format version |
NSHADER_API macro handles symbol visibility:
NSHADER_SHARED, NSHADER_EXPORTS)