A MoonBit reimplementation of libepoxy: OpenGL function pointer dispatch.
$ moon -C examples run hello_gl/main --release
GL_VERSION = 2.1 Metal - 90.5
gl_version = 21 (2.1)
is_desktop = true
has GL_APPLE_vertex_array_object = true
GL_MAX_TEXTURE_SIZE = 16384
glGenBuffers -> [1, 2, 3]
glShaderSource+compile ok = true
glColor3sv round-trip = [1, 0, 0]$ moon run ./examples/triangle/main --release| Path | Role |
|---|---|
| resolver.mbt, version.mbt, handles.mbt | The epoxy library (module root, tonyfettes/epoxy): the lazy dlopen/dlsym resolver + self-patching Dispatch slots, the version/extension introspection API, and the opaque-handle types. |
| epoxy.c | Hand-written C: the dlopen/dlsym resolver and C-string conversion. |
| gl.mbt | Hand-written safe GL wrappers for packed buffer uploads. |
| gl_generated.mbt | Generated MoonBit FuncRef dispatch wrappers (3213) — no C shim. |
| gl_generated_enums.mbt | Generated GL enum constants (pub const GL_* : UInt/UInt64/Int, 6061). |
| internal/glinfo/ | Pure parsers for the GL_VERSION/GL_EXTENSIONS strings (the introspection logic, unit-tested in isolation). Module-internal — not part of the public API. |
| internal/pointer/ | Minimal native Pointer[T] package: pointer methods, array/bytes borrow scopes, and three ABI helpers. Importable only inside this module. |
| generator/ | The binding generator — its own module, tonyfettes/epoxy-generator: parse.mbt (streaming registry parse), emit.mbt (classification + codegen), main.mbt (CLI driver), plus its private support packages gen/ (the GLxxx→type table), cdecl/ (C-declarator parser), aliasgroup/ (union-find over <alias> edges). |
| examples/ | A separate module (tonyfettes/epoxy-examples); see hello_gl and triangle. |
| upstream/libepoxy | The reference C implementation (submodule), incl. registry/*.xml. |
Why the sub-word narrow? MoonBit lowers every FuncRef return (Bool, Byte, …) to int32_t and reads the whole return register, so a GL function that returns unsigned char/short would leave the high bits unspecified per the psABI. The generated wrapper always masks/sign-extends the low byte/halfword — the same fixup the old C shim's (T) cast did, now done MoonBit-side.
moon -C generator run . # regenerate bindings from gl.xml
moon test # all unit tests
moon -C examples run hello_gl/main --release # the demo (release: see examples/hello_gl)moon -C generator run . -- \
--registry ../upstream/libepoxy/registry/gl.xml \
--out-mbt ../gl_generated.mbt \
--out-enums ../gl_generated_enums.mbt| Category | Count | Status |
|---|---|---|
| dispatch wrappers, including allow-listed VBO-offset vertex-array setters | 3213 | ✅ generated |
| safe buffer upload/subdata | 4 | ✅ hand-written |
| void** out-pointers (glGetPointerv, glMultiDrawElements, …) | 36 | deferred |
| GLhandleARB (platform-variant ABI; modern GLuint form is bound) | 23 | deferred |
| non-string pointer return (void* glMapBuffer) | 11 | deferred |
| pointer-width arrays (GLintptr* in glBindBuffersRange, …) | 5 | deferred |
| callback argument (GLDEBUGPROC) | 4 | deferred |
| non-char double-pointer arrays (GLvdpauSurfaceNV*) | 2 | deferred |
| OpenCL interop type (glCreateSyncFromCLeventARB) | 1 | deferred |
This package contains over 9288 items.
A MoonBit reimplementation of libepoxy: OpenGL function pointer dispatch.