Split akgl_render_bind2d out of akgl_render_init2d
A host that owns its own window -- an embedded interpreter, which must not create one -- wants the six 2D function pointers without the window, the camera and the property registry that came with them. Until now the only options were to let libakgl own the window or to assign the vtable by hand. akgl_render_bind2d() installs the methods and nothing else, deliberately leaving self->sdl_renderer alone so a caller's own renderer survives it and a caller without one gets a backend that reports AKERR_NULLPOINTER rather than crashing. akgl_render_init2d() calls it once its window exists. tests/renderer.c is new and needs no display: the binding, frame start and end, both draw_texture paths and the draw_mesh stub against a software renderer under the dummy video driver. src/renderer.c goes from 10% line coverage to 56%. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
* the six `akgl_render_2d_*` entry points. A different renderer is a different
|
||||
* initializer populating the same struct, not a branch inside these functions.
|
||||
*
|
||||
* Those are two separable jobs, and a host that already owns an `SDL_Renderer`
|
||||
* -- an embedded interpreter, which must not create the window -- wants only the
|
||||
* second. akgl_render_bind2d() is that half on its own; akgl_render_init2d()
|
||||
* makes the window and then calls it.
|
||||
*
|
||||
* Callers do not normally name the `akgl_render_2d_*` functions directly; they
|
||||
* go through the pointers on the backend (`renderer->frame_start(renderer)`),
|
||||
* which is what makes the swap possible. The global `renderer` in game.h is the
|
||||
@@ -139,14 +144,36 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_render_2d_draw_mesh(akgl_RenderBackend *
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_render_2d_draw_world(akgl_RenderBackend *self, akgl_Iterator *opflags);
|
||||
|
||||
/**
|
||||
* @brief Install the 2D backend's methods on a backend the caller owns.
|
||||
*
|
||||
* The vtable half of akgl_render_init2d(), with no window, no renderer, and no
|
||||
* property registry involved: it points @p self's six function pointers at the
|
||||
* `akgl_render_2d_*` entry points and returns. `sdl_renderer` is not touched,
|
||||
* so a caller who has already put its own `SDL_Renderer` there keeps it, and a
|
||||
* caller who has not gets a backend whose entry points all report
|
||||
* `AKERR_NULLPOINTER` rather than crash.
|
||||
*
|
||||
* This is the entry point for a host that owns its own window -- it can drive
|
||||
* akgl_actor_render(), akgl_tilemap_draw() and the rest through a backend
|
||||
* libakgl never created. akgl_render_init2d() is the same thing with a window
|
||||
* in front of it.
|
||||
*
|
||||
* @param self The backend to bind. Required. Only the method pointers are
|
||||
* written.
|
||||
* @return `NULL` on success, otherwise an error context owned by the caller.
|
||||
* @throws AKERR_NULLPOINTER If @p self is `NULL`.
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_render_bind2d(akgl_RenderBackend *self);
|
||||
|
||||
/**
|
||||
* @brief Create the window and SDL renderer, and bind the 2D backend's methods.
|
||||
*
|
||||
* Reads `game.screenwidth` and `game.screenheight` from the property registry
|
||||
* (both defaulting to the string "0", which asks SDL for a zero-sized window),
|
||||
* creates the window and renderer with `game.uri` as the title, points `camera`
|
||||
* at the full screen rectangle, and installs the six `akgl_render_2d_*` function
|
||||
* pointers on @p self.
|
||||
* at the full screen rectangle, and then calls akgl_render_bind2d() to install
|
||||
* the six `akgl_render_2d_*` function pointers on @p self.
|
||||
*
|
||||
* Because the dimensions come from the registry, akgl_registry_init_properties
|
||||
* and the property writes have to happen first -- see the note on
|
||||
|
||||
Reference in New Issue
Block a user