![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Data Structures | |
| struct | N_ATLAS |
| a set of atlas pages addressed as (page, cell index) More... | |
| struct | N_ATLAS_PAGE |
| one atlas page: a bitmap holding cols*rows equally sized cells More... | |
Functions | |
| int | n_atlas_cell_rect (const N_ATLAS *atlas, size_t page, size_t index, float *sx, float *sy, float *sw, float *sh) |
| compute the source rectangle of one cell | |
| void | n_atlas_destroy (N_ATLAS **atlas) |
| destroy an atlas and every bitmap it owns | |
| int | n_atlas_draw_cell (N_ATLAS *atlas, size_t page, size_t index, float x, float y, float size) |
| draw one cell as a size x size square | |
| int | n_atlas_max_bitmap_size (void) |
| get the largest bitmap dimension this display can hold | |
| int | n_atlas_page_ready (const N_ATLAS *atlas, size_t page) |
| test whether a page holds a usable bitmap | |
| int | n_atlas_set_page (N_ATLAS *atlas, size_t page, const void *bytes, size_t len, const char *ext, uint16_t cols, uint16_t rows) |
| decode bytes into one atlas page | |
| N_ATLAS * | new_n_atlas (size_t npages) |
| allocate an atlas holding npages empty pages | |
| struct N_ATLAS |
a set of atlas pages addressed as (page, cell index)
| Data Fields | ||
|---|---|---|
| size_t | npages | number of pages |
| N_ATLAS_PAGE * | pages | page array, npages entries |
| struct N_ATLAS_PAGE |
| int n_atlas_cell_rect | ( | const N_ATLAS * | atlas, |
| size_t | page, | ||
| size_t | index, | ||
| float * | sx, | ||
| float * | sy, | ||
| float * | sw, | ||
| float * | sh ) |
compute the source rectangle of one cell
| atlas | the atlas |
| page | page index |
| index | cell index, counted left to right then top to bottom |
| sx | filled with the cell's left edge in page pixels, may be NULL |
| sy | filled with the cell's top edge in page pixels, may be NULL |
| sw | filled with the cell width in pixels, may be NULL |
| sh | filled with the cell height in pixels, may be NULL |
Cell size is DERIVED from the page bitmap and its grid rather than declared separately, so an atlas cannot disagree with its own artwork.
Definition at line 183 of file n_atlas.c.
References N_ATLAS_PAGE::bmp, N_ATLAS_PAGE::cols, n_atlas_page_ready(), N_ATLAS::pages, row(), and N_ATLAS_PAGE::rows.
Referenced by main(), and n_atlas_draw_cell().
| void n_atlas_destroy | ( | N_ATLAS ** | atlas | ) |
destroy an atlas and every bitmap it owns
| atlas | pointer to the atlas to destroy, set to NULL on return |
Definition at line 75 of file n_atlas.c.
References __n_assert, and Free.
Referenced by main().
| int n_atlas_draw_cell | ( | N_ATLAS * | atlas, |
| size_t | page, | ||
| size_t | index, | ||
| float | x, | ||
| float | y, | ||
| float | size ) |
draw one cell as a size x size square
| atlas | the atlas |
| page | page index |
| index | cell index |
| x | destination left edge |
| y | destination top edge |
| size | destination width and height in pixels |
Returning FALSE rather than drawing nothing lets a text layout fall back to literal text for a glyph its atlas does not have.
Definition at line 226 of file n_atlas.c.
References __n_assert, N_ATLAS_PAGE::bmp, n_atlas_cell_rect(), and N_ATLAS::pages.
| int n_atlas_max_bitmap_size | ( | void | ) |
get the largest bitmap dimension this display can hold
Older mobile GPUs cap textures at 2048x2048. A page above the limit uploads blank rather than failing, which renders as nothing at all with no error, so callers are expected to REFUSE an oversized page instead of showing an empty grid. n_atlas_set_page does that for you.
Definition at line 43 of file n_atlas.c.
Referenced by main(), and n_atlas_set_page().
| int n_atlas_page_ready | ( | const N_ATLAS * | atlas, |
| size_t | page ) |
test whether a page holds a usable bitmap
| atlas | the atlas |
| page | page index |
Definition at line 160 of file n_atlas.c.
References __n_assert, N_ATLAS_PAGE::bmp, N_ATLAS_PAGE::cols, N_ATLAS::npages, N_ATLAS::pages, and N_ATLAS_PAGE::rows.
Referenced by main(), and n_atlas_cell_rect().
| int n_atlas_set_page | ( | N_ATLAS * | atlas, |
| size_t | page, | ||
| const void * | bytes, | ||
| size_t | len, | ||
| const char * | ext, | ||
| uint16_t | cols, | ||
| uint16_t | rows ) |
decode bytes into one atlas page
| atlas | the atlas |
| page | page index, < npages |
| bytes | encoded image data (PNG, JPEG, ... per the loaded image addon) |
| len | size of bytes |
| ext | extension hint for the decoder, e.g. ".png" |
| cols | grid width in cells, must be > 0 |
| rows | grid height in cells, must be > 0 |
The bytes are decoded from memory, so a caller that verified them (a hash, a signature) can hand over the exact buffer it checked rather than a path that could change underneath. A page larger than n_atlas_max_bitmap_size() is REFUSED, not uploaded: an oversized texture renders blank with no error, and failing loudly lets the caller keep whatever it had before.
Replacing a page destroys the bitmap it held. On failure the previous page is left untouched.
Definition at line 112 of file n_atlas.c.
References __n_assert, N_ATLAS_PAGE::bmp, N_ATLAS_PAGE::cols, LOG_ERR, n_atlas_max_bitmap_size(), n_log, N_ATLAS::pages, and N_ATLAS_PAGE::rows.
Referenced by main().
| N_ATLAS * new_n_atlas | ( | size_t | npages | ) |
allocate an atlas holding npages empty pages
| npages | number of pages, must be > 0 |
Definition at line 54 of file n_atlas.c.
References __n_assert, Free, Malloc, N_ATLAS::npages, and N_ATLAS::pages.
Referenced by main().