[vid] Add a function to set the palette and colormap

Mostly for qwaq as it uses the default VGA palette but I need to do some
testing with the quake palette.
This commit is contained in:
Bill Currie 2022-11-14 19:39:55 +09:00
parent 7c53a68ad7
commit 8fa6167a57
6 changed files with 57 additions and 16 deletions

View file

@ -71,6 +71,7 @@ void VID_Init_Cvars (void);
// 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 (byte *palette, byte *colormap);
void VID_SetPalette (byte *palette, byte *colormap);
void VID_SetCaption (const char *text);
void VID_ClearMemory (void);

View file

@ -6,6 +6,7 @@
typedef struct vid_system_s {
void (*init) (byte *palette, byte *colormap);
void (*set_palette) (byte *palette, byte *colormap);
void (*init_cvars) (void);
void (*update_fullscreen) (int fullscreen);
} vid_system_t;

View file

@ -246,7 +246,11 @@ VID_InitGamma (const byte *pal)
{
int i;
double gamma = 1.0;
static int cvar_initialized;
free (viddef.gammatable);
free (viddef.palette);
free (viddef.palette32);
viddef.gammatable = malloc (256);
viddef.basepal = pal;
viddef.palette = malloc (256 * 3);
@ -256,9 +260,13 @@ VID_InitGamma (const byte *pal)
}
gamma = bound (0.1, gamma, 9.9);
Cvar_Register (&vid_gamma_cvar, vid_gamma_f, 0);
if (!cvar_initialized) {
cvar_initialized = 1;
Cvar_Register (&vid_gamma_cvar, vid_gamma_f, 0);
}
VID_BuildGammaTable (vid_gamma);
//VID_BuildGammaTable (vid_gamma);
VID_UpdateGamma ();
if (viddef.onPaletteChanged) {
LISTENER_INVOKE (viddef.onPaletteChanged, &viddef);
@ -315,6 +323,12 @@ VID_Init (byte *palette, byte *colormap)
vid_system.init (palette, colormap);
}
VISIBLE void
VID_SetPalette (byte *palette, byte *colormap)
{
vid_system.set_palette (palette, colormap);
}
static void
vid_fullscreen_f (void *data, const cvar_t *var)
{

View file

@ -117,6 +117,19 @@ VID_shutdown (void *data)
Win_CloseDisplay ();
}
static v oid
Win_VID_SetPalette (byte *palette, byte *colormap)
{
viddef.colormap8 = colormap;
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
if (vid_internal.set_colormap) {
vid_internal.set_colormap (vid_internal.data, colormap);
}
VID_InitGamma (palette);
viddef.vid_internal->set_palette (win_sw_context, palette);
}
static void
Win_VID_Init (byte *palette, byte *colormap)
{
@ -131,11 +144,6 @@ Win_VID_Init (byte *palette, byte *colormap)
R_LoadModule (&vid_internal);
viddef.numpages = 1;
viddef.colormap8 = colormap;
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
if (vid_internal.set_colormap) {
vid_internal.set_colormap (vid_internal.data, colormap);
}
VID_GetWindowSize (640, 480);
Win_OpenDisplay ();
@ -144,8 +152,7 @@ Win_VID_Init (byte *palette, byte *colormap)
Win_CreateWindow (viddef.width, viddef.height);
vid_internal.create_context (win_sw_context);
VID_InitGamma (palette);
viddef.vid_internal->set_palette (win_sw_context, palette);
Win_VID_SetPalette (palette, colormap);
Sys_MaskPrintf (SYS_vid, "Video mode %dx%d initialized.\n",
viddef.width, viddef.height);
@ -166,6 +173,7 @@ Win_VID_Init_Cvars (void)
vid_system_t vid_system = {
.init = Win_VID_Init,
.set_palette = Win_VID_SetPalette,
.init_cvars = Win_VID_Init_Cvars,
};

View file

@ -89,6 +89,19 @@ VID_shutdown (void *data)
X11_CloseDisplay ();
}
static void
X11_VID_SetPalette (byte *palette, byte *colormap)
{
viddef.colormap8 = colormap;
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
if (vid_internal.set_colormap) {
vid_internal.set_colormap (vid_internal.data, colormap);
}
VID_InitGamma (palette);
vid_internal.set_palette (vid_internal.data, viddef.palette);
}
/*
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
@ -108,11 +121,6 @@ X11_VID_Init (byte *palette, byte *colormap)
R_LoadModule (&vid_internal);
viddef.numpages = 2;
viddef.colormap8 = colormap;
viddef.fullbright = 256 - viddef.colormap8[256 * VID_GRADES];
if (vid_internal.set_colormap) {
vid_internal.set_colormap (vid_internal.data, colormap);
}
srandom (getpid ());
@ -124,8 +132,7 @@ X11_VID_Init (byte *palette, byte *colormap)
X11_CreateNullCursor (); // hide mouse pointer
vid_internal.create_context (vid_internal.data);
VID_InitGamma (palette);
vid_internal.set_palette (vid_internal.data, viddef.palette);
X11_VID_SetPalette (palette, colormap);
Sys_MaskPrintf (SYS_vid, "Video mode %dx%d initialized.\n",
viddef.width, viddef.height);
@ -149,6 +156,7 @@ vid_system_t vid_system = {
.init = X11_VID_Init,
.init_cvars = X11_VID_Init_Cvars,
.update_fullscreen = X11_UpdateFullscreen,
.set_palette = X11_VID_SetPalette,
};
#if 0

View file

@ -124,6 +124,14 @@ bi_refresh_2d (progs_t *pr, void *_res)
qc2d = P_FUNCTION (pr, 0);
}
static void
bi_setpalette (progs_t *pr, void *_res)
{
byte *palette = (byte *) P_GPOINTER (pr, 0);
byte *colormap = (byte *) P_GPOINTER (pr, 1);
VID_SetPalette (palette, colormap);
}
static void
bi_shutdown (progs_t *pr, void *_res)
{
@ -136,6 +144,7 @@ static builtin_t builtins[] = {
bi(newscene, -1, 1, p(long)),
bi(refresh, -1, 0),
bi(refresh_2d, -1, 1, p(func)),
bi(setpalette, -1, 2, p(ptr), p(ptr)),
bi(shutdown, -1, 0),
{0}
};