Files
plotter/include/plot/gl/loader.hpp
T

29 lines
1.3 KiB
C++

#pragma once
#include <plot/gl/api.hpp>
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.
///
/// 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;
} // namespace plot::gl