swung0x48 5239ae0c19 [MG_Remote] (P6/cp): EGL control frames cross to the other process, and answer
An eglInitialize issued in one process is dispatched in another and its answer
comes back. That is the last thing standing between the session and a native
context, because the server creates its context on the apply thread when the
client's first eglMakeCurrent crosses - and until now nothing crossed.

ONE SEAM, NOT TWELVE. a6 row A4-13 counted twelve Server* forwarders, each
ending in ServerLoopInstance().RunSurfaceControlFrame(frame) with no role
branch, and concluded twelve edits. They all funnel through that one function,
so the branch goes there and the forwarders are untouched.

A HOOK, NOT A CALL. ServerLoop::SetRemoteControlSink takes a function pointer
the client installs at handshake. The obvious alternative - the server half
asking ClientSession::Active() - would have added a fifth symbol to the six
MG_Remote already owes itself (a6-link-experiment §5), in the one file with a
clean reason not to.

The branch is BEFORE the local seq mint, deliberately. RunSurfaceControlFrame
numbers unnumbered local posts; a wire request must keep the CLIENT's number all
the way through dispatch and reply or its answer cannot be correlated
(CONTRACT-P6 §6.3, which says the client mints, always).

The client sink encodes with EncodeSurfaceOpFrame, sends, and waits for the
SurfaceReply carrying its own seq - under one mutex, because the twelve
forwarders are already caller-serialised on the server's m_callerMutex under
inproc and two replies racing for one correlation is the same bug on either
side. A CapsSnapshot arriving while it waits is ADOPTED rather than dropped:
the server republishes caps from inside its MakeCurrent dispatch (a6 row A4-30)
so a snapshot legitimately precedes the reply to the op that produced it. The
wait is bounded and its expiry is NOT fatal - a peer that is gone is a different
fact from a peer that is slow, and only the doorbell's death latch may say which.

The server's pump decodes and applies through ServerApplyWireSurfaceOp, which
a6 found had no production caller anywhere. It runs on ServerMain's own thread -
NOT the apply thread - which is what §6.2 asks for: a control arrival must not
wake the applier, and frame decode must not happen on the thread holding the
native context. A frame that is not a verifiable SurfaceOp ends the session
rather than being ignored, because a silent drop is the failure mode this
project refuses everywhere else.

THE TEST'S ASSERTION IS THE OUT-PARAMETERS, not the EGL result. A headless
machine has no display to initialise, so the op is expected to be refused - and
ServerInitializeEGLDisplay writes major/minor "whenever the dispatch ran,
success or not" (the forwarder's own comment). They move off -1 if and only if
a SurfaceReply came back from the other process; a transport failure returns
before the write-back. I got this backwards first and the test said so.

Gates: ServerSpawnTest 5/5; unit suite 2345 with the same two pre-existing
environmental failures; G1 pull 0 added / 0 removed, .text 10822147 unchanged.

Not TCP. It was considered and dropped for now: TCP has no SCM_RIGHTS, so the
four segments cannot cross it, and a TCP control plane would have to refuse a
data plane by name until StreamLink exists (P6.5). Recorded here so the reason
is on file rather than re-derived.
2026-09-21 10:50:28 -04:00

MobileGL

C++ GNU LGPL 3.0 Development

A desktop OpenGL implementation

MobileGL is a free and open-source project that implements a desktop OpenGL API. The goal is to provide a complete desktop OpenGL implementation with a state management layer and multi-backend support.

Note

Status: In development. Parts of the codebase are incomplete. Current short-term target: OpenGL 4.2 (Core Profile).

Project positioning

MobileGL is an implementation of a desktop OpenGL library. It aims to provide:

  • Full OpenGL state management.
  • A front-end that exposes OpenGL functions.
  • Multiple independent backend implementations, where each backend targets a specific graphics API and remains fully isolated from others.

This project is intended as an implementation/translation layer.

Key components

The repository is organized into following top-level modules:

  1. MG_State — state tracking and management logic for Graphics APIs.
  2. MG_Impl — front-end implementations of Graphics APIs that interact with MG_State and MG_Backend.
  3. MG_Backend — per-backend translation layer that maps front-end Graphics APIs' semantics and state into concrete backend API calls (e.g. OpenGL ES, Vulkan).
  4. MG_Util and other utility modules.

Third-party components

MobileGL reuses several open-source projects:

Refer to each component's repository for exact license texts. Any bundled third-party code in this repository is included under the upstream project's license.

Compatibility & target

  • Short-term target: OpenGL 4.2 (Core Profile).
  • Current development focus:
    • Performance improvement
    • MG_State and MG_Impl for OpenGL 4.2 (Core Profile)
    • Direct (Vulkan) backend
    • Direct (OpenGL ES) backend

Build Instructions

We currently provide no releases and no precompiled binaries.
If you want to try the project right now, you’ll need to build it yourself:

  1. Clone the repository:

    git clone https://github.com/MobileGL-Dev/MobileGL.git
    
  2. Initialize and update all submodules recursively:

    git submodule update --init --recursive
    
  3. Follow glslang’s own documentation for its required initiation.

  4. Configure and build the project with CMake:

    cmake -B build
    cmake --build build
    

    or do it in a modern way:

    cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
    cmake --build build
    

    Alternatively, you can use platform-specific build commands as needed.

Build For macOS

On macOS, MobileGL can be built as a dylib that exposes the normal OpenGL/CGL/NSOpenGL entry points and routes them to the DirectVulkan backend. This is useful for running applications such as Minecraft through their stock GLFW/LWJGL OpenGL path while MobileGL is injected before context creation.

Prerequisites:

  • macOS with Clang and Ninja.
  • Vulkan loader and MoltenVK installed. With Homebrew, the MoltenVK ICD is commonly located at /opt/homebrew/etc/vulkan/icd.d/MoltenVK_icd.json.

Configure and build:

cmake -S . -B build-macos-magma \
  -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DMOBILEGL_BACKEND_TYPE=DirectVulkan \
  -DMOBILEGL_BUILD_TEST=OFF \
  -DMOBILEGL_BUILD_BENCHMARK=OFF

cmake --build build-macos-magma --target MobileGL -j8

The dylib will be generated at:

build-macos-magma/libMobileGL.dylib

To run Minecraft by MobileGL from a launcher like PrismLauncher, keep the stock LWJGL/GLFW natives and add a wrapper command to the instance settings:

env DYLD_INSERT_LIBRARIES=/absolute/path/to/MobileGL/build-macos-magma/libMobileGL.dylib MOBILEGL_BACKEND_TYPE=DirectVulkan VK_ICD_FILENAMES=/opt/homebrew/etc/vulkan/icd.d/MoltenVK_icd.json

Also make sure the JVM arguments include:

-XstartOnFirstThread

DYLD_INSERT_LIBRARIES must be active before GLFW creates its OpenGL context. After startup, the Minecraft F3 screen should report MobileGL and the Direct (Vulkan) backend if the injection worked.

Build Options

Option Description Default
MOBILEGL_BUILD_TEST Build MobileGL tests (requires Clang) ON
MOBILEGL_BUILD_BENCHMARK Build MobileGL benchmarks (requires Clang) ON
MOBILEGL_FORCE_RELEASE_OPT Enable O3 and LTO in Debug build ON
MOBILEGL_ENABLE_TRACY Enable Tracy profiler for performance analysis OFF

Notes:

  • The project requires C++23.
  • MG_Test and MG_Benchmark can only be built with Clang, not GCC. To enforce Clang, add -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ to your command.
  • On Android, tests and benchmarks are always disabled.

Environment Variables

MobileGL supports runtime configuration via environment variables.

Supported Keys

Variable Description Allowed Values Default
MOBILEGL_BACKEND_TYPE Select active backend implementation at startup. DirectGLES, DirectVulkan DirectGLES
MOBILEGL_DISABLE_TIMERQUERY Disable GPU timer-query exposure and use. 0, 1 0
MOBILEGL_ESPRYT_USE_ANGLE Load ANGLE EGL/GLES libraries. 0, 1 0
MOBILEGL_MAGMA_DISABLE_SUBGROUP Disable Vulkan shader subgroup support. 0, 1 0
MOBILEGL_ADVERTISE_FP64 Advertise GL_ARB_gpu_shader_fp64. GLSL double/dvec/dmat compile and run either way - they are narrowed to 32 bits - so this only changes whether an application is told it has 64-bit precision, which it does not. 0, 1 0
MOBILEGL_MAGMA_R11G11B10F_FALLBACK Use Magma's R11G11B10F format fallback. 0, 1 0
MOBILEGL_MAGMA_FRAMESINFLIGHT Set Magma frames in flight. Integer 1–64 3
MOBILEGL_ESPRYT_AVOID_SAMPLER_MIPMAP_MIN_FILTER Avoid sampler mipmap minification filters. 0, 1 0
MOBILEGL_COHERENT_AS_FLUSH Treat persistent GL_MAP_FLUSH_EXPLICIT_BIT maps as coherent (app-compat for engines like Flywheel that never flush them). 0, 1 0
MOBILEGL_ESPRYT_FORCE_DS_READBACK_EMULATION Always emulate depth/stencil glReadPixels/glGetTexImage by shader sampling on Espryt, instead of using the driver's own depth/stencil readback where it has one. 0, 1 0
VK_ICD_FILENAMES Select the Vulkan ICD used by the Vulkan loader. Path to an ICD JSON file Loader default

License

This project is distributed under GNU LGPL v3.0. See the LICENSE file in the repository for detailed information.

S
Description
No description provided
Readme
2.6 GiB
Languages
C++ 84.3%
C 6.1%
Python 5.7%
CMake 1.7%
Shell 1.4%
Other 0.5%