Man page - sdl_gl_getprocaddress(3)
Packages contains this manual
Manual
SDL_GL_GetProcAddress
NAMEHEADER FILE
SYNOPSIS
DESCRIPTION
FUNCTION PARAMETERS
RETURN VALUE
THREAD SAFETY
AVAILABILITY
SEE ALSO
NAME
SDL_GL_GetProcAddress - Get an OpenGL function by name.
HEADER FILE
Defined in SDL3/SDL_video.h
SYNOPSIS
#include "SDL3/SDL.h"
SDL_FunctionPointer SDL_GL_GetProcAddress(const char *proc);
DESCRIPTION
If the GL library is loaded at runtime with
SDL_GL_LoadLibrary (), then all GL functions must be retrieved this way. Usually this is used to retrieve function pointers to OpenGL extensions.
There are some quirks to looking up OpenGL functions that require some extra care from the application. If you code carefully, you can handle these quirks without any platform-specific code, though:
⢠On
Windows, function pointers are specific to the current GL
context;
this means you need to have created a GL context and made it
current
before calling
SDL_GL_GetProcAddress
(). If you
recreate your context or create a second context, you should
assume that
any existing function pointers arenât valid to use
with it. This is
(currently) a Windows-specific limitation, and in practice
lots of
drivers donât suffer this limitation, but it is still
the way the wgl API
is documented to work and you should expect crashes if you
donât respect
it. Store a copy of the function pointers that comes and
goes with
context lifespan.
⢠On X11,
function pointers returned by this function are valid for
any
context, and can even be looked up before a context is
created at all.
This means that, for at least some common OpenGL
implementations, if you
look up a function that doesnât exist, youâll
get a non-NULL result that
is _NOT_ safe to call. You must always make sure the
function is actually
available for a given GL context before calling it, by
checking for the
existence of the appropriate extension with
SDL_GL_ExtensionSupported
(), or verifying
that the version of OpenGL youâre using offers the
function as core
functionality.
⢠Some
OpenGL drivers, on all platforms,
will
return NULL if
a function
isnât supported, but you canât count on this
behavior. Check for
extensions you use, and if you get a NULL anyway, act as if
that
extension wasnât available. This is probably a bug in
the driver, but you
can code defensively for this scenario anyhow.
⢠Just
because youâre on Linux/Unix, donât assume
youâll be using X11.
Next-gen display servers are waiting to replace it, and may
or may not
make the same promises about function pointers.
⢠OpenGL
function pointers must be declared
APIENTRY
as in the
example
code. This will ensure the proper calling convention is
followed on
platforms where this matters (Win32) thereby avoiding stack
corruption.
FUNCTION PARAMETERS
|
proc |
the name of an OpenGL function. |
RETURN VALUE
( SDL_FunctionPointer ) Returns a pointer to the named OpenGL function. The returned pointer should be cast to the appropriate function signature.
THREAD SAFETY
This function should only be called on the main thread.
AVAILABILITY
This function is available since SDL 3.2.0.
SEE ALSO
⢠(3), SDL_GL_ExtensionSupported (3), ⢠(3), SDL_GL_LoadLibrary (3), ⢠(3), SDL_GL_UnloadLibrary (3)