2001-06-24 09:25:55 +00:00
|
|
|
/*
|
|
|
|
gl_funcs.c
|
|
|
|
|
|
|
|
GL functions.
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-06-24 09:25:55 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-06-25 06:17:07 +00:00
|
|
|
|
2001-10-02 21:14:11 +00:00
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2001-06-25 06:17:07 +00:00
|
|
|
#ifdef HAVE_DLFCN_H
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
2001-06-24 09:25:55 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-09-01 08:57:04 +00:00
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#include <stdio.h>
|
2001-06-25 06:17:07 +00:00
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#include <QF/cvar.h>
|
|
|
|
#include <QF/console.h>
|
2001-06-25 09:32:08 +00:00
|
|
|
#include <QF/sys.h>
|
2001-09-01 08:57:04 +00:00
|
|
|
#include <QF/GL/funcs.h>
|
2001-08-22 11:00:25 +00:00
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "r_cvar.h"
|
|
|
|
|
|
|
|
// First we need to get all the function pointers declared.
|
2001-06-25 06:17:07 +00:00
|
|
|
#define QFGL_NEED(ret, name, args) \
|
2002-03-11 23:55:50 +00:00
|
|
|
ret (GLAPIENTRY * qf##name) args;
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_funcs_list.h"
|
|
|
|
#undef QFGL_NEED
|
|
|
|
|
2001-10-15 19:06:22 +00:00
|
|
|
void *libgl_handle;
|
|
|
|
|
2001-10-15 18:24:30 +00:00
|
|
|
#if defined(HAVE_DLOPEN)
|
|
|
|
|
|
|
|
static QF_glXGetProcAddressARB glGetProcAddress = NULL;
|
|
|
|
static void * (*getProcAddress) (void *handle, const char *symbol);
|
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
2001-06-24 09:25:55 +00:00
|
|
|
{
|
2001-06-25 06:17:07 +00:00
|
|
|
void *handle;
|
|
|
|
|
2001-09-28 07:41:38 +00:00
|
|
|
if (!(handle = dlopen (gl_driver->string, RTLD_NOW))) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't load OpenGL library %s: %s", gl_driver->string,
|
2001-08-22 11:00:25 +00:00
|
|
|
dlerror ());
|
2001-06-25 09:32:08 +00:00
|
|
|
}
|
2001-10-15 18:24:30 +00:00
|
|
|
getProcAddress = dlsym;
|
|
|
|
glGetProcAddress = dlsym (handle, "glXGetProcAddressARB");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2001-06-26 02:59:37 +00:00
|
|
|
#elif defined(_WIN32)
|
2001-10-15 18:24:30 +00:00
|
|
|
|
|
|
|
static void * (APIENTRY *glGetProcAddress) (const char *) = NULL;
|
|
|
|
static FARPROC (WINAPI *getProcAddress) (HINSTANCE,LPCSTR);
|
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
|
|
|
{
|
|
|
|
void *handle;
|
|
|
|
|
2001-09-28 07:41:38 +00:00
|
|
|
if (!(handle = LoadLibrary (gl_driver->string))) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't load OpenGL library %s!", gl_driver->string);
|
2001-06-25 09:32:08 +00:00
|
|
|
}
|
2001-10-15 18:24:30 +00:00
|
|
|
getProcAddress = GetProcAddress;
|
|
|
|
(FARPROC)glGetProcAddress = GetProcAddress (handle, "wglGetProcAddress");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2001-06-26 02:59:37 +00:00
|
|
|
#else
|
2001-10-15 18:24:30 +00:00
|
|
|
|
2001-06-26 02:59:37 +00:00
|
|
|
# error "Cannot load libraries: %s was not configured with DSO support"
|
2001-10-15 18:24:30 +00:00
|
|
|
|
|
|
|
// the following is to avoid other compiler errors
|
|
|
|
static QF_glXGetProcAddressARB glGetProcAddress = NULL;
|
|
|
|
static void * (*getProcAddress) (void *handle, const char *symbol);
|
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-06-25 06:17:07 +00:00
|
|
|
#endif
|
2001-06-24 09:25:55 +00:00
|
|
|
|
2001-10-15 18:24:30 +00:00
|
|
|
// Then we need to open the libGL and set all the symbols.
|
|
|
|
qboolean
|
|
|
|
GLF_Init (void)
|
|
|
|
{
|
2001-10-15 19:06:22 +00:00
|
|
|
libgl_handle = QFGL_LoadLibrary ();
|
2001-10-15 18:24:30 +00:00
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#define QFGL_NEED(ret, name, args) \
|
2002-03-11 23:55:50 +00:00
|
|
|
qf##name = QFGL_ProcAddress (libgl_handle, #name, true);
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_funcs_list.h"
|
|
|
|
#undef QFGL_NEED
|
2001-10-15 18:24:30 +00:00
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-06-25 06:17:07 +00:00
|
|
|
|
|
|
|
void *
|
2001-06-27 07:40:10 +00:00
|
|
|
QFGL_ProcAddress (void *handle, const char *name, qboolean crit)
|
2001-06-25 06:17:07 +00:00
|
|
|
{
|
2001-06-25 09:32:08 +00:00
|
|
|
void *glfunc = NULL;
|
|
|
|
|
2001-06-27 07:40:10 +00:00
|
|
|
Con_DPrintf ("DEBUG: Finding symbol %s ... ", name);
|
2001-10-15 18:24:30 +00:00
|
|
|
if (glGetProcAddress)
|
2001-06-26 02:59:37 +00:00
|
|
|
glfunc = glGetProcAddress (name);
|
2001-10-15 18:24:30 +00:00
|
|
|
if (!glfunc)
|
|
|
|
glfunc = getProcAddress (handle, name);
|
2001-06-26 02:59:37 +00:00
|
|
|
|
2001-06-25 09:32:08 +00:00
|
|
|
if (glfunc) {
|
2001-06-27 04:18:39 +00:00
|
|
|
Con_DPrintf ("found [%p]\n", glfunc);
|
2001-06-25 09:32:08 +00:00
|
|
|
return glfunc;
|
|
|
|
}
|
2001-06-27 07:40:10 +00:00
|
|
|
|
|
|
|
Con_DPrintf ("not found\n");
|
|
|
|
|
|
|
|
if (crit)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Couldn't load critical OpenGL function %s, exiting...",
|
2001-08-22 11:00:25 +00:00
|
|
|
name);
|
2001-06-27 07:40:10 +00:00
|
|
|
|
2001-06-26 02:59:37 +00:00
|
|
|
return NULL;
|
2001-06-25 06:17:07 +00:00
|
|
|
}
|