diff --git a/include/QF/GL/funcs.h b/include/QF/GL/funcs.h index 8e6f9ec47..3a9844bc5 100644 --- a/include/QF/GL/funcs.h +++ b/include/QF/GL/funcs.h @@ -37,6 +37,8 @@ #include "QF/GL/qf_funcs_list.h" #undef QFGL_NEED +extern void *libgl_handle; + qboolean GLF_Init (void); void *QFGL_ProcAddress (void *, const char *, qboolean); diff --git a/libs/video/renderer/gl/gl_funcs.c b/libs/video/renderer/gl/gl_funcs.c index fb351fe3d..0828fb737 100644 --- a/libs/video/renderer/gl/gl_funcs.c +++ b/libs/video/renderer/gl/gl_funcs.c @@ -62,6 +62,8 @@ ret (GLAPIENTRY * qf##name) args = NULL; #include "QF/GL/qf_funcs_list.h" #undef QFGL_NEED +void *libgl_handle; + #if defined(HAVE_DLOPEN) static QF_glXGetProcAddressARB glGetProcAddress = NULL; @@ -119,18 +121,13 @@ QFGL_LoadLibrary (void) qboolean GLF_Init (void) { - void *handle; - - handle = QFGL_LoadLibrary (); + libgl_handle = QFGL_LoadLibrary (); #define QFGL_NEED(ret, name, args) \ - qf##name = QFGL_ProcAddress (handle, #name, true); + qf##name = QFGL_ProcAddress (libgl_handle, #name, true); #include "QF/GL/qf_funcs_list.h" #undef QFGL_NEED - // tell ProcAddress to clear its cache - QFGL_ProcAddress (NULL, NULL, false); - return true; } diff --git a/libs/video/targets/vid_3dfxsvga.c b/libs/video/targets/vid_3dfxsvga.c index aa4a19793..0e34891f9 100644 --- a/libs/video/targets/vid_3dfxsvga.c +++ b/libs/video/targets/vid_3dfxsvga.c @@ -88,10 +88,9 @@ cvar_t *tdfx_brighten; static fxMesaContext fc = NULL; -void *libgl_handle; - int VID_options_items = 0; +extern void GL_Pre_Init (void); extern void GL_Init_Common (void); extern void VID_Init8bitPalette (void); @@ -264,15 +263,8 @@ VID_Init (unsigned char *palette) int i; GLint attribs[32]; -#ifdef HAVE_DLOPEN - if (!(libgl_handle = dlopen (gl_driver->string, RTLD_NOW))) { - Sys_Error ("Can't open OpenGL library \"%s\": %s\n", gl_driver->string, - dlerror()); - return; - } -#else -# error "No dynamic library support. FIXME." -#endif + GL_Pre_Init (); + fxMesaCreateContext = QFGL_ProcAddress (libgl_handle, "fxMesaCreateContext", true); fxMesaDestroyContext = QFGL_ProcAddress (libgl_handle, @@ -282,7 +274,6 @@ VID_Init (unsigned char *palette) fxMesaSwapBuffers = QFGL_ProcAddress (libgl_handle, "fxMesaSwapBuffers", true); - QFGL_ProcAddress (NULL, NULL, false); VID_GetWindowSize (640, 480); Con_CheckResize (); // Now that we have a window size, fix console diff --git a/libs/video/targets/vid_common_gl.c b/libs/video/targets/vid_common_gl.c index cf59f3b7f..e8b788785 100644 --- a/libs/video/targets/vid_common_gl.c +++ b/libs/video/targets/vid_common_gl.c @@ -228,17 +228,21 @@ VID_SetPalette (unsigned char *palette) } } +void +GL_Pre_Init (void) +{ + if (!GLF_Init()) { + Sys_Error("Can't init video.\n"); + return; + } +} + /* GL_Init_Common */ void GL_Init_Common (void) { - if (!GLF_Init()) { - Sys_Error("Can't init video.\n"); - return; - } - gl_vendor = qfglGetString (GL_VENDOR); Con_Printf ("GL_VENDOR: %s\n", gl_vendor); gl_renderer = qfglGetString (GL_RENDERER); diff --git a/libs/video/targets/vid_glx.c b/libs/video/targets/vid_glx.c index 32a7bf903..dfa233e17 100644 --- a/libs/video/targets/vid_glx.c +++ b/libs/video/targets/vid_glx.c @@ -86,6 +86,7 @@ XVisualInfo* (* glXChooseVisual) (Display *dpy, int screen, int *attribList); GLXContext (* glXCreateContext) (Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct); Bool (* glXMakeCurrent) (Display *dpy, GLXDrawable drawable, GLXContext ctx); +extern void GL_Pre_Init (void); extern void GL_Init_Common (void); extern void VID_Init8bitPalette (void); @@ -95,7 +96,6 @@ const char *gl_vendor; const char *gl_renderer; const char *gl_version; const char *gl_extensions; -void *libgl_handle; void @@ -143,22 +143,13 @@ VID_Init (unsigned char *palette) None }; -#ifdef HAVE_DLOPEN - if (!(libgl_handle = dlopen (gl_driver->string, RTLD_NOW))) { - Sys_Error ("Can't open OpenGL library \"%s\": %s\n", gl_driver->string, - dlerror()); - return; - } -#else -# error "No dynamic library support. FIXME." -#endif + GL_Pre_Init (); glXSwapBuffers = QFGL_ProcAddress (libgl_handle, "glXSwapBuffers", true); glXChooseVisual = QFGL_ProcAddress (libgl_handle, "glXChooseVisual", true); glXCreateContext = QFGL_ProcAddress (libgl_handle, "glXCreateContext", true); glXMakeCurrent = QFGL_ProcAddress (libgl_handle, "glXMakeCurrent", true); - QFGL_ProcAddress (NULL, NULL, false); // make ProcAddress clear its cache Cmd_AddCommand ("vid_center", VID_Center_f, "Center the view port on the " "quake window in a virtual desktop.\n"); diff --git a/libs/video/targets/vid_sgl.c b/libs/video/targets/vid_sgl.c index 07dc9c96e..85aa59912 100644 --- a/libs/video/targets/vid_sgl.c +++ b/libs/video/targets/vid_sgl.c @@ -69,6 +69,7 @@ cvar_t *vid_system_gamma; int VID_options_items = 1; int modestate; +extern void GL_Pre_Init (void); extern void GL_Init_Common (void); extern void VID_Init8bitPalette (void); @@ -134,6 +135,8 @@ VID_Init (unsigned char *palette) Uint32 flags = SDL_OPENGL; int i; + GL_Pre_Init (); + // SDL_SysWMinfo info; VID_GetWindowSize (640, 480); diff --git a/libs/video/targets/vid_wgl.c b/libs/video/targets/vid_wgl.c index 961233add..19c2e4ce1 100644 --- a/libs/video/targets/vid_wgl.c +++ b/libs/video/targets/vid_wgl.c @@ -55,6 +55,7 @@ static const char rcsid[] = #include "resource.h" #include "sbar.h" +extern void GL_Pre_Init (void); extern void GL_Init_Common (void); extern void VID_Init8bitPalette (void); @@ -108,7 +109,6 @@ const char *gl_vendor; const char *gl_renderer; const char *gl_version; const char *gl_extensions; -void *libgl_handle; // 8-bit and permedia support qboolean isPermedia = false; @@ -1138,10 +1138,7 @@ VID_Init (unsigned char *palette) HGLRC baseRC; DWORD lasterror; - if (!(libgl_handle = LoadLibrary (gl_driver->string))) { - Sys_Error ("Can't open OpenGL library \"%s\"\n", gl_driver->string); - return; - } + GL_Pre_Init (); qf_wglCreateContext = QFGL_ProcAddress (libgl_handle, "wglCreateContext", true);