Emmanuele Bassi | 87371e9 | 2017-02-09 14:30:13 +0000 | [diff] [blame] | 1 | [](https://travis-ci.org/anholt/libepoxy) |
Emmanuele Bassi | 176db4b | 2017-02-10 11:43:03 +0000 | [diff] [blame] | 2 | [](https://ci.appveyor.com/project/ebassi/libepoxy/branch/master) |
Emmanuele Bassi | 87371e9 | 2017-02-09 14:30:13 +0000 | [diff] [blame] | 3 | |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 4 | Epoxy is a library for handling OpenGL function pointer management for |
| 5 | you. |
| 6 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 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()`. |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 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 | |
Eric Anholt | edf5aed | 2013-12-09 22:36:23 -0800 | [diff] [blame] | 16 | Features |
| 17 | -------- |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 18 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 19 | * Automatically initializes as new GL functions are used. |
Emmanuele Bassi | c794dce | 2018-02-23 15:48:44 +0000 | [diff] [blame] | 20 | * GL 4.6 core and compatibility context support. |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 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. |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 27 | |
Emmanuele Bassi | 8dead45 | 2016-12-07 14:45:14 +0000 | [diff] [blame] | 28 | Building |
| 29 | -------- |
Eric Anholt | 6c0e042 | 2013-12-11 16:21:47 -0800 | [diff] [blame] | 30 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 31 | ```sh |
| 32 | mkdir _build && cd _build |
| 33 | meson |
| 34 | ninja |
| 35 | sudo ninja install |
| 36 | ``` |
Eric Anholt | 6c0e042 | 2013-12-11 16:21:47 -0800 | [diff] [blame] | 37 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 38 | Dependencies for Debian: |
Eric Anholt | 6c0e042 | 2013-12-11 16:21:47 -0800 | [diff] [blame] | 39 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 40 | * meson |
| 41 | * libegl1-mesa-dev |
Eric Anholt | 6c0e042 | 2013-12-11 16:21:47 -0800 | [diff] [blame] | 42 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 43 | Dependencies for macOS (using MacPorts): |
Eric Anholt | 6c0e042 | 2013-12-11 16:21:47 -0800 | [diff] [blame] | 44 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 45 | * pkgconfig |
| 46 | * meson |
Eric Anholt | 6c0e042 | 2013-12-11 16:21:47 -0800 | [diff] [blame] | 47 | |
| 48 | The test suite has additional dependencies depending on the platform. |
| 49 | (X11, EGL, a running X Server). |
| 50 | |
Emmanuele Bassi | 8dead45 | 2016-12-07 14:45:14 +0000 | [diff] [blame] | 51 | Switching your code to using epoxy |
| 52 | ---------------------------------- |
Yaron Cohen-Tal | 44d51f2 | 2015-09-03 23:17:39 +0300 | [diff] [blame] | 53 | |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 54 | It should be as easy as replacing: |
| 55 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 56 | ```cpp |
| 57 | #include <GL/gl.h> |
| 58 | #include <GL/glx.h> |
| 59 | #include <GL/glext.h> |
| 60 | ``` |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 61 | |
| 62 | with: |
| 63 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 64 | ```cpp |
| 65 | #include <epoxy/gl.h> |
| 66 | #include <epoxy/glx.h> |
| 67 | ``` |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 68 | |
Eric Anholt | edf5aed | 2013-12-09 22:36:23 -0800 | [diff] [blame] | 69 | As long as epoxy's headers appear first, you should be ready to go. |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 70 | Additionally, some new helpers become available, so you don't have to |
| 71 | write them: |
| 72 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 73 | `int epoxy_gl_version()` returns the GL version: |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 74 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 75 | * 12 for GL 1.2 |
| 76 | * 20 for GL 2.0 |
| 77 | * 44 for GL 4.4 |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 78 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 79 | `bool epoxy_has_gl_extension()` returns whether a GL extension is |
| 80 | available (`GL_ARB_texture_buffer_object`, for example). |
Eric Anholt | a909eb4 | 2013-09-19 09:50:49 -0700 | [diff] [blame] | 81 | |
| 82 | Note that this is not terribly fast, so keep it out of your hot paths, |
| 83 | ok? |
Eric Anholt | edf5aed | 2013-12-09 22:36:23 -0800 | [diff] [blame] | 84 | |
Emmanuele Bassi | 8dead45 | 2016-12-07 14:45:14 +0000 | [diff] [blame] | 85 | Why not use libGLEW? |
Eric Anholt | edf5aed | 2013-12-09 22:36:23 -0800 | [diff] [blame] | 86 | -------------------- |
| 87 | |
| 88 | GLEW has several issues: |
| 89 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 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). |
Emmanuele Bassi | f1c038a | 2017-02-10 17:57:01 +0000 | [diff] [blame] | 93 | * Doesn't support OpenGL ES. |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 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. |
Eric Anholt | edf5aed | 2013-12-09 22:36:23 -0800 | [diff] [blame] | 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. |
Eric Anholt | 3ae4726 | 2013-12-17 14:18:49 -0800 | [diff] [blame] | 110 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 111 | Known issues when running on Windows |
| 112 | ------------------------------------ |
Eric Anholt | 3ae4726 | 2013-12-17 14:18:49 -0800 | [diff] [blame] | 113 | |
| 114 | The automatic per-context symbol resolution for win32 requires that |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 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. |
Eric Anholt | 9bc909f | 2013-12-17 14:32:18 -0800 | [diff] [blame] | 120 | |
Emmanuele Bassi | 7c902e3 | 2017-01-25 14:51:04 +0000 | [diff] [blame] | 121 | The win32 `wglMakeCurrent()` variants are slower than they should be, |
Eric Anholt | 9bc909f | 2013-12-17 14:32:18 -0800 | [diff] [blame] | 122 | because they should be caching the resolved dispatch tables instead of |
| 123 | resetting an entire thread-local dispatch table every time. |