Module Name: xsrc Committed By: mrg Date: Tue Jul 9 21:55:21 UTC 2019
Modified Files: xsrc/external/mit/libepoxy/dist/src: dispatch_common.c dispatch_common.h Log Message: merge libepoxy 1.4.3. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 \ xsrc/external/mit/libepoxy/dist/src/dispatch_common.c cvs rdiff -u -r1.4 -r1.5 \ xsrc/external/mit/libepoxy/dist/src/dispatch_common.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: xsrc/external/mit/libepoxy/dist/src/dispatch_common.c diff -u xsrc/external/mit/libepoxy/dist/src/dispatch_common.c:1.3 xsrc/external/mit/libepoxy/dist/src/dispatch_common.c:1.4 --- xsrc/external/mit/libepoxy/dist/src/dispatch_common.c:1.3 Fri Aug 19 11:56:56 2016 +++ xsrc/external/mit/libepoxy/dist/src/dispatch_common.c Tue Jul 9 21:55:21 2019 @@ -22,9 +22,80 @@ */ /** + * \mainpage Epoxy + * + * \section intro_sec Introduction + * + * Epoxy is a library for handling OpenGL function pointer management for + * you. + * + * It hides the complexity of `dlopen()`, `dlsym()`, `glXGetProcAddress()`, + * `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 like `glCompileShader()`. + * + * 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. + * + * \section features_sec Features + * + * - Automatically initializes as new GL functions are used. + * - GL 4.4 core and compatibility context support. + * - GLES 1/2/3 context support. + * - Knows about function aliases so (e.g.) `glBufferData()` can be + * used with `GL_ARB_vertex_buffer_object` implementations, along + * with GL 1.5+ implementations. + * - EGL, GLX, and WGL support. + * - Can be mixed with non-epoxy GL usage. + * + * \section using_sec Using Epoxy + * + * Using Epoxy should be as easy as replacing: + * + * ```cpp + * #include <GL/gl.h> + * #include <GL/glx.h> + * #include <GL/glext.h> + * ``` + * + * with: + * + * ```cpp + * #include <epoxy/gl.h> + * #include <epoxy/glx.h> + * ``` + * + * \subsection using_include_sec Headers + * + * Epoxy comes with the following public headers: + * + * - `epoxy/gl.h` - For GL API + * - `epoxy/egl.h` - For EGL API + * - `epoxy/glx.h` - For GLX API + * - `epoxy/wgl.h` - For WGL API + * + * \section links_sec Additional links + * + * The latest version of the Epoxy code is available on [GitHub](https://github.com/anholt/libepoxy). + * + * For bug reports and enhancements, please use the [Issues](https://github.com/anholt/libepoxy/issues) + * link. + * + * The scope of this API reference does not include the documentation for + * OpenGL and OpenGL ES. For more information on those programming interfaces + * please visit: + * + * - [Khronos](https://www.khronos.org/) + * - [OpenGL page on Khronos.org](https://www.khronos.org/opengl/) + * - [OpenGL ES page on Khronos.org](https://www.khronos.org/opengles/) + * - [docs.GL](http://docs.gl/) + */ + +/** * @file dispatch_common.c * - * Implements common code shared by the generated GL/EGL/GLX dispatch code. + * @brief Implements common code shared by the generated GL/EGL/GLX dispatch code. * * A collection of some important specs on getting GL function pointers. * @@ -118,6 +189,10 @@ #define EGL_LIB "libEGL.so" #define GLES1_LIB "libGLESv1_CM.so" #define GLES2_LIB "libGLESv2.so" +#elif defined _WIN32 +#define EGL_LIB "libEGL.dll" +#define GLES1_LIB "libGLES_CM.dll" +#define GLES2_LIB "libGLESv2.dll" #else #define EGL_LIB "libEGL.so.1" #define GLES1_LIB "libGLESv1_CM.so.1" @@ -149,32 +224,32 @@ struct api { #ifndef _WIN32 - /** + /* * Locking for making sure we don't double-dlopen(). */ pthread_mutex_t mutex; #endif - /** dlopen() return value for libGL.so.1. */ + /* dlopen() return value for libGL.so.1. */ void *glx_handle; - /** + /* * dlopen() return value for OS X's GL library. * * On linux, glx_handle is used instead. */ void *gl_handle; - /** dlopen() return value for libEGL.so.1 */ + /* dlopen() return value for libEGL.so.1 */ void *egl_handle; - /** dlopen() return value for libGLESv1_CM.so.1 */ + /* dlopen() return value for libGLESv1_CM.so.1 */ void *gles1_handle; - /** dlopen() return value for libGLESv2.so.2 */ + /* dlopen() return value for libGLESv2.so.2 */ void *gles2_handle; - /** + /* * This value gets incremented when any thread is in * glBegin()/glEnd() called through epoxy. * @@ -272,7 +347,12 @@ do_dlsym(void **handle, const char *lib_ return result; } -PUBLIC bool +/** + * @brief Checks whether we're using OpenGL or OpenGL ES + * + * @return `true` if we're using OpenGL + */ +bool epoxy_is_desktop_gl(void) { const char *es_prefix = "OpenGL ES"; @@ -336,7 +416,22 @@ epoxy_internal_gl_version(int error_vers return 10 * major + minor; } -PUBLIC int +/** + * @brief Returns the version of OpenGL we are using + * + * The version is encoded as: + * + * ``` + * + * version = major * 10 + minor + * + * ``` + * + * So it can be easily used for version comparisons. + * + * @return The encoded version of OpenGL we are using + */ +int epoxy_gl_version(void) { return epoxy_internal_gl_version(0); @@ -355,7 +450,15 @@ bool epoxy_extension_in_string(const char *extension_list, const char *ext) { const char *ptr = extension_list; - int len = strlen(ext); + int len; + + if (!ext) + return false; + + len = strlen(ext); + + if (extension_list == NULL || *extension_list == '\0') + return false; /* Make sure that don't just find an extension with our name as a prefix. */ while (true) { @@ -387,6 +490,8 @@ epoxy_internal_has_gl_extension(const ch for (i = 0; i < num_extensions; i++) { const char *gl_ext = (const char *)glGetStringi(GL_EXTENSIONS, i); + if (!gl_ext) + return false; if (strcmp(ext, gl_ext) == 0) return true; } @@ -452,14 +557,17 @@ epoxy_current_context_is_glx(void) } /** - * Returns true if the given GL extension is supported in the current context. + * @brief Returns true if the given GL extension is supported in the current context. + * + * @param ext The name of the GL extension + * @return `true` if the extension is available * - * Note that this function can't be called from within glBegin()/glEnd(). + * @note that this function can't be called from within `glBegin()` and `glEnd()`. * - * \sa epoxy_has_egl_extension() - * \sa epoxy_has_glx_extension() + * @see epoxy_has_egl_extension() + * @see epoxy_has_glx_extension() */ -PUBLIC bool +bool epoxy_has_gl_extension(const char *ext) { return epoxy_internal_has_gl_extension(ext, false); @@ -475,15 +583,27 @@ epoxy_conservative_has_gl_extension(cons } void * +epoxy_conservative_egl_dlsym(const char *name, bool exit_if_fails) +{ + return do_dlsym(&api.egl_handle, EGL_LIB, name, exit_if_fails); +} + +void * epoxy_egl_dlsym(const char *name) { - return do_dlsym(&api.egl_handle, EGL_LIB, name, true); + return epoxy_conservative_egl_dlsym(name, true); +} + +void * +epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails) +{ + return do_dlsym(&api.glx_handle, GLX_LIB, name, exit_if_fails); } void * epoxy_glx_dlsym(const char *name) { - return do_dlsym(&api.glx_handle, GLX_LIB, name, true); + return epoxy_conservative_glx_dlsym(name, true); } void * @@ -576,31 +696,15 @@ epoxy_get_core_proc_address(const char * static EGLenum epoxy_egl_get_current_gl_context_api(void) { - EGLenum save_api = eglQueryAPI(); - EGLContext ctx; - - if (eglBindAPI(EGL_OPENGL_API)) { - ctx = eglGetCurrentContext(); - if (ctx) { - eglBindAPI(save_api); - return EGL_OPENGL_API; - } - } else { - (void)eglGetError(); - } + EGLint curapi; - if (eglBindAPI(EGL_OPENGL_ES_API)) { - ctx = eglGetCurrentContext(); - eglBindAPI(save_api); - if (ctx) { - eglBindAPI(save_api); - return EGL_OPENGL_ES_API; - } - } else { - (void)eglGetError(); + if (eglQueryContext(eglGetCurrentDisplay(), eglGetCurrentContext(), + EGL_CONTEXT_CLIENT_TYPE, &curapi) == EGL_FALSE) { + (void)eglGetError(); + return EGL_NONE; } - return EGL_NONE; + return (EGLenum) curapi; } #endif /* PLATFORM_HAS_EGL */ @@ -658,28 +762,32 @@ epoxy_get_bootstrap_proc_address(const c void * epoxy_get_proc_address(const char *name) { -#ifdef _WIN32 +#if PLATFORM_HAS_EGL + GLenum egl_api = EGL_NONE; + + if (!epoxy_current_context_is_glx()) + egl_api = epoxy_egl_get_current_gl_context_api(); + + switch (egl_api) { + case EGL_OPENGL_API: + case EGL_OPENGL_ES_API: + return eglGetProcAddress(name); + case EGL_NONE: + break; + } +#endif + +#if defined(_WIN32) return wglGetProcAddress(name); #elif defined(__APPLE__) return epoxy_gl_dlsym(name); -#else - if (epoxy_current_context_is_glx()) { +#elif PLATFORM_HAS_GLX + if (epoxy_current_context_is_glx()) return glXGetProcAddressARB((const GLubyte *)name); - } else { -#if PLATFORM_HAS_EGL - GLenum egl_api = epoxy_egl_get_current_gl_context_api(); - - switch (egl_api) { - case EGL_OPENGL_API: - case EGL_OPENGL_ES_API: - return eglGetProcAddress(name); - case EGL_NONE: - break; - } -#endif - } errx(1, "Couldn't find current GLX or EGL context.\n"); #endif + + return NULL; } WRAPPER_VISIBILITY (void) @@ -710,5 +818,5 @@ WRAPPER(epoxy_glEnd)(void) #endif } -PUBLIC PFNGLBEGINPROC epoxy_glBegin = epoxy_glBegin_wrapped; -PUBLIC PFNGLENDPROC epoxy_glEnd = epoxy_glEnd_wrapped; +PFNGLBEGINPROC epoxy_glBegin = epoxy_glBegin_wrapped; +PFNGLENDPROC epoxy_glEnd = epoxy_glEnd_wrapped; Index: xsrc/external/mit/libepoxy/dist/src/dispatch_common.h diff -u xsrc/external/mit/libepoxy/dist/src/dispatch_common.h:1.4 xsrc/external/mit/libepoxy/dist/src/dispatch_common.h:1.5 --- xsrc/external/mit/libepoxy/dist/src/dispatch_common.h:1.4 Thu Apr 18 10:09:37 2019 +++ xsrc/external/mit/libepoxy/dist/src/dispatch_common.h Tue Jul 9 21:55:21 2019 @@ -21,24 +21,22 @@ * IN THE SOFTWARE. */ -#include <stdbool.h> +#include "config.h" #ifdef _WIN32 -#define PLATFORM_HAS_EGL 0 -#define PLATFORM_HAS_GLX 0 +#define PLATFORM_HAS_EGL ENABLE_EGL +#define PLATFORM_HAS_GLX ENABLE_GLX #define PLATFORM_HAS_WGL 1 -#define EPOXY_IMPORTEXPORT __declspec(dllexport) #elif defined(__APPLE__) -#define PLATFORM_HAS_EGL 0 -#define PLATFORM_HAS_GLX 0 +#define PLATFORM_HAS_EGL ENABLE_EGL +#define PLATFORM_HAS_GLX ENABLE_GLX #define PLATFORM_HAS_WGL 0 -#define EPOXY_IMPORTEXPORT #elif defined(ANDROID) -#define PLATFORM_HAS_EGL 1 +#define PLATFORM_HAS_EGL ENABLE_EGL #define PLATFORM_HAS_GLX 0 #define PLATFORM_HAS_WGL 0 -#define EPOXY_IMPORTEXPORT #else +# if 0 #if defined(__NetBSD__) && !defined(PLATFORM_HAS_EGL) # if defined(__amd64__) || defined(__i386__) || defined(__aarch64__) // XXX evbarm32 # define PLATFORM_HAS_EGL 1 @@ -49,8 +47,11 @@ #define PLATFORM_HAS_EGL 1 #endif #define PLATFORM_HAS_GLX 1 +# else +#define PLATFORM_HAS_EGL ENABLE_EGL +#define PLATFORM_HAS_GLX ENABLE_GLX +# endif #define PLATFORM_HAS_WGL 0 -#define EPOXY_IMPORTEXPORT #endif #include "epoxy/gl.h" @@ -64,20 +65,15 @@ #include "epoxy/wgl.h" #endif -#ifndef PUBLIC -# ifdef _WIN32 -# define PUBLIC __declspec(dllexport) -# elif (defined(__GNUC__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) -# define PUBLIC __attribute__((visibility("default"))) -# else -# define PUBLIC -# endif -#endif - #if defined(__GNUC__) #define PACKED __attribute__((__packed__)) +#define ENDPACKED +#elif defined (_MSC_VER) +#define PACKED __pragma(pack(push,1)) +#define ENDPACKED __pragma(pack(pop)) #else #define PACKED +#define ENDPACKED #endif /* On win32, we're going to need to keep a per-thread dispatch table, @@ -179,6 +175,8 @@ bool epoxy_conservative_has_glx_extensio int epoxy_conservative_egl_version(void); bool epoxy_conservative_has_egl_extension(const char *name); bool epoxy_conservative_has_wgl_extension(const char *name); +void *epoxy_conservative_egl_dlsym(const char *name, bool exit_if_fails); +void *epoxy_conservative_glx_dlsym(const char *name, bool exit_if_fails); bool epoxy_extension_in_string(const char *extension_list, const char *ext);