First stage of video and input system merge. The city has collapsed, wreckage sifting ensues...

This commit is contained in:
Ragnvald Maartmann-Moe IV 2001-04-15 04:18:22 +00:00
parent bd0fab4ce1
commit 66fafd3e0e
91 changed files with 20971 additions and 1214 deletions

View file

@ -1258,7 +1258,8 @@ fi
dnl We want warnings, lots of warnings...
if test "x$GCC" = xyes; then
CFLAGS="$CFLAGS -Wall -Werror"
CFLAGS="$CFLAGS -Wall"
# CFLAGS="$CFLAGS -Wall -Werror"
# CFLAGS="$CFLAGS -Wall -pedantic"
fi

View file

@ -34,6 +34,10 @@
#define VID_CBITS 6
#define VID_GRADES (1 << VID_CBITS)
struct cvar_s;
extern byte *vid_basepal;
extern byte *vid_colormap;
typedef struct vrect_s {
int x,y,width,height;
struct vrect_s *pnext;

View file

@ -1,8 +1,10 @@
INCLUDES= -I$(top_srcdir)/include
lib_LTLIBRARIES = libQFjs.la
lib_LTLIBRARIES = libQFjs.la libQFfbdev.la libQFmgl.la libQFsdl.la \
libQFsvga.la libQFx11.la libQFglx.la libQFsgl.la \
libQFtdfx.la libQFwgl.la
libQFjs_la_LDFLAGS = -version-info 1:0:0 $(CD_LIBS)
libQFjs_la_LDFLAGS= -version-info 1:0:0
if JOYTYPE_LINUX
libQFjs_la_SOURCES= joy.c joy_linux.c
@ -15,4 +17,34 @@ libQFjs_la_SOURCES= joy.c joy_null.c
endif
libQFjs_la_CFLAGS= $(JOY_CFLAGS)
LIBLIST = libQFjs.la @LIBRARY_SEARCH_PATH@
# Linux FBdev
YFLAGS = -d
libQFfbdev_la_LDFLAGS= -version-info 1:0:0
libQFfbdev_la_SOURCES= fbset.c fbset_modes_y.y fbset_modes_l.l vid_fbdev.c in_fbdev.c
YACCLEX_CLEANFILES= fbset_modes_y.c fbset_modes_y.h fbset_modes_y.tab.h fbset_modes_l.c
EXTRA_libQFfbdev_la_SOURCES=fbset_modes_y.h
fbset_modes_y.o: fbset_modes_y.c
$(COMPILE) -Wno-error -c fbset_modes_y.c
fbset_modes_l.o: fbset_modes_l.c
$(COMPILE) -Wno-error -c fbset_modes_l.c
##libQFmgl_la_LDFLAGS= -version-info 1:0:0
##libQFmgl_la_SOURCES= in_win.c vid_common_sw.c vid_mgl.c
libQFsdl_la_LDFLAGS= -version-info 1:0:0
libQFsdl_la_SOURCES= in_sdl.c vid_common_sw.c vid_sdl.c
libQFsvga_la_LDFLAGS= -version-info 1:0:0
libQFsvga_la_SOURCES= d_copy.S in_svgalib.c vid_common_sw.c vid_svgalib.c
libQFx11_la_LDFLAGS= -version-info 1:0:0
libQFx11_la_SOURCES= in_x11.c context_x11.c dga_check.c vid_common_sw.c vid_x11.c
libQFglx_la_LDFLAGS= -version-info 1:0:0
libQFglx_la_SOURCES= in_x11.c context_x11.c dga_check.c vid_common_gl.c vid_glx.c
libQFsgl_la_LDFLAGS= -version-info 1:0:0
libQFsgl_la_SOURCES= in_sdl.c vid_common_gl.c vid_sgl.c
libQFtdfx_la_LDFLAGS= -version-info 1:0:0
libQFtdfx_la_SOURCES= in_svgalib.c vid_common_gl.c vid_3dfxsvga.c
##libQFwgl_la_LDFLAGS= -version-info 1:0:0
##libQFwgl_la_SOURCES= in_win.c vid_wgl.c
LIBLIST = $(lib_LTLIBRARIES) @LIBRARY_SEARCH_PATH@

View file

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

@ -0,0 +1,152 @@
/*
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
}

1071
libs/video/targets/fbset.c Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,138 @@
/*
* 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);
}
%%

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,26 @@
#ifndef YYSTYPE
#define YYSTYPE int
#endif
#define MODE 257
#define GEOMETRY 258
#define TIMINGS 259
#define HSYNC 260
#define VSYNC 261
#define CSYNC 262
#define GSYNC 263
#define EXTSYNC 264
#define BCAST 265
#define LACED 266
#define DOUBLE 267
#define RGBA 268
#define NONSTD 269
#define ACCEL 270
#define GRAYSCALE 271
#define ENDMODE 272
#define POLARITY 273
#define BOOLEAN 274
#define STRING 275
#define NUMBER 276
extern YYSTYPE yylval;

View file

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

@ -309,7 +309,7 @@ IN_MouseMove (void)
if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
if (in_strafe.state & 1)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;

View file

@ -0,0 +1,151 @@
/*
in_fbdev.c
fix this!
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_UNISTD_H
# include <unistd.h>
#endif
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "QF/cvar.h"
#include "QF/keys.h"
cvar_t *_windowed_mouse;
int
fd_blocking (int fd, int on)
{
int x;
#if defined(_POSIX_SOURCE) || !defined(FIONBIO)
#if !defined(O_NONBLOCK)
# if defined(O_NDELAY)
# define O_NONBLOCK O_NDELAY
# endif
#endif
if ((x = fcntl(fd, F_GETFL, 0)) == -1)
return -1;
if (on)
x &= ~O_NONBLOCK;
else
x |= O_NONBLOCK;
return fcntl(fd, F_SETFL, x);
#else
x = !on;
return ioctl(fd, FIONBIO, &x);
#endif
}
static struct termios old_tty, new_tty;
static int tty_fd = 0;
void
IN_Init (void)
{
fd_blocking(0, 0);
tcgetattr(tty_fd, &old_tty);
new_tty = old_tty;
new_tty.c_cc[VMIN] = 1;
new_tty.c_cc[VTIME] = 0;
new_tty.c_lflag &= ~ICANON;
new_tty.c_iflag &= ~IXON;
tcsetattr(tty_fd, TCSADRAIN, &new_tty);
}
void
IN_Init_Cvars (void)
{
}
void
IN_Shutdown (void)
{
}
void
IN_SendKeyEvents (void)
{
int k, down;
char buf[4];
if (read(0, buf, 1) == 1) {
k = buf[0];
switch (k) {
case '\r':
case '\n':
k = K_ENTER;
break;
case '\033':
if (read(0, buf, 2) != 2)
break;
switch (buf[1]) {
case 'A':
k = K_UPARROW;
break;
case 'B':
k = K_DOWNARROW;
break;
case 'C':
k = K_RIGHTARROW;
break;
case 'D':
k = K_LEFTARROW;
break;
}
break;
}
down = 1;
Key_Event(k, -1, down);
Key_Event(k, -1, !down);
}
}
void
IN_Commands (void)
{
}
void
IN_Move (void)
{
}
/*
IN_ModeChanged
*/
void
IN_ModeChanged (void)
{
}

View file

@ -1,7 +1,7 @@
/*
sbar.h
in_null.c
@description@
for systems without a mouse
Copyright (C) 1996-1997 Id Software, Inc.
@ -26,23 +26,39 @@
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
// the status bar is only redrawn if something has changed, but if anything
// does, the entire thing will be redrawn for the next vid.numpages frames.
void
IN_Init (void)
{
}
#define SBAR_HEIGHT 24
void
IN_Init_Cvars (void)
{
}
extern int sb_lines; // scan lines to draw
void
IN_Shutdown (void)
{
}
void Sbar_Init (void);
void
IN_Commands (void)
{
}
void Sbar_Changed (void);
// call whenever any of the client stats represented on the sbar changes
void
IN_Move (usercmd_t *cmd)
{
}
void Sbar_Draw (void);
// called every frame by screen
void Sbar_IntermissionOverlay (void);
// called each frame after the level has been completed
void Sbar_FinaleOverlay (void);
/*
IN_ModeChanged
*/
void
IN_ModeChanged (void)
{
}

432
libs/video/targets/in_sdl.c Normal file
View file

@ -0,0 +1,432 @@
/*
in_sdl.c
general sdl input driver
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <SDL.h>
#include "client.h"
#include "cl_input.h"
#include "cl_main.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "draw.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/sys.h"
#include "QF/qargs.h"
#include "QF/qendian.h"
#include "view.h" // FIXME: probable evil
#ifdef WIN32
// FIXME: this is evil...
# include <windows.h>
HWND mainwindow;
#endif
cvar_t *m_filter;
cvar_t *_windowed_mouse;
int old_windowed_mouse;
int modestate; // FIXME: just to avoid cross-comp.
// errors - remove later
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int mouse_oldbuttonstate = 0;
extern viddef_t vid; // global video state
/*
IN_SendKeyEvents
*/
void
IN_SendKeyEvents (void)
{
SDL_Event event;
int sym, state, but;
int modstate;
while (SDL_PollEvent (&event)) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
sym = event.key.keysym.sym;
state = event.key.state;
modstate = SDL_GetModState ();
switch (sym) {
case SDLK_DELETE:
sym = K_DEL;
break;
case SDLK_BACKSPACE:
sym = K_BACKSPACE;
break;
case SDLK_F1:
sym = K_F1;
break;
case SDLK_F2:
sym = K_F2;
break;
case SDLK_F3:
sym = K_F3;
break;
case SDLK_F4:
sym = K_F4;
break;
case SDLK_F5:
sym = K_F5;
break;
case SDLK_F6:
sym = K_F6;
break;
case SDLK_F7:
sym = K_F7;
break;
case SDLK_F8:
sym = K_F8;
break;
case SDLK_F9:
sym = K_F9;
break;
case SDLK_F10:
sym = K_F10;
break;
case SDLK_F11:
sym = K_F11;
break;
case SDLK_F12:
sym = K_F12;
break;
case SDLK_BREAK:
case SDLK_PAUSE:
sym = K_PAUSE;
break;
case SDLK_UP:
sym = K_UPARROW;
break;
case SDLK_DOWN:
sym = K_DOWNARROW;
break;
case SDLK_RIGHT:
sym = K_RIGHTARROW;
break;
case SDLK_LEFT:
sym = K_LEFTARROW;
break;
case SDLK_INSERT:
sym = K_INS;
break;
case SDLK_HOME:
sym = K_HOME;
break;
case SDLK_END:
sym = K_END;
break;
case SDLK_PAGEUP:
sym = K_PGUP;
break;
case SDLK_PAGEDOWN:
sym = K_PGDN;
break;
case SDLK_RSHIFT:
case SDLK_LSHIFT:
sym = K_SHIFT;
break;
case SDLK_RCTRL:
case SDLK_LCTRL:
sym = K_CTRL;
break;
case SDLK_RALT:
case SDLK_LALT:
sym = K_ALT;
break;
case SDLK_CAPSLOCK:
sym = K_CAPSLOCK;
break;
case SDLK_KP0:
if (modstate & KMOD_NUM)
sym = K_INS;
else
sym = SDLK_0;
break;
case SDLK_KP1:
if (modstate & KMOD_NUM)
sym = K_END;
else
sym = SDLK_1;
break;
case SDLK_KP2:
if (modstate & KMOD_NUM)
sym = K_DOWNARROW;
else
sym = SDLK_2;
break;
case SDLK_KP3:
if (modstate & KMOD_NUM)
sym = K_PGDN;
else
sym = SDLK_3;
break;
case SDLK_KP4:
if (modstate & KMOD_NUM)
sym = K_LEFTARROW;
else
sym = SDLK_4;
break;
case SDLK_KP5:
sym = SDLK_5;
break;
case SDLK_KP6:
if (modstate & KMOD_NUM)
sym = K_RIGHTARROW;
else
sym = SDLK_6;
break;
case SDLK_KP7:
if (modstate & KMOD_NUM)
sym = K_HOME;
else
sym = SDLK_7;
break;
case SDLK_KP8:
if (modstate & KMOD_NUM)
sym = K_UPARROW;
else
sym = SDLK_8;
break;
case SDLK_KP9:
if (modstate & KMOD_NUM)
sym = K_PGUP;
else
sym = SDLK_9;
break;
case SDLK_KP_PERIOD:
if (modstate & KMOD_NUM)
sym = K_DEL;
else
sym = SDLK_PERIOD;
break;
case SDLK_KP_DIVIDE:
sym = SDLK_SLASH;
break;
case SDLK_KP_MULTIPLY:
sym = SDLK_ASTERISK;
break;
case SDLK_KP_MINUS:
sym = SDLK_MINUS;
break;
case SDLK_KP_PLUS:
sym = SDLK_PLUS;
break;
case SDLK_KP_ENTER:
sym = SDLK_RETURN;
break;
case SDLK_KP_EQUALS:
sym = SDLK_EQUALS;
break;
}
// If we're not directly handled and still above 255
// just force it to 0
if (sym > 255)
sym = 0;
Key_Event (sym, -1, state);
break;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
but = event.button.button;
if (but == 2)
but = 3;
else if (but == 3)
but = 2;
switch (but) {
case 1:
case 2:
case 3:
Key_Event (K_MOUSE1 + but - 1, 0, event.type
== SDL_MOUSEBUTTONDOWN);
break;
case 4:
Key_Event (K_MWHEELUP, 0,
event.type == SDL_MOUSEBUTTONDOWN);
break;
case 5:
Key_Event (K_MWHEELDOWN, 0,
event.type == SDL_MOUSEBUTTONDOWN);
break;
}
break;
case SDL_MOUSEMOTION:
if (_windowed_mouse->value) {
if ((event.motion.x != (vid.width / 2))
|| (event.motion.y != (vid.height / 2))) {
// *2 for vid_sdl.c, *10 for vid_sgl.c.
mouse_x = event.motion.xrel * 5;
mouse_y = event.motion.yrel * 5;
if (
(event.motion.x <
((vid.width / 2) - (vid.width / 4)))
|| (event.motion.x >
((vid.width / 2) + (vid.width / 4)))
|| (event.motion.y <
((vid.height / 2) - (vid.height / 4)))
|| (event.motion.y >
((vid.height / 2) + (vid.height / 4))))
SDL_WarpMouse (vid.width / 2, vid.height / 2);
}
} else {
// following are *2 in vid_sdl.c, vid_sgl.c is *10
mouse_x = event.motion.xrel * 5;
mouse_y = event.motion.yrel * 5;
}
break;
case SDL_QUIT:
CL_Disconnect ();
Sys_Quit ();
break;
default:
break;
}
}
}
void
IN_Commands (void)
{
JOY_Command ();
if (old_windowed_mouse != _windowed_mouse->value) {
old_windowed_mouse = _windowed_mouse->value;
if (!_windowed_mouse->value) {
// SDL_ShowCursor (0);
SDL_WM_GrabInput (SDL_GRAB_OFF);
} else {
SDL_WM_GrabInput (SDL_GRAB_ON);
// SDL_ShowCursor (1);
}
}
}
void
IN_Init (void)
{
JOY_Init ();
if (COM_CheckParm ("-nomouse") && !_windowed_mouse->value)
return;
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
// SDL_ShowCursor (0);
// SDL_WM_GrabInput (SDL_GRAB_ON);
// FIXME: disable DGA if in_dgamouse says to.
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL, "If set to 1, quake will grab the mouse in X");
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL, "Toggle mouse input filtering");
}
void
IN_Shutdown (void)
{
mouse_avail = 0;
}
void
IN_Frame (void)
{
int i;
int mouse_buttonstate;
if (!mouse_avail)
return;
i = SDL_GetMouseState (NULL, NULL);
/* Quake swaps the second and third buttons */
mouse_buttonstate = (i & ~0x06) | ((i & 0x02) << 1) | ((i & 0x04) >> 1);
for (i = 0; i < 3; i++) {
if ((mouse_buttonstate & (1 << i))
&& !(mouse_oldbuttonstate & (1 << i))) Key_Event (K_MOUSE1 + i, 0,
true);
if (!(mouse_buttonstate & (1 << i))
&& (mouse_oldbuttonstate & (1 << i))) Key_Event (K_MOUSE1 + i, 0,
false);
}
mouse_oldbuttonstate = mouse_buttonstate;
}
void
IN_Move (void)
{
JOY_Move ();
if (!mouse_avail)
return;
if (m_filter->value) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ((in_strafe.state & 1) || (lookstrafe->value && (in_mlook.state & 1)))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if (in_strafe.state & 1)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
mouse_x = mouse_y = 0.0;
}

View file

@ -258,7 +258,7 @@ IN_Move (void)
if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += dy;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
if (in_strafe.state & 1)
viewdelta.position[1] -= dy;
else
viewdelta.position[2] -= dy;

View file

@ -0,0 +1,400 @@
/*
in_svgalib.c
(description)
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1999-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$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include <vgakeyboard.h>
#include <vgamouse.h>
#include "cl_input.h"
#include "client.h"
#include "QF/cmd.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "view.h"
static int UseKeyboard = 1;
static int UseMouse = 1;
static int in_svgalib_inited = 0;
static unsigned char scantokey[128];
static int mouse_buttons;
static int mouse_buttonstate;
static int mouse_oldbuttonstate;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int mx, my;
static void IN_InitKeyboard (void);
static void IN_InitMouse (void);
cvar_t *_windowed_mouse;
cvar_t *m_filter;
static void
keyhandler (int scancode, int state)
{
int sc;
sc = scancode & 0x7f;
#if 0
Con_Printf ("scancode=%x (%d%s)\n", scancode, sc,
scancode & 0x80 ? "+128" : "");
#endif
Key_Event (scantokey[sc], -1, state == KEY_EVENTPRESS);
}
static void
mousehandler (int buttonstate, int dx, int dy, int dz, int drx, int dry, int drz)
{
mouse_buttonstate = buttonstate;
mx += dx;
my += dy;
if (drx > 0) {
Key_Event (K_MWHEELUP, 0, 1);
Key_Event (K_MWHEELUP, 0, 0);
} else if (drx < 0) {
Key_Event (K_MWHEELDOWN, 0, 1);
Key_Event (K_MWHEELDOWN, 0, 0);
}
}
void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
void
IN_Init (void)
{
if (COM_CheckParm ("-nokbd"))
UseKeyboard = 0;
if (COM_CheckParm ("-nomouse"))
UseMouse = 0;
if (UseKeyboard)
IN_InitKeyboard ();
if (UseMouse)
IN_InitMouse ();
JOY_Init ();
in_svgalib_inited = 1;
return;
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
}
static void
IN_InitKeyboard (void)
{
int i;
for (i = 0; i < 128; i++) {
scantokey[i] = ' ';
}
scantokey[1] = K_ESCAPE;
scantokey[2] = '1';
scantokey[3] = '2';
scantokey[4] = '3';
scantokey[5] = '4';
scantokey[6] = '5';
scantokey[7] = '6';
scantokey[8] = '7';
scantokey[9] = '8';
scantokey[10] = '9';
scantokey[11] = '0';
scantokey[12] = '-';
scantokey[13] = '=';
scantokey[14] = K_BACKSPACE;
scantokey[15] = K_TAB;
scantokey[16] = 'q';
scantokey[17] = 'w';
scantokey[18] = 'e';
scantokey[19] = 'r';
scantokey[20] = 't';
scantokey[21] = 'y';
scantokey[22] = 'u';
scantokey[23] = 'i';
scantokey[24] = 'o';
scantokey[25] = 'p';
scantokey[26] = '[';
scantokey[27] = ']';
scantokey[28] = K_ENTER;
scantokey[29] = K_CTRL; /* left */
scantokey[30] = 'a';
scantokey[31] = 's';
scantokey[32] = 'd';
scantokey[33] = 'f';
scantokey[34] = 'g';
scantokey[35] = 'h';
scantokey[36] = 'j';
scantokey[37] = 'k';
scantokey[38] = 'l';
scantokey[39] = ';';
scantokey[40] = '\'';
scantokey[41] = '`';
scantokey[42] = K_SHIFT; /* left */
scantokey[43] = '\\';
scantokey[44] = 'z';
scantokey[45] = 'x';
scantokey[46] = 'c';
scantokey[47] = 'v';
scantokey[48] = 'b';
scantokey[49] = 'n';
scantokey[50] = 'm';
scantokey[51] = ',';
scantokey[52] = '.';
scantokey[53] = '/';
scantokey[54] = K_SHIFT; /* right */
scantokey[55] = KP_MULTIPLY;
scantokey[56] = K_ALT; /* left */
scantokey[57] = ' ';
scantokey[58] = K_CAPSLOCK;
scantokey[59] = K_F1;
scantokey[60] = K_F2;
scantokey[61] = K_F3;
scantokey[62] = K_F4;
scantokey[63] = K_F5;
scantokey[64] = K_F6;
scantokey[65] = K_F7;
scantokey[66] = K_F8;
scantokey[67] = K_F9;
scantokey[68] = K_F10;
scantokey[69] = KP_NUMLCK;
scantokey[70] = K_SCRLCK;
scantokey[71] = KP_HOME;
scantokey[72] = KP_UPARROW;
scantokey[73] = KP_PGUP;
scantokey[74] = KP_MINUS;
scantokey[75] = KP_LEFTARROW;
scantokey[76] = KP_5;
scantokey[77] = KP_RIGHTARROW;
scantokey[79] = KP_END;
scantokey[78] = KP_PLUS;
scantokey[80] = KP_DOWNARROW;
scantokey[81] = KP_PGDN;
scantokey[82] = KP_INS;
scantokey[83] = KP_DEL;
/* 84 to 86 not used */
scantokey[87] = K_F11;
scantokey[88] = K_F12;
/* 89 to 95 not used */
scantokey[96] = KP_ENTER; /* keypad enter */
scantokey[97] = K_CTRL; /* right */
scantokey[98] = KP_DIVIDE;
scantokey[99] = K_PRNTSCR; /* print screen */
scantokey[100] = K_ALT; /* right */
scantokey[101] = K_PAUSE; /* break */
scantokey[102] = K_HOME;
scantokey[103] = K_UPARROW;
scantokey[104] = K_PGUP;
scantokey[105] = K_LEFTARROW;
scantokey[106] = K_RIGHTARROW;
scantokey[107] = K_END;
scantokey[108] = K_DOWNARROW;
scantokey[109] = K_PGDN;
scantokey[110] = K_INS;
scantokey[111] = K_DEL;
scantokey[119] = K_PAUSE;
if (keyboard_init ()) {
Sys_Error ("keyboard_init() failed");
}
keyboard_seteventhandler (keyhandler);
}
static void
IN_InitMouse (void)
{
int mtype;
char *mousedev;
int mouserate = MOUSE_DEFAULTSAMPLERATE;
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force viewpoint of player to center");
mouse_buttons = 3;
mtype = vga_getmousetype ();
mousedev = "/dev/mouse";
if (getenv ("MOUSEDEV"))
mousedev = getenv ("MOUSEDEV");
if (COM_CheckParm ("-mdev")) {
mousedev = com_argv[COM_CheckParm ("-mdev") + 1];
}
if (getenv ("MOUSERATE"))
mouserate = atoi (getenv ("MOUSERATE"));
if (COM_CheckParm ("-mrate")) {
mouserate = atoi (com_argv[COM_CheckParm ("-mrate") + 1]);
}
#if 0
printf ("Mouse: dev=%s,type=%s,speed=%d\n",
mousedev, mice[mtype].name, mouserate);
#endif
if (mouse_init (mousedev, mtype, mouserate)) {
Con_Printf ("No mouse found\n");
UseMouse = 0;
} else {
mouse_seteventhandler ((void *) mousehandler);
}
}
void
IN_Shutdown (void)
{
JOY_Shutdown ();
Con_Printf ("IN_Shutdown\n");
if (UseMouse)
mouse_close ();
if (UseKeyboard)
keyboard_close ();
in_svgalib_inited = 0;
}
void
IN_SendKeyEvents (void)
{
if (!in_svgalib_inited)
return;
if (UseKeyboard) {
while ((keyboard_update ()));
}
}
void
IN_Commands (void)
{
JOY_Command ();
if (UseMouse) {
/* Poll mouse values */
while (mouse_update ());
/* Perform button actions */
if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, true);
else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
Key_Event (K_MOUSE1, 0, false);
if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, true);
else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
Key_Event (K_MOUSE2, 0, false);
if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
!(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, true);
else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
Key_Event (K_MOUSE3, 0, false);
mouse_oldbuttonstate = mouse_buttonstate;
}
}
void
IN_Move (void)
{
JOY_Move ();
if (!UseMouse)
return;
/* Poll mouse values */
while (mouse_update ());
if (m_filter->int_val) {
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
/* Clear for next update */
mx = my = 0;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
/* Add mouse X/Y movement to cmd */
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook)) {
viewdelta.position[0] += mouse_x;
} else {
viewdelta.angles[YAW] -= mouse_x;
}
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if (in_strafe.state & 1)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
}

668
libs/video/targets/in_win.c Normal file
View file

@ -0,0 +1,668 @@
/*
in_win.c
windows 95 mouse stuff
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$
*/
// 02/21/97 JCB Added extended DirectInput code to support external controllers.
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "winquake.h"
#include <dinput.h>
#include "client.h"
#include "QF/keys.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/qargs.h"
#include "QF/cmd.h"
#include "QF/input.h"
#include "cl_input.h"
#include "view.h"
#define DINPUT_BUFFERSIZE 16
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
HRESULT (WINAPI * pDirectInputCreate) (HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * lplpDirectInput,
LPUNKNOWN punkOuter);
// mouse public variables
float mouse_x, mouse_y;
qboolean mouseactive;
unsigned int uiWheelMessage;
// mouse local variables
static int mouse_buttons;
static int mouse_oldbuttonstate;
static POINT current_pos;
static float old_mouse_x, old_mouse_y, mx_accum, my_accum;
static qboolean mouseinitialized;
static cvar_t *m_filter;
static qboolean restore_spi;
static int originalmouseparms[3], newmouseparms[3] = { 0, 0, 1 };
static qboolean mouseparmsvalid, mouseactivatetoggle;
static qboolean mouseshowtoggle = 1;
static qboolean dinput_acquired;
static unsigned int mstate_di;
// misc locals
static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse;
static HINSTANCE hInstDI;
static qboolean dinput;
typedef struct MYDATA {
LONG lX; // X axis goes here
LONG lY; // Y axis goes here
LONG lZ; // Z axis goes here
BYTE bButtonA; // One button goes here
BYTE bButtonB; // Another button goes here
BYTE bButtonC; // Another button goes here
BYTE bButtonD; // Another button goes here
} MYDATA;
static DIOBJECTDATAFORMAT rgodf[] = {
{&GUID_XAxis, FIELD_OFFSET (MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{&GUID_YAxis, FIELD_OFFSET (MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{&GUID_ZAxis, FIELD_OFFSET (MYDATA, lZ),
0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonC),
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{0, FIELD_OFFSET (MYDATA, bButtonD),
0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
};
#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
static DIDATAFORMAT df = {
sizeof (DIDATAFORMAT), // this structure
sizeof (DIOBJECTDATAFORMAT), // size of object data format
DIDF_RELAXIS, // absolute axis coordinates
sizeof (MYDATA), // device data size
NUM_OBJECTS, // number of objects
rgodf, // and here they are
};
// forward-referenced functions, joy
extern void JOY_Command(void);
extern void JOY_Init_Cvars(void);
extern void JOY_Init (void);
extern void JOY_AdvancedUpdate_f (void);
extern void JOY_Move (void);
/*
Force_CenterView_f
*/
static void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
/*
IN_UpdateClipCursor
*/
void
IN_UpdateClipCursor (void)
{
if (mouseinitialized && mouseactive && !dinput) {
ClipCursor (&window_rect);
}
}
/*
IN_ShowMouse
*/
void
IN_ShowMouse (void)
{
if (!mouseshowtoggle) {
ShowCursor (TRUE);
mouseshowtoggle = 1;
}
}
/*
IN_HideMouse
*/
void
IN_HideMouse (void)
{
if (mouseshowtoggle) {
ShowCursor (FALSE);
mouseshowtoggle = 0;
}
}
/*
IN_ActivateMouse
*/
void
IN_ActivateMouse (void)
{
mouseactivatetoggle = true;
if (mouseinitialized) {
if (dinput) {
if (g_pMouse) {
if (!dinput_acquired) {
IDirectInputDevice_Acquire (g_pMouse);
dinput_acquired = true;
}
} else {
return;
}
} else {
if (mouseparmsvalid)
restore_spi =
SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
SetCursorPos (window_center_x, window_center_y);
SetCapture (mainwindow);
ClipCursor (&window_rect);
}
mouseactive = true;
}
}
/*
IN_SetQuakeMouseState
*/
void
IN_SetQuakeMouseState (void)
{
if (mouseactivatetoggle)
IN_ActivateMouse ();
}
/*
IN_DeactivateMouse
*/
void
IN_DeactivateMouse (void)
{
mouseactivatetoggle = false;
if (mouseinitialized) {
if (dinput) {
if (g_pMouse) {
if (dinput_acquired) {
IDirectInputDevice_Unacquire (g_pMouse);
dinput_acquired = false;
}
}
} else {
if (restore_spi)
SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
ClipCursor (NULL);
ReleaseCapture ();
}
mouseactive = false;
}
}
/*
IN_RestoreOriginalMouseState
*/
void
IN_RestoreOriginalMouseState (void)
{
if (mouseactivatetoggle) {
IN_DeactivateMouse ();
mouseactivatetoggle = true;
}
// try to redraw the cursor so it gets reinitialized, because sometimes it
// has garbage after the mode switch
ShowCursor (TRUE);
ShowCursor (FALSE);
}
/*
IN_InitDInput
*/
static qboolean
IN_InitDInput (void)
{
HRESULT hr;
DIPROPDWORD dipdw = {
{
sizeof (DIPROPDWORD), // diph.dwSize
sizeof (DIPROPHEADER), // diph.dwHeaderSize
0, // diph.dwObj
DIPH_DEVICE, // diph.dwHow
}
,
DINPUT_BUFFERSIZE, // dwData
};
if (!hInstDI) {
hInstDI = LoadLibrary ("dinput.dll");
if (hInstDI == NULL) {
Con_Printf ("Couldn't load dinput.dll\n");
return false;
}
}
if (!pDirectInputCreate) {
pDirectInputCreate =
(void *) GetProcAddress (hInstDI, "DirectInputCreateA");
if (!pDirectInputCreate) {
Con_Printf ("Couldn't get DI proc addr\n");
return false;
}
}
// register with DirectInput and get an IDirectInput to play with.
hr =
iDirectInputCreate (global_hInstance, DIRECTINPUT_VERSION, &g_pdi,
NULL);
if (FAILED (hr)) {
return false;
}
// obtain an interface to the system mouse device.
hr = IDirectInput_CreateDevice (g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
if (FAILED (hr)) {
Con_Printf ("Couldn't open DI mouse device\n");
return false;
}
// set the data format to "mouse format".
hr = IDirectInputDevice_SetDataFormat (g_pMouse, &df);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI mouse format\n");
return false;
}
// set the cooperativity level.
hr = IDirectInputDevice_SetCooperativeLevel (g_pMouse, mainwindow,
DISCL_EXCLUSIVE |
DISCL_FOREGROUND);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI coop level\n");
return false;
}
// set the buffer size to DINPUT_BUFFERSIZE elements.
// the buffer size is a DWORD property associated with the device
hr =
IDirectInputDevice_SetProperty (g_pMouse, DIPROP_BUFFERSIZE,
&dipdw.diph);
if (FAILED (hr)) {
Con_Printf ("Couldn't set DI buffersize\n");
return false;
}
return true;
}
/*
IN_StartupMouse
*/
static void
IN_StartupMouse (void)
{
// HDC hdc;
if (COM_CheckParm ("-nomouse"))
return;
mouseinitialized = true;
if (COM_CheckParm ("-dinput")) {
dinput = IN_InitDInput ();
if (dinput) {
Con_Printf ("DirectInput initialized\n");
} else {
Con_Printf ("DirectInput not initialized\n");
}
}
if (!dinput) {
mouseparmsvalid =
SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
if (mouseparmsvalid) {
if (COM_CheckParm ("-noforcemspd"))
newmouseparms[2] = originalmouseparms[2];
if (COM_CheckParm ("-noforcemaccel")) {
newmouseparms[0] = originalmouseparms[0];
newmouseparms[1] = originalmouseparms[1];
}
if (COM_CheckParm ("-noforcemparms")) {
newmouseparms[0] = originalmouseparms[0];
newmouseparms[1] = originalmouseparms[1];
newmouseparms[2] = originalmouseparms[2];
}
}
}
mouse_buttons = 3;
// if a fullscreen video mode was set before the mouse was initialized,
// set the mouse state appropriately
if (mouseactivatetoggle)
IN_ActivateMouse ();
}
/*
IN_Init
*/
void
IN_Init (void)
{
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
uiWheelMessage = RegisterWindowMessage ("MSWHEEL_ROLLMSG");
IN_StartupMouse ();
JOY_Init ();
}
void
IN_Init_Cvars (void)
{
// mouse variables
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
JOY_Init_Cvars();
}
/*
IN_Shutdown
*/
void
IN_Shutdown (void)
{
IN_DeactivateMouse ();
IN_ShowMouse ();
if (g_pMouse) {
IDirectInputDevice_Release (g_pMouse);
g_pMouse = NULL;
}
if (g_pdi) {
IDirectInput_Release (g_pdi);
g_pdi = NULL;
}
}
/*
IN_MouseEvent
*/
void
IN_MouseEvent (int mstate)
{
int i;
if (mouseactive && !dinput) {
// perform button actions
for (i = 0; i < mouse_buttons; i++) {
if ((mstate & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, true);
}
if (!(mstate & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, false);
}
}
mouse_oldbuttonstate = mstate;
}
}
/*
IN_MouseMove
*/
void
IN_MouseMove (void)
{
int mx, my;
// HDC hdc;
int i;
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
if (!mouseactive)
return;
if (dinput) {
mx = 0;
my = 0;
for (;;) {
dwElements = 1;
hr = IDirectInputDevice_GetDeviceData (g_pMouse,
sizeof (DIDEVICEOBJECTDATA),
&od, &dwElements, 0);
if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) {
dinput_acquired = true;
IDirectInputDevice_Acquire (g_pMouse);
break;
}
/* Unable to read data or no data available */
if (FAILED (hr) || dwElements == 0) {
break;
}
/* Look at the element to see what happened */
switch (od.dwOfs) {
case DIMOFS_X:
mx += od.dwData;
break;
case DIMOFS_Y:
my += od.dwData;
break;
case DIMOFS_BUTTON0:
if (od.dwData & 0x80)
mstate_di |= 1;
else
mstate_di &= ~1;
break;
case DIMOFS_BUTTON1:
if (od.dwData & 0x80)
mstate_di |= (1 << 1);
else
mstate_di &= ~(1 << 1);
break;
case DIMOFS_BUTTON2:
if (od.dwData & 0x80)
mstate_di |= (1 << 2);
else
mstate_di &= ~(1 << 2);
break;
}
}
// perform button actions
for (i = 0; i < mouse_buttons; i++) {
if ((mstate_di & (1 << i)) && !(mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, true);
}
if (!(mstate_di & (1 << i)) && (mouse_oldbuttonstate & (1 << i))) {
Key_Event (K_MOUSE1 + i, -1, false);
}
}
mouse_oldbuttonstate = mstate_di;
} else {
GetCursorPos (&current_pos);
mx = current_pos.x - window_center_x + mx_accum;
my = current_pos.y - window_center_y + my_accum;
mx_accum = 0;
my_accum = 0;
}
if (m_filter->value) {
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
} else {
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
// add mouse X/Y movement to cmd
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if (in_strafe.state & 1)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
// if the mouse has moved, force it to the center, so there's room to move
if (mx || my) {
SetCursorPos (window_center_x, window_center_y);
}
}
/*
IN_Move
*/
void
IN_Move (void)
{
if (ActiveApp && !Minimized) {
IN_MouseMove ();
JOY_Move ();
}
}
/*
IN_Accumulate
*/
void
IN_Accumulate (void)
{
// int mx, my;
// HDC hdc;
// if (dinput) return; // If using dinput we don't probably need this
if (mouseactive) {
GetCursorPos (&current_pos);
mx_accum += current_pos.x - window_center_x;
my_accum += current_pos.y - window_center_y;
// force the mouse to the center, so there's room to move
SetCursorPos (window_center_x, window_center_y);
}
}
/*
IN_ClearStates
*/
void
IN_ClearStates (void)
{
if (mouseactive) {
mx_accum = 0;
my_accum = 0;
mouse_oldbuttonstate = 0;
}
}
/*
IN_Commands
*/
void
IN_Commands (void)
{
// Joystick
JOY_Command();
}

556
libs/video/targets/in_x11.c Normal file
View file

@ -0,0 +1,556 @@
/*
in_x11.c
general x11 input driver
Copyright (C) 1996-1997 Id Software, Inc.
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$
*/
#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
#define _BSD
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#ifdef HAVE_DGA
# include <X11/extensions/XShm.h>
# include <X11/extensions/xf86dga.h>
#endif
#include "cl_input.h"
#include "client.h"
#include "QF/compat.h"
#include "QF/console.h"
#include "context_x11.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "dga_check.h"
#include "QF/input.h"
#include "QF/joystick.h"
#include "QF/keys.h"
#include "QF/qargs.h"
#include "QF/sys.h"
#include "view.h"
cvar_t *_windowed_mouse;
cvar_t *m_filter;
cvar_t *in_dga;
cvar_t *in_dga_mouseaccel;
static qboolean dga_avail;
static qboolean dga_active;
static keydest_t old_key_dest = key_none;
static qboolean mouse_avail;
static float mouse_x, mouse_y;
static float old_mouse_x, old_mouse_y;
static int p_mouse_x, p_mouse_y;
#define KEY_MASK (KeyPressMask | KeyReleaseMask)
#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
#define INPUT_MASK (KEY_MASK | MOUSE_MASK)
static int
XLateKey (XKeyEvent * ev, qboolean modified)
{
char tmp[2];
int key = 0;
KeySym keysym;
if (!modified) {
keysym = XLookupKeysym (ev, 0);
} else {
XLookupString (ev, tmp, 1, &keysym, NULL);
}
switch (keysym) {
case XK_KP_Page_Up:
key = KP_PGUP;
break;
case XK_Page_Up:
key = K_PGUP;
break;
case XK_KP_Page_Down:
key = KP_PGDN;
break;
case XK_Page_Down:
key = K_PGDN;
break;
case XK_KP_Home:
key = KP_HOME;
break;
case XK_Home:
key = K_HOME;
break;
case XK_KP_End:
key = KP_END;
break;
case XK_End:
key = K_END;
break;
case XK_KP_Left:
key = KP_LEFTARROW;
break;
case XK_Left:
key = K_LEFTARROW;
break;
case XK_KP_Right:
key = KP_RIGHTARROW;
break;
case XK_Right:
key = K_RIGHTARROW;
break;
case XK_KP_Down:
key = KP_DOWNARROW;
break;
case XK_Down:
key = K_DOWNARROW;
break;
case XK_KP_Up:
key = KP_UPARROW;
break;
case XK_Up:
key = K_UPARROW;
break;
case XK_Escape:
key = K_ESCAPE;
break;
case XK_KP_Enter:
key = KP_ENTER;
break;
case XK_Return:
key = K_ENTER;
break;
case XK_Tab:
key = K_TAB;
break;
case XK_F1:
key = K_F1;
break;
case XK_F2:
key = K_F2;
break;
case XK_F3:
key = K_F3;
break;
case XK_F4:
key = K_F4;
break;
case XK_F5:
key = K_F5;
break;
case XK_F6:
key = K_F6;
break;
case XK_F7:
key = K_F7;
break;
case XK_F8:
key = K_F8;
break;
case XK_F9:
key = K_F9;
break;
case XK_F10:
key = K_F10;
break;
case XK_F11:
key = K_F11;
break;
case XK_F12:
key = K_F12;
break;
case XK_BackSpace:
key = K_BACKSPACE;
break;
case XK_KP_Delete:
key = KP_DEL;
break;
case XK_Delete:
key = K_DEL;
break;
case XK_Pause:
key = K_PAUSE;
break;
case XK_Shift_L:
case XK_Shift_R:
key = K_SHIFT;
break;
case XK_Execute:
case XK_Control_L:
case XK_Control_R:
key = K_CTRL;
break;
case XK_Mode_switch:
case XK_Alt_L:
case XK_Meta_L:
case XK_Alt_R:
case XK_Meta_R:
key = K_ALT;
break;
case XK_Caps_Lock:
key = K_CAPSLOCK;
break;
case XK_KP_Begin:
key = KP_5;
break;
case XK_Insert:
key = K_INS;
break;
case XK_KP_Insert:
key = KP_INS;
break;
case XK_KP_Multiply:
key = KP_MULTIPLY;
break;
case XK_KP_Add:
key = KP_PLUS;
break;
case XK_KP_Subtract:
key = KP_MINUS;
break;
case XK_KP_Divide:
key = KP_DIVIDE;
break;
/* For Sun keyboards */
case XK_F27:
key = K_HOME;
break;
case XK_F29:
key = K_PGUP;
break;
case XK_F33:
key = K_END;
break;
case XK_F35:
key = K_PGDN;
break;
default:
if (keysym < 128) {
/* ASCII keys */
key = keysym;
if (!modified && ((key >= 'A') && (key <= 'Z'))) {
key = key + ('a' - 'A');
}
}
break;
}
return key;
}
static void
event_key (XEvent * event)
{
if (old_key_dest != key_dest) {
old_key_dest = key_dest;
if (key_dest == key_game) {
XAutoRepeatOff (x_disp);
} else {
XAutoRepeatOn (x_disp);
}
}
Key_Event (XLateKey (&event->xkey, 0), XLateKey (&event->xkey, 1),
event->type == KeyPress);
}
static void
event_button (XEvent * event)
{
int but;
but = event->xbutton.button;
if (but == 2)
but = 3;
else if (but == 3)
but = 2;
switch (but) {
case 1:
case 2:
case 3:
Key_Event (K_MOUSE1 + but - 1, 0, event->type == ButtonPress);
break;
case 4:
Key_Event (K_MWHEELUP, 0, event->type == ButtonPress);
break;
case 5:
Key_Event (K_MWHEELDOWN, 0, event->type == ButtonPress);
break;
}
}
static void
center_pointer (void)
{
XEvent event;
event.type = MotionNotify;
event.xmotion.display = x_disp;
event.xmotion.window = x_win;
event.xmotion.x = vid.width / 2;
event.xmotion.y = vid.height / 2;
XSendEvent (x_disp, x_win, False, PointerMotionMask, &event);
XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0,
vid.width / 2, vid.height / 2);
}
static void
event_motion (XEvent * event)
{
if (dga_active) {
mouse_x += event->xmotion.x_root * in_dga_mouseaccel->value;
mouse_y += event->xmotion.y_root * in_dga_mouseaccel->value;
} else {
if (vid_fullscreen->int_val || _windowed_mouse->int_val) {
if (!event->xmotion.send_event) {
mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y);
if (abs (vid.width / 2 - event->xmotion.x) > vid.width / 4
|| abs (vid.height / 2 - event->xmotion.y) > vid.height / 4) {
center_pointer ();
}
}
} else {
mouse_x += (event->xmotion.x - p_mouse_x);
mouse_y += (event->xmotion.y - p_mouse_y);
}
p_mouse_x = event->xmotion.x;
p_mouse_y = event->xmotion.y;
}
}
void
IN_Commands (void)
{
static int old_windowed_mouse;
static int old_in_dga;
JOY_Command ();
if ((old_windowed_mouse != _windowed_mouse->int_val)
|| (old_in_dga != in_dga->int_val)) {
old_windowed_mouse = _windowed_mouse->int_val;
old_in_dga = in_dga->int_val;
if (_windowed_mouse->int_val) { // grab the pointer
XGrabPointer (x_disp, x_win, True, MOUSE_MASK, GrabModeAsync,
GrabModeAsync, x_win, None, CurrentTime);
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && !dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp),
XF86DGADirectMouse);
dga_active = true;
}
#endif
} else { // ungrab the pointer
#ifdef HAVE_DGA
if (dga_avail && in_dga->int_val && dga_active) {
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
dga_active = false;
}
#endif
XUngrabPointer (x_disp, CurrentTime);
}
}
}
void
IN_SendKeyEvents (void)
{
/* Get events from X server. */
X11_ProcessEvents ();
}
void
IN_Move (void)
{
JOY_Move ();
if (!mouse_avail)
return;
if (m_filter->int_val) {
mouse_x = (mouse_x + old_mouse_x) * 0.5;
mouse_y = (mouse_y + old_mouse_y) * 0.5;
}
old_mouse_x = mouse_x;
old_mouse_y = mouse_y;
mouse_x *= sensitivity->value;
mouse_y *= sensitivity->value;
if ((in_strafe.state & 1) || (lookstrafe->int_val && freelook))
viewdelta.position[0] += mouse_x;
else
viewdelta.angles[YAW] -= mouse_x;
if (freelook && !(in_strafe.state & 1)) {
viewdelta.angles[PITCH] += mouse_y;
} else {
if ((in_strafe.state & 1) && noclip_anglehack)
viewdelta.position[1] -= mouse_y;
else
viewdelta.position[2] -= mouse_y;
}
mouse_x = mouse_y = 0.0;
}
/*
Called at shutdown
*/
void
IN_Shutdown (void)
{
JOY_Shutdown ();
Con_Printf ("IN_Shutdown\n");
mouse_avail = 0;
if (x_disp) {
XAutoRepeatOn (x_disp);
#ifdef HAVE_DGA
if (dga_avail)
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
#endif
}
X11_CloseDisplay ();
}
void
Force_CenterView_f (void)
{
cl.viewangles[PITCH] = 0;
}
void
IN_Init (void)
{
// open the display
if (!x_disp)
Sys_Error ("IN: No display!!\n");
if (!x_win)
Sys_Error ("IN: No window!!\n");
X11_OpenDisplay (); // call to increment the reference counter
{
int attribmask = CWEventMask;
XWindowAttributes attribs_1;
XSetWindowAttributes attribs_2;
XGetWindowAttributes (x_disp, x_win, &attribs_1);
attribs_2.event_mask = attribs_1.your_event_mask | INPUT_MASK;
XChangeWindowAttributes (x_disp, x_win, attribmask, &attribs_2);
}
JOY_Init ();
XAutoRepeatOff (x_disp);
if (COM_CheckParm ("-nomouse"))
return;
dga_avail = VID_CheckDGA (x_disp, NULL, NULL, NULL);
if (vid_fullscreen->int_val) {
Cvar_Set (_windowed_mouse, "1");
_windowed_mouse->flags |= CVAR_ROM;
}
mouse_x = mouse_y = 0.0;
mouse_avail = 1;
X11_AddEvent (KeyPress, &event_key);
X11_AddEvent (KeyRelease, &event_key);
X11_AddEvent (ButtonPress, &event_button);
X11_AddEvent (ButtonRelease, &event_button);
X11_AddEvent (MotionNotify, &event_motion);
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
}
void
IN_Init_Cvars (void)
{
JOY_Init_Cvars ();
_windowed_mouse = Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, NULL,
"With this set to 1, quake will grab the mouse from X");
m_filter = Cvar_Get ("m_filter", "0", CVAR_ARCHIVE, NULL,
"Toggle mouse input filtering.");
in_dga = Cvar_Get ("in_dga", "1", CVAR_ARCHIVE, NULL,
"DGA Input support");
in_dga_mouseaccel = Cvar_Get ("in_dga_mouseaccel", "1", CVAR_ARCHIVE, NULL,
"DGA Mouse accelleration multiplier");
}

View file

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

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

@ -0,0 +1,39 @@
/*
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 "QF/vid.h"
#include "view.h"

View file

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

@ -0,0 +1,773 @@
/*
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 = vid_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

@ -0,0 +1,708 @@
/*
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 "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 ((vid_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 *) vid_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

@ -0,0 +1,249 @@
/*
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 "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 = vid_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);
}

3196
libs/video/targets/vid_mgl.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,108 @@
/*
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 = vid_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

@ -0,0 +1,302 @@
/*
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 "QF/qendian.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/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 = vid_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

@ -0,0 +1,267 @@
/*
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 "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 = vid_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);
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,772 @@
/*
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 "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 ((vid_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 *) vid_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
}

View file

@ -0,0 +1,455 @@
/*
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 = vid_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)
{
}

1693
libs/video/targets/vid_wgl.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,50 @@
/*
vid_win.c
windows 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 <windows.h>
#include "QF/vid.h"
extern HWND mainwindow;
void
VID_RaiseWindow (void)
{
ShowWindow (mainwindow, SW_RESTORE);
SetForegroundWindow (mainwindow);
}
void
VID_MinimiseWindow (void)
{
SendMessage (mainwindow, WM_SYSKEYUP, VK_TAB, 1 | (0x0F << 16) | (1 << 29));
}

View file

@ -0,0 +1,797 @@
/*
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 "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 = vid_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);
}

View file

@ -1,154 +0,0 @@
/*
asm_draw.h
@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$
*/
//
// !!! note that this file must match the corresponding C structures at all
// times !!!
//
// !!! if this is changed, it must be changed in r_local.h too !!!
#define NEAR_CLIP 0.01
// !!! if this is changed, it must be changed in r_local.h too !!!
#define CYCLE 128
// espan_t structure
// !!! if this is changed, it must be changed in r_shared.h too !!!
#define espan_t_u 0
#define espan_t_v 4
#define espan_t_count 8
#define espan_t_pnext 12
#define espan_t_size 16
// sspan_t structure
// !!! if this is changed, it must be changed in d_local.h too !!!
#define sspan_t_u 0
#define sspan_t_v 4
#define sspan_t_count 8
#define sspan_t_size 12
// spanpackage_t structure
// !!! if this is changed, it must be changed in d_polyset.c too !!!
#define spanpackage_t_pdest 0
#define spanpackage_t_pz 4
#define spanpackage_t_count 8
#define spanpackage_t_ptex 12
#define spanpackage_t_sfrac 16
#define spanpackage_t_tfrac 20
#define spanpackage_t_light 24
#define spanpackage_t_zi 28
#define spanpackage_t_size 32
// edge_t structure
// !!! if this is changed, it must be changed in r_shared.h too !!!
#define et_u 0
#define et_u_step 4
#define et_prev 8
#define et_next 12
#define et_surfs 16
#define et_nextremove 20
#define et_nearzi 24
#define et_owner 28
#define et_size 32
// surf_t structure
// !!! if this is changed, it must be changed in r_shared.h too !!!
#define SURF_T_SHIFT 6
#define st_next 0
#define st_prev 4
#define st_spans 8
#define st_key 12
#define st_last_u 16
#define st_spanstate 20
#define st_flags 24
#define st_data 28
#define st_entity 32
#define st_nearzi 36
#define st_insubmodel 40
#define st_d_ziorigin 44
#define st_d_zistepu 48
#define st_d_zistepv 52
#define st_pad 56
#define st_size 64
// clipplane_t structure
// !!! if this is changed, it must be changed in r_local.h too !!!
#define cp_normal 0
#define cp_dist 12
#define cp_next 16
#define cp_leftedge 20
#define cp_rightedge 21
#define cp_reserved 22
#define cp_size 24
// medge_t structure
// !!! if this is changed, it must be changed in model.h too !!!
#define me_v 0
#define me_cachededgeoffset 4
#define me_size 8
// mvertex_t structure
// !!! if this is changed, it must be changed in model.h too !!!
#define mv_position 0
#define mv_size 12
// refdef_t structure
// !!! if this is changed, it must be changed in render.h too !!!
#define rd_vrect 0
#define rd_aliasvrect 20
#define rd_vrectright 40
#define rd_vrectbottom 44
#define rd_aliasvrectright 48
#define rd_aliasvrectbottom 52
#define rd_vrectrightedge 56
#define rd_fvrectx 60
#define rd_fvrecty 64
#define rd_fvrectx_adj 68
#define rd_fvrecty_adj 72
#define rd_vrect_x_adj_shift20 76
#define rd_vrectright_adj_shift20 80
#define rd_fvrectright_adj 84
#define rd_fvrectbottom_adj 88
#define rd_fvrectright 92
#define rd_fvrectbottom 96
#define rd_horizontalFieldOfView 100
#define rd_xOrigin 104
#define rd_yOrigin 108
#define rd_vieworg 112
#define rd_viewangles 124
#define rd_ambientlight 136
#define rd_size 140
// mtriangle_t structure
// !!! if this is changed, it must be changed in model.h too !!!
#define mtri_facesfront 0
#define mtri_vertindex 4
#define mtri_size 16 // !!! if this changes, array indexing in !!!
// !!! d_polysa.s must be changed to match !!!
#define mtri_shift 4

View file

@ -1,68 +0,0 @@
/*
context_x11.h
(description)
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$
*/
#ifndef __CONTEXT_X11_H__
#define __CONTEXT_X11_H__
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "QF/cvar.h"
#include "QF/qtypes.h"
void GetEvent( void );
extern Display *x_disp;
extern int x_screen;
extern Window x_root;
extern XVisualInfo *x_visinfo;
extern Visual *x_vis;
extern Window x_win;
extern qboolean doShm;
extern int x_shmeventtype;
extern qboolean oktodraw;
extern cvar_t *vid_fullscreen;
qboolean x11_add_event (int event, void (*event_handler)(XEvent *));
qboolean x11_del_event (int event, void (*event_handler)(XEvent *));
void x11_process_event (void);
void x11_process_events (void);
void x11_open_display (void);
void x11_close_display (void);
void x11_create_null_cursor (void);
void x11_set_vidmode (int, int);
void x11_restore_vidmode (void);
void x11_create_window (int, int);
void x11_grab_keyboard (void);
void x11_set_caption (char *);
void x11_force_view_port (void);
void x11_Init_Cvars (void);
#endif // __CONTEXT_X11_H__

View file

@ -1,119 +0,0 @@
/*
d_local.h
@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$
*/
#include "r_shared.h"
//
// TODO: fine-tune this; it's based on providing some overage even if there
// is a 2k-wide scan, with subdivision every 8, for 256 spans of 12 bytes each
//
#define SCANBUFFERPAD 0x1000
#define R_SKY_SMASK 0x007F0000
#define R_SKY_TMASK 0x007F0000
#define DS_SPAN_LIST_END -128
#define SURFCACHE_SIZE_AT_320X200 600*1024
typedef struct surfcache_s
{
struct surfcache_s *next;
struct surfcache_s **owner; // NULL is an empty chunk of memory
int lightadj[MAXLIGHTMAPS]; // checked for strobe flush
int dlight;
int size; // including header
unsigned width;
unsigned height; // DEBUG only needed for debug
float mipscale;
struct texture_s *texture; // checked for animating textures
byte data[4]; // width*height elements
} surfcache_t;
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct sspan_s
{
int u, v, count;
} sspan_t;
extern cvar_t *d_subdiv16;
extern float scale_for_mip;
extern qboolean d_roverwrapped;
extern surfcache_t *sc_rover;
extern surfcache_t *d_initial_rover;
extern float d_sdivzstepu, d_tdivzstepu, d_zistepu;
extern float d_sdivzstepv, d_tdivzstepv, d_zistepv;
extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin;
fixed16_t sadjust, tadjust;
fixed16_t bbextents, bbextentt;
void D_DrawSpans8 (espan_t *pspans);
void D_DrawSpans16 (espan_t *pspans);
void D_DrawZSpans (espan_t *pspans);
void Turbulent8 (espan_t *pspan);
void D_SpriteDrawSpans (sspan_t *pspan);
void D_DrawSkyScans8 (espan_t *pspan);
void D_DrawSkyScans16 (espan_t *pspan);
void R_ShowSubDiv (void);
void (*prealspandrawer)(void);
surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel);
extern int D_MipLevelForScale (float scale);
#ifdef USE_INTEL_ASM
extern void D_PolysetAff8Start (void);
extern void D_PolysetAff8End (void);
#endif
extern short *d_pzbuffer;
extern unsigned int d_zrowbytes, d_zwidth;
extern int *d_pscantable;
extern int d_scantable[MAXHEIGHT];
extern int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
extern int d_y_aspect_shift, d_pix_min, d_pix_max, d_pix_shift;
extern pixel_t *d_viewbuffer;
extern short *zspantable[MAXHEIGHT];
extern int d_minmip;
extern float d_scalemip[3];
extern void (*d_drawspans) (espan_t *pspan);

View file

@ -1,263 +0,0 @@
/*
quakeasm.h
general asm header file
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$
*/
#ifndef _QUAKEASM_H_
#define _QUAKEASM_H_
// !!! must be kept the same as in d_iface.h !!!
#define TRANSPARENT_COLOR 255
.extern C(d_zistepu)
.extern C(d_pzbuffer)
.extern C(d_zistepv)
.extern C(d_zrowbytes)
.extern C(d_ziorigin)
.extern C(r_turb_s)
.extern C(r_turb_t)
.extern C(r_turb_pdest)
.extern C(r_turb_spancount)
.extern C(r_turb_turb)
.extern C(r_turb_pbase)
.extern C(r_turb_sstep)
.extern C(r_turb_tstep)
.extern C(r_bmodelactive)
.extern C(d_sdivzstepu)
.extern C(d_tdivzstepu)
.extern C(d_sdivzstepv)
.extern C(d_tdivzstepv)
.extern C(d_sdivzorigin)
.extern C(d_tdivzorigin)
.extern C(sadjust)
.extern C(tadjust)
.extern C(bbextents)
.extern C(bbextentt)
.extern C(cacheblock)
.extern C(d_viewbuffer)
.extern C(cachewidth)
.extern C(d_pzbuffer)
.extern C(d_zrowbytes)
.extern C(d_zwidth)
.extern C(d_scantable)
.extern C(r_lightptr)
.extern C(r_numvblocks)
.extern C(prowdestbase)
.extern C(pbasesource)
.extern C(r_lightwidth)
.extern C(lightright)
.extern C(lightrightstep)
.extern C(lightdeltastep)
.extern C(lightdelta)
.extern C(lightright)
.extern C(lightdelta)
.extern C(sourcetstep)
.extern C(surfrowbytes)
.extern C(lightrightstep)
.extern C(lightdeltastep)
.extern C(r_sourcemax)
.extern C(r_stepback)
.extern C(colormap)
.extern C(blocksize)
.extern C(sourcesstep)
.extern C(lightleft)
.extern C(blockdivshift)
.extern C(blockdivmask)
.extern C(lightleftstep)
.extern C(r_origin)
.extern C(r_ppn)
.extern C(r_pup)
.extern C(r_pright)
.extern C(ycenter)
.extern C(xcenter)
.extern C(d_vrectbottom_particle)
.extern C(d_vrectright_particle)
.extern C(d_vrecty)
.extern C(d_vrectx)
.extern C(d_pix_shift)
.extern C(d_pix_min)
.extern C(d_pix_max)
.extern C(d_y_aspect_shift)
.extern C(screenwidth)
.extern C(r_leftclipped)
.extern C(r_leftenter)
.extern C(r_rightclipped)
.extern C(r_rightenter)
.extern C(modelorg)
.extern C(xscale)
.extern C(r_refdef)
.extern C(yscale)
.extern C(r_leftexit)
.extern C(r_rightexit)
.extern C(r_lastvertvalid)
.extern C(cacheoffset)
.extern C(newedges)
.extern C(removeedges)
.extern C(r_pedge)
.extern C(r_framecount)
.extern C(r_u1)
.extern C(r_emitted)
.extern C(edge_p)
.extern C(surface_p)
.extern C(surfaces)
.extern C(r_lzi1)
.extern C(r_v1)
.extern C(r_ceilv1)
.extern C(r_nearzi)
.extern C(r_nearzionly)
.extern C(edge_aftertail)
.extern C(edge_tail)
.extern C(current_iv)
.extern C(edge_head_u_shift20)
.extern C(span_p)
.extern C(edge_head)
.extern C(fv)
.extern C(edge_tail_u_shift20)
.extern C(r_apverts)
.extern C(r_anumverts)
.extern C(aliastransform)
.extern C(r_avertexnormals)
.extern C(r_plightvec)
.extern C(r_ambientlight)
.extern C(r_shadelight)
.extern C(aliasxcenter)
.extern C(aliasycenter)
.extern C(a_sstepxfrac)
.extern C(r_affinetridesc)
.extern C(acolormap)
.extern C(d_pcolormap)
.extern C(r_affinetridesc)
.extern C(d_sfrac)
.extern C(d_ptex)
.extern C(d_pedgespanpackage)
.extern C(d_tfrac)
.extern C(d_light)
.extern C(d_zi)
.extern C(d_pdest)
.extern C(d_pz)
.extern C(d_aspancount)
.extern C(erroradjustup)
.extern C(errorterm)
.extern C(d_xdenom)
.extern C(r_p0)
.extern C(r_p1)
.extern C(r_p2)
.extern C(a_tstepxfrac)
.extern C(r_sstepx)
.extern C(r_tstepx)
.extern C(a_ststepxwhole)
.extern C(zspantable)
.extern C(skintable)
.extern C(r_zistepx)
.extern C(erroradjustdown)
.extern C(d_countextrastep)
.extern C(ubasestep)
.extern C(a_ststepxwhole)
.extern C(a_tstepxfrac)
.extern C(r_lstepx)
.extern C(a_spans)
.extern C(erroradjustdown)
.extern C(d_pdestextrastep)
.extern C(d_pzextrastep)
.extern C(d_sfracextrastep)
.extern C(d_ptexextrastep)
.extern C(d_countextrastep)
.extern C(d_tfracextrastep)
.extern C(d_lightextrastep)
.extern C(d_ziextrastep)
.extern C(d_pdestbasestep)
.extern C(d_pzbasestep)
.extern C(d_sfracbasestep)
.extern C(d_ptexbasestep)
.extern C(ubasestep)
.extern C(d_tfracbasestep)
.extern C(d_lightbasestep)
.extern C(d_zibasestep)
.extern C(zspantable)
.extern C(r_lstepy)
.extern C(r_sstepy)
.extern C(r_tstepy)
.extern C(r_zistepy)
.extern C(D_PolysetSetEdgeTable)
.extern C(D_RasterizeAliasPolySmooth)
.extern float_point5
.extern Float2ToThe31nd
.extern izistep
.extern izi
.extern FloatMinus2ToThe31nd
.extern float_1
.extern float_particle_z_clip
.extern float_minus_1
.extern float_0
.extern fp_16
.extern fp_64k
.extern fp_1m
.extern fp_1m_minus_1
.extern fp_8
.extern entryvec_table
.extern advancetable
.extern sstep
.extern tstep
.extern pspantemp
.extern counttemp
.extern jumptemp
.extern reciprocal_table
.extern DP_Count
.extern DP_u
.extern DP_v
.extern DP_32768
.extern DP_Color
.extern DP_Pix
.extern DP_EntryTable
.extern pbase
.extern s
.extern t
.extern sfracf
.extern tfracf
.extern snext
.extern tnext
.extern spancountminus1
.extern zi16stepu
.extern sdivz16stepu
.extern tdivz16stepu
.extern zi8stepu
.extern sdivz8stepu
.extern tdivz8stepu
.extern reciprocal_table_16
.extern entryvec_table_16
.extern ceil_cw
.extern single_cw
.extern fp_64kx64k
.extern pz
.extern spr8entryvec_table
.extern C(vright)
.extern C(vup)
.extern C(vpn)
#endif // _QUAKEASM_H_

View file

@ -31,7 +31,7 @@
#include "QF/mathlib.h"
#include "QF/cvar.h"
#include "vid.h"
#include "QF/vid.h"
#include "protocol.h"
#define MAXCLIPPLANES 11

View file

@ -1,104 +0,0 @@
/*
vid.h
video driver defs
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$
*/
#ifndef __vid_h_
#define __vid_h_
#include "QF/qtypes.h"
#define VID_CBITS 6
#define VID_GRADES (1 << VID_CBITS)
typedef struct vrect_s {
int x,y,width,height;
struct vrect_s *pnext;
} vrect_t;
typedef struct {
pixel_t *buffer; // invisible buffer
pixel_t *colormap; // 256 * VID_GRADES size
unsigned short *colormap16; // 256 * VID_GRADES size
int fullbright; // index of first fullbright color
unsigned int rowbytes; // may be > width if displayed in a window
unsigned int width;
unsigned int height;
float aspect; // width / height -- < 0 is taller than wide
int numpages;
int recalc_refdef; // if true, recalc vid-based stuff
pixel_t *conbuffer;
int conrowbytes;
unsigned int conwidth;
unsigned int conheight;
int maxwarpwidth;
int maxwarpheight;
pixel_t *direct; // direct drawing to framebuffer, if not
// NULL
} viddef_t;
extern viddef_t vid; // global video state
extern unsigned short d_8to16table[256];
extern unsigned int d_8to24table[256];
extern int scr_width, scr_height;
// called at startup and after any gamma correction
void VID_SetPalette (unsigned char *palette);
// called for bonus and pain flashes, and for underwater color changes
void VID_ShiftPalette (unsigned char *palette);
void VID_Init_Cvars (void);
// 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 *);
// Called at shutdown
void VID_Shutdown (void);
// flushes the given rectangles from the view buffer to the screen
void VID_Update (vrect_t *rects);
// sets the mode; only used by the Quake engine for resetting to mode 0 (the
// base mode) on memory allocation failures
// int VID_SetMode (int modenum, unsigned char *palette);
// called only on Win32, when pause happens, so the mouse can be released
void VID_HandlePause (qboolean pause);
void VID_LockBuffer (void);
void VID_UnlockBuffer (void);
qboolean VID_Is8bit (void);
void VID_SetCaption (char *text);
// used to set window caption
void VID_GetWindowSize (int def_w, int def_h);
#endif // __vid_h_

View file

@ -1,89 +0,0 @@
/*
wad.h
@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$
*/
#ifndef __wad_h
#define __wad_h
#include "QF/qtypes.h"
//===============
// TYPES
//===============
#define CMP_NONE 0
#define CMP_LZSS 1
#define TYP_NONE 0
#define TYP_LABEL 1
#define TYP_LUMPY 64 // 64 + grab command number
#define TYP_PALETTE 64
#define TYP_QTEX 65
#define TYP_QPIC 66
#define TYP_SOUND 67
#define TYP_MIPTEX 68
typedef struct
{
int width, height;
byte data[4]; // variably sized
} qpic_t;
typedef struct
{
char identification[4]; // should be WAD2 or 2DAW
int numlumps;
int infotableofs;
} wadinfo_t;
typedef struct
{
int filepos;
int disksize;
int size; // uncompressed
char type;
char compression;
char pad1, pad2;
char name[16]; // must be null terminated
} lumpinfo_t;
extern int wad_numlumps;
extern lumpinfo_t *wad_lumps;
extern byte *wad_base;
void W_LoadWadFile (char *filename);
void W_CleanupName (char *in, char *out);
lumpinfo_t *W_GetLumpinfo (char *name);
void *W_GetLumpName (char *name);
void *W_GetLumpNum (int num);
void SwapPic (qpic_t *pic);
#endif // __wad_h

View file

@ -394,7 +394,7 @@ SetPal (int i)
old = i;
if (i == 0)
VID_SetPalette (host_basepal);
VID_SetPalette (vid_basepal);
else if (i == 1) {
for (c = 0; c < 768; c += 3) {
pal[c] = 0;

View file

@ -1,7 +1,7 @@
/*
d_fill.c
@description@
clears a specified rectangle to the specified color
Copyright (C) 1996-1997 Id Software, Inc.
@ -30,19 +30,18 @@
# include "config.h"
#endif
#include "vid.h"
#include "d_iface.h"
/*
================
D_FillRect
================
D_FillRect
*/
void
D_FillRect (vrect_t *rect, int color)
{
int rx, ry, rwidth, rheight;
unsigned char *dest;
unsigned *ldest;
unsigned int *ldest;
rx = rect->x;
ry = rect->y;
@ -69,7 +68,7 @@ D_FillRect (vrect_t *rect, int color)
if (((rwidth & 0x03) == 0) && (((long) dest & 0x03) == 0)) {
// faster aligned dword clear
ldest = (unsigned *) dest;
ldest = (unsigned int *) dest;
color += color << 16;
rwidth >>= 2;
@ -78,7 +77,7 @@ D_FillRect (vrect_t *rect, int color)
for (ry = 0; ry < rheight; ry++) {
for (rx = 0; rx < rwidth; rx++)
ldest[rx] = color;
ldest = (unsigned *) ((byte *) ldest + vid.rowbytes);
ldest = (unsigned int *) ((byte *) ldest + vid.rowbytes);
}
} else {
// slower byte-by-byte clear for unaligned cases

View file

@ -31,7 +31,6 @@
#endif
#include "d_local.h"
#include "vid.h"
#define NUM_MIPS 4

View file

@ -31,7 +31,7 @@
#endif
#include "draw.h"
#include "vid.h"
#include "QF/vid.h"
#include "QF/zone.h"
#include "QF/sys.h"
#include "QF/quakefs.h"

View file

@ -37,7 +37,7 @@
#endif
#include "QF/compat.h"
#include "vid.h"
#include "QF/vid.h"
#include "QF/sys.h"
#include "QF/mathlib.h" // needed by: protocol.h, render.h,
// client.h,
@ -58,7 +58,7 @@
static int GL_LoadPicTexture (qpic_t *pic);
extern byte *host_basepal;
extern byte *vid_basepal;
extern unsigned char d_15to8table[65536];
extern cvar_t *crosshair, *cl_crossx, *cl_crossy, *crosshaircolor;
extern qboolean lighthalf;
@ -877,11 +877,11 @@ Draw_Fill (int x, int y, int w, int h, int c)
{
glDisable (GL_TEXTURE_2D);
if (lighthalf)
glColor3f (host_basepal[c * 3] / 510.0, host_basepal[c * 3 + 1] / 510.0,
host_basepal[c * 3 + 2] / 510.0);
glColor3f (vid_basepal[c * 3] / 510.0, vid_basepal[c * 3 + 1] / 510.0,
vid_basepal[c * 3 + 2] / 510.0);
else
glColor3f (host_basepal[c * 3] / 255.0, host_basepal[c * 3 + 1] / 255.0,
host_basepal[c * 3 + 2] / 255.0);
glColor3f (vid_basepal[c * 3] / 255.0, vid_basepal[c * 3 + 1] / 255.0,
vid_basepal[c * 3 + 2] / 255.0);
glBegin (GL_QUADS);

View file

@ -36,7 +36,7 @@
#include <strings.h>
#endif
#include "vid.h"
#include "QF/vid.h"
#include "QF/sys.h"
#include "QF/mathlib.h" // needed by: protocol.h, render.h,
// client.h,

View file

@ -39,7 +39,7 @@
#include "QF/compat.h"
#include "r_local.h"
#include "QF/qargs.h"
#include "vid.h"
#include "QF/vid.h"
#include "QF/sys.h"
#include "QF/mathlib.h" // needed by: protocol.h, render.h,
// client.h,

View file

@ -39,7 +39,7 @@
#include "QF/compat.h"
#include "QF/input.h"
#include "QF/qendian.h"
#include "vid.h"
#include "QF/vid.h"
#include "QF/sys.h"
#include "QF/mathlib.h" // needed by: protocol.h, render.h,
// client.h,
@ -110,7 +110,7 @@ console is:
*/
extern byte *host_basepal;
extern byte *vid_basepal;
extern double host_frametime;
extern double realtime;
int glx, gly, glwidth, glheight;
@ -887,7 +887,7 @@ SCR_BringDownConsole (void)
cl.cshifts[0].percent = 0; // no area contents palette on next
// frame
VID_SetPalette (host_basepal);
VID_SetPalette (vid_basepal);
}
void

View file

@ -46,7 +46,7 @@
#include "QF/sys.h"
#include "QF/va.h"
#include "sbar.h"
#include "vid.h"
#include "QF/vid.h"
#include "draw.h"
#include "QF/input.h"
#include "screen.h"
@ -86,7 +86,7 @@ client_t *host_client; // current client
jmp_buf host_abortserver;
byte *host_basepal;
byte *vid_basepal;
byte *host_colormap;
cvar_t *fs_globalcfg;
@ -960,10 +960,10 @@ Host_Init (quakeparms_t *parms)
R_InitTextures (); // needed even for dedicated servers
if (cls.state != ca_dedicated) {
host_basepal = (byte *) COM_LoadHunkFile ("gfx/palette.lmp");
if (!host_basepal)
vid_basepal = (byte *) COM_LoadHunkFile ("gfx/palette.lmp");
if (!vid_basepal)
Sys_Error ("Couldn't load gfx/palette.lmp");
host_basepal[765] = host_basepal[766] = host_basepal[767] = 0; // LordHavoc:
vid_basepal[765] = vid_basepal[766] = vid_basepal[767] = 0; // LordHavoc:
//
// force
// the
@ -975,7 +975,7 @@ Host_Init (quakeparms_t *parms)
if (!host_colormap)
Sys_Error ("Couldn't load gfx/colormap.lmp");
VID_Init (host_basepal);
VID_Init (vid_basepal);
IN_Init ();
Draw_Init ();

View file

@ -35,7 +35,7 @@
#include "sbar.h"
#include "game.h"
#include "QF/cmd.h"
#include "vid.h"
#include "QF/vid.h"
#include "QF/va.h"
#include "draw.h"
#include "wad.h"

View file

@ -733,7 +733,7 @@ SCR_ScreenShot_f (void)
// buffer
WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
host_basepal);
vid_basepal);
D_DisableBackBufferAccess (); // for adapters that can't stay
// mapped in
@ -887,7 +887,7 @@ SCR_BringDownConsole (void)
cl.cshifts[0].percent = 0; // no area contents palette on next
// frame
VID_SetPalette (host_basepal);
VID_SetPalette (vid_basepal);
}

View file

@ -277,7 +277,7 @@ WarpPalette (void)
for (i = 0; i < 256; i++) {
for (j = 0; j < 3; j++) {
newpalette[i * 3 + j] =
(host_basepal[i * 3 + j] + basecolor[j]) / 2;
(vid_basepal[i * 3 + j] + basecolor[j]) / 2;
}
}

View file

@ -37,7 +37,7 @@
#include "draw.h"
#include "host.h"
#include "view.h"
#include "vid.h"
#include "QF/vid.h"
extern byte gammatable[256];
@ -95,7 +95,7 @@ V_UpdatePalette (void)
if (!new && !force)
return;
basepal = host_basepal;
basepal = vid_basepal;
newpal = pal;
for (i = 0; i < 256; i++) {

View file

@ -30,34 +30,50 @@
# include "config.h"
#endif
#include <math.h>
#include "QF/compat.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "vid.h"
#include "QF/va.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
int scr_width, scr_height;
cvar_t *vid_width;
cvar_t *vid_height;
/*
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;
int pnum;
vid_width =
Cvar_Get ("vid_width", va ("%d", def_w), CVAR_ROM, NULL,
"screen width");
vid_height =
Cvar_Get ("vid_height", va ("%d", def_h), CVAR_ROM, NULL,
"screen height");
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_SetROM (vid_width, com_argv[pnum + 1]);
Cvar_Set (vid_width, com_argv[pnum + 1]);
if (!vid_width->int_val)
Sys_Error ("VID: Bad window width\n");
}
@ -65,7 +81,9 @@ VID_GetWindowSize (int def_w, int def_h)
if ((pnum = COM_CheckParm ("-height"))) {
if (pnum >= com_argc - 1)
Sys_Error ("VID: -height <height>\n");
Cvar_SetROM (vid_height, com_argv[pnum + 1]);
Cvar_Set (vid_height, com_argv[pnum + 1]);
if (!vid_height->int_val)
Sys_Error ("VID: Bad window height\n");
}
@ -73,12 +91,90 @@ VID_GetWindowSize (int def_w, int def_h)
if ((pnum = COM_CheckParm ("-winsize"))) {
if (pnum >= com_argc - 2)
Sys_Error ("VID: -winsize <width> <height>\n");
Cvar_SetROM (vid_width, com_argv[pnum + 1]);
Cvar_SetROM (vid_height, com_argv[pnum + 2]);
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,20 +1,14 @@
## Process this file with automake to produce Makefile.in
AUTOMAKE_OPTIONS= foreign
EXTRA_DIST = adivtab.h anorm_dots.h anorms.h asm_draw.h asm_i386.h block16.h \
block8.h bothdefs.h bspfile.h buildnum.h checksum.h cl_cam.h \
cl_demo.h cl_ents.h cl_input.h cl_main.h cl_parse.h cl_pred.h \
cl_slist.h cl_tent.h client.h cmd.h commdef.h compat.h config.h.in \
console.h context_x11.h crc.h cvar.h d_iface.h d_ifacea.h d_local.h \
dga_check.h draw.h fbset.h fractalnoise.h gcc_attr.h gl_warp_sin.h \
glquake.h hash.h host.h in_win.h info.h input.h joystick.h keys.h \
link.h locs.h mathlib.h mdfour.h model.h modelgen.h msg.h net.h pcx.h \
pmove.h pr_comp.h progdefs.h progs.h protocol.h qargs.h qdefs.h \
qendian.h qfgl_ext.h qtypes.h quakeasm.h quakefs.h quakeio.h \
EXTRA_DIST = adivtab.h anorm_dots.h anorms.h asm_draw.h block16.h block8.h \
bothdefs.h buildnum.h cl_cam.h cl_demo.h cl_ents.h cl_input.h \
cl_main.h cl_parse.h cl_pred.h cl_slist.h cl_tent.h client.h \
commdef.h config.h.in d_iface.h d_ifacea.h d_local.h draw.h \
gcc_attr.h gl_warp_sin.h glquake.h host.h locs.h modelgen.h net.h \
pcx.h pmove.h pr_comp.h progdefs.h protocol.h quakeasm.h \
r_dynamic.h r_local.h r_shared.h render.h sbar.h screen.h server.h \
sizebuf.h skin.h sound.h spritegn.h sv_pr_cmds.h sys.h tga.h \
teamplay.h texture.h uint32.h va.h ver_check.h vid.h view.h wad.h \
winquake.h world.h zone.h \
skin.h sv_pr_cmds.h teamplay.h texture.h tga.h wad.h world.h \
\
win32/fnmatch.h win32/version.h win32/version.h.in \
win32/mingw/config.h \

View file

@ -34,7 +34,7 @@
#include "protocol.h"
#include "QF/quakefs.h"
#include "render.h"
#include "vid.h"
#include "QF/vid.h"
#include "QF/zone.h"
// player_state_t is the information needed by a player entity

View file

@ -1,122 +0,0 @@
/*
d_local.h
Private rasterization driver defs
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$
*/
#ifndef _D_LOCAL_H
#define _D_LOCAL_H
#include "r_shared.h"
//
// TODO: fine-tune this; it's based on providing some overage even if there
// is a 2k-wide scan, with subdivision every 8, for 256 spans of 12 bytes each
//
#define SCANBUFFERPAD 0x1000
#define R_SKY_SMASK 0x007F0000
#define R_SKY_TMASK 0x007F0000
#define DS_SPAN_LIST_END -128
#define SURFCACHE_SIZE_AT_320X200 600*1024
typedef struct surfcache_s
{
struct surfcache_s *next;
struct surfcache_s **owner; // NULL is an empty chunk of memory
int lightadj[MAXLIGHTMAPS]; // checked for strobe flush
int dlight;
int size; // including header
unsigned int width;
unsigned int height; // DEBUG only needed for debug
float mipscale;
struct texture_s *texture; // checked for animating textures
byte data[4]; // width*height elements
} surfcache_t;
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct sspan_s
{
int u, v, count;
} sspan_t;
extern cvar_t *d_subdiv16;
extern float scale_for_mip;
extern qboolean d_roverwrapped;
extern surfcache_t *sc_rover;
extern surfcache_t *d_initial_rover;
extern float d_sdivzstepu, d_tdivzstepu, d_zistepu;
extern float d_sdivzstepv, d_tdivzstepv, d_zistepv;
extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin;
extern fixed16_t sadjust, tadjust;
extern fixed16_t bbextents, bbextentt;
void D_DrawSpans8 (espan_t *pspans);
void D_DrawSpans16 (espan_t *pspans);
void D_DrawZSpans (espan_t *pspans);
void Turbulent8 (espan_t *pspan);
void D_SpriteDrawSpans (sspan_t *pspan);
void D_DrawSkyScans8 (espan_t *pspan);
void D_DrawSkyScans16 (espan_t *pspan);
void R_ShowSubDiv (void);
void (*prealspandrawer)(void);
surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel);
extern int D_MipLevelForScale (float scale);
#ifdef USE_INTEL_ASM
extern void D_PolysetAff8Start (void);
extern void D_PolysetAff8End (void);
#endif
extern short *d_pzbuffer;
extern unsigned int d_zrowbytes, d_zwidth;
extern int *d_pscantable;
extern int d_scantable[MAXHEIGHT];
extern int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
extern int d_y_aspect_shift, d_pix_min, d_pix_max, d_pix_shift;
extern pixel_t *d_viewbuffer;
extern short *zspantable[MAXHEIGHT];
extern int d_minmip;
extern float d_scalemip[3];
extern void (*d_drawspans) (espan_t *pspan);
#endif // _D_LOCAL_H

View file

@ -49,8 +49,6 @@ extern struct cvar_s *password;
extern double host_frametime; // Tonik
extern byte *host_basepal;
extern byte *host_colormap;
extern int host_framecount; // incremented every frame, never reset
extern qboolean msg_suppress_1; // Suppresses resolution and cache size

View file

@ -31,7 +31,7 @@
#include "QF/mathlib.h"
#include "QF/cvar.h"
#include "vid.h"
#include "QF/vid.h"
#include "client.h"
#include "QF/model.h"
#include "pmove.h"

View file

@ -1,162 +0,0 @@
/*
r_shared.h
general refresh-related stuff shared between the refresh and the driver
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$
*/
// FIXME: clean up and move into d_iface.h
#ifndef _R_SHARED_H
#define _R_SHARED_H
#include "QF/mathlib.h"
#include "QF/cvar.h"
#include "QF/model.h"
#include "d_iface.h"
#define MAXVERTS 16 // max points in a surface polygon
#define MAXWORKINGVERTS (MAXVERTS+4) // max points in an intermediate
// polygon (while processing)
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
#define MAXHEIGHT 1024
#define MAXWIDTH 1280
#define INFINITE_DISTANCE 0x10000 // distance that's always guaranteed to
// be farther away than anything in
// the scene
//===================================================================
extern void R_DrawLine (polyvert_t *polyvert0, polyvert_t *polyvert1);
extern int cachewidth;
extern pixel_t *cacheblock;
extern int screenwidth;
extern float pixelAspect;
extern int r_drawnpolycount;
extern cvar_t *r_clearcolor;
extern int sintable[1280];
extern int intsintable[1280];
extern vec3_t vup, base_vup;
extern vec3_t vpn, base_vpn;
extern vec3_t vright, base_vright;
extern entity_t *currententity;
#define NUMSTACKEDGES 2000
#define MINEDGES NUMSTACKEDGES
#define NUMSTACKSURFACES 1000
#define MINSURFACES NUMSTACKSURFACES
#define MAXSPANS 3000
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct espan_s
{
int u, v, count;
struct espan_s *pnext;
} espan_t;
// FIXME: compress, make a union if that will help
// insubmodel is only 1, flags is fewer than 32, spanstate could be a byte
typedef struct surf_s
{
struct surf_s *next; // active surface stack in r_edge.c
struct surf_s *prev; // used in r_edge.c for active surf stack
struct espan_s *spans; // pointer to linked list of spans to draw
int key; // sorting key (BSP order)
int last_u; // set during tracing
int spanstate; // 0 = not in span
// 1 = in span
// -1 = in inverted span (end before
// start)
int flags; // currentface flags
void *data; // associated data like msurface_t
entity_t *entity;
float nearzi; // nearest 1/z on surface, for mipmapping
qboolean insubmodel;
float d_ziorigin, d_zistepu, d_zistepv;
int pad[2]; // to 64 bytes
} surf_t;
extern surf_t *surfaces, *surface_p, *surf_max;
// surfaces are generated in back to front order by the bsp, so if a surf
// pointer is greater than another one, it should be drawn in front
// surfaces[1] is the background, and is used as the active surface stack.
// surfaces[0] is a dummy, because index 0 is used to indicate no surface
// attached to an edge_t
//===================================================================
extern vec3_t sxformaxis[4]; // s axis transformed into viewspace
extern vec3_t txformaxis[4]; // t axis transformed into viewspac
extern vec3_t modelorg, base_modelorg;
extern float xcenter, ycenter;
extern float xscale, yscale;
extern float xscaleinv, yscaleinv;
extern float xscaleshrink, yscaleshrink;
extern int d_lightstylevalue[256]; // 8.8 frac of base light value
extern void TransformVector (vec3_t in, vec3_t out);
extern void SetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv,
fixed8_t endvertu, fixed8_t endvertv);
extern int r_skymade;
extern void R_MakeSky (void);
extern int ubasestep, errorterm, erroradjustup, erroradjustdown;
// flags in finalvert_t.flags
#define ALIAS_LEFT_CLIP 0x0001
#define ALIAS_TOP_CLIP 0x0002
#define ALIAS_RIGHT_CLIP 0x0004
#define ALIAS_BOTTOM_CLIP 0x0008
#define ALIAS_Z_CLIP 0x0010
// !!! if this is changed, it must be changed in d_ifacea.h too !!!
#define ALIAS_ONSEAM 0x0020 // also defined in modelgen.h;
// must be kept in sync
#define ALIAS_XY_CLIP_MASK 0x000F
// !!! if this is changed, it must be changed in asm_draw.h too !!!
typedef struct edge_s
{
fixed16_t u;
fixed16_t u_step;
struct edge_s *prev, *next;
unsigned short surfs[2];
struct edge_s *nextremove;
float nearzi;
medge_t *owner;
} edge_t;
#endif // _R_SHARED_H

View file

@ -32,7 +32,7 @@
#include "QF/mathlib.h"
#include "QF/model.h"
#include "QF/cvar.h"
#include "vid.h"
#include "QF/vid.h"
//#include "model.h"
//now we know why (struct model_s *) is used here instead of model_t
//damn circular reference ! same with player_info_s -- yan

View file

@ -93,7 +93,7 @@
#include "QF/sound.h"
#include "QF/sys.h"
#include "teamplay.h"
#include "vid.h"
#include "QF/vid.h"
#include "view.h"
#include "QF/va.h"
@ -189,8 +189,8 @@ int host_framecount;
int host_hunklevel;
byte *host_basepal;
byte *host_colormap;
byte *vid_basepal;
byte *vid_colormap;
cvar_t *host_speeds; // set for running times
cvar_t *show_fps; // set for running times
@ -1634,15 +1634,15 @@ Host_Init (void)
R_Textures_Init ();
host_basepal = (byte *) COM_LoadHunkFile ("gfx/palette.lmp");
if (!host_basepal)
vid_basepal = (byte *) COM_LoadHunkFile ("gfx/palette.lmp");
if (!vid_basepal)
Sys_Error ("Couldn't load gfx/palette.lmp");
host_colormap = (byte *) COM_LoadHunkFile ("gfx/colormap.lmp");
if (!host_colormap)
vid_colormap = (byte *) COM_LoadHunkFile ("gfx/colormap.lmp");
if (!vid_colormap)
Sys_Error ("Couldn't load gfx/colormap.lmp");
#ifdef __linux__
CDAudio_Init ();
VID_Init (host_basepal);
VID_Init (vid_basepal);
IN_Init ();
Draw_Init ();
SCR_Init ();
@ -1655,7 +1655,7 @@ Host_Init (void)
Skin_Init ();
CL_Init ();
#else
VID_Init (host_basepal);
VID_Init (vid_basepal);
Draw_Init ();
SCR_Init ();
R_Init ();
@ -1719,6 +1719,6 @@ Host_Shutdown (void)
NET_Shutdown ();
S_Shutdown ();
IN_Shutdown ();
if (host_basepal)
if (vid_basepal)
VID_Shutdown ();
}

View file

@ -47,7 +47,7 @@
#include "screen.h"
#include "QF/sound.h"
#include "QF/sys.h"
#include "vid.h"
#include "QF/vid.h"
qboolean is_server = false;
char *svs_info;

View file

@ -47,7 +47,7 @@
#include "QF/sys.h"
extern byte *host_basepal;
extern byte *vid_basepal;
extern cvar_t *crosshair, *cl_crossx, *cl_crossy, *crosshaircolor,
*gl_lightmap_components;
@ -684,11 +684,11 @@ Draw_Fill (int x, int y, int w, int h, int c)
{
glDisable (GL_TEXTURE_2D);
if (lighthalf)
glColor3f (host_basepal[c * 3] / 510.0, host_basepal[c * 3 + 1] / 510.0,
host_basepal[c * 3 + 2] / 510.0);
glColor3f (vid_basepal[c * 3] / 510.0, vid_basepal[c * 3 + 1] / 510.0,
vid_basepal[c * 3 + 2] / 510.0);
else
glColor3f (host_basepal[c * 3] / 255.0, host_basepal[c * 3 + 1] / 255.0,
host_basepal[c * 3 + 2] / 255.0);
glColor3f (vid_basepal[c * 3] / 255.0, vid_basepal[c * 3 + 1] / 255.0,
vid_basepal[c * 3 + 2] / 255.0);
glBegin (GL_QUADS);

View file

@ -55,7 +55,7 @@
#include "locs.h"
#include "r_dynamic.h"
#include "skin.h"
#include "vid.h"
#include "QF/vid.h"
#include "view.h"
entity_t r_worldentity;

View file

@ -45,7 +45,7 @@
#include "r_dynamic.h"
#include "skin.h"
#include "QF/sys.h"
#include "vid.h"
#include "QF/vid.h"
qboolean VID_Is8bit (void);
void R_InitBubble (void);

View file

@ -673,9 +673,9 @@ MipColor (int r, int g, int b)
bestdist = 256 * 256 * 3;
for (i = 0; i < 256; i++) {
r1 = host_basepal[i * 3] - r;
g1 = host_basepal[i * 3 + 1] - g;
b1 = host_basepal[i * 3 + 2] - b;
r1 = vid_basepal[i * 3] - r;
g1 = vid_basepal[i * 3 + 1] - g;
b1 = vid_basepal[i * 3 + 2] - b;
dist = r1 * r1 + g1 * g1 + b1 * b1;
if (dist < bestdist) {
bestdist = dist;
@ -834,7 +834,7 @@ SCR_RSShot_f (void)
st[sizeof (st) - 1] = 0;
SCR_DrawStringToSnap (st, newbuf, w - strlen (st) * 8, h - 21, w);
WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true, true);
WritePCXfile (pcxname, newbuf, w, h, w, vid_basepal, true, true);
free (newbuf);

View file

@ -44,7 +44,7 @@
#include "QF/compat.h"
extern byte *host_basepal;
extern byte *vid_basepal;
extern double host_frametime;
extern int onground;
extern byte gammatable[256];

View file

@ -98,7 +98,7 @@ LoadPCX (QFile *f, int convert)
if (convert) {
tex->palette = 0;
} else {
tex->palette = host_basepal;
tex->palette = vid_basepal;
}
pix = tex->data;

View file

@ -42,7 +42,7 @@
#include "QF/msg.h"
#include "pmove.h"
#include "screen.h"
#include "vid.h"
#include "QF/vid.h"
#include "view.h"
/*

View file

@ -48,7 +48,7 @@
#include "sbar.h"
#include "screen.h"
#include "QF/va.h"
#include "vid.h"
#include "QF/vid.h"
int sb_updates; // if >= vid.numpages, no update

View file

@ -51,7 +51,7 @@
#include "sbar.h"
#include "skin.h"
#include "QF/sys.h"
#include "vid.h"
#include "QF/vid.h"
#include "view.h"
/*
@ -664,7 +664,7 @@ SCR_ScreenShot_f (void)
// save the pcx file
WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
host_basepal, false, false);
vid_basepal, false, false);
// for adapters that can't stay mapped in for linear writes all the time
D_DisableBackBufferAccess ();
@ -692,9 +692,9 @@ MipColor (int r, int g, int b)
bestdist = 256 * 256 * 3;
for (i = 0; i < 256; i++) {
r1 = host_basepal[i * 3] - r;
g1 = host_basepal[i * 3 + 1] - g;
b1 = host_basepal[i * 3 + 2] - b;
r1 = vid_basepal[i * 3] - r;
g1 = vid_basepal[i * 3 + 1] - g;
b1 = vid_basepal[i * 3 + 2] - b;
dist = r1 * r1 + g1 * g1 + b1 * b1;
if (dist < bestdist) {
bestdist = dist;
@ -815,9 +815,9 @@ SCR_RSShot_f (void)
for ( /* */ ; dy < dey; dy++) {
src = vid.buffer + (vid.rowbytes * dy) + dx;
for (nx = dx; nx < dex; nx++) {
r += host_basepal[*src * 3];
g += host_basepal[*src * 3 + 1];
b += host_basepal[*src * 3 + 2];
r += vid_basepal[*src * 3];
g += vid_basepal[*src * 3 + 1];
b += vid_basepal[*src * 3 + 2];
src++;
count++;
}
@ -842,7 +842,7 @@ SCR_RSShot_f (void)
st[sizeof (st) - 1] = 0;
SCR_DrawStringToSnap (st, newbuf, w - strlen (st) * 8, 20, w);
WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true, false);
WritePCXfile (pcxname, newbuf, w, h, w, vid_basepal, true, false);
free (newbuf);

View file

@ -181,7 +181,7 @@ Skin_Cache (skin_t *skin)
opix = out->data;
out->width = 320;
out->height = 200;
out->palette = tex->palette; //FIXME assumes 0 or host_basepal
out->palette = tex->palette; //FIXME assumes 0 or vid_basepal
memset (opix, 0, pixels);
for (i = 0, ipix = tex->data; i < tex->height;
i++, opix += 320, ipix += tex->width)

View file

@ -350,7 +350,7 @@ WarpPalette (void)
for (i = 0; i < 256; i++) {
for (j = 0; j < 3; j++) {
newpalette[i * 3 + j] =
(host_basepal[i * 3 + j] + basecolor[j]) / 2;
(vid_basepal[i * 3 + j] + basecolor[j]) / 2;
}
}

View file

@ -42,7 +42,7 @@
#include "skin.h"
#include "QF/compat.h"
#include "QF/sys.h"
#include "vid.h"
#include "QF/vid.h"
void
Skin_Set_Translate (player_info_t *player)

View file

@ -128,7 +128,7 @@ V_UpdatePalette (void)
if (!new && !force)
return;
basepal = host_basepal;
basepal = vid_basepal;
newpal = pal;
for (i = 0; i < 256; i++) {

View file

@ -29,6 +29,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <math.h>
#include "QF/compat.h"
@ -37,7 +38,7 @@
#include "QF/qargs.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "vid.h"
#include "QF/vid.h"
#include "view.h"
extern viddef_t vid; // global video state
@ -114,19 +115,21 @@ VID_BuildGammaTable (double gamma)
{
int i;
gammatable[0] = 0;
if (gamma == 1.0) { // linear, don't bother with the math
for (i = 0; i < 256; i++) {
for (i = 1; i < 255; i++) {
gammatable[i] = i;
}
} else {
double g = 1.0 / gamma;
int v;
for (i = 0; i < 256; i++) { // Build/update gamma lookup table
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;
}
/*