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.
#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.
mk_backbuffer_is_srgbfunctionbool mk_backbuffer_is_srgb(void)True when the main backbuffer performs linear-to-sRGB conversion.
Returns True when the condition holds.
mk_debug_text_clearfunctionvoid mk_debug_text_clear(uint8_t attr, bool small_text)Clear debug text buffer.
| Parameter | Type | Description |
|---|---|---|
attr | uint8_t | Value for attr. |
small_text | bool | Value for small text. |
mk_debug_text_enablefunctionvoid mk_debug_text_enable(bool enable)Enable/disable debug text overlay.
| Parameter | Type | Description |
|---|---|---|
enable | bool | Value for enable. |
mk_debug_text_enabledfunctionbool mk_debug_text_enabled(void)Check if debug text overlay is enabled.
Returns True when the operation succeeds.
mk_debug_text_imagefunctionvoid 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.
| Parameter | Type | Description |
|---|---|---|
x | uint16_t | Value for x. |
y | uint16_t | Value for y. |
width | uint16_t | Value for width. |
height | uint16_t | Value for height. |
data | const void * | Data buffer. |
pitch | uint16_t | Value for pitch. |
mk_debug_text_printffunctionvoid 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.
| Parameter | Type | Description |
|---|---|---|
x | uint16_t | Value for x. |
y | uint16_t | Value for y. |
attr | uint8_t | Value for attr. |
fmt | const char * | Value for fmt. |
| ... | — |
mk_debug_wireframefunctionvoid mk_debug_wireframe(bool enable)Enable/disable debug wireframe mode.
Renders ALL primitives as wireframe (triangles, 2D, 3D, everything).
| Parameter | Type | Description |
|---|---|---|
enable | bool | Value for enable. |
mk_debug_wireframe_enabledfunctionbool mk_debug_wireframe_enabled(void)Check if debug wireframe mode is enabled.
Returns True when the operation succeeds.
mk_frame_beginfunctionvoid mk_frame_begin(void)Begin a new frame.
mk_frame_endfunctionbool 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_numberfunctionuint32_t mk_frame_number(void)Most recent frame number returned by a successful bgfx_frame call.
Returns The resulting value.
mk_get_capsfunctionvoid 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.
| Parameter | Type | Description |
|---|---|---|
out | mk_caps * | Value for out. |
mk_get_max_draw_callsfunctionuint32_t mk_get_max_draw_calls(void)Get maximum supported draw calls per frame.
Returns Maximum draw call count
mk_get_max_texture_sizefunctionuint32_t mk_get_max_texture_size(void)Get maximum supported texture size.
Returns Maximum texture dimension in pixels
mk_get_renderer_typefunctionmk_renderer_type_t mk_get_renderer_type(void)Get the current renderer type.
Returns Renderer type enum
mk_get_resolutionfunctionvoid mk_get_resolution(uint16_t *width, uint16_t *height)Get current backbuffer dimensions.
| Parameter | Type | Description |
|---|---|---|
width | uint16_t * | Value for width. |
height | uint16_t * | Value for height. |
mk_get_statsfunctionconst 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_renderersfunctionuint8_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).
| Parameter | Type | Description |
|---|---|---|
out | mk_renderer_type_t * | Array to receive renderer types (may be NULL to just count) |
max_count | uint8_t | Capacity of out |
Returns Number of supported renderers
mk_gfx_flushfunctionvoid 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_resizefunctionvoid mk_graphics_resize(uint16_t width, uint16_t height)Handle window resize.
Updates resolution. Called automatically when window resize event is detected.
| Parameter | Type | Description |
|---|---|---|
width | uint16_t | Value for width. |
height | uint16_t | Value for height. |
mk_has_featurefunctionbool mk_has_feature(uint64_t feature)Check if a feature is supported by the current renderer.
| Parameter | Type | Description |
|---|---|---|
feature | uint64_t | Feature flag to check |
Returns true if supported
mk_renderer_namefunctionconst 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_coveredfunctionbool mk_renderer_profile_covered(mk_renderer_type_t renderer)Perform the renderer profile covered operation.
| Parameter | Type | Description |
|---|---|---|
renderer | mk_renderer_type_t | Value for renderer. |
Returns True when the operation succeeds.
mk_set_debug_flagsfunctionvoid mk_set_debug_flags(uint32_t flags)Set debug flags directly.
Prefer using mk_debug_enable(MK_DEBUG_*) for high-level debug control.
| Parameter | Type | Description |
|---|---|---|
flags | uint32_t | Combination of MK_DEBUG_FLAG_* flags |
mk_texture_format_renderablefunctionbool mk_texture_format_renderable(mk_texture_format_t format)True if a texture format can be used as a render-target (framebuffer) attachment.
| Parameter | Type | Description |
|---|---|---|
format | mk_texture_format_t | Value for format. |
Returns True when the operation succeeds.
mk_texture_format_supportedfunctionbool mk_texture_format_supported(mk_texture_format_t format)True if a texture format can be sampled as a 2D texture on this GPU.
| Parameter | Type | Description |
|---|---|---|
format | mk_texture_format_t | Value for format. |
Returns True when the condition holds.
mk_texture_format_supported_3dfunctionbool 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.
| Parameter | Type | Description |
|---|---|---|
format | mk_texture_format_t | Value for format. |
Returns True when the operation succeeds.
mk_trace_to_logfunctionvoid mk_trace_to_log(bool enable)Enable/disable forwarding backend trace messages to mk_log.
| Parameter | Type | Description |
|---|---|---|
enable | bool | true to forward to mk_log, false for stderr only |
mk_capsstructConsolidated, 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.
| Field | Type | Description |
|---|---|---|
renderer | mk_renderer_type_t | Active backend. |
vendor_id | uint16_t | GPU vendor PCI id (0 if unknown). |
device_id | uint16_t | GPU device PCI id. |
num_gpus | uint8_t | Number of enumerated GPUs. |
homogeneous_depth | bool | NDC depth is [-1,1] (GL) vs [0,1]. |
origin_bottom_left | bool | Framebuffer origin is bottom-left (GL). |
max_texture_size | uint32_t | Max 2D texture dimension. |
max_texture_layers | uint32_t | Max array texture layers. |
max_texture_samplers | uint32_t | Max texture stages per draw. |
max_uniform_handles | uint32_t | Max live uniform handles. |
max_compute_bindings | uint32_t | Max compute image/buffer bindings. |
max_vertex_streams | uint32_t | Max simultaneous vertex streams. |
max_fb_attachments | uint32_t | Max color attachments per framebuffer. |
max_views | uint32_t | Max render views. |
max_draw_calls | uint32_t | Max draw calls per frame. |
max_encoders | uint32_t | Total encoders including encoder 0. |
supported | uint64_t | Raw BGFX_CAPS_* bitfield. |
mk_graphics_configstructGraphics configuration for mk_init().
| Field | Type | Description |
|---|---|---|
renderer | mk_renderer_type_t | MK_RENDERER_AUTO = auto-detect. |
reset_flags | uint32_t | Reset flags (MK_RESET_*). |
video_decode | mk_video_decode_mode_t | Hardware video device opt-in. |
mk_statsstructFrame 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.
| Field | Type | Description |
|---|---|---|
cpu_frame_ms | double | CPU time between two frame calls. |
cpu_submit_ms | double | CPU render-thread submit time. |
gpu_frame_ms | double | GPU frame time. |
wait_render_ms | double | Time waiting for render thread. |
wait_submit_ms | double | Time waiting for submit thread. |
num_draw | uint32_t | Number of draw calls submitted. |
num_compute | uint32_t | Number of compute calls submitted. |
num_blit | uint32_t | Number of blit calls submitted. |
num_prims_triangles | uint32_t | Number of triangle primitives. |
num_prims_lines | uint32_t | Number of line primitives. |
num_prims_points | uint32_t | Number of point primitives. |
gpu_memory_used | int64_t | GPU memory used (bytes), -1 if N/A. |
gpu_memory_max | int64_t | GPU memory max (bytes), -1 if N/A. |
texture_memory | int64_t | Estimated texture memory (bytes). |
rt_memory | int64_t | Estimated render target memory (bytes). |
num_textures | uint16_t | Number of textures in use. |
num_shaders | uint16_t | Number of shaders in use. |
num_programs | uint16_t | Number of programs in use. |
num_uniforms | uint16_t | Number of uniforms in use. |
num_vertex_buffers | uint16_t | Number of vertex buffers in use. |
num_index_buffers | uint16_t | Number of index buffers (static). |
num_dynamic_vertex_buffers | uint16_t | Number of dynamic vertex buffers. |
num_dynamic_index_buffers | uint16_t | Number of dynamic index buffers. |
num_frame_buffers | uint16_t | Number of frame buffers in use. |
transient_vb_used | int32_t | Transient vertex buffer bytes used. |
transient_ib_used | int32_t | Transient index buffer bytes used. |
width | uint16_t | Backbuffer width in pixels. |
height | uint16_t | Backbuffer height in pixels. |
num_views | uint16_t | Number of active views. |
view_stats | const mk_view_stats_t * | Array of per-view stats (num_views entries). |
max_gpu_latency | uint32_t | GPU driver latency (frames). |
num_encoders | uint8_t | Number of encoders used this frame. |
retained_packets | uint32_t | Eligible draw packets captured. |
batched_draws | uint32_t | Actual instanced submissions. |
batched_instances | uint32_t | Instances in batched submissions. |
batch_fallback_draws | uint32_t | Retained packets submitted individually. |
mk_view_statsstructPer-view performance statistics.
| Field | Type | Description |
|---|---|---|
name | char | View name. |
view | uint16_t | View ID. |
cpu_time_ms | double | CPU submit time in milliseconds. |
gpu_time_ms | double | GPU time in milliseconds. |
gpu_frame_number | uint32_t | Backend frame that produced GPU timing. |
mk_video_decode_modeenumHardware 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.
| Value | Description |
|---|---|
MK_VIDEO_DECODE_DEFAULT | Selects default. |
MK_VIDEO_DECODE_ENABLED | Selects enabled. |
MK_VIDEO_DECODE_DISABLED | Selects disabled. |
mk_capstypedeftypedef struct mk_caps mk_capsConsolidated, 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_configtypedeftypedef struct mk_graphics_config mk_graphics_configGraphics configuration for mk_init().
mk_stats_ttypedeftypedef struct mk_stats mk_stats_tFrame 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_ttypedeftypedef enum mk_video_decode_mode mk_video_decode_mode_tHardware 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_ttypedeftypedef struct mk_view_stats mk_view_stats_tPer-view performance statistics.
MK_DEBUG_FLAG_IFHdefineMK_DEBUG_FLAG_IFHConstant for debug flag ifh.
MK_DEBUG_FLAG_NONEdefineMK_DEBUG_FLAG_NONEConstant for debug flag none.
MK_DEBUG_FLAG_PROFILERdefineMK_DEBUG_FLAG_PROFILERConstant for debug flag profiler.
MK_DEBUG_FLAG_STATSdefineMK_DEBUG_FLAG_STATSConstant for debug flag stats.
MK_DEBUG_FLAG_TEXTdefineMK_DEBUG_FLAG_TEXTConstant for debug flag text.
MK_DEBUG_FLAG_WIREFRAMEdefineMK_DEBUG_FLAG_WIREFRAMEConstant for debug flag wireframe.
MK_GRAPHICS_CONFIG_DEFAULTdefineMK_GRAPHICS_CONFIG_DEFAULTConstant for graphics config default.
MK_RESET_CAPTUREdefineMK_RESET_CAPTUREConstant for reset capture.
MK_RESET_DEPTH_CLAMPdefineMK_RESET_DEPTH_CLAMPConstant for reset depth clamp.
MK_RESET_FLUSH_AFTER_RENDERdefineMK_RESET_FLUSH_AFTER_RENDERConstant for reset flush after render.
MK_RESET_FULLSCREENdefineMK_RESET_FULLSCREENConstant for reset fullscreen.
MK_RESET_HDR10defineMK_RESET_HDR10Constant for reset hdr10.
MK_RESET_HIDPIdefineMK_RESET_HIDPIConstant for reset hidpi.
MK_RESET_MAXANISOTROPYdefineMK_RESET_MAXANISOTROPYMaximum supported reset maxanisotropy.
MK_RESET_MSAA_X16defineMK_RESET_MSAA_X16Constant for reset msaa x16.
MK_RESET_MSAA_X2defineMK_RESET_MSAA_X2Constant for reset msaa x2.
MK_RESET_MSAA_X4defineMK_RESET_MSAA_X4Constant for reset msaa x4.
MK_RESET_MSAA_X8defineMK_RESET_MSAA_X8Constant for reset msaa x8.
MK_RESET_NONEdefineMK_RESET_NONEConstant for reset none.
MK_RESET_SRGB_BACKBUFFERdefineMK_RESET_SRGB_BACKBUFFERConstant for reset srgb backbuffer.
MK_RESET_TRANSPARENT_BACKBUFFERdefineMK_RESET_TRANSPARENT_BACKBUFFERConstant for reset transparent backbuffer.
MK_RESET_VSYNCdefineMK_RESET_VSYNCConstant for reset vsync.