2001-04-15 04:18:22 +00:00
|
|
|
/*
|
|
|
|
vid_x11.c
|
|
|
|
|
|
|
|
General X11 video driver
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999-2000 contributors of the QuakeForge project
|
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#define _BSD
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_VIDMODE
|
|
|
|
# include <X11/extensions/xf86vmode.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/qendian.h"
|
2001-04-15 08:04:15 +00:00
|
|
|
#include "QF/screen.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2012-02-14 10:47:02 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "compat.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "context_x11.h"
|
2003-01-06 18:28:13 +00:00
|
|
|
#include "d_iface.h"
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2019-07-08 04:40:29 +00:00
|
|
|
static vid_internal_t vid_internal;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
int VID_options_items = 1;
|
|
|
|
|
|
|
|
void
|
|
|
|
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
|
|
|
|
{
|
|
|
|
// direct drawing of the "accessing disk" icon isn't supported
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
D_EndDirectRect (int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
// direct drawing of the "accessing disk" icon isn't supported
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-03-05 07:56:09 +00:00
|
|
|
X11_VID_Shutdown (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
2023-03-05 07:56:09 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "X11_VID_shutdown\n");
|
2019-07-12 14:15:26 +00:00
|
|
|
X11_CloseDisplay ();
|
2023-03-06 12:15:15 +00:00
|
|
|
if (vid_internal.unload) {
|
|
|
|
vid_internal.unload (vid_internal.ctx);
|
|
|
|
}
|
2012-04-12 04:57:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 10:39:55 +00:00
|
|
|
static void
|
|
|
|
X11_VID_SetPalette (byte *palette, byte *colormap)
|
|
|
|
{
|
|
|
|
viddef.colormap8 = colormap;
|
|
|
|
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
|
|
|
|
if (vid_internal.set_colormap) {
|
2023-03-06 12:15:15 +00:00
|
|
|
vid_internal.set_colormap (vid_internal.ctx, colormap);
|
2022-11-14 10:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VID_InitGamma (palette);
|
2023-03-06 12:15:15 +00:00
|
|
|
vid_internal.set_palette (vid_internal.ctx, viddef.palette);
|
2022-11-14 10:39:55 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 05:53:47 +00:00
|
|
|
static void
|
|
|
|
X11_VID_SetCursor (bool visible)
|
|
|
|
{
|
|
|
|
XDefineCursor (x_disp, x_win, visible ? None : x_nullcursor);
|
|
|
|
}
|
|
|
|
|
2012-02-18 12:33:54 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static void
|
|
|
|
X11_VID_Init (byte *palette, byte *colormap)
|
2012-02-18 12:33:54 +00:00
|
|
|
{
|
2019-07-08 16:00:47 +00:00
|
|
|
vid_internal.gl_context = X11_GL_Context;
|
|
|
|
vid_internal.sw_context = X11_SW_Context;
|
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
vid_internal.vulkan_context = X11_Vulkan_Context;
|
|
|
|
#endif
|
2012-04-11 07:44:38 +00:00
|
|
|
|
2019-07-08 05:02:24 +00:00
|
|
|
R_LoadModule (&vid_internal);
|
2012-04-10 04:27:53 +00:00
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.numpages = 2;
|
2012-02-18 12:33:54 +00:00
|
|
|
|
|
|
|
srandom (getpid ());
|
|
|
|
|
2013-01-24 06:43:04 +00:00
|
|
|
VID_GetWindowSize (640, 480);
|
2012-02-18 12:33:54 +00:00
|
|
|
X11_OpenDisplay ();
|
2023-03-06 12:15:15 +00:00
|
|
|
vid_internal.choose_visual (vid_internal.ctx);
|
2012-02-14 10:47:02 +00:00
|
|
|
X11_SetVidMode (viddef.width, viddef.height);
|
|
|
|
X11_CreateWindow (viddef.width, viddef.height);
|
2012-02-18 12:33:54 +00:00
|
|
|
X11_CreateNullCursor (); // hide mouse pointer
|
2023-03-06 12:15:15 +00:00
|
|
|
vid_internal.create_context (vid_internal.ctx);
|
2012-02-18 12:33:54 +00:00
|
|
|
|
2022-11-14 10:39:55 +00:00
|
|
|
X11_VID_SetPalette (palette, colormap);
|
2012-02-18 12:33:54 +00:00
|
|
|
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_vid, "Video mode %dx%d initialized.\n",
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.width, viddef.height);
|
2001-05-25 04:03:47 +00:00
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.initialized = true;
|
|
|
|
viddef.recalc_refdef = 1; // force a surface cache flush
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static void
|
|
|
|
X11_VID_Init_Cvars (void)
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
X11_Init_Cvars ();
|
2019-07-08 16:00:47 +00:00
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
X11_Vulkan_Init_Cvars ();
|
|
|
|
#endif
|
|
|
|
X11_GL_Init_Cvars ();
|
2021-07-10 15:09:41 +00:00
|
|
|
X11_SW_Init_Cvars ();
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
vid_system_t vid_system = {
|
|
|
|
.init = X11_VID_Init,
|
2023-03-05 07:56:09 +00:00
|
|
|
.shutdown = X11_VID_Shutdown,
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
.init_cvars = X11_VID_Init_Cvars,
|
|
|
|
.update_fullscreen = X11_UpdateFullscreen,
|
2022-11-14 10:39:55 +00:00
|
|
|
.set_palette = X11_VID_SetPalette,
|
2023-06-30 05:53:47 +00:00
|
|
|
.set_cursor = X11_VID_SetCursor,
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
};
|
|
|
|
|
2019-07-08 16:00:47 +00:00
|
|
|
#if 0
|
2001-04-15 04:18:22 +00:00
|
|
|
static int config_notify = 0;
|
|
|
|
static int config_notify_width;
|
|
|
|
static int config_notify_height;
|
|
|
|
|
2019-07-08 16:00:47 +00:00
|
|
|
static void
|
|
|
|
update ()
|
2001-04-15 04:18:22 +00:00
|
|
|
{
|
|
|
|
/* If the window changes dimension, skip this frame. */
|
|
|
|
if (config_notify) {
|
|
|
|
fprintf (stderr, "config notify\n");
|
|
|
|
config_notify = 0;
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.width = config_notify_width & ~7;
|
|
|
|
viddef.height = config_notify_height;
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-04-16 19:25:55 +00:00
|
|
|
VID_InitBuffers ();
|
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.recalc_refdef = 1; /* force a surface cache flush */
|
2001-04-15 04:18:22 +00:00
|
|
|
Con_CheckResize ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-07-08 16:00:47 +00:00
|
|
|
#endif
|
2001-04-15 04:18:22 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-01-31 07:01:20 +00:00
|
|
|
X11_SetCaption (va (0, "%s: %s", PACKAGE_STRING, temp));
|
2001-04-15 04:18:22 +00:00
|
|
|
free (temp);
|
|
|
|
} else {
|
2021-01-31 07:01:20 +00:00
|
|
|
X11_SetCaption (va (0, "%s", PACKAGE_STRING));
|
2001-04-15 04:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-13 09:06:11 +00:00
|
|
|
bool
|
2001-04-15 04:18:22 +00:00
|
|
|
VID_SetGamma (double gamma)
|
|
|
|
{
|
|
|
|
return X11_SetGamma (gamma);
|
|
|
|
}
|