Debian Codegraph @

doc/internal/gl.rst

raw
1 OpenGL Interface Implementation
2 --------------------------------
3
4 See `OpenGL Interface` for details on the publically-visible modules.
5
6 See `ctypes Wrapper Generation` for details on some of these modules are
7 generated.
8
9 ctypes linkage
10 ==============
11
12 Most functions link to libGL.so (Linux), opengl32.dll (Windows) or
13 OpenGL.framework (OS X). ``pyglet.gl.lib`` provides some helper types then
14 imports linker functions for the appropriate platform: one of
15 ``pyglet.gl.lib_agl``, ``pyglet.gl.lib_glx``, ``pyglet.gl.lib_wgl``.
16
17 On any platform, the following steps are taken to link each function during
18 import:
19
20 1. Look in the appropriate library (e.g. libGL.so, opengl32.dll,
21 etc.) using ``cdll`` or ``windll``.
22
23 2. If not found, call ``wglGetProcAddress`` or ``glxGetProcAddress`` to try to
24 resolve the function's address dynamically. On OS X, skip this step.
25
26 3. On Windows, this will fail if the context hasn't been created yet. Create
27 and return a proxy object ``WGLFunctionProxy`` which will try the same
28 resolution again when the object is ``__call__``'d.
29
30 The proxy object caches its result so that subsequent calls have only a
31 single extra function-call overhead.
32
33 4. If the function is still not found (either during import or proxy call),
34 the function is replaced with ``MissingFunction`` (defined in
35 ``pyglet.gl.lib``), which raises an exception. The exception message
36 details the name of the function, and optionally the name of the extension
37 or OpenGL version it requires.
38
39 We currently include all functions and enums from OpenGL 4.6 in separate
40 modules. ``gl.g`` exposes the core api and ``gl_compat.py`` exposes the
41 compatibility profile (no deprecation).
42
43 What extensions are included can be found in ``gengl.py``.
44
45 To access the linking function, import ``pyglet.gl.lib`` and use one of
46 ``link_AGL``, ``link_GLX``, ``link_WGL`` or ``link_GL``. This
47 is what the generated modules do.
48
49 Missing extensions
50 ==================
51
52 Missing extensions can be added to the ``extensions`` list in ``gengl.py``.