Debian Codegraph @

doc/internal/generated.rst

raw
1 ctypes Wrapper Generation
2 =========================
3
4 The following modules in pyglet are entirely (or mostly) generated from one or
5 more C header files:
6
7 * pyglet.gl.gl
8 * pyglet.gl.gl_compat
9 * pyglet.gl.agl
10 * pyglet.gl.glext_abi
11 * pyglet.gl.glext_nv
12 * pyglet.gl.glx
13 * pyglet.gl.glxext_abi
14 * pyglet.gl.glxext_nv
15 * pyglet.gl.wgl
16 * pyglet.gl.wglext_abi
17 * pyglet.gl.wglext_nv
18 * pyglet.window.xlib.xlib
19 * pyglet.window.xlib.xinerama
20
21 The wrapping framework is in ``tools/wraptypes``, and pyglet-specialised batch
22 scripts are ``tools/genwrappers.py`` (generates xlib wrappers) and
23 ``tools/gengl.py`` (generates gl wrappers).
24
25 Generating GL wrappers (new version)
26 ------------------------------------
27
28 The new ``gengl.py`` script only generates the following modules:
29
30 * ``gl.py``: OpenGL 4.6 core profile enums and functions. All deprecated
31 enums and functions are not included.
32 * ``gl_compat.py``: OpenGL 4.6 compatibility profile with all enums and
33 functions all the way back to OpenGL 1.0.
34
35 Running the script:
36
37 # Fetch latest gl.xml from Khronos github and generate new modules
38 python tools/gengl.py
39 python tools/gengl.py --source url
40
41 # Read the local gl.xml version
42 python tools/gengl.py --source local
43
44 The old ``gengl.py`` script also handled agl, wgl and glx.
45 The section below is still present for historical reasons
46 and the old script is still around in the tools directory.
47
48 Generating GL wrappers (old version)
49 ------------------------------------
50
51 This process needs to be followed when the wraptypes is updated, the header
52 files are updated (e.g., a new release of the operating system), or the GL
53 extensions are updated. Each file can only be generated a a specific
54 platform.
55
56 Before beginning, remove the file ``tools/.gengl.cache`` if it exists. This
57 merely caches header files so they don't need to be repeatedly downloaded (but
58 you'd prefer to use the most recent uncached copies if you're reading this,
59 presumably).
60
61 On Linux, generate ``pyglet.gl.gl``, ``pyglet.gl.glext_abi`` and
62 ``pyglet.gl.glext_nv`` (the complete user-visible GL
63 package)::
64
65 python tools/gengl.py gl glext_abi glext_nv
66
67 The header files for ``pyglet.gl.gl`` are located in
68 ``/usr/include/GL``. Ensure your Linux distribution has recent versions
69 of these files (unfortunately they do not seem to be accessible outside of a
70 distribution or OS).
71
72 The header files for ``pyglet.glext_abi`` and ``pyglet.glext_nv`` are
73 downloaded from http://www.opengl.org and http://developer.nvidia.com,
74 respectively.
75
76 On Linux still, generate ``pyglet.gl.glx``, ``pyglet.gl.glxext_abi`` and
77 ``pyglet.gl.glxext_nv``::
78
79 python tools/gengl.py glx glxext_abi glxext_nv
80
81 The header file for ``pyglet.gl.glx`` is in ``/usr/include/GL``, and
82 is expected to depend on X11 header files from ``/usr/include/X11``.
83 ``glext_abi`` and ``glext_nv`` header files are downloaded from the above
84 websites.
85
86 On OS X, generate ``pyglet.gl.agl``::
87
88 python tools/gengl.py agl
89
90 Watch a movie while you wait -- it uses virtually every header file on the
91 system. Expect to see one syntax error in ``PictUtils.h`` line 67, it is
92 unimportant.
93
94 On Windows XP, generate ``pyglet.gl.wgl``, ``pyglet.gl.wglext_abi`` and
95 ``pyglet.gl.wglext_nv``::
96
97 python tools/gengl.py wgl wglext_abi wglext_nv
98
99 You do not need to have a development environment installed on Windows.
100 ``pyglet.gl.wgl`` is generated from ``tools/wgl.h``, which is a hand-coded
101 header file containing the prototypes and constants for WGL and its
102 dependencies. In a real development environment you would find these mostly
103 in ``WinGDI.h``, but wraptypes is not quite sophisticated enough to parse
104 Windows system headers (see below for what needs implementing). It is
105 extremely unlikely this header will ever need to change (excepting a bug fix).
106
107 The headers for ``pyglet.gl.wglext_abi`` and ``pyglet.gl.wglext_nv`` are
108 downloaded from the same websites as for GL and GLX.
109
110 Generated GL wrappers
111 ---------------------
112
113 Each generated file contains a pair of markers ``# BEGIN GENERATED CONTENT``
114 and ``# END GENERATED CONTENT`` which are searched for when replacing the
115 file. If either marker is missing or corrupt, the file will not be modified.
116 This allows for custom content around the generated content. Only ``glx.py``
117 makes use of this, to include some additional enumerators that are not
118 generated by default.
119
120 If a generating process is interrupted (either you get sick of it, or it
121 crashes), it will leave a partially-complete file written, which will not
122 include both markers. It is up to you to restore the file or otherwise
123 reinsert the markers.
124
125 Generating Xlib wrappers
126 ------------------------
127
128 On Linux with the Xinerama extension installed (doesn't have to be in use,
129 just available), run::
130
131 python tools/genwrappers.py
132
133 This generates ``pyglet.window.xlib.xlib`` and
134 ``pyglet.window.xlib.xinerama``.
135
136 Note that this process, as well as the generated modules, depend on
137 ``pyglet.gl.glx``. So, you should always run this `after` the above GL
138 generation.
139
140