mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-10 06:42:26 +00:00
backport the gamma code from the quakeforge tree in preparation for 0.3.1
Doesn't work yet because VID_UpdateGamma needs to be called at the appropriate time and cvar callbacks are not implemented in newtree.
This commit is contained in:
parent
b9caa4273c
commit
bd06625c55
15 changed files with 353 additions and 192 deletions
|
@ -36,32 +36,35 @@
|
|||
|
||||
#include "qtypes.h"
|
||||
|
||||
void GetEvent( void );
|
||||
|
||||
extern Display *x_disp;
|
||||
extern int x_screen;
|
||||
extern Window x_root;
|
||||
extern XVisualInfo *x_visinfo;
|
||||
extern Visual *x_vis;
|
||||
extern Visual *x_vis;
|
||||
extern Window x_root;
|
||||
extern Window x_win;
|
||||
extern qboolean doShm;
|
||||
extern XVisualInfo *x_visinfo;
|
||||
extern double x_gamma;
|
||||
extern int x_screen;
|
||||
extern int x_shmeventtype;
|
||||
extern qboolean doShm;
|
||||
extern qboolean oktodraw;
|
||||
extern struct cvar_s *vid_fullscreen;
|
||||
extern struct cvar_s *vid_fullscreen;
|
||||
|
||||
qboolean x11_add_event (int event, void (*event_handler)(XEvent *));
|
||||
qboolean x11_del_event (int event, void (*event_handler)(XEvent *));
|
||||
void x11_process_event (void);
|
||||
void x11_process_events (void);
|
||||
void x11_open_display (void);
|
||||
void x11_close_display (void);
|
||||
void x11_create_null_cursor (void);
|
||||
void x11_set_vidmode (int, int);
|
||||
void x11_restore_vidmode (void);
|
||||
void x11_create_window (int, int);
|
||||
void x11_grab_keyboard (void);
|
||||
void x11_set_caption (char *);
|
||||
void x11_force_view_port (void);
|
||||
void x11_Init_Cvars (void);
|
||||
void GetEvent (void);
|
||||
|
||||
double X11_GetGamma (void);
|
||||
qboolean X11_AddEvent (int event, void (*event_handler)(XEvent *));
|
||||
qboolean X11_RemoveEvent (int event, void (*event_handler)(XEvent *));
|
||||
qboolean X11_SetGamma (double);
|
||||
void X11_CloseDisplay (void);
|
||||
void X11_CreateNullCursor (void);
|
||||
void X11_CreateWindow (int, int);
|
||||
void X11_ForceViewPort (void);
|
||||
void X11_GrabKeyboard (void);
|
||||
void X11_Init_Cvars (void);
|
||||
void X11_OpenDisplay (void);
|
||||
void X11_ProcessEvent (void);
|
||||
void X11_ProcessEvents (void);
|
||||
void X11_RestoreVidMode (void);
|
||||
void X11_SetCaption (char *);
|
||||
void X11_SetVidMode (int, int);
|
||||
|
||||
#endif // __context_x11_h_
|
||||
|
|
|
@ -65,6 +65,7 @@ extern unsigned short d_8to16table[256];
|
|||
extern unsigned int d_8to24table[256];
|
||||
extern int scr_width, scr_height;
|
||||
extern qboolean DDActive;
|
||||
extern byte gammatable[256];
|
||||
|
||||
// called at startup and after any gamma correction
|
||||
void VID_SetPalette (unsigned char *palette);
|
||||
|
@ -108,4 +109,9 @@ void VID_GetWindowSize (int def_w, int def_h);
|
|||
int VID_ForceUnlockedAndReturnState (void);
|
||||
void VID_ForceLockState (int lk);
|
||||
|
||||
void VID_InitGamma (unsigned char *);
|
||||
double VID_GetGamma (void);
|
||||
qboolean VID_SetGamma (double);
|
||||
void VID_UpdateGamma (struct cvar_s *);
|
||||
|
||||
#endif // __vid_h_
|
||||
|
|
|
@ -60,7 +60,6 @@
|
|||
# include <X11/extensions/xf86vmode.h>
|
||||
#endif
|
||||
|
||||
#include "commdef.h"
|
||||
#include "console.h"
|
||||
#include "context_x11.h"
|
||||
#include "cvar.h"
|
||||
|
@ -73,47 +72,51 @@
|
|||
#include "vid.h"
|
||||
|
||||
static void (*event_handlers[LASTEvent]) (XEvent *);
|
||||
qboolean oktodraw = false;
|
||||
int x_shmeventtype;
|
||||
qboolean oktodraw = false;
|
||||
int x_shmeventtype;
|
||||
|
||||
static int x_disp_ref_count = 0;
|
||||
static int x_disp_ref_count = 0;
|
||||
|
||||
Display *x_disp = NULL;
|
||||
int x_screen;
|
||||
Window x_root = None;
|
||||
Display *x_disp = NULL;
|
||||
int x_screen;
|
||||
Window x_root = None;
|
||||
XVisualInfo *x_visinfo;
|
||||
Visual *x_vis;
|
||||
Window x_win;
|
||||
Cursor nullcursor = None;
|
||||
Visual *x_vis;
|
||||
Window x_win;
|
||||
Cursor nullcursor = None;
|
||||
static Atom aWMDelete = 0;
|
||||
|
||||
#define X_MASK (VisibilityChangeMask | StructureNotifyMask | ExposureMask)
|
||||
|
||||
#ifdef HAVE_VIDMODE
|
||||
static XF86VidModeModeInfo **vidmodes;
|
||||
static int nummodes;
|
||||
static int nummodes;
|
||||
static int original_mode = 0;
|
||||
#endif
|
||||
|
||||
static qboolean vidmode_avail = false;
|
||||
static qboolean vidmode_active = false;
|
||||
|
||||
cvar_t *vid_fullscreen;
|
||||
qboolean vid_fullscreen_active;
|
||||
cvar_t *vid_fullscreen;
|
||||
cvar_t *vid_system_gamma;
|
||||
qboolean vid_gamma_avail;
|
||||
qboolean vid_fullscreen_active;
|
||||
static double x_gamma;
|
||||
|
||||
static int xss_timeout;
|
||||
static int xss_interval;
|
||||
static int xss_blanking;
|
||||
static int xss_exposures;
|
||||
static int xss_timeout;
|
||||
static int xss_interval;
|
||||
static int xss_blanking;
|
||||
static int xss_exposures;
|
||||
|
||||
qboolean
|
||||
x11_add_event (int event, void (*event_handler) (XEvent *))
|
||||
X11_AddEvent (int event, void (*event_handler) (XEvent *))
|
||||
{
|
||||
if (event >= LASTEvent) {
|
||||
printf ("event: %d, LASTEvent: %d\n", event, LASTEvent);
|
||||
return false;
|
||||
}
|
||||
if (event_handlers[event] != NULL)
|
||||
|
||||
if (event_handlers[event])
|
||||
return false;
|
||||
|
||||
event_handlers[event] = event_handler;
|
||||
|
@ -121,10 +124,11 @@ x11_add_event (int event, void (*event_handler) (XEvent *))
|
|||
}
|
||||
|
||||
qboolean
|
||||
x11_del_event (int event, void (*event_handler) (XEvent *))
|
||||
X11_RemoveEvent (int event, void (*event_handler) (XEvent *))
|
||||
{
|
||||
if (event >= LASTEvent)
|
||||
return false;
|
||||
|
||||
if (event_handlers[event] != event_handler)
|
||||
return false;
|
||||
|
||||
|
@ -133,7 +137,7 @@ x11_del_event (int event, void (*event_handler) (XEvent *))
|
|||
}
|
||||
|
||||
void
|
||||
x11_process_event (void)
|
||||
X11_ProcessEvent (void)
|
||||
{
|
||||
XEvent x_event;
|
||||
|
||||
|
@ -149,11 +153,11 @@ x11_process_event (void)
|
|||
}
|
||||
|
||||
void
|
||||
x11_process_events (void)
|
||||
X11_ProcessEvents (void)
|
||||
{
|
||||
/* Get events from X server. */
|
||||
while (XPending (x_disp)) {
|
||||
x11_process_event ();
|
||||
X11_ProcessEvent ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,12 +177,12 @@ TragicDeath (int sig)
|
|||
}
|
||||
|
||||
void
|
||||
x11_open_display (void)
|
||||
X11_OpenDisplay (void)
|
||||
{
|
||||
if (!x_disp) {
|
||||
x_disp = XOpenDisplay (NULL);
|
||||
if (!x_disp) {
|
||||
Sys_Error ("x11_open_display: Could not open display [%s]\n",
|
||||
Sys_Error ("X11_OpenDisplay: Could not open display [%s]\n",
|
||||
XDisplayName (NULL));
|
||||
}
|
||||
|
||||
|
@ -193,7 +197,7 @@ x11_open_display (void)
|
|||
signal (SIGTRAP, TragicDeath);
|
||||
signal (SIGIOT, TragicDeath);
|
||||
signal (SIGBUS, TragicDeath);
|
||||
/* signal(SIGFPE, TragicDeath); */
|
||||
// signal(SIGFPE, TragicDeath);
|
||||
signal (SIGSEGV, TragicDeath);
|
||||
signal (SIGTERM, TragicDeath);
|
||||
|
||||
|
@ -207,7 +211,7 @@ x11_open_display (void)
|
|||
}
|
||||
|
||||
void
|
||||
x11_close_display (void)
|
||||
X11_CloseDisplay (void)
|
||||
{
|
||||
if (nullcursor != None) {
|
||||
XFreeCursor (x_disp, nullcursor);
|
||||
|
@ -221,17 +225,17 @@ x11_close_display (void)
|
|||
}
|
||||
|
||||
/*
|
||||
x11_create_null_cursor
|
||||
X11_CreateNullCursor
|
||||
|
||||
Create an empty cursor
|
||||
Create an empty cursor (in other words, make it disappear)
|
||||
*/
|
||||
void
|
||||
x11_create_null_cursor (void)
|
||||
X11_CreateNullCursor (void)
|
||||
{
|
||||
Pixmap cursormask;
|
||||
XGCValues xgc;
|
||||
GC gc;
|
||||
XColor dummycolour;
|
||||
Pixmap cursormask;
|
||||
XGCValues xgc;
|
||||
GC gc;
|
||||
XColor dummycolour;
|
||||
|
||||
if (nullcursor != None)
|
||||
return;
|
||||
|
@ -254,7 +258,7 @@ x11_create_null_cursor (void)
|
|||
}
|
||||
|
||||
void
|
||||
x11_set_vidmode (int width, int height)
|
||||
X11_SetVidMode (int width, int height)
|
||||
{
|
||||
const char *str = getenv ("MESA_GLX_FX");
|
||||
|
||||
|
@ -268,6 +272,10 @@ x11_set_vidmode (int width, int height)
|
|||
#ifdef HAVE_VIDMODE
|
||||
vidmode_avail = VID_CheckVMode (x_disp, NULL, NULL);
|
||||
|
||||
if (vidmode_avail) {
|
||||
vid_gamma_avail = ((x_gamma = X11_GetGamma ()) > 0);
|
||||
}
|
||||
|
||||
if (vid_fullscreen->int_val && vidmode_avail) {
|
||||
|
||||
int i, dotclock;
|
||||
|
@ -300,25 +308,27 @@ x11_set_vidmode (int width, int height)
|
|||
|
||||
XSetScreenSaver (x_disp, 0, xss_interval, xss_blanking, xss_exposures);
|
||||
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[best_mode]);
|
||||
x11_force_view_port ();
|
||||
X11_ForceViewPort ();
|
||||
vidmode_active = true;
|
||||
} else {
|
||||
Con_Printf ("VID: Mode %dx%d can't go fullscreen.\n", vid.width, vid.height);
|
||||
vidmode_avail = vidmode_active = false;
|
||||
vid_gamma_avail = vidmode_avail = vidmode_active = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
x11_Init_Cvars (void)
|
||||
X11_Init_Cvars (void)
|
||||
{
|
||||
vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ROM,
|
||||
"Toggles fullscreen game mode");
|
||||
vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE,
|
||||
"Use system gamma control if available");
|
||||
}
|
||||
|
||||
void
|
||||
x11_create_window (int width, int height)
|
||||
X11_CreateWindow (int width, int height)
|
||||
{
|
||||
XSetWindowAttributes attr;
|
||||
XClassHint *ClassHint;
|
||||
|
@ -355,7 +365,7 @@ x11_create_window (int width, int height)
|
|||
XFree (SizeHints);
|
||||
}
|
||||
// Set window title
|
||||
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
|
||||
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
|
||||
|
||||
// Set icon name
|
||||
XSetIconName (x_disp, x_win, PROGRAM);
|
||||
|
@ -378,7 +388,7 @@ x11_create_window (int width, int height)
|
|||
XMoveWindow (x_disp, x_win, 0, 0);
|
||||
XWarpPointer (x_disp, None, x_win, 0, 0, 0, 0,
|
||||
vid.width + 2, vid.height + 2);
|
||||
x11_force_view_port ();
|
||||
X11_ForceViewPort ();
|
||||
}
|
||||
|
||||
XMapWindow (x_disp, x_win);
|
||||
|
@ -389,13 +399,14 @@ x11_create_window (int width, int height)
|
|||
}
|
||||
|
||||
void
|
||||
x11_restore_vidmode (void)
|
||||
X11_RestoreVidMode (void)
|
||||
{
|
||||
XSetScreenSaver (x_disp, xss_timeout, xss_interval, xss_blanking,
|
||||
xss_exposures);
|
||||
|
||||
#ifdef HAVE_VIDMODE
|
||||
if (vidmode_active) {
|
||||
X11_SetGamma (x_gamma);
|
||||
XF86VidModeSwitchToMode (x_disp, x_screen, vidmodes[original_mode]);
|
||||
XFree (vidmodes);
|
||||
}
|
||||
|
@ -403,7 +414,7 @@ x11_restore_vidmode (void)
|
|||
}
|
||||
|
||||
void
|
||||
x11_grab_keyboard (void)
|
||||
X11_GrabKeyboard (void)
|
||||
{
|
||||
#ifdef HAVE_VIDMODE
|
||||
if (vidmode_active && vid_fullscreen->int_val) {
|
||||
|
@ -414,14 +425,14 @@ x11_grab_keyboard (void)
|
|||
}
|
||||
|
||||
void
|
||||
x11_set_caption (char *text)
|
||||
X11_SetCaption (char *text)
|
||||
{
|
||||
if (x_disp && x_win && text)
|
||||
XStoreName (x_disp, x_win, text);
|
||||
}
|
||||
|
||||
void
|
||||
x11_force_view_port (void)
|
||||
X11_ForceViewPort (void)
|
||||
{
|
||||
#ifdef HAVE_VIDMODE
|
||||
int x, y;
|
||||
|
@ -435,3 +446,37 @@ x11_force_view_port (void)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
double
|
||||
X11_GetGamma (void)
|
||||
{
|
||||
#ifdef HAVE_VIDMODE
|
||||
# ifdef X_XF86VidModeGetGamma
|
||||
XF86VidModeGamma xgamma;
|
||||
|
||||
if (vidmode_avail && vid_system_gamma->int_val) {
|
||||
if (XF86VidModeGetGamma (x_disp, x_screen, &xgamma)) {
|
||||
return ((xgamma.red + xgamma.green + xgamma.blue) / 3);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
qboolean
|
||||
X11_SetGamma (double gamma)
|
||||
{
|
||||
#ifdef HAVE_VIDMODE
|
||||
# ifdef X_XF86VidModeSetGamma
|
||||
XF86VidModeGamma xgamma;
|
||||
|
||||
if (vidmode_avail && vid_system_gamma->int_val) {
|
||||
xgamma.red = xgamma.green = xgamma.blue = (float) gamma;
|
||||
if (XF86VidModeSetGamma (x_disp, x_screen, &xgamma))
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -426,7 +426,7 @@ void
|
|||
IN_SendKeyEvents (void)
|
||||
{
|
||||
/* Get events from X server. */
|
||||
x11_process_events ();
|
||||
X11_ProcessEvents ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -487,7 +487,7 @@ IN_Shutdown (void)
|
|||
XF86DGADirectVideo (x_disp, DefaultScreen (x_disp), 0);
|
||||
#endif
|
||||
}
|
||||
x11_close_display ();
|
||||
X11_CloseDisplay ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -505,7 +505,7 @@ IN_Init (void)
|
|||
if (!x_win)
|
||||
Sys_Error ("IN: No window!!\n");
|
||||
|
||||
x11_open_display (); // call to increment the reference
|
||||
X11_OpenDisplay (); // call to increment the reference
|
||||
// counter
|
||||
|
||||
{
|
||||
|
@ -536,11 +536,11 @@ IN_Init (void)
|
|||
mouse_x = mouse_y = 0.0;
|
||||
mouse_avail = 1;
|
||||
|
||||
x11_add_event (KeyPress, &event_key);
|
||||
x11_add_event (KeyRelease, &event_key);
|
||||
x11_add_event (ButtonPress, &event_button);
|
||||
x11_add_event (ButtonRelease, &event_button);
|
||||
x11_add_event (MotionNotify, &event_motion);
|
||||
X11_AddEvent (KeyPress, &event_key);
|
||||
X11_AddEvent (KeyRelease, &event_key);
|
||||
X11_AddEvent (ButtonPress, &event_button);
|
||||
X11_AddEvent (ButtonRelease, &event_button);
|
||||
X11_AddEvent (MotionNotify, &event_motion);
|
||||
|
||||
Cmd_AddCommand ("force_centerview", Force_CenterView_f, "Force view of player to center");
|
||||
}
|
||||
|
|
|
@ -43,11 +43,11 @@
|
|||
static int snd_inited;
|
||||
|
||||
static snd_pcm_t *pcm;
|
||||
static const snd_pcm_channel_area_t *mmap_areas;
|
||||
static char *pcmname = NULL;
|
||||
size_t buffer_size;
|
||||
|
||||
qboolean SNDDMA_Init(void)
|
||||
qboolean
|
||||
SNDDMA_Init(void)
|
||||
{
|
||||
int err,i;
|
||||
int rate=-1,bps=-1,stereo=-1,frag_size;
|
||||
|
@ -189,19 +189,17 @@ qboolean SNDDMA_Init(void)
|
|||
goto error;
|
||||
}
|
||||
|
||||
mmap_areas = snd_pcm_mmap_running_areas(pcm);
|
||||
|
||||
shm=&sn;
|
||||
memset((dma_t*)shm,0,sizeof(*shm));
|
||||
shm->splitbuffer = 0;
|
||||
shm->channels=stereo+1;
|
||||
shm->submission_chunk=snd_pcm_hw_params_get_period_size(hw, 0); // don't mix less than this #
|
||||
shm->submission_chunk = snd_pcm_hw_params_get_period_size (hw, 0); // don't mix less than this #
|
||||
shm->samplepos=0; // in mono samples
|
||||
shm->samplebits=bps;
|
||||
buffer_size = snd_pcm_hw_params_get_buffer_size(hw);
|
||||
shm->samples=buffer_size*shm->channels; // mono samples in buffer
|
||||
shm->speed=rate;
|
||||
shm->buffer=(unsigned char*)mmap_areas->addr;
|
||||
SNDDMA_GetDMAPos ();//XXX sets shm->buffer
|
||||
Con_Printf("%5d stereo\n", shm->channels - 1);
|
||||
Con_Printf("%5d samples\n", shm->samples);
|
||||
Con_Printf("%5d samplepos\n", shm->samplepos);
|
||||
|
@ -218,92 +216,64 @@ qboolean SNDDMA_Init(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
get_hw_ptr()
|
||||
int
|
||||
SNDDMA_GetDMAPos(void)
|
||||
{
|
||||
size_t app_ptr;
|
||||
snd_pcm_sframes_t delay;
|
||||
int hw_ptr;
|
||||
snd_pcm_uframes_t offset;
|
||||
snd_pcm_uframes_t nframes = shm->samples/shm->channels;
|
||||
const snd_pcm_channel_area_t *areas;
|
||||
|
||||
if (snd_pcm_state (pcm) != SND_PCM_STATE_RUNNING)
|
||||
if (!snd_inited)
|
||||
return 0;
|
||||
app_ptr = snd_pcm_mmap_offset (pcm);
|
||||
snd_pcm_delay (pcm, &delay);
|
||||
hw_ptr = app_ptr - delay;
|
||||
if (hw_ptr < 0)
|
||||
hw_ptr += buffer_size;
|
||||
return hw_ptr;
|
||||
}
|
||||
|
||||
int SNDDMA_GetDMAPos(void)
|
||||
{
|
||||
int hw_ptr;
|
||||
snd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);
|
||||
offset *= shm->channels;
|
||||
nframes *= shm->channels;
|
||||
shm->samplepos = offset;
|
||||
shm->buffer = areas->addr;//XXX FIXME there's an area per channel
|
||||
|
||||
if (!snd_inited) return 0;
|
||||
|
||||
hw_ptr = get_hw_ptr();
|
||||
hw_ptr *= shm->channels;
|
||||
shm->samplepos = hw_ptr;
|
||||
return shm->samplepos;
|
||||
}
|
||||
|
||||
void SNDDMA_Shutdown(void)
|
||||
void
|
||||
SNDDMA_Shutdown(void)
|
||||
{
|
||||
if (snd_inited)
|
||||
{
|
||||
if (snd_inited) {
|
||||
snd_pcm_close(pcm);
|
||||
snd_inited = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
SNDDMA_Submit
|
||||
SNDDMA_Submit
|
||||
|
||||
Send sound to device if buffer isn't really the dma buffer
|
||||
===============
|
||||
Send sound to device if buffer isn't really the dma buffer
|
||||
*/
|
||||
void SNDDMA_Submit(void)
|
||||
void
|
||||
SNDDMA_Submit(void)
|
||||
{
|
||||
int count = paintedtime - soundtime;
|
||||
int avail;
|
||||
int missed;
|
||||
int state;
|
||||
int hw_ptr;
|
||||
int offset;
|
||||
snd_pcm_uframes_t offset;
|
||||
snd_pcm_uframes_t nframes;
|
||||
const snd_pcm_channel_area_t *areas;
|
||||
int state;
|
||||
int count = paintedtime - soundtime;
|
||||
|
||||
nframes = count / shm->channels;
|
||||
|
||||
snd_pcm_mmap_begin (pcm, &areas, &offset, &nframes);
|
||||
|
||||
state = snd_pcm_state (pcm);
|
||||
|
||||
switch (state) {
|
||||
case SND_PCM_STATE_PREPARED:
|
||||
snd_pcm_mmap_forward (pcm, count);
|
||||
snd_pcm_start (pcm);
|
||||
break;
|
||||
case SND_PCM_STATE_RUNNING:
|
||||
hw_ptr = get_hw_ptr();
|
||||
missed = hw_ptr - shm->samplepos / shm->channels;
|
||||
if (missed < 0)
|
||||
missed += buffer_size;
|
||||
count -= missed;
|
||||
offset = snd_pcm_mmap_offset (pcm);
|
||||
if (offset > hw_ptr)
|
||||
count -= (offset - hw_ptr);
|
||||
else
|
||||
count -= (buffer_size - hw_ptr + offset);
|
||||
if (count < 0) {
|
||||
snd_pcm_rewind (pcm, -count);
|
||||
} else {
|
||||
avail = snd_pcm_avail_update(pcm);
|
||||
if (avail < 0)
|
||||
avail = buffer_size;
|
||||
if (count > avail)
|
||||
count = avail;
|
||||
if (count)
|
||||
snd_pcm_mmap_forward (pcm, count);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case SND_PCM_STATE_PREPARED:
|
||||
snd_pcm_mmap_commit (pcm, offset, nframes);
|
||||
snd_pcm_start (pcm);
|
||||
break;
|
||||
case SND_PCM_STATE_RUNNING:
|
||||
snd_pcm_mmap_commit (pcm, offset, nframes);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
117
source/vid.c
117
source/vid.c
|
@ -29,18 +29,33 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
#include <math.h>
|
||||
|
||||
#include "compat.h"
|
||||
#include "console.h"
|
||||
#include "cvar.h"
|
||||
#include "vid.h"
|
||||
#include "va.h"
|
||||
#include "qargs.h"
|
||||
#include "sys.h"
|
||||
#include "va.h"
|
||||
#include "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)
|
||||
|
@ -88,27 +103,79 @@ VID_GetWindowSize (int def_w, int def_h)
|
|||
scr_height = vid.height = vid_height->int_val;
|
||||
}
|
||||
|
||||
#if 0
|
||||
VID_Calc_Gamma (void)
|
||||
{
|
||||
float f;
|
||||
int i;
|
||||
int v;
|
||||
byte
|
||||
float g = bound (0.3, gamma->value, 3);
|
||||
/****************************************************************************
|
||||
* GAMMA FUNCTIONS *
|
||||
****************************************************************************/
|
||||
|
||||
Cvar_SetValue (gamma, g);
|
||||
if (gamma_flipped->int_val)
|
||||
g = 1 / g;
|
||||
for (i = 0; i < 256; i++) {
|
||||
f = pow ((i + 1) / 256.0, g);
|
||||
v = f * 255 + 0.5;
|
||||
lightmap_gamma[i] = bound (0, v, 255);
|
||||
for (j = 0; j < 3; j++) {
|
||||
f = pow ((host_basepal[i * 3 + j] + 1) / 256.0, g);
|
||||
v = f * 255 + 0.5;
|
||||
palette[i] = bound (0, v, 255);
|
||||
void
|
||||
VID_BuildGammaTable (double gamma)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (gamma == 1.0) { // linear, don't bother with the math
|
||||
for (i = 0; i < 256; i++) {
|
||||
gammatable[i] = i;
|
||||
}
|
||||
} else {
|
||||
double g = 1.0 / gamma;
|
||||
int v;
|
||||
|
||||
for (i = 0; i < 256; i++) { // Build/update gamma lookup table
|
||||
v = (int) ((255.0 * pow ((double) i / 255.0, g)) + 0.5);
|
||||
gammatable[i] = bound (0, v, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
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,
|
||||
"Gamma correction");
|
||||
VID_UpdateGamma (vid_gamma);
|
||||
|
||||
VID_BuildGammaTable (vid_gamma->value);
|
||||
}
|
||||
|
||||
void
|
||||
VID_HandlePause (qboolean paused)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -312,3 +312,12 @@ 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;
|
||||
}
|
||||
|
|
|
@ -701,3 +701,9 @@ void
|
|||
VID_SetCaption (char *text)
|
||||
{
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_SetGamma (double gamma)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -82,8 +82,8 @@ VID_Shutdown (void)
|
|||
|
||||
Con_Printf ("VID_Shutdown\n");
|
||||
|
||||
x11_restore_vidmode ();
|
||||
x11_close_display ();
|
||||
X11_RestoreVidMode ();
|
||||
X11_CloseDisplay ();
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -170,7 +170,7 @@ VID_Init (unsigned char *palette)
|
|||
vid.conheight = atoi (com_argv[i + 1]);
|
||||
vid.conheight = max (vid.conheight, 200);
|
||||
|
||||
x11_open_display ();
|
||||
X11_OpenDisplay ();
|
||||
|
||||
x_visinfo = glXChooseVisual (x_disp, x_screen, attrib);
|
||||
if (!x_visinfo) {
|
||||
|
@ -180,12 +180,12 @@ VID_Init (unsigned char *palette)
|
|||
}
|
||||
x_vis = x_visinfo->visual;
|
||||
|
||||
x11_set_vidmode (scr_width, scr_height);
|
||||
x11_create_window (scr_width, scr_height);
|
||||
X11_SetVidMode (scr_width, scr_height);
|
||||
X11_CreateWindow (scr_width, scr_height);
|
||||
/* Invisible cursor */
|
||||
x11_create_null_cursor ();
|
||||
X11_CreateNullCursor ();
|
||||
|
||||
x11_grab_keyboard ();
|
||||
X11_GrabKeyboard ();
|
||||
|
||||
XSync (x_disp, 0);
|
||||
|
||||
|
@ -219,7 +219,7 @@ VID_Init (unsigned char *palette)
|
|||
void
|
||||
VID_Init_Cvars ()
|
||||
{
|
||||
x11_Init_Cvars ();
|
||||
X11_Init_Cvars ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -228,9 +228,21 @@ VID_SetCaption (char *text)
|
|||
if (text && *text) {
|
||||
char *temp = strdup (text);
|
||||
|
||||
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
|
||||
X11_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp));
|
||||
free (temp);
|
||||
} else {
|
||||
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
|
||||
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
VID_GetGamma (void)
|
||||
{
|
||||
return (double) X11_GetGamma ();
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_SetGamma (double gamma)
|
||||
{
|
||||
return X11_SetGamma (gamma);
|
||||
}
|
||||
|
|
|
@ -3195,3 +3195,9 @@ VID_SetCaption (char *text)
|
|||
SetWindowText (mainwindow, (LPSTR) va ("%s %s", PROGRAM, VERSION));
|
||||
}
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_SetGamma (double gamma)
|
||||
{
|
||||
return false; //FIXME
|
||||
}
|
||||
|
|
|
@ -288,3 +288,10 @@ VID_SetCaption (char *text)
|
|||
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
|
||||
}
|
||||
|
|
|
@ -240,3 +240,9 @@ VID_SetCaption (char *text)
|
|||
SDL_WM_SetCaption (va ("%s %s", PROGRAM, VERSION), NULL);
|
||||
}
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_SetGamma (double gamma)
|
||||
{
|
||||
return SDL_SetGamma((float) gamma, (float) gamma, (float) gamma);
|
||||
}
|
||||
|
|
|
@ -759,3 +759,9 @@ void
|
|||
VID_SetCaption (char *text)
|
||||
{
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_SetGamma (double gamma)
|
||||
{
|
||||
return false; //FIXME
|
||||
}
|
||||
|
|
|
@ -1785,3 +1785,9 @@ VID_SetCaption (char *text)
|
|||
SetWindowText (mainwindow, (LPSTR) va ("%s %s", PROGRAM, VERSION));
|
||||
}
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_SetGamma (double gamma)
|
||||
{
|
||||
return false; //FIXME
|
||||
}
|
||||
|
|
|
@ -519,7 +519,7 @@ VID_Init (unsigned char *palette)
|
|||
verbose = COM_CheckParm ("-verbose");
|
||||
|
||||
// open the display
|
||||
x11_open_display ();
|
||||
X11_OpenDisplay ();
|
||||
|
||||
template_mask = 0;
|
||||
|
||||
|
@ -567,13 +567,13 @@ VID_Init (unsigned char *palette)
|
|||
}
|
||||
|
||||
/* Setup attributes for main window */
|
||||
x11_set_vidmode (vid.width, vid.height);
|
||||
X11_SetVidMode (vid.width, vid.height);
|
||||
|
||||
/* Create the main window */
|
||||
x11_create_window (vid.width, vid.height);
|
||||
X11_CreateWindow (vid.width, vid.height);
|
||||
|
||||
/* Invisible cursor */
|
||||
x11_create_null_cursor ();
|
||||
X11_CreateNullCursor ();
|
||||
|
||||
if (x_visinfo->depth == 8) {
|
||||
/* Create and upload the palette */
|
||||
|
@ -592,7 +592,7 @@ VID_Init (unsigned char *palette)
|
|||
x_gc = XCreateGC (x_disp, x_win, valuemask, &xgcvalues);
|
||||
}
|
||||
|
||||
x11_grab_keyboard ();
|
||||
X11_GrabKeyboard ();
|
||||
|
||||
// wait for first exposure event
|
||||
{
|
||||
|
@ -640,13 +640,13 @@ VID_Init (unsigned char *palette)
|
|||
vid.aspect = ((float) vid.height / (float) vid.width) * (320.0 / 240.0);
|
||||
|
||||
// XSynchronize (x_disp, False);
|
||||
x11_add_event (x_shmeventtype, event_shm);
|
||||
X11_AddEvent (x_shmeventtype, event_shm);
|
||||
}
|
||||
|
||||
void
|
||||
VID_Init_Cvars ()
|
||||
{
|
||||
x11_Init_Cvars ();
|
||||
X11_Init_Cvars ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -696,8 +696,8 @@ VID_Shutdown (void)
|
|||
{
|
||||
Sys_Printf ("VID_Shutdown\n");
|
||||
if (x_disp) {
|
||||
x11_restore_vidmode ();
|
||||
x11_close_display ();
|
||||
X11_RestoreVidMode ();
|
||||
X11_CloseDisplay ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -757,7 +757,7 @@ VID_Update (vrect_t *rects)
|
|||
}
|
||||
oktodraw = false;
|
||||
while (!oktodraw)
|
||||
x11_process_event ();
|
||||
X11_ProcessEvent ();
|
||||
rects = rects->pnext;
|
||||
|
||||
current_framebuffer = !current_framebuffer;
|
||||
|
@ -813,9 +813,21 @@ VID_SetCaption (char *text)
|
|||
if (text && *text) {
|
||||
char *temp = strdup (text);
|
||||
|
||||
x11_set_caption (va ("%s %s: %s", PROGRAM, VERSION, temp));
|
||||
X11_SetCaption (va ("%s %s: %s", PROGRAM, VERSION, temp));
|
||||
free (temp);
|
||||
} else {
|
||||
x11_set_caption (va ("%s %s", PROGRAM, VERSION));
|
||||
X11_SetCaption (va ("%s %s", PROGRAM, VERSION));
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
VID_GetGamma (void)
|
||||
{
|
||||
return (double) X11_GetGamma ();
|
||||
}
|
||||
|
||||
qboolean
|
||||
VID_SetGamma (double gamma)
|
||||
{
|
||||
return X11_SetGamma (gamma);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue