More merging.

This commit is contained in:
Ragnvald Maartmann-Moe IV 2001-04-15 04:45:07 +00:00
parent 6a696881b3
commit 84461e1f1f
38 changed files with 0 additions and 28379 deletions

View file

@ -1,52 +0,0 @@
/*
dga_check.h
Definitions for XFree86 DGA and VidMode support
Copyright (C) 2000 Jeff Teunissen <deek@dusknet.dhs.org>
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifndef __dga_check_h_
#define __dga_check_h_
#include <X11/Xlib.h>
#include "QF/qtypes.h"
/*
VID_CheckDGA
Check for the presence of the XFree86-DGA support in the X server
*/
qboolean VID_CheckDGA (Display *, int *, int *, int *);
/*
VID_CheckVMode
Check for the presence of the XFree86-VMode X server extension
*/
qboolean VID_CheckVMode (Display *, int *, int *);
#endif // __dga_check_h_

View file

@ -1,413 +0,0 @@
/*
context_x11.c
general x11 context layer
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Zephaniah E. Hull <warp@whitestar.soark.net>
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
$Id$
*/
#include <config.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include <errno.h>
#include <limits.h>
#include <sys/poll.h>
#ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h>
#endif
#include "context_x11.h"
#include "dga_check.h"
#include "QF/va.h"
#include "QF/qargs.h"
#include "QF/qtypes.h"
#include "vid.h"
#include "QF/sys.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/input.h"
static void (*event_handlers[LASTEvent]) (XEvent *);
qboolean oktodraw = false;
int x_shmeventtype;
static int x_disp_ref_count = 0;
Display *x_disp = NULL;
int x_screen;
Window x_root = None;
XVisualInfo *x_visinfo;
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;
#endif
static int hasvidmode = 0;
cvar_t *vid_fullscreen;
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 *))
{
if (event >= LASTEvent) {
printf ("event: %d, LASTEvent: %d\n", event, LASTEvent);
return false;
}
if (event_handlers[event] != NULL)
return false;
event_handlers[event] = event_handler;
return true;
}
qboolean
x11_del_event (int event, void (*event_handler) (XEvent *))
{
if (event >= LASTEvent)
return false;
if (event_handlers[event] != event_handler)
return false;
event_handlers[event] = NULL;
return true;
}
void
x11_process_event (void)
{
XEvent x_event;
XNextEvent (x_disp, &x_event);
if (x_event.type >= LASTEvent) {
// FIXME: KLUGE!!!!!!
if (x_event.type == x_shmeventtype)
oktodraw = 1;
return;
}
if (event_handlers[x_event.type])
event_handlers[x_event.type] (&x_event);
}
void
x11_process_events (void)
{
/* Get events from X server. */
while (XPending (x_disp)) {
x11_process_event ();
}
}
// ========================================================================
// Tragic death handler
// ========================================================================
static void
TragicDeath (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Sys_Quit ();
exit (sig);
// XCloseDisplay(x_disp);
// VID_Shutdown();
// Sys_Error("This death brought to you by the number %d\n", signal_num);
}
void
x11_open_display (void)
{
if (!x_disp) {
x_disp = XOpenDisplay (NULL);
if (!x_disp) {
Sys_Error ("x11_open_display: Could not open display [%s]\n",
XDisplayName (NULL));
}
x_screen = DefaultScreen (x_disp);
x_root = RootWindow (x_disp, x_screen);
// catch signals
signal (SIGHUP, TragicDeath);
signal (SIGINT, TragicDeath);
signal (SIGQUIT, TragicDeath);
signal (SIGILL, TragicDeath);
signal (SIGTRAP, TragicDeath);
signal (SIGIOT, TragicDeath);
signal (SIGBUS, TragicDeath);
/* signal(SIGFPE, TragicDeath); */
signal (SIGSEGV, TragicDeath);
signal (SIGTERM, TragicDeath);
// for debugging only
XSynchronize (x_disp, True);
x_disp_ref_count = 1;
} else {
x_disp_ref_count++;
}
}
void
x11_close_display (void)
{
if (nullcursor != None) {
XFreeCursor (x_disp, nullcursor);
nullcursor = None;
}
if (!--x_disp_ref_count) {
XCloseDisplay (x_disp);
x_disp = 0;
}
}
/*
x11_create_null_cursor
Create an empty cursor
*/
void
x11_create_null_cursor (void)
{
Pixmap cursormask;
XGCValues xgc;
GC gc;
XColor dummycolour;
if (nullcursor != None)
return;
cursormask = XCreatePixmap (x_disp, x_root, 1, 1, 1 /* depth */ );
xgc.function = GXclear;
gc = XCreateGC (x_disp, cursormask, GCFunction, &xgc);
XFillRectangle (x_disp, cursormask, gc, 0, 0, 1, 1);
dummycolour.pixel = 0;
dummycolour.red = 0;
dummycolour.flags = 04;
nullcursor = XCreatePixmapCursor (x_disp, cursormask, cursormask,
&dummycolour, &dummycolour, 0, 0);
XFreePixmap (x_disp, cursormask);
XFreeGC (x_disp, gc);
XDefineCursor (x_disp, x_win, nullcursor);
}
void
x11_set_vidmode (int width, int height)
{
int i;
int best_mode = 0, best_x = INT_MAX, best_y = INT_MAX;
XGetScreenSaver (x_disp, &xss_timeout, &xss_interval, &xss_blanking,
&xss_exposures);
XSetScreenSaver (x_disp, 0, xss_interval, xss_blanking, xss_exposures);
#ifdef XMESA
const char *str = getenv ("MESA_GLX_FX");
if (str != NULL && *str != 'd') {
if (tolower (*str) == 'w') {
Cvar_Set (vid_fullscreen, "0");
} else {
Cvar_Set (vid_fullscreen, "1");
}
}
#endif
#ifdef HAVE_VIDMODE
if (!(hasvidmode = VID_CheckVMode (x_disp, NULL, NULL))) {
Cvar_Set (vid_fullscreen, "0");
return;
}
XF86VidModeGetAllModeLines (x_disp, x_screen, &nummodes, &vidmodes);
if (vid_fullscreen->int_val) {
for (i = 0; i < nummodes; i++) {
if ((best_x > vidmodes[i]->hdisplay) ||
(best_y > vidmodes[i]->vdisplay)) {
if ((vidmodes[i]->hdisplay >= width) &&
(vidmodes[i]->vdisplay >= height)) {
best_mode = i;
best_x = vidmodes[i]->hdisplay;
best_y = vidmodes[i]->vdisplay;
}
}
printf ("%dx%d\n", vidmodes[i]->hdisplay, vidmodes[i]->vdisplay);
}
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[best_mode]);
x11_force_view_port ();
}
#endif
}
void
x11_Init_Cvars ()
{
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ROM, NULL,
"Toggles fullscreen game mode");
}
void
x11_create_window (int width, int height)
{
XSetWindowAttributes attr;
XClassHint *ClassHint;
XSizeHints *SizeHints;
char *resname;
unsigned long mask;
/* window attributes */
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap (x_disp, x_root, x_vis, AllocNone);
attr.event_mask = X_MASK;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
if (hasvidmode && vid_fullscreen->int_val) {
attr.override_redirect = 1;
mask |= CWOverrideRedirect;
}
x_win = XCreateWindow (x_disp, x_root, 0, 0, width, height,
0, x_visinfo->depth, InputOutput,
x_vis, mask, &attr);
// Set window size hints
SizeHints = XAllocSizeHints ();
if (SizeHints) {
SizeHints->flags = (PMinSize | PMaxSize);
SizeHints->min_width = width;
SizeHints->min_height = height;
SizeHints->max_width = width;
SizeHints->max_height = height;
XSetWMNormalHints (x_disp, x_win, SizeHints);
XFree (SizeHints);
}
// Set window title
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
// Set icon name
XSetIconName (x_disp, x_win, PROGRAM);
// Set window class
ClassHint = XAllocClassHint ();
if (ClassHint) {
resname = strrchr (com_argv[0], '/');
ClassHint->res_name = (resname ? resname + 1 : resname);
ClassHint->res_class = PROGRAM;
XSetClassHint (x_disp, x_win, ClassHint);
XFree (ClassHint);
}
// Make window respond to Delete events
aWMDelete = XInternAtom (x_disp, "WM_DELETE_WINDOW", False);
XSetWMProtocols (x_disp, x_win, &aWMDelete, 1);
if (vid_fullscreen->int_val) {
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 ();
}
XMapWindow (x_disp, x_win);
XRaiseWindow (x_disp, x_win);
}
void
x11_restore_vidmode (void)
{
XSetScreenSaver (x_disp, xss_timeout, xss_interval, xss_blanking,
xss_exposures);
#ifdef HAVE_VIDMODE
if (hasvidmode) {
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[0]);
XFree (vidmodes);
}
#endif
}
void
x11_grab_keyboard (void)
{
#ifdef HAVE_VIDMODE
if (hasvidmode && vid_fullscreen->int_val) {
XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync,
CurrentTime);
}
#endif
}
void
x11_set_caption (char *text)
{
if (x_disp && x_win && text)
XStoreName (x_disp, x_win, text);
}
void
x11_force_view_port (void)
{
#ifdef HAVE_VIDMODE
int x, y;
if (vid_fullscreen->int_val) {
do {
XF86VidModeSetViewPort (x_disp, x_screen, 0, 0);
poll (0, 0, 50);
XF86VidModeGetViewPort (x_disp, x_screen, &x, &y);
} while (x || y);
}
#endif
}

View file

@ -1,117 +0,0 @@
/*
dga_check.c
Routines to check for XFree86 DGA and VidMode extensions
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 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
$Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <X11/Xlib.h>
#ifdef HAVE_DGA
#include <X11/extensions/xf86dga.h>
#endif
#ifdef HAVE_VIDMODE
#include <X11/extensions/xf86vmode.h>
#endif
#include "dga_check.h"
/*
VID_CheckDGA
Check for the presence of the XFree86-DGA X server extension
*/
qboolean
VID_CheckDGA (Display * dpy, int *maj_ver, int *min_ver, int *hasvideo)
{
#ifdef HAVE_DGA
int event_base, error_base, dgafeat, dummy;
if (!XF86DGAQueryExtension (dpy, &event_base, &error_base)) {
return false;
}
if (!maj_ver)
maj_ver = &dummy;
if (!min_ver)
min_ver = &dummy;
if (!XF86DGAQueryVersion (dpy, maj_ver, min_ver)) {
return false;
}
if (!hasvideo)
hasvideo = &dummy;
if (!XF86DGAQueryDirectVideo (dpy, DefaultScreen (dpy), &dgafeat)) {
*hasvideo = 0;
} else {
*hasvideo = (dgafeat & XF86DGADirectPresent);
}
return true;
#else
return false;
#endif // HAVE_DGA
}
/*
VID_CheckVMode
Check for the presence of the XFree86-VidMode X server extension
*/
qboolean
VID_CheckVMode (Display * dpy, int *maj_ver, int *min_ver)
{
#if defined(HAVE_VIDMODE)
int event_base, error_base;
int dummy;
if (!XF86VidModeQueryExtension (dpy, &event_base, &error_base)) {
return false;
}
if (maj_ver == NULL)
maj_ver = &dummy;
if (min_ver == NULL)
min_ver = &dummy;
if (!XF86VidModeQueryVersion (dpy, maj_ver, min_ver)) {
return false;
}
return true;
#else
return false;
#endif // HAVE_VIDMODE
}

File diff suppressed because it is too large Load diff

View file

@ -1,138 +0,0 @@
/*
* Linux Frame Buffer Device Configuration
*
* © Copyright 1995-1998 by Geert Uytterhoeven
* (Geert.Uytterhoeven@cs.kuleuven.ac.be)
*
* --------------------------------------------------------------------------
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of the Linux
* distribution for more details.
*/
%{
#define YYSTYPE long
#include <string.h>
#include <stdlib.h>
#define Die Sys_Error
#include "fbset.h"
#include "fbset_modes_y.h"
struct keyword {
const char *name;
int token;
int value;
};
static struct keyword keywords[] = {
{ "mode", MODE, 0 },
{ "geometry", GEOMETRY, 0 },
{ "timings", TIMINGS, 0 },
{ "hsync", HSYNC, 0 },
{ "vsync", VSYNC, 0 },
{ "csync", CSYNC, 0 },
{ "gsync", GSYNC, 0 },
{ "extsync", EXTSYNC, 0 },
{ "bcast", BCAST, 0 },
{ "laced", LACED, 0 },
{ "double", DOUBLE, 0 },
{ "rgba", RGBA, 0 },
{ "nonstd", NONSTD, 0 },
{ "accel", ACCEL, 0 },
{ "grayscale", GRAYSCALE, 0 },
{ "endmode", ENDMODE, 0 },
{ "low", POLARITY, LOW },
{ "high", POLARITY, HIGH },
{ "false", BOOLEAN, FALSE },
{ "true", BOOLEAN, TRUE },
{ "", -1, 0 }
};
int line = 1;
void yyerror(const char *s)
{
Die("%s:%d: %s\n", Opt_modedb, line, s);
}
int yywrap(void)
{
return 1;
}
static int FindToken(const char *s)
{
int i;
for (i = 0; keywords[i].token > 0; i++)
if (!strcasecmp(s, keywords[i].name)) {
return keywords[i].token;
}
Die("%s:%d: Unknown keyword `%s'\n", Opt_modedb, line, s);
}
static const char *CopyString(const char *s)
{
int len;
char *s2;
len = strlen(s)-2;
if (!(s2 = malloc(len+1)))
Die("No memory\n");
strncpy(s2, s+1, len);
s2[len] = '\0';
return s2;
}
%}
keyword [a-zA-Z][a-zA-Z0-9]*
number [0-9]*
string \"[^\"\n]*\"
comment \#([^\n]*)
space [ \t]+
junk .
%%
{keyword} {
yylval = FindToken(yytext);
return yylval;
}
{number} {
yylval = strtoul(yytext, NULL, 0);
return NUMBER;
}
{string} {
yylval = (unsigned long)CopyString(yytext);
return STRING;
}
{comment}$ break;
{space} break;
\n {
line++;
break;
}
{junk} {
Die("%s:%d: Invalid token `%s'\n", Opt_modedb, line, yytext);
}
%%

View file

@ -1,176 +0,0 @@
/*
* Linux Frame Buffer Device Configuration
*
* © Copyright 1995-1998 by Geert Uytterhoeven
* (Geert.Uytterhoeven@cs.kuleuven.ac.be)
*
* --------------------------------------------------------------------------
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of the Linux
* distribution for more details.
*/
%{
#define YYSTYPE long
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Die Sys_Error
#include "fbset.h"
extern int yylex(void);
extern void yyerror(const char *s);
extern int line;
static struct VideoMode VideoMode;
static void ClearVideoMode(void)
{
memset(&VideoMode, 0, sizeof(VideoMode));
VideoMode.accel_flags = FB_ACCELF_TEXT;
}
%}
%start file
%token MODE GEOMETRY TIMINGS HSYNC VSYNC CSYNC GSYNC EXTSYNC BCAST LACED DOUBLE
RGBA NONSTD ACCEL GRAYSCALE
ENDMODE POLARITY BOOLEAN STRING NUMBER
%%
file : vmodes
;
vmodes : /* empty */
| vmodes vmode
;
vmode : MODE STRING geometry timings options ENDMODE
{
VideoMode.name = (char *)$2;
AddVideoMode(&VideoMode);
ClearVideoMode();
}
;
geometry : GEOMETRY NUMBER NUMBER NUMBER NUMBER NUMBER
{
ClearVideoMode();
VideoMode.xres = $2;
VideoMode.yres = $3;
VideoMode.vxres = $4;
VideoMode.vyres = $5;
VideoMode.depth = $6;
}
;
timings : TIMINGS NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER
{
VideoMode.pixclock = $2;
VideoMode.left = $3;
VideoMode.right = $4;
VideoMode.upper = $5;
VideoMode.lower = $6;
VideoMode.hslen = $7;
VideoMode.vslen = $8;
}
;
options : /* empty */
| options hsync
| options vsync
| options csync
| options gsync
| options extsync
| options bcast
| options laced
| options double
| options rgba
| options nonstd
| options accel
| options grayscale
;
hsync : HSYNC POLARITY
{
VideoMode.hsync = $2;
}
;
vsync : VSYNC POLARITY
{
VideoMode.vsync = $2;
}
;
csync : CSYNC POLARITY
{
VideoMode.csync = $2;
}
;
gsync : GSYNC POLARITY
{
VideoMode.gsync = $2;
}
;
extsync : EXTSYNC BOOLEAN
{
VideoMode.extsync = $2;
}
;
bcast : BCAST BOOLEAN
{
VideoMode.bcast = $2;
}
;
laced : LACED BOOLEAN
{
VideoMode.laced = $2;
}
;
double : DOUBLE BOOLEAN
{
VideoMode.dblscan = $2;
}
;
rgba : RGBA STRING
{
makeRGBA(&VideoMode, (const char*)$2);
}
;
nonstd : NONSTD NUMBER
{
VideoMode.nonstd = $2;
}
;
accel : ACCEL BOOLEAN
{
VideoMode.accel_flags = $2;
}
;
grayscale : GRAYSCALE BOOLEAN
{
VideoMode.grayscale = $2;
}
;
%%

View file

@ -1,341 +0,0 @@
/*
vid_3dfxsvga.c
OpenGL device driver for 3Dfx chipsets running Linux
Copyright (C) 1996-1997 Id Software, Inc.
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
$Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/fxmesa.h>
#include <glide/sst1vid.h>
#include <sys/signal.h>
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#ifndef RTLD_LAZY
# ifdef DL_LAZY
# define RTLD_LAZY DL_LAZY
# else
# define RTLD_LAZY 0
# endif
#endif
#include "QF/console.h"
#include "glquake.h"
#include "host.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "sbar.h"
#include "QF/sys.h"
#include "QF/va.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
static fxMesaContext fc = NULL;
static void *dlhand;
int VID_options_items = 0;
extern void GL_Init_Common (void);
extern void VID_Init8bitPalette (void);
/*-----------------------------------------------------------------------*/
void
VID_Shutdown (void)
{
if (!fc)
return;
fxMesaDestroyContext (fc);
}
void
signal_handler (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Host_Shutdown ();
abort ();
// Sys_Quit();
exit (0);
}
void
InitSig (void)
{
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
// signal(SIGIOT, signal_handler);
signal (SIGBUS, signal_handler);
// signal(SIGFPE, signal_handler);
signal (SIGSEGV, signal_handler);
signal (SIGTERM, signal_handler);
}
typedef void (GLAPIENTRY * gl3DfxSetDitherModeEXT_FUNC) (GrDitherMode_t mode);
/*
===============
GL_Init
===============
*/
void
GL_Init (void)
{
GL_Init_Common ();
Con_Printf ("Dithering: ");
dlhand = dlopen (NULL, RTLD_LAZY);
if (dlhand == NULL) {
Con_Printf ("unable to set.\n");
return;
}
if (strstr (gl_extensions, "3DFX_set_dither_mode")) {
gl3DfxSetDitherModeEXT_FUNC dither_select = NULL;
dither_select = (void *) dlsym (dlhand, "gl3DfxSetDitherModeEXT");
if (COM_CheckParm ("-dither_2x2")) {
dither_select (GR_DITHER_2x2);
Con_Printf ("2x2.\n");
} else if (COM_CheckParm ("-dither_4x4")) {
dither_select (GR_DITHER_4x4);
Con_Printf ("4x4.\n");
} else {
glDisable (GL_DITHER);
Con_Printf ("disabled.\n");
}
}
dlclose (dlhand);
dlhand = NULL;
}
void
GL_EndRendering (void)
{
glFlush ();
fxMesaSwapBuffers ();
Sbar_Changed ();
}
static int resolutions[][3] = {
{320, 200, GR_RESOLUTION_320x200},
{320, 240, GR_RESOLUTION_320x240},
{400, 256, GR_RESOLUTION_400x256},
{400, 300, GR_RESOLUTION_400x300},
{512, 256, GR_RESOLUTION_512x256},
{512, 384, GR_RESOLUTION_512x384},
{640, 200, GR_RESOLUTION_640x200},
{640, 350, GR_RESOLUTION_640x350},
{640, 400, GR_RESOLUTION_640x400},
{640, 480, GR_RESOLUTION_640x480},
{800, 600, GR_RESOLUTION_800x600},
{856, 480, GR_RESOLUTION_856x480},
{960, 720, GR_RESOLUTION_960x720},
#ifdef GR_RESOLUTION_1024x768
{1024, 768, GR_RESOLUTION_1024x768},
#endif
#ifdef GR_RESOLUTION_1152x864
{1152, 864, GR_RESOLUTION_1152x864},
#endif
#ifdef GR_RESOLUTION_1280x960
{1280, 960, GR_RESOLUTION_1280x960},
#endif
#ifdef GR_RESOLUTION_1280x1024
{1280, 1024, GR_RESOLUTION_1280x1024},
#endif
#ifdef GR_RESOLUTION_1600x1024
{1600, 1024, GR_RESOLUTION_1600x1024},
#endif
#ifdef GR_RESOLUTION_1600x1200
{1600, 1200, GR_RESOLUTION_1600x1200},
#endif
#ifdef GR_RESOLUTION_1792x1344
{1792, 1344, GR_RESOLUTION_1792x1344},
#endif
#ifdef GR_RESOLUTION_1856x1392
{1856, 1392, GR_RESOLUTION_1856x1392},
#endif
#ifdef GR_RESOLUTION_1920x1440
{1920, 1440, GR_RESOLUTION_1920x1440},
#endif
#ifdef GR_RESOLUTION_2048x1536
{2048, 1536, GR_RESOLUTION_2048x1536},
#endif
#ifdef GR_RESOLUTION_2048x2048
{2048, 2048, GR_RESOLUTION_2048x2048}
#endif
};
#define NUM_RESOLUTIONS (sizeof(resolutions)/(sizeof(int)*3))
static int
findres (int *width, int *height)
{
int i;
for (i = 0; i < NUM_RESOLUTIONS; i++) {
if ((*width <= resolutions[i][0]) && (*height <= resolutions[i][1])) {
*width = resolutions[i][0];
*height = resolutions[i][1];
return resolutions[i][2];
}
}
*width = 640;
*height = 480;
return GR_RESOLUTION_640x480;
}
typedef void (GLAPIENTRY * glColorTableEXT_FUNC) (GLenum, GLenum, GLsizei,
GLenum, GLenum,
const GLvoid *);
typedef void (GLAPIENTRY * gl3DfxSetPaletteEXT_FUNC) (GLuint * pal);
void
VID_Init (unsigned char *palette)
{
int i;
GLint attribs[32];
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
// interpret command-line params
// set vid parameters
attribs[0] = FXMESA_DOUBLEBUFFER;
attribs[1] = FXMESA_ALPHA_SIZE;
attribs[2] = 1;
attribs[3] = FXMESA_DEPTH_SIZE;
attribs[4] = 1;
attribs[5] = FXMESA_NONE;
if ((i = COM_CheckParm ("-conwidth")) != 0)
vid.conwidth = atoi (com_argv[i + 1]);
else
vid.conwidth = 640;
vid.conwidth &= 0xfff8; // make it a multiple of eight
if (vid.conwidth < 320)
vid.conwidth = 320;
// pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4;
if ((i = COM_CheckParm ("-conheight")) != 0)
vid.conheight = atoi (com_argv[i + 1]);
if (vid.conheight < 200)
vid.conheight = 200;
fc = fxMesaCreateContext (0, findres (&scr_width, &scr_height),
GR_REFRESH_75Hz, attribs);
if (!fc)
Sys_Error ("Unable to create 3DFX context.\n");
fxMesaMakeCurrent (fc);
if (vid.conheight > scr_height)
vid.conheight = scr_height;
if (vid.conwidth > scr_width)
vid.conwidth = scr_width;
vid.width = vid.conwidth;
vid.height = vid.conheight;
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
InitSig (); // trap evil signals
GL_Init ();
VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them.
VID_Init8bitPalette ();
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
vid.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars ()
{
}
void
VID_ExtraOptionDraw (unsigned int options_draw_cursor)
{
/* Port specific Options menu entrys */
}
void
VID_ExtraOptionCmd (int option_cursor)
{
/*
switch(option_cursor)
{
case 12: // Always start with 12
break;
}
*/
}
void
VID_SetCaption (char *text)
{
}
void
VID_HandlePause (qboolean paused)
{
}

View file

@ -1,412 +0,0 @@
/*
vid_common_gl.c
Common OpenGL video driver functions
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <GL/gl.h>
#ifdef HAVE_GL_GLEXT_H
#include <GL/glext.h>
#endif
#include <string.h>
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#ifndef RTLD_LAZY
# ifdef DL_LAZY
# define RTLD_LAZY DL_LAZY
# else
# define RTLD_LAZY 0
# endif
#endif
#include "QF/console.h"
#include "QF/compat.h"
#include "glquake.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "sbar.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
#ifdef HAVE_DLOPEN
static void *dlhand = NULL;
#endif
//unsigned short d_8to16table[256];
unsigned int d_8to24table[256];
unsigned char d_15to8table[65536];
cvar_t *vid_mode;
/*-----------------------------------------------------------------------*/
int texture_mode = GL_LINEAR;
int texture_extension_number = 1;
float gldepthmin, gldepthmax;
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
// ARB Multitexture
GLenum gl_mtex_enum = TEXTURE0_SGIS;
qboolean gl_arb_mtex = false;
qboolean gl_mtexable = false;
qboolean is8bit = false;
cvar_t *vid_use8bit;
/*-----------------------------------------------------------------------*/
/*
CheckMultiTextureExtensions
Check for ARB, SGIS, or EXT multitexture support
*/
void
CheckMultiTextureExtensions (void)
{
Con_Printf ("Checking for multitexture... ");
if (COM_CheckParm ("-nomtex")) {
Con_Printf ("disabled\n");
return;
}
#ifdef HAVE_DLOPEN
dlhand = dlopen (NULL, RTLD_LAZY);
if (dlhand == NULL) {
Con_Printf ("unable to check\n");
return;
}
if (strstr (gl_extensions, "GL_ARB_multitexture ")) {
Con_Printf ("GL_ARB_multitexture\n");
qglMTexCoord2f = (void *) dlsym (dlhand, "glMultiTexCoord2fARB");
qglSelectTexture = (void *) dlsym (dlhand, "glActiveTextureARB");
gl_mtex_enum = GL_TEXTURE0_ARB;
gl_mtexable = true;
gl_arb_mtex = true;
} else if (strstr (gl_extensions, "GL_SGIS_multitexture ")) {
Con_Printf ("GL_SGIS_multitexture\n");
qglMTexCoord2f = (void *) dlsym (dlhand, "glMTexCoord2fSGIS");
qglSelectTexture = (void *) dlsym (dlhand, "glSelectTextureSGIS");
gl_mtex_enum = TEXTURE0_SGIS;
gl_mtexable = true;
gl_arb_mtex = false;
} else if (strstr (gl_extensions, "GL_EXT_multitexture ")) {
Con_Printf ("GL_EXT_multitexture\n");
qglMTexCoord2f = (void *) dlsym (dlhand, "glMTexCoord2fEXT");
qglSelectTexture = (void *) dlsym (dlhand, "glSelectTextureEXT");
gl_mtex_enum = TEXTURE0_SGIS;
gl_mtexable = true;
gl_arb_mtex = false;
} else {
Con_Printf ("none found\n");
}
dlclose (dlhand);
dlhand = NULL;
#else
gl_mtexable = false;
#endif
}
void
VID_SetPalette (unsigned char *palette)
{
byte *pal;
unsigned int r, g, b;
unsigned int v;
int r1, g1, b1;
int k;
unsigned short i;
unsigned int *table;
QFile *f;
char s[255];
float dist, bestdist;
static qboolean palflag = false;
//
// 8 8 8 encoding
//
// Con_Printf("Converting 8to24\n");
pal = palette;
table = d_8to24table;
for (i = 0; i < 255; i++) { // used to be i<256, see d_8to24table
//
//
// below
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
// v = (255<<24) + (r<<16) + (g<<8) + (b<<0);
// v = (255<<0) + (r<<8) + (g<<16) + (b<<24);
v = (255 << 24) + (r << 0) + (g << 8) + (b << 16);
*table++ = v;
}
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.
if (palflag)
return;
palflag = true;
COM_FOpenFile ("glquake/15to8.pal", &f);
if (f) {
Qread (f, d_15to8table, 1 << 15);
Qclose (f);
} else {
for (i = 0; i < (1 << 15); i++) {
/* 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;
pal = (unsigned char *) d_8to24table;
for (v = 0, k = 0, bestdist = 10000.0; v < 256; v++, pal += 4) {
r1 = (int) r - (int) pal[0];
g1 = (int) g - (int) pal[1];
b1 = (int) b - (int) pal[2];
dist = sqrt (((r1 * r1) + (g1 * g1) + (b1 * b1)));
if (dist < bestdist) {
k = v;
bestdist = dist;
}
}
d_15to8table[i] = k;
}
snprintf (s, sizeof (s), "%s/glquake/15to8.pal", com_gamedir);
COM_CreatePath (s);
if ((f = Qopen (s, "wb")) != NULL) {
Qwrite (f, d_15to8table, 1 << 15);
Qclose (f);
}
}
}
/*
===============
GL_Init_Common
===============
*/
void
GL_Init_Common (void)
{
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
gl_version = glGetString (GL_VERSION);
Con_Printf ("GL_VERSION: %s\n", gl_version);
gl_extensions = glGetString (GL_EXTENSIONS);
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
glClearColor (0, 0, 0, 0);
glCullFace (GL_FRONT);
glEnable (GL_TEXTURE_2D);
glEnable (GL_ALPHA_TEST);
glAlphaFunc (GL_GREATER, 0.666);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glShadeModel (GL_FLAT);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
CheckMultiTextureExtensions ();
}
/*
=================
GL_BeginRendering
=================
*/
void
GL_BeginRendering (int *x, int *y, int *width, int *height)
{
*x = *y = 0;
*width = scr_width;
*height = scr_height;
}
qboolean
VID_Is8bit (void)
{
return is8bit;
}
#ifdef HAVE_TDFXGL
void
Tdfx_Init8bitPalette ()
{
// Check for 8bit Extensions and initialize them.
int i;
dlhand = dlopen (NULL, RTLD_LAZY);
Con_Printf ("8-bit GL extensions: ");
if (dlhand == NULL) {
Con_Printf ("unable to check.\n");
return;
}
if (strstr (gl_extensions, "3DFX_set_global_palette")) {
char *oldpal;
GLubyte table[256][4];
gl3DfxSetPaletteEXT_FUNC load_texture = NULL;
Con_Printf ("3DFX_set_global_palette.\n");
load_texture = (void *) dlsym (dlhand, "gl3DfxSetPaletteEXT");
glEnable (GL_SHARED_TEXTURE_PALETTE_EXT);
oldpal = (char *) d_8to24table; // d_8to24table3dfx;
for (i = 0; i < 256; i++) {
table[i][2] = *oldpal++;
table[i][1] = *oldpal++;
table[i][0] = *oldpal++;
table[i][3] = 255;
oldpal++;
}
load_texture ((GLuint *) table);
is8bit = true;
} else
Shared_Init8bitPalette ();
dlclose (dlhand);
dlhand = NULL;
Con_Printf ("not found.\n");
}
#endif
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
void
Shared_Init8bitPalette ()
{
int i;
char thePalette[256 * 3];
char *oldPalette, *newPalette;
if (strstr (gl_extensions, "GL_EXT_shared_texture_palette") == NULL)
return;
#ifdef HAVE_TDFXGL
glColorTableEXT_FUNC load_texture = NULL;
load_texture = (void *) dlsym (dlhand, "glColorTableEXT");
#endif
Con_Printf ("8-bit GL extensions enabled.\n");
glEnable (GL_SHARED_TEXTURE_PALETTE_EXT);
oldPalette = (char *) d_8to24table; // d_8to24table3dfx;
newPalette = thePalette;
for (i = 0; i < 256; i++) {
*newPalette++ = *oldPalette++;
*newPalette++ = *oldPalette++;
*newPalette++ = *oldPalette++;
oldPalette++;
}
is8bit = true;
if strstr
(gl_renderer, "Mesa Glide") {
#ifdef HAVE_TDFXGL
load_texture (GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB,
GL_UNSIGNED_BYTE, (void *) thePalette);
#endif
} else
glColorTable (GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB,
GL_UNSIGNED_BYTE, (void *) thePalette);
}
#endif
void
VID_Init8bitPalette (void)
{
if (COM_CheckParm ("-no8bit")) {
Con_Printf ("disabled.\n");
return;
}
vid_use8bit = Cvar_Get ("vid_use8bit", "0", CVAR_ROM, NULL,
"Whether to use Shared Palettes.");
if (vid_use8bit->value) {
#ifdef HAVE_TDFXGL
Tdfx_Init8bitPalette ();
#else
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
Shared_Init8bitPalette ();
#endif
#endif
}
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
}
void
D_EndDirectRect (int x, int y, int width, int height)
{
}

View file

@ -1,772 +0,0 @@
/*
vid_dos.c
@description@
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <dpmi.h>
#include <go32.h>
#include "d_local.h"
#include "dosisms.h"
#include "vid_dos.h"
int vid_modenum;
vmode_t *pcurrentmode = NULL;
int vid_testingmode, vid_realmode;
double vid_testendtime;
cvar_t *vid_mode;
cvar_t *vid_wait;
cvar_t *vid_nopageflip;
cvar_t *_vid_wait_override;
cvar_t *_vid_default_mode;
cvar_t *_vid_default_mode_win;
cvar_t *vid_config_x;
cvar_t *vid_config_y;
cvar_t *vid_stretch_by_2;
cvar_t *_windowed_mouse;
cvar_t *vid_fullscreen_mode;
cvar_t *vid_windowed_mode;
cvar_t *block_switch;
cvar_t *vid_window_x;
cvar_t *vid_window_y;
int d_con_indirect = 0;
int numvidmodes;
vmode_t *pvidmodes;
static int firstupdate = 1;
extern regs_t regs;
void VID_TestMode_f (void);
void VID_NumModes_f (void);
void VID_DescribeCurrentMode_f (void);
void VID_DescribeMode_f (void);
void VID_DescribeModes_f (void);
byte vid_current_palette[768]; // save for mode changes
static qboolean nomodecheck = false;
unsigned short d_8to16table[256]; // not used in 8 bpp mode
unsigned d_8to24table[256]; // not used in 8 bpp mode
void VID_MenuDraw (void);
void VID_MenuKey (int key);
void
VID_InitCvars (void)
{
}
/*
================
VID_Init
================
*/
void
VID_Init (unsigned char *palette)
{
vid_mode = Cvar_Get ("vid_mode", "0", CVAR_NONE, NULL, "None");
vid_wait = Cvar_Get ("vid_wait", "0", CVAR_NONE, NULL, "None");
vid_nopageflip = Cvar_Get ("vid_nopageflip", "0", CVAR_ARCHIVE, NULL,
"None");
_vid_wait_override =
Cvar_Get ("_vid_wait_override", "0", CVAR_ARCHIVE, NULL, "None");
_vid_default_mode =
Cvar_Get ("_vid_default_mode", "0", CVAR_ARCHIVE, NULL, "None");
_vid_default_mode_win =
Cvar_Get ("_vid_default_mode_win", "3", CVAR_ARCHIVE, NULL, "None");
vid_config_x = Cvar_Get ("vid_config_x", "800", CVAR_ARCHIVE, NULL, "None");
vid_config_y = Cvar_Get ("vid_config_y", "600", CVAR_ARCHIVE, NULL, "None");
vid_stretch_by_2 = Cvar_Get ("vid_stretch_by_2", "1", CVAR_ARCHIVE, NULL,
"None");
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
"None");
vid_fullscreen_mode =
Cvar_Get ("vid_fullscreen_mode", "3", CVAR_ARCHIVE, NULL, "None");
vid_windowed_mode =
Cvar_Get ("vid_windowed_mode", "0", CVAR_ARCHIVE, NULL, "None");
block_switch = Cvar_Get ("block_switch", "0", CVAR_ARCHIVE, NULL, "None");
Cmd_AddCommand ("vid_testmode", VID_TestMode_f, "No Description");
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, "No Description");
Cmd_AddCommand ("vid_describecurrentmode", VID_DescribeCurrentMode_f,
"No Description");
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f, "No Description");
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f, "No Description");
// set up the mode list; note that later inits link in their modes ahead of
// earlier ones, so the standard VGA modes are always first in the list. This
// is important because mode 0 must always be VGA mode 0x13
if (!COM_CheckParm ("-stdvid"))
VID_InitExtra ();
VGA_Init ();
vid_testingmode = 0;
vid_modenum = vid_mode->int_val;
VID_SetMode (vid_modenum, palette);
vid_realmode = vid_modenum;
vid_menudrawfn = VID_MenuDraw;
vid_menukeyfn = VID_MenuKey;
}
/*
=================
VID_GetModePtr
=================
*/
vmode_t *
VID_GetModePtr (int modenum)
{
vmode_t *pv;
pv = pvidmodes;
if (!pv)
Sys_Error ("VID_GetModePtr: empty vid mode list");
while (modenum--) {
pv = pv->pnext;
if (!pv)
Sys_Error ("VID_GetModePtr: corrupt vid mode list");
}
return pv;
}
/*
================
VID_NumModes
================
*/
int
VID_NumModes ()
{
return (numvidmodes);
}
/*
================
VID_ModeInfo
================
*/
char *
VID_ModeInfo (int modenum, char **ppheader)
{
static char *badmodestr = "Bad mode number";
vmode_t *pv;
pv = VID_GetModePtr (modenum);
if (!pv) {
if (ppheader)
*ppheader = NULL;
return badmodestr;
} else {
if (ppheader)
*ppheader = pv->header;
return pv->name;
}
}
/*
================
VID_SetMode
================
*/
int
VID_SetMode (int modenum, unsigned char *palette)
{
int stat;
vmode_t *pnewmode, *poldmode;
if ((modenum >= numvidmodes) || (modenum < 0)) {
Cvar_SetValue (vid_mode, (float) vid_modenum);
nomodecheck = true;
Con_Printf ("No such video mode: %d\n", modenum);
nomodecheck = false;
if (pcurrentmode == NULL) {
modenum = 0; // mode hasn't been set yet, so
// initialize to base
// mode since they gave us an invalid initial mode
} else {
return 0;
}
}
pnewmode = VID_GetModePtr (modenum);
if (pnewmode == pcurrentmode)
return 1; // already in the desired mode
// initialize the new mode
poldmode = pcurrentmode;
pcurrentmode = pnewmode;
vid.width = pcurrentmode->width;
vid.height = pcurrentmode->height;
vid.aspect = pcurrentmode->aspect;
vid.rowbytes = pcurrentmode->rowbytes;
stat = (*pcurrentmode->setmode) (&vid, pcurrentmode);
if (stat < 1) {
if (stat == 0) {
// real, hard failure that requires resetting the mode
if (!VID_SetMode (vid_modenum, palette)) // restore prior mode
Sys_Error ("VID_SetMode: Unable to set any mode, probably "
"because there's not enough memory available");
Con_Printf ("Failed to set mode %d\n", modenum);
return 0;
} else if (stat == -1) {
// not enough memory; just put things back the way they were
pcurrentmode = poldmode;
vid.width = pcurrentmode->width;
vid.height = pcurrentmode->height;
vid.aspect = pcurrentmode->aspect;
vid.rowbytes = pcurrentmode->rowbytes;
return 0;
} else {
Sys_Error ("VID_SetMode: invalid setmode return code %d");
}
}
(*pcurrentmode->setpalette) (&vid, pcurrentmode, palette);
vid_modenum = modenum;
Cvar_SetValue (vid_mode, (float) vid_modenum);
nomodecheck = true;
Con_Printf ("%s\n", VID_ModeInfo (vid_modenum, NULL));
nomodecheck = false;
vid.recalc_refdef = 1;
return 1;
}
/*
================
VID_SetPalette
================
*/
void
VID_SetPalette (unsigned char *palette)
{
if (palette != vid_current_palette)
Q_memcpy (vid_current_palette, palette, 768);
(*pcurrentmode->setpalette) (&vid, pcurrentmode, vid_current_palette);
}
/*
================
VID_ShiftPalette
================
*/
void
VID_ShiftPalette (unsigned char *palette)
{
VID_SetPalette (palette);
}
/*
================
VID_Shutdown
================
*/
void
VID_Shutdown (void)
{
regs.h.ah = 0;
regs.h.al = 0x3;
dos_int86 (0x10);
vid_testingmode = 0;
}
/*
================
VID_Update
================
*/
void
VID_Update (vrect_t *rects)
{
if (firstupdate && _vid_default_mode->int_val) {
if (_vid_default_mode->int_val >= numvidmodes)
Cvar_SetValue (_vid_default_mode, 0);
firstupdate = 0;
Cvar_SetValue (vid_mode, _vid_default_mode->int_val);
}
(*pcurrentmode->swapbuffers) (&vid, pcurrentmode, rects);
if (!nomodecheck) {
if (vid_testingmode) {
if (realtime >= vid_testendtime) {
VID_SetMode (vid_realmode, vid_current_palette);
vid_testingmode = 0;
}
} else {
if (vid_mode->int_val != vid_realmode) {
VID_SetMode (vid_mode->int_val, vid_current_palette);
Cvar_SetValue (vid_mode, (float) vid_modenum);
// so if mode set fails, we don't keep on
// trying to set that mode
vid_realmode = vid_modenum;
}
}
}
}
/*
=================
VID_NumModes_f
=================
*/
void
VID_NumModes_f (void)
{
int nummodes;
nummodes = VID_NumModes ();
if (nummodes == 1)
Con_Printf ("%d video mode is available\n", VID_NumModes ());
else
Con_Printf ("%d video modes are available\n", VID_NumModes ());
}
/*
=================
VID_DescribeCurrentMode_f
=================
*/
void
VID_DescribeCurrentMode_f (void)
{
Con_Printf ("%s\n", VID_ModeInfo (vid_modenum, NULL));
}
/*
=================
VID_DescribeMode_f
=================
*/
void
VID_DescribeMode_f (void)
{
int modenum;
modenum = Q_atoi (Cmd_Argv (1));
Con_Printf ("%s\n", VID_ModeInfo (modenum, NULL));
}
/*
=================
VID_DescribeModes_f
=================
*/
void
VID_DescribeModes_f (void)
{
int i, nummodes;
char *pinfo, *pheader;
vmode_t *pv;
qboolean na;
na = false;
nummodes = VID_NumModes ();
for (i = 0; i < nummodes; i++) {
pv = VID_GetModePtr (i);
pinfo = VID_ModeInfo (i, &pheader);
if (pheader)
Con_Printf ("\n%s\n", pheader);
if (VGA_CheckAdequateMem (pv->width, pv->height, pv->rowbytes,
(pv->numpages == 1)
|| vid_nopageflip->int_val)) {
Con_Printf ("%2d: %s\n", i, pinfo);
} else {
Con_Printf ("**: %s\n", pinfo);
na = true;
}
}
if (na) {
Con_Printf ("\n[**: not enough system RAM for mode]\n");
}
}
/*
=================
VID_GetModeDescription
=================
*/
char *
VID_GetModeDescription (int mode)
{
char *pinfo, *pheader;
vmode_t *pv;
pv = VID_GetModePtr (mode);
pinfo = VID_ModeInfo (mode, &pheader);
if (VGA_CheckAdequateMem (pv->width, pv->height, pv->rowbytes,
(pv->numpages == 1) || vid_nopageflip->int_val)) {
return pinfo;
} else {
return NULL;
}
}
/*
=================
VID_TestMode_f
=================
*/
void
VID_TestMode_f (void)
{
int modenum;
double testduration;
if (!vid_testingmode) {
modenum = Q_atoi (Cmd_Argv (1));
if (VID_SetMode (modenum, vid_current_palette)) {
vid_testingmode = 1;
testduration = Q_atof (Cmd_Argv (2));
if (testduration == 0)
testduration = 5.0;
vid_testendtime = realtime + testduration;
}
}
}
/*
================
D_BeginDirectRect
================
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
if (!vid.direct || !pcurrentmode)
return;
if ((width > 24) || (height > 24) || (width < 1) || (height < 1))
return;
if (width & 0x03)
return;
(*pcurrentmode->begindirectrect) (&vid, pcurrentmode, x, y, pbitmap, width,
height);
}
/*
================
D_EndDirectRect
================
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
if (!vid.direct || !pcurrentmode)
return;
if ((width > 24) || (height > 24) || (width < 1) || (height < 1))
return;
if ((width & 0x03) || (height & 0x03))
return;
(*pcurrentmode->enddirectrect) (&vid, pcurrentmode, x, y, width, height);
}
//===========================================================================
extern void M_Menu_Options_f (void);
extern void M_Print (int cx, int cy, char *str);
extern void M_PrintWhite (int cx, int cy, char *str);
extern void M_DrawCharacter (int cx, int line, int num);
extern void M_DrawTransPic (int x, int y, qpic_t *pic);
extern void M_DrawPic (int x, int y, qpic_t *pic);
static int vid_line, vid_wmodes, vid_column_size;
typedef struct {
int modenum;
char *desc;
int iscur;
} modedesc_t;
#define MAX_COLUMN_SIZE 11
#define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
static modedesc_t modedescs[MAX_MODEDESCS];
/*
================
VID_MenuDraw
================
*/
void
VID_MenuDraw (void)
{
qpic_t *p;
char *ptr;
int nummodes, i, j, column, row, dup;
char temp[100];
vid_wmodes = 0;
nummodes = VID_NumModes ();
p = Draw_CachePic ("gfx/vidmodes.lmp");
M_DrawPic ((320 - p->width) / 2, 4, p);
for (i = 0; i < nummodes; i++) {
if (vid_wmodes < MAX_MODEDESCS) {
if (i != 1) {
ptr = VID_GetModeDescription (i);
if (ptr) {
dup = 0;
for (j = 0; j < vid_wmodes; j++) {
if (!strcmp (modedescs[j].desc, ptr)) {
if (modedescs[j].modenum != 0) {
modedescs[j].modenum = i;
dup = 1;
if (i == vid_modenum)
modedescs[j].iscur = 1;
} else {
dup = 1;
}
break;
}
}
if (!dup) {
modedescs[vid_wmodes].modenum = i;
modedescs[vid_wmodes].desc = ptr;
modedescs[vid_wmodes].iscur = 0;
if (i == vid_modenum)
modedescs[vid_wmodes].iscur = 1;
vid_wmodes++;
}
}
}
}
}
vid_column_size = (vid_wmodes + 2) / 3;
column = 16;
row = 36;
for (i = 0; i < vid_wmodes; i++) {
if (modedescs[i].iscur)
M_PrintWhite (column, row, modedescs[i].desc);
else
M_Print (column, row, modedescs[i].desc);
row += 8;
if ((i % vid_column_size) == (vid_column_size - 1)) {
column += 13 * 8;
row = 36;
}
}
// line cursor
if (vid_testingmode) {
snprintf (temp, sizeof (temp), "TESTING %s", modedescs[vid_line].desc);
M_Print (13 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 4, temp);
M_Print (9 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 6,
"Please wait 5 seconds...");
} else {
M_Print (9 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8,
"Press Enter to set mode");
M_Print (6 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 3,
"T to test mode for 5 seconds");
ptr = VID_GetModeDescription (vid_modenum);
snprintf (temp, sizeof (temp), "D to make %s the default", ptr);
M_Print (6 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 5, temp);
ptr = VID_GetModeDescription (_vid_default_mode->int_val);
if (ptr) {
snprintf (temp, sizeof (temp), "Current default is %s", ptr);
M_Print (7 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 6, temp);
}
M_Print (15 * 8, 36 + MAX_COLUMN_SIZE * 8 + 8 * 8, "Esc to exit");
row = 36 + (vid_line % vid_column_size) * 8;
column = 8 + (vid_line / vid_column_size) * 13 * 8;
M_DrawCharacter (column, row, 12 + ((int) (realtime * 4) & 1));
}
}
/*
================
VID_MenuKey
================
*/
void
VID_MenuKey (int key)
{
if (vid_testingmode)
return;
switch (key) {
case K_ESCAPE:
S_LocalSound ("misc/menu1.wav");
M_Menu_Options_f ();
break;
case K_UPARROW:
S_LocalSound ("misc/menu1.wav");
vid_line--;
if (vid_line < 0)
vid_line = vid_wmodes - 1;
break;
case K_DOWNARROW:
S_LocalSound ("misc/menu1.wav");
vid_line++;
if (vid_line >= vid_wmodes)
vid_line = 0;
break;
case K_LEFTARROW:
S_LocalSound ("misc/menu1.wav");
vid_line -= vid_column_size;
if (vid_line < 0) {
vid_line += ((vid_wmodes + (vid_column_size - 1)) /
vid_column_size) * vid_column_size;
while (vid_line >= vid_wmodes)
vid_line -= vid_column_size;
}
break;
case K_RIGHTARROW:
S_LocalSound ("misc/menu1.wav");
vid_line += vid_column_size;
if (vid_line >= vid_wmodes) {
vid_line -= ((vid_wmodes + (vid_column_size - 1)) /
vid_column_size) * vid_column_size;
while (vid_line < 0)
vid_line += vid_column_size;
}
break;
case K_ENTER:
S_LocalSound ("misc/menu1.wav");
VID_SetMode (modedescs[vid_line].modenum, vid_current_palette);
break;
case 'T':
case 't':
S_LocalSound ("misc/menu1.wav");
if (VID_SetMode (modedescs[vid_line].modenum, vid_current_palette)) {
vid_testingmode = 1;
vid_testendtime = realtime + 5.0;
}
break;
case 'D':
case 'd':
S_LocalSound ("misc/menu1.wav");
firstupdate = 0;
Cvar_SetValue (_vid_default_mode, vid_modenum);
break;
default:
break;
}
}
void
VID_HandlePause (qboolean pause)
{
}

View file

@ -1,773 +0,0 @@
/*
vid_ext.c
@description@
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <dos.h>
#include "d_local.h"
#include "dosisms.h"
#include "vid_dos.h"
#include <dpmi.h>
#define MODE_SUPPORTED_IN_HW 0x0001
#define COLOR_MODE 0x0008
#define GRAPHICS_MODE 0x0010
#define VGA_INCOMPATIBLE 0x0020
#define LINEAR_FRAME_BUFFER 0x0080
#define LINEAR_MODE 0x4000
#define VESA_DONT_WAIT_VSYNC 0 // when page flipping
#define VESA_WAIT_VSYNC 0x80
#define MAX_VESA_MODES 30 // we'll just take the first 30 if
// there
// are more
typedef struct {
int pages[3]; // either 2 or 3 is valid
int vesamode; // LINEAR_MODE set if linear mode
void *plinearmem; // linear address of start of frame
// buffer
qboolean vga_incompatible;
} vesa_extra_t;
static vmode_t vesa_modes[MAX_VESA_MODES] =
{ {NULL, NULL, " ********* VESA modes ********* "} };
static vesa_extra_t vesa_extra[MAX_VESA_MODES];
static char names[MAX_VESA_MODES][10];
extern regs_t regs;
static int VID_currentpage;
static int VID_displayedpage;
static int *VID_pagelist;
static byte *VID_membase;
static int VID_banked;
typedef struct {
int modenum;
int mode_attributes;
int winasegment;
int winbsegment;
int bytes_per_scanline; // bytes per logical scanline (+16)
int win; // window number (A=0, B=1)
int win_size; // window size (+6)
int granularity; // how finely i can set the window in
//
//
// vid mem (+4)
int width, height; // displayed width and height (+18,
// +20)
int bits_per_pixel; // er, better be 8, 15, 16, 24, or 32
//
//
// (+25)
int bytes_per_pixel; // er, better be 1, 2, or 4
int memory_model; // and better be 4 or 6, packed or
// direct color (+27)
int num_pages; // number of complete frame buffer
// pages (+29)
int red_width; // the # of bits in the red component
//
//
// (+31)
int red_pos; // the bit position of the red
// component (+32)
int green_width; // etc.. (+33)
int green_pos; // (+34)
int blue_width; // (+35)
int blue_pos; // (+36)
int pptr;
int pagesize;
int numpages;
} modeinfo_t;
static modeinfo_t modeinfo;
// all bytes to avoid problems with compiler field packing
typedef struct vbeinfoblock_s {
byte VbeSignature[4];
byte VbeVersion[2];
byte OemStringPtr[4];
byte Capabilities[4];
byte VideoModePtr[4];
byte TotalMemory[2];
byte OemSoftwareRev[2];
byte OemVendorNamePtr[4];
byte OemProductNamePtr[4];
byte OemProductRevPtr[4];
byte Reserved[222];
byte OemData[256];
} vbeinfoblock_t;
static int totalvidmem;
static byte *ppal;
qboolean vsync_exists, de_exists;
qboolean VID_ExtraGetModeInfo (int modenum);
int VID_ExtraInitMode (viddef_t *vid, vmode_t * pcurrentmode);
void VID_ExtraSwapBuffers (viddef_t *vid, vmode_t * pcurrentmode,
vrect_t *rects);
/*
================
VGA_BankedBeginDirectRect
================
*/
void
VGA_BankedBeginDirectRect (viddef_t *lvid, struct vmode_s *pcurrentmode,
int x, int y, byte * pbitmap, int width, int height)
{
if (!lvid->direct)
return;
regs.x.ax = 0x4f05;
regs.x.bx = 0;
regs.x.dx = VID_displayedpage;
dos_int86 (0x10);
VGA_BeginDirectRect (lvid, pcurrentmode, x, y, pbitmap, width, height);
regs.x.ax = 0x4f05;
regs.x.bx = 0;
regs.x.dx = VID_currentpage;
dos_int86 (0x10);
}
/*
================
VGA_BankedEndDirectRect
================
*/
void
VGA_BankedEndDirectRect (viddef_t *lvid, struct vmode_s *pcurrentmode,
int x, int y, int width, int height)
{
if (!lvid->direct)
return;
regs.x.ax = 0x4f05;
regs.x.bx = 0;
regs.x.dx = VID_displayedpage;
dos_int86 (0x10);
VGA_EndDirectRect (lvid, pcurrentmode, x, y, width, height);
regs.x.ax = 0x4f05;
regs.x.bx = 0;
regs.x.dx = VID_currentpage;
dos_int86 (0x10);
}
/*
================
VID_SetVESAPalette
================
*/
void
VID_SetVESAPalette (viddef_t *lvid, vmode_t * pcurrentmode, unsigned char *pal)
{
int i;
byte *pp;
UNUSED (lvid);
UNUSED (pcurrentmode);
pp = ppal;
for (i = 0; i < 256; i++) {
pp[2] = pal[0] >> 2;
pp[1] = pal[1] >> 2;
pp[0] = pal[2] >> 2;
pp += 4;
pal += 3;
}
regs.x.ax = 0x4F09;
regs.x.bx = 0;
regs.x.cx = 256;
regs.x.dx = 0;
regs.x.es = ptr2real (ppal) >> 4;
regs.x.di = ptr2real (ppal) & 0xf;
dos_int86 (0x10);
if (regs.x.ax != 0x4f)
Sys_Error ("Unable to load VESA palette\n");
}
/*
================
VID_ExtraFarToLinear
================
*/
void *
VID_ExtraFarToLinear (void *ptr)
{
int temp;
temp = (int) ptr;
return real2ptr (((temp & 0xFFFF0000) >> 12) + (temp & 0xFFFF));
}
/*
================
VID_ExtraWaitDisplayEnable
================
*/
void
VID_ExtraWaitDisplayEnable ()
{
while ((inportb (0x3DA) & 0x01) == 1);
}
/*
================
VID_ExtraVidLookForState
================
*/
qboolean
VID_ExtraVidLookForState (unsigned state, unsigned mask)
{
int i;
double starttime, time;
starttime = Sys_DoubleTime ();
do {
for (i = 0; i < 100000; i++) {
if ((inportb (0x3DA) & mask) == state)
return true;
}
time = Sys_DoubleTime ();
} while ((time - starttime) < 0.1);
return false;
}
/*
================
VID_ExtraStateFound
================
*/
qboolean
VID_ExtraStateFound (unsigned state)
{
int i, workingstate;
workingstate = 0;
for (i = 0; i < 10; i++) {
if (!VID_ExtraVidLookForState (workingstate, state)) {
return false;
}
workingstate ^= state;
}
return true;
}
/*
================
VID_InitExtra
================
*/
void
VID_InitExtra (void)
{
int nummodes;
short *pmodenums;
vbeinfoblock_t *pinfoblock;
__dpmi_meminfo phys_mem_info;
pinfoblock = dos_getmemory (sizeof (vbeinfoblock_t));
*(long *) pinfoblock->VbeSignature =
'V' + ('B' << 8) + ('E' << 16) + ('2' << 24);
// see if VESA support is available
regs.x.ax = 0x4f00;
regs.x.es = ptr2real (pinfoblock) >> 4;
regs.x.di = ptr2real (pinfoblock) & 0xf;
dos_int86 (0x10);
if (regs.x.ax != 0x4f)
return; // no VESA support
if (pinfoblock->VbeVersion[1] < 0x02)
return; // not VESA 2.0 or greater
Con_Printf ("VESA 2.0 compliant adapter:\n%s\n",
VID_ExtraFarToLinear (*(byte **) &
pinfoblock->OemStringPtr[0]));
totalvidmem = *(unsigned short *) &pinfoblock->TotalMemory[0] << 16;
pmodenums = (short *)
VID_ExtraFarToLinear (*(byte **) & pinfoblock->VideoModePtr[0]);
// find 8 bit modes until we either run out of space or run out of modes
nummodes = 0;
while ((*pmodenums != -1) && (nummodes < MAX_VESA_MODES)) {
if (VID_ExtraGetModeInfo (*pmodenums)) {
vesa_modes[nummodes].pnext = &vesa_modes[nummodes + 1];
if (modeinfo.width > 999) {
if (modeinfo.height > 999) {
snprintf (&names[nummodes][0], sizeof (&names[nummodes][0]),
"%4dx%4d", modeinfo.width, modeinfo.height);
names[nummodes][9] = 0;
} else {
snprintf (&names[nummodes][0], sizeof (&names[nummodes][0]),
"%4dx%3d", modeinfo.width, modeinfo.height);
names[nummodes][8] = 0;
}
} else {
if (modeinfo.height > 999) {
snprintf (&names[nummodes][0], sizeof (&names[nummodes][0]),
"%3dx%4d", modeinfo.width, modeinfo.height);
names[nummodes][8] = 0;
} else {
snprintf (&names[nummodes][0], sizeof (&names[nummodes][0]),
"%3dx%3d", modeinfo.width, modeinfo.height);
names[nummodes][7] = 0;
}
}
vesa_modes[nummodes].name = &names[nummodes][0];
vesa_modes[nummodes].width = modeinfo.width;
vesa_modes[nummodes].height = modeinfo.height;
vesa_modes[nummodes].aspect =
((float) modeinfo.height / (float) modeinfo.width) *
(320.0 / 240.0);
vesa_modes[nummodes].rowbytes = modeinfo.bytes_per_scanline;
vesa_modes[nummodes].planar = 0;
vesa_modes[nummodes].pextradata = &vesa_extra[nummodes];
vesa_modes[nummodes].setmode = VID_ExtraInitMode;
vesa_modes[nummodes].swapbuffers = VID_ExtraSwapBuffers;
vesa_modes[nummodes].setpalette = VID_SetVESAPalette;
if (modeinfo.mode_attributes & LINEAR_FRAME_BUFFER) {
// add linear bit to mode for linear modes
vesa_extra[nummodes].vesamode = modeinfo.modenum | LINEAR_MODE;
vesa_extra[nummodes].pages[0] = 0;
vesa_extra[nummodes].pages[1] = modeinfo.pagesize;
vesa_extra[nummodes].pages[2] = modeinfo.pagesize * 2;
vesa_modes[nummodes].numpages = modeinfo.numpages;
vesa_modes[nummodes].begindirectrect = VGA_BeginDirectRect;
vesa_modes[nummodes].enddirectrect = VGA_EndDirectRect;
phys_mem_info.address = (int) modeinfo.pptr;
phys_mem_info.size = 0x400000;
if (__dpmi_physical_address_mapping (&phys_mem_info))
goto NextMode;
vesa_extra[nummodes].plinearmem =
real2ptr (phys_mem_info.address);
} else {
// banked at 0xA0000
vesa_extra[nummodes].vesamode = modeinfo.modenum;
vesa_extra[nummodes].pages[0] = 0;
vesa_extra[nummodes].plinearmem =
real2ptr (modeinfo.winasegment << 4);
vesa_modes[nummodes].begindirectrect =
VGA_BankedBeginDirectRect;
vesa_modes[nummodes].enddirectrect = VGA_BankedEndDirectRect;
vesa_extra[nummodes].pages[1] = modeinfo.pagesize;
vesa_extra[nummodes].pages[2] = modeinfo.pagesize * 2;
vesa_modes[nummodes].numpages = modeinfo.numpages;
}
vesa_extra[nummodes].vga_incompatible =
modeinfo.mode_attributes & VGA_INCOMPATIBLE;
nummodes++;
}
NextMode:
pmodenums++;
}
// add the VESA modes at the start of the mode list (if there are any)
if (nummodes) {
vesa_modes[nummodes - 1].pnext = pvidmodes;
pvidmodes = &vesa_modes[0];
numvidmodes += nummodes;
ppal = dos_getmemory (256 * 4);
}
dos_freememory (pinfoblock);
}
/*
================
VID_ExtraGetModeInfo
================
*/
qboolean
VID_ExtraGetModeInfo (int modenum)
{
char *infobuf;
int numimagepages;
infobuf = dos_getmemory (256);
regs.x.ax = 0x4f01;
regs.x.cx = modenum;
regs.x.es = ptr2real (infobuf) >> 4;
regs.x.di = ptr2real (infobuf) & 0xf;
dos_int86 (0x10);
if (regs.x.ax != 0x4f) {
return false;
} else {
modeinfo.modenum = modenum;
modeinfo.bits_per_pixel = *(char *) (infobuf + 25);
modeinfo.bytes_per_pixel = (modeinfo.bits_per_pixel + 1) / 8;
modeinfo.width = *(short *) (infobuf + 18);
modeinfo.height = *(short *) (infobuf + 20);
// we do only 8-bpp in software
if ((modeinfo.bits_per_pixel != 8) ||
(modeinfo.bytes_per_pixel != 1) ||
(modeinfo.width > MAXWIDTH) || (modeinfo.height > MAXHEIGHT)) {
return false;
}
modeinfo.mode_attributes = *(short *) infobuf;
// we only want color graphics modes that are supported by the
// hardware
if ((modeinfo.mode_attributes &
(MODE_SUPPORTED_IN_HW | COLOR_MODE | GRAPHICS_MODE)) !=
(MODE_SUPPORTED_IN_HW | COLOR_MODE | GRAPHICS_MODE)) {
return false;
}
// we only work with linear frame buffers, except for 320x200, which
// can
// effectively be linear when banked at 0xA000
if (!(modeinfo.mode_attributes & LINEAR_FRAME_BUFFER)) {
if ((modeinfo.width != 320) || (modeinfo.height != 200))
return false;
}
modeinfo.bytes_per_scanline = *(short *) (infobuf + 16);
modeinfo.pagesize = modeinfo.bytes_per_scanline * modeinfo.height;
if (modeinfo.pagesize > totalvidmem)
return false;
// force to one page if the adapter reports it doesn't support more
// pages
// than that, no matter how much memory it has--it may not have
// hardware
// support for page flipping
numimagepages = *(unsigned char *) (infobuf + 29);
if (numimagepages <= 0) {
// wrong, but there seems to be an ATI VESA driver that reports 0
modeinfo.numpages = 1;
} else if (numimagepages < 3) {
modeinfo.numpages = numimagepages;
} else {
modeinfo.numpages = 3;
}
if (*(char *) (infobuf + 2) & 5) {
modeinfo.winasegment = *(unsigned short *) (infobuf + 8);
modeinfo.win = 0;
} else if (*(char *) (infobuf + 3) & 5) {
modeinfo.winbsegment = *(unsigned short *) (infobuf + 8);
modeinfo.win = 1;
}
modeinfo.granularity = *(short *) (infobuf + 4) * 1024;
modeinfo.win_size = *(short *) (infobuf + 6) * 1024;
modeinfo.bits_per_pixel = *(char *) (infobuf + 25);
modeinfo.bytes_per_pixel = (modeinfo.bits_per_pixel + 1) / 8;
modeinfo.memory_model = *(unsigned char *) (infobuf + 27);
modeinfo.num_pages = *(char *) (infobuf + 29) + 1;
modeinfo.red_width = *(char *) (infobuf + 31);
modeinfo.red_pos = *(char *) (infobuf + 32);
modeinfo.green_width = *(char *) (infobuf + 33);
modeinfo.green_pos = *(char *) (infobuf + 34);
modeinfo.blue_width = *(char *) (infobuf + 35);
modeinfo.blue_pos = *(char *) (infobuf + 36);
modeinfo.pptr = *(long *) (infobuf + 40);
#if 0
printf ("VID: (VESA) info for mode 0x%x\n", modeinfo.modenum);
printf (" mode attrib = 0x%0x\n", modeinfo.mode_attributes);
printf (" win a attrib = 0x%0x\n", *(unsigned char *) (infobuf + 2));
printf (" win b attrib = 0x%0x\n", *(unsigned char *) (infobuf + 3));
printf (" win a seg 0x%0x\n", (int) modeinfo.winasegment);
printf (" win b seg 0x%0x\n", (int) modeinfo.winbsegment);
printf (" bytes per scanline = %d\n", modeinfo.bytes_per_scanline);
printf (" width = %d, height = %d\n", modeinfo.width, modeinfo.height);
printf (" win = %c\n", 'A' + modeinfo.win);
printf (" win granularity = %d\n", modeinfo.granularity);
printf (" win size = %d\n", modeinfo.win_size);
printf (" bits per pixel = %d\n", modeinfo.bits_per_pixel);
printf (" bytes per pixel = %d\n", modeinfo.bytes_per_pixel);
printf (" memory model = 0x%x\n", modeinfo.memory_model);
printf (" num pages = %d\n", modeinfo.num_pages);
printf (" red width = %d\n", modeinfo.red_width);
printf (" red pos = %d\n", modeinfo.red_pos);
printf (" green width = %d\n", modeinfo.green_width);
printf (" green pos = %d\n", modeinfo.green_pos);
printf (" blue width = %d\n", modeinfo.blue_width);
printf (" blue pos = %d\n", modeinfo.blue_pos);
printf (" phys mem = %x\n", modeinfo.pptr);
#endif
}
dos_freememory (infobuf);
return true;
}
/*
================
VID_ExtraInitMode
================
*/
int
VID_ExtraInitMode (viddef_t *lvid, vmode_t * pcurrentmode)
{
vesa_extra_t *pextra;
int pageoffset;
pextra = pcurrentmode->pextradata;
if (vid_nopageflip->int_val)
lvid->numpages = 1;
else
lvid->numpages = pcurrentmode->numpages;
// clean up any old vid buffer lying around, alloc new if needed
if (!VGA_FreeAndAllocVidbuffer (lvid, lvid->numpages == 1))
return -1; // memory alloc failed
// clear the screen and wait for the next frame. VGA_pcurmode, which
// VGA_ClearVideoMem relies on, is guaranteed to be set because mode 0 is
// always the first mode set in a session
if (VGA_pcurmode)
VGA_ClearVideoMem (VGA_pcurmode->planar);
// set the mode
regs.x.ax = 0x4f02;
regs.x.bx = pextra->vesamode;
dos_int86 (0x10);
if (regs.x.ax != 0x4f)
return 0;
VID_banked = !(pextra->vesamode & LINEAR_MODE);
VID_membase = pextra->plinearmem;
VGA_width = lvid->width;
VGA_height = lvid->height;
VGA_rowbytes = lvid->rowbytes;
lvid->colormap = host_colormap;
VID_pagelist = &pextra->pages[0];
// wait for display enable by default only when triple-buffering on a VGA-
// compatible machine that actually has a functioning display enable status
vsync_exists = VID_ExtraStateFound (0x08);
de_exists = VID_ExtraStateFound (0x01);
if (!pextra->vga_incompatible &&
(lvid->numpages == 3) && de_exists && !_vid_wait_override->int_val) {
Cvar_SetValue (vid_wait, (float) VID_WAIT_DISPLAY_ENABLE);
VID_displayedpage = 0;
VID_currentpage = 1;
} else {
if ((lvid->numpages == 1) && !_vid_wait_override->int_val) {
Cvar_SetValue (vid_wait, (float) VID_WAIT_NONE);
VID_displayedpage = VID_currentpage = 0;
} else {
Cvar_SetValue (vid_wait, (float) VID_WAIT_VSYNC);
VID_displayedpage = 0;
if (lvid->numpages > 1)
VID_currentpage = 1;
else
VID_currentpage = 0;
}
}
// TODO: really should be a call to a function
pageoffset = VID_pagelist[VID_displayedpage];
regs.x.ax = 0x4f07;
regs.x.bx = 0x80; // wait for vsync so we know page 0
// is visible
regs.x.cx = pageoffset % VGA_rowbytes;
regs.x.dx = pageoffset / VGA_rowbytes;
dos_int86 (0x10);
if (VID_banked) {
regs.x.ax = 0x4f05;
regs.x.bx = 0;
regs.x.dx = VID_currentpage;
dos_int86 (0x10);
VGA_pagebase = VID_membase;
} else {
VGA_pagebase = VID_membase + VID_pagelist[VID_currentpage];
}
if (lvid->numpages > 1) {
lvid->buffer = VGA_pagebase;
lvid->conbuffer = lvid->buffer;
} else {
lvid->rowbytes = lvid->width;
}
lvid->direct = VGA_pagebase;
lvid->conrowbytes = lvid->rowbytes;
lvid->conwidth = lvid->width;
lvid->conheight = lvid->height;
lvid->maxwarpwidth = WARP_WIDTH;
lvid->maxwarpheight = WARP_HEIGHT;
VGA_pcurmode = pcurrentmode;
D_InitCaches (vid_surfcache, vid_surfcachesize);
return 1;
}
/*
================
VID_ExtraSwapBuffers
================
*/
void
VID_ExtraSwapBuffers (viddef_t *lvid, vmode_t * pcurrentmode, vrect_t *rects)
{
int pageoffset;
UNUSED (rects);
UNUSED (pcurrentmode);
pageoffset = VID_pagelist[VID_currentpage];
// display the newly finished page
if (lvid->numpages > 1) {
// page flipped
regs.x.ax = 0x4f07;
if (vid_wait->int_val != VID_WAIT_VSYNC) {
if ((vid_wait->int_val == VID_WAIT_DISPLAY_ENABLE) && de_exists)
VID_ExtraWaitDisplayEnable ();
regs.x.bx = VESA_DONT_WAIT_VSYNC;
} else {
regs.x.bx = VESA_WAIT_VSYNC; // double buffered has to wait
}
regs.x.cx = pageoffset % VGA_rowbytes;
regs.x.dx = pageoffset / VGA_rowbytes;
dos_int86 (0x10);
VID_displayedpage = VID_currentpage;
if (++VID_currentpage >= lvid->numpages)
VID_currentpage = 0;
//
// set the new write window if this is a banked mode; otherwise, set
// the
// new address to which to write
//
if (VID_banked) {
regs.x.ax = 0x4f05;
regs.x.bx = 0;
regs.x.dx = VID_currentpage;
dos_int86 (0x10);
} else {
lvid->direct = lvid->buffer; // direct drawing goes to the
// currently displayed page
lvid->buffer = VID_membase + VID_pagelist[VID_currentpage];
lvid->conbuffer = lvid->buffer;
}
VGA_pagebase = lvid->buffer;
} else {
// non-page-flipped
if (vsync_exists && (vid_wait->int_val == VID_WAIT_VSYNC)) {
VGA_WaitVsync ();
}
while (rects) {
VGA_UpdateLinearScreen (lvid->buffer + rects->x +
(rects->y * lvid->rowbytes),
VGA_pagebase + rects->x +
(rects->y * VGA_rowbytes), rects->width,
rects->height, lvid->rowbytes,
VGA_rowbytes);
rects = rects->pnext;
}
}
}
void
VID_HandlePause (qboolean pause)
{
}

View file

@ -1,709 +0,0 @@
/*
vid_fbdev.c
Linux FBDev video routines
based on vid_svgalib.c
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999-2000 David Symonds [xoxus@usa.net]
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_IO_H
# include <sys/io.h>
#elif defined(HAVE_ASM_IO_H)
# include <asm/io.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <asm/page.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "d_local.h"
#include "host.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/sys.h"
#include "fbset.h"
unsigned short d_8to16table[256];
extern void ReadModeDB(void);
extern struct VideoMode *FindVideoMode(const char *name);
void ConvertFromVideoMode(const struct VideoMode *vmode,
struct fb_var_screeninfo *var);
void ConvertToVideoMode(const struct fb_var_screeninfo *var,
struct VideoMode *vmode);
extern struct VideoMode *VideoModes;
static struct VideoMode current_mode;
static char current_name[32];
static int num_modes;
static int fb_fd = -1;
static int tty_fd = 0;
static byte vid_current_palette[768];
static int fbdev_inited = 0;
static int fbdev_backgrounded = 0;
static int UseDisplay = 1;
static cvar_t *vid_mode;
static cvar_t *vid_redrawfull;
static cvar_t *vid_waitforrefresh;
static char *framebuffer_ptr;
static byte backingbuf[48 * 24];
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
int i, j, reps, repshift, offset, off;
if (!fbdev_inited || !vid.direct || fbdev_backgrounded)
return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
memcpy (&backingbuf[(i + j) * 24], vid.direct + off, width);
memcpy (vid.direct + off,
&pbitmap[(i >> repshift) * width], width);
}
}
}
void
D_EndDirectRect (int x, int y, int width, int height)
{
int i, j, reps, repshift, offset, off;
if (!fbdev_inited || !vid.direct || fbdev_backgrounded)
return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
memcpy (vid.direct + off, &backingbuf[(i + j) * 24], width);
}
}
}
static void
VID_Gamma_f (void)
{
float gamma, f, inf;
unsigned char palette[768];
int i;
if (Cmd_Argc () == 2) {
gamma = atof (Cmd_Argv (1));
for (i = 0; i < 768; i++) {
f = pow ((host_basepal[i] + 1) / 256.0, gamma);
inf = f * 255 + 0.5;
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
palette[i] = inf;
}
VID_SetPalette (palette);
/* Force a surface cache flush */
vid.recalc_refdef = 1;
}
}
static void
VID_DescribeMode_f (void)
{
char *modestr;
struct VideoMode *vmode;
modestr = Cmd_Argv(1);
vmode = FindVideoMode(modestr);
if (!vmode) {
Con_Printf ("Invalid video mode: %s!\n", modestr);
return;
}
Con_Printf ("%s: %d x %d - %d bpp - %5.3f Hz\n", vmode->name,
vmode->xres, vmode->yres, vmode->depth, vmode->vrate);
}
static void
VID_DescribeModes_f (void)
{
struct VideoMode *vmode;
for (vmode = VideoModes; vmode; vmode = vmode->next) {
Con_Printf ("%s: %d x %d - %d bpp - %5.3f Hz\n", vmode->name,
vmode->xres, vmode->yres, vmode->depth, vmode->vrate);
}
}
/*
VID_NumModes
*/
static int
VID_NumModes (void)
{
struct VideoMode *vmode;
int i = 0;
for (vmode = VideoModes; vmode; vmode = vmode->next)
i++;
return i;
}
static void
VID_NumModes_f (void)
{
Con_Printf ("%d modes\n", VID_NumModes ());
}
int VID_SetMode (char *name, unsigned char *palette);
extern void fbset_main (int argc, char **argv);
static void
VID_fbset_f (void)
{
int i, argc;
char *argv[32];
argc = Cmd_Argc();
if (argc > 32)
argc = 32;
argv[0] = "vid_fbset";
for (i = 1; i < argc; i++) {
argv[i] = Cmd_Argv(i);
}
fbset_main(argc, argv);
}
static void
VID_Debug_f (void)
{
Con_Printf ("mode: %s\n", current_mode.name);
Con_Printf ("height x width: %d x %d\n", current_mode.xres, current_mode.yres);
Con_Printf ("bpp: %d\n", current_mode.depth);
Con_Printf ("vrate: %5.3f\n", current_mode.vrate);
Con_Printf ("vid.aspect: %f\n", vid.aspect);
}
static void
VID_InitModes (void)
{
ReadModeDB();
num_modes = VID_NumModes();
}
static char *
get_mode (char *name, int width, int height, int depth)
{
struct VideoMode *vmode;
for (vmode = VideoModes; vmode; vmode = vmode->next) {
if (name) {
if (!strcmp(vmode->name, name))
return name;
} else {
if (vmode->xres == width
&& vmode->yres == height
&& vmode->depth == depth)
return vmode->name;
}
}
Sys_Printf ("Mode %dx%d (%d bits) not supported\n",
width, height, depth);
return "640x480-60";
}
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize;
void *vid_surfcache;
// Calculate the sizes we want first
buffersize = vid.rowbytes * vid.height;
zbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
cachesize = D_SurfaceCacheForRes (vid.width, vid.height);
// Free the old screen buffer
if (vid.buffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
}
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new screen buffer
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
if (!vid.conbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new z-buffer
d_pzbuffer = calloc (zbuffersize, 1);
if (!d_pzbuffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (cachesize, 1);
if (!vid_surfcache) {
free (vid.buffer);
free (d_pzbuffer);
vid.conbuffer = vid.buffer = NULL;
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, cachesize);
}
static unsigned char *fb_map_addr = 0;
static unsigned long fb_map_length = 0;
static struct fb_var_screeninfo orig_var;
void
VID_Shutdown (void)
{
Sys_Printf ("VID_Shutdown\n");
if (!fbdev_inited)
return;
if (munmap(fb_map_addr, fb_map_length) == -1) {
Sys_Printf("could not unmap framebuffer at %p: %s\n",
fb_map_addr, strerror(errno));
} else {
if (ioctl(fb_fd, FBIOPUT_VSCREENINFO, &orig_var))
Sys_Printf ("failed to get var screen info\n");
}
close(fb_fd);
if (UseDisplay) {
ioctl(tty_fd, KDSETMODE, KD_TEXT);
write(tty_fd, "\033]R", 3); /* reset palette */
}
fbdev_inited = 0;
}
void
VID_ShiftPalette (unsigned char *p)
{
VID_SetPalette (p);
}
static void
loadpalette (unsigned short *red, unsigned short *green, unsigned short *blue)
{
struct fb_cmap cmap;
cmap.len = 256;
cmap.red = red;
cmap.green = green;
cmap.blue = blue;
cmap.transp = NULL;
cmap.start = 0;
if (-1 == ioctl(fb_fd, FBIOPUTCMAP, (void *)&cmap))
Sys_Error("ioctl FBIOPUTCMAP %s\n", strerror(errno));
}
void
VID_SetPalette (byte * palette)
{
static unsigned short tmppalr[256], tmppalg[256], tmppalb[256];
unsigned short i, *tpr, *tpg, *tpb;
if (!fbdev_inited || fbdev_backgrounded || fb_fd < 0)
return;
memcpy (vid_current_palette, palette, sizeof (vid_current_palette));
if (current_mode.depth == 8) {
tpr = tmppalr;
tpg = tmppalg;
tpb = tmppalb;
for (i = 0; i < 256; i++) {
*tpr++ = (*palette++) << 8;
*tpg++ = (*palette++) << 8;
*tpb++ = (*palette++) << 8;
}
if (UseDisplay) {
loadpalette(tmppalr, tmppalg, tmppalb);
}
}
}
int
VID_SetMode (char *name, unsigned char *palette)
{
struct VideoMode *vmode;
struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;
int err;
unsigned long smem_start, smem_offset;
vmode = FindVideoMode(name);
if (!vmode) {
Cvar_Set (vid_mode, current_mode.name);
// Con_Printf ("No such video mode: %s\n", name);
return 0;
}
current_mode = *vmode;
Cvar_Set (vid_mode, current_mode.name);
strncpy(current_name, current_mode.name, sizeof(current_name)-1);
current_name[31] = 0;
vid.width = vmode->xres;
vid.height = vmode->yres;
vid.rowbytes = vmode->xres * (vmode->depth >> 3);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.colormap = (pixel_t *) host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.numpages = 1;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
if (fb_map_addr) {
if (munmap(fb_map_addr, fb_map_length) == -1) {
Sys_Printf("could not unmap framebuffer at %p: %s\n",
fb_map_addr, strerror(errno));
}
}
ConvertFromVideoMode(&current_mode, &var);
err = ioctl(fb_fd, FBIOPUT_VSCREENINFO, &var);
if (err)
Sys_Error ("Video mode failed: %s\n", name);
ConvertToVideoMode(&var, &current_mode);
current_mode.name = current_name;
VID_SetPalette (palette);
err = ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix);
if (err)
Sys_Error ("Video mode failed: %s\n", name);
smem_start = (unsigned long)fix.smem_start & PAGE_MASK;
smem_offset = (unsigned long)fix.smem_start & ~PAGE_MASK;
fb_map_length = (smem_offset+fix.smem_len+~PAGE_MASK) & PAGE_MASK;
fb_map_addr = (char *)mmap(0, fb_map_length, PROT_WRITE, MAP_SHARED, fb_fd, 0);
if (!fb_map_addr)
Sys_Error ("This mode isn't hapnin'\n");
vid.direct = framebuffer_ptr = fb_map_addr;
// alloc screen buffer, z-buffer, and surface cache
VID_InitBuffers ();
if (!fbdev_inited) {
fbdev_inited = 1;
}
/* Force a surface cache flush */
vid.recalc_refdef = 1;
return 1;
}
static void
fb_switch_handler (int sig)
{
if (sig == SIGUSR1) {
fbdev_backgrounded = 1;
} else if (sig == SIGUSR2) {
fbdev_backgrounded = 2;
}
}
static void
fb_switch_release (void)
{
ioctl(tty_fd, VT_RELDISP, 1);
}
static void
fb_switch_acquire (void)
{
ioctl(tty_fd, VT_RELDISP, VT_ACKACQ);
}
static void
fb_switch_init (void)
{
struct sigaction act;
struct vt_mode vtmode;
memset(&act, 0, sizeof(act));
act.sa_handler = fb_switch_handler;
sigemptyset(&act.sa_mask);
sigaction(SIGUSR1, &act, 0);
sigaction(SIGUSR2, &act, 0);
if (ioctl(tty_fd, VT_GETMODE, &vtmode)) {
Sys_Error("ioctl VT_GETMODE: %s\n", strerror(errno));
}
vtmode.mode = VT_PROCESS;
vtmode.waitv = 0;
vtmode.relsig = SIGUSR1;
vtmode.acqsig = SIGUSR2;
if (ioctl(tty_fd, VT_SETMODE, &vtmode)) {
Sys_Error("ioctl VT_SETMODE: %s\n", strerror(errno));
}
}
void
VID_Init (unsigned char *palette)
{
int w, h, d;
struct VideoMode *vmode;
char *modestr;
char *fbname;
// plugin_load("in_fbdev.so");
if (fbdev_inited)
return;
Cmd_AddCommand ("gamma", VID_Gamma_f, "No Description");
if (UseDisplay) {
fbname = getenv("FRAMEBUFFER");
if (!fbname)
fbname = "/dev/fb0";
fb_fd = open(fbname, O_RDWR);
if (fb_fd < 0)
Sys_Error ("failed to open fb device\n");
if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &orig_var))
Sys_Error ("failed to get var screen info\n");
fb_switch_init();
VID_InitModes ();
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, "No Description");
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f, "No Description");
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f, "No Description");
Cmd_AddCommand ("vid_debug", VID_Debug_f, "No Description");
Cmd_AddCommand ("vid_fbset", VID_fbset_f, "No Description");
/* Interpret command-line params */
w = h = d = 0;
if (getenv ("GFBDEVMODE")) {
modestr = get_mode (getenv ("GFBDEVMODE"), w, h, d);
} else if (COM_CheckParm ("-mode")) {
modestr = get_mode (com_argv[COM_CheckParm ("-mode") + 1], w, h, d);
} else if (COM_CheckParm ("-w") || COM_CheckParm ("-h")
|| COM_CheckParm ("-d")) {
if (COM_CheckParm ("-w")) {
w = atoi (com_argv[COM_CheckParm ("-w") + 1]);
}
if (COM_CheckParm ("-h")) {
h = atoi (com_argv[COM_CheckParm ("-h") + 1]);
}
if (COM_CheckParm ("-d")) {
d = atoi (com_argv[COM_CheckParm ("-d") + 1]);
}
modestr = get_mode (0, w, h, d);
} else {
modestr = "640x480-60";
}
/* Set vid parameters */
vmode = FindVideoMode(modestr);
if (!vmode)
Sys_Error("no video mode %s\n", modestr);
current_mode = *vmode;
ioctl(tty_fd, KDSETMODE, KD_GRAPHICS);
VID_SetMode (current_mode.name, palette);
Con_CheckResize (); // Now that we have a window size, fix console
VID_SetPalette (palette);
}
}
void
VID_Init_Cvars ()
{
vid_mode = Cvar_Get ("vid_mode", "0", CVAR_NONE, NULL,
"Sets the video mode");
vid_redrawfull = Cvar_Get ("vid_redrawfull", "0", CVAR_NONE, NULL,
"Redraw entire screen each frame instead of just dirty areas");
vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh", "0", CVAR_ARCHIVE,
NULL, "Wait for vertical retrace before drawing next frame");
}
void
VID_Update (vrect_t *rects)
{
if (!fbdev_inited)
return;
if (fbdev_backgrounded) {
if (fbdev_backgrounded == 3) {
return;
} else if (fbdev_backgrounded == 2) {
fb_switch_acquire();
fbdev_backgrounded = 0;
VID_SetPalette(vid_current_palette);
} else if (fbdev_backgrounded == 1) {
fb_switch_release();
fbdev_backgrounded = 3;
return;
}
}
if (vid_waitforrefresh->int_val) {
// ???
}
if (vid_redrawfull->int_val) {
double *d = (double *)framebuffer_ptr, *s = (double *)vid.buffer;
double *ends = (double *)(vid.buffer + vid.height*vid.rowbytes);
while (s < ends)
*d++ = *s++;
} else {
while (rects) {
int height, width, lineskip, i, j, xoff, yoff;
double *d, *s;
height = rects->height;
width = rects->width / sizeof(double);
xoff = rects->x;
yoff = rects->y;
lineskip = (vid.width - (xoff + rects->width)) / sizeof(double);
d = (double *)(framebuffer_ptr + yoff * vid.rowbytes + xoff);
s = (double *)(vid.buffer + yoff * vid.rowbytes + xoff);
for (i = yoff; i < height; i++) {
for (j = xoff; j < width; j++)
*d++ = *s++;
d += lineskip;
s += lineskip;
}
rects = rects->pnext;
}
}
if (current_mode.name && strcmp(vid_mode->string, current_mode.name)) {
VID_SetMode (vid_mode->string, vid_current_palette);
}
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
}
void
VID_HandlePause (qboolean paused)
{
}

View file

@ -1,240 +0,0 @@
/*
vid_glx.c
OpenGL GLX video driver
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include <GL/glx.h>
#include <X11/keysym.h>
#include <X11/cursorfont.h>
#ifdef HAVE_DGA
# include <X11/extensions/xf86dga.h>
#endif
#include "QF/compat.h"
#include "QF/console.h"
#include "context_x11.h"
#include "glquake.h"
#include "host.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "sbar.h"
#include "QF/va.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
static qboolean vid_initialized = false;
static GLXContext ctx = NULL;
extern void GL_Init_Common (void);
extern void VID_Init8bitPalette (void);
/*-----------------------------------------------------------------------*/
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
void
VID_Shutdown (void)
{
if (!vid_initialized)
return;
Con_Printf ("VID_Shutdown\n");
x11_restore_vidmode ();
x11_close_display ();
}
#if 0
static void
signal_handler (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Sys_Quit ();
exit (sig);
}
static void
InitSig (void)
{
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
signal (SIGIOT, signal_handler);
signal (SIGBUS, signal_handler);
/* signal (SIGFPE, signal_handler); */
signal (SIGSEGV, signal_handler);
signal (SIGTERM, signal_handler);
}
#endif
/*
===============
GL_Init
===============
*/
void
GL_Init (void)
{
GL_Init_Common ();
}
void
GL_EndRendering (void)
{
glFlush ();
glXSwapBuffers (x_disp, x_win);
Sbar_Changed ();
}
void
VID_Init (unsigned char *palette)
{
int i;
int attrib[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, 1,
None
};
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
/* Interpret command-line params */
/* Set vid parameters */
if ((i = COM_CheckParm ("-conwidth")))
vid.conwidth = atoi (com_argv[i + 1]);
else
vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight
vid.conwidth = max (vid.conwidth, 320);
// pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4;
if ((i = COM_CheckParm ("-conheight"))) // conheight no smaller than
// 200px
vid.conheight = atoi (com_argv[i + 1]);
vid.conheight = max (vid.conheight, 200);
x11_open_display ();
x_visinfo = glXChooseVisual (x_disp, x_screen, attrib);
if (!x_visinfo) {
fprintf (stderr,
"Error couldn't get an RGB, Double-buffered, Depth visual\n");
exit (1);
}
x_vis = x_visinfo->visual;
x11_set_vidmode (scr_width, scr_height);
x11_create_window (scr_width, scr_height);
/* Invisible cursor */
x11_create_null_cursor ();
x11_grab_keyboard ();
XSync (x_disp, 0);
ctx = glXCreateContext (x_disp, x_visinfo, NULL, True);
glXMakeCurrent (x_disp, x_win, ctx);
vid.height = vid.conheight = min (vid.conheight, scr_height);
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
// InitSig (); // trap evil signals
GL_Init ();
// XXX not yet GL_CheckBrightness (palette);
VID_SetPalette (palette);
// Check for 8-bit extension and initialize if present
VID_Init8bitPalette ();
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
vid_initialized = true;
vid.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars ()
{
x11_Init_Cvars ();
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
}
}
void
VID_HandlePause (qboolean paused)
{
}

File diff suppressed because it is too large Load diff

View file

@ -1,117 +0,0 @@
/*
vid_null.c
null video driver to aid porting efforts
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "quakedef.h"
#include "d_local.h"
viddef_t vid; // global video state
#define BASEWIDTH 320
#define BASEHEIGHT 200
byte vid_buffer[BASEWIDTH * BASEHEIGHT];
short zbuffer[BASEWIDTH * BASEHEIGHT];
byte surfcache[256 * 1024];
unsigned short d_8to16table[256];
unsigned int d_8to24table[256];
void
VID_SetPalette (unsigned char *palette)
{
}
void
VID_ShiftPalette (unsigned char *palette)
{
}
void
VID_Init (unsigned char *palette)
{
vid.maxwarpwidth = vid.width = vid.conwidth = BASEWIDTH;
vid.maxwarpheight = vid.height = vid.conheight = BASEHEIGHT;
vid.aspect = 1.0;
vid.numpages = 1;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
vid.buffer = vid.conbuffer = vid_buffer;
vid.rowbytes = vid.conrowbytes = BASEWIDTH;
d_pzbuffer = zbuffer;
D_InitCaches (surfcache, sizeof (surfcache));
}
void
VID_Init_Cvars ()
{
}
void
VID_Shutdown (void)
{
}
void
VID_Update (vrect_t *rects)
{
}
/*
================
D_BeginDirectRect
================
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
}
/*
================
D_EndDirectRect
================
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
}
void
VID_SetCaption (char *text)
{
}
void
VID_HandlePause (qboolean paused)
{
}

View file

@ -1,291 +0,0 @@
/*
vid_sdl.c
Video driver for Sam Lantinga's Simple DirectMedia Layer
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
$Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <SDL.h>
#include "QF/cvar.h"
#include "d_local.h"
#include "host.h"
#include "QF/qendian.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "vid.h"
// static float oldin_grab = 0;
cvar_t *vid_fullscreen;
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
#ifdef WIN32
// FIXME: this is evil...
#include <windows.h>
HWND mainwindow;
#endif
int modestate; // FIXME: just to avoid cross-comp.
// errors - remove later
// The original defaults
#define BASEWIDTH 320
#define BASEHEIGHT 200
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0;
byte *VGA_pagebase;
static SDL_Surface *screen = NULL;
void
VID_InitBuffers (int width, int height)
{
int tbuffersize, tcachesize;
void *vid_surfcache;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes (width, height);
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, tcachesize);
}
void
VID_SetPalette (unsigned char *palette)
{
int i;
SDL_Color colors[256];
for (i = 0; i < 256; ++i) {
colors[i].r = *palette++;
colors[i].g = *palette++;
colors[i].b = *palette++;
}
SDL_SetColors (screen, colors, 0, 256);
}
void
VID_ShiftPalette (unsigned char *palette)
{
VID_SetPalette (palette);
}
void
VID_Init (unsigned char *palette)
{
// Uint8 video_bpp;
// Uint16 video_w, video_h;
Uint32 flags;
// Load the SDL library
if (SDL_Init (SDL_INIT_VIDEO) < 0) // |SDL_INIT_AUDIO|SDL_INIT_CDROM) <
// 0)
Sys_Error ("VID: Couldn't load SDL: %s", SDL_GetError ());
// Set up display mode (width and height)
VID_GetWindowSize (BASEWIDTH, BASEHEIGHT);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
// Set video width, height and flags
flags = (SDL_SWSURFACE | SDL_HWPALETTE);
if (vid_fullscreen->int_val)
flags |= SDL_FULLSCREEN;
// Initialize display
if (!(screen = SDL_SetVideoMode (vid.width, vid.height, 8, flags)))
Sys_Error ("VID: Couldn't set video mode: %s\n", SDL_GetError ());
VID_SetPalette (palette);
VID_SetCaption ("");
// now know everything we need to know about the buffer
VGA_width = vid.conwidth = vid.width;
VGA_height = vid.conheight = vid.height;
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 1;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
VGA_pagebase = vid.buffer = screen->pixels;
VGA_rowbytes = vid.rowbytes = screen->pitch;
vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes;
vid.direct = 0;
// allocate z buffer and surface cache
VID_InitBuffers (vid.width, vid.height);
// initialize the mouse
SDL_ShowCursor (0);
#ifdef WIN32
// FIXME: EVIL thing - but needed for win32 until we get
// SDL_sound ready - without this DirectSound fails.
// could replace this with SDL_SysWMInfo
mainwindow = GetActiveWindow ();
#endif
}
void
VID_Init_Cvars ()
{
vid_fullscreen =
Cvar_Get ("vid_fullscreen", "0", CVAR_ROM, NULL,
"Toggles fullscreen game mode");
}
void
VID_Shutdown (void)
{
SDL_Quit ();
}
void
VID_Update (vrect_t *rects)
{
SDL_Rect *sdlrects;
int n, i;
vrect_t *rect;
// Two-pass system, since Quake doesn't do it the SDL way...
// First, count the number of rectangles
n = 0;
for (rect = rects; rect; rect = rect->pnext)
++n;
// Second, copy them to SDL rectangles and update
if (!(sdlrects = (SDL_Rect *) calloc (1, n * sizeof (SDL_Rect))))
Sys_Error ("Out of memory!");
i = 0;
for (rect = rects; rect; rect = rect->pnext) {
sdlrects[i].x = rect->x;
sdlrects[i].y = rect->y;
sdlrects[i].w = rect->width;
sdlrects[i].h = rect->height;
++i;
}
SDL_UpdateRects (screen, n, sdlrects);
}
/*
================
D_BeginDirectRect
================
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
Uint8 *offset;
if (!screen)
return;
if (x < 0)
x = screen->w + x - 1;
offset = (Uint8 *) screen->pixels + y * screen->pitch + x;
while (height--) {
memcpy (offset, pbitmap, width);
offset += screen->pitch;
pbitmap += width;
}
}
/*
================
D_EndDirectRect
================
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
if (!screen)
return;
if (x < 0)
x = screen->w + x - 1;
SDL_UpdateRect (screen, x, y, width, height);
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
SDL_WM_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
free (temp);
} else {
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
}
}
void
VID_HandlePause (qboolean paused)
{
}

View file

@ -1,243 +0,0 @@
/*
vid_sgl.c
Video driver for OpenGL-using versions of SDL
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
$Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifndef WIN32
#include <sys/signal.h>
#endif
#include <SDL.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "host.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "sbar.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "glquake.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
static qboolean vid_initialized = false;
cvar_t *vid_fullscreen;
#ifdef WIN32
/* FIXME: this is evil hack */
#include <windows.h>
HWND mainwindow;
#endif
int VID_options_items = 1;
int modestate;
extern void GL_Init_Common (void);
extern void VID_Init8bitPalette (void);
/*-----------------------------------------------------------------------*/
void
VID_Shutdown (void)
{
if (!vid_initialized)
return;
Con_Printf ("VID_Shutdown\n");
SDL_Quit ();
}
#ifndef WIN32
static void
signal_handler (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Sys_Quit ();
exit (sig);
}
static void
InitSig (void)
{
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
signal (SIGIOT, signal_handler);
signal (SIGBUS, signal_handler);
// signal(SIGFPE, signal_handler);
signal (SIGSEGV, signal_handler);
signal (SIGTERM, signal_handler);
}
#endif
void
GL_Init (void)
{
GL_Init_Common ();
}
void
GL_EndRendering (void)
{
glFlush ();
SDL_GL_SwapBuffers ();
Sbar_Changed ();
}
void
VID_Init (unsigned char *palette)
{
Uint32 flags = SDL_OPENGL;
int i;
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
// Interpret command-line params
// Set vid parameters
if ((i = COM_CheckParm ("-conwidth")) != 0)
vid.conwidth = atoi (com_argv[i + 1]);
else
vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight
if (vid.conwidth < 320)
vid.conwidth = 320;
// pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4;
i = COM_CheckParm ("-conheight");
if (i != 0) // Set console height, but no smaller
//
//
// than 200 px
vid.conheight = max (atoi (com_argv[i + 1]), 200);
// Initialize the SDL library
if (SDL_Init (SDL_INIT_VIDEO) < 0)
Sys_Error ("Couldn't initialize SDL: %s\n", SDL_GetError ());
// Check if we want fullscreen
if (vid_fullscreen->value) {
flags |= SDL_FULLSCREEN;
// Don't annoy Mesa/3dfx folks
#ifndef WIN32
// FIXME: Maybe this could be put in a different spot, but I don't
// know where.
// Anyway, it's to work around a 3Dfx Glide bug.
SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_ON);
setenv ("MESA_GLX_FX", "fullscreen", 1);
} else {
setenv ("MESA_GLX_FX", "window", 1);
#endif
}
// Setup GL Attributes
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
if (SDL_SetVideoMode (scr_width, scr_height, 8, flags) == NULL) {
Sys_Error ("Couldn't set video mode: %s\n", SDL_GetError ());
SDL_Quit ();
}
vid.height = vid.conheight = min (vid.conheight, scr_height);
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
#ifndef WIN32
InitSig (); // trap evil signals
#endif
GL_Init ();
// XXX not yet GL_CheckBrightness (palette);
VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them.
VID_Init8bitPalette ();
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
vid_initialized = true;
#ifdef WIN32
// FIXME: EVIL thing - but needed for win32 until we get
// SDL_sound ready - without this DirectSound fails.
// could replace this with SDL_SysWMInfo
mainwindow = GetActiveWindow ();
#endif
vid.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars ()
{
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_NONE, NULL, "None");
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
SDL_WM_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
free (temp);
} else {
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
}
}
void
VID_HandlePause (qboolean paused)
{
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,756 +0,0 @@
/*
vid_svgalib.c
Linux SVGALib video routines
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999-2000 David Symonds [xoxus@usa.net]
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#if defined(HAVE_SYS_IO_H)
# include <sys/io.h>
#elif defined(HAVE_ASM_IO_H)
# include <asm/io.h>
#endif
#include <vga.h>
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "d_local.h"
#include "host.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/sys.h"
void VGA_UpdatePlanarScreen (void *srcbuffer);
unsigned short d_8to16table[256];
static int num_modes, current_mode;
static vga_modeinfo *modes;
static byte vid_current_palette[768];
static int svgalib_inited = 0;
static int UseDisplay = 1;
static cvar_t *vid_mode;
static cvar_t *vid_redrawfull;
static cvar_t *vid_waitforrefresh;
static char *framebuffer_ptr;
static byte backingbuf[48 * 24];
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar;
byte *VGA_pagebase;
int VID_options_items = 0;
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
int i, j, k, plane, reps, repshift, offset, vidpage, off;
if (!svgalib_inited || !vid.direct || !vga_oktowrite ())
return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
vidpage = 0;
vga_setpage (0);
if (VGA_planar) {
for (plane = 0; plane < 4; plane++) {
/* Select the correct plane for reading and writing */
outb (0x02, 0x3C4);
outb (1 << plane, 0x3C5);
outb (4, 0x3CE);
outb (plane, 0x3CF);
for (i = 0; i < (height << repshift); i += reps) {
for (k = 0; k < reps; k++) {
for (j = 0; j < (width >> 2); j++) {
backingbuf[(i + k) * 24 + (j << 2) + plane] =
vid.direct[(y + i + k) * VGA_rowbytes +
(x >> 2) + j];
vid.direct[(y + i + k) * VGA_rowbytes + (x >> 2) + j] =
pbitmap[(i >> repshift) * 24 + (j << 2) + plane];
}
}
}
}
} else {
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
if ((offset / 0x10000) != vidpage) {
vidpage = offset / 0x10000;
vga_setpage (vidpage);
}
memcpy (&backingbuf[(i + j) * 24], vid.direct + off, width);
memcpy (vid.direct + off,
&pbitmap[(i >> repshift) * width], width);
}
}
}
}
void
D_EndDirectRect (int x, int y, int width, int height)
{
int i, j, k, plane, reps, repshift, offset, vidpage, off;
if (!svgalib_inited || !vid.direct || !vga_oktowrite ())
return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
vidpage = 0;
vga_setpage (0);
if (VGA_planar) {
for (plane = 0; plane < 4; plane++) {
/* Select the correct plane for writing */
outb (2, 0x3C4);
outb (1 << plane, 0x3C5);
outb (4, 0x3CE);
outb (plane, 0x3CF);
for (i = 0; i < (height << repshift); i += reps) {
for (k = 0; k < reps; k++) {
for (j = 0; j < (width >> 2); j++) {
vid.direct[(y + i + k) * VGA_rowbytes + (x >> 2) + j] =
backingbuf[(i + k) * 24 + (j << 2) + plane];
}
}
}
}
} else {
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
if ((offset / 0x10000) != vidpage) {
vidpage = offset / 0x10000;
vga_setpage (vidpage);
}
memcpy (vid.direct + off, &backingbuf[(i + j) * 24], width);
}
}
}
}
#if 0
static void
VID_Gamma_f (void)
{
float gamma, f, inf;
unsigned char palette[768];
int i;
if (Cmd_Argc () == 2) {
gamma = atof (Cmd_Argv (1));
for (i = 0; i < 768; i++) {
f = pow ((host_basepal[i] + 1) / 256.0, gamma);
inf = f * 255 + 0.5;
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
palette[i] = inf;
}
VID_SetPalette (palette);
/* Force a surface cache flush */
vid.recalc_refdef = 1;
}
}
#endif
static void
VID_DescribeMode_f (void)
{
int modenum;
modenum = atoi (Cmd_Argv (1));
if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width) {
Con_Printf ("Invalid video mode: %d!\n", modenum);
}
Con_Printf ("%d: %d x %d - ", modenum,
modes[modenum].width, modes[modenum].height);
if (modes[modenum].bytesperpixel == 0) {
Con_Printf ("ModeX\n");
} else {
Con_Printf ("%d bpp\n", modes[modenum].bytesperpixel << 3);
}
}
static void
VID_DescribeModes_f (void)
{
int i;
for (i = 0; i < num_modes; i++) {
if (modes[i].width) {
Con_Printf ("%d: %d x %d - ", i, modes[i].width, modes[i].height);
if (modes[i].bytesperpixel == 0)
Con_Printf ("ModeX\n");
else
Con_Printf ("%d bpp\n", modes[i].bytesperpixel << 3);
}
}
}
/*
================
VID_NumModes
================
*/
static int
VID_NumModes (void)
{
int i, i1 = 0;
for (i = 0; i < num_modes; i++) {
i1 += modes[i].width ? 1 : 0;
}
return (i1);
}
static void
VID_NumModes_f (void)
{
Con_Printf ("%d modes\n", VID_NumModes ());
}
static void
VID_Debug_f (void)
{
Con_Printf ("mode: %d\n", current_mode);
Con_Printf ("height x width: %d x %d\n", vid.height, vid.width);
Con_Printf ("bpp: %d\n", modes[current_mode].bytesperpixel * 8);
Con_Printf ("vid.aspect: %f\n", vid.aspect);
}
static void
VID_InitModes (void)
{
int i;
/* Get complete information on all modes */
num_modes = vga_lastmodenumber () + 1;
modes = malloc (num_modes * sizeof (vga_modeinfo));
for (i = 0; i < num_modes; i++) {
if (vga_hasmode (i)) {
memcpy (&modes[i], vga_getmodeinfo (i), sizeof (vga_modeinfo));
} else {
modes[i].width = 0; // means not available
}
}
/* Filter for modes we don't support */
for (i = 0; i < num_modes; i++) {
if (modes[i].bytesperpixel != 1 && modes[i].colors != 256) {
modes[i].width = 0;
}
}
}
static int
get_mode (char *name, int width, int height, int depth)
{
int i, ok, match;
match = (!!width) + (!!height) * 2 + (!!depth) * 4;
if (name) {
i = vga_getmodenumber (name);
if (!modes[i].width) {
Sys_Printf ("Mode [%s] not supported\n", name);
i = G320x200x256;
}
} else {
for (i = 0; i < num_modes; i++) {
if (modes[i].width) {
ok = (modes[i].width == width)
+ (modes[i].height == height) * 2
+ (modes[i].bytesperpixel == depth / 8) * 4;
if ((ok & match) == ok)
break;
}
}
if (i == num_modes) {
Sys_Printf ("Mode %dx%d (%d bits) not supported\n",
width, height, depth);
i = G320x200x256;
}
}
return i;
}
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize;
void *vid_surfcache;
// Calculate the sizes we want first
buffersize = vid.rowbytes * vid.height;
zbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
cachesize = D_SurfaceCacheForRes (vid.width, vid.height);
// Free the old screen buffer
if (vid.buffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
}
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new screen buffer
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
if (!vid.conbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new z-buffer
d_pzbuffer = calloc (zbuffersize, 1);
if (!d_pzbuffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (cachesize, 1);
if (!vid_surfcache) {
free (vid.buffer);
free (d_pzbuffer);
vid.conbuffer = vid.buffer = NULL;
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, cachesize);
}
void
VID_Shutdown (void)
{
Sys_Printf ("VID_Shutdown\n");
if (!svgalib_inited)
return;
if (UseDisplay) {
vga_setmode (TEXT);
}
svgalib_inited = 0;
}
void
VID_ShiftPalette (unsigned char *p)
{
VID_SetPalette (p);
}
void
VID_SetPalette (byte * palette)
{
static int tmppal[256 * 3];
int *tp;
int i;
if (!svgalib_inited)
return;
memcpy (vid_current_palette, palette, sizeof (vid_current_palette));
if (vga_getcolors () == 256) {
tp = tmppal;
for (i = 256 * 3; i; i--) {
*(tp++) = *(palette++) >> 2;
}
if (UseDisplay && vga_oktowrite ()) {
vga_setpalvec (0, 256, tmppal);
}
}
}
int
VID_SetMode (int modenum, unsigned char *palette)
{
int err;
if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width) {
Cvar_SetValue (vid_mode, current_mode);
Con_Printf ("No such video mode: %d\n", modenum);
return 0;
}
Cvar_SetValue (vid_mode, modenum);
current_mode = modenum;
vid.width = modes[current_mode].width;
vid.height = modes[current_mode].height;
VGA_width = modes[current_mode].width;
VGA_height = modes[current_mode].height;
VGA_planar = modes[current_mode].bytesperpixel == 0;
VGA_rowbytes = modes[current_mode].linewidth;
vid.rowbytes = modes[current_mode].linewidth;
if (VGA_planar) {
VGA_bufferrowbytes = modes[current_mode].linewidth * 4;
vid.rowbytes = modes[current_mode].linewidth * 4;
}
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.colormap = (pixel_t *) host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.numpages = 1;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
// alloc screen buffer, z-buffer, and surface cache
VID_InitBuffers ();
/* get goin' */
err = vga_setmode (current_mode);
if (err) {
Sys_Error ("Video mode failed: %d\n", modenum);
}
VID_SetPalette (palette);
VGA_pagebase = vid.direct = framebuffer_ptr = (char *) vga_getgraphmem ();
#if 0
if (vga_setlinearaddressing () > 0) {
framebuffer_ptr = (char *) vga_getgraphmem ();
}
#endif
if (!framebuffer_ptr) {
Sys_Error ("This mode isn't hapnin'\n");
}
vga_setpage (0);
svgalib_inited = 1;
/* Force a surface cache flush */
vid.recalc_refdef = 1;
return 1;
}
void
VID_Init (unsigned char *palette)
{
int w, h, d;
int err;
// plugin_load("in_svgalib.so");
if (svgalib_inited)
return;
#if 0
Cmd_AddCommand ("gamma", VID_Gamma_f, "No Description");
#endif
if (UseDisplay) {
err = vga_init ();
if (err)
Sys_Error ("SVGALib failed to allocate a new VC\n");
VID_InitModes ();
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, "No Description");
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f,
"No Description");
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f,
"No Description");
Cmd_AddCommand ("vid_debug", VID_Debug_f, "No Description");
/* Interpret command-line params */
w = h = d = 0;
if (getenv ("GSVGAMODE")) {
current_mode = get_mode (getenv ("GSVGAMODE"), w, h, d);
} else if (COM_CheckParm ("-mode")) {
current_mode =
get_mode (com_argv[COM_CheckParm ("-mode") + 1], w, h, d);
} else if (COM_CheckParm ("-w") || COM_CheckParm ("-h")
|| COM_CheckParm ("-d")) {
if (COM_CheckParm ("-w")) {
w = atoi (com_argv[COM_CheckParm ("-w") + 1]);
}
if (COM_CheckParm ("-h")) {
h = atoi (com_argv[COM_CheckParm ("-h") + 1]);
}
if (COM_CheckParm ("-d")) {
d = atoi (com_argv[COM_CheckParm ("-d") + 1]);
}
current_mode = get_mode (0, w, h, d);
} else {
current_mode = G320x200x256;
}
/* Set vid parameters */
VID_SetMode (current_mode, palette);
VID_SetPalette (palette);
/* XoXus: Running in background is just plain bad... */
vga_runinbackground (0);
}
/* XoXus: Why was input initialised here?!? */
/* IN_Init(); */
}
void
VID_Init_Cvars ()
{
vid_mode = Cvar_Get ("vid_mode", "5", CVAR_NONE, NULL, "None");
vid_redrawfull = Cvar_Get ("vid_redrawfull", "0", CVAR_NONE, NULL, "None");
vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh", "0", CVAR_ARCHIVE,
NULL, "None");
}
void
VID_Update (vrect_t *rects)
{
if (!svgalib_inited)
return;
if (!vga_oktowrite ()) {
/* Can't update screen if it's not active */
return;
}
if (vid_waitforrefresh->int_val) {
vga_waitretrace ();
}
if (VGA_planar) {
VGA_UpdatePlanarScreen (vid.buffer);
} else if (vid_redrawfull->int_val) {
int total = vid.rowbytes * vid.height;
int offset;
for (offset = 0; offset < total; offset += 0x10000) {
vga_setpage (offset / 0x10000);
memcpy (framebuffer_ptr, vid.buffer + offset,
((total - offset > 0x10000) ? 0x10000 : (total - offset)));
}
} else {
int ycount;
int offset;
int vidpage = 0;
vga_setpage (0);
while (rects) {
ycount = rects->height;
offset = rects->y * vid.rowbytes + rects->x;
while (ycount--) {
register int i = offset % 0x10000;
if ((offset / 0x10000) != vidpage) {
vidpage = offset / 0x10000;
vga_setpage (vidpage);
}
if (rects->width + i > 0x10000) {
memcpy (framebuffer_ptr + i,
vid.buffer + offset, 0x10000 - i);
vga_setpage (++vidpage);
memcpy (framebuffer_ptr,
vid.buffer + offset + 0x10000 - i,
rects->width - 0x10000 + i);
} else {
memcpy (framebuffer_ptr + i,
vid.buffer + offset, rects->width);
}
offset += vid.rowbytes;
}
rects = rects->pnext;
}
}
if (vid_mode->int_val != current_mode) {
VID_SetMode (vid_mode->int_val, vid_current_palette);
}
}
static int dither = 0;
void
VID_DitherOn (void)
{
if (dither == 0) {
#if 0
R_ViewChanged (&vrect, sb_lines, vid.aspect);
#endif
dither = 1;
}
}
void
VID_DitherOff (void)
{
if (dither) {
#if 0
R_ViewChanged (&vrect, sb_lines, vid.aspect);
#endif
dither = 0;
}
}
/*
================
VID_ModeInfo
================
*/
char *
VID_ModeInfo (int modenum)
{
static char *badmodestr = "Bad mode number";
static char modestr[40];
if (modenum == 0) {
snprintf (modestr, sizeof (modestr), "%d x %d, %d bpp",
vid.width, vid.height, modes[current_mode].bytesperpixel * 8);
return (modestr);
} else {
return (badmodestr);
}
}
void
VID_ExtraOptionDraw (unsigned int options_draw_cursor)
{
/* No extra option menu items yet */
}
void
VID_ExtraOptionCmd (int option_cursor)
{
#if 0
switch (option_cursor) {
case 1: // Always start with 1
break;
}
#endif
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
}
void
VID_HandlePause (qboolean paused)
{
}

View file

@ -1,455 +0,0 @@
/*
vid_vga.c
@description@
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <dos.h>
#include "d_local.h"
#include "dosisms.h"
#include "vid_dos.h"
#include <dpmi.h>
extern regs_t regs;
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes;
byte *VGA_pagebase;
vmode_t *VGA_pcurmode;
static int VGA_planar;
static int VGA_numpages;
static int VGA_buffersize;
void *vid_surfcache;
int vid_surfcachesize;
int VGA_highhunkmark;
#include "vgamodes.h"
#define NUMVIDMODES (sizeof(vgavidmodes) / sizeof(vgavidmodes[0]))
void VGA_UpdatePlanarScreen (void *srcbuffer);
static byte backingbuf[48 * 24];
/*
================
VGA_BeginDirectRect
================
*/
void
VGA_BeginDirectRect (viddef_t *lvid, struct vmode_s *pcurrentmode, int x,
int y, byte * pbitmap, int width, int height)
{
int i, j, k, plane, reps, repshift;
if (!lvid->direct)
return;
if (lvid->aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
if (pcurrentmode->planar) {
for (plane = 0; plane < 4; plane++) {
// select the correct plane for reading and writing
outportb (SC_INDEX, MAP_MASK);
outportb (SC_DATA, 1 << plane);
outportb (GC_INDEX, READ_MAP);
outportb (GC_DATA, plane);
for (i = 0; i < (height << repshift); i += reps) {
for (k = 0; k < reps; k++) {
for (j = 0; j < (width >> 2); j++) {
backingbuf[(i + k) * 24 + (j << 2) + plane] =
lvid->direct[(y + i + k) * VGA_rowbytes +
(x >> 2) + j];
lvid->direct[(y + i + k) * VGA_rowbytes + (x >> 2) +
j] =
pbitmap[(i >> repshift) * 24 + (j << 2) + plane];
}
}
}
}
} else {
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
memcpy (&backingbuf[(i + j) * 24],
lvid->direct + x + ((y << repshift) + i + j) *
VGA_rowbytes, width);
memcpy (lvid->direct + x + ((y << repshift) + i + j) *
VGA_rowbytes, &pbitmap[(i >> repshift) * width], width);
}
}
}
}
/*
================
VGA_EndDirectRect
================
*/
void
VGA_EndDirectRect (viddef_t *lvid, struct vmode_s *pcurrentmode, int x,
int y, int width, int height)
{
int i, j, k, plane, reps, repshift;
if (!lvid->direct)
return;
if (lvid->aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
if (pcurrentmode->planar) {
for (plane = 0; plane < 4; plane++) {
// select the correct plane for writing
outportb (SC_INDEX, MAP_MASK);
outportb (SC_DATA, 1 << plane);
for (i = 0; i < (height << repshift); i += reps) {
for (k = 0; k < reps; k++) {
for (j = 0; j < (width >> 2); j++) {
lvid->direct[(y + i + k) * VGA_rowbytes + (x >> 2) +
j] =
backingbuf[(i + k) * 24 + (j << 2) + plane];
}
}
}
}
} else {
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
memcpy (lvid->direct + x + ((y << repshift) + i + j) *
VGA_rowbytes, &backingbuf[(i + j) * 24], width);
}
}
}
}
/*
================
VGA_Init
================
*/
void
VGA_Init (void)
{
int i;
// link together all the VGA modes
for (i = 0; i < (NUMVIDMODES - 1); i++) {
vgavidmodes[i].pnext = &vgavidmodes[i + 1];
}
// add the VGA modes at the start of the mode list
vgavidmodes[NUMVIDMODES - 1].pnext = pvidmodes;
pvidmodes = &vgavidmodes[0];
numvidmodes += NUMVIDMODES;
}
/*
================
VGA_WaitVsync
================
*/
void
VGA_WaitVsync (void)
{
while ((inportb (0x3DA) & 0x08) == 0);
}
/*
================
VGA_ClearVideoMem
================
*/
void
VGA_ClearVideoMem (int planar)
{
if (planar) {
// enable all planes for writing
outportb (SC_INDEX, MAP_MASK);
outportb (SC_DATA, 0x0F);
}
Q_memset (VGA_pagebase, 0, VGA_rowbytes * VGA_height);
}
/*
================
VGA_FreeAndAllocVidbuffer
================
*/
qboolean
VGA_FreeAndAllocVidbuffer (viddef_t *lvid, int allocnewbuffer)
{
int tsize, tbuffersize;
if (allocnewbuffer) {
// alloc an extra line in case we want to wrap, and allocate the
// z-buffer
tbuffersize = (lvid->rowbytes * (lvid->height + 1)) +
(lvid->width * lvid->height * sizeof (*d_pzbuffer));
} else {
// just allocate the z-buffer
tbuffersize = lvid->width * lvid->height * sizeof (*d_pzbuffer);
}
tsize = D_SurfaceCacheForRes (lvid->width, lvid->height);
tbuffersize += tsize;
// see if there's enough memory, allowing for the normal mode 0x13 pixel,
// z, and surface buffers
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
0x10000 * 3) < minimum_memory) {
Con_Printf ("Not enough memory for video mode\n");
VGA_pcurmode = NULL; // so no further accesses to the
// buffer are
// attempted, particularly when clearing
return false; // not enough memory for mode
}
VGA_buffersize = tbuffersize;
vid_surfcachesize = tsize;
if (d_pzbuffer) {
D_FlushCaches ();
Hunk_FreeToHighMark (VGA_highhunkmark);
d_pzbuffer = NULL;
}
VGA_highhunkmark = Hunk_HighMark ();
d_pzbuffer = Hunk_HighAllocName (VGA_buffersize, "video");
vid_surfcache = (byte *) d_pzbuffer
+ lvid->width * lvid->height * sizeof (*d_pzbuffer);
if (allocnewbuffer) {
lvid->buffer = (void *) ((byte *) vid_surfcache + vid_surfcachesize);
lvid->conbuffer = lvid->buffer;
}
return true;
}
/*
================
VGA_CheckAdequateMem
================
*/
qboolean
VGA_CheckAdequateMem (int width, int height, int rowbytes, int allocnewbuffer)
{
int tbuffersize;
tbuffersize = width * height * sizeof (*d_pzbuffer);
if (allocnewbuffer) {
// alloc an extra line in case we want to wrap, and allocate the
// z-buffer
tbuffersize += (rowbytes * (height + 1));
}
tbuffersize += D_SurfaceCacheForRes (width, height);
// see if there's enough memory, allowing for the normal mode 0x13 pixel,
// z, and surface buffers
if ((host_parms.memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 +
0x10000 * 3) < minimum_memory) {
return false; // not enough memory for mode
}
return true;
}
/*
================
VGA_InitMode
================
*/
int
VGA_InitMode (viddef_t *lvid, vmode_t * pcurrentmode)
{
vextra_t *pextra;
pextra = pcurrentmode->pextradata;
if (!VGA_FreeAndAllocVidbuffer (lvid, pextra->vidbuffer))
return -1; // memory alloc failed
if (VGA_pcurmode)
VGA_ClearVideoMem (VGA_pcurmode->planar);
// mode 0x13 is the base for all the Mode X-class mode sets
regs.h.ah = 0;
regs.h.al = 0x13;
dos_int86 (0x10);
VGA_pagebase = (void *) real2ptr (0xa0000);
lvid->direct = (pixel_t *) VGA_pagebase;
// set additional registers as needed
VideoRegisterSet (pextra->pregset);
VGA_numpages = 1;
lvid->numpages = VGA_numpages;
VGA_width = (lvid->width + 0x1F) & ~0x1F;
VGA_height = lvid->height;
VGA_planar = pcurrentmode->planar;
if (VGA_planar)
VGA_rowbytes = lvid->rowbytes / 4;
else
VGA_rowbytes = lvid->rowbytes;
VGA_bufferrowbytes = lvid->rowbytes;
lvid->colormap = host_colormap;
lvid->fullbright = 256 - LittleLong (*((int *) lvid->colormap + 2048));
lvid->maxwarpwidth = WARP_WIDTH;
lvid->maxwarpheight = WARP_HEIGHT;
lvid->conbuffer = lvid->buffer;
lvid->conrowbytes = lvid->rowbytes;
lvid->conwidth = lvid->width;
lvid->conheight = lvid->height;
VGA_pcurmode = pcurrentmode;
VGA_ClearVideoMem (pcurrentmode->planar);
if (_vid_wait_override->int_val) {
Cvar_SetValue (vid_wait, (float) VID_WAIT_VSYNC);
} else {
Cvar_SetValue (vid_wait, (float) VID_WAIT_NONE);
}
D_InitCaches (vid_surfcache, vid_surfcachesize);
return 1;
}
/*
================
VGA_SetPalette
================
*/
void
VGA_SetPalette (viddef_t *lvid, vmode_t * pcurrentmode, unsigned char *pal)
{
int shiftcomponents = 2;
int i;
UNUSED (lvid);
UNUSED (pcurrentmode);
dos_outportb (0x3c8, 0);
for (i = 0; i < 768; i++)
outportb (0x3c9, pal[i] >> shiftcomponents);
}
/*
================
VGA_SwapBuffersCopy
================
*/
void
VGA_SwapBuffersCopy (viddef_t *lvid, vmode_t * pcurrentmode, vrect_t *rects)
{
UNUSED (pcurrentmode);
// TODO: can write a dword at a time
// TODO: put in ASM
// TODO: copy only specified rectangles
if (VGA_planar) {
// TODO: copy only specified rectangles
VGA_UpdatePlanarScreen (lvid->buffer);
} else {
while (rects) {
VGA_UpdateLinearScreen (lvid->buffer + rects->x +
(rects->y * lvid->rowbytes),
VGA_pagebase + rects->x +
(rects->y * VGA_rowbytes), rects->width,
rects->height, lvid->rowbytes,
VGA_rowbytes);
rects = rects->pnext;
}
}
}
/*
================
VGA_SwapBuffers
================
*/
void
VGA_SwapBuffers (viddef_t *lvid, vmode_t * pcurrentmode, vrect_t *rects)
{
UNUSED (lvid);
if (vid_wait->int_val == VID_WAIT_VSYNC)
VGA_WaitVsync ();
VGA_SwapBuffersCopy (lvid, pcurrentmode, rects);
}
void
VID_HandlePause (qboolean pause)
{
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,814 +0,0 @@
/*
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
$Id$
*/
#define _BSD
#include <config.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include "QF/qendian.h"
#include "QF/qargs.h"
#include "d_local.h"
#include "QF/keys.h"
#include "QF/cvar.h"
#include "QF/sys.h"
#include "QF/cmd.h"
#include "QF/input.h"
#include "draw.h"
#include "QF/console.h"
#include "QF/va.h"
#include "client.h"
#include "context_x11.h"
#include "host.h"
#ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h>
#endif
#include "dga_check.h"
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
static Colormap x_cmap;
static GC x_gc;
int XShmQueryExtension (Display *);
int XShmGetEventBase (Display *);
qboolean doShm;
static XShmSegmentInfo x_shminfo[2];
static int current_framebuffer;
static XImage *x_framebuffer[2] = { 0, 0 };
static int verbose = 0;
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 unsigned long r_mask, g_mask, b_mask;
cvar_t *vid_width;
cvar_t *vid_height;
static void
shiftmask_init (void)
{
unsigned int x;
r_mask = x_vis->red_mask;
g_mask = x_vis->green_mask;
b_mask = x_vis->blue_mask;
for (r_shift = -8, x = 1; x < r_mask; x <<= 1)
r_shift++;
for (g_shift = -8, x = 1; x < g_mask; x <<= 1)
g_shift++;
for (b_shift = -8, x = 1; x < b_mask; x <<= 1)
b_shift++;
shiftmask_fl = 1;
}
static PIXEL16
xlib_rgb16 (int r, int g, int b)
{
PIXEL16 p = 0;
if (shiftmask_fl == 0)
shiftmask_init ();
if (r_shift > 0) {
p = (r << (r_shift)) & r_mask;
} else if (r_shift < 0) {
p = (r >> (-r_shift)) & r_mask;
} else
p |= (r & r_mask);
if (g_shift > 0) {
p |= (g << (g_shift)) & g_mask;
} else if (g_shift < 0) {
p |= (g >> (-g_shift)) & g_mask;
} else
p |= (g & g_mask);
if (b_shift > 0) {
p |= (b << (b_shift)) & b_mask;
} else if (b_shift < 0) {
p |= (b >> (-b_shift)) & b_mask;
} else
p |= (b & b_mask);
return p;
}
static PIXEL24
xlib_rgb24 (int r, int g, int b)
{
PIXEL24 p = 0;
if (shiftmask_fl == 0)
shiftmask_init ();
if (r_shift > 0) {
p = (r << (r_shift)) & r_mask;
} else if (r_shift < 0) {
p = (r >> (-r_shift)) & r_mask;
} else
p |= (r & r_mask);
if (g_shift > 0) {
p |= (g << (g_shift)) & g_mask;
} else if (g_shift < 0) {
p |= (g >> (-g_shift)) & g_mask;
} else
p |= (g & g_mask);
if (b_shift > 0) {
p |= (b << (b_shift)) & b_mask;
} else if (b_shift < 0) {
p |= (b >> (-b_shift)) & b_mask;
} else
p |= (b & b_mask);
return p;
}
static void
st2_fixup (XImage * framebuf, int x, int y, int width, int height)
{
int xi, yi;
unsigned char *src;
PIXEL16 *dest;
if (x < 0 || y < 0)
return;
for (yi = y; yi < (y + height); yi++) {
src = &framebuf->data[yi * framebuf->bytes_per_line];
dest = (PIXEL16 *) src;
for (xi = (x + width - 1); xi >= x; xi--) {
dest[xi] = st2d_8to16table[src[xi]];
}
}
}
static void
st3_fixup (XImage * framebuf, int x, int y, int width, int height)
{
int yi;
unsigned char *src;
PIXEL24 *dest;
register int count, n;
if (x < 0 || y < 0)
return;
for (yi = y; yi < (y + height); yi++) {
src = &framebuf->data[yi * framebuf->bytes_per_line];
// Duff's Device
count = width;
n = (count + 7) / 8;
dest = ((PIXEL24 *) src) + x + width - 1;
src += x + width - 1;
switch (count % 8) {
case 0:
do {
*dest-- = st2d_8to24table[*src--];
case 7:
*dest-- = st2d_8to24table[*src--];
case 6:
*dest-- = st2d_8to24table[*src--];
case 5:
*dest-- = st2d_8to24table[*src--];
case 4:
*dest-- = st2d_8to24table[*src--];
case 3:
*dest-- = st2d_8to24table[*src--];
case 2:
*dest-- = st2d_8to24table[*src--];
case 1:
*dest-- = st2d_8to24table[*src--];
} while (--n > 0);
}
// for(xi = (x+width-1); xi >= x; xi--) {
// dest[xi] = st2d_8to16table[src[xi]];
// }
}
}
/*
================
D_BeginDirectRect
================
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
// direct drawing of the "accessing disk" icon isn't supported
}
/*
================
D_EndDirectRect
================
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
// direct drawing of the "accessing disk" icon isn't supported
}
/*
=================
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;
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
vid_gamma[i] = inf;
}
VID_SetPalette (current_palette);
vid.recalc_refdef = 1; // force a surface cache flush
}
}
static void
ResetFrameBuffer (void)
{
int tbuffersize, tcachesize;
void *vid_surfcache;
int mem, pwidth;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
if (x_framebuffer[0]) {
XDestroyImage (x_framebuffer[0]);
}
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, tcachesize);
pwidth = x_visinfo->depth / 8;
if (pwidth == 3)
pwidth = 4;
mem = ((vid.width * pwidth + 7) & ~7) * vid.height;
x_framebuffer[0] = XCreateImage (x_disp, x_vis, x_visinfo->depth,
ZPixmap, 0,
malloc (mem),
vid.width, vid.height, 32, 0);
if (!x_framebuffer[0]) {
Sys_Error ("VID: XCreateImage failed\n");
}
}
static void
ResetSharedFrameBuffers (void)
{
int tbuffersize, tcachesize;
void *vid_surfcache;
int size;
int key;
int minsize = getpagesize ();
int frm;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, tcachesize);
for (frm = 0; frm < 2; frm++) {
// free up old frame buffer memory
if (x_framebuffer[frm]) {
XShmDetach (x_disp, &x_shminfo[frm]);
free (x_framebuffer[frm]);
shmdt (x_shminfo[frm].shmaddr);
}
// create the image
x_framebuffer[frm] = XShmCreateImage (x_disp,
x_vis,
x_visinfo->depth,
ZPixmap,
0,
&x_shminfo[frm],
vid.width, vid.height);
// grab shared memory
size = x_framebuffer[frm]->bytes_per_line * x_framebuffer[frm]->height;
if (size < minsize)
Sys_Error ("VID: Window must use at least %d bytes\n", minsize);
key = random ();
x_shminfo[frm].shmid = shmget ((key_t) key, size, IPC_CREAT | 0777);
if (x_shminfo[frm].shmid == -1)
Sys_Error ("VID: Could not get any shared memory\n");
// attach to the shared memory segment
x_shminfo[frm].shmaddr = (void *) shmat (x_shminfo[frm].shmid, 0, 0);
printf ("VID: shared memory id=%d, addr=0x%lx\n", x_shminfo[frm].shmid,
(long) x_shminfo[frm].shmaddr);
x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
// get the X server to attach to it
if (!XShmAttach (x_disp, &x_shminfo[frm]))
Sys_Error ("VID: XShmAttach() failed\n");
XSync (x_disp, 0);
shmctl (x_shminfo[frm].shmid, IPC_RMID, 0);
}
}
static void
event_shm (XEvent * event)
{
if (doShm)
oktodraw = true;
}
// Called at startup to set up translation tables, takes 256 8 bit RGB values
// the palette data will go away after the call, so it must be copied off if
// the video driver will need it again
void
VID_Init (unsigned char *palette)
{
int pnum, i;
XVisualInfo template;
int num_visuals;
int template_mask;
VID_GetWindowSize (320, 200);
// plugin_load("in_x11.so");
// Cmd_AddCommand("gamma", VID_Gamma_f, "No Description");
for (i = 0; i < 256; i++)
vid_gamma[i] = i;
vid.width = vid_width->int_val;
vid.height = vid_height->int_val;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.numpages = 2;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
srandom (getpid ());
verbose = COM_CheckParm ("-verbose");
// open the display
x11_open_display ();
// check for command-line window size
template_mask = 0;
// specify a visual id
if ((pnum = COM_CheckParm ("-visualid"))) {
if (pnum >= com_argc - 1)
Sys_Error ("VID: -visualid <id#>\n");
template.visualid = atoi (com_argv[pnum + 1]);
template_mask = VisualIDMask;
}
// If not specified, use default visual
else {
template.visualid =
XVisualIDFromVisual (XDefaultVisual (x_disp, x_screen));
template_mask = VisualIDMask;
}
// pick a visual- warn if more than one was available
x_visinfo = XGetVisualInfo (x_disp, template_mask, &template, &num_visuals);
x_vis = x_visinfo->visual;
if (num_visuals > 1) {
printf ("Found more than one visual id at depth %d:\n", template.depth);
for (i = 0; i < num_visuals; i++)
printf (" -visualid %d\n", (int) (x_visinfo[i].visualid));
} else if (num_visuals == 0) {
if (template_mask == VisualIDMask) {
Sys_Error ("VID: Bad visual id %ld\n", template.visualid);
} else {
Sys_Error ("VID: No visuals at depth %d\n", template.depth);
}
}
if (verbose) {
printf ("Using visualid %d:\n", (int) (x_visinfo->visualid));
printf (" class %d\n", x_visinfo->class);
printf (" screen %d\n", x_visinfo->screen);
printf (" depth %d\n", x_visinfo->depth);
printf (" red_mask 0x%x\n", (int) (x_visinfo->red_mask));
printf (" green_mask 0x%x\n", (int) (x_visinfo->green_mask));
printf (" blue_mask 0x%x\n", (int) (x_visinfo->blue_mask));
printf (" colormap_size %d\n", x_visinfo->colormap_size);
printf (" bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
}
/* Setup attributes for main window */
x11_set_vidmode (vid.width, vid.height);
/* Create the main window */
x11_create_window (vid.width, vid.height);
/* Invisible cursor */
x11_create_null_cursor ();
if (x_visinfo->depth == 8) {
/* Create and upload the palette */
if (x_visinfo->class == PseudoColor) {
x_cmap = XCreateColormap (x_disp, x_win, x_vis, AllocAll);
VID_SetPalette (palette);
XSetWindowColormap (x_disp, x_win, x_cmap);
}
}
// create the GC
{
XGCValues xgcvalues;
int valuemask = GCGraphicsExposures;
xgcvalues.graphics_exposures = False;
x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues);
}
x11_grab_keyboard ();
// wait for first exposure event
{
XEvent event;
do {
XNextEvent (x_disp, &event);
if (event.type == Expose && !event.xexpose.count)
oktodraw = true;
} while (!oktodraw);
}
// now safe to draw
// even if MITSHM is available, make sure it's a local connection
if (XShmQueryExtension (x_disp))
// if (0)
{
char *displayname;
doShm = true;
displayname = (char *) getenv ("DISPLAY");
if (displayname) {
char *d = displayname;
while (*d && (*d != ':'))
d++;
if (*d)
*d = 0;
if (!(!strcasecmp (displayname, "unix") || !*displayname))
doShm = false;
}
}
if (doShm) {
x_shmeventtype = XShmGetEventBase (x_disp) + ShmCompletion;
ResetSharedFrameBuffers ();
} else
ResetFrameBuffer ();
current_framebuffer = 0;
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
vid.buffer = x_framebuffer[0]->data;
vid.direct = 0;
vid.conbuffer = x_framebuffer[0]->data;
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
// XSynchronize(x_disp, False);
x11_add_event (x_shmeventtype, event_shm);
}
void
VID_Init_Cvars ()
{
x11_Init_Cvars ();
}
void
VID_ShiftPalette (unsigned char *p)
{
VID_SetPalette (p);
}
void
VID_SetPalette (unsigned char *palette)
{
int i;
XColor colors[256];
for (i = 0; i < 256; i++) {
st2d_8to16table[i] = xlib_rgb16 (palette[i * 3], palette[i * 3 + 1],
palette[i * 3 + 2]);
st2d_8to24table[i] = xlib_rgb24 (palette[i * 3], palette[i * 3 + 1],
palette[i * 3 + 2]);
}
if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) {
if (palette != current_palette) {
memcpy (current_palette, palette, 768);
}
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;
}
XStoreColors (x_disp, x_cmap, colors, 256);
}
}
/*
Called at shutdown
*/
void
VID_Shutdown (void)
{
Sys_Printf ("VID_Shutdown\n");
if (x_disp) {
x11_restore_vidmode ();
x11_close_display ();
}
}
static int config_notify = 0;
static int config_notify_width;
static int config_notify_height;
/*
Flushes the given rectangles from the view buffer to the screen.
*/
void
VID_Update (vrect_t *rects)
{
/* If the window changes dimension, skip this frame. */
if (config_notify) {
fprintf (stderr, "config notify\n");
config_notify = 0;
vid.width = config_notify_width & ~7;
vid.height = config_notify_height;
if (doShm)
ResetSharedFrameBuffers ();
else
ResetFrameBuffer ();
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
vid.buffer = x_framebuffer[current_framebuffer]->data;
vid.conbuffer = vid.buffer;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.conrowbytes = vid.rowbytes;
vid.recalc_refdef = 1; /* force a surface cache flush */
Con_CheckResize ();
Con_Clear_f ();
return;
}
if (doShm) {
while (rects) {
if (x_visinfo->depth == 16) {
st2_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->height);
} else if (x_visinfo->depth == 24) {
st3_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->height);
}
if (!XShmPutImage (x_disp, x_win, x_gc,
x_framebuffer[current_framebuffer],
rects->x, rects->y,
rects->x, rects->y,
rects->width, rects->height, True)) {
Sys_Error ("VID_Update: XShmPutImage failed\n");
}
oktodraw = false;
while (!oktodraw)
x11_process_event ();
rects = rects->pnext;
}
current_framebuffer = !current_framebuffer;
vid.buffer = x_framebuffer[current_framebuffer]->data;
vid.conbuffer = vid.buffer;
XSync (x_disp, False);
} else {
while (rects) {
if (x_visinfo->depth == 16) {
st2_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->height);
} else if (x_visinfo->depth == 24) {
st3_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->height);
}
XPutImage (x_disp, x_win, x_gc, x_framebuffer[0],
rects->x, rects->y, rects->x, rects->y,
rects->width, rects->height);
rects = rects->pnext;
}
XSync (x_disp, False);
}
}
static int dither;
void
VID_DitherOn (void)
{
if (dither == 0) {
vid.recalc_refdef = 1;
dither = 1;
}
}
void
VID_DitherOff (void)
{
if (dither) {
vid.recalc_refdef = 1;
dither = 0;
}
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
}
}
void
VID_HandlePause (qboolean paused)
{
}

View file

@ -1,482 +0,0 @@
/*
context_x11.c
general x11 context layer
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Zephaniah E. Hull <warp@whitestar.soark.net>
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/extensions/XShm.h>
#include <errno.h>
#include <limits.h>
#include <sys/poll.h>
#ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h>
#endif
#include "QF/console.h"
#include "context_x11.h"
#include "QF/cvar.h"
#include "dga_check.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/qtypes.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "vid.h"
static void (*event_handlers[LASTEvent]) (XEvent *);
qboolean oktodraw = false;
int x_shmeventtype;
static int x_disp_ref_count = 0;
Display *x_disp = NULL;
int x_screen;
Window x_root = None;
XVisualInfo *x_visinfo;
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 original_mode = 0;
#endif
static qboolean vidmode_avail = false;
static qboolean vidmode_active = false;
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;
qboolean
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])
return false;
event_handlers[event] = event_handler;
return true;
}
qboolean
X11_RemoveEvent (int event, void (*event_handler) (XEvent *))
{
if (event >= LASTEvent)
return false;
if (event_handlers[event] != event_handler)
return false;
event_handlers[event] = NULL;
return true;
}
void
X11_ProcessEvent (void)
{
XEvent x_event;
XNextEvent (x_disp, &x_event);
if (x_event.type >= LASTEvent) {
// FIXME: KLUGE!!!!!!
if (x_event.type == x_shmeventtype)
oktodraw = 1;
return;
}
if (event_handlers[x_event.type])
event_handlers[x_event.type] (&x_event);
}
void
X11_ProcessEvents (void)
{
/* Get events from X server. */
while (XPending (x_disp)) {
X11_ProcessEvent ();
}
}
// ========================================================================
// Tragic death handler
// ========================================================================
static void
TragicDeath (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Sys_Quit ();
exit (sig);
// XCloseDisplay(x_disp);
// VID_Shutdown();
// Sys_Error("This death brought to you by the number %d\n", signal_num);
}
void
X11_OpenDisplay (void)
{
if (!x_disp) {
x_disp = XOpenDisplay (NULL);
if (!x_disp) {
Sys_Error ("X11_OpenDisplay: Could not open display [%s]\n",
XDisplayName (NULL));
}
x_screen = DefaultScreen (x_disp);
x_root = RootWindow (x_disp, x_screen);
// catch signals
signal (SIGHUP, TragicDeath);
signal (SIGINT, TragicDeath);
signal (SIGQUIT, TragicDeath);
signal (SIGILL, TragicDeath);
signal (SIGTRAP, TragicDeath);
signal (SIGIOT, TragicDeath);
signal (SIGBUS, TragicDeath);
// signal(SIGFPE, TragicDeath);
signal (SIGSEGV, TragicDeath);
signal (SIGTERM, TragicDeath);
// for debugging only
XSynchronize (x_disp, True);
x_disp_ref_count = 1;
} else {
x_disp_ref_count++;
}
}
void
X11_CloseDisplay (void)
{
if (nullcursor != None) {
XFreeCursor (x_disp, nullcursor);
nullcursor = None;
}
if (!--x_disp_ref_count) {
XCloseDisplay (x_disp);
x_disp = 0;
}
}
/*
X11_CreateNullCursor
Create an empty cursor (in other words, make it disappear)
*/
void
X11_CreateNullCursor (void)
{
Pixmap cursormask;
XGCValues xgc;
GC gc;
XColor dummycolour;
if (nullcursor != None)
return;
cursormask = XCreatePixmap (x_disp, x_root, 1, 1, 1);
xgc.function = GXclear;
gc = XCreateGC (x_disp, cursormask, GCFunction, &xgc);
XFillRectangle (x_disp, cursormask, gc, 0, 0, 1, 1);
dummycolour.pixel = 0;
dummycolour.red = 0;
dummycolour.flags = 04;
nullcursor = XCreatePixmapCursor (x_disp, cursormask, cursormask,
&dummycolour, &dummycolour, 0, 0);
XFreePixmap (x_disp, cursormask);
XFreeGC (x_disp, gc);
XDefineCursor (x_disp, x_win, nullcursor);
}
void
X11_SetVidMode (int width, int height)
{
const char *str = getenv ("MESA_GLX_FX");
if (str && (tolower (*str) == 'f')) {
Cvar_Set (vid_fullscreen, "1");
}
XGetScreenSaver (x_disp, &xss_timeout, &xss_interval, &xss_blanking,
&xss_exposures);
#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;
int best_mode = 0;
qboolean found_mode = false;
XF86VidModeModeLine orig_data;
XF86VidModeGetAllModeLines (x_disp, x_screen, &nummodes, &vidmodes);
XF86VidModeGetModeLine (x_disp, x_screen, &dotclock, &orig_data);
for (i = 0; i < nummodes; i++) {
if ((vidmodes[i]->hdisplay == orig_data.hdisplay) &&
(vidmodes[i]->vdisplay == orig_data.vdisplay)) {
original_mode = i;
break;
}
}
for (i = 0; i < nummodes; i++) {
if ((vidmodes[i]->hdisplay == vid.width) &&
(vidmodes[i]->vdisplay == vid.height)) {
found_mode = true;
best_mode = i;
break;
}
}
if (found_mode) {
Con_Printf ("VID: Chose video mode: %dx%d\n", vid.width, vid.height);
XSetScreenSaver (x_disp, 0, xss_interval, xss_blanking, xss_exposures);
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[best_mode]);
X11_ForceViewPort ();
vidmode_active = true;
} else {
Con_Printf ("VID: Mode %dx%d can't go fullscreen.\n", vid.width, vid.height);
vid_gamma_avail = vidmode_avail = vidmode_active = false;
}
}
#endif
}
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_CreateWindow (int width, int height)
{
XSetWindowAttributes attr;
XClassHint *ClassHint;
XSizeHints *SizeHints;
char *resname;
unsigned long mask;
/* window attributes */
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap (x_disp, x_root, x_vis, AllocNone);
attr.event_mask = X_MASK;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
if (vidmode_active && vid_fullscreen->int_val) {
attr.override_redirect = 1;
mask |= CWOverrideRedirect;
}
x_win = XCreateWindow (x_disp, x_root, 0, 0, width, height,
0, x_visinfo->depth, InputOutput,
x_vis, mask, &attr);
// Set window size hints
SizeHints = XAllocSizeHints ();
if (SizeHints) {
SizeHints->flags = (PMinSize | PMaxSize);
SizeHints->min_width = width;
SizeHints->min_height = height;
SizeHints->max_width = width;
SizeHints->max_height = height;
XSetWMNormalHints (x_disp, x_win, SizeHints);
XFree (SizeHints);
}
// Set window title
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
// Set icon name
XSetIconName (x_disp, x_win, PROGRAM);
// Set window class
ClassHint = XAllocClassHint ();
if (ClassHint) {
resname = strrchr (com_argv[0], '/');
ClassHint->res_name = (resname ? resname + 1 : com_argv[0]);
ClassHint->res_class = PACKAGE;
XSetClassHint (x_disp, x_win, ClassHint);
XFree (ClassHint);
}
// Make window respond to Delete events
aWMDelete = XInternAtom (x_disp, "WM_DELETE_WINDOW", False);
XSetWMProtocols (x_disp, x_win, &aWMDelete, 1);
if (vidmode_active && vid_fullscreen->int_val) {
XMoveWindow (x_disp, x_win, 0, 0);
XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0,
vid.width + 2, vid.height + 2);
X11_ForceViewPort ();
}
XMapWindow (x_disp, x_win);
if (vidmode_active && vid_fullscreen->int_val) {
XGrabPointer (x_disp, x_win, True, 0, GrabModeAsync, GrabModeAsync, x_win, None, CurrentTime);
}
XRaiseWindow (x_disp, x_win);
}
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);
}
#endif
}
void
X11_GrabKeyboard (void)
{
#ifdef HAVE_VIDMODE
if (vidmode_active && vid_fullscreen->int_val) {
XGrabKeyboard (x_disp, x_win, 1, GrabModeAsync, GrabModeAsync,
CurrentTime);
}
#endif
}
void
X11_SetCaption (char *text)
{
if (x_disp && x_win && text)
XStoreName (x_disp, x_win, text);
}
void
X11_ForceViewPort (void)
{
#ifdef HAVE_VIDMODE
int x, y;
if (vidmode_active && vid_fullscreen->int_val) {
do {
XF86VidModeSetViewPort (x_disp, x_screen, 0, 0);
poll (0, 0, 50);
XF86VidModeGetViewPort (x_disp, x_screen, &x, &y);
} while (x || y);
}
#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

@ -1,152 +0,0 @@
/*
dga_check.c
Routines to check for XFree86 DGA and VidMode extensions
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#ifdef HAVE_DGA
# include <X11/extensions/xf86dga.h>
# include <X11/extensions/xf86dgastr.h>
# ifndef XDGA_MAJOR_VERSION
# ifdef XF86DGA_MAJOR_VERSION
# define XDGA_MAJOR_VERSION XF86DGA_MAJOR_VERSION
# else
# error "Neither XDGA_MAJOR_VERSION nor XF86DGA_MAJOR_VERSION found."
# endif
# endif
#endif
#ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h>
# include <X11/extensions/xf86vmstr.h>
#endif
#include "QF/console.h"
#include "dga_check.h"
/*
VID_CheckDGA
Check for the presence of the XFree86-DGA X server extension
*/
qboolean
VID_CheckDGA (Display * dpy, int *maj_ver, int *min_ver, int *hasvideo)
{
#ifdef HAVE_DGA
int event_base, error_base, dgafeat;
int dummy, dummy_major, dummy_minor, dummy_video;
if (!XQueryExtension (dpy, XF86DGANAME, &dummy, &dummy, &dummy)) {
return false;
}
if (!XF86DGAQueryExtension (dpy, &event_base, &error_base)) {
return false;
}
if (!maj_ver)
maj_ver = &dummy_major;
if (!min_ver)
min_ver = &dummy_minor;
if (!XF86DGAQueryVersion (dpy, maj_ver, min_ver)) {
return false;
}
if ((!maj_ver) || (*maj_ver != XDGA_MAJOR_VERSION)) {
Con_Printf ("VID: Incorrect DGA version: %d.%d, \n", *maj_ver, *min_ver);
return false;
}
Con_Printf ("VID: DGA version: %d.%d\n", *maj_ver, *min_ver);
if (!hasvideo)
hasvideo = &dummy_video;
if (!XF86DGAQueryDirectVideo (dpy, DefaultScreen (dpy), &dgafeat)) {
*hasvideo = 0;
} else {
*hasvideo = (dgafeat & XF86DGADirectGraphics);
}
if (!(dgafeat & (XF86DGADirectPresent | XF86DGADirectMouse))) {
return false;
}
return true;
#else
return false;
#endif // HAVE_DGA
}
/*
VID_CheckVMode
Check for the presence of the XFree86-VidMode X server extension
*/
qboolean
VID_CheckVMode (Display * dpy, int *maj_ver, int *min_ver)
{
#ifdef HAVE_VIDMODE
int event_base, error_base;
int dummy, dummy_major, dummy_minor;
if (!XQueryExtension (dpy, XF86VIDMODENAME, &dummy, &dummy, &dummy)) {
return false;
}
if (!XF86VidModeQueryExtension (dpy, &event_base, &error_base)) {
return false;
}
if (!maj_ver)
maj_ver = &dummy_major;
if (!min_ver)
min_ver = &dummy_minor;
if (!XF86VidModeQueryVersion (dpy, maj_ver, min_ver))
return false;
if ((!maj_ver) || (*maj_ver != XF86VIDMODE_MAJOR_VERSION)) {
Con_Printf ("VID: Incorrect VidMode version: %d.%d\n", *maj_ver, *min_ver);
return false;
}
Con_Printf ("VID: VidMode version: %d.%d\n", *maj_ver, *min_ver);
return true;
#else
return false;
#endif // HAVE_VIDMODE
}

View file

@ -1,180 +0,0 @@
/*
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <math.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/vid.h"
#include "view.h"
extern viddef_t vid; // global video state
/*
Software and hardware gamma support
*/
byte gammatable[256];
cvar_t *vid_gamma;
cvar_t *vid_system_gamma;
qboolean vid_gamma_avail; // hardware gamma availability
/*
Screen size
*/
int scr_width, scr_height;
cvar_t *vid_width;
cvar_t *vid_height;
void
VID_GetWindowSize (int def_w, int def_h)
{
int pnum;
vid_width = Cvar_Get ("vid_width", va ("%d", def_w), CVAR_NONE, NULL,
"screen width");
vid_height = Cvar_Get ("vid_height", va ("%d", def_h), CVAR_NONE, NULL,
"screen height");
if ((pnum = COM_CheckParm ("-width"))) {
if (pnum >= com_argc - 1)
Sys_Error ("VID: -width <width>\n");
Cvar_Set (vid_width, com_argv[pnum + 1]);
if (!vid_width->int_val)
Sys_Error ("VID: Bad window width\n");
}
if ((pnum = COM_CheckParm ("-height"))) {
if (pnum >= com_argc - 1)
Sys_Error ("VID: -height <height>\n");
Cvar_Set (vid_height, com_argv[pnum + 1]);
if (!vid_height->int_val)
Sys_Error ("VID: Bad window height\n");
}
if ((pnum = COM_CheckParm ("-winsize"))) {
if (pnum >= com_argc - 2)
Sys_Error ("VID: -winsize <width> <height>\n");
Cvar_Set (vid_width, com_argv[pnum + 1]);
Cvar_Set (vid_height, com_argv[pnum + 2]);
if (!vid_width->int_val || !vid_height->int_val)
Sys_Error ("VID: Bad window width/height\n");
}
Cvar_SetFlags (vid_width, vid_width->flags | CVAR_ROM);
Cvar_SetFlags (vid_height, vid_height->flags | CVAR_ROM);
scr_width = vid.width = vid_width->int_val;
scr_height = vid.height = vid_height->int_val;
}
/****************************************************************************
* GAMMA FUNCTIONS *
****************************************************************************/
void
VID_BuildGammaTable (double gamma)
{
int i;
gammatable[0] = 0;
if (gamma == 1.0) { // linear, don't bother with the math
for (i = 1; i < 255; i++) {
gammatable[i] = i;
}
} else {
double g = 1.0 / gamma;
int v;
for (i = 1; i < 255; i++) { // Build/update gamma lookup table
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
gammatable[i] = bound (0, v, 255);
}
}
gammatable[255] = 255;
}
/*
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)
{
double gamma = bound (0.1, vid_gamma->value, 9.9);
if (vid_gamma->flags & CVAR_ROM) // System gamma unavailable
return;
if (vid_gamma_avail && vid_system_gamma->int_val) { // Have system, use it
Con_DPrintf ("Setting hardware gamma to %g\n", gamma);
VID_BuildGammaTable (1.0); // hardware gamma wants a linear palette
VID_SetGamma (gamma);
} else { // We have to hack the palette
Con_DPrintf ("Setting software gamma to %g\n", gamma);
VID_BuildGammaTable (gamma);
V_UpdatePalette (); // update with the new palette
}
}
/*
VID_InitGamma
Initialize the vid_gamma Cvar, and set up the palette
*/
void
VID_InitGamma (unsigned char *pal)
{
int i;
double gamma = 1.45;
if ((i = COM_CheckParm ("-gamma"))) {
gamma = atof (com_argv[i + 1]);
}
gamma = bound (0.1, gamma, 9.9);
vid_gamma = Cvar_Get ("vid_gamma", va ("%f", gamma), CVAR_ARCHIVE,
VID_UpdateGamma, "Gamma correction");
VID_BuildGammaTable (vid_gamma->value);
}

View file

@ -1,330 +0,0 @@
/*
vid_3dfxsvga.c
OpenGL device driver for 3Dfx chipsets running Linux
Copyright (C) 1996-1997 Id Software, Inc.
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <GL/gl.h>
#include <GL/fxmesa.h>
#include <glide/glide.h>
#include <glide/sst1vid.h>
#include <sys/signal.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "glquake.h"
#include "host.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/qfgl_ext.h"
#include "QF/quakefs.h"
#include "sbar.h"
#include "QF/sys.h"
#include "QF/va.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
// FIXME!!!!! This belongs in include/qfgl_ext.h -- deek
typedef void (GLAPIENTRY * QF_3DfxSetDitherModeEXT) (GrDitherMode_t mode);
cvar_t *vid_system_gamma;
static fxMesaContext fc = NULL;
int VID_options_items = 0;
extern void GL_Init_Common (void);
extern void VID_Init8bitPalette (void);
/*-----------------------------------------------------------------------*/
void
VID_Shutdown (void)
{
if (!fc)
return;
fxMesaDestroyContext (fc);
}
void
signal_handler (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Host_Shutdown ();
abort ();
// Sys_Quit();
exit (0);
}
void
InitSig (void)
{
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
// signal(SIGIOT, signal_handler);
signal (SIGBUS, signal_handler);
// signal(SIGFPE, signal_handler);
signal (SIGSEGV, signal_handler);
signal (SIGTERM, signal_handler);
}
/*
GL_Init
*/
void
GL_Init (void)
{
QF_3DfxSetDitherModeEXT dither_select = NULL;
int p;
GL_Init_Common ();
if (!(QFGL_ExtensionPresent ("3DFX_set_dither_mode")))
return;
if (!(dither_select = QFGL_ExtensionAddress ("gl3DfxSetDitherModeEXT")))
return;
Con_Printf ("Dithering: ");
if ((p = COM_CheckParm ("-dither")) && p < com_argc) {
if (strequal (com_argv[p+1], "2x2")) {
dither_select (GR_DITHER_2x2);
Con_Printf ("2x2.\n");
}
if (strequal (com_argv[p+1], "4x4")) {
dither_select (GR_DITHER_4x4);
Con_Printf ("4x4.\n");
}
} else {
glDisable (GL_DITHER);
Con_Printf ("disabled.\n");
}
}
void
GL_EndRendering (void)
{
glFlush ();
fxMesaSwapBuffers ();
Sbar_Changed ();
}
static int resolutions[][3] = {
{320, 200, GR_RESOLUTION_320x200},
{320, 240, GR_RESOLUTION_320x240},
{400, 256, GR_RESOLUTION_400x256},
{400, 300, GR_RESOLUTION_400x300},
{512, 256, GR_RESOLUTION_512x256},
{512, 384, GR_RESOLUTION_512x384},
{640, 200, GR_RESOLUTION_640x200},
{640, 350, GR_RESOLUTION_640x350},
{640, 400, GR_RESOLUTION_640x400},
{640, 480, GR_RESOLUTION_640x480},
{800, 600, GR_RESOLUTION_800x600},
{856, 480, GR_RESOLUTION_856x480},
{960, 720, GR_RESOLUTION_960x720},
#ifdef GR_RESOLUTION_1024x768
{1024, 768, GR_RESOLUTION_1024x768},
#endif
#ifdef GR_RESOLUTION_1152x864
{1152, 864, GR_RESOLUTION_1152x864},
#endif
#ifdef GR_RESOLUTION_1280x960
{1280, 960, GR_RESOLUTION_1280x960},
#endif
#ifdef GR_RESOLUTION_1280x1024
{1280, 1024, GR_RESOLUTION_1280x1024},
#endif
#ifdef GR_RESOLUTION_1600x1024
{1600, 1024, GR_RESOLUTION_1600x1024},
#endif
#ifdef GR_RESOLUTION_1600x1200
{1600, 1200, GR_RESOLUTION_1600x1200},
#endif
#ifdef GR_RESOLUTION_1792x1344
{1792, 1344, GR_RESOLUTION_1792x1344},
#endif
#ifdef GR_RESOLUTION_1856x1392
{1856, 1392, GR_RESOLUTION_1856x1392},
#endif
#ifdef GR_RESOLUTION_1920x1440
{1920, 1440, GR_RESOLUTION_1920x1440},
#endif
#ifdef GR_RESOLUTION_2048x1536
{2048, 1536, GR_RESOLUTION_2048x1536},
#endif
#ifdef GR_RESOLUTION_2048x2048
{2048, 2048, GR_RESOLUTION_2048x2048}
#endif
};
#define NUM_RESOLUTIONS (sizeof (resolutions) / (sizeof (int) * 3))
static int
findres (int *width, int *height)
{
int i;
for (i = 0; i < NUM_RESOLUTIONS; i++) {
if ((*width <= resolutions[i][0]) && (*height <= resolutions[i][1])) {
*width = resolutions[i][0];
*height = resolutions[i][1];
return resolutions[i][2];
}
}
*width = 640;
*height = 480;
return GR_RESOLUTION_640x480;
}
void
VID_Init (unsigned char *palette)
{
int i;
GLint attribs[32];
VID_GetWindowSize (640, 480);
Con_CheckResize (); // Now that we have a window size, fix console
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
// interpret command-line params
// set vid parameters
attribs[0] = FXMESA_DOUBLEBUFFER;
attribs[1] = FXMESA_ALPHA_SIZE;
attribs[2] = 1;
attribs[3] = FXMESA_DEPTH_SIZE;
attribs[4] = 1;
attribs[5] = FXMESA_NONE;
if ((i = COM_CheckParm ("-conwidth")))
vid.conwidth = atoi (com_argv[i + 1]);
else
vid.conwidth = 640;
vid.conwidth &= 0xfff8; // make it a multiple of eight
vid.conwidth = max (vid.conwidth, 320);
// pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4;
if ((i = COM_CheckParm ("-conheight")) != 0)
vid.conheight = atoi (com_argv[i + 1]);
vid.conheight = max (vid.conheight, 200);
fc = fxMesaCreateContext (0, findres (&scr_width, &scr_height),
GR_REFRESH_75Hz, attribs);
if (!fc)
Sys_Error ("Unable to create 3DFX context.\n");
fxMesaMakeCurrent (fc);
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
vid.height = vid.conheight = min (vid.conheight, scr_height);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
InitSig (); // trap evil signals
GL_Init ();
GL_CheckBrightness (palette);
VID_InitGamma (palette);
VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them.
VID_Init8bitPalette ();
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
vid.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars (void)
{
vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL, "Use system gamma control if available");
}
void
VID_ExtraOptionDraw (unsigned int options_draw_cursor)
{
/* Port specific Options menu entrys */
}
void
VID_ExtraOptionCmd (int option_cursor)
{
/*
switch(option_cursor)
{
case 12: // Always start with 12
break;
}
*/
}
void
VID_SetCaption (char *text)
{
}
qboolean
VID_SetGamma (double gamma)
{
// FIXME: Need function for HW gamma correction
// return X11_SetGamma (gamma);
grGammaCorrectionValue((float) gamma);
return true;
}

View file

@ -1,395 +0,0 @@
/*
vid_common_gl.c
Common OpenGL video driver functions
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef _WIN32
// must be BEFORE include gl/gl.h
# include "winquake.h"
#endif
#include <GL/gl.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "glquake.h"
#include "QF/qfgl_ext.h"
#include "sbar.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
//unsigned short d_8to16table[256];
unsigned int d_8to24table[256];
unsigned char d_15to8table[65536];
cvar_t *vid_mode;
extern byte gammatable[256];
/*-----------------------------------------------------------------------*/
int texture_extension_number = 1;
float gldepthmin, gldepthmax;
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
// ARB Multitexture
qboolean gl_mtex_capable = false;
GLenum gl_mtex_enum = GL_TEXTURE0_ARB;
QF_glColorTableEXT qglColorTableEXT = NULL;
qboolean is8bit = false;
cvar_t *vid_use8bit;
cvar_t *brightness;
cvar_t *contrast;
extern int gl_filter_min, gl_filter_max;
/*-----------------------------------------------------------------------*/
void
GL_Common_Init_Cvars (void)
{
vid_use8bit = Cvar_Get ("vid_use8bit", "0", CVAR_ROM, NULL, "Use 8-bit shared palettes.");
brightness = Cvar_Get ("brightness", "1", CVAR_ARCHIVE, NULL, "Brightness level");
contrast = Cvar_Get ("contrast", "1", CVAR_ARCHIVE, NULL, "Contrast level");
}
/*
CheckMultiTextureExtensions
Check for ARB multitexture support
*/
void
CheckMultiTextureExtensions (void)
{
Con_Printf ("Checking for multitexture: ");
if (COM_CheckParm ("-nomtex")) {
Con_Printf ("disabled.\n");
return;
}
if (QFGL_ExtensionPresent ("GL_ARB_multitexture")) {
int max_texture_units = 0;
glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &max_texture_units);
if (max_texture_units >= 2) {
Con_Printf ("enabled, %d TMUs.\n", max_texture_units);
qglMultiTexCoord2f = QFGL_ExtensionAddress ("glMultiTexCoord2fARB");
qglActiveTexture = QFGL_ExtensionAddress ("glActiveTextureARB");
gl_mtex_enum = GL_TEXTURE0_ARB;
gl_mtex_capable = true;
} else {
Con_Printf ("disabled, not enough TMUs.\n");
}
} else {
Con_Printf ("not found.\n");
}
}
void
VID_SetPalette (unsigned char *palette)
{
byte *pal;
unsigned int r, g, b;
unsigned int v;
int r1, g1, b1;
int k;
unsigned short i;
unsigned int *table;
QFile *f;
char s[255];
float dist, bestdist;
static qboolean palflag = false;
//
// 8 8 8 encoding
//
// Con_Printf("Converting 8to24\n");
pal = palette;
table = d_8to24table;
for (i = 0; i < 255; i++) { // used to be i<256, see d_8to24table below
r = pal[0];
g = pal[1];
b = pal[2];
pal += 3;
#ifdef WORDS_BIGENDIAN
v = (255 << 0) + (r << 24) + (g << 16) + (b << 8);
#else
v = (255 << 24) + (r << 0) + (g << 8) + (b << 16);
#endif
*table++ = v;
}
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.
if (palflag)
return;
palflag = true;
COM_FOpenFile ("glquake/15to8.pal", &f);
if (f) {
Qread (f, d_15to8table, 1 << 15);
Qclose (f);
} else {
for (i = 0; i < (1 << 15); i++) {
/* 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;
pal = (unsigned char *) d_8to24table;
for (v = 0, k = 0, bestdist = 10000.0; v < 256; v++, pal += 4) {
r1 = (int) r - (int) pal[0];
g1 = (int) g - (int) pal[1];
b1 = (int) b - (int) pal[2];
dist = sqrt (((r1 * r1) + (g1 * g1) + (b1 * b1)));
if (dist < bestdist) {
k = v;
bestdist = dist;
}
}
d_15to8table[i] = k;
}
snprintf (s, sizeof (s), "%s/glquake/15to8.pal", com_gamedir);
COM_CreatePath (s);
if ((f = Qopen (s, "wb")) != NULL) {
Qwrite (f, d_15to8table, 1 << 15);
Qclose (f);
}
}
}
/*
GL_Init_Common
*/
void
GL_Init_Common (void)
{
GL_Common_Init_Cvars ();
gl_vendor = glGetString (GL_VENDOR);
Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
gl_renderer = glGetString (GL_RENDERER);
Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
gl_version = glGetString (GL_VERSION);
Con_Printf ("GL_VERSION: %s\n", gl_version);
gl_extensions = glGetString (GL_EXTENSIONS);
Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
glClearColor (0, 0, 0, 0);
glCullFace (GL_FRONT);
glEnable (GL_TEXTURE_2D);
glEnable (GL_ALPHA_TEST);
glAlphaFunc (GL_GREATER, 0.666);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glShadeModel (GL_FLAT);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
CheckMultiTextureExtensions ();
}
/*
GL_BeginRendering
*/
void
GL_BeginRendering (int *x, int *y, int *width, int *height)
{
*x = *y = 0;
*width = scr_width;
*height = scr_height;
}
qboolean
VID_Is8bit (void)
{
return is8bit;
}
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
void
Tdfx_Init8bitPalette (void)
{
// Check for 8bit Extensions and initialize them.
int i;
if (is8bit) {
return;
}
if (QFGL_ExtensionPresent ("3DFX_set_global_palette")) {
char *oldpal;
GLubyte table[256][4];
QF_gl3DfxSetPaletteEXT qgl3DfxSetPaletteEXT = NULL;
if (!(qgl3DfxSetPaletteEXT = QFGL_ExtensionAddress ("gl3DfxSetPaletteEXT"))) {
Con_Printf ("3DFX_set_global_palette not found.\n");
return;
}
Con_Printf ("3DFX_set_global_palette.\n");
oldpal = (char *) d_8to24table; // d_8to24table3dfx;
for (i = 0; i < 256; i++) {
table[i][2] = *oldpal++;
table[i][1] = *oldpal++;
table[i][0] = *oldpal++;
table[i][3] = 255;
oldpal++;
}
glEnable (GL_SHARED_TEXTURE_PALETTE_EXT);
qgl3DfxSetPaletteEXT ((GLuint *) table);
is8bit = true;
} else {
Con_Printf ("\n 3DFX_set_global_palette not found.");
}
}
/*
* The GL_EXT_shared_texture_palette seems like an idea which is
* /almost/ a good idea, but seems to be severely broken with many
* drivers, as such it is disabled.
*
* It should be noted, that a palette object extension as suggested by
* the GL_EXT_shared_texture_palette spec might be a very good idea in
* general.
*/
void
Shared_Init8bitPalette (void)
{
int i;
GLubyte thePalette[256 * 3];
GLubyte *oldPalette, *newPalette;
if (is8bit) {
return;
}
if (QFGL_ExtensionPresent ("GL_EXT_shared_texture_palette")) {
if (!(qglColorTableEXT = QFGL_ExtensionAddress ("glColorTableEXT"))) {
Con_Printf ("glColorTableEXT not found.\n");
return;
}
Con_Printf ("GL_EXT_shared_texture_palette\n");
glEnable (GL_SHARED_TEXTURE_PALETTE_EXT);
oldPalette = (GLubyte *) d_8to24table; // d_8to24table3dfx;
newPalette = thePalette;
for (i = 0; i < 256; i++) {
*newPalette++ = *oldPalette++;
*newPalette++ = *oldPalette++;
*newPalette++ = *oldPalette++;
oldPalette++;
}
qglColorTableEXT (GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB,
GL_UNSIGNED_BYTE, (GLvoid *) thePalette);
is8bit = true;
} else {
Con_Printf ("\n GL_EXT_shared_texture_palette not found.");
}
}
#endif
void
VID_Init8bitPalette (void)
{
Con_Printf ("Checking for 8-bit extension: ");
if (vid_use8bit->int_val) {
#ifdef GL_SHARED_TEXTURE_PALETTE_EXT
Tdfx_Init8bitPalette ();
Shared_Init8bitPalette ();
#endif
if (!is8bit) {
Con_Printf ("\n 8-bit extension not found.\n");
}
} else {
Con_Printf ("disabled.\n");
}
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{
}
void
D_EndDirectRect (int x, int y, int width, int height)
{
}

View file

@ -1,39 +0,0 @@
/*
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"

View file

@ -1,710 +0,0 @@
/*
vid_fbdev.c
Linux FBDev video routines
based on vid_svgalib.c
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999-2000 David Symonds [xoxus@usa.net]
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_IO_H
# include <sys/io.h>
#elif defined(HAVE_ASM_IO_H)
# include <asm/io.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <asm/page.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include "QF/cmd.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "d_local.h"
#include "host.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/sys.h"
#include "fbset.h"
unsigned short d_8to16table[256];
extern void ReadModeDB(void);
extern struct VideoMode *FindVideoMode(const char *name);
void ConvertFromVideoMode(const struct VideoMode *vmode,
struct fb_var_screeninfo *var);
void ConvertToVideoMode(const struct fb_var_screeninfo *var,
struct VideoMode *vmode);
extern struct VideoMode *VideoModes;
static struct VideoMode current_mode;
static char current_name[32];
static int num_modes;
static int fb_fd = -1;
static int tty_fd = 0;
static byte vid_current_palette[768];
static int fbdev_inited = 0;
static int fbdev_backgrounded = 0;
static int UseDisplay = 1;
static cvar_t *vid_mode;
static cvar_t *vid_redrawfull;
static cvar_t *vid_waitforrefresh;
static char *framebuffer_ptr;
static byte backingbuf[48 * 24];
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
int i, j, reps, repshift, offset, off;
if (!fbdev_inited || !vid.direct || fbdev_backgrounded)
return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
memcpy (&backingbuf[(i + j) * 24], vid.direct + off, width);
memcpy (vid.direct + off,
&pbitmap[(i >> repshift) * width], width);
}
}
}
void
D_EndDirectRect (int x, int y, int width, int height)
{
int i, j, reps, repshift, offset, off;
if (!fbdev_inited || !vid.direct || fbdev_backgrounded)
return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
memcpy (vid.direct + off, &backingbuf[(i + j) * 24], width);
}
}
}
static void
VID_Gamma_f (void)
{
float gamma, f, inf;
unsigned char palette[768];
int i;
if (Cmd_Argc () == 2) {
gamma = atof (Cmd_Argv (1));
for (i = 0; i < 768; i++) {
f = pow ((host_basepal[i] + 1) / 256.0, gamma);
inf = f * 255 + 0.5;
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
palette[i] = inf;
}
VID_SetPalette (palette);
/* Force a surface cache flush */
vid.recalc_refdef = 1;
}
}
static void
VID_DescribeMode_f (void)
{
char *modestr;
struct VideoMode *vmode;
modestr = Cmd_Argv(1);
vmode = FindVideoMode(modestr);
if (!vmode) {
Con_Printf ("Invalid video mode: %s!\n", modestr);
return;
}
Con_Printf ("%s: %d x %d - %d bpp - %5.3f Hz\n", vmode->name,
vmode->xres, vmode->yres, vmode->depth, vmode->vrate);
}
static void
VID_DescribeModes_f (void)
{
struct VideoMode *vmode;
for (vmode = VideoModes; vmode; vmode = vmode->next) {
Con_Printf ("%s: %d x %d - %d bpp - %5.3f Hz\n", vmode->name,
vmode->xres, vmode->yres, vmode->depth, vmode->vrate);
}
}
/*
VID_NumModes
*/
static int
VID_NumModes (void)
{
struct VideoMode *vmode;
int i = 0;
for (vmode = VideoModes; vmode; vmode = vmode->next)
i++;
return i;
}
static void
VID_NumModes_f (void)
{
Con_Printf ("%d modes\n", VID_NumModes ());
}
int VID_SetMode (char *name, unsigned char *palette);
extern void fbset_main (int argc, char **argv);
static void
VID_fbset_f (void)
{
int i, argc;
char *argv[32];
argc = Cmd_Argc();
if (argc > 32)
argc = 32;
argv[0] = "vid_fbset";
for (i = 1; i < argc; i++) {
argv[i] = Cmd_Argv(i);
}
fbset_main(argc, argv);
}
static void
VID_Debug_f (void)
{
Con_Printf ("mode: %s\n", current_mode.name);
Con_Printf ("height x width: %d x %d\n", current_mode.xres, current_mode.yres);
Con_Printf ("bpp: %d\n", current_mode.depth);
Con_Printf ("vrate: %5.3f\n", current_mode.vrate);
Con_Printf ("vid.aspect: %f\n", vid.aspect);
}
static void
VID_InitModes (void)
{
ReadModeDB();
num_modes = VID_NumModes();
}
static char *
get_mode (char *name, int width, int height, int depth)
{
struct VideoMode *vmode;
for (vmode = VideoModes; vmode; vmode = vmode->next) {
if (name) {
if (!strcmp(vmode->name, name))
return name;
} else {
if (vmode->xres == width
&& vmode->yres == height
&& vmode->depth == depth)
return vmode->name;
}
}
Sys_Printf ("Mode %dx%d (%d bits) not supported\n",
width, height, depth);
return "640x480-60";
}
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize;
void *vid_surfcache;
// Calculate the sizes we want first
buffersize = vid.rowbytes * vid.height;
zbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
cachesize = D_SurfaceCacheForRes (vid.width, vid.height);
// Free the old screen buffer
if (vid.buffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
}
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new screen buffer
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
if (!vid.conbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new z-buffer
d_pzbuffer = calloc (zbuffersize, 1);
if (!d_pzbuffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (cachesize, 1);
if (!vid_surfcache) {
free (vid.buffer);
free (d_pzbuffer);
vid.conbuffer = vid.buffer = NULL;
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, cachesize);
}
static unsigned char *fb_map_addr = 0;
static unsigned long fb_map_length = 0;
static struct fb_var_screeninfo orig_var;
void
VID_Shutdown (void)
{
Sys_Printf ("VID_Shutdown\n");
if (!fbdev_inited)
return;
if (munmap(fb_map_addr, fb_map_length) == -1) {
Sys_Printf("could not unmap framebuffer at %p: %s\n",
fb_map_addr, strerror(errno));
} else {
if (ioctl(fb_fd, FBIOPUT_VSCREENINFO, &orig_var))
Sys_Printf ("failed to get var screen info\n");
}
close(fb_fd);
if (UseDisplay) {
ioctl(tty_fd, KDSETMODE, KD_TEXT);
write(tty_fd, "\033]R", 3); /* reset palette */
}
fbdev_inited = 0;
}
void
VID_ShiftPalette (unsigned char *p)
{
VID_SetPalette (p);
}
static void
loadpalette (unsigned short *red, unsigned short *green, unsigned short *blue)
{
struct fb_cmap cmap;
cmap.len = 256;
cmap.red = red;
cmap.green = green;
cmap.blue = blue;
cmap.transp = NULL;
cmap.start = 0;
if (-1 == ioctl(fb_fd, FBIOPUTCMAP, (void *)&cmap))
Sys_Error("ioctl FBIOPUTCMAP %s\n", strerror(errno));
}
void
VID_SetPalette (byte * palette)
{
static unsigned short tmppalr[256], tmppalg[256], tmppalb[256];
unsigned short i, *tpr, *tpg, *tpb;
if (!fbdev_inited || fbdev_backgrounded || fb_fd < 0)
return;
memcpy (vid_current_palette, palette, sizeof (vid_current_palette));
if (current_mode.depth == 8) {
tpr = tmppalr;
tpg = tmppalg;
tpb = tmppalb;
for (i = 0; i < 256; i++) {
*tpr++ = (*palette++) << 8;
*tpg++ = (*palette++) << 8;
*tpb++ = (*palette++) << 8;
}
if (UseDisplay) {
loadpalette(tmppalr, tmppalg, tmppalb);
}
}
}
int
VID_SetMode (char *name, unsigned char *palette)
{
struct VideoMode *vmode;
struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;
int err;
unsigned long smem_start, smem_offset;
vmode = FindVideoMode(name);
if (!vmode) {
Cvar_Set (vid_mode, current_mode.name);
// Con_Printf ("No such video mode: %s\n", name);
return 0;
}
current_mode = *vmode;
Cvar_Set (vid_mode, current_mode.name);
strncpy(current_name, current_mode.name, sizeof(current_name)-1);
current_name[31] = 0;
vid.width = vmode->xres;
vid.height = vmode->yres;
vid.rowbytes = vmode->xres * (vmode->depth >> 3);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.colormap = (pixel_t *) host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.numpages = 1;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
if (fb_map_addr) {
if (munmap(fb_map_addr, fb_map_length) == -1) {
Sys_Printf("could not unmap framebuffer at %p: %s\n",
fb_map_addr, strerror(errno));
}
}
ConvertFromVideoMode(&current_mode, &var);
err = ioctl(fb_fd, FBIOPUT_VSCREENINFO, &var);
if (err)
Sys_Error ("Video mode failed: %s\n", name);
ConvertToVideoMode(&var, &current_mode);
current_mode.name = current_name;
VID_SetPalette (palette);
err = ioctl(fb_fd, FBIOGET_FSCREENINFO, &fix);
if (err)
Sys_Error ("Video mode failed: %s\n", name);
smem_start = (unsigned long)fix.smem_start & PAGE_MASK;
smem_offset = (unsigned long)fix.smem_start & ~PAGE_MASK;
fb_map_length = (smem_offset+fix.smem_len+~PAGE_MASK) & PAGE_MASK;
fb_map_addr = (char *)mmap(0, fb_map_length, PROT_WRITE, MAP_SHARED, fb_fd, 0);
if (!fb_map_addr)
Sys_Error ("This mode isn't hapnin'\n");
vid.direct = framebuffer_ptr = fb_map_addr;
// alloc screen buffer, z-buffer, and surface cache
VID_InitBuffers ();
if (!fbdev_inited) {
fbdev_inited = 1;
}
/* Force a surface cache flush */
vid.recalc_refdef = 1;
return 1;
}
static void
fb_switch_handler (int sig)
{
if (sig == SIGUSR1) {
fbdev_backgrounded = 1;
} else if (sig == SIGUSR2) {
fbdev_backgrounded = 2;
}
}
static void
fb_switch_release (void)
{
ioctl(tty_fd, VT_RELDISP, 1);
}
static void
fb_switch_acquire (void)
{
ioctl(tty_fd, VT_RELDISP, VT_ACKACQ);
}
static void
fb_switch_init (void)
{
struct sigaction act;
struct vt_mode vtmode;
memset(&act, 0, sizeof(act));
act.sa_handler = fb_switch_handler;
sigemptyset(&act.sa_mask);
sigaction(SIGUSR1, &act, 0);
sigaction(SIGUSR2, &act, 0);
if (ioctl(tty_fd, VT_GETMODE, &vtmode)) {
Sys_Error("ioctl VT_GETMODE: %s\n", strerror(errno));
}
vtmode.mode = VT_PROCESS;
vtmode.waitv = 0;
vtmode.relsig = SIGUSR1;
vtmode.acqsig = SIGUSR2;
if (ioctl(tty_fd, VT_SETMODE, &vtmode)) {
Sys_Error("ioctl VT_SETMODE: %s\n", strerror(errno));
}
}
void
VID_Init (unsigned char *palette)
{
int w, h, d;
struct VideoMode *vmode;
char *modestr;
char *fbname;
// plugin_load("in_fbdev.so");
if (fbdev_inited)
return;
Cmd_AddCommand ("gamma", VID_Gamma_f, "No Description");
if (UseDisplay) {
fbname = getenv("FRAMEBUFFER");
if (!fbname)
fbname = "/dev/fb0";
fb_fd = open(fbname, O_RDWR);
if (fb_fd < 0)
Sys_Error ("failed to open fb device\n");
if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &orig_var))
Sys_Error ("failed to get var screen info\n");
fb_switch_init();
VID_InitModes ();
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, "No Description");
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f, "No Description");
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f, "No Description");
Cmd_AddCommand ("vid_debug", VID_Debug_f, "No Description");
Cmd_AddCommand ("vid_fbset", VID_fbset_f, "No Description");
/* Interpret command-line params */
w = h = d = 0;
if (getenv ("GFBDEVMODE")) {
modestr = get_mode (getenv ("GFBDEVMODE"), w, h, d);
} else if (COM_CheckParm ("-mode")) {
modestr = get_mode (com_argv[COM_CheckParm ("-mode") + 1], w, h, d);
} else if (COM_CheckParm ("-w") || COM_CheckParm ("-h")
|| COM_CheckParm ("-d")) {
if (COM_CheckParm ("-w")) {
w = atoi (com_argv[COM_CheckParm ("-w") + 1]);
}
if (COM_CheckParm ("-h")) {
h = atoi (com_argv[COM_CheckParm ("-h") + 1]);
}
if (COM_CheckParm ("-d")) {
d = atoi (com_argv[COM_CheckParm ("-d") + 1]);
}
modestr = get_mode (0, w, h, d);
} else {
modestr = "640x480-60";
}
/* Set vid parameters */
vmode = FindVideoMode(modestr);
if (!vmode)
Sys_Error("no video mode %s\n", modestr);
current_mode = *vmode;
ioctl(tty_fd, KDSETMODE, KD_GRAPHICS);
VID_SetMode (current_mode.name, palette);
Con_CheckResize (); // Now that we have a window size, fix console
VID_SetPalette (palette);
}
}
void
VID_Init_Cvars ()
{
vid_mode = Cvar_Get ("vid_mode", "0", CVAR_NONE, NULL,
"Sets the video mode");
vid_redrawfull = Cvar_Get ("vid_redrawfull", "0", CVAR_NONE, NULL,
"Redraw entire screen each frame instead of just dirty areas");
vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh", "0", CVAR_ARCHIVE,
NULL, "Wait for vertical retrace before drawing next frame");
}
void
VID_Update (vrect_t *rects)
{
if (!fbdev_inited)
return;
if (fbdev_backgrounded) {
if (fbdev_backgrounded == 3) {
return;
} else if (fbdev_backgrounded == 2) {
fb_switch_acquire();
fbdev_backgrounded = 0;
VID_SetPalette(vid_current_palette);
} else if (fbdev_backgrounded == 1) {
fb_switch_release();
fbdev_backgrounded = 3;
return;
}
}
if (vid_waitforrefresh->int_val) {
// ???
}
if (vid_redrawfull->int_val) {
double *d = (double *)framebuffer_ptr, *s = (double *)vid.buffer;
double *ends = (double *)(vid.buffer + vid.height*vid.rowbytes);
while (s < ends)
*d++ = *s++;
} else {
while (rects) {
int height, width, lineskip, i, j, xoff, yoff;
double *d, *s;
height = rects->height;
width = rects->width / sizeof(double);
xoff = rects->x;
yoff = rects->y;
lineskip = (vid.width - (xoff + rects->width)) / sizeof(double);
d = (double *)(framebuffer_ptr + yoff * vid.rowbytes + xoff);
s = (double *)(vid.buffer + yoff * vid.rowbytes + xoff);
for (i = yoff; i < height; i++) {
for (j = xoff; j < width; j++)
*d++ = *s++;
d += lineskip;
s += lineskip;
}
rects = rects->pnext;
}
}
if (current_mode.name && strcmp(vid_mode->string, current_mode.name)) {
VID_SetMode (vid_mode->string, vid_current_palette);
}
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
}
qboolean
VID_SetGamma (double gamma)
{
return false;
}

View file

@ -1,250 +0,0 @@
/*
vid_glx.c
OpenGL GLX video driver
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <GL/glx.h>
#include <X11/keysym.h>
#include <X11/cursorfont.h>
#ifdef HAVE_DGA
# include <X11/extensions/xf86dga.h>
#endif
#include "QF/compat.h"
#include "QF/console.h"
#include "context_x11.h"
#include "glquake.h"
#include "host.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"
#include "sbar.h"
#include "QF/va.h"
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
static qboolean vid_initialized = false;
static GLXContext ctx = NULL;
extern void GL_Init_Common (void);
extern void VID_Init8bitPalette (void);
/*-----------------------------------------------------------------------*/
const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;
void
VID_Shutdown (void)
{
if (!vid_initialized)
return;
Con_Printf ("VID_Shutdown\n");
X11_RestoreVidMode ();
X11_CloseDisplay ();
}
#if 0
static void
signal_handler (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Sys_Quit ();
exit (sig);
}
static void
InitSig (void)
{
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
signal (SIGIOT, signal_handler);
signal (SIGBUS, signal_handler);
/* signal (SIGFPE, signal_handler); */
signal (SIGSEGV, signal_handler);
signal (SIGTERM, signal_handler);
}
#endif
/*
GL_Init
*/
void
GL_Init (void)
{
GL_Init_Common ();
}
void
GL_EndRendering (void)
{
glFlush ();
glXSwapBuffers (x_disp, x_win);
Sbar_Changed ();
}
void
VID_Init (unsigned char *palette)
{
int i;
int attrib[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, 1,
None
};
VID_GetWindowSize (640, 480);
Con_CheckResize (); // Now that we have a window size, fix console
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
/* Interpret command-line params */
/* Set vid parameters */
if ((i = COM_CheckParm ("-conwidth")))
vid.conwidth = atoi (com_argv[i + 1]);
else
vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight
vid.conwidth = max (vid.conwidth, 320);
// pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4;
if ((i = COM_CheckParm ("-conheight"))) // conheight no smaller than
// 200px
vid.conheight = atoi (com_argv[i + 1]);
vid.conheight = max (vid.conheight, 200);
X11_OpenDisplay ();
x_visinfo = glXChooseVisual (x_disp, x_screen, attrib);
if (!x_visinfo) {
fprintf (stderr,
"Error couldn't get an RGB, Double-buffered, Depth visual\n");
exit (1);
}
x_vis = x_visinfo->visual;
X11_SetVidMode (scr_width, scr_height);
X11_CreateWindow (scr_width, scr_height);
/* Invisible cursor */
X11_CreateNullCursor ();
X11_GrabKeyboard ();
XSync (x_disp, 0);
ctx = glXCreateContext (x_disp, x_visinfo, NULL, True);
glXMakeCurrent (x_disp, x_win, ctx);
vid.height = vid.conheight = min (vid.conheight, scr_height);
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
// InitSig (); // trap evil signals
GL_Init ();
GL_CheckBrightness (palette);
VID_InitGamma (palette);
VID_SetPalette (palette);
// Check for 8-bit extension and initialize if present
VID_Init8bitPalette ();
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
vid_initialized = true;
vid.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars ()
{
X11_Init_Cvars ();
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
X11_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
}
}
double
VID_GetGamma (void)
{
return (double) X11_GetGamma ();
}
qboolean
VID_SetGamma (double gamma)
{
return X11_SetGamma (gamma);
}

File diff suppressed because it is too large Load diff

View file

@ -1,108 +0,0 @@
/*
vid_null.c
null video driver to aid porting efforts
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "d_local.h"
viddef_t vid; // global video state
#define BASEWIDTH 320
#define BASEHEIGHT 200
byte vid_buffer[BASEWIDTH * BASEHEIGHT];
short zbuffer[BASEWIDTH * BASEHEIGHT];
byte surfcache[256 * 1024];
unsigned short d_8to16table[256];
unsigned int d_8to24table[256];
void
VID_SetPalette (unsigned char *palette)
{
}
void
VID_ShiftPalette (unsigned char *palette)
{
}
void
VID_Init (unsigned char *palette)
{
vid.maxwarpwidth = vid.width = vid.conwidth = BASEWIDTH;
vid.maxwarpheight = vid.height = vid.conheight = BASEHEIGHT;
vid.aspect = 1.0;
vid.numpages = 1;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
vid.buffer = vid.conbuffer = vid_buffer;
vid.rowbytes = vid.conrowbytes = BASEWIDTH;
d_pzbuffer = zbuffer;
D_InitCaches (surfcache, sizeof (surfcache));
}
void
VID_Init_Cvars ()
{
}
void
VID_Shutdown (void)
{
}
void
VID_Update (vrect_t *rects)
{
}
/*
D_BeginDirectRect
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
}
/*
D_EndDirectRect
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
}
void
VID_SetCaption (char *text)
{
}

View file

@ -1,303 +0,0 @@
/*
vid_sdl.c
Video driver for Sam Lantinga's Simple DirectMedia Layer
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <stdlib.h>
#include <SDL.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "d_local.h"
#include "host.h"
#include "QF/qendian.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "vid.h"
#ifdef WIN32
/* FIXME: this is evil hack to get full DirectSound support with SDL */
#include <windows.h>
#include <SDL_syswm.h>
HWND mainwindow;
#endif
// static float oldin_grab = 0;
cvar_t *vid_fullscreen;
cvar_t *vid_system_gamma;
qboolean vid_gamma_avail;
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
int modestate; // FIXME: just to avoid cross-comp.
// errors - remove later
// The original defaults
#define BASEWIDTH 320
#define BASEHEIGHT 200
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes = 0;
byte *VGA_pagebase;
static SDL_Surface *screen = NULL;
void
VID_InitBuffers (int width, int height)
{
int tbuffersize, tcachesize;
void *vid_surfcache;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes (width, height);
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, tcachesize);
}
void
VID_SetPalette (unsigned char *palette)
{
int i;
SDL_Color colors[256];
for (i = 0; i < 256; ++i) {
colors[i].r = *palette++;
colors[i].g = *palette++;
colors[i].b = *palette++;
}
SDL_SetColors (screen, colors, 0, 256);
}
void
VID_ShiftPalette (unsigned char *palette)
{
VID_SetPalette (palette);
}
void
VID_Init (unsigned char *palette)
{
// Uint8 video_bpp;
// Uint16 video_w, video_h;
Uint32 flags;
// Load the SDL library
if (SDL_Init (SDL_INIT_VIDEO) < 0) // |SDL_INIT_AUDIO|SDL_INIT_CDROM) <
// 0)
Sys_Error ("VID: Couldn't load SDL: %s", SDL_GetError ());
// Set up display mode (width and height)
VID_GetWindowSize (BASEWIDTH, BASEHEIGHT);
Con_CheckResize (); // Now that we have a window size, fix console
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
// Set video width, height and flags
flags = (SDL_SWSURFACE | SDL_HWPALETTE);
if (vid_fullscreen->int_val)
flags |= SDL_FULLSCREEN;
// Initialize display
if (!(screen = SDL_SetVideoMode (vid.width, vid.height, 8, flags)))
Sys_Error ("VID: Couldn't set video mode: %s\n", SDL_GetError ());
VID_InitGamma (palette);
VID_SetPalette (palette);
// now know everything we need to know about the buffer
VGA_width = vid.conwidth = vid.width;
VGA_height = vid.conheight = vid.height;
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 1;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
VGA_pagebase = vid.buffer = screen->pixels;
VGA_rowbytes = vid.rowbytes = screen->pitch;
vid.conbuffer = vid.buffer;
vid.conrowbytes = vid.rowbytes;
vid.direct = 0;
// allocate z buffer and surface cache
VID_InitBuffers (vid.width, vid.height);
// initialize the mouse
SDL_ShowCursor (0);
#ifdef WIN32
// FIXME: EVIL thing - but needed for win32 until
// SDL_sound works better - without this DirectSound fails.
// SDL_GetWMInfo(&info);
// mainwindow=info.window;
mainwindow=GetActiveWindow();
#endif
}
void
VID_Init_Cvars ()
{
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
VID_Shutdown (void)
{
SDL_Quit ();
}
void
VID_Update (vrect_t *rects)
{
SDL_Rect *sdlrects;
int n, i;
vrect_t *rect;
// Two-pass system, since Quake doesn't do it the SDL way...
// First, count the number of rectangles
n = 0;
for (rect = rects; rect; rect = rect->pnext)
++n;
// Second, copy them to SDL rectangles and update
if (!(sdlrects = (SDL_Rect *) calloc (1, n * sizeof (SDL_Rect))))
Sys_Error ("Out of memory!");
i = 0;
for (rect = rects; rect; rect = rect->pnext) {
sdlrects[i].x = rect->x;
sdlrects[i].y = rect->y;
sdlrects[i].w = rect->width;
sdlrects[i].h = rect->height;
++i;
}
SDL_UpdateRects (screen, n, sdlrects);
}
/*
D_BeginDirectRect
*/
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
Uint8 *offset;
if (!screen)
return;
if (x < 0)
x = screen->w + x - 1;
offset = (Uint8 *) screen->pixels + y * screen->pitch + x;
while (height--) {
memcpy (offset, pbitmap, width);
offset += screen->pitch;
pbitmap += width;
}
}
/*
D_EndDirectRect
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
if (!screen)
return;
if (x < 0)
x = screen->w + x - 1;
SDL_UpdateRect (screen, x, y, width, height);
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
SDL_WM_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
free (temp);
} else {
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
}
}
qboolean
VID_SetGamma (double gamma)
{
// return SDL_SetGamma ((float) gamma, (float) gamma, (float) gamma);
return false; // FIXME
}

View file

@ -1,268 +0,0 @@
/*
vid_sgl.c
Video driver for OpenGL-using versions of SDL
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifndef WIN32
# include <sys/signal.h>
#endif
#include <SDL.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "glquake.h"
#include "host.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "sbar.h"
#include "QF/sys.h"
#include "QF/va.h"
#ifdef WIN32
/* FIXME: this is evil hack to get full DirectSound support with SDL */
# include <windows.h>
# include <SDL_syswm.h>
HWND mainwindow;
#endif
#define WARP_WIDTH 320
#define WARP_HEIGHT 200
static qboolean vid_initialized = false;
cvar_t *vid_fullscreen;
cvar_t *vid_system_gamma;
qboolean vid_gamma_avail;
int VID_options_items = 1;
int modestate;
extern void GL_Init_Common (void);
extern void VID_Init8bitPalette (void);
/*-----------------------------------------------------------------------*/
void
VID_SDL_GammaCheck (void)
{
Uint16 redtable[256], greentable[256], bluetable[256];
if (SDL_GetGammaRamp(redtable, greentable, bluetable) < 0)
vid_gamma_avail = false;
else
vid_gamma_avail = true;
}
void
VID_Shutdown (void)
{
// if (!vid_initialized)
// return;
// Con_Printf ("VID_Shutdown\n");
SDL_Quit ();
}
#ifndef WIN32
static void
signal_handler (int sig)
{
printf ("Received signal %d, exiting...\n", sig);
Sys_Quit ();
exit (sig);
}
static void
InitSig (void)
{
signal (SIGHUP, signal_handler);
signal (SIGINT, signal_handler);
signal (SIGQUIT, signal_handler);
signal (SIGILL, signal_handler);
signal (SIGTRAP, signal_handler);
signal (SIGIOT, signal_handler);
signal (SIGBUS, signal_handler);
// signal(SIGFPE, signal_handler);
signal (SIGSEGV, signal_handler);
signal (SIGTERM, signal_handler);
}
#endif
void
GL_Init (void)
{
GL_Init_Common ();
}
void
GL_EndRendering (void)
{
glFlush ();
SDL_GL_SwapBuffers ();
Sbar_Changed ();
}
void
VID_Init (unsigned char *palette)
{
Uint32 flags = SDL_OPENGL;
int i;
// SDL_SysWMinfo info;
VID_GetWindowSize (640, 480);
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
// Interpret command-line params
// Set vid parameters
if ((i = COM_CheckParm ("-conwidth")) != 0)
vid.conwidth = atoi (com_argv[i + 1]);
else
vid.conwidth = scr_width;
vid.conwidth &= 0xfff8; // make it a multiple of eight
if (vid.conwidth < 320)
vid.conwidth = 320;
// pick a conheight that matches with correct aspect
vid.conheight = vid.conwidth * 3 / 4;
i = COM_CheckParm ("-conheight");
if (i != 0) // Set console height, but no smaller
// than 200 px
vid.conheight = max (atoi (com_argv[i + 1]), 200);
// Initialize the SDL library
if (SDL_Init (SDL_INIT_VIDEO) < 0)
Sys_Error ("Couldn't initialize SDL: %s\n", SDL_GetError ());
// Check if we want fullscreen
if (vid_fullscreen->value) {
flags |= SDL_FULLSCREEN;
// Don't annoy Mesa/3dfx folks
#ifndef WIN32
// FIXME: Maybe this could be put in a different spot, but I don't
// know where.
// Anyway, it's to work around a 3Dfx Glide bug.
SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_ON);
setenv ("MESA_GLX_FX", "fullscreen", 1);
} else {
setenv ("MESA_GLX_FX", "window", 1);
#endif
}
// Setup GL Attributes
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1);
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 1);
if (SDL_SetVideoMode (scr_width, scr_height, 8, flags) == NULL) {
Sys_Error ("Couldn't set video mode: %s\n", SDL_GetError ());
SDL_Quit ();
}
vid.height = vid.conheight = min (vid.conheight, scr_height);
vid.width = vid.conwidth = min (vid.conwidth, scr_width);
Con_CheckResize (); // Now that we have a window size, fix console
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.numpages = 2;
#ifndef WIN32
InitSig (); // trap evil signals
#endif
GL_Init ();
VID_SDL_GammaCheck ();
GL_CheckBrightness (palette);
VID_InitGamma (palette);
VID_SetPalette (palette);
// Check for 3DFX Extensions and initialize them.
VID_Init8bitPalette ();
Con_Printf ("Video mode %dx%d initialized.\n", scr_width, scr_height);
vid_initialized = true;
#ifdef WIN32
// FIXME: EVIL thing - but needed for win32 until
// SDL_sound works better - without this DirectSound fails.
// SDL_GetWMInfo(&info);
// mainwindow=info.window;
mainwindow=GetActiveWindow();
#endif
vid.recalc_refdef = 1; // force a surface cache flush
}
void
VID_Init_Cvars ()
{
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ROM, NULL,
"Toggles fullscreen mode");
vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL,
"Use system gamma control if available");
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
SDL_WM_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp), NULL);
free (temp);
} else {
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
}
}
qboolean
VID_SetGamma (double gamma)
{
return SDL_SetGamma((float) gamma, (float) gamma, (float) gamma);
}

View file

@ -1,773 +0,0 @@
/*
vid_svgalib.c
Linux SVGALib video routines
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-2000 Marcus Sundberg [mackan@stacken.kth.se]
Copyright (C) 1999-2000 David Symonds [xoxus@usa.net]
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
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(HAVE_SYS_IO_H)
# include <sys/io.h>
#elif defined(HAVE_ASM_IO_H)
# include <asm/io.h>
#endif
#include <stdio.h>
#include <vga.h>
#include "QF/cmd.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "d_local.h"
#include "host.h"
#include "QF/input.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "QF/sys.h"
void VGA_UpdatePlanarScreen (void *srcbuffer);
cvar_t *vid_system_gamma;
qboolean vid_gamma_avail;
unsigned short d_8to16table[256];
static int num_modes, current_mode;
static vga_modeinfo *modes;
static byte vid_current_palette[768];
static int svgalib_inited = 0;
static int svgalib_backgrounded = 0;
static int UseDisplay = 1;
static cvar_t *vid_mode;
static cvar_t *vid_redrawfull;
static cvar_t *vid_waitforrefresh;
static char *framebuffer_ptr;
static byte backingbuf[48 * 24];
int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar;
byte *VGA_pagebase;
int VID_options_items = 0;
void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height)
{
int i, j, k, plane, reps, repshift, offset, vidpage, off;
if (!svgalib_inited || !vid.direct || svgalib_backgrounded
|| !vga_oktowrite ())return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
vidpage = 0;
vga_setpage (0);
if (VGA_planar) {
for (plane = 0; plane < 4; plane++) {
/* Select the correct plane for reading and writing */
outb (0x02, 0x3C4);
outb (1 << plane, 0x3C5);
outb (4, 0x3CE);
outb (plane, 0x3CF);
for (i = 0; i < (height << repshift); i += reps) {
for (k = 0; k < reps; k++) {
for (j = 0; j < (width >> 2); j++) {
backingbuf[(i + k) * 24 + (j << 2) + plane] =
vid.direct[(y + i + k) * VGA_rowbytes +
(x >> 2) + j];
vid.direct[(y + i + k) * VGA_rowbytes + (x >> 2) + j] =
pbitmap[(i >> repshift) * 24 + (j << 2) + plane];
}
}
}
}
} else {
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
if ((offset / 0x10000) != vidpage) {
vidpage = offset / 0x10000;
vga_setpage (vidpage);
}
memcpy (&backingbuf[(i + j) * 24], vid.direct + off, width);
memcpy (vid.direct + off,
&pbitmap[(i >> repshift) * width], width);
}
}
}
}
void
D_EndDirectRect (int x, int y, int width, int height)
{
int i, j, k, plane, reps, repshift, offset, vidpage, off;
if (!svgalib_inited || !vid.direct || svgalib_backgrounded
|| !vga_oktowrite ())return;
if (vid.aspect > 1.5) {
reps = 2;
repshift = 1;
} else {
reps = 1;
repshift = 0;
}
vidpage = 0;
vga_setpage (0);
if (VGA_planar) {
for (plane = 0; plane < 4; plane++) {
/* Select the correct plane for writing */
outb (2, 0x3C4);
outb (1 << plane, 0x3C5);
outb (4, 0x3CE);
outb (plane, 0x3CF);
for (i = 0; i < (height << repshift); i += reps) {
for (k = 0; k < reps; k++) {
for (j = 0; j < (width >> 2); j++) {
vid.direct[(y + i + k) * VGA_rowbytes + (x >> 2) + j] =
backingbuf[(i + k) * 24 + (j << 2) + plane];
}
}
}
}
} else {
for (i = 0; i < (height << repshift); i += reps) {
for (j = 0; j < reps; j++) {
offset = x + ((y << repshift) + i + j)
* vid.rowbytes;
off = offset % 0x10000;
if ((offset / 0x10000) != vidpage) {
vidpage = offset / 0x10000;
vga_setpage (vidpage);
}
memcpy (vid.direct + off, &backingbuf[(i + j) * 24], width);
}
}
}
}
#if 0
static void
VID_Gamma_f (void)
{
float gamma, f, inf;
unsigned char palette[768];
int i;
if (Cmd_Argc () == 2) {
gamma = atof (Cmd_Argv (1));
for (i = 0; i < 768; i++) {
f = pow ((host_basepal[i] + 1) / 256.0, gamma);
inf = f * 255 + 0.5;
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
palette[i] = inf;
}
VID_SetPalette (palette);
/* Force a surface cache flush */
vid.recalc_refdef = 1;
}
}
#endif
static void
VID_DescribeMode_f (void)
{
int modenum;
modenum = atoi (Cmd_Argv (1));
if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width) {
Con_Printf ("Invalid video mode: %d!\n", modenum);
}
Con_Printf ("%d: %d x %d - ", modenum,
modes[modenum].width, modes[modenum].height);
if (modes[modenum].bytesperpixel == 0) {
Con_Printf ("ModeX\n");
} else {
Con_Printf ("%d bpp\n", modes[modenum].bytesperpixel << 3);
}
}
static void
VID_DescribeModes_f (void)
{
int i;
for (i = 0; i < num_modes; i++) {
if (modes[i].width) {
Con_Printf ("%d: %d x %d - ", i, modes[i].width, modes[i].height);
if (modes[i].bytesperpixel == 0)
Con_Printf ("ModeX\n");
else
Con_Printf ("%d bpp\n", modes[i].bytesperpixel << 3);
}
}
}
/*
VID_NumModes
*/
static int
VID_NumModes (void)
{
int i, i1 = 0;
for (i = 0; i < num_modes; i++) {
i1 += modes[i].width ? 1 : 0;
}
return (i1);
}
static void
VID_NumModes_f (void)
{
Con_Printf ("%d modes\n", VID_NumModes ());
}
static void
VID_Debug_f (void)
{
Con_Printf ("mode: %d\n", current_mode);
Con_Printf ("height x width: %d x %d\n", vid.height, vid.width);
Con_Printf ("bpp: %d\n", modes[current_mode].bytesperpixel * 8);
Con_Printf ("vid.aspect: %f\n", vid.aspect);
}
static void
VID_InitModes (void)
{
int i;
/* Get complete information on all modes */
num_modes = vga_lastmodenumber () + 1;
modes = malloc (num_modes * sizeof (vga_modeinfo));
for (i = 0; i < num_modes; i++) {
if (vga_hasmode (i)) {
memcpy (&modes[i], vga_getmodeinfo (i), sizeof (vga_modeinfo));
} else {
modes[i].width = 0; // means not available
}
}
/* Filter for modes we don't support */
for (i = 0; i < num_modes; i++) {
if (modes[i].bytesperpixel != 1 && modes[i].colors != 256) {
modes[i].width = 0;
}
}
}
static int
get_mode (char *name, int width, int height, int depth)
{
int i, ok, match;
match = (!!width) + (!!height) * 2 + (!!depth) * 4;
if (name) {
i = vga_getmodenumber (name);
if (!modes[i].width) {
Sys_Printf ("Mode [%s] not supported\n", name);
i = G320x200x256;
}
} else {
for (i = 0; i < num_modes; i++) {
if (modes[i].width) {
ok = (modes[i].width == width)
+ (modes[i].height == height) * 2
+ (modes[i].bytesperpixel == depth / 8) * 4;
if ((ok & match) == ok)
break;
}
}
if (i == num_modes) {
Sys_Printf ("Mode %dx%d (%d bits) not supported\n",
width, height, depth);
i = G320x200x256;
}
}
return i;
}
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize;
void *vid_surfcache;
// Calculate the sizes we want first
buffersize = vid.rowbytes * vid.height;
zbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
cachesize = D_SurfaceCacheForRes (vid.width, vid.height);
// Free the old screen buffer
if (vid.buffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
}
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new screen buffer
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
if (!vid.conbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new z-buffer
d_pzbuffer = calloc (zbuffersize, 1);
if (!d_pzbuffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (cachesize, 1);
if (!vid_surfcache) {
free (vid.buffer);
free (d_pzbuffer);
vid.conbuffer = vid.buffer = NULL;
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, cachesize);
}
void
VID_Shutdown (void)
{
Sys_Printf ("VID_Shutdown\n");
if (!svgalib_inited)
return;
if (UseDisplay) {
vga_setmode (TEXT);
}
svgalib_inited = 0;
}
void
VID_ShiftPalette (unsigned char *p)
{
VID_SetPalette (p);
}
void
VID_SetPalette (byte * palette)
{
static int tmppal[256 * 3];
int *tp;
int i;
if (!svgalib_inited || svgalib_backgrounded)
return;
memcpy (vid_current_palette, palette, sizeof (vid_current_palette));
if (vga_getcolors () == 256) {
tp = tmppal;
for (i = 256 * 3; i; i--) {
*(tp++) = *(palette++) >> 2;
}
if (UseDisplay && vga_oktowrite ()) {
vga_setpalvec (0, 256, tmppal);
}
}
}
int
VID_SetMode (int modenum, unsigned char *palette)
{
int err;
if ((modenum >= num_modes) || (modenum < 0) || !modes[modenum].width) {
Cvar_SetValue (vid_mode, current_mode);
Con_Printf ("No such video mode: %d\n", modenum);
return 0;
}
Cvar_SetValue (vid_mode, modenum);
current_mode = modenum;
vid.width = modes[current_mode].width;
vid.height = modes[current_mode].height;
VGA_width = modes[current_mode].width;
VGA_height = modes[current_mode].height;
VGA_planar = modes[current_mode].bytesperpixel == 0;
VGA_rowbytes = modes[current_mode].linewidth;
vid.rowbytes = modes[current_mode].linewidth;
if (VGA_planar) {
VGA_bufferrowbytes = modes[current_mode].linewidth * 4;
vid.rowbytes = modes[current_mode].linewidth * 4;
}
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
vid.colormap = (pixel_t *) host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.numpages = 1;
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
// alloc screen buffer, z-buffer, and surface cache
VID_InitBuffers ();
/* get goin' */
err = vga_setmode (current_mode);
if (err) {
Sys_Error ("Video mode failed: %d\n", modenum);
}
VID_SetPalette (palette);
VGA_pagebase = vid.direct = framebuffer_ptr = (char *) vga_getgraphmem ();
#if 0
if (vga_setlinearaddressing () > 0) {
framebuffer_ptr = (char *) vga_getgraphmem ();
}
#endif
if (!framebuffer_ptr) {
Sys_Error ("This mode isn't hapnin'\n");
}
vga_setpage (0);
svgalib_inited = 1;
/* Force a surface cache flush */
vid.recalc_refdef = 1;
return 1;
}
static void
goto_background (void)
{
svgalib_backgrounded = 1;
}
static void
comefrom_background (void)
{
svgalib_backgrounded = 0;
}
void
VID_Init (unsigned char *palette)
{
int w, h, d;
int err;
// plugin_load("in_svgalib.so");
if (svgalib_inited)
return;
#if 0
Cmd_AddCommand ("gamma", VID_Gamma_f, "Brightness level");
#endif
if (UseDisplay) {
err = vga_init ();
if (err)
Sys_Error ("SVGALib failed to allocate a new VC\n");
if (vga_runinbackground_version () == 1) {
Con_Printf ("SVGALIB background support detected\n");
vga_runinbackground (VGA_GOTOBACK, goto_background);
vga_runinbackground (VGA_COMEFROMBACK, comefrom_background);
vga_runinbackground (1);
} else {
vga_runinbackground (0);
}
VID_InitModes ();
Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, "Reports the total number of video modes available.");
Cmd_AddCommand ("vid_describemode", VID_DescribeMode_f, "Report information on specified video mode, default is current.\n"
"(vid_describemode (mode))");
Cmd_AddCommand ("vid_describemodes", VID_DescribeModes_f, "Report information on all video modes.");
Cmd_AddCommand ("vid_debug", VID_Debug_f, "FIXME: No Description");
/* Interpret command-line params */
w = h = d = 0;
if (getenv ("GSVGAMODE")) {
current_mode = get_mode (getenv ("GSVGAMODE"), w, h, d);
} else if (COM_CheckParm ("-mode")) {
current_mode =
get_mode (com_argv[COM_CheckParm ("-mode") + 1], w, h, d);
} else if (COM_CheckParm ("-w") || COM_CheckParm ("-h")
|| COM_CheckParm ("-d")) {
if (COM_CheckParm ("-w")) {
w = atoi (com_argv[COM_CheckParm ("-w") + 1]);
}
if (COM_CheckParm ("-h")) {
h = atoi (com_argv[COM_CheckParm ("-h") + 1]);
}
if (COM_CheckParm ("-d")) {
d = atoi (com_argv[COM_CheckParm ("-d") + 1]);
}
current_mode = get_mode (0, w, h, d);
} else {
current_mode = G320x200x256;
}
/* Set vid parameters */
VID_SetMode (current_mode, palette);
Con_CheckResize (); // Now that we have a window size, fix console
VID_SetPalette (palette);
}
}
void
VID_Init_Cvars ()
{
vid_mode = Cvar_Get ("vid_mode", "5", CVAR_NONE, NULL,
"Sets the video mode");
vid_redrawfull = Cvar_Get ("vid_redrawfull", "0", CVAR_NONE, NULL,
"Redraw entire screen each frame instead of just dirty areas");
vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh", "0", CVAR_ARCHIVE,
NULL, "Wait for vertical retrace before drawing next frame");
vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL,
"Use system gamma control if available");
}
void
VID_Update (vrect_t *rects)
{
if (!svgalib_inited || svgalib_backgrounded)
return;
if (!vga_oktowrite ()) {
/* Can't update screen if it's not active */
return;
}
if (vid_waitforrefresh->int_val) {
vga_waitretrace ();
}
if (VGA_planar) {
VGA_UpdatePlanarScreen (vid.buffer);
} else if (vid_redrawfull->int_val) {
int total = vid.rowbytes * vid.height;
int offset;
for (offset = 0; offset < total; offset += 0x10000) {
vga_setpage (offset / 0x10000);
memcpy (framebuffer_ptr, vid.buffer + offset,
((total - offset > 0x10000) ? 0x10000 : (total - offset)));
}
} else {
int ycount;
int offset;
int vidpage = 0;
vga_setpage (0);
while (rects) {
ycount = rects->height;
offset = rects->y * vid.rowbytes + rects->x;
while (ycount--) {
register int i = offset % 0x10000;
if ((offset / 0x10000) != vidpage) {
vidpage = offset / 0x10000;
vga_setpage (vidpage);
}
if (rects->width + i > 0x10000) {
memcpy (framebuffer_ptr + i,
vid.buffer + offset, 0x10000 - i);
vga_setpage (++vidpage);
memcpy (framebuffer_ptr,
vid.buffer + offset + 0x10000 - i,
rects->width - 0x10000 + i);
} else {
memcpy (framebuffer_ptr + i,
vid.buffer + offset, rects->width);
}
offset += vid.rowbytes;
}
rects = rects->pnext;
}
}
if (vid_mode->int_val != current_mode) {
VID_SetMode (vid_mode->int_val, vid_current_palette);
}
}
static int dither = 0;
void
VID_DitherOn (void)
{
if (dither == 0) {
#if 0
R_ViewChanged (&vrect, sb_lines, vid.aspect);
#endif
dither = 1;
}
}
void
VID_DitherOff (void)
{
if (dither) {
#if 0
R_ViewChanged (&vrect, sb_lines, vid.aspect);
#endif
dither = 0;
}
}
/*
VID_ModeInfo
*/
char *
VID_ModeInfo (int modenum)
{
static char *badmodestr = "Bad mode number";
static char modestr[40];
if (modenum == 0) {
snprintf (modestr, sizeof (modestr), "%d x %d, %d bpp",
vid.width, vid.height, modes[current_mode].bytesperpixel * 8);
return (modestr);
} else {
return (badmodestr);
}
}
void
VID_ExtraOptionDraw (unsigned int options_draw_cursor)
{
/* No extra option menu items yet */
}
void
VID_ExtraOptionCmd (int option_cursor)
{
#if 0
switch (option_cursor) {
case 1: // Always start with 1
break;
}
#endif
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
}
qboolean
VID_SetGamma (double gamma)
{
return false; //FIXME
}

File diff suppressed because it is too large Load diff

View file

@ -1,798 +0,0 @@
/*
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
$Id$
*/
#define _BSD
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#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 <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h>
#ifdef HAVE_VIDMODE
# include <X11/extensions/xf86vmode.h>
#endif
#include "QF/cmd.h"
#include "QF/compat.h"
#include "QF/console.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 "screen.h"
extern viddef_t vid; // global video state
unsigned short d_8to16table[256];
static Colormap x_cmap;
static GC x_gc;
int XShmQueryExtension (Display *);
int XShmGetEventBase (Display *);
static qboolean doShm;
static XShmSegmentInfo x_shminfo[2];
static int current_framebuffer;
static XImage *x_framebuffer[2] = { 0, 0 };
static int verbose = 0;
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 unsigned long r_mask, g_mask, b_mask;
cvar_t *vid_width;
cvar_t *vid_height;
static void
shiftmask_init (void)
{
unsigned int x;
r_mask = x_vis->red_mask;
g_mask = x_vis->green_mask;
b_mask = x_vis->blue_mask;
for (r_shift = -8, x = 1; x < r_mask; x <<= 1)
r_shift++;
for (g_shift = -8, x = 1; x < g_mask; x <<= 1)
g_shift++;
for (b_shift = -8, x = 1; x < b_mask; x <<= 1)
b_shift++;
shiftmask_fl = 1;
}
static PIXEL16
xlib_rgb16 (int r, int g, int b)
{
PIXEL16 p = 0;
if (!shiftmask_fl)
shiftmask_init ();
if (r_shift > 0) {
p = (r << (r_shift)) & r_mask;
} else {
if (r_shift < 0) {
p = (r >> (-r_shift)) & r_mask;
} else {
p |= (r & r_mask);
}
}
if (g_shift > 0) {
p |= (g << (g_shift)) & g_mask;
} else {
if (g_shift < 0) {
p |= (g >> (-g_shift)) & g_mask;
} else {
p |= (g & g_mask);
}
}
if (b_shift > 0) {
p |= (b << (b_shift)) & b_mask;
} else {
if (b_shift < 0) {
p |= (b >> (-b_shift)) & b_mask;
} else {
p |= (b & b_mask);
}
}
return p;
}
static PIXEL24
xlib_rgb24 (int r, int g, int b)
{
PIXEL24 p = 0;
if (!shiftmask_fl)
shiftmask_init ();
if (r_shift > 0) {
p = (r << (r_shift)) & r_mask;
} else {
if (r_shift < 0) {
p = (r >> (-r_shift)) & r_mask;
} else {
p |= (r & r_mask);
}
}
if (g_shift > 0) {
p |= (g << (g_shift)) & g_mask;
} else {
if (g_shift < 0) {
p |= (g >> (-g_shift)) & g_mask;
} else {
p |= (g & g_mask);
}
}
if (b_shift > 0) {
p |= (b << (b_shift)) & b_mask;
} else {
if (b_shift < 0) {
p |= (b >> (-b_shift)) & b_mask;
} else {
p |= (b & b_mask);
}
}
return p;
}
static void
st2_fixup (XImage *framebuf, int x, int y, int width, int height)
{
int xi, yi;
unsigned char *src;
PIXEL16 *dest;
if (x < 0 || y < 0)
return;
for (yi = y; yi < (y + height); yi++) {
src = &framebuf->data[yi * framebuf->bytes_per_line];
dest = (PIXEL16 *) src;
for (xi = (x + width - 1); xi >= x; xi--) {
dest[xi] = st2d_8to16table[src[xi]];
}
}
}
static void
st3_fixup (XImage * framebuf, int x, int y, int width, int height)
{
int yi;
unsigned char *src;
PIXEL24 *dest;
register int count, n;
if (x < 0 || y < 0)
return;
for (yi = y; yi < (y + height); yi++) {
src = &framebuf->data[yi * framebuf->bytes_per_line];
// Duff's Device
count = width;
n = (count + 7) / 8;
dest = ((PIXEL24 *) src) + x + width - 1;
src += x + width - 1;
switch (count % 8) {
case 0:
do {
*dest-- = st2d_8to24table[*src--];
case 7:
*dest-- = st2d_8to24table[*src--];
case 6:
*dest-- = st2d_8to24table[*src--];
case 5:
*dest-- = st2d_8to24table[*src--];
case 4:
*dest-- = st2d_8to24table[*src--];
case 3:
*dest-- = st2d_8to24table[*src--];
case 2:
*dest-- = st2d_8to24table[*src--];
case 1:
*dest-- = st2d_8to24table[*src--];
} while (--n > 0);
}
// for(xi = (x+width-1); xi >= x; xi--) {
// dest[xi] = st2d_8to16table[src[xi]];
// }
}
}
/*
D_BeginDirectRect
*/
void
D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{
// direct drawing of the "accessing disk" icon isn't supported
}
/*
D_EndDirectRect
*/
void
D_EndDirectRect (int x, int y, int width, int height)
{
// direct drawing of the "accessing disk" icon isn't supported
}
static void
ResetFrameBuffer (void)
{
int tbuffersize, tcachesize;
void *vid_surfcache;
int mem, pwidth;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
if (x_framebuffer[0]) {
XDestroyImage (x_framebuffer[0]);
}
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, tcachesize);
pwidth = x_visinfo->depth / 8;
if (pwidth == 3)
pwidth = 4;
mem = ((vid.width * pwidth + 7) & ~7) * vid.height;
x_framebuffer[0] = XCreateImage (x_disp, x_vis, x_visinfo->depth,
ZPixmap, 0, malloc (mem), vid.width,
vid.height, 32, 0);
if (!x_framebuffer[0]) {
Sys_Error ("VID: XCreateImage failed\n");
}
}
static void
ResetSharedFrameBuffers (void)
{
int tbuffersize, tcachesize;
void *vid_surfcache;
int size;
int key;
int minsize = getpagesize ();
int frm;
// Calculate the sizes we want first
tbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
tcachesize = D_SurfaceCacheForRes (vid.width, vid.height);
// Free the old z-buffer
if (d_pzbuffer) {
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// Free the old surface cache
vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) {
D_FlushCaches ();
free (vid_surfcache);
vid_surfcache = NULL;
}
// Allocate the new z-buffer
d_pzbuffer = calloc (tbuffersize, 1);
if (!d_pzbuffer) {
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (tcachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
D_InitCaches (vid_surfcache, tcachesize);
for (frm = 0; frm < 2; frm++) {
// free up old frame buffer memory
if (x_framebuffer[frm]) {
XShmDetach (x_disp, &x_shminfo[frm]);
free (x_framebuffer[frm]);
shmdt (x_shminfo[frm].shmaddr);
}
// create the image
x_framebuffer[frm] = XShmCreateImage (x_disp, x_vis, x_visinfo->depth,
ZPixmap, 0, &x_shminfo[frm],
vid.width, vid.height);
// grab shared memory
size = x_framebuffer[frm]->bytes_per_line * x_framebuffer[frm]->height;
if (size < minsize)
Sys_Error ("VID: Window must use at least %d bytes\n", minsize);
key = random ();
x_shminfo[frm].shmid = shmget ((key_t) key, size, IPC_CREAT | 0777);
if (x_shminfo[frm].shmid == -1)
Sys_Error ("VID: Could not get any shared memory\n");
// attach to the shared memory segment
x_shminfo[frm].shmaddr = (void *) shmat (x_shminfo[frm].shmid, 0, 0);
printf ("VID: shared memory id=%d, addr=0x%lx\n", x_shminfo[frm].shmid,
(long) x_shminfo[frm].shmaddr);
x_framebuffer[frm]->data = x_shminfo[frm].shmaddr;
// get the X server to attach to it
if (!XShmAttach (x_disp, &x_shminfo[frm]))
Sys_Error ("VID: XShmAttach() failed\n");
XSync (x_disp, 0);
shmctl (x_shminfo[frm].shmid, IPC_RMID, 0);
}
}
static void
event_shm (XEvent * event)
{
if (doShm)
oktodraw = true;
}
/*
VID_Init
Set up color translation tables and the window. Takes a 256-color 8-bit
palette. Palette data will go away after the call, so copy it if you'll
need it later.
*/
void
VID_Init (unsigned char *palette)
{
int pnum, i;
XVisualInfo template;
int num_visuals;
int template_mask;
VID_GetWindowSize (320, 200);
vid.width = vid_width->int_val;
vid.height = vid_height->int_val;
Con_CheckResize (); // Now that we have a window size, fix console
vid.maxwarpwidth = WARP_WIDTH;
vid.maxwarpheight = WARP_HEIGHT;
vid.numpages = 2;
vid.colormap = host_colormap;
vid.fullbright = 256 - LittleLong (*((int *) vid.colormap + 2048));
srandom (getpid ());
verbose = COM_CheckParm ("-verbose");
// open the display
X11_OpenDisplay ();
template_mask = 0;
// specify a visual id
if ((pnum = COM_CheckParm ("-visualid"))) {
if (pnum >= com_argc - 1)
Sys_Error ("VID: -visualid <id#>\n");
template.visualid = atoi (com_argv[pnum + 1]);
template_mask = VisualIDMask;
} else { // If not specified, use default
// visual
template.visualid =
XVisualIDFromVisual (XDefaultVisual (x_disp, x_screen));
template_mask = VisualIDMask;
}
// pick a visual -- warn if more than one was available
x_visinfo = XGetVisualInfo (x_disp, template_mask, &template, &num_visuals);
x_vis = x_visinfo->visual;
if (num_visuals > 1) {
printf ("Found more than one visual id at depth %d:\n", template.depth);
for (i = 0; i < num_visuals; i++)
printf (" -visualid %d\n", (int) x_visinfo[i].visualid);
} else {
if (num_visuals == 0) {
if (template_mask == VisualIDMask) {
Sys_Error ("VID: Bad visual ID %ld\n", template.visualid);
} else {
Sys_Error ("VID: No visuals at depth %d\n", template.depth);
}
}
}
if (verbose) {
printf ("Using visualid %d:\n", (int) x_visinfo->visualid);
printf (" class %d\n", x_visinfo->class);
printf (" screen %d\n", x_visinfo->screen);
printf (" depth %d\n", x_visinfo->depth);
printf (" red_mask 0x%x\n", (int) x_visinfo->red_mask);
printf (" green_mask 0x%x\n", (int) x_visinfo->green_mask);
printf (" blue_mask 0x%x\n", (int) x_visinfo->blue_mask);
printf (" colormap_size %d\n", x_visinfo->colormap_size);
printf (" bits_per_rgb %d\n", x_visinfo->bits_per_rgb);
}
/* Setup attributes for main window */
X11_SetVidMode (vid.width, vid.height);
/* Create the main window */
X11_CreateWindow (vid.width, vid.height);
/* Invisible cursor */
X11_CreateNullCursor ();
VID_InitGamma (palette);
VID_SetPalette (palette);
if (x_visinfo->depth == 8) {
/* Create and upload the palette */
if (x_visinfo->class == PseudoColor) {
x_cmap = XCreateColormap (x_disp, x_win, x_vis, AllocAll);
VID_SetPalette (palette);
XSetWindowColormap (x_disp, x_win, x_cmap);
}
}
// create the GC
{
XGCValues xgcvalues;
int valuemask = GCGraphicsExposures;
xgcvalues.graphics_exposures = False;
x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues);
}
X11_GrabKeyboard ();
// wait for first exposure event
{
XEvent event;
do {
XNextEvent (x_disp, &event);
if (event.type == Expose && !event.xexpose.count)
oktodraw = true;
} while (!oktodraw);
}
// now safe to draw
// even if MITSHM is available, make sure it's a local connection
if (XShmQueryExtension (x_disp)) {
char *displayname;
char *d;
doShm = true;
if ((displayname = XDisplayName (NULL))) {
if ((d = strchr (displayname, ':')))
*d = '\0';
if (!(!strcasecmp (displayname, "unix") || !*displayname))
doShm = false;
}
}
if (doShm) {
x_shmeventtype = XShmGetEventBase (x_disp) + ShmCompletion;
ResetSharedFrameBuffers ();
} else {
ResetFrameBuffer ();
}
current_framebuffer = 0;
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
vid.buffer = x_framebuffer[0]->data;
vid.direct = 0;
vid.conbuffer = x_framebuffer[0]->data;
vid.conrowbytes = vid.rowbytes;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
// XSynchronize (x_disp, False);
X11_AddEvent (x_shmeventtype, event_shm);
}
void
VID_Init_Cvars ()
{
X11_Init_Cvars ();
}
void
VID_ShiftPalette (unsigned char *p)
{
VID_SetPalette (p);
}
void
VID_SetPalette (unsigned char *palette)
{
int i;
XColor colors[256];
for (i = 0; i < 256; i++) {
st2d_8to16table[i] = xlib_rgb16 (palette[i * 3], palette[i * 3 + 1],
palette[i * 3 + 2]);
st2d_8to24table[i] = xlib_rgb24 (palette[i * 3], palette[i * 3 + 1],
palette[i * 3 + 2]);
}
if (x_visinfo->class == PseudoColor && x_visinfo->depth == 8) {
if (palette != current_palette) {
memcpy (current_palette, palette, 768);
}
for (i = 0; i < 256; i++) {
colors[i].pixel = i;
colors[i].flags = DoRed | DoGreen | DoBlue;
colors[i].red = gammatable[(byte) palette[(i * 3)]];
colors[i].green = gammatable[(byte) palette[(i * 3) + 1]];
colors[i].blue = gammatable[(byte) palette[(i * 3) + 2]];
}
XStoreColors (x_disp, x_cmap, colors, 256);
}
}
/*
VID_Shutdown
Restore video mode
*/
void
VID_Shutdown (void)
{
Sys_Printf ("VID_Shutdown\n");
if (x_disp) {
X11_RestoreVidMode ();
X11_CloseDisplay ();
}
}
static int config_notify = 0;
static int config_notify_width;
static int config_notify_height;
/*
VID_Update
Flush the given rectangles from the view buffer to the screen.
*/
void
VID_Update (vrect_t *rects)
{
/* If the window changes dimension, skip this frame. */
if (config_notify) {
fprintf (stderr, "config notify\n");
config_notify = 0;
vid.width = config_notify_width & ~7;
vid.height = config_notify_height;
if (doShm)
ResetSharedFrameBuffers ();
else
ResetFrameBuffer ();
vid.rowbytes = x_framebuffer[0]->bytes_per_line;
vid.buffer = x_framebuffer[current_framebuffer]->data;
vid.conbuffer = vid.buffer;
vid.conwidth = vid.width;
vid.conheight = vid.height;
vid.conrowbytes = vid.rowbytes;
vid.recalc_refdef = 1; /* force a surface cache flush */
Con_CheckResize ();
Con_Clear_f ();
return;
}
while (rects) {
switch (x_visinfo->depth) {
case 16:
st2_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->height);
break;
case 24:
st3_fixup (x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->width, rects->height);
break;
}
if (doShm) {
if (!XShmPutImage (x_disp, x_win, x_gc,
x_framebuffer[current_framebuffer],
rects->x, rects->y, rects->x, rects->y,
rects->width, rects->height, True)) {
Sys_Error ("VID_Update: XShmPutImage failed\n");
}
oktodraw = false;
while (!oktodraw)
X11_ProcessEvent ();
rects = rects->pnext;
current_framebuffer = !current_framebuffer;
vid.buffer = x_framebuffer[current_framebuffer]->data;
vid.conbuffer = vid.buffer;
} else {
if (!XPutImage (x_disp, x_win, x_gc, x_framebuffer[0],
rects->x, rects->y, rects->x, rects->y,
rects->width, rects->height)) {
Sys_Error ("VID_Update: XPutImage failed\n");
}
rects = rects->pnext;
}
}
XSync (x_disp, False);
scr_fullupdate = 0;
}
static qboolean dither;
void
VID_DitherOn (void)
{
if (!dither) {
vid.recalc_refdef = 1;
dither = true;
}
}
void
VID_DitherOff (void)
{
if (dither) {
vid.recalc_refdef = 1;
dither = false;
}
}
void
VID_LockBuffer (void)
{
}
void
VID_UnlockBuffer (void)
{
}
void
VID_SetCaption (char *text)
{
if (text && *text) {
char *temp = strdup (text);
X11_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp));
free (temp);
} else {
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
}
}
double
VID_GetGamma (void)
{
return (double) X11_GetGamma ();
}
qboolean
VID_SetGamma (double gamma)
{
return X11_SetGamma (gamma);
}