Skip to content
modkitv0.2

graphics.h

#include <modkit/graphics.h>28 functions · 4 structs · 1 enums · 5 typedefs · 22 macros

Graphics context and rendering.

Thin wrapper around the GPU backend for initialization and frame management. Use modkit.h for direct GPU backend access.

Functions

mk_backbuffer_is_srgbfunction

bool mk_backbuffer_is_srgb(void)

True when the main backbuffer performs linear-to-sRGB conversion.

Returns True when the condition holds.

mk_debug_text_clearfunction

void mk_debug_text_clear(uint8_t attr, bool small_text)

Clear debug text buffer.

ParameterTypeDescription
attruint8_tValue for attr.
small_textboolValue for small text.

mk_debug_text_enablefunction

void mk_debug_text_enable(bool enable)

Enable/disable debug text overlay.

ParameterTypeDescription
enableboolValue for enable.

mk_debug_text_enabledfunction

bool mk_debug_text_enabled(void)

Check if debug text overlay is enabled.

Returns True when the operation succeeds.

mk_debug_text_imagefunction

void mk_debug_text_image(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const void *data, uint16_t pitch)

Blit a raw 2-bytes-per-cell (char + attribute) image block into the debug text layer at cell (x,y).

data is width*height cells; pitch is the source row stride in bytes (0 => width*2). Lets you draw a precomputed text/glyph block in one call.

ParameterTypeDescription
xuint16_tValue for x.
yuint16_tValue for y.
widthuint16_tValue for width.
heightuint16_tValue for height.
dataconst void *Data buffer.
pitchuint16_tValue for pitch.

mk_debug_text_printffunction

void mk_debug_text_printf(uint16_t x, uint16_t y, uint8_t attr, const char *fmt,...)

Print debug text at position.

Uses debug text positioned relative to the main window's safe area.

ParameterTypeDescription
xuint16_tValue for x.
yuint16_tValue for y.
attruint8_tValue for attr.
fmtconst char *Value for fmt.
...

mk_debug_wireframefunction

void mk_debug_wireframe(bool enable)

Enable/disable debug wireframe mode.

Renders ALL primitives as wireframe (triangles, 2D, 3D, everything).

ParameterTypeDescription
enableboolValue for enable.

mk_debug_wireframe_enabledfunction

bool mk_debug_wireframe_enabled(void)

Check if debug wireframe mode is enabled.

Returns True when the operation succeeds.

mk_frame_beginfunction

void mk_frame_begin(void)

Begin a new frame.

mk_frame_endfunction

bool mk_frame_end(void)

Seal, submit, and present the frame.

Returns false without entering bgfx when a pass or worker context is still active. The sealed frame may be retried after ending the outstanding work.

Returns True when the operation succeeds.

mk_frame_numberfunction

uint32_t mk_frame_number(void)

Most recent frame number returned by a successful bgfx_frame call.

Returns The resulting value.

mk_get_capsfunction

void mk_get_caps(mk_caps *out)

Fill a mk_caps describing the active renderer.

NOOP exposes its real bgfx limits; the structure is zeroed when caps are unavailable before init.

ParameterTypeDescription
outmk_caps *Value for out.

mk_get_max_draw_callsfunction

uint32_t mk_get_max_draw_calls(void)

Get maximum supported draw calls per frame.

Returns Maximum draw call count

mk_get_max_texture_sizefunction

uint32_t mk_get_max_texture_size(void)

Get maximum supported texture size.

Returns Maximum texture dimension in pixels

mk_get_renderer_typefunction

mk_renderer_type_t mk_get_renderer_type(void)

Get the current renderer type.

Returns Renderer type enum

mk_get_resolutionfunction

void mk_get_resolution(uint16_t *width, uint16_t *height)

Get current backbuffer dimensions.

ParameterTypeDescription
widthuint16_t *Value for width.
heightuint16_t *Value for height.

mk_get_statsfunction

const mk_stats_t * mk_get_stats(void)

Get frame performance statistics.

Returns a snapshot of the current frame's performance counters including draw call counts, GPU memory usage, CPU/GPU frame times, and per-view stats. Example:

Returns Pointer to stats struct. Valid until the next mk_frame_end() call. Returns NULL if the GPU backend is not initialized.

const mk_stats_t* stats = mk_get_stats();
if (stats) {
    mk_debug_text_printf(0, 0, 0x0f, "Draw calls: %u", stats->num_draw);
    mk_debug_text_printf(0, 1, 0x0f, "GPU: %.2f ms", stats->gpu_frame_ms);
}

mk_get_supported_renderersfunction

uint8_t mk_get_supported_renderers(mk_renderer_type_t *out, uint8_t max_count)

Enumerate the renderer backends supported on this system.

Safe to call before mk_init() (e.g. to offer the user a backend choice). Backends modkit does not model are omitted. Writes up to max_count entries into out; returns the total supported count (which may exceed max_count).

ParameterTypeDescription
outmk_renderer_type_t *Array to receive renderer types (may be NULL to just count)
max_countuint8_tCapacity of out

Returns Number of supported renderers

mk_gfx_flushfunction

void mk_gfx_flush(void)

Advance bgfx by one frame without the full frame-end present/overlay pipeline.

For init-time offscreen GPU work (e.g. IBL prefiltering) that submits many one-shot draws and must flush queued views between batches. Not for normal per-frame use — call mk_frame_end() for that.

mk_graphics_resizefunction

void mk_graphics_resize(uint16_t width, uint16_t height)

Handle window resize.

Updates resolution. Called automatically when window resize event is detected.

ParameterTypeDescription
widthuint16_tValue for width.
heightuint16_tValue for height.

mk_has_featurefunction

bool mk_has_feature(uint64_t feature)

Check if a feature is supported by the current renderer.

ParameterTypeDescription
featureuint64_tFeature flag to check

Returns true if supported

mk_renderer_namefunction

const char * mk_renderer_name(void)

Get the current renderer name as a string.

Returns Human-readable renderer name (e.g., "Vulkan", "OpenGL", "Direct3D 11")

mk_renderer_profile_coveredfunction

bool mk_renderer_profile_covered(mk_renderer_type_t renderer)

Perform the renderer profile covered operation.

ParameterTypeDescription
renderermk_renderer_type_tValue for renderer.

Returns True when the operation succeeds.

mk_set_debug_flagsfunction

void mk_set_debug_flags(uint32_t flags)

Set debug flags directly.

Prefer using mk_debug_enable(MK_DEBUG_*) for high-level debug control.

ParameterTypeDescription
flagsuint32_tCombination of MK_DEBUG_FLAG_* flags

mk_texture_format_renderablefunction

bool mk_texture_format_renderable(mk_texture_format_t format)

True if a texture format can be used as a render-target (framebuffer) attachment.

ParameterTypeDescription
formatmk_texture_format_tValue for format.

Returns True when the operation succeeds.

mk_texture_format_supportedfunction

bool mk_texture_format_supported(mk_texture_format_t format)

True if a texture format can be sampled as a 2D texture on this GPU.

ParameterTypeDescription
formatmk_texture_format_tValue for format.

Returns True when the condition holds.

mk_texture_format_supported_3dfunction

bool mk_texture_format_supported_3d(mk_texture_format_t format)

True if a texture format can be sampled as a 3D texture on this GPU.

ParameterTypeDescription
formatmk_texture_format_tValue for format.

Returns True when the operation succeeds.

mk_trace_to_logfunction

void mk_trace_to_log(bool enable)

Enable/disable forwarding backend trace messages to mk_log.

ParameterTypeDescription
enablebooltrue to forward to mk_log, false for stderr only

Structs

mk_capsstruct

Consolidated, renderer-agnostic device capabilities.

A curated subset of the underlying bgfx caps — the fields apps actually branch on. Use mk_has_feature() for individual BGFX_CAPS_* flags and mk_texture_format_supported() for formats.

FieldTypeDescription
renderermk_renderer_type_tActive backend.
vendor_iduint16_tGPU vendor PCI id (0 if unknown).
device_iduint16_tGPU device PCI id.
num_gpusuint8_tNumber of enumerated GPUs.
homogeneous_depthboolNDC depth is [-1,1] (GL) vs [0,1].
origin_bottom_leftboolFramebuffer origin is bottom-left (GL).
max_texture_sizeuint32_tMax 2D texture dimension.
max_texture_layersuint32_tMax array texture layers.
max_texture_samplersuint32_tMax texture stages per draw.
max_uniform_handlesuint32_tMax live uniform handles.
max_compute_bindingsuint32_tMax compute image/buffer bindings.
max_vertex_streamsuint32_tMax simultaneous vertex streams.
max_fb_attachmentsuint32_tMax color attachments per framebuffer.
max_viewsuint32_tMax render views.
max_draw_callsuint32_tMax draw calls per frame.
max_encodersuint32_tTotal encoders including encoder 0.
supporteduint64_tRaw BGFX_CAPS_* bitfield.

mk_graphics_configstruct

Graphics configuration for mk_init().

FieldTypeDescription
renderermk_renderer_type_tMK_RENDERER_AUTO = auto-detect.
reset_flagsuint32_tReset flags (MK_RESET_*).
video_decodemk_video_decode_mode_tHardware video device opt-in.

mk_statsstruct

Frame performance statistics.

Returned by mk_get_stats(). Pointer is valid until the next mk_frame_end() call. All time values are pre-computed in milliseconds for convenience.

FieldTypeDescription
cpu_frame_msdoubleCPU time between two frame calls.
cpu_submit_msdoubleCPU render-thread submit time.
gpu_frame_msdoubleGPU frame time.
wait_render_msdoubleTime waiting for render thread.
wait_submit_msdoubleTime waiting for submit thread.
num_drawuint32_tNumber of draw calls submitted.
num_computeuint32_tNumber of compute calls submitted.
num_blituint32_tNumber of blit calls submitted.
num_prims_trianglesuint32_tNumber of triangle primitives.
num_prims_linesuint32_tNumber of line primitives.
num_prims_pointsuint32_tNumber of point primitives.
gpu_memory_usedint64_tGPU memory used (bytes), -1 if N/A.
gpu_memory_maxint64_tGPU memory max (bytes), -1 if N/A.
texture_memoryint64_tEstimated texture memory (bytes).
rt_memoryint64_tEstimated render target memory (bytes).
num_texturesuint16_tNumber of textures in use.
num_shadersuint16_tNumber of shaders in use.
num_programsuint16_tNumber of programs in use.
num_uniformsuint16_tNumber of uniforms in use.
num_vertex_buffersuint16_tNumber of vertex buffers in use.
num_index_buffersuint16_tNumber of index buffers (static).
num_dynamic_vertex_buffersuint16_tNumber of dynamic vertex buffers.
num_dynamic_index_buffersuint16_tNumber of dynamic index buffers.
num_frame_buffersuint16_tNumber of frame buffers in use.
transient_vb_usedint32_tTransient vertex buffer bytes used.
transient_ib_usedint32_tTransient index buffer bytes used.
widthuint16_tBackbuffer width in pixels.
heightuint16_tBackbuffer height in pixels.
num_viewsuint16_tNumber of active views.
view_statsconst mk_view_stats_t *Array of per-view stats (num_views entries).
max_gpu_latencyuint32_tGPU driver latency (frames).
num_encodersuint8_tNumber of encoders used this frame.
retained_packetsuint32_tEligible draw packets captured.
batched_drawsuint32_tActual instanced submissions.
batched_instancesuint32_tInstances in batched submissions.
batch_fallback_drawsuint32_tRetained packets submitted individually.

mk_view_statsstruct

Per-view performance statistics.

FieldTypeDescription
namecharView name.
viewuint16_tView ID.
cpu_time_msdoubleCPU submit time in milliseconds.
gpu_time_msdoubleGPU time in milliseconds.
gpu_frame_numberuint32_tBackend frame that produced GPU timing.

Enums

mk_video_decode_modeenum

Hardware video decode device opt-in.

DEFAULT follows the build: enabled when MODKIT_HAS_VIDEO is non-zero and disabled otherwise. DISABLED is useful for deterministic software-only playback and avoids asking the graphics backend to create video queues.

ValueDescription
MK_VIDEO_DECODE_DEFAULTSelects default.
MK_VIDEO_DECODE_ENABLEDSelects enabled.
MK_VIDEO_DECODE_DISABLEDSelects disabled.

Typedefs

mk_capstypedef

typedef struct mk_caps mk_caps

Consolidated, renderer-agnostic device capabilities.

A curated subset of the underlying bgfx caps — the fields apps actually branch on. Use mk_has_feature() for individual BGFX_CAPS_* flags and mk_texture_format_supported() for formats.

mk_graphics_configtypedef

typedef struct mk_graphics_config mk_graphics_config

Graphics configuration for mk_init().

mk_stats_ttypedef

typedef struct mk_stats mk_stats_t

Frame performance statistics.

Returned by mk_get_stats(). Pointer is valid until the next mk_frame_end() call. All time values are pre-computed in milliseconds for convenience.

mk_video_decode_mode_ttypedef

typedef enum mk_video_decode_mode mk_video_decode_mode_t

Hardware video decode device opt-in.

DEFAULT follows the build: enabled when MODKIT_HAS_VIDEO is non-zero and disabled otherwise. DISABLED is useful for deterministic software-only playback and avoids asking the graphics backend to create video queues.

mk_view_stats_ttypedef

typedef struct mk_view_stats mk_view_stats_t

Per-view performance statistics.

Macros

MK_DEBUG_FLAG_IFHdefine

MK_DEBUG_FLAG_IFH

Constant for debug flag ifh.

MK_DEBUG_FLAG_NONEdefine

MK_DEBUG_FLAG_NONE

Constant for debug flag none.

MK_DEBUG_FLAG_PROFILERdefine

MK_DEBUG_FLAG_PROFILER

Constant for debug flag profiler.

MK_DEBUG_FLAG_STATSdefine

MK_DEBUG_FLAG_STATS

Constant for debug flag stats.

MK_DEBUG_FLAG_TEXTdefine

MK_DEBUG_FLAG_TEXT

Constant for debug flag text.

MK_DEBUG_FLAG_WIREFRAMEdefine

MK_DEBUG_FLAG_WIREFRAME

Constant for debug flag wireframe.

MK_GRAPHICS_CONFIG_DEFAULTdefine

MK_GRAPHICS_CONFIG_DEFAULT

Constant for graphics config default.

MK_RESET_CAPTUREdefine

MK_RESET_CAPTURE

Constant for reset capture.

MK_RESET_DEPTH_CLAMPdefine

MK_RESET_DEPTH_CLAMP

Constant for reset depth clamp.

MK_RESET_FLUSH_AFTER_RENDERdefine

MK_RESET_FLUSH_AFTER_RENDER

Constant for reset flush after render.

MK_RESET_FULLSCREENdefine

MK_RESET_FULLSCREEN

Constant for reset fullscreen.

MK_RESET_HDR10define

MK_RESET_HDR10

Constant for reset hdr10.

MK_RESET_HIDPIdefine

MK_RESET_HIDPI

Constant for reset hidpi.

MK_RESET_MAXANISOTROPYdefine

MK_RESET_MAXANISOTROPY

Maximum supported reset maxanisotropy.

MK_RESET_MSAA_X16define

MK_RESET_MSAA_X16

Constant for reset msaa x16.

MK_RESET_MSAA_X2define

MK_RESET_MSAA_X2

Constant for reset msaa x2.

MK_RESET_MSAA_X4define

MK_RESET_MSAA_X4

Constant for reset msaa x4.

MK_RESET_MSAA_X8define

MK_RESET_MSAA_X8

Constant for reset msaa x8.

MK_RESET_NONEdefine

MK_RESET_NONE

Constant for reset none.

MK_RESET_SRGB_BACKBUFFERdefine

MK_RESET_SRGB_BACKBUFFER

Constant for reset srgb backbuffer.

MK_RESET_TRANSPARENT_BACKBUFFERdefine

MK_RESET_TRANSPARENT_BACKBUFFER

Constant for reset transparent backbuffer.

MK_RESET_VSYNCdefine

MK_RESET_VSYNC

Constant for reset vsync.