Skip to content
modkitv0.2

nanovg.h

#include <modkit/nanovg.h>7 functions

NanoVG integration for modkit.

Provides vector graphics rendering using NanoVG with the modkit GPU backend. This wraps the upstream NanoVG API and provides modkit-specific creation/destruction functions.

Functions

mk_nvg_createfunction

NVGcontext * mk_nvg_create(mk_view_id_t view_id, bool edgeaa)

Create a NanoVG context with modkit GPU backend.

ParameterTypeDescription
view_idmk_view_id_tThe view ID to render to
edgeaaboolEnable edge anti-aliasing (true) or disable (false)

Returns NanoVG context, or NULL on failure

mk_nvg_create_image_from_texturefunction

int mk_nvg_create_image_from_texture(NVGcontext *ctx, mk_texture_t texture, int flags)

Create a NanoVG image from a modkit texture.

The texture is NOT owned by NanoVG - you must keep it alive.

ParameterTypeDescription
ctxNVGcontext *The NanoVG context
texturemk_texture_tThe modkit texture
flagsintNanoVG image flags (NVG_IMAGE_*)

Returns Image handle for use with nvgImagePattern(), or -1 on failure

mk_nvg_destroyfunction

void mk_nvg_destroy(NVGcontext *ctx)

Destroy a NanoVG context and release all resources.

ParameterTypeDescription
ctxNVGcontext *The context to destroy

mk_nvg_get_viewfunction

mk_view_id_t mk_nvg_get_view(NVGcontext *ctx)

Get the current view ID.

ParameterTypeDescription
ctxNVGcontext *The NanoVG context

Returns The current view ID

mk_nvg_set_encoderfunction

void mk_nvg_set_encoder(NVGcontext *ctx, mk_encoder_t encoder)

Set the encoder for thread-safe rendering.

Must be called before nvgBeginFrame() each frame.

ParameterTypeDescription
ctxNVGcontext *The NanoVG context
encodermk_encoder_tThe encoder to use for rendering

mk_nvg_set_viewfunction

void mk_nvg_set_view(NVGcontext *ctx, mk_view_id_t view_id)

Set the view ID for rendering.

ParameterTypeDescription
ctxNVGcontext *The NanoVG context
view_idmk_view_id_tThe new view ID

mk_pass_nvgfunction

void mk_pass_nvg(NVGcontext *ctx)

Bind a NanoVG context to the currently-active pass — the pass-native entry point (mirrors mk_pass_canvas/draw3d/text).

Flushes any active pass draw context, then points the NanoVG context at the pass's encoder + view so the next nvgBeginFrame()/nvgEndFrame() renders into the pass. No-op (logs) if no pass is active. Call once per frame before nvgBeginFrame().

ParameterTypeDescription
ctxNVGcontext *Active operation context.
mk_begin_pass(&mk_pass_clear(0x202020ff));
mk_pass_nvg(vg);
nvgBeginFrame(vg, w, h, 1.0f);
... nvg draw calls ...
nvgEndFrame(vg);
mk_end_pass();