From: José Fonseca Date: Sun, 28 Nov 2010 16:43:04 +0000 (+0000) Subject: Eliminate GLEW dependency. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=c6b49ce0258320f1981819f10c94c9c28a604b2b;p=apitrace Eliminate GLEW dependency. --- diff --git a/.gitignore b/.gitignore index 9efbe62..8cdc5ca 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ d3d9.cpp ddraw.cpp dump dxsdk +glproc.hpp glretrace glretrace.cpp glxtrace.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a580abb..a1ce86d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,14 +20,6 @@ find_package (DirectX) find_package (GLUT) -find_library (GLEW_glew_LIBRARY GLEW - /usr/lib -) - -find_path (GLEW_INCLUDE_DIR GL/glew.h - /usr/include/GL -) - if (WIN32) # MSVC & MinGW only define & use APIENTRY add_definitions (-DGLAPIENTRY=__stdcall) @@ -161,7 +153,13 @@ endif () add_executable (dump dump.cpp trace_model.cpp) -if (GLEW_INCLUDE_DIR) +if (GLUT_INCLUDE_DIR) + add_custom_command ( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp + DEPENDS glproc.py wglapi.py glxapi.py glapi.py glenum.py stdapi.py + ) + add_custom_command ( OUTPUT glretrace.cpp COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace.cpp @@ -169,19 +167,18 @@ if (GLEW_INCLUDE_DIR) ) include_directories ( + ${CMAKE_CURRENT_BINARY_DIR} ${OPENGL_INCLUDE_PATH} ${GLUT_INCLUDE_DIR} - ${GLEW_INCLUDE_DIR} ) - add_executable (glretrace glretrace.cpp trace_model.cpp) + add_executable (glretrace glretrace.cpp trace_model.cpp ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp) target_link_libraries (glretrace ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${GLUT_glut_LIBRARY} - ${GLEW_glew_LIBRARY} ) -endif (GLEW_INCLUDE_DIR) +endif (GLUT_INCLUDE_DIR) diff --git a/TODO b/TODO index b28a865..64d3f02 100644 --- a/TODO +++ b/TODO @@ -13,9 +13,6 @@ * Allow clamping to a GL version or a number of extensions. -* Drop GLEW dependency -- the supported extension subset is different from what - we want, and it is trivial to code generate the wrappers - * Trace multiple threads * GetCurrentThreadId() * pthread_self() diff --git a/glimports.hpp b/glimports.hpp index 9c5492a..c96a69d 100644 --- a/glimports.hpp +++ b/glimports.hpp @@ -27,11 +27,18 @@ #define _GLIMPORTS_HPP_ #ifdef WIN32 + #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 #endif + #include -#endif + +#else /* !WIN32 */ + +#include + +#endif /* !WIN32 */ #include @@ -42,7 +49,35 @@ #endif #ifdef WIN32 + #include "wglext.h" -#endif /* WIN32 */ + +#define GLAPIENTRY __stdcall + +#ifndef PFD_SUPPORT_DIRECTDRAW +#define PFD_SUPPORT_DIRECTDRAW 0x00002000 +#endif +#ifndef PFD_SUPPORT_COMPOSITION +#define PFD_SUPPORT_COMPOSITION 0x00008000 +#endif + +#ifdef __MINGW32__ + +typedef struct _WGLSWAP +{ + HDC hdc; + UINT uiFlags; +} WGLSWAP, *PWGLSWAP, FAR *LPWGLSWAP; + +#define WGL_SWAPMULTIPLE_MAX 16 + +#endif /* __MINGW32__ */ + +#else /* !WIN32 */ + +#include +#include "glxext.h" + +#endif /* !WIN32 */ #endif /* _GLIMPORTS_HPP_ */ diff --git a/glproc.py b/glproc.py new file mode 100644 index 0000000..c2e5ffc --- /dev/null +++ b/glproc.py @@ -0,0 +1,534 @@ +########################################################################## +# +# Copyright 2010 VMware, Inc. +# 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. +# +##########################################################################/ + + +import stdapi +from glapi import glapi +from glxapi import glxapi +from wglapi import wglapi + + +public_symbols = set([ + "glAccum", + "glAlphaFunc", + "glAreTexturesResident", + "glArrayElement", + "glBegin", + "glBindTexture", + "glBitmap", + "glBlendFunc", + "glCallList", + "glCallLists", + "glClear", + "glClearAccum", + "glClearColor", + "glClearDepth", + "glClearIndex", + "glClearStencil", + "glClipPlane", + "glColor3b", + "glColor3bv", + "glColor3d", + "glColor3dv", + "glColor3f", + "glColor3fv", + "glColor3i", + "glColor3iv", + "glColor3s", + "glColor3sv", + "glColor3ub", + "glColor3ubv", + "glColor3ui", + "glColor3uiv", + "glColor3us", + "glColor3usv", + "glColor4b", + "glColor4bv", + "glColor4d", + "glColor4dv", + "glColor4f", + "glColor4fv", + "glColor4i", + "glColor4iv", + "glColor4s", + "glColor4sv", + "glColor4ub", + "glColor4ubv", + "glColor4ui", + "glColor4uiv", + "glColor4us", + "glColor4usv", + "glColorMask", + "glColorMaterial", + "glColorPointer", + "glCopyPixels", + "glCopyTexImage1D", + "glCopyTexImage2D", + "glCopyTexSubImage1D", + "glCopyTexSubImage2D", + "glCullFace", +# "glDebugEntry", + "glDeleteLists", + "glDeleteTextures", + "glDepthFunc", + "glDepthMask", + "glDepthRange", + "glDisable", + "glDisableClientState", + "glDrawArrays", + "glDrawBuffer", + "glDrawElements", + "glDrawPixels", + "glEdgeFlag", + "glEdgeFlagPointer", + "glEdgeFlagv", + "glEnable", + "glEnableClientState", + "glEnd", + "glEndList", + "glEvalCoord1d", + "glEvalCoord1dv", + "glEvalCoord1f", + "glEvalCoord1fv", + "glEvalCoord2d", + "glEvalCoord2dv", + "glEvalCoord2f", + "glEvalCoord2fv", + "glEvalMesh1", + "glEvalMesh2", + "glEvalPoint1", + "glEvalPoint2", + "glFeedbackBuffer", + "glFinish", + "glFlush", + "glFogf", + "glFogfv", + "glFogi", + "glFogiv", + "glFrontFace", + "glFrustum", + "glGenLists", + "glGenTextures", + "glGetBooleanv", + "glGetClipPlane", + "glGetDoublev", + "glGetError", + "glGetFloatv", + "glGetIntegerv", + "glGetLightfv", + "glGetLightiv", + "glGetMapdv", + "glGetMapfv", + "glGetMapiv", + "glGetMaterialfv", + "glGetMaterialiv", + "glGetPixelMapfv", + "glGetPixelMapuiv", + "glGetPixelMapusv", + "glGetPointerv", + "glGetPolygonStipple", + "glGetString", + "glGetTexEnvfv", + "glGetTexEnviv", + "glGetTexGendv", + "glGetTexGenfv", + "glGetTexGeniv", + "glGetTexImage", + "glGetTexLevelParameterfv", + "glGetTexLevelParameteriv", + "glGetTexParameterfv", + "glGetTexParameteriv", + "glHint", + "glIndexMask", + "glIndexPointer", + "glIndexd", + "glIndexdv", + "glIndexf", + "glIndexfv", + "glIndexi", + "glIndexiv", + "glIndexs", + "glIndexsv", + "glIndexub", + "glIndexubv", + "glInitNames", + "glInterleavedArrays", + "glIsEnabled", + "glIsList", + "glIsTexture", + "glLightModelf", + "glLightModelfv", + "glLightModeli", + "glLightModeliv", + "glLightf", + "glLightfv", + "glLighti", + "glLightiv", + "glLineStipple", + "glLineWidth", + "glListBase", + "glLoadIdentity", + "glLoadMatrixd", + "glLoadMatrixf", + "glLoadName", + "glLogicOp", + "glMap1d", + "glMap1f", + "glMap2d", + "glMap2f", + "glMapGrid1d", + "glMapGrid1f", + "glMapGrid2d", + "glMapGrid2f", + "glMaterialf", + "glMaterialfv", + "glMateriali", + "glMaterialiv", + "glMatrixMode", + "glMultMatrixd", + "glMultMatrixf", + "glNewList", + "glNormal3b", + "glNormal3bv", + "glNormal3d", + "glNormal3dv", + "glNormal3f", + "glNormal3fv", + "glNormal3i", + "glNormal3iv", + "glNormal3s", + "glNormal3sv", + "glNormalPointer", + "glOrtho", + "glPassThrough", + "glPixelMapfv", + "glPixelMapuiv", + "glPixelMapusv", + "glPixelStoref", + "glPixelStorei", + "glPixelTransferf", + "glPixelTransferi", + "glPixelZoom", + "glPointSize", + "glPolygonMode", + "glPolygonOffset", + "glPolygonStipple", + "glPopAttrib", + "glPopClientAttrib", + "glPopMatrix", + "glPopName", + "glPrioritizeTextures", + "glPushAttrib", + "glPushClientAttrib", + "glPushMatrix", + "glPushName", + "glRasterPos2d", + "glRasterPos2dv", + "glRasterPos2f", + "glRasterPos2fv", + "glRasterPos2i", + "glRasterPos2iv", + "glRasterPos2s", + "glRasterPos2sv", + "glRasterPos3d", + "glRasterPos3dv", + "glRasterPos3f", + "glRasterPos3fv", + "glRasterPos3i", + "glRasterPos3iv", + "glRasterPos3s", + "glRasterPos3sv", + "glRasterPos4d", + "glRasterPos4dv", + "glRasterPos4f", + "glRasterPos4fv", + "glRasterPos4i", + "glRasterPos4iv", + "glRasterPos4s", + "glRasterPos4sv", + "glReadBuffer", + "glReadPixels", + "glRectd", + "glRectdv", + "glRectf", + "glRectfv", + "glRecti", + "glRectiv", + "glRects", + "glRectsv", + "glRenderMode", + "glRotated", + "glRotatef", + "glScaled", + "glScalef", + "glScissor", + "glSelectBuffer", + "glShadeModel", + "glStencilFunc", + "glStencilMask", + "glStencilOp", + "glTexCoord1d", + "glTexCoord1dv", + "glTexCoord1f", + "glTexCoord1fv", + "glTexCoord1i", + "glTexCoord1iv", + "glTexCoord1s", + "glTexCoord1sv", + "glTexCoord2d", + "glTexCoord2dv", + "glTexCoord2f", + "glTexCoord2fv", + "glTexCoord2i", + "glTexCoord2iv", + "glTexCoord2s", + "glTexCoord2sv", + "glTexCoord3d", + "glTexCoord3dv", + "glTexCoord3f", + "glTexCoord3fv", + "glTexCoord3i", + "glTexCoord3iv", + "glTexCoord3s", + "glTexCoord3sv", + "glTexCoord4d", + "glTexCoord4dv", + "glTexCoord4f", + "glTexCoord4fv", + "glTexCoord4i", + "glTexCoord4iv", + "glTexCoord4s", + "glTexCoord4sv", + "glTexCoordPointer", + "glTexEnvf", + "glTexEnvfv", + "glTexEnvi", + "glTexEnviv", + "glTexGend", + "glTexGendv", + "glTexGenf", + "glTexGenfv", + "glTexGeni", + "glTexGeniv", + "glTexImage1D", + "glTexImage2D", + "glTexParameterf", + "glTexParameterfv", + "glTexParameteri", + "glTexParameteriv", + "glTexSubImage1D", + "glTexSubImage2D", + "glTranslated", + "glTranslatef", + "glVertex2d", + "glVertex2dv", + "glVertex2f", + "glVertex2fv", + "glVertex2i", + "glVertex2iv", + "glVertex2s", + "glVertex2sv", + "glVertex3d", + "glVertex3dv", + "glVertex3f", + "glVertex3fv", + "glVertex3i", + "glVertex3iv", + "glVertex3s", + "glVertex3sv", + "glVertex4d", + "glVertex4dv", + "glVertex4f", + "glVertex4fv", + "glVertex4i", + "glVertex4iv", + "glVertex4s", + "glVertex4sv", + "glVertexPointer", + "glViewport", + "wglChoosePixelFormat", + "wglCopyContext", + "wglCreateContext", + "wglCreateLayerContext", + "wglDeleteContext", + "wglDescribeLayerPlane", + "wglDescribePixelFormat", + "wglGetCurrentContext", + "wglGetCurrentDC", + "wglGetDefaultProcAddress", + "wglGetLayerPaletteEntries", + "wglGetPixelFormat", + "wglGetProcAddress", + "wglMakeCurrent", + "wglRealizeLayerPalette", + "wglSetLayerPaletteEntries", + "wglSetPixelFormat", + "wglShareLists", + "wglSwapBuffers", + "wglSwapLayerBuffers", + "wglSwapMultipleBuffers", + "wglUseFontBitmapsA", + "wglUseFontBitmapsW", + "wglUseFontOutlinesA", + "wglUseFontOutlinesW", +]) + + +class Dispatcher: + + def function_pointer_type(self, function): + return '__PFN' + function.name.upper() + + def function_pointer_value(self, function): + return '__' + function.name + '_ptr' + + def dispatch_function(self, function): + if function.name in public_symbols: + return + + ptype = self.function_pointer_type(function) + pvalue = self.function_pointer_value(function) + print 'typedef ' + function.prototype('* %s' % ptype) + ';' + print 'static %s %s = NULL;' % (ptype, pvalue) + print + print 'static inline ' + function.prototype('__' + function.name) + ' {' + if function.type is stdapi.Void: + ret = '' + else: + ret = 'return ' + self.get_true_pointer(function) + pvalue = self.function_pointer_value(function) + print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args])) + print '}' + print + print '#define %s __%s' % (function.name, function.name) + + def get_true_pointer(self, function): + ptype = self.function_pointer_type(function) + pvalue = self.function_pointer_value(function) + if function.name in public_symbols: + get_proc_address = '__getProcAddress' + else: + get_proc_address = '__glGetProcAddress' + print ' if (!%s) {' % (pvalue,) + print ' %s = (%s)%s("%s");' % (pvalue, ptype, get_proc_address, function.name) + print ' if (!%s) {' % (pvalue,) + self.fail_function(function) + print ' }' + print ' }' + + def fail_function(self, function): + print ' std::cerr << "error: unavailable function \\"%s\\"\\n";' % function.name + if function.fail is not None: + if function.type is stdapi.Void: + assert function.fail == '' + print ' return;' + else: + assert function.fail != '' + print ' return %s;' % function.fail + else: + print ' abort();' + + +if __name__ == '__main__': + print + print '#include "glimports.hpp"' + print '#include "os.hpp"' + print + if 0: + print 'typedef void (*__PROC)(void);' + print + print 'static __PROC __getProcAddress(const char *name);' + print + print 'static __PROC __glGetProcAddress(const char *name);' + else: + print '#ifdef WIN32' + print '#define __glGetProcAddress wglGetProcAddress' + print '#else' + print '#define __glGetProcAddress(name) glXGetProcAddress((const GLubyte *)(name))' + print '#endif' + print + dispatcher = Dispatcher() + for function in glapi.functions: + dispatcher.dispatch_function(function) + print + if 0: + print ''' + +#ifdef WIN32 + +static HINSTANCE g_hDll = NULL; + +static __PROC +__getProcAddress(const char *name) +{ + 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, name); +} + +static inline __PROC +__glGetProcAddress(const char *name) { + return __wglGetProcAddress(name); +} + +#else + +static void g_module = NULL; + +static __PROC +__getProcAddress(const char *name) +{ + if (!g_module) { + g_module = dlopen("libGL.so", RTLD_LAZY); + if (!g_module) { + return NULL; + } + } + + return (__PROC)dlsym(g_module, name); +} + +static inline __PROC +__glGetProcAddress(const char *name) { + return __glXGetProcAddress(name); +} + +#endif + + ''' diff --git a/glretrace.py b/glretrace.py index ff22e99..39a818a 100644 --- a/glretrace.py +++ b/glretrace.py @@ -90,11 +90,7 @@ if __name__ == '__main__': print '#include ' print '#include ' print - print '#ifdef WIN32' - print '#include ' - print '#endif' - print - print '#include ' + print '#include "glproc.hpp"' print '#include ' print print 'static bool double_buffer = false;' @@ -210,7 +206,6 @@ int main(int argc, char **argv) glutInitWindowSize(800, 600); glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | (double_buffer ? GLUT_DOUBLE : GLUT_SINGLE)); glutCreateWindow(argv[0]); - glewInit(); glutDisplayFunc(&display); glutIdleFunc(&idle); diff --git a/trace_model.hpp b/trace_model.hpp index 5ee9b19..71581e8 100644 --- a/trace_model.hpp +++ b/trace_model.hpp @@ -104,6 +104,8 @@ public: }; +#undef Bool + class Bool : public Value { public: diff --git a/wgltrace.py b/wgltrace.py index f75ae80..11da692 100644 --- a/wgltrace.py +++ b/wgltrace.py @@ -435,27 +435,6 @@ if __name__ == '__main__': print '#include "os.hpp"' print '#include "glsize.hpp"' print - print '#ifndef PFD_SUPPORT_DIRECTDRAW' - print '#define PFD_SUPPORT_DIRECTDRAW 0x00002000' - print '#endif' - print '#ifndef PFD_SUPPORT_COMPOSITION' - print '#define PFD_SUPPORT_COMPOSITION 0x00008000' - print '#endif' - - print '#define GLAPIENTRY __stdcall' - print - print '#ifdef __MINGW32__' - print '' - print 'typedef struct _WGLSWAP' - print '{' - print ' HDC hdc;' - print ' UINT uiFlags;' - print '} WGLSWAP, *PWGLSWAP, FAR *LPWGLSWAP;' - print '' - print '#define WGL_SWAPMULTIPLE_MAX 16' - print '' - print '#endif' - print print 'extern "C" {' print ''' static HINSTANCE g_hDll = NULL;