2001-04-15 04:18:22 +00:00
|
|
|
/*
|
|
|
|
vid_glx.c
|
|
|
|
|
|
|
|
OpenGL GLX video driver
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-08-25 02:47:11 +00:00
|
|
|
#ifdef HAVE_DLOPEN
|
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#include <X11/Xlib.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_DGA
|
2010-08-05 02:35:16 +00:00
|
|
|
# ifdef DGA_OLD_HEADERS
|
2010-08-08 01:58:17 +00:00
|
|
|
# include <X11/extensions/xf86dga.h>
|
2010-08-05 02:35:16 +00:00
|
|
|
# else
|
|
|
|
# include <X11/extensions/Xxf86dga.h>
|
|
|
|
# endif
|
2001-04-15 04:18:22 +00:00
|
|
|
#endif
|
|
|
|
|
2001-05-17 06:55:47 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/input.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/qendian.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/sys.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/va.h"
|
2001-04-15 08:04:15 +00:00
|
|
|
#include "QF/vid.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/funcs.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "QF/GL/qf_vid.h"
|
2001-04-15 08:04:15 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "compat.h"
|
2001-04-15 08:04:15 +00:00
|
|
|
#include "context_x11.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
#define WARP_WIDTH 320
|
|
|
|
#define WARP_HEIGHT 200
|
|
|
|
|
2002-08-21 05:59:00 +00:00
|
|
|
// GLXContext is a pointer to opaque data
|
2001-06-24 09:25:55 +00:00
|
|
|
typedef struct __GLXcontextRec *GLXContext;
|
|
|
|
|
2002-06-24 21:35:37 +00:00
|
|
|
#define GLX_RGBA 4 // true if RGBA mode
|
|
|
|
#define GLX_DOUBLEBUFFER 5 // double buffering supported
|
|
|
|
#define GLX_RED_SIZE 8 // number of red component bits
|
|
|
|
#define GLX_GREEN_SIZE 9 // number of green component bits
|
|
|
|
#define GLX_BLUE_SIZE 10 // number of blue component bits
|
|
|
|
#define GLX_DEPTH_SIZE 12 // number of depth bits
|
2001-06-24 09:25:55 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
static GLXContext ctx = NULL;
|
2001-06-24 09:25:55 +00:00
|
|
|
typedef XID GLXDrawable;
|
|
|
|
|
2004-02-06 00:58:35 +00:00
|
|
|
void (*qfglXSwapBuffers) (Display *dpy, GLXDrawable drawable);
|
|
|
|
XVisualInfo* (*qfglXChooseVisual) (Display *dpy, int screen, int *attribList);
|
|
|
|
GLXContext (*qfglXCreateContext) (Display *dpy, XVisualInfo *vis,
|
|
|
|
GLXContext shareList, Bool direct);
|
|
|
|
Bool (*qfglXMakeCurrent) (Display *dpy, GLXDrawable drawable, GLXContext ctx);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
|
2002-08-21 05:59:00 +00:00
|
|
|
// ============================================================================
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2010-08-05 02:38:47 +00:00
|
|
|
static int use_gl_procaddress = 0;
|
2002-11-10 23:31:19 +00:00
|
|
|
|
2002-06-24 21:35:37 +00:00
|
|
|
#if defined(HAVE_DLOPEN)
|
|
|
|
|
|
|
|
void * (* glGetProcAddress) (const char *symbol) = NULL;
|
2002-08-16 18:29:21 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_GetProcAddress (void *handle, const char *name)
|
|
|
|
{
|
|
|
|
void *glfunc = NULL;
|
|
|
|
|
2002-11-10 23:31:19 +00:00
|
|
|
if (use_gl_procaddress && glGetProcAddress)
|
2002-08-16 18:29:21 +00:00
|
|
|
glfunc = glGetProcAddress (name);
|
|
|
|
if (!glfunc)
|
|
|
|
glfunc = dlsym (handle, name);
|
|
|
|
return glfunc;
|
|
|
|
}
|
2002-06-24 21:35:37 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
|
|
|
{
|
|
|
|
void *handle;
|
2004-01-09 23:37:04 +00:00
|
|
|
int flags = RTLD_NOW;
|
2002-06-24 21:35:37 +00:00
|
|
|
|
2004-01-09 23:37:04 +00:00
|
|
|
#ifdef RTLD_GLOBAL
|
|
|
|
flags |= RTLD_GLOBAL;
|
|
|
|
#endif
|
|
|
|
if (!(handle = dlopen (gl_driver->string, flags))) {
|
2002-06-24 21:35:37 +00:00
|
|
|
Sys_Error ("Couldn't load OpenGL library %s: %s", gl_driver->string,
|
|
|
|
dlerror ());
|
|
|
|
}
|
2004-05-06 07:13:18 +00:00
|
|
|
glGetProcAddress = dlsym (handle, "glXGetProcAddress");
|
|
|
|
if (!glGetProcAddress)
|
|
|
|
glGetProcAddress = dlsym (handle, "glXGetProcAddressARB");
|
2002-06-24 21:35:37 +00:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
# error "Cannot load libraries: %s was not configured with DSO support"
|
|
|
|
|
|
|
|
// the following is to avoid other compiler errors
|
2002-08-16 18:29:21 +00:00
|
|
|
void *
|
|
|
|
QFGL_GetProcAddress (void *handle, const char *name)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2002-06-24 21:35:37 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
QFGL_LoadLibrary (void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif // HAVE_DLOPEN
|
|
|
|
|
2010-11-27 06:10:34 +00:00
|
|
|
static void
|
|
|
|
glx_get_functions (void)
|
|
|
|
{
|
|
|
|
GLF_Init ();
|
|
|
|
|
|
|
|
qfglXSwapBuffers = QFGL_ProcAddress (libgl_handle, "glXSwapBuffers", true);
|
|
|
|
qfglXChooseVisual = QFGL_ProcAddress (libgl_handle, "glXChooseVisual",
|
|
|
|
true);
|
|
|
|
qfglXCreateContext = QFGL_ProcAddress (libgl_handle, "glXCreateContext",
|
|
|
|
true);
|
|
|
|
qfglXMakeCurrent = QFGL_ProcAddress (libgl_handle, "glXMakeCurrent", true);
|
|
|
|
|
|
|
|
use_gl_procaddress = 1;
|
|
|
|
}
|
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
VID_Shutdown (void)
|
|
|
|
{
|
2010-11-26 23:48:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_VID, "VID_Shutdown\n");
|
2004-03-19 20:24:26 +00:00
|
|
|
X11_CloseDisplay ();
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-04-15 04:18:22 +00:00
|
|
|
GL_Init (void)
|
|
|
|
{
|
|
|
|
GL_Init_Common ();
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-04-15 04:18:22 +00:00
|
|
|
GL_EndRendering (void)
|
|
|
|
{
|
2002-02-27 05:22:21 +00:00
|
|
|
qfglFinish ();
|
2001-10-16 04:11:25 +00:00
|
|
|
qfglXSwapBuffers (x_disp, x_win);
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 12:33:54 +00:00
|
|
|
static void
|
|
|
|
glx_choose_visual (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
int attrib[] = {
|
|
|
|
GLX_RGBA,
|
|
|
|
GLX_RED_SIZE, 1,
|
|
|
|
GLX_GREEN_SIZE, 1,
|
|
|
|
GLX_BLUE_SIZE, 1,
|
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
GLX_DEPTH_SIZE, 1,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2001-10-16 04:11:25 +00:00
|
|
|
x_visinfo = qfglXChooseVisual (x_disp, x_screen, attrib);
|
2001-04-15 04:18:22 +00:00
|
|
|
if (!x_visinfo) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Error couldn't get an RGB, Double-buffered, Depth visual");
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
x_vis = x_visinfo->visual;
|
2012-02-18 12:33:54 +00:00
|
|
|
}
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2012-02-18 12:33:54 +00:00
|
|
|
static void
|
|
|
|
glx_create_context (void)
|
|
|
|
{
|
2001-04-15 04:18:22 +00:00
|
|
|
XSync (x_disp, 0);
|
2001-10-16 04:11:25 +00:00
|
|
|
ctx = qfglXCreateContext (x_disp, x_visinfo, NULL, True);
|
|
|
|
qfglXMakeCurrent (x_disp, x_win, ctx);
|
2012-02-18 12:33:54 +00:00
|
|
|
GL_Init ();
|
|
|
|
}
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2012-02-18 12:33:54 +00:00
|
|
|
void
|
|
|
|
VID_Init (byte *palette, byte *colormap)
|
|
|
|
{
|
|
|
|
vid.maxwarpwidth = WARP_WIDTH;
|
|
|
|
vid.maxwarpheight = WARP_HEIGHT;
|
|
|
|
vid.colormap8 = vid_colormap = colormap;
|
|
|
|
vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES];
|
2001-04-15 04:18:22 +00:00
|
|
|
vid.numpages = 2;
|
|
|
|
|
2012-02-18 12:33:54 +00:00
|
|
|
glx_get_functions ();
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2012-02-18 12:33:54 +00:00
|
|
|
VID_GetWindowSize (640, 480);
|
|
|
|
X11_OpenDisplay ();
|
|
|
|
glx_choose_visual ();
|
|
|
|
X11_SetVidMode (vid.width, vid.height);
|
|
|
|
X11_CreateWindow (vid.width, vid.height);
|
|
|
|
X11_CreateNullCursor (); // hide mouse pointer
|
|
|
|
glx_create_context ();
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2012-02-18 12:33:54 +00:00
|
|
|
VID_InitGamma (palette);
|
2002-09-10 06:35:32 +00:00
|
|
|
VID_SetPalette (vid.palette);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2010-11-26 23:48:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_VID, "Video mode %dx%d initialized.\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
vid.width, vid.height);
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-05-25 04:03:47 +00:00
|
|
|
vid.initialized = true;
|
2001-04-15 04:18:22 +00:00
|
|
|
vid.recalc_refdef = 1; // force a surface cache flush
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VID_Init_Cvars ()
|
|
|
|
{
|
|
|
|
X11_Init_Cvars ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
VID_SetCaption (const char *text)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
if (text && *text) {
|
|
|
|
char *temp = strdup (text);
|
|
|
|
|
2010-08-19 06:01:43 +00:00
|
|
|
X11_SetCaption (va ("%s: %s", PACKAGE_STRING, temp));
|
2001-04-15 04:18:22 +00:00
|
|
|
free (temp);
|
|
|
|
} else {
|
2010-08-19 06:01:43 +00:00
|
|
|
X11_SetCaption (va ("%s", PACKAGE_STRING));
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
VID_SetGamma (double gamma)
|
|
|
|
{
|
|
|
|
return X11_SetGamma (gamma);
|
|
|
|
}
|