GPU texture loading and management with stb_image. Supports: PNG, JPG/JPEG, BMP, TGA, GIF, PSD, HDR, PIC For low-level GPU interop, include modkit.h and use the escape hatch accessor mk_texture_get_bgfx_handle() (via modkit.h).
Create an empty 2D render-target texture, optionally with a mip chain.
Target each mip by building a framebuffer via mk_framebuf_create_from_attachments() with layer=0, mip=k. Used for the GPU-generated BRDF LUT (num_mips=1) and the prefiltered equirect specular map (one mip per roughness level).
Parameter
Type
Description
width
uint16_t
Texture width
height
uint16_t
Texture height
format
mk_texture_format_t
Texture format (e.g. MK_TEXTURE_FORMAT_RGBA16F)
num_mips
uint8_t
Mip count (1 = no mips)
sampler_flags
uint64_t
Sampler flags (MK_SAMPLER_*); the render-target flag is added internally
NULL data creates a mutable empty cube updatable later via mk_texture_update_cube. When data is provided it must hold all six faces in order +X,-X,+Y,-Y,+Z,-Z, each face's mip chain packed in order. For a renderable cubemap (IBL prefilter targets) use mk_texture_create_cube_rt.
Parameter
Type
Description
face_size
uint16_t
Edge length of each cube face (mip 0)
format
mk_texture_format_t
Texture format (MK_TEXTURE_FORMAT_*)
sampler_flags
uint64_t
Sampler flags (MK_SAMPLER_*)
data
const void *
Packed 6-face data, or NULL for mutable empty
data_size
uint32_t
Size of data in bytes (0 with NULL data)
has_mips
bool
Allocate a mip chain
Returns Cubemap texture or MK_TEXTURE_INVALID on failure
mk_texture_create_cube_rtfunction
mk_texture_t mk_texture_create_cube_rt(uint16_t face_size, mk_texture_format_t format, uint8_t num_mips, uint64_t sampler_flags)
Create an empty render-target cubemap with an optional mip chain.
Each face+mip can be targeted individually by building a framebuffer via mk_framebuf_create_from_attachments(). Used for GPU IBL prefiltering (panorama->cube, GGX prefilter).
Parameter
Type
Description
face_size
uint16_t
Edge length of each cube face (mip 0)
format
mk_texture_format_t
Texture format (e.g. MK_TEXTURE_FORMAT_RGBA16F)
num_mips
uint8_t
Mip count (1 = no mips)
sampler_flags
uint64_t
Sampler flags (MK_SAMPLER_*); render-target and blit-destination flags are added internally
Returns Cubemap texture or MK_TEXTURE_INVALID on failure
mk_texture_create_hdr_mipsfunction
mk_texture_t mk_texture_create_hdr_mips(int width, int height, const float *pixels, uint64_t sampler_flags)
Upload linear float RGBA pixels to a MIPPED RGBA16F 2D texture (CPU-built mip chain).
For IBL filtered-importance-sampling: the GGX prefilter reads pre-blurred mips so glossy reflections stay low-variance/smooth instead of grainy. The HDR file loader cannot mip float data; build the env once and pass its pixels here.
Create an empty texture suitable as a GPU->CPU read-back / blit destination (created with blit-dst + read-back flags).
Blit a render target into it with mk_encoder_blit(), then retrieve the pixels with mk_texture_read(). Requires BGFX_CAPS_TEXTURE_READ_BACK (see mk_has_feature). Returns MK_TEXTURE_INVALID on failure.
Parameter
Type
Description
width
uint16_t
Texture width
height
uint16_t
Texture height
format
mk_texture_format_t
Texture format (match the source you will blit, e.g. RGBA8)
Returns Texture or MK_TEXTURE_INVALID
mk_texture_create_storagefunction
mk_texture_t mk_texture_create_storage(uint16_t width, uint16_t height, mk_texture_format_t format, uint64_t sampler_flags)
Create a compute-writable storage image (empty 2D texture).
Bind it to a compute dispatch via mk_dispatch (image binding) / mk_encoder_set_image with MK_ACCESS_WRITE or _READWRITE; the texture is also sampleable, so a later draw pass can read what the compute shader wrote. Use a compute-writable format (e.g. MK_TEXTURE_FORMAT_RGBA8).
Parameter
Type
Description
width
uint16_t
Texture width
height
uint16_t
Texture height
format
mk_texture_format_t
Texture format (e.g. MK_TEXTURE_FORMAT_RGBA8)
sampler_flags
uint64_t
Sampler flags (MK_SAMPLER_*); the compute-write flag is added internally
Supports PNG, JPG, BMP, TGA, GIF, PSD, HDR, PIC. Floating-point HDR (.hdr): pass MK_TEXTURE_HDR to decode as float into an RGBA16F texture (linear; sRGB is ignored). HDR files are also auto-detected, so a .hdr without the flag still loads as float (never silently tonemapped to 8-bit). MK_TEXTURE_MIPS is ignored on HDR loads (warns) โ build a prefilter mip chain via render targets. For RGBA32F or fine control, use mk_texture_load_ex with mk_texture_load_desc.hdr / .hdr_format.
Load a cubemap from six image files (one per face).
Face order: +X, -X, +Y, -Y, +Z, -Z (right, left, top, bottom, front, back). All faces must be square and the same size. A full mip chain is generated per face. Sample in shaders with SAMPLERCUBE; bind like any texture.
Load a texture from a full configuration descriptor (the power path).
Use this when you need per-load control over mips, filtering and anisotropy beyond what the flag shorthand expresses. mk_texture_load()/_mem() are sugar over this.
Read a texture back from the GPU into CPU memory (async).
The texture must have been created read-back capable (created blit-readable; e.g. a render target, or a texture made with the read-back flag). dest must be large enough for the full mip-0 image (width * height * bytes-per-pixel of the texture's format). The copy is NOT ready immediately: it completes on a future frame. The return value is the frame number at which dest will contain valid data โ keep calling mk_frame_end(); query mk_frame_number() for the submitted frame number and only read dest once that counter reaches the returned frame.
Parameter
Type
Description
texture
mk_texture_t
Value for texture.
dest
void *
Value for dest.
Returns The frame number when the data will be available, or 0 on error (invalid texture / not read-back capable on this renderer).