Hardware gamma support in QW. Currently, only -x11 and -glx will

build. Look at their vid files, as well as vid_common_{gl,sw}.c to find
out what will need to be added to the rest of the video targets.
This commit is contained in:
Jeff Teunissen 2001-04-11 07:16:34 +00:00
parent 43fd681809
commit 5cd24de097
13 changed files with 488 additions and 233 deletions

View file

@ -36,32 +36,35 @@
#include "QF/qtypes.h"
void GetEvent( void );
extern Display *x_disp;
extern int x_screen;
extern Window x_root;
extern XVisualInfo *x_visinfo;
extern Visual *x_vis;
extern Visual *x_vis;
extern Window x_root;
extern Window x_win;
extern qboolean doShm;
extern XVisualInfo *x_visinfo;
extern double x_gamma;
extern int x_screen;
extern int x_shmeventtype;
extern qboolean doShm;
extern qboolean oktodraw;
extern struct cvar_s *vid_fullscreen;
extern struct cvar_s *vid_fullscreen;
qboolean x11_add_event (int event, void (*event_handler)(XEvent *));
qboolean x11_del_event (int event, void (*event_handler)(XEvent *));
void x11_process_event (void);
void x11_process_events (void);
void x11_open_display (void);
void x11_close_display (void);
void x11_create_null_cursor (void);
void x11_set_vidmode (int, int);
void x11_restore_vidmode (void);
void x11_create_window (int, int);
void x11_grab_keyboard (void);
void x11_set_caption (char *);
void x11_force_view_port (void);
void x11_Init_Cvars (void);
void GetEvent (void);
double X11_GetGamma (void);
qboolean X11_AddEvent (int event, void (*event_handler)(XEvent *));
qboolean X11_RemoveEvent (int event, void (*event_handler)(XEvent *));
qboolean X11_SetGamma (double);
void X11_CloseDisplay (void);
void X11_CreateNullCursor (void);
void X11_CreateWindow (int, int);
void X11_ForceViewPort (void);
void X11_GrabKeyboard (void);
void X11_Init_Cvars (void);
void X11_OpenDisplay (void);
void X11_ProcessEvent (void);
void X11_ProcessEvents (void);
void X11_RestoreVidMode (void);
void X11_SetCaption (char *);
void X11_SetVidMode (int, int);
#endif // __context_x11_h_

View file

@ -63,8 +63,10 @@ typedef struct {
extern viddef_t vid; // global video state
extern unsigned short d_8to16table[256];
extern unsigned int d_8to24table[256];
extern int scr_width, scr_height;
extern qboolean DDActive;
extern int scr_width, scr_height;
extern qboolean DDActive;
extern byte gammatable[256];
// called at startup and after any gamma correction
void VID_SetPalette (unsigned char *palette);
@ -108,4 +110,9 @@ void VID_GetWindowSize (int def_w, int def_h);
int VID_ForceUnlockedAndReturnState (void);
void VID_ForceLockState (int lk);
void VID_InitGamma (unsigned char *);
double VID_GetGamma (void);
qboolean VID_SetGamma (double);
void VID_UpdateGamma (struct cvar_s *);
#endif // __vid_h_

View file

@ -173,7 +173,7 @@ qw_client_fbdev_DEPENDENCIES= $(CLIENT_LIB_DEPS)
#
# ... SciTech MGL
#
mgl_SOURCES= vid_mgl.c in_win.c
mgl_SOURCES= in_win.c vid_common_sw.c vid_mgl.c
qw_client_mgl_SOURCES= $(common_SOURCES) $(client_SOURCES) $(soft_SOURCES) $(mgl_SOURCES)
qw_client_mgl_LDADD= $(MGL_LIBS) $(CLIENT_LIBS)
@ -182,7 +182,7 @@ qw_client_mgl_DEPENDENCIES= $(CLIENT_LIB_DEPS)
#
# ... Sam Lantinga's Simple DirectMedia Layer, version 1.0 and higher
#
sdl_SOURCES= vid_sdl.c in_sdl.c
sdl_SOURCES= in_sdl.c vid_common_sw.c vid_sdl.c
qw_client_sdl_SOURCES= $(common_SOURCES) $(client_SOURCES) $(soft_SOURCES) $(sdl_SOURCES)
qw_client_sdl_LDADD= $(SDL_LIBS) $(CLIENT_LIBS)
@ -191,7 +191,7 @@ qw_client_sdl_DEPENDENCIES= $(CLIENT_LIB_DEPS)
#
# ... Linux SVGAlib
#
svga_SOURCES= d_copy.S vid_svgalib.c in_svgalib.c
svga_SOURCES= d_copy.S in_svgalib.c vid_common_sw.c vid_svgalib.c
qw_client_svga_SOURCES= $(common_SOURCES) $(client_SOURCES) $(soft_SOURCES) $(svga_SOURCES)
qw_client_svga_LDADD= $(SVGA_LIBS) $(CLIENT_LIBS)
@ -200,7 +200,7 @@ qw_client_svga_DEPENDENCIES= $(CLIENT_LIB_DEPS)
#
# ... X11
#
x11_SOURCES= vid_x11.c in_x11.c context_x11.c dga_check.c
x11_SOURCES= context_x11.c dga_check.c in_x11.c vid_common_sw.c vid_x11.c
qw_client_x11_SOURCES= $(common_SOURCES) $(client_SOURCES) $(soft_SOURCES) $(x11_SOURCES)
qw_client_x11_LDADD= $(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) $(X_SHM_LIB) $(CLIENT_LIBS)

View file

@ -72,47 +72,51 @@
#include "vid.h"
static void (*event_handlers[LASTEvent]) (XEvent *);
qboolean oktodraw = false;
int x_shmeventtype;
qboolean oktodraw = false;
int x_shmeventtype;
static int x_disp_ref_count = 0;
static int x_disp_ref_count = 0;
Display *x_disp = NULL;
int x_screen;
Window x_root = None;
Display *x_disp = NULL;
int x_screen;
Window x_root = None;
XVisualInfo *x_visinfo;
Visual *x_vis;
Window x_win;
Cursor nullcursor = None;
Visual *x_vis;
Window x_win;
Cursor nullcursor = None;
static Atom aWMDelete = 0;
#define X_MASK (VisibilityChangeMask | StructureNotifyMask | ExposureMask)
#ifdef HAVE_VIDMODE
static XF86VidModeModeInfo **vidmodes;
static int nummodes;
static int nummodes;
static int original_mode = 0;
#endif
static qboolean vidmode_avail = false;
static qboolean vidmode_active = false;
cvar_t *vid_fullscreen;
qboolean vid_fullscreen_active;
cvar_t *vid_fullscreen;
cvar_t *vid_system_gamma;
qboolean vid_gamma_avail;
qboolean vid_fullscreen_active;
static double x_gamma;
static int xss_timeout;
static int xss_interval;
static int xss_blanking;
static int xss_exposures;
static int xss_timeout;
static int xss_interval;
static int xss_blanking;
static int xss_exposures;
qboolean
x11_add_event (int event, void (*event_handler) (XEvent *))
X11_AddEvent (int event, void (*event_handler) (XEvent *))
{
if (event >= LASTEvent) {
printf ("event: %d, LASTEvent: %d\n", event, LASTEvent);
return false;
}
if (event_handlers[event] != NULL)
if (event_handlers[event])
return false;
event_handlers[event] = event_handler;
@ -120,10 +124,11 @@ x11_add_event (int event, void (*event_handler) (XEvent *))
}
qboolean
x11_del_event (int event, void (*event_handler) (XEvent *))
X11_RemoveEvent (int event, void (*event_handler) (XEvent *))
{
if (event >= LASTEvent)
return false;
if (event_handlers[event] != event_handler)
return false;
@ -132,7 +137,7 @@ x11_del_event (int event, void (*event_handler) (XEvent *))
}
void
x11_process_event (void)
X11_ProcessEvent (void)
{
XEvent x_event;
@ -148,11 +153,11 @@ x11_process_event (void)
}
void
x11_process_events (void)
X11_ProcessEvents (void)
{
/* Get events from X server. */
while (XPending (x_disp)) {
x11_process_event ();
X11_ProcessEvent ();
}
}
@ -172,12 +177,12 @@ TragicDeath (int sig)
}
void
x11_open_display (void)
X11_OpenDisplay (void)
{
if (!x_disp) {
x_disp = XOpenDisplay (NULL);
if (!x_disp) {
Sys_Error ("x11_open_display: Could not open display [%s]\n",
Sys_Error ("X11_OpenDisplay: Could not open display [%s]\n",
XDisplayName (NULL));
}
@ -192,7 +197,7 @@ x11_open_display (void)
signal (SIGTRAP, TragicDeath);
signal (SIGIOT, TragicDeath);
signal (SIGBUS, TragicDeath);
/* signal(SIGFPE, TragicDeath); */
// signal(SIGFPE, TragicDeath);
signal (SIGSEGV, TragicDeath);
signal (SIGTERM, TragicDeath);
@ -206,7 +211,7 @@ x11_open_display (void)
}
void
x11_close_display (void)
X11_CloseDisplay (void)
{
if (nullcursor != None) {
XFreeCursor (x_disp, nullcursor);
@ -220,17 +225,17 @@ x11_close_display (void)
}
/*
x11_create_null_cursor
X11_CreateNullCursor
Create an empty cursor
Create an empty cursor (in other words, make it disappear)
*/
void
x11_create_null_cursor (void)
X11_CreateNullCursor (void)
{
Pixmap cursormask;
XGCValues xgc;
GC gc;
XColor dummycolour;
Pixmap cursormask;
XGCValues xgc;
GC gc;
XColor dummycolour;
if (nullcursor != None)
return;
@ -253,7 +258,7 @@ x11_create_null_cursor (void)
}
void
x11_set_vidmode (int width, int height)
X11_SetVidMode (int width, int height)
{
const char *str = getenv ("MESA_GLX_FX");
@ -267,6 +272,10 @@ x11_set_vidmode (int width, int height)
#ifdef HAVE_VIDMODE
vidmode_avail = VID_CheckVMode (x_disp, NULL, NULL);
if (vidmode_avail) {
vid_gamma_avail = ((x_gamma = X11_GetGamma ()) > 0);
}
if (vid_fullscreen->int_val && vidmode_avail) {
int i, dotclock;
@ -299,25 +308,27 @@ x11_set_vidmode (int width, int height)
XSetScreenSaver (x_disp, 0, xss_interval, xss_blanking, xss_exposures);
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[best_mode]);
x11_force_view_port ();
X11_ForceViewPort ();
vidmode_active = true;
} else {
Con_Printf ("VID: Mode %dx%d can't go fullscreen.\n", vid.width, vid.height);
vidmode_avail = vidmode_active = false;
vid_gamma_avail = vidmode_avail = vidmode_active = false;
}
}
#endif
}
void
x11_Init_Cvars (void)
X11_Init_Cvars (void)
{
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ROM, NULL,
"Toggles fullscreen game mode");
vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL,
"Use system gamma control if available");
}
void
x11_create_window (int width, int height)
X11_CreateWindow (int width, int height)
{
XSetWindowAttributes attr;
XClassHint *ClassHint;
@ -354,7 +365,7 @@ x11_create_window (int width, int height)
XFree (SizeHints);
}
// Set window title
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
// Set icon name
XSetIconName (x_disp, x_win, PROGRAM);
@ -377,7 +388,7 @@ x11_create_window (int width, int height)
XMoveWindow (x_disp, x_win, 0, 0);
XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0,
vid.width + 2, vid.height + 2);
x11_force_view_port ();
X11_ForceViewPort ();
}
XMapWindow (x_disp, x_win);
@ -388,13 +399,14 @@ x11_create_window (int width, int height)
}
void
x11_restore_vidmode (void)
X11_RestoreVidMode (void)
{
XSetScreenSaver (x_disp, xss_timeout, xss_interval, xss_blanking,
xss_exposures);
#ifdef HAVE_VIDMODE
if (vidmode_active) {
X11_SetGamma (x_gamma);
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[original_mode]);
XFree (vidmodes);
}
@ -402,7 +414,7 @@ x11_restore_vidmode (void)
}
void
x11_grab_keyboard (void)
X11_GrabKeyboard (void)
{
#ifdef HAVE_VIDMODE
if (vidmode_active && vid_fullscreen->int_val) {
@ -413,14 +425,14 @@ x11_grab_keyboard (void)
}
void
x11_set_caption (char *text)
X11_SetCaption (char *text)
{
if (x_disp && x_win && text)
XStoreName (x_disp, x_win, text);
}
void
x11_force_view_port (void)
X11_ForceViewPort (void)
{
#ifdef HAVE_VIDMODE
int x, y;
@ -434,3 +446,37 @@ x11_force_view_port (void)
}
#endif
}
double
X11_GetGamma (void)
{
#ifdef HAVE_VIDMODE
# ifdef X_XF86VidModeGetGamma
XF86VidModeGamma xgamma;
if (vidmode_avail && vid_system_gamma->int_val) {
if (XF86VidModeGetGamma (x_disp, x_screen, &xgamma)) {
return ((xgamma.red + xgamma.green + xgamma.blue) / 3);
}
}
# endif
#endif
return -1.0;
}
qboolean
X11_SetGamma (double gamma)
{
#ifdef HAVE_VIDMODE
# ifdef X_XF86VidModeSetGamma
XF86VidModeGamma xgamma;
if (vidmode_avail && vid_system_gamma->int_val) {
xgamma.red = xgamma.green = xgamma.blue = (float) gamma;
if (XF86VidModeSetGamma (x_disp, x_screen, &xgamma))
return true;
}
# endif
#endif
return false;
}

View file

@ -40,20 +40,22 @@
#include <stdio.h>
#include <stdlib.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/mathlib.h"
#include "QF/qargs.h"
#include "QF/sound.h"
#include "QF/sys.h"
#include "bothdefs.h"
#include "cl_cam.h"
#include "cl_main.h"
#include "cl_parse.h" //FIXME CL_NewTranslation
#include "QF/compat.h"
#include "QF/console.h"
#include "locs.h"
#include "commdef.h"
#include "glquake.h"
#include "QF/mathlib.h"
#include "QF/qargs.h"
#include "locs.h"
#include "r_dynamic.h"
#include "skin.h"
#include "QF/sound.h"
#include "QF/sys.h"
#include "vid.h"
#include "view.h"
entity_t r_worldentity;
@ -190,7 +192,7 @@ GL_CheckBrightness (unsigned char *pal)
/*
R_CullBox
Returns true if the box is completely outside the frustom
Returns true if the box is completely outside the frustum
*/
/*
qboolean R_CullBox (vec3_t mins, vec3_t maxs)

View file

@ -427,7 +427,7 @@ void
IN_SendKeyEvents (void)
{
/* Get events from X server. */
x11_process_events ();
X11_ProcessEvents ();
}
@ -488,7 +488,7 @@ IN_Shutdown (void)
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
#endif
}
x11_close_display ();
X11_CloseDisplay ();
}
void
@ -506,11 +506,11 @@ IN_Init (void)
if (!x_win)
Sys_Error ("IN: No window!!\n");
x11_open_display (); // call to increment the reference
// counter
X11_OpenDisplay (); // call to increment the reference counter
{
int attribmask = CWEventMask;
int attribmask = CWEventMask;
XWindowAttributes attribs_1;
XSetWindowAttributes attribs_2;
@ -537,11 +537,11 @@ IN_Init (void)
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
x11_add_event (KeyPress, &event_key);
x11_add_event (KeyRelease, &event_key);
x11_add_event (ButtonPress, &event_button);
x11_add_event (ButtonRelease, &event_button);
x11_add_event (MotionNotify, &event_motion);
X11_AddEvent (KeyPress, &event_key);
X11_AddEvent (KeyRelease, &event_key);
X11_AddEvent (ButtonPress, &event_button);
X11_AddEvent (ButtonRelease, &event_button);
X11_AddEvent (MotionNotify, &event_motion);
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
}

View file

@ -81,7 +81,7 @@ extern int in_forward, in_forward2, in_back;
frame_t *view_frame;
player_state_t *view_message;
void BuildGammaTable (float, float);
void BuildGammaTable (float, float);
/*
V_CalcRoll
@ -256,15 +256,15 @@ extern cvar_t *cl_cshift_contents;
extern cvar_t *cl_cshift_damage;
// extern cvar_t *cl_cshift_powerup;
cshift_t cshift_empty = { {130, 80, 50}, 0 };
cshift_t cshift_water = { {130, 80, 50}, 128 };
cshift_t cshift_slime = { {0, 25, 5}, 150 };
cshift_t cshift_lava = { {255, 80, 0}, 150 };
cshift_t cshift_empty = { {130, 80, 50}, 0 };
cshift_t cshift_water = { {130, 80, 50}, 128 };
cshift_t cshift_slime = { {0, 25, 5}, 150 };
cshift_t cshift_lava = { {255, 80, 0}, 150 };
cvar_t *brightness;
cvar_t *contrast;
cvar_t *brightness;
cvar_t *contrast;
byte gammatable[256]; // palette is sent through this
extern byte gammatable[256]; // palette is sent through this
/*
V_CheckGamma
@ -272,18 +272,23 @@ byte gammatable[256]; // palette is sent through this
qboolean
V_CheckGamma (void)
{
static float oldbrightness;
static float oldcontrast;
#if 0
static float oldbrightness;
static float oldcontrast;
if ((brightness->value == oldbrightness) && contrast->value == oldcontrast)
return false;
oldbrightness = brightness->value;
oldcontrast = contrast->value;
BuildGammaTable (brightness->value, contrast->value);
vid.recalc_refdef = 1; // force a surface cache flush
vid.recalc_refdef = 1; // force a surface cache flush
return true;
#else
return false;
#endif
}
/*

View file

@ -30,11 +30,11 @@
# include "config.h"
#endif
#include "QF/compat.h"
#include "bothdefs.h"
#include "host.h"
#include "r_local.h"
#include "view.h"
#include "QF/compat.h"
extern cvar_t *cl_cshift_powerup;
@ -157,6 +157,7 @@ V_UpdatePalette (void)
void
BuildGammaTable (float b, float c)
{
#if 0
int i, inf;
// int p = (int) c;
@ -167,8 +168,9 @@ BuildGammaTable (float b, float c)
}
for (i = 0; i < 256; i++) { // weighted average toward the median, 127
inf = (i * b); // gamma is brightness now, and positive
inf = (i * b); // gamma is brightness now, and positive
inf = bound (0, inf, 255);
gammatable[i] = inf + (int) ((127 - inf) * (1 - c));
}
#endif
}

View file

@ -42,6 +42,8 @@ int scr_width, scr_height;
cvar_t *vid_width;
cvar_t *vid_height;
byte gammatable[256];
void
VID_GetWindowSize (int def_w, int def_h)
{
@ -91,26 +93,27 @@ VID_GetWindowSize (int def_w, int def_h)
}
#if 0
VID_Calc_Gamma (void)
void
VID_CalcGamma (double gamma)
{
float f;
int i;
int v;
byte
float g = bound (0.3, gamma->value, 3);
int i;
int v;
double g = bound (0.3, gamma, 3);
Cvar_SetValue (gamma, g);
if (gamma_flipped->int_val)
g = 1 / g;
for (i = 0; i < 256; i++) {
f = pow ((i + 1) / 256.0, g);
v = f * 255 + 0.5;
lightmap_gamma[i] = bound (0, v, 255);
for (j = 0; j < 3; j++) {
f = pow ((host_basepal[i * 3 + j] + 1) / 256.0, g);
v = f * 255 + 0.5;
palette[i] = bound (0, v, 255);
if (!(gamma_flipped->int_val))
g = 1.0 / g;
if (g == 1.0) {
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
}
for (i = 0; i < 256; i++) {
v = (int) (255.0 * pow ((double) i / 255.0, g));
gammatable[i] = bound (0, v, 255);
}
}
#endif

View file

@ -46,11 +46,11 @@
#include "QF/compat.h"
#include "QF/console.h"
#include "glquake.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "qfgl_ext.h"
#include "QF/quakefs.h"
#include "glquake.h"
#include "qfgl_ext.h"
#include "sbar.h"
#define WARP_WIDTH 320
@ -61,6 +61,7 @@ unsigned int d_8to24table[256];
unsigned char d_15to8table[65536];
cvar_t *vid_mode;
extern byte gammatable[256];
/*-----------------------------------------------------------------------*/
@ -79,8 +80,10 @@ GLenum gl_mtex_enum = GL_TEXTURE0_ARB;
QF_glColorTableEXT qglColorTableEXT = NULL;
qboolean is8bit = false;
cvar_t *vid_use8bit;
cvar_t *vid_gamma;
extern int gl_filter_min, gl_filter_max;
extern int gl_filter_min, gl_filter_max;
extern cvar_t *vid_system_gamma;
/*-----------------------------------------------------------------------*/
@ -117,6 +120,56 @@ CheckMultiTextureExtensions (void)
}
}
/*
VID_InitGamma
Initialize the gamma lookup table
This function does some nasty things to Cvars, but at least we have the
excuse that it has to.
*/
void
VID_InitGamma (unsigned char *pal)
{
int i;
double gamma;
vid_gamma = Cvar_Get ("vid_gamma", "1.45", CVAR_ARCHIVE, VID_UpdateGamma,
"Gamma correction");
if ((i = COM_CheckParm ("-gamma"))) {
gamma = atof (com_argv[i + 1]);
} else {
gamma = vid_gamma->value;
}
gamma = bound (0.1, gamma, 9.9);
Cvar_SetValue (vid_gamma, gamma);
if (gamma == 1.0) { // screw the math, 1.0 is linear
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
} else {
if (vid_system_gamma->int_val) {
VID_SetGamma (gamma);
} else {
double g = 1.0 / gamma;
int v;
Cvar_SetFlags (vid_gamma, vid_gamma->flags | CVAR_ROM);
for (i = 0; i < 256; i++) { // Create the gamma-correction table
v = (int) (255.0 * pow ((double) i / 255.0, g));
gammatable[i] = bound (0, v, 255);
}
}
}
for (i = 0; i < 768; i++) { // correct the palette
pal[i] = gammatable[pal[i]];
}
}
void
VID_SetPalette (unsigned char *palette)
{
@ -139,8 +192,7 @@ VID_SetPalette (unsigned char *palette)
pal = palette;
table = d_8to24table;
for (i = 0; i < 255; i++) { // used to be i<256, see d_8to24table
// below
for (i = 0; i < 255; i++) { // used to be i<256, see d_8to24table below
r = pal[0];
g = pal[1];
b = pal[2];
@ -153,7 +205,7 @@ VID_SetPalette (unsigned char *palette)
#endif
*table++ = v;
}
d_8to24table[255] = 0; // 255 is transparent
d_8to24table[255] = 0; // 255 is transparent
// JACK: 3D distance calcs - k is last closest, l is the distance.
// FIXME: Precalculate this and cache to disk.
@ -167,9 +219,12 @@ VID_SetPalette (unsigned char *palette)
Qclose (f);
} else {
for (i = 0; i < (1 << 15); i++) {
/* Maps 000000000000000 000000000011111 = Red = 0x1F
000001111100000 = Blue = 0x03E0 111110000000000 = Grn =
0x7C00 */
/* Maps
000000000000000
000000000011111 = Red = 0x1F
000001111100000 = Blue = 0x03E0
111110000000000 = Grn = 0x7C00
*/
r = ((i & 0x1F) << 3) + 4;
g = ((i & 0x03E0) >> 2) + 4;
b = ((i & 0x7C00) >> 7) + 4;
@ -344,9 +399,8 @@ Shared_Init8bitPalette (void)
void
VID_Init8bitPalette (void)
{
vid_use8bit =
Cvar_Get ("vid_use8bit", "0", CVAR_ROM, NULL,
"Use 8-bit shared palettes.");
vid_use8bit = Cvar_Get ("vid_use8bit", "0", CVAR_ROM, NULL,
"Use 8-bit shared palettes.");
Con_Printf ("Checking for 8-bit extension: ");
if (vid_use8bit->int_val) {

133
qw/source/vid_common_sw.c Normal file
View file

@ -0,0 +1,133 @@
/*
vid_common_sw.c
Common software video driver functions
Copyright (C) 2001 Jeff Teunissen <deek@quakeforge.net>
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <math.h>
#include "QF/cvar.h"
#include "QF/compat.h"
#include "QF/qargs.h"
#include "vid.h"
#include "view.h"
extern byte gammatable[256];
extern cvar_t *vid_system_gamma;
extern qboolean vid_gamma_avail; // hardware gamma availability
cvar_t *vid_gamma;
/*
VID_InitGamma
Initialize the gamma lookup table
This function is less complex than the GL version.
*/
void
VID_InitGamma (unsigned char *pal)
{
int i;
double gamma;
vid_gamma = Cvar_Get ("vid_gamma", "1.45", CVAR_ARCHIVE, VID_UpdateGamma,
"Gamma correction");
if ((i = COM_CheckParm ("-gamma"))) {
gamma = atof (com_argv[i + 1]);
} else {
gamma = vid_gamma->value;
}
gamma = bound (0.1, gamma, 9.9);
Cvar_SetValue (vid_gamma, gamma);
if (gamma == 1.0) { // screw the math, 1.0 is linear
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
} else {
if (vid_system_gamma->int_val) {
VID_SetGamma (gamma);
} else {
double g = 1.0 / gamma;
int v;
for (i = 0; i < 256; i++) { // Create the gamma-correction table
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
gammatable[i] = bound (0, v, 255);
}
}
}
for (i = 0; i < 768; i++) { // correct the palette
pal[i] = gammatable[pal[i]];
}
}
/*
VID_UpdateGamma
This is a callback to update the palette or system gamma whenever the
vid_gamma Cvar is changed.
*/
void
VID_UpdateGamma (cvar_t *vid_gamma)
{
int i;
if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable
return;
Cvar_SetValue (vid_gamma, bound (0.1, vid_gamma->value, 9.9));
if (vid_gamma_avail && vid_system_gamma->int_val) { // Have sys gamma, use it
for (i = 0; i < 256; i++) { // linear, to keep things kosher
gammatable[i] = i;
}
VID_SetGamma (vid_gamma->value);
} else { // We have to hack the palette
if (vid_gamma->value == 1.0) { // screw the math, 1.0 is linear
for (i = 0; i < 256; i++) {
gammatable[i] = i;
}
} else {
double g = 1.0 / vid_gamma->value;
int v;
for (i = 0; i < 256; i++) { // Update the gamma LUT
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
gammatable[i] = bound (0, v, 255);
}
}
V_UpdatePalette (); // update with the new palette
}
}

View file

@ -83,8 +83,8 @@ VID_Shutdown (void)
Con_Printf ("VID_Shutdown\n");
x11_restore_vidmode ();
x11_close_display ();
X11_RestoreVidMode ();
X11_CloseDisplay ();
}
#if 0
@ -171,7 +171,7 @@ VID_Init (unsigned char *palette)
vid.conheight = atoi (com_argv[i + 1]);
vid.conheight = max (vid.conheight, 200);
x11_open_display ();
X11_OpenDisplay ();
x_visinfo = glXChooseVisual (x_disp, x_screen, attrib);
if (!x_visinfo) {
@ -181,12 +181,12 @@ VID_Init (unsigned char *palette)
}
x_vis = x_visinfo->visual;
x11_set_vidmode (scr_width, scr_height);
x11_create_window (scr_width, scr_height);
X11_SetVidMode (scr_width, scr_height);
X11_CreateWindow (scr_width, scr_height);
/* Invisible cursor */
x11_create_null_cursor ();
X11_CreateNullCursor ();
x11_grab_keyboard ();
X11_GrabKeyboard ();
XSync (x_disp, 0);
@ -205,6 +205,7 @@ VID_Init (unsigned char *palette)
GL_Init ();
GL_CheckBrightness (palette);
VID_InitGamma (palette);
VID_SetPalette (palette);
// Check for 8-bit extension and initialize if present
@ -220,18 +221,41 @@ VID_Init (unsigned char *palette)
void
VID_Init_Cvars ()
{
x11_Init_Cvars ();
X11_Init_Cvars ();
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
char *temp = strdup (text);
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
X11_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
}
}
double
VID_GetGamma (void)
{
return (double) X11_GetGamma ();
}
qboolean
VID_SetGamma (double gamma)
{
return X11_SetGamma (gamma);
}
void
VID_UpdateGamma (cvar_t *vid_gamma)
{
if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable
return;
Cvar_SetValue (vid_gamma, bound (0.1, vid_gamma->value, 9.9));
X11_SetGamma (vid_gamma->value);
}

View file

@ -65,54 +65,54 @@
# include <X11/extensions/xf86vmode.h>
#endif
#include "client.h"
#include "QF/cmd.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "context_x11.h"
#include "QF/cvar.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "client.h"
#include "context_x11.h"
#include "d_local.h"
#include "dga_check.h"
#include "draw.h"
#include "host.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "screen.h"
#include "QF/sys.h"
#include "QF/va.h"
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
static Colormap x_cmap;
static GC x_gc;
static GC x_gc;
int XShmQueryExtension (Display *);
int XShmGetEventBase (Display *);
int XShmQueryExtension (Display *);
int XShmGetEventBase (Display *);
static qboolean doShm;
static XShmSegmentInfo x_shminfo[2];
static int current_framebuffer;
static int current_framebuffer;
static XImage *x_framebuffer[2] = { 0, 0 };
static int verbose = 0;
static int verbose = 0;
int VID_options_items = 1;
int VID_options_items = 1;
static byte current_palette[768];
typedef unsigned short PIXEL16;
typedef unsigned long PIXEL24;
static PIXEL16 st2d_8to16table[256];
static PIXEL24 st2d_8to24table[256];
static int shiftmask_fl = 0;
static long r_shift, g_shift, b_shift;
static PIXEL16 st2d_8to16table[256];
static PIXEL24 st2d_8to24table[256];
static int shiftmask_fl = 0;
static long r_shift, g_shift, b_shift;
static unsigned long r_mask, g_mask, b_mask;
cvar_t *vid_width;
cvar_t *vid_height;
cvar_t *vid_width;
cvar_t *vid_height;
static void
shiftmask_init (void)
@ -135,7 +135,7 @@ shiftmask_init (void)
static PIXEL16
xlib_rgb16 (int r, int g, int b)
{
PIXEL16 p = 0;
PIXEL16 p = 0;
if (!shiftmask_fl)
shiftmask_init ();
@ -174,10 +174,10 @@ xlib_rgb16 (int r, int g, int b)
}
static PIXEL24
static PIXEL24
xlib_rgb24 (int r, int g, int b)
{
PIXEL24 p = 0;
PIXEL24 p = 0;
if (!shiftmask_fl)
shiftmask_init ();
@ -216,11 +216,11 @@ xlib_rgb24 (int r, int g, int b)
}
static void
st2_fixup (XImage * framebuf, int x, int y, int width, int height)
st2_fixup (XImage *framebuf, int x, int y, int width, int height)
{
int xi, yi;
int xi, yi;
unsigned char *src;
PIXEL16 *dest;
PIXEL16 *dest;
if (x < 0 || y < 0)
return;
@ -238,9 +238,9 @@ st2_fixup (XImage * framebuf, int x, int y, int width, int height)
static void
st3_fixup (XImage * framebuf, int x, int y, int width, int height)
{
int yi;
int yi;
unsigned char *src;
PIXEL24 *dest;
PIXEL24 *dest;
register int count, n;
if (x < 0 || y < 0)
@ -276,9 +276,9 @@ st3_fixup (XImage * framebuf, int x, int y, int width, int height)
} while (--n > 0);
}
// for(xi = (x+width-1); xi >= x; xi--) {
// dest[xi] = st2d_8to16table[src[xi]];
// }
// for(xi = (x+width-1); xi >= x; xi--) {
// dest[xi] = st2d_8to16table[src[xi]];
// }
}
}
@ -286,7 +286,7 @@ st3_fixup (XImage * framebuf, int x, int y, int width, int height)
D_BeginDirectRect
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{
// direct drawing of the "accessing disk" icon isn't supported
}
@ -302,38 +302,6 @@ D_EndDirectRect (int x, int y, int width, int height)
}
/*
VID_Gamma_f
Keybinding command
*/
byte vid_gamma[256];
void
VID_Gamma_f (void)
{
float g, f, inf;
int i;
if (Cmd_Argc () == 2) {
g = atof (Cmd_Argv (1));
for (i = 0; i < 255; i++) {
f = pow ((i + 1) / 256.0, g);
inf = f * 255 + 0.5;
inf = bound (0, inf, 255);
vid_gamma[i] = inf;
}
VID_SetPalette (current_palette);
vid.recalc_refdef = 1; // force a surface cache flush
}
}
static void
ResetFrameBuffer (void)
{
@ -394,13 +362,13 @@ ResetFrameBuffer (void)
static void
ResetSharedFrameBuffers (void)
{
int tbuffersize, tcachesize;
void *vid_surfcache;
int tbuffersize, tcachesize;
void *vid_surfcache;
int size;
int key;
int minsize = getpagesize ();
int frm;
int size;
int key;
int minsize = getpagesize ();
int frm;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
@ -499,11 +467,6 @@ VID_Init (unsigned char *palette)
VID_GetWindowSize (320, 200);
// plugin_load ("in_x11.so");
// Cmd_AddCommand ("gamma", VID_Gamma_f, "Change brightness level");
for (i = 0; i < 256; i++)
vid_gamma[i] = i;
vid.width = vid_width->int_val;
vid.height = vid_height->int_val;
Con_CheckResize (); // Now that we have a window size, fix console
@ -519,7 +482,7 @@ VID_Init (unsigned char *palette)
verbose = COM_CheckParm ("-verbose");
// open the display
x11_open_display ();
X11_OpenDisplay ();
template_mask = 0;
@ -567,14 +530,15 @@ VID_Init (unsigned char *palette)
}
/* Setup attributes for main window */
x11_set_vidmode (vid.width, vid.height);
X11_SetVidMode (vid.width, vid.height);
/* Create the main window */
x11_create_window (vid.width, vid.height);
X11_CreateWindow (vid.width, vid.height);
/* Invisible cursor */
x11_create_null_cursor ();
X11_CreateNullCursor ();
VID_InitGamma (palette);
if (x_visinfo->depth == 8) {
/* Create and upload the palette */
if (x_visinfo->class == PseudoColor) {
@ -592,11 +556,11 @@ VID_Init (unsigned char *palette)
x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues);
}
x11_grab_keyboard ();
X11_GrabKeyboard ();
// wait for first exposure event
{
XEvent event;
XEvent event;
do {
XNextEvent (x_disp, &event);
@ -640,13 +604,13 @@ VID_Init (unsigned char *palette)
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
// XSynchronize (x_disp, False);
x11_add_event (x_shmeventtype, event_shm);
X11_AddEvent (x_shmeventtype, event_shm);
}
void
VID_Init_Cvars ()
{
x11_Init_Cvars ();
X11_Init_Cvars ();
}
@ -677,9 +641,9 @@ VID_SetPalette (unsigned char *palette)
for (i = 0; i < 256; i++) {
colors[i].pixel = i;
colors[i].flags = DoRed | DoGreen | DoBlue;
colors[i].red = vid_gamma[palette[i * 3]] * 256;
colors[i].green = vid_gamma[palette[i * 3 + 1]] * 256;
colors[i].blue = vid_gamma[palette[i * 3 + 2]] * 256;
colors[i].red = gammatable[palette[i * 3]];
colors[i].green = gammatable[palette[i * 3 + 1]];
colors[i].blue = gammatable[palette[i * 3 + 2]];
}
XStoreColors (x_disp, x_cmap, colors, 256);
}
@ -696,8 +660,8 @@ VID_Shutdown (void)
{
Sys_Printf ("VID_Shutdown\n");
if (x_disp) {
x11_restore_vidmode ();
x11_close_display ();
X11_RestoreVidMode ();
X11_CloseDisplay ();
}
}
@ -757,7 +721,7 @@ VID_Update (vrect_t *rects)
}
oktodraw = false;
while (!oktodraw)
x11_process_event ();
X11_ProcessEvent ();
rects = rects->pnext;
current_framebuffer = !current_framebuffer;
@ -813,9 +777,21 @@ VID_SetCaption (char *text)
if (text && *text) {
char *temp = strdup (text);
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
X11_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
}
}
double
VID_GetGamma (void)
{
return (double) X11_GetGamma ();
}
qboolean
VID_SetGamma (double gamma)
{
return X11_SetGamma (gamma);
}