|
SBgl 0.1.0
A graphics framework in C99
|
SBgl utilizes a strict Platform Abstraction Layer (HAL) to ensure that the core engine and user code remain completely isolated from OS-specific dependencies. This prevents heavy, namespace-polluting headers like <windows.h> or <X11/Xlib.h> from leaking into the user's application.
sbgl_platform.h)The core interacts with the operating system through a set of explicitly defined functions in src/core/sbgl_platform.h. The interface mandates that all OS-specific state be kept opaque from the rest of the engine.
sbgl_ContextThe public sbgl_Context structure serves as a thin shell. Its inner member points to a private sbgl_InternalContext, which encapsulates the platform layer state:
sbgl_Context*.sbgl_InternalContext, which manages engine-wide state (Arena, clear colors, etc.).sbgl_InternalContext holds a pointer to an opaque sbgl_Window, which is defined only within the specific platform's source files (e.g., window_wayland.c).This hierarchy allows the engine to pass a generic sbgl_Context to the public API while the platform layer internally retrieves the specific handles it needs to communicate with the OS.
The most critical functions in the HAL manage the lifecycle and event loop of the native window:
The sbgl_WindowShouldClose function provides a mechanism for the engine to report that the operating system or the user has requested the window to be closed. It does not automatically terminate the application; instead, it sets a flag that the application should poll in its main loop.
The internal shouldClose flag is set by the platform layer in response to specific OS events:
WindowProc intercepts a WM_CLOSE message. This typically occurs when the "X" button is clicked or Alt+F4 is pressed.xdg_toplevel_listener's close event. This is sent by the compositor when it requests the surface to be destroyed.XEvent of type ClientMessage is received containing the WM_DELETE_WINDOW atom.Once sbgl_WindowShouldClose returns true, it is the application's responsibility to:
sbgl_Shutdown(ctx) to perform a graceful cleanup of all native handles and memory arenas.Each platform backend implements its own concrete version of struct sbgl_Window to bridge the gap between SBgl's Data-Oriented arena allocator and the OS's native requirements.
The Win32 implementation registers a WNDCLASSW and creates an HWND. It utilizes GWLP_USERDATA to associate the sbgl_Window state with the native window procedure.
The Wayland implementation is asynchronous and uses the XDG-Shell protocol. It manages the connection to the wl_display and handles surface state transitions via listeners.
The X11 implementation uses XCreateSimpleWindow and interacts with the Window Manager via Atoms to handle graceful termination.
For detailed technical specifications of the underlying platform protocols and APIs, refer to the following official documentation: