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