summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Fonseca <jose.r.fonseca@gmail.com>2011-12-03 10:04:14 +0000
committerJosé Fonseca <jose.r.fonseca@gmail.com>2011-12-03 10:04:14 +0000
commitd31700077ae75f450b12ad7d9276c08cbad57d1b (patch)
tree5e397a219882964f130673997d2c7d8f77e36e50
parent33783a898e5450ae5bbe21a2b9c9db159f53d2ab (diff)
parenta665ba7cf6de6e071538f64104b122e6bbb1a6b1 (diff)
Merge branch 'glproc-cleanup'
-rwxr-xr-xCMakeLists.txt16
-rw-r--r--cgltrace.py61
-rw-r--r--dispatch.py11
-rw-r--r--egltrace.py20
-rw-r--r--glproc.py42
-rw-r--r--glproc_egl.cpp100
-rw-r--r--glproc_gl.cpp232
-rw-r--r--glstate.cpp4
-rw-r--r--glws_egl_xlib.cpp25
-rw-r--r--glws_glx.cpp3
-rw-r--r--glws_wgl.cpp6
-rw-r--r--glxtrace.py54
-rw-r--r--wgltrace.py25
13 files changed, 385 insertions, 214 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 29df0cb..710c626 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,15 +40,14 @@ if (ENABLE_GUI)
find_package (QJSON ${REQUIRE_GUI})
endif ()
+include_directories (${OPENGL_INCLUDE_DIR})
+
if (WIN32)
find_package (DirectX)
elseif (APPLE)
else ()
find_package (X11 REQUIRED)
- set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
- set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
-
include_directories (${X11_INCLUDE_DIR})
if (ENABLE_EGL)
@@ -378,6 +377,7 @@ if (WIN32)
add_library (wgltrace MODULE specs/opengl32.def
wgltrace.cpp
glcaps.cpp
+ glproc_gl.cpp
${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
)
set_target_properties (wgltrace PROPERTIES
@@ -399,6 +399,7 @@ elseif (APPLE)
add_library (cgltrace SHARED
cgltrace.cpp
glcaps.cpp
+ glproc_gl.cpp
${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
)
@@ -426,6 +427,7 @@ else ()
${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
glxtrace.cpp
glcaps.cpp
+ glproc_gl.cpp
)
set_target_properties (glxtrace PROPERTIES
@@ -456,6 +458,7 @@ if (EGL_FOUND)
${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
egltrace.cpp
glcaps.cpp
+ glproc_egl.cpp
)
set_property (
@@ -517,6 +520,7 @@ set (retrace_sources
add_executable (glretrace
${retrace_sources}
${glws_os}
+ glproc_gl.cpp
)
set_property (
@@ -530,7 +534,6 @@ target_link_libraries (glretrace
)
if (WIN32)
- target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
elseif (APPLE)
target_link_libraries (glretrace
"-framework Cocoa"
@@ -538,7 +541,7 @@ elseif (APPLE)
${OPENGL_gl_LIBRARY} # CGL*
)
else ()
- target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${X11_X11_LIB})
+ target_link_libraries (glretrace ${X11_X11_LIB})
endif ()
install (TARGETS glretrace RUNTIME DESTINATION bin)
@@ -547,6 +550,7 @@ if (EGL_FOUND AND NOT WIN32 AND NOT APPLE)
add_executable (eglretrace
${retrace_sources}
glws_egl_xlib.cpp
+ glproc_egl.cpp
)
set_property (
@@ -561,8 +565,6 @@ if (EGL_FOUND AND NOT WIN32 AND NOT APPLE)
)
target_link_libraries (eglretrace
- ${EGL_LIBRARIES}
- ${OPENGL_gl_LIBRARY}
${X11_X11_LIB}
)
diff --git a/cgltrace.py b/cgltrace.py
index b6a6fd0..1b31419 100644
--- a/cgltrace.py
+++ b/cgltrace.py
@@ -46,11 +46,6 @@ if __name__ == '__main__':
print '#include <string.h>'
print '#include <unistd.h>'
print
- print '#ifndef _GNU_SOURCE'
- print '#define _GNU_SOURCE // for dladdr'
- print '#endif'
- print '#include <dlfcn.h>'
- print
print '#include "trace_writer.hpp"'
print
print '// To validate our prototypes'
@@ -68,62 +63,6 @@ if __name__ == '__main__':
print r'''
-
-/*
- * Path to the true OpenGL framework
- */
-static const char *libgl_filename = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
-
-
-/*
- * Handle to the true OpenGL framework.
- */
-static void *libgl_handle = NULL;
-
-
-/*
- * Lookup a libGL symbol
- */
-void * __libgl_sym(const char *symbol)
-{
- void *result;
-
- if (!libgl_handle) {
- /*
- * Unfortunately we can't just dlopen the true dynamic library because
- * DYLD_LIBRARY_PATH/DYLD_FRAMEWORK_PATH take precedence, even for
- * absolute paths. So we create a temporary symlink, and dlopen that
- * instead.
- */
-
- char temp_filename[] = "/tmp/tmp.XXXXXX";
-
- if (mktemp(temp_filename) != NULL) {
- if (symlink(libgl_filename, temp_filename) == 0) {
- libgl_handle = dlopen(temp_filename, RTLD_LOCAL | RTLD_NOW | RTLD_FIRST);
- remove(temp_filename);
- }
- }
-
- if (!libgl_handle) {
- os::log("apitrace: error: couldn't load %s\n", libgl_filename);
- os::abort();
- return NULL;
- }
- }
-
- result = dlsym(libgl_handle, symbol);
-
- if (result == dlsym(RTLD_SELF, symbol)) {
- os::log("apitrace: error: symbol lookup recursion\n");
- os::abort();
- return NULL;
- }
-
- return result;
-}
-
-
PUBLIC
void * gll_noop = 0;
diff --git a/dispatch.py b/dispatch.py
index a2f23e9..adb16b7 100644
--- a/dispatch.py
+++ b/dispatch.py
@@ -61,17 +61,11 @@ class Dispatcher:
# functions
print '#ifdef RETRACE'
for function in api.functions:
- if self.is_public_function(function):
- print '#define __%s %s' % (function.name, function.name)
- else:
- print '#define %s __%s' % (function.name, function.name)
+ print '#define %s __%s' % (function.name, function.name)
print '#endif /* RETRACE */'
print
def dispatch_function(self, function):
- if self.is_public_function(function):
- print '#ifndef RETRACE'
- print
ptype = function_pointer_type(function)
pvalue = function_pointer_value(function)
print 'typedef ' + function.prototype('* %s' % ptype) + ';'
@@ -87,9 +81,6 @@ class Dispatcher:
print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args]))
print '}'
print
- if self.is_public_function(function):
- print '#endif /* !RETRACE */'
- print
def is_public_function(self, function):
return True
diff --git a/egltrace.py b/egltrace.py
index 1148924..de90799 100644
--- a/egltrace.py
+++ b/egltrace.py
@@ -110,23 +110,3 @@ if __name__ == '__main__':
print ' return procPtr;'
print '}'
print
- print r'''
-
-/*
- * Lookup a EGL or GLES symbol
- */
-void * __libegl_sym(const char *symbol)
-{
- void *proc;
-
- /* Always try dlsym before eglGetProcAddress as spec 3.10 says
- * implementation may choose to also export extension functions
- * publicly.
- */
- proc = dlsym(RTLD_NEXT, symbol);
- if (!proc && symbol[0] == 'g' && symbol[1] == 'l')
- proc = (void *) __eglGetProcAddress(symbol);
-
- return proc;
-}
-'''
diff --git a/glproc.py b/glproc.py
index 67079e4..26df9df 100644
--- a/glproc.py
+++ b/glproc.py
@@ -492,38 +492,16 @@ public_symbols.update([
class GlDispatcher(Dispatcher):
def header(self):
- print '#ifdef RETRACE'
- print '# if defined(TRACE_EGL)'
- print '# define __getPrivateProcAddress(name) eglGetProcAddress(name)'
- print '# elif defined(_WIN32)'
- print '# define __getPrivateProcAddress(name) wglGetProcAddress(name)'
- print '# elif defined(__APPLE__)'
- print '# include <dlfcn.h>'
- print '# define __getPrivateProcAddress(name) dlsym(RTLD_DEFAULT, name)'
- print '# else'
- print '# define __getPrivateProcAddress(name) glXGetProcAddressARB((const GLubyte *)(name))'
- print '# endif'
- print '#else /* !RETRACE */'
- print '# if defined(TRACE_EGL)'
- print '# define __getPublicProcAddress(name) __libegl_sym(name)'
- print '# define __getPrivateProcAddress(name) __libegl_sym(name)'
- print ' void * __libegl_sym(const char *symbol);'
- print '# elif defined(_WIN32)'
- print ' PROC __getPublicProcAddress(LPCSTR lpProcName);'
- print '# define __getPrivateProcAddress(name) __wglGetProcAddress(name)'
- print ' static inline PROC __stdcall __wglGetProcAddress(const char * lpszProc);'
- print '# else'
- print '# define __getPublicProcAddress(name) __libgl_sym(name)'
- print ' void * __libgl_sym(const char *symbol);'
- print '# ifdef __APPLE__'
- print '# define __getPrivateProcAddress(name) __getPublicProcAddress(name)'
- print '# else'
- print '# define __getPrivateProcAddress(name) __glXGetProcAddressARB((const GLubyte *)(name))'
- print ' static inline __GLXextFuncPtr __glXGetProcAddressARB(const GLubyte * procName);'
- print '# endif'
- print '# endif'
- print '#endif /* !RETRACE */'
- print
+ print '''
+#if defined(_WIN32)
+extern HINSTANCE __libGlHandle;
+#else
+extern void * __libGlHandle;
+#endif
+
+void * __getPublicProcAddress(const char *procName);
+void * __getPrivateProcAddress(const char *procName);
+'''
def is_public_function(self, function):
return function.name in public_symbols or function.name.startswith('CGL')
diff --git a/glproc_egl.cpp b/glproc_egl.cpp
new file mode 100644
index 0000000..4ceb2ff
--- /dev/null
+++ b/glproc_egl.cpp
@@ -0,0 +1,100 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "glproc.hpp"
+
+
+#if !defined(_WIN32)
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // for dladdr
+#endif
+#include <dlfcn.h>
+#endif
+
+
+/*
+ * Handle to the true OpenGL library.
+ */
+#if defined(_WIN32)
+HINSTANCE __libGlHandle = NULL;
+#else
+void *__libGlHandle = NULL;
+#endif
+
+
+
+#if defined(_WIN32)
+
+#error Unsupported
+
+#elif defined(__APPLE__)
+
+#error Unsupported
+
+#else
+
+/*
+ * Lookup a public EGL/GL/GLES symbol
+ *
+ * The spec states that eglGetProcAddress should only be used for non-core
+ * (extensions) entry-points. Core entry-points should be taken directly from
+ * the API specific libraries.
+ *
+ * We cannot tell here which API a symbol is meant for here (as some are
+ * exported by many). So this code assumes that the appropriate shared
+ * libraries have been loaded previously (either dlopened with RTLD_GLOBAL, or
+ * as part of the executable dependencies), and that their symbols available
+ * for quering via dlsym(RTLD_NEXT, ...).
+ */
+void *
+__getPublicProcAddress(const char *procName)
+{
+ return dlsym(RTLD_NEXT, procName);
+}
+
+/*
+ * Lookup a private EGL/GL/GLES symbol
+ *
+ * Private symbols should always be available through eglGetProcAddress, and
+ * they are guaranteed to work with any context bound (regardless of the API).
+ *
+ * However, per issue#57, eglGetProcAddress returns garbage on some
+ * implementations, and the spec states that implementations may choose to also
+ * export extension functions publicly, so we always attempt dlsym before
+ * eglGetProcAddress to mitigate that.
+ */
+void *
+__getPrivateProcAddress(const char *procName)
+{
+ void *proc;
+ proc = dlsym(RTLD_NEXT, procName);
+ if (!proc && procName[0] == 'g' && procName[1] == 'l')
+ proc = (void *) __eglGetProcAddress(procName);
+
+ return proc;
+}
+
+#endif
diff --git a/glproc_gl.cpp b/glproc_gl.cpp
new file mode 100644
index 0000000..d9fb469
--- /dev/null
+++ b/glproc_gl.cpp
@@ -0,0 +1,232 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "glproc.hpp"
+
+
+#if !defined(_WIN32)
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE // for dladdr
+#endif
+#include <dlfcn.h>
+#endif
+
+
+/*
+ * Handle to the true OpenGL library.
+ */
+#if defined(_WIN32)
+HINSTANCE __libGlHandle = NULL;
+#else
+void *__libGlHandle = NULL;
+#endif
+
+
+
+#if defined(_WIN32)
+
+void *
+__getPublicProcAddress(const char *procName)
+{
+ if (!__libGlHandle) {
+ char szDll[MAX_PATH] = {0};
+
+ if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
+ return NULL;
+ }
+
+ strcat(szDll, "\\\\opengl32.dll");
+
+ __libGlHandle = LoadLibraryA(szDll);
+ if (!__libGlHandle) {
+ os::log("apitrace: error: couldn't load %s\n", szDll);
+ return NULL;
+ }
+ }
+
+ return (void *)GetProcAddress(__libGlHandle, procName);
+}
+
+
+void *
+__getPrivateProcAddress(const char *procName) {
+ return (void *)__wglGetProcAddress(procName);
+}
+
+
+#elif defined(__APPLE__)
+
+
+/*
+ * Path to the true OpenGL framework
+ */
+static const char *libgl_filename = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
+
+
+/*
+ * Lookup a libGL symbol
+ */
+void * __libgl_sym(const char *symbol)
+{
+ void *result;
+
+ if (!__libGlHandle) {
+ /*
+ * Unfortunately we can't just dlopen the true dynamic library because
+ * DYLD_LIBRARY_PATH/DYLD_FRAMEWORK_PATH take precedence, even for
+ * absolute paths. So we create a temporary symlink, and dlopen that
+ * instead.
+ */
+
+ char temp_filename[] = "/tmp/tmp.XXXXXX";
+
+ if (mktemp(temp_filename) != NULL) {
+ if (symlink(libgl_filename, temp_filename) == 0) {
+ __libGlHandle = dlopen(temp_filename, RTLD_LOCAL | RTLD_NOW | RTLD_FIRST);
+ remove(temp_filename);
+ }
+ }
+
+ if (!__libGlHandle) {
+ os::log("apitrace: error: couldn't load %s\n", libgl_filename);
+ os::abort();
+ return NULL;
+ }
+ }
+
+ result = dlsym(__libGlHandle, symbol);
+
+#ifndef RETRACE
+ if (result == dlsym(RTLD_SELF, symbol)) {
+ os::log("apitrace: error: symbol lookup recursion\n");
+ os::abort();
+ return NULL;
+ }
+#endif
+
+ return result;
+}
+
+
+void *
+__getPublicProcAddress(const char *procName)
+{
+ return __libgl_sym(procName);
+}
+
+void *
+__getPrivateProcAddress(const char *procName)
+{
+ return __libgl_sym(procName);
+}
+
+
+#else
+
+
+/*
+ * Invoke the true dlopen() function.
+ */
+static void *
+__dlopen(const char *filename, int flag)
+{
+ typedef void * (*PFNDLOPEN)(const char *, int);
+ static PFNDLOPEN dlopen_ptr = NULL;
+
+ if (!dlopen_ptr) {
+ dlopen_ptr = (PFNDLOPEN)dlsym(RTLD_NEXT, "dlopen");
+ if (!dlopen_ptr) {
+ os::log("apitrace: error: dlsym(RTLD_NEXT, \"dlopen\") failed\n");
+ return NULL;
+ }
+ }
+
+ return dlopen_ptr(filename, flag);
+}
+
+
+/*
+ * Lookup a libGL symbol
+ */
+void * __libgl_sym(const char *symbol)
+{
+ void *result;
+
+ if (!__libGlHandle) {
+ /*
+ * The app doesn't directly link against libGL.so, nor does it directly
+ * dlopen it. So we have to load it ourselves.
+ */
+
+ const char * libgl_filename = getenv("TRACE_LIBGL");
+
+ if (!libgl_filename) {
+ /*
+ * Try to use whatever libGL.so the library is linked against.
+ */
+
+ result = dlsym(RTLD_NEXT, symbol);
+ if (result) {
+ __libGlHandle = RTLD_NEXT;
+ return result;
+ }
+
+ libgl_filename = "libGL.so.1";
+ }
+
+ /*
+ * It would have been preferable to use RTLD_LOCAL to ensure that the
+ * application can never access libGL.so symbols directly, but this
+ * won't work, given libGL.so often loads a driver specific SO and
+ * exposes symbols to it.
+ */
+
+ __libGlHandle = __dlopen(libgl_filename, RTLD_GLOBAL | RTLD_LAZY);
+ if (!__libGlHandle) {
+ os::log("apitrace: error: couldn't find libGL.so\n");
+ return NULL;
+ }
+ }
+
+ return dlsym(__libGlHandle, symbol);
+}
+
+
+void *
+__getPublicProcAddress(const char *procName)
+{
+ return __libgl_sym(procName);
+}
+
+void *
+__getPrivateProcAddress(const char *procName)
+{
+ return (void *)__glXGetProcAddressARB((const GLubyte *)procName);
+}
+
+
+#endif
+
diff --git a/glstate.cpp b/glstate.cpp
index 6b9c072..329276f 100644
--- a/glstate.cpp
+++ b/glstate.cpp
@@ -738,6 +738,7 @@ getDrawableBounds(GLint *width, GLint *height) {
#else
+#if !TRACE_EGL
Display *display;
Drawable drawable;
Window root;
@@ -760,6 +761,9 @@ getDrawableBounds(GLint *width, GLint *height) {
*width = w;
*height = h;
+#else
+ return false;
+#endif
#endif
diff --git a/glws_egl_xlib.cpp b/glws_egl_xlib.cpp
index 958e951..d127705 100644
--- a/glws_egl_xlib.cpp
+++ b/glws_egl_xlib.cpp
@@ -29,9 +29,10 @@
#include <iostream>
-#include "glws.hpp"
+#include <dlfcn.h>
#include "glproc.hpp"
+#include "glws.hpp"
namespace glws {
@@ -136,7 +137,7 @@ public:
eglWaitNative(EGL_CORE_NATIVE_ENGINE);
EGLConfig config = static_cast<const EglVisual *>(visual)->config;
- surface = eglCreateWindowSurface(eglDisplay, config, window, NULL);
+ surface = eglCreateWindowSurface(eglDisplay, config, (EGLNativeWindowType)window, NULL);
}
void waitForEvent(int type) {
@@ -219,8 +220,23 @@ public:
}
};
+/**
+ * Load the symbols from the specified shared object into global namespace, so
+ * that they can be later found by dlsym(RTLD_NEXT, ...);
+ */
+static void
+load(const char *filename)
+{
+ if (!dlopen(filename, RTLD_GLOBAL | RTLD_LAZY)) {
+ std::cerr << "error: unable to open " << filename << "\n";
+ exit(1);
+ }
+}
+
void
init(void) {
+ load("libEGL.so.1");
+
display = XOpenDisplay(NULL);
if (!display) {
std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
@@ -229,7 +245,7 @@ init(void) {
screen = DefaultScreen(display);
- eglDisplay = eglGetDisplay(display);
+ eglDisplay = eglGetDisplay((EGLNativeDisplayType)display);
if (eglDisplay == EGL_NO_DISPLAY) {
std::cerr << "error: unable to get EGL display\n";
XCloseDisplay(display);
@@ -320,12 +336,15 @@ createContext(const Visual *_visual, Context *shareContext, Profile profile)
switch (profile) {
case PROFILE_COMPAT:
+ load("libGL.so.1");
eglBindAPI(EGL_OPENGL_API);
break;
case PROFILE_ES1:
+ load("libGLESv1_CM.so.1");
eglBindAPI(EGL_OPENGL_ES_API);
break;
case PROFILE_ES2:
+ load("libGLESv2.so.2");
eglBindAPI(EGL_OPENGL_ES_API);
attribs.add(EGL_CONTEXT_CLIENT_VERSION, 2);
break;
diff --git a/glws_glx.cpp b/glws_glx.cpp
index 8a0b403..db24b7f 100644
--- a/glws_glx.cpp
+++ b/glws_glx.cpp
@@ -28,9 +28,8 @@
#include <iostream>
-#include "glws.hpp"
-
#include "glproc.hpp"
+#include "glws.hpp"
namespace glws {
diff --git a/glws_wgl.cpp b/glws_wgl.cpp
index 2487eb0..63ce5fe 100644
--- a/glws_wgl.cpp
+++ b/glws_wgl.cpp
@@ -23,7 +23,7 @@
*
**************************************************************************/
-#include "glimports.hpp"
+#include "glproc.hpp"
#include "glws.hpp"
@@ -188,6 +188,10 @@ public:
void
init(void) {
+ /*
+ * OpenGL library must be loaded by the time we call GDI.
+ */
+ __libGlHandle = LoadLibraryA("OPENGL32");
}
void
diff --git a/glxtrace.py b/glxtrace.py
index be577cb..c9e9518 100644
--- a/glxtrace.py
+++ b/glxtrace.py
@@ -95,12 +95,6 @@ if __name__ == '__main__':
/*
- * Handle to the true libGL.so
- */
-static void *libgl_handle = NULL;
-
-
-/*
* Invoke the true dlopen() function.
*/
static void *__dlopen(const char *filename, int flag)
@@ -145,7 +139,7 @@ void * dlopen(const char *filename, int flag)
strcmp(filename, "libGL.so.1") == 0) {
// Use the true libGL.so handle instead of RTLD_NEXT from now on
- libgl_handle = handle;
+ __libGlHandle = handle;
// Get the file path for our shared object, and use it instead
static int dummy = 0xdeedbeef;
@@ -163,51 +157,5 @@ void * dlopen(const char *filename, int flag)
}
-/*
- * Lookup a libGL symbol
- */
-void * __libgl_sym(const char *symbol)
-{
- void *result;
-
- if (!libgl_handle) {
- /*
- * The app doesn't directly link against libGL.so, nor does it directly
- * dlopen it. So we have to load it ourselves.
- */
-
- const char * libgl_filename = getenv("TRACE_LIBGL");
-
- if (!libgl_filename) {
- /*
- * Try to use whatever libGL.so the library is linked against.
- */
-
- result = dlsym(RTLD_NEXT, symbol);
- if (result) {
- libgl_handle = RTLD_NEXT;
- return result;
- }
-
- libgl_filename = "libGL.so.1";
- }
-
- /*
- * It would have been preferable to use RTLD_LOCAL to ensure that the
- * application can never access libGL.so symbols directly, but this
- * won't work, given libGL.so often loads a driver specific SO and
- * exposes symbols to it.
- */
-
- libgl_handle = __dlopen(libgl_filename, RTLD_GLOBAL | RTLD_LAZY);
- if (!libgl_handle) {
- os::log("apitrace: error: couldn't find libGL.so\n");
- return NULL;
- }
- }
-
- return dlsym(libgl_handle, symbol);
-}
-
'''
diff --git a/wgltrace.py b/wgltrace.py
index cf2cc97..d5a5248 100644
--- a/wgltrace.py
+++ b/wgltrace.py
@@ -69,31 +69,6 @@ if __name__ == '__main__':
print '#include "trace_writer.hpp"'
print '#include "os.hpp"'
print
- print '''
-static HINSTANCE g_hDll = NULL;
-
-PROC
-__getPublicProcAddress(LPCSTR lpProcName)
-{
- if (!g_hDll) {
- char szDll[MAX_PATH] = {0};
-
- if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
- return NULL;
- }
-
- strcat(szDll, "\\\\opengl32.dll");
-
- g_hDll = LoadLibraryA(szDll);
- if (!g_hDll) {
- return NULL;
- }
- }
-
- return GetProcAddress(g_hDll, lpProcName);
-}
-
- '''
print '// To validate our prototypes'
print '#define GL_GLEXT_PROTOTYPES'
print '#define WGL_GLXEXT_PROTOTYPES'