Updated GB_set_rgb_encode_callback (markdown)

Lior Halphon 2024-11-26 23:33:43 +02:00
parent a75d598b5b
commit 6060a63c69
1 changed files with 27 additions and 5 deletions

@ -1,17 +1,39 @@
## Definition
```c
typedef uint32_t (*GB_rgb_encode_callback_t)(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b);
```
<tt>typedef uint32_t (*GB_rgb_encode_callback_t)([[GB_gameboy_t]] *gb, uint8_t r, uint8_t g, uint8_t b);</tt>
<tt>void GB_set_rgb_encode_callback([[GB_gameboy_t]] *gb, [[GB_rgb_encode_callback_t]] callback);</tt>
<tt>void GB_set_rgb_encode_callback([[GB_gameboy_t]] *gb, GB_rgb_encode_callback_t callback);</tt>
In `display.h`
## Description
TBD
Sets an encoding function that will convert red, green, and blue triplets to a single `uint32_t` value supported by your frontend. For example:
```c
/* Assuming Little Endian */
static uint32_t encode_rgba(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b)
{
return (r << 0) | (g << 8) | (b << 16) | 0xFF000000;
}
static uint32_t encode_bgrx(GB_gameboy_t *gb, uint8_t r, uint8_t g, uint8_t b)
{
return (r << 16) | (g << 8) | (b << 0);
}
```
You must either call this function with a valid function pointer or [[GB_set_rendering_disabled]] with `true` before first calling `GB_run`.
## Thread Safety
If `callback` is not NULL, `GB_set_rgb_encode_callback` is thread-safe and can be called from any thread and context. Otherwise, it must not be called if the instance is being run in another thread, but may be called from the current one (via a callback).
## See Also
* [[GB_set_pixels_output]]
* [[GB_set_rgb_encode_callback]]
* [[GB_get_screen_width and GB_get_screen_height]]