// SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2026 Martino Ferrari #pragma once #include namespace plot::gl { /// Entry point resolver supplied by the caller, normally the *GetProcAddress /// of the API that owns the current context: `eglGetProcAddress`, /// `glXGetProcAddressARB` or `wglGetProcAddress`. using ProcLoader = void* (*)(const char*); /// Resolves every entry point of `PLOT_GL_FUNCS` (see api.hpp) into the global /// table declared there, so the rest of the library can call `gl*` directly. /// The above-baseline entries of `PLOT_GL_OPTIONAL_FUNCS` are resolved the same /// way but never fail the load: a driver without them leaves those pointers /// null, and callers reach them only behind `caps()`. /// /// Returns false when any required name cannot be found; entries that did /// resolve keep their pointers, so a failed load() never breaks a table that /// was already usable. `loader` is consulted first; when it is null, or returns /// null for a name, the fallback is `dlsym(RTLD_DEFAULT, name)` and then /// `dlopen("libGL.so.1")` + `dlsym`. The fallback makes the library usable /// without a caller-supplied resolver, but only a context-aware resolver is /// guaranteed to return pointers valid for the *current* context — pass one /// whenever a context is current. /// /// A load() attempt invalidates the caps() cache. The table is process-global /// and is not synchronised, so call from the thread that owns the current /// context. bool load(ProcLoader loader = nullptr) noexcept; /// True once a `load()` has resolved every required entry point of the global /// table. This is the gate superseding per-pointer null checks: while it is /// false the table may be only partially populated (see load()), so no `gl*` /// entry point may be called. The fallible handle constructors report /// `ErrorCode::Unsupported` until it becomes true. bool available() noexcept; } // namespace plot::gl