Run a vacuum cleaner over the diffs between x11 and glx init.

X11 and GLX init are nowhere near as scary as I thought they were, once
they've been tidied up.
This commit is contained in:
Bill Currie 2012-02-18 21:33:54 +09:00
parent eff8ebd9ba
commit 82679066cc
5 changed files with 79 additions and 69 deletions

View file

@ -50,6 +50,7 @@ extern Display *x_disp;
extern Visual *x_vis;
extern Window x_root;
extern Window x_win;
extern Colormap x_cmap;
extern XVisualInfo *x_visinfo;
extern int x_screen;
extern int x_shmeventtype;

View file

@ -90,6 +90,7 @@ Window x_root = None;
XVisualInfo *x_visinfo;
Visual *x_vis;
Window x_win;
Colormap x_cmap;
Time x_time;
Time x_mouse_time;
@ -516,6 +517,8 @@ X11_CreateWindow (int width, int height)
// window attributes
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = x_cmap;
if (!attr.colormap)
attr.colormap = XCreateColormap (x_disp, x_root, x_vis, AllocNone);
attr.event_mask = X11_MASK;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;

View file

@ -532,7 +532,13 @@ VID_SetPalette (unsigned char *palette)
unsigned int *table;
static qboolean palflag = false;
QFile *f;
static int inited_8 = 0;
if (!inited_8) {
inited_8 = 1;
// Check for 8-bit extension and initialize if present
VID_Init8bitPalette ();
}
// 8 8 8 encoding
Sys_MaskPrintf (SYS_VID, "Converting 8to24\n");

View file

@ -185,8 +185,8 @@ GL_EndRendering (void)
qfglXSwapBuffers (x_disp, x_win);
}
void
VID_Init (byte *palette, byte *colormap)
static void
glx_choose_visual (void)
{
int attrib[] = {
GLX_RGBA,
@ -198,48 +198,48 @@ VID_Init (byte *palette, byte *colormap)
None
};
glx_get_functions ();
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap8 = vid_colormap = colormap;
vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES];
X11_OpenDisplay ();
x_visinfo = qfglXChooseVisual (x_disp, x_screen, attrib);
if (!x_visinfo) {
Sys_Error ("Error couldn't get an RGB, Double-buffered, Depth visual");
}
x_vis = x_visinfo->visual;
}
static void
glx_create_context (void)
{
XSync (x_disp, 0);
ctx = qfglXCreateContext (x_disp, x_visinfo, NULL, True);
qfglXMakeCurrent (x_disp, x_win, ctx);
GL_Init ();
}
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];
vid.numpages = 2;
glx_get_functions ();
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
XSync (x_disp, 0);
ctx = qfglXCreateContext (x_disp, x_visinfo, NULL, True);
qfglXMakeCurrent (x_disp, x_win, ctx);
vid.numpages = 2;
GL_Init ();
glx_create_context ();
VID_InitGamma (palette);
// Check for 8-bit extension and initialize if present
VID_Init8bitPalette ();
VID_SetPalette (vid.palette);
Sys_MaskPrintf (SYS_VID, "Video mode %dx%d initialized.\n",
vid.width, vid.height);
vid.initialized = true;
vid.recalc_refdef = 1; // force a surface cache flush
}

View file

@ -83,7 +83,6 @@ static __attribute__ ((used)) const char rcsid[] =
int XShmGetEventBase (Display *x); // for broken X11 headers
static Colormap x_cmap;
static GC x_gc;
static qboolean doShm;
@ -384,32 +383,14 @@ x11_init_buffers (void)
vid.conrowbytes = vid.rowbytes;
}
/*
VID_Init
Set up color translation tables and the window. Takes a 256-color 8-bit
palette. Palette data will go away after the call, so copy it if you'll
need it later.
*/
void
VID_Init (byte *palette, byte *colormap)
static void
x11_choose_visual (void)
{
int pnum, i;
XVisualInfo template;
int num_visuals;
int template_mask;
VID_GetWindowSize (320, 200);
vid.numpages = 2;
vid.colormap8 = vid_colormap = colormap;
vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES];
srandom (getpid ());
// open the display
X11_OpenDisplay ();
template_mask = 0;
// specify a visual id
@ -428,6 +409,9 @@ VID_Init (byte *palette, byte *colormap)
// pick a visual -- warn if more than one was available
x_visinfo = XGetVisualInfo (x_disp, template_mask, &template,
&num_visuals);
if (x_visinfo->depth == 8 && x_visinfo->class == PseudoColor)
x_cmap = XCreateColormap (x_disp, x_win, x_vis, AllocAll);
x_vis = x_visinfo->visual;
if (num_visuals > 1) {
@ -462,27 +446,11 @@ VID_Init (byte *palette, byte *colormap)
x_visinfo->colormap_size);
Sys_MaskPrintf (SYS_VID, " bits_per_rgb %d\n",
x_visinfo->bits_per_rgb);
}
/* Setup attributes for main window */
X11_SetVidMode (vid.width, vid.height);
/* Create the main window */
X11_CreateWindow (vid.width, vid.height);
/* Invisible cursor */
X11_CreateNullCursor ();
if (x_visinfo->depth == 8) {
/* Create and upload the palette */
if (x_visinfo->class == PseudoColor) {
x_cmap = XCreateColormap (x_disp, x_win, x_vis, AllocAll);
VID_SetPalette (palette);
XSetWindowColormap (x_disp, x_win, x_cmap);
}
}
VID_InitGamma (palette);
VID_SetPalette (vid.palette);
static void
x11_create_context (void)
{
// create the GC
{
@ -518,8 +486,40 @@ VID_Init (byte *palette, byte *colormap)
// XSynchronize (x_disp, False);
// X11_AddEvent (x_shmeventtype, event_shm);
}
/*
VID_Init
Set up color translation tables and the window. Takes a 256-color 8-bit
palette. Palette data will go away after the call, so copy it if you'll
need it later.
*/
void
VID_Init (byte *palette, byte *colormap)
{
vid.numpages = 2;
vid.colormap8 = vid_colormap = colormap;
vid.fullbright = 256 - vid.colormap8[256 * VID_GRADES];
srandom (getpid ());
VID_GetWindowSize (320, 200);
X11_OpenDisplay ();
x11_choose_visual ();
X11_SetVidMode (vid.width, vid.height);
X11_CreateWindow (vid.width, vid.height);
X11_CreateNullCursor (); // hide mouse pointer
x11_create_context ();
VID_InitGamma (palette);
VID_SetPalette (vid.palette);
Sys_MaskPrintf (SYS_VID, "Video mode %dx%d initialized.\n",
vid.width, vid.height);
vid.initialized = true;
vid.recalc_refdef = 1; // force a surface cache flush
}
void