mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-29 20:20:43 +00:00
Clean up gl_funcs.c, it's actually readable now. Unfortunately, it sig11s
for me. This may be due to the NVIDIA libGL problem (which they claim is a bug in libc), but it could very well be that Mercury was right and we can't have the same names internally as the libGL names. Even so, this code will probably work on Windows.
This commit is contained in:
parent
59ae0114df
commit
5e1de4c8a7
2 changed files with 69 additions and 64 deletions
|
@ -46,13 +46,12 @@
|
|||
#include <QF/GL/extensions.h>
|
||||
#include <QF/cvar.h>
|
||||
#include <QF/console.h>
|
||||
#include <QF/sys.h>
|
||||
#include "r_cvar.h"
|
||||
|
||||
// First we need to get all the function pointers declared.
|
||||
#define QFGL_NEED(ret, name, args) \
|
||||
typedef ret (* QF_##name) args; \
|
||||
QF_##name name = NULL;
|
||||
|
||||
ret (* name) args = NULL;
|
||||
#include "QF/GL/qf_funcs_list.h"
|
||||
#undef QFGL_NEED
|
||||
|
||||
|
@ -64,23 +63,27 @@ GLF_Init (void)
|
|||
|
||||
#ifdef HAVE_DLOPEN
|
||||
if (!(handle = dlopen (gl_libgl->string, RTLD_NOW))) {
|
||||
Con_Printf ("Couldn't load OpenGL library %s: %s\n", gl_libgl->string, dlerror ());
|
||||
Sys_Error ("Couldn't load OpenGL library %s: %s\n", gl_libgl->string, dlerror ());
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
# if _WIN32
|
||||
if (!(handle = LoadLibrary (gl_libgl->string))) {
|
||||
Con_Printf ("Couldn't load OpenGL library %s!\n", gl_libgl->string);
|
||||
# else
|
||||
{
|
||||
Con_Printf ("Cannot load libraries: %s was built without DSO support", PROGRAM);
|
||||
# endif
|
||||
#endif
|
||||
Sys_Error ("Couldn't load OpenGL library %s!\n", gl_libgl->string);
|
||||
return false;
|
||||
}
|
||||
# else
|
||||
Sys_Error ("Cannot load libraries: %s was built without DSO support", PROGRAM);
|
||||
return false;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define QFGL_NEED(ret, name, args) \
|
||||
name = QFGL_ProcAddress (handle, (#name));
|
||||
name = QFGL_ProcAddress (handle, #name);
|
||||
|
||||
#include "QF/GL/qf_funcs_list.h"
|
||||
#undef QFGL_NEED
|
||||
QFGL_ProcAddress (NULL, NULL); // tell ProcAddress to clear its cache
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -88,46 +91,50 @@ GLF_Init (void)
|
|||
void *
|
||||
QFGL_ProcAddress (void *handle, const char *name)
|
||||
{
|
||||
#if defined(HAVE_GLX) && defined(HAVE_DLOPEN)
|
||||
static QF_glXGetProcAddressARB glXGetProcAddress = NULL;
|
||||
static qboolean inited = false;
|
||||
static qboolean inited = false;
|
||||
void *glfunc = NULL;
|
||||
|
||||
if (!handle || !name)
|
||||
return NULL;
|
||||
|
||||
#ifdef HAVE_DLOPEN
|
||||
static QF_glXGetProcAddressARB glGetProcAddress = NULL;
|
||||
#else
|
||||
# ifdef _WIN32
|
||||
static void * (* wglGetProcAddress) (char *) glGetProcAddress = NULL;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (!inited) {
|
||||
inited = true;
|
||||
glXGetProcAddress = dlsym (handle, "glXGetProcAddressARB");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (name) {
|
||||
#if defined(HAVE_GLX) && defined(HAVE_DLOPEN)
|
||||
if (glXGetProcAddress) {
|
||||
return glXGetProcAddress ((const GLubyte *) name);
|
||||
} else {
|
||||
void *glfunction;
|
||||
|
||||
if (!(glfunction = dlsym (handle, name))) {
|
||||
Con_Printf ("Cannot find symbol %s: %s\n", name, dlerror ());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return glfunction;
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_DLOPEN
|
||||
glGetProcAddress = dlsym (handle, "glXGetProcAddressARB");
|
||||
#else
|
||||
# ifdef _WIN32
|
||||
void *glfunction;
|
||||
char filename[4096];
|
||||
|
||||
if (!(glfunction = GetProcAddress (handle, name))) {
|
||||
if (GetModuleFileName (handle, &filename, sizeof (filename)))
|
||||
Con_Printf ("Cannot find symbol %s in library %s", name, filename);
|
||||
else
|
||||
Con_Printf ("Cannot find symbol %s in library %s", name, gl_libgl->string);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return glfunction;
|
||||
glGetProcAddress = GetProcAddress (handle, "wglGetProcAddress");
|
||||
# endif
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Sys_Printf ("DEBUG: Finding symbol %s ... ", name);
|
||||
#ifdef HAVE_DLOPEN
|
||||
if (glGetProcAddress)
|
||||
glfunc = glGetProcAddress (name);
|
||||
else
|
||||
glfunc = dlsym (handle, name);
|
||||
#else
|
||||
# ifdef _WIN32
|
||||
if (glGetProcAddress)
|
||||
glfunc = glGetProcAddress (name);
|
||||
else
|
||||
glfunc = GetProcAddress (handle, name);
|
||||
# endif
|
||||
#endif
|
||||
if (glfunc) {
|
||||
Sys_Printf ("found [0x%x]\n", (unsigned int) glfunc);
|
||||
return glfunc;
|
||||
} else {
|
||||
Sys_Printf ("not found\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,12 +81,10 @@ typedef struct __GLXcontextRec *GLXContext;
|
|||
static GLXContext ctx = NULL;
|
||||
typedef XID GLXDrawable;
|
||||
|
||||
void (* QFGLX_glXSwapBuffers) (Display *dpy, GLXDrawable drawable);
|
||||
XVisualInfo* (* QFGLX_glXChooseVisual) (Display *dpy, int screen, int *attribList);
|
||||
GLXContext (* QFGLX_glXCreateContext) (Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct);
|
||||
Bool (* QFGLX_glXMakeCurrent) (Display *dpy, GLXDrawable drawable, GLXContext ctx);
|
||||
|
||||
|
||||
void (* glXSwapBuffers) (Display *dpy, GLXDrawable drawable);
|
||||
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_Init_Common (void);
|
||||
extern void VID_Init8bitPalette (void);
|
||||
|
@ -149,7 +147,7 @@ void
|
|||
GL_EndRendering (void)
|
||||
{
|
||||
glFlush ();
|
||||
QFGLX_glXSwapBuffers (x_disp, x_win);
|
||||
glXSwapBuffers (x_disp, x_win);
|
||||
Sbar_Changed ();
|
||||
}
|
||||
|
||||
|
@ -178,26 +176,26 @@ VID_Init (unsigned char *palette)
|
|||
return;
|
||||
}
|
||||
|
||||
QFGLX_glXSwapBuffers = dlsym(libgl_handle, "glXSwapBuffers");
|
||||
if (!QFGLX_glXSwapBuffers) {
|
||||
glXSwapBuffers = QFGL_ProcAddress (libgl_handle, "glXSwapBuffers");
|
||||
if (!glXSwapBuffers) {
|
||||
Sys_Error(va("Can't load symbol glXSwapBuffers: %s\n", dlerror()));
|
||||
return;
|
||||
}
|
||||
|
||||
QFGLX_glXChooseVisual = dlsym(libgl_handle, "glXChooseVisual");
|
||||
if (!QFGLX_glXChooseVisual) {
|
||||
glXChooseVisual = QFGL_ProcAddress (libgl_handle, "glXChooseVisual");
|
||||
if (!glXChooseVisual) {
|
||||
Sys_Error(va("Can't load symbol glXChooseVisual: %s\n", dlerror()));
|
||||
return;
|
||||
}
|
||||
|
||||
QFGLX_glXCreateContext = dlsym(libgl_handle, "glXCreateContext");
|
||||
if (!QFGLX_glXCreateContext) {
|
||||
glXCreateContext = QFGL_ProcAddress (libgl_handle, "glXCreateContext");
|
||||
if (!glXCreateContext) {
|
||||
Sys_Error(va("Can't load symbol glXCreateContext: %s\n", dlerror()));
|
||||
return;
|
||||
}
|
||||
|
||||
QFGLX_glXMakeCurrent = dlsym(libgl_handle, "glXMakeCurrent");
|
||||
if (!QFGLX_glXMakeCurrent) {
|
||||
glXMakeCurrent = QFGL_ProcAddress (libgl_handle, "glXMakeCurrent");
|
||||
if (!glXMakeCurrent) {
|
||||
Sys_Error(va("Can't load symbol glXMakeCurrent: %s\n", dlerror()));
|
||||
return;
|
||||
}
|
||||
|
@ -234,7 +232,7 @@ VID_Init (unsigned char *palette)
|
|||
|
||||
X11_OpenDisplay ();
|
||||
|
||||
x_visinfo = QFGLX_glXChooseVisual (x_disp, x_screen, attrib);
|
||||
x_visinfo = glXChooseVisual (x_disp, x_screen, attrib);
|
||||
if (!x_visinfo) {
|
||||
fprintf (stderr,
|
||||
"Error couldn't get an RGB, Double-buffered, Depth visual\n");
|
||||
|
@ -251,9 +249,9 @@ VID_Init (unsigned char *palette)
|
|||
|
||||
XSync (x_disp, 0);
|
||||
|
||||
ctx = QFGLX_glXCreateContext (x_disp, x_visinfo, NULL, True);
|
||||
ctx = glXCreateContext (x_disp, x_visinfo, NULL, True);
|
||||
|
||||
QFGLX_glXMakeCurrent (x_disp, x_win, ctx);
|
||||
glXMakeCurrent (x_disp, x_win, ctx);
|
||||
|
||||
vid.height = vid.conheight = min (vid.conheight, scr_height);
|
||||
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
|
||||
|
|
Loading…
Reference in a new issue