2001-08-25 02:47:11 +00:00
|
|
|
/*
|
|
|
|
vid_common_sw32.c
|
|
|
|
|
|
|
|
general video driver functions
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-14 08:54:53 +00:00
|
|
|
#include "QF/console.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/cvar.h"
|
2011-12-24 01:04:33 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
|
|
|
#include "QF/vid.h"
|
|
|
|
|
2001-08-25 03:52:34 +00:00
|
|
|
#include "compat.h"
|
2012-02-15 00:50:40 +00:00
|
|
|
#include "r_internal.h"
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
unsigned short sw32_8to16table[256];
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
VID_MakeColormap32
|
|
|
|
|
|
|
|
LordHavoc: makes a 32bit color*light table, RGBA order, no endian,
|
|
|
|
may need to be re-ordered to hardware at display time
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
VID_MakeColormap32 (void *outcolormap, byte *pal)
|
|
|
|
{
|
|
|
|
int c, l;
|
|
|
|
byte *out;
|
|
|
|
out = (byte *)&d_8to24table;
|
2014-02-03 07:04:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Generates colors not affected by lighting, such as
|
|
|
|
* HUD pieces and general sprites (such as explosions)
|
|
|
|
*/
|
2001-08-25 02:47:11 +00:00
|
|
|
for (c = 0; c < 256; c++) {
|
|
|
|
*out++ = pal[c*3+2];
|
2014-02-03 07:04:11 +00:00
|
|
|
*out++ = pal[c*3+1];
|
|
|
|
*out++ = pal[c*3+0];
|
2001-08-25 02:47:11 +00:00
|
|
|
*out++ = 255;
|
|
|
|
}
|
|
|
|
d_8to24table[255] = 0; // 255 is transparent
|
|
|
|
out = (byte *) outcolormap;
|
2014-02-03 07:04:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Generates colors affected by lighting, such as the
|
|
|
|
* world and other models that give it life, like foes and pickups.
|
|
|
|
*/
|
2001-08-25 02:47:11 +00:00
|
|
|
for (l = 0;l < VID_GRADES;l++)
|
|
|
|
{
|
|
|
|
for (c = 0;c < vid.fullbright;c++)
|
|
|
|
{
|
2014-02-03 07:04:11 +00:00
|
|
|
out[(l*256+c)*4+0] = bound(0, (pal[c*3+2] * l) >> (VID_CBITS - 1),
|
2001-08-25 02:47:11 +00:00
|
|
|
255);
|
|
|
|
out[(l*256+c)*4+1] = bound(0, (pal[c*3+1] * l) >> (VID_CBITS - 1),
|
|
|
|
255);
|
2014-02-03 07:04:11 +00:00
|
|
|
out[(l*256+c)*4+2] = bound(0, (pal[c*3+0] * l) >> (VID_CBITS - 1),
|
2001-08-25 02:47:11 +00:00
|
|
|
255);
|
|
|
|
out[(l*256+c)*4+3] = 255;
|
|
|
|
}
|
|
|
|
for (;c < 255;c++)
|
|
|
|
{
|
2014-02-03 07:04:11 +00:00
|
|
|
out[(l*256+c)*4+0] = pal[c*3+2];
|
2001-08-25 02:47:11 +00:00
|
|
|
out[(l*256+c)*4+1] = pal[c*3+1];
|
2014-02-03 07:04:11 +00:00
|
|
|
out[(l*256+c)*4+2] = pal[c*3+0];
|
2001-08-25 02:47:11 +00:00
|
|
|
out[(l*256+c)*4+3] = 255;
|
|
|
|
}
|
|
|
|
out[(l*256+255)*4+0] = 0;
|
|
|
|
out[(l*256+255)*4+1] = 0;
|
|
|
|
out[(l*256+255)*4+2] = 0;
|
|
|
|
out[(l*256+255)*4+3] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static unsigned short
|
|
|
|
lh24to16bit (int red, int green, int blue)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
red = bound(0, red, 255);
|
|
|
|
green = bound(0, green, 255);
|
|
|
|
blue = bound(0, blue, 255);
|
|
|
|
red >>= 3;
|
|
|
|
green >>= 2;
|
|
|
|
blue >>= 3;
|
|
|
|
red <<= 11;
|
|
|
|
green <<= 5;
|
|
|
|
return (unsigned short) (red | green | blue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
VID_MakeColormap16
|
|
|
|
|
|
|
|
LordHavoc: makes a 16bit color*light table, RGB order, native endian,
|
|
|
|
may need to be translated to hardware order at display time
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
VID_MakeColormap16 (void *outcolormap, byte *pal)
|
|
|
|
{
|
|
|
|
int c, l;
|
|
|
|
unsigned short *out;
|
2012-02-22 07:32:34 +00:00
|
|
|
out = (unsigned short *)&sw32_8to16table;
|
2001-08-25 02:47:11 +00:00
|
|
|
for (c = 0; c < 256; c++)
|
|
|
|
*out++ = lh24to16bit(pal[c*3+0], pal[c*3+1], pal[c*3+2]);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_8to16table[255] = 0; // 255 is transparent
|
2001-08-25 02:47:11 +00:00
|
|
|
out = (unsigned short *) outcolormap;
|
|
|
|
for (l = 0;l < VID_GRADES;l++)
|
|
|
|
{
|
|
|
|
for (c = 0;c < vid.fullbright;c++)
|
|
|
|
out[l*256+c] = lh24to16bit(
|
2012-05-21 23:23:22 +00:00
|
|
|
(pal[c*3+0] * l) >> (VID_CBITS - 1),
|
|
|
|
(pal[c*3+1] * l) >> (VID_CBITS - 1),
|
2001-08-25 02:47:11 +00:00
|
|
|
(pal[c*3+2] * l) >> (VID_CBITS - 1));
|
|
|
|
for (;c < 255;c++)
|
|
|
|
out[l*256+c] = lh24to16bit(pal[c*3+0], pal[c*3+1], pal[c*3+2]);
|
|
|
|
out[l*256+255] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
VID_MakeColormaps
|
|
|
|
|
|
|
|
LordHavoc: makes 8bit, 16bit, and 32bit colormaps and palettes
|
|
|
|
*/
|
2014-02-02 07:19:04 +00:00
|
|
|
void
|
2014-02-02 07:42:08 +00:00
|
|
|
VID_MakeColormaps (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
2018-09-07 11:00:57 +00:00
|
|
|
vid.colormap16 = malloc (256*VID_GRADES * sizeof (unsigned short));
|
|
|
|
vid.colormap32 = malloc (256*VID_GRADES * sizeof (unsigned int));
|
2014-02-02 07:42:08 +00:00
|
|
|
SYS_CHECKMEM (vid.colormap16 && vid.colormap32);
|
|
|
|
VID_MakeColormap16(vid.colormap16, vid.palette);
|
|
|
|
VID_MakeColormap32(vid.colormap32, vid.palette);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|