README.md
1 [](https://travis-ci.org/anholt/libepoxy)
2 [](https://ci.appveyor.com/project/ebassi/libepoxy/branch/master)
3
4 Epoxy is a library for handling OpenGL function pointer management for
5 you.
6
7 It hides the complexity of `dlopen()`, `dlsym()`, `glXGetProcAddress()`,
8 `eglGetProcAddress()`, etc. from the app developer, with very little
9 knowledge needed on their part. They get to read GL specs and write
10 code using undecorated function names like `glCompileShader()`.
11
12 Don't forget to check for your extensions or versions being present
13 before you use them, just like before! We'll tell you what you forgot
14 to check for instead of just segfaulting, though.
15
16 Features
17 --------
18
19 * Automatically initializes as new GL functions are used.
20 * GL 4.6 core and compatibility context support.
21 * GLES 1/2/3 context support.
22 * Knows about function aliases so (e.g.) `glBufferData()` can be
23 used with `GL_ARB_vertex_buffer_object` implementations, along
24 with GL 1.5+ implementations.
25 * EGL, GLX, and WGL support.
26 * Can be mixed with non-epoxy GL usage.
27
28 Building
29 --------
30
31 ```sh
32 mkdir _build && cd _build
33 meson
34 ninja
35 sudo ninja install
36 ```
37
38 Dependencies for Debian:
39
40 * meson
41 * libegl1-mesa-dev
42
43 Dependencies for macOS (using MacPorts):
44
45 * pkgconfig
46 * meson
47
48 The test suite has additional dependencies depending on the platform.
49 (X11, EGL, a running X Server).
50
51 Switching your code to using epoxy
52 ----------------------------------
53
54 It should be as easy as replacing:
55
56 ```cpp
57 #include <GL/gl.h>
58 #include <GL/glx.h>
59 #include <GL/glext.h>
60 ```
61
62 with:
63
64 ```cpp
65 #include <epoxy/gl.h>
66 #include <epoxy/glx.h>
67 ```
68
69 As long as epoxy's headers appear first, you should be ready to go.
70 Additionally, some new helpers become available, so you don't have to
71 write them:
72
73 `int epoxy_gl_version()` returns the GL version:
74
75 * 12 for GL 1.2
76 * 20 for GL 2.0
77 * 44 for GL 4.4
78
79 `bool epoxy_has_gl_extension()` returns whether a GL extension is
80 available (`GL_ARB_texture_buffer_object`, for example).
81
82 Note that this is not terribly fast, so keep it out of your hot paths,
83 ok?
84
85 Why not use libGLEW?
86 --------------------
87
88 GLEW has several issues:
89
90 * Doesn't know about aliases of functions (There are 5 providers of
91 `glPointParameterfv()`, for example, and you don't want to have to
92 choose which one to call when they're all the same).
93 * Doesn't support OpenGL ES.
94 * Has a hard-to-maintain parser of extension specification text
95 instead of using the old .spec file or the new .xml.
96 * Has significant startup time overhead when `glewInit()`
97 autodetects the world.
98 * User-visible multithreading support choice for win32.
99
100 The motivation for this project came out of previous use of libGLEW in
101 [piglit](http://piglit.freedesktop.org/). Other GL dispatch code
102 generation projects had similar failures. Ideally, piglit wants to be
103 able to build a single binary for a test that can run on whatever
104 context or window system it chooses, not based on link time choices.
105
106 We had to solve some of GLEW's problems for piglit and solving them
107 meant replacing every single piece of GLEW, so we built
108 piglit-dispatch from scratch. And since we wanted to reuse it in
109 other GL-related projects, this is the result.
110
111 Known issues when running on Windows
112 ------------------------------------
113
114 The automatic per-context symbol resolution for win32 requires that
115 epoxy knows when `wglMakeCurrent()` is called, because `wglGetProcAddress()`
116 returns values depend on the context's device and pixel format. If
117 `wglMakeCurrent()` is called from outside of epoxy (in a way that might
118 change the device or pixel format), then epoxy needs to be notified of
119 the change using the `epoxy_handle_external_wglMakeCurrent()` function.
120
121 The win32 `wglMakeCurrent()` variants are slower than they should be,
122 because they should be caching the resolved dispatch tables instead of
123 resetting an entire thread-local dispatch table every time.
124