blob: 56b6a65e3469471d025d3122ee5b218d958b13ce [file] [log] [blame] [view]
Emmanuele Bassi87371e92017-02-09 14:30:13 +00001[![Build Status](https://travis-ci.org/anholt/libepoxy.svg?branch=master)](https://travis-ci.org/anholt/libepoxy)
Emmanuele Bassi176db4b2017-02-10 11:43:03 +00002[![Build status](https://ci.appveyor.com/api/projects/status/xv6y5jurt5v5ngjx/branch/master?svg=true)](https://ci.appveyor.com/project/ebassi/libepoxy/branch/master)
Emmanuele Bassi87371e92017-02-09 14:30:13 +00003
Eric Anholta909eb42013-09-19 09:50:49 -07004Epoxy is a library for handling OpenGL function pointer management for
5you.
6
Emmanuele Bassi7c902e32017-01-25 14:51:04 +00007It hides the complexity of `dlopen()`, `dlsym()`, `glXGetProcAddress()`,
8`eglGetProcAddress()`, etc. from the app developer, with very little
9knowledge needed on their part. They get to read GL specs and write
10code using undecorated function names like `glCompileShader()`.
Eric Anholta909eb42013-09-19 09:50:49 -070011
12Don't forget to check for your extensions or versions being present
13before you use them, just like before! We'll tell you what you forgot
14to check for instead of just segfaulting, though.
15
Eric Anholtedf5aed2013-12-09 22:36:23 -080016Features
17--------
Eric Anholta909eb42013-09-19 09:50:49 -070018
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000019 * Automatically initializes as new GL functions are used.
Emmanuele Bassic794dce2018-02-23 15:48:44 +000020 * GL 4.6 core and compatibility context support.
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000021 * 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 Anholta909eb42013-09-19 09:50:49 -070027
Emmanuele Bassi8dead452016-12-07 14:45:14 +000028Building
29--------
Eric Anholt6c0e0422013-12-11 16:21:47 -080030
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000031```sh
32mkdir _build && cd _build
33meson
34ninja
35sudo ninja install
36```
Eric Anholt6c0e0422013-12-11 16:21:47 -080037
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000038Dependencies for Debian:
Eric Anholt6c0e0422013-12-11 16:21:47 -080039
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000040 * meson
41 * libegl1-mesa-dev
Eric Anholt6c0e0422013-12-11 16:21:47 -080042
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000043Dependencies for macOS (using MacPorts):
Eric Anholt6c0e0422013-12-11 16:21:47 -080044
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000045 * pkgconfig
46 * meson
Eric Anholt6c0e0422013-12-11 16:21:47 -080047
48The test suite has additional dependencies depending on the platform.
49(X11, EGL, a running X Server).
50
Emmanuele Bassi8dead452016-12-07 14:45:14 +000051Switching your code to using epoxy
52----------------------------------
Yaron Cohen-Tal44d51f22015-09-03 23:17:39 +030053
Eric Anholta909eb42013-09-19 09:50:49 -070054It should be as easy as replacing:
55
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000056```cpp
57#include <GL/gl.h>
58#include <GL/glx.h>
59#include <GL/glext.h>
60```
Eric Anholta909eb42013-09-19 09:50:49 -070061
62with:
63
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000064```cpp
65#include <epoxy/gl.h>
66#include <epoxy/glx.h>
67```
Eric Anholta909eb42013-09-19 09:50:49 -070068
Eric Anholtedf5aed2013-12-09 22:36:23 -080069As long as epoxy's headers appear first, you should be ready to go.
Eric Anholta909eb42013-09-19 09:50:49 -070070Additionally, some new helpers become available, so you don't have to
71write them:
72
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000073`int epoxy_gl_version()` returns the GL version:
Eric Anholta909eb42013-09-19 09:50:49 -070074
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000075 * 12 for GL 1.2
76 * 20 for GL 2.0
77 * 44 for GL 4.4
Eric Anholta909eb42013-09-19 09:50:49 -070078
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000079`bool epoxy_has_gl_extension()` returns whether a GL extension is
80available (`GL_ARB_texture_buffer_object`, for example).
Eric Anholta909eb42013-09-19 09:50:49 -070081
82Note that this is not terribly fast, so keep it out of your hot paths,
83ok?
Eric Anholtedf5aed2013-12-09 22:36:23 -080084
Emmanuele Bassi8dead452016-12-07 14:45:14 +000085Why not use libGLEW?
Eric Anholtedf5aed2013-12-09 22:36:23 -080086--------------------
87
88GLEW has several issues:
89
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000090 * 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 Bassif1c038a2017-02-10 17:57:01 +000093 * Doesn't support OpenGL ES.
Emmanuele Bassi7c902e32017-01-25 14:51:04 +000094 * 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 Anholtedf5aed2013-12-09 22:36:23 -080099
100The motivation for this project came out of previous use of libGLEW in
101[piglit](http://piglit.freedesktop.org/). Other GL dispatch code
102generation projects had similar failures. Ideally, piglit wants to be
103able to build a single binary for a test that can run on whatever
104context or window system it chooses, not based on link time choices.
105
106We had to solve some of GLEW's problems for piglit and solving them
107meant replacing every single piece of GLEW, so we built
108piglit-dispatch from scratch. And since we wanted to reuse it in
109other GL-related projects, this is the result.
Eric Anholt3ae47262013-12-17 14:18:49 -0800110
Emmanuele Bassi7c902e32017-01-25 14:51:04 +0000111Known issues when running on Windows
112------------------------------------
Eric Anholt3ae47262013-12-17 14:18:49 -0800113
114The automatic per-context symbol resolution for win32 requires that
Emmanuele Bassi7c902e32017-01-25 14:51:04 +0000115epoxy knows when `wglMakeCurrent()` is called, because `wglGetProcAddress()`
116returns values depend on the context's device and pixel format. If
117`wglMakeCurrent()` is called from outside of epoxy (in a way that might
118change the device or pixel format), then epoxy needs to be notified of
119the change using the `epoxy_handle_external_wglMakeCurrent()` function.
Eric Anholt9bc909f2013-12-17 14:32:18 -0800120
Emmanuele Bassi7c902e32017-01-25 14:51:04 +0000121The win32 `wglMakeCurrent()` variants are slower than they should be,
Eric Anholt9bc909f2013-12-17 14:32:18 -0800122because they should be caching the resolved dispatch tables instead of
123resetting an entire thread-local dispatch table every time.