2001-04-15 06:43:11 +00:00
|
|
|
/*
|
|
|
|
vid.c
|
|
|
|
|
|
|
|
general video driver 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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-08-27 01:00:03 +00:00
|
|
|
|
2002-09-10 06:35:32 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-04-15 06:43:11 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2010-11-27 06:10:34 +00:00
|
|
|
#include "QF/console.h"
|
2001-04-15 06:43:11 +00:00
|
|
|
#include "QF/cvar.h"
|
2011-12-24 01:04:33 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-04-15 06:43:11 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/ui/view.h"
|
2001-08-27 01:00:03 +00:00
|
|
|
|
|
|
|
#include "compat.h"
|
2013-01-27 03:53:58 +00:00
|
|
|
#include "d_iface.h"
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
2001-04-15 06:43:11 +00:00
|
|
|
|
2001-08-27 01:00:03 +00:00
|
|
|
/* Software and hardware gamma support */
|
2013-01-16 02:23:47 +00:00
|
|
|
#define viddef (*r_data->vid)
|
2021-07-10 15:09:41 +00:00
|
|
|
#define vi (viddef.vid_internal)
|
[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
|
|
|
float vid_gamma;
|
|
|
|
static cvar_t vid_gamma_cvar = {
|
|
|
|
.name = "vid_gamma",
|
|
|
|
.description =
|
|
|
|
"Gamma correction",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &vid_gamma },
|
|
|
|
};
|
|
|
|
int vid_system_gamma;
|
|
|
|
static cvar_t vid_system_gamma_cvar = {
|
|
|
|
.name = "vid_system_gamma",
|
|
|
|
.description =
|
|
|
|
"Use system gamma control if available",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &vid_system_gamma },
|
|
|
|
};
|
|
|
|
int con_width;
|
|
|
|
static cvar_t con_width_cvar = {
|
|
|
|
.name = "con_width",
|
|
|
|
.description =
|
|
|
|
"console effective width (GL only)",
|
|
|
|
.default_value = 0,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = &cexpr_int, .value = &con_width },
|
|
|
|
};
|
|
|
|
int con_height;
|
|
|
|
static cvar_t con_height_cvar = {
|
|
|
|
.name = "con_height",
|
|
|
|
.description =
|
|
|
|
"console effective height (GL only)",
|
|
|
|
.default_value = 0,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = &cexpr_int, .value = &con_height },
|
|
|
|
};
|
2001-04-15 06:43:11 +00:00
|
|
|
qboolean vid_gamma_avail; // hardware gamma availability
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE unsigned int d_8to24table[256];
|
2002-06-18 21:41:24 +00:00
|
|
|
|
2001-08-27 01:00:03 +00:00
|
|
|
/* Screen size */
|
[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
|
|
|
int vid_width;
|
|
|
|
static cvar_t vid_width_cvar = {
|
|
|
|
.name = "vid_width",
|
|
|
|
.description =
|
|
|
|
"screen width",
|
|
|
|
.default_value = 0,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = &cexpr_int, .value = &vid_width },
|
|
|
|
};
|
|
|
|
int vid_height;
|
|
|
|
static cvar_t vid_height_cvar = {
|
|
|
|
.name = "vid_height",
|
|
|
|
.description =
|
|
|
|
"screen height",
|
|
|
|
.default_value = 0,
|
|
|
|
.flags = CVAR_ROM,
|
|
|
|
.value = { .type = &cexpr_int, .value = &vid_height },
|
|
|
|
};
|
|
|
|
|
|
|
|
int vid_fullscreen;
|
|
|
|
static cvar_t vid_fullscreen_cvar = {
|
|
|
|
.name = "vid_fullscreen",
|
|
|
|
.description =
|
|
|
|
"Toggles fullscreen mode",
|
|
|
|
.default_value = "0",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_int, .value = &vid_fullscreen },
|
|
|
|
};
|
2001-08-27 01:00:03 +00:00
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
static view_t conview;
|
|
|
|
|
2001-04-15 06:43:11 +00:00
|
|
|
void
|
|
|
|
VID_GetWindowSize (int def_w, int def_h)
|
|
|
|
{
|
2003-06-21 00:07:59 +00:00
|
|
|
int pnum, conheight;
|
2001-04-15 06:43:11 +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_width_cvar.default_value = nva ("%d", def_w);
|
|
|
|
vid_height_cvar.default_value = nva ("%d", def_h);
|
|
|
|
Cvar_Register (&vid_width_cvar, 0, 0);
|
|
|
|
Cvar_Register (&vid_height_cvar, 0, 0);
|
2001-04-15 06:43:11 +00:00
|
|
|
|
|
|
|
if ((pnum = COM_CheckParm ("-width"))) {
|
|
|
|
if (pnum >= com_argc - 1)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("VID: -width <width>");
|
2001-04-15 06:43:11 +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_width = atoi (com_argv[pnum + 1]);
|
|
|
|
if (!vid_width)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("VID: Bad window width");
|
2001-04-15 06:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((pnum = COM_CheckParm ("-height"))) {
|
|
|
|
if (pnum >= com_argc - 1)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("VID: -height <height>");
|
2001-04-15 06:43:11 +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_height = atoi (com_argv[pnum + 1]);
|
|
|
|
if (!vid_height)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("VID: Bad window height");
|
2001-04-15 06:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((pnum = COM_CheckParm ("-winsize"))) {
|
|
|
|
if (pnum >= com_argc - 2)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("VID: -winsize <width> <height>");
|
2001-04-15 06:43:11 +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_width = atoi (com_argv[pnum + 1]);
|
|
|
|
vid_height = atoi (com_argv[pnum + 2]);
|
2001-04-15 06:43:11 +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
|
|
|
if (!vid_width || !vid_height)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("VID: Bad window width/height");
|
2001-04-15 06:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-27 03:53:58 +00:00
|
|
|
// viddef.maxlowwidth = LOW_WIDTH;
|
|
|
|
// viddef.maxlowheight = LOW_HEIGHT;
|
|
|
|
|
[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
|
|
|
viddef.width = vid_width;
|
|
|
|
viddef.height = vid_height;
|
2021-07-10 09:04:34 +00:00
|
|
|
viddef.conview = &conview;
|
2003-03-17 05:17:58 +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
|
|
|
con_width_cvar.default_value = nva ("%d", vid_width);
|
|
|
|
Cvar_Register (&con_width_cvar, 0, 0);
|
2003-03-17 05:17:58 +00:00
|
|
|
if ((pnum = COM_CheckParm ("-conwidth"))) {
|
|
|
|
if (pnum >= com_argc - 1)
|
|
|
|
Sys_Error ("VID: -conwidth <width>");
|
[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
|
|
|
con_width = atoi(com_argv[pnum + 1]);
|
2003-03-17 05:17:58 +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
|
|
|
con_width = max (con_width & ~7, 320);
|
2009-12-21 12:36:12 +00:00
|
|
|
// make con_width a multiple of 8 and >= 320
|
[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
|
|
|
viddef.conview->xlen = con_width;
|
2003-07-27 20:20:20 +00:00
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
conheight = (viddef.conview->xlen * viddef.height) / viddef.width;
|
[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
|
|
|
con_height_cvar.default_value = nva ("%d", conheight);
|
|
|
|
Cvar_Register (&con_height_cvar, 0, 0);
|
2003-06-21 00:07:59 +00:00
|
|
|
if ((pnum = COM_CheckParm ("-conheight"))) {
|
|
|
|
if (pnum >= com_argc - 1)
|
|
|
|
Sys_Error ("VID: -conheight <width>");
|
[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
|
|
|
con_height = atoi (com_argv[pnum + 1]);
|
2003-06-21 00:07:59 +00:00
|
|
|
}
|
2009-12-21 12:36:12 +00:00
|
|
|
// make con_height >= 200
|
[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
|
|
|
con_height = max (con_height & ~7, 200);
|
|
|
|
viddef.conview->ylen = con_height;
|
2010-11-27 06:10:34 +00:00
|
|
|
|
|
|
|
Con_CheckResize (); // Now that we have a window size, fix console
|
2001-04-15 06:43:11 +00:00
|
|
|
}
|
|
|
|
|
2001-08-27 01:00:03 +00:00
|
|
|
/* GAMMA FUNCTIONS */
|
2001-04-15 06:43:11 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-04-15 06:43:11 +00:00
|
|
|
VID_BuildGammaTable (double gamma)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (gamma == 1.0) { // linear, don't bother with the math
|
|
|
|
for (i = 0; i < 256; i++) {
|
2012-02-26 05:00:15 +00:00
|
|
|
viddef.gammatable[i] = i;
|
2001-04-15 06:43:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
double g = 1.0 / gamma;
|
|
|
|
int v;
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) { // Build/update gamma lookup table
|
|
|
|
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
|
2012-02-26 05:00:15 +00:00
|
|
|
viddef.gammatable[i] = bound (0, v, 255);
|
2001-04-15 06:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[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_UpdateGamma (void)
|
2001-04-15 06:43:11 +00:00
|
|
|
{
|
2021-01-23 14:56:33 +00:00
|
|
|
byte *p24;
|
|
|
|
byte *p32;
|
2021-03-25 13:42:16 +00:00
|
|
|
const byte *col;
|
2021-01-23 14:56:33 +00:00
|
|
|
int i;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.recalc_refdef = 1; // force a surface cache flush
|
2001-05-24 15:48:39 +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
|
|
|
if (vid_gamma_avail && vid_system_gamma) { // Have system, use it
|
|
|
|
Sys_MaskPrintf (SYS_vid, "Setting hardware gamma to %g\n", vid_gamma);
|
2001-04-15 06:43:11 +00:00
|
|
|
VID_BuildGammaTable (1.0); // hardware gamma wants a linear palette
|
[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_SetGamma (vid_gamma);
|
2021-01-23 14:56:33 +00:00
|
|
|
p24 = viddef.palette;
|
|
|
|
p32 = viddef.palette32;
|
|
|
|
col = viddef.basepal;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
*p32++ = *p24++ = *col++;
|
|
|
|
*p32++ = *p24++ = *col++;
|
|
|
|
*p32++ = *p24++ = *col++;
|
|
|
|
*p32++ = 255;
|
|
|
|
}
|
|
|
|
p32[-1] = 0; // color 255 is transparent
|
2001-04-15 06:43:11 +00:00
|
|
|
} else { // We have to hack the palette
|
[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
|
|
|
Sys_MaskPrintf (SYS_vid, "Setting software gamma to %g\n", vid_gamma);
|
|
|
|
VID_BuildGammaTable (vid_gamma);
|
2021-01-23 14:56:33 +00:00
|
|
|
p24 = viddef.palette;
|
|
|
|
p32 = viddef.palette32;
|
|
|
|
col = viddef.basepal;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
*p32++ = *p24++ = viddef.gammatable[*col++];
|
|
|
|
*p32++ = *p24++ = viddef.gammatable[*col++];
|
|
|
|
*p32++ = *p24++ = viddef.gammatable[*col++];
|
|
|
|
*p32++ = 255;
|
|
|
|
}
|
|
|
|
p32[-1] = 0; // color 255 is transparent
|
2021-07-10 15:09:41 +00:00
|
|
|
// update with the new palette
|
|
|
|
vi->set_palette (vi->data, viddef.palette);
|
2001-04-15 06:43:11 +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
|
|
|
|
vid_gamma_f (void *data, const cvar_t *cvar)
|
|
|
|
{
|
|
|
|
vid_gamma = bound (0.1, vid_gamma, 9.9);
|
|
|
|
VID_UpdateGamma ();
|
|
|
|
}
|
|
|
|
|
2001-04-15 06:43:11 +00:00
|
|
|
/*
|
|
|
|
VID_InitGamma
|
|
|
|
|
|
|
|
Initialize the vid_gamma Cvar, and set up the palette
|
|
|
|
*/
|
|
|
|
void
|
2013-01-27 10:57:40 +00:00
|
|
|
VID_InitGamma (const byte *pal)
|
2001-04-15 06:43:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
2012-07-16 13:05:36 +00:00
|
|
|
double gamma = 1.0;
|
2001-04-15 06:43:11 +00:00
|
|
|
|
2012-02-26 05:00:15 +00:00
|
|
|
viddef.gammatable = malloc (256);
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.basepal = pal;
|
|
|
|
viddef.palette = malloc (256 * 3);
|
2021-01-23 14:56:33 +00:00
|
|
|
viddef.palette32 = malloc (256 * 4);
|
2001-04-15 06:43:11 +00:00
|
|
|
if ((i = COM_CheckParm ("-gamma"))) {
|
|
|
|
gamma = atof (com_argv[i + 1]);
|
|
|
|
}
|
|
|
|
gamma = bound (0.1, gamma, 9.9);
|
|
|
|
|
[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
|
|
|
Cvar_Register (&vid_gamma_cvar, vid_gamma_f, 0);
|
2001-04-15 06:43:11 +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_BuildGammaTable (vid_gamma);
|
2021-12-18 04:02:42 +00:00
|
|
|
|
|
|
|
if (viddef.onPaletteChanged) {
|
|
|
|
LISTENER_INVOKE (viddef.onPaletteChanged, &viddef);
|
|
|
|
}
|
2001-04-15 06:43:11 +00:00
|
|
|
}
|
2012-02-23 01:06:30 +00:00
|
|
|
|
2019-07-08 03:46:22 +00:00
|
|
|
void
|
|
|
|
VID_ClearMemory (void)
|
|
|
|
{
|
2021-07-10 15:09:41 +00:00
|
|
|
if (vi->flush_caches) {
|
|
|
|
vi->flush_caches (vi->data);
|
|
|
|
}
|
2012-02-23 01:06:30 +00:00
|
|
|
}
|
2021-12-18 04:02:42 +00:00
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
VID_OnPaletteChange_AddListener (viddef_listener_t listener, void *data)
|
|
|
|
{
|
|
|
|
if (!viddef.onPaletteChanged) {
|
|
|
|
viddef.onPaletteChanged = malloc (sizeof (*viddef.onPaletteChanged));
|
|
|
|
LISTENER_SET_INIT (viddef.onPaletteChanged, 8);
|
|
|
|
}
|
|
|
|
LISTENER_ADD (viddef.onPaletteChanged, listener, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
VID_OnPaletteChange_RemoveListener (viddef_listener_t listener, void *data)
|
|
|
|
{
|
|
|
|
if (viddef.onPaletteChanged) {
|
|
|
|
LISTENER_REMOVE (viddef.onPaletteChanged, listener, data);
|
|
|
|
}
|
|
|
|
}
|
[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
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
VID_Init (byte *palette, byte *colormap)
|
|
|
|
{
|
|
|
|
vid_system.init (palette, colormap);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vid_fullscreen_f (void *data, const cvar_t *var)
|
|
|
|
{
|
|
|
|
vid_system.update_fullscreen (vid_fullscreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
VISIBLE void
|
|
|
|
VID_Init_Cvars (void)
|
|
|
|
{
|
|
|
|
if (vid_system.update_fullscreen) {
|
|
|
|
// A bit of a hack, but windows registers a vid_fullscreen command
|
|
|
|
// and does fullscreen handling differently.
|
|
|
|
Cvar_Register (&vid_fullscreen_cvar, vid_fullscreen_f, 0);
|
|
|
|
}
|
|
|
|
Cvar_Register (&vid_system_gamma_cvar, 0, 0);
|
|
|
|
vid_system.init_cvars ();
|
|
|
|
}
|