]> git.cworth.org Git - apitrace/blob - glproc_egl.cpp
First stab at tracing thread IDs.
[apitrace] / glproc_egl.cpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26
27 #include "glproc.hpp"
28
29
30 #if !defined(_WIN32)
31 #ifndef _GNU_SOURCE
32 #define _GNU_SOURCE // for dladdr
33 #endif
34 #include <dlfcn.h>
35 #endif
36
37
38 /*
39  * Handle to the true OpenGL library.
40  */
41 #if defined(_WIN32)
42 HINSTANCE __libGlHandle = NULL;
43 #else
44 void *__libGlHandle = NULL;
45 #endif
46
47
48
49 #if defined(_WIN32)
50
51 #error Unsupported
52
53 #elif defined(__APPLE__)
54
55 #error Unsupported
56
57 #else
58
59 /*
60  * Lookup a public EGL/GL/GLES symbol
61  *
62  * The spec states that eglGetProcAddress should only be used for non-core
63  * (extensions) entry-points.  Core entry-points should be taken directly from
64  * the API specific libraries.
65  *
66  * We cannot tell here which API a symbol is meant for here (as some are
67  * exported by many).  So this code assumes that the appropriate shared
68  * libraries have been loaded previously (either dlopened with RTLD_GLOBAL, or
69  * as part of the executable dependencies), and that their symbols available
70  * for quering via dlsym(RTLD_NEXT, ...).
71  */
72 void *
73 __getPublicProcAddress(const char *procName)
74 {
75     return dlsym(RTLD_NEXT, procName);
76 }
77
78 /*
79  * Lookup a private EGL/GL/GLES symbol
80  *
81  * Private symbols should always be available through eglGetProcAddress, and
82  * they are guaranteed to work with any context bound (regardless of the API).
83  *
84  * However, per issue#57, eglGetProcAddress returns garbage on some
85  * implementations, and the spec states that implementations may choose to also
86  * export extension functions publicly, so we always attempt dlsym before
87  * eglGetProcAddress to mitigate that.
88  */
89 void *
90 __getPrivateProcAddress(const char *procName)
91 {
92     void *proc;
93     proc = dlsym(RTLD_NEXT, procName);
94     if (!proc && procName[0] == 'g' && procName[1] == 'l')
95         proc = (void *) __eglGetProcAddress(procName);
96
97     return proc;
98 }
99
100 #endif