Epoxy is a library for handling OpenGL function pointer management for you.
It hides the complexity of
eglGetProcAddress(), etc. from the
app developer, with very little knowledge needed on their part. They
get to read GL specs and write code using undecorated function names
Don't forget to check for your extensions or versions being present before you use them, just like before! We'll tell you what you forgot to check for instead of just segfaulting, though.
- Automatically initializes as new OpenGL functions are used.
- Desktop OpenGL 4.4 core and compatibility context support.
- OpenGL ES 1/2/3 context support.
- Knows about function aliases so (e.g.)
glBufferData()can be used with
GL_ARB_vertex_buffer_objectimplementations, along with desktop OpenGL 1.5+ implementations.
- GLX, and WGL support.
- EGL support. EGL headers are included, so they're not necessary to build Epoxy with EGL support.
- Can be mixed with non-epoxy OpenGL usage.
CMake is now the recommended way to build epoxy. It supports building both shared and static libraries (by default only shared library is built). It also supports building and running tests, both for the static and the shared library.
Building with CMake should be as simple as running:
cd <my-build_dir> cmake -G <my-generator> <my-source-dir>
cmake -h see a list of possible generators). Then, to build the project,
depending on the type of generator you use, e.g. for Unix type
make, and for
MSVC open the solution in Visual studio and build the solution.
NOTE: To build for 64 bit with MSVC add
Win64to the generator name, e.g.
Visual studio 14 2015 Win64.
To rebuild the generated headers from the specs, add
To build also static libraries, add
To disable building shared libraries, add
To disable building tests, add
To link to the static Runtime Library with MSVC (rather than to the DLL), add
On Unix you can also use autotools to build. This type of build only supports building shared libraries. However it also supports building and running tests. To build with autotools, write:
./autogen.sh make make check [optional] sudo make install
Dependencies for debian:
Dependencies for OS X (macports):
The test suite has additional dependencies depending on the platform. (X11, EGL, a running X Server).
With MSVC you can also build directly with NMAKE. This type of build only supports building shared libraries. However it also supports building tests.
src\Makefile.vcto ensure that
PYTHONDIRis pointing to your Python installation, either a 32-bit or a 64-bit (x64) installation of Python 2 or 3 will do.
- Open an MSVC Command prompt and run
nmake Makefile.vc CFG=releaseor
nmake Makefile.vc CFG=debugin src\ for a release or debug build.
- Optionally, add src\ into your PATH and run the previous step in test. Run
the tests by running the built
- Assuming you want to install in
epoxy-vs12.pdb(if you've built a debug build) from
%INSTALL_DIR%\bin\. Create directories as needed.
- To clean the project, repeat steps 2 and 3, adding
cleanto the commands.
Switching your Code to Use Epoxy
- NOTE: If you use the static version of Epoxy, you must build your project with "EPOXY_STATIC_LIB" defined!
It should be as easy as replacing:
#include <GL/gl.h> #include <GL/glx.h> #include <GL/glext.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include <Windows.h> // for WGL
#include <epoxy/gl.h> #include <epoxy/glx.h> #include <epoxy/egl.h> #include <epoxy/wgl.h>
As long as epoxy's headers appear first, you should be ready to go. Additionally, some new helpers become available, so you don't have to write them:
int epoxy_gl_version() returns the GL version:
- 12 for GL 1.2
- 20 for GL 2.0
- 44 for GL 4.4
bool epoxy_has_gl_extension() returns whether a GL extension is
GL_ARB_texture_buffer_object, for example).
Note that this is not terribly fast, so keep it out of your hot paths, ok?
Using OpenGL ES / EGL
Building Epoxy with OpenGL ES / EGL support is now built-in. However, to
actually make use OpenGL ES and/or EGL on a computer, it's recommended (and in
some platforms necessary) to use an OpenGL ES / EGL emulator. I recommend using
which is available for Linux, OS X and Windows. Download it and run the
installer. In the installer, you don't have to check everything: Enough to check
PowerVR Tools -> PVRVFrame and
PowerVR SDK -> Native SDK. There's no need to
add anything from PowerVR SDK to the include directories to build or use Epoxy,
as it already includes all the necessary headers for using OpenGL ES / EGL.
There's also no need to link with anything from PowerVR SDK to build or use
Epoxy, as it loads the necessary libraries at run-time. However, when running
your app, if want to use EGL / OpenGL ES, you'll have to add the directory that
contains the right shared libraries (
EGL) to your
PATH environment variable. For instance, if you're on Windows, and used the
default locations when installing PowerVR SDK, then add
PATH (for Windows 64 bit) or
(for Windows 32 bit). For other platforms it would be something similar. Of
course, feel free to copy the shared libraries somewhere else.
Why not use GLEW?
GLEW has several issues:
- Doesn't know about aliases of functions (There are 5 providers of glPointParameterfv, for example, and you don't want to have to choose which one to call when they're all the same).
- Doesn't support Desktop OpenGL 3.2+ core contexts.
- Doesn't support OpenGL ES.
- Doesn't support EGL.
- Has a hard-to-maintain parser of extension specification text instead of using the old .spec file or the new .xml.
- Has significant startup time overhead when
glewInit()autodetects the world.
The motivation for this project came out of previous use of libGLEW in piglit. Other GL dispatch code generation projects had similar failures. Ideally, piglit wants to be able to build a single binary for a test that can run on whatever context or window system it chooses, not based on link time choices.
We had to solve some of GLEW's problems for piglit and solving them meant replacing every single piece of GLEW, so we built piglit-dispatch from scratch. And since we wanted to reuse it in other GL-related projects, this is the result.
The automatic per-context symbol resolution for win32 requires that
epoxy knows when
wglMakeCurrent() is called, because
wglGetProcAddress() return values depend on the context's device and
pixel format. If
wglMakeCurrent() is called from outside of
epoxy (in a way that might change the device or pixel format), then
epoxy needs to be notified of the change using the
wglMakeCurrent() variants are slower than they should be,
because they should be caching the resolved dispatch tables instead of
resetting an entire thread-local dispatch table every time.