2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-04-15 04:18:22 +00:00
|
|
|
vid_common_sw.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
Common software video driver functions
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
Copyright (C) 2001 Jeff Teunissen <deek@quakeforge.net>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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
|
2001-04-15 04:18:22 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-15 04:18:22 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-16 09:12:21 +00:00
|
|
|
#include <stdlib.h>
|
2001-04-15 04:18:22 +00:00
|
|
|
#include <math.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-16 09:12:21 +00:00
|
|
|
#include "QF/sys.h"
|
2001-04-15 04:18:22 +00:00
|
|
|
#include "QF/vid.h"
|
2001-04-15 07:18:04 +00:00
|
|
|
|
2001-04-17 06:13:51 +00:00
|
|
|
unsigned short d_8to16table[256];
|
|
|
|
|
2001-04-15 07:18:04 +00:00
|
|
|
void
|
|
|
|
VID_InitBuffers (void)
|
|
|
|
{
|
2001-04-16 09:12:21 +00:00
|
|
|
int buffersize, zbuffersize, cachesize = 1;
|
2001-04-15 07:18:04 +00:00
|
|
|
|
|
|
|
// Calculate the sizes we want first
|
|
|
|
buffersize = vid.rowbytes * vid.height;
|
2001-04-16 09:12:21 +00:00
|
|
|
zbuffersize = vid.width * vid.height * sizeof (*vid.zbuffer);
|
|
|
|
if (vid.surf_cache_size)
|
|
|
|
cachesize = vid.surf_cache_size (vid.width, vid.height);
|
2001-04-15 07:18:04 +00:00
|
|
|
|
|
|
|
// Free the old z-buffer
|
2001-04-16 09:12:21 +00:00
|
|
|
if (vid.zbuffer) {
|
|
|
|
free (vid.zbuffer);
|
|
|
|
vid.zbuffer = NULL;
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
// Free the old surface cache
|
2001-04-16 09:12:21 +00:00
|
|
|
if (vid.surfcache) {
|
|
|
|
if (vid.flush_caches)
|
|
|
|
vid.flush_caches ();
|
|
|
|
free (vid.surfcache);
|
|
|
|
vid.surfcache = NULL;
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
2001-04-16 19:25:55 +00:00
|
|
|
if (vid.do_screen_buffer) {
|
|
|
|
vid.do_screen_buffer ();
|
|
|
|
} else {
|
|
|
|
// Free the old screen buffer
|
|
|
|
if (vid.buffer) {
|
|
|
|
free (vid.buffer);
|
|
|
|
vid.conbuffer = vid.buffer = 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");
|
|
|
|
}
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
// Allocate the new z-buffer
|
2001-04-16 09:12:21 +00:00
|
|
|
vid.zbuffer = calloc (zbuffersize, 1);
|
|
|
|
if (!vid.zbuffer) {
|
2001-04-15 07:18:04 +00:00
|
|
|
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
|
2001-04-16 09:12:21 +00:00
|
|
|
vid.surfcache = calloc (cachesize, 1);
|
|
|
|
if (!vid.surfcache) {
|
2001-04-15 07:18:04 +00:00
|
|
|
free (vid.buffer);
|
2001-04-16 09:12:21 +00:00
|
|
|
free (vid.zbuffer);
|
2001-04-15 07:18:04 +00:00
|
|
|
vid.conbuffer = vid.buffer = NULL;
|
2001-04-16 09:12:21 +00:00
|
|
|
vid.zbuffer = NULL;
|
2001-04-15 07:18:04 +00:00
|
|
|
Sys_Error ("Not enough memory for video mode\n");
|
|
|
|
}
|
|
|
|
|
2001-04-16 09:12:21 +00:00
|
|
|
if (vid.init_caches)
|
|
|
|
vid.init_caches (vid.surfcache, cachesize);
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
2001-05-25 16:42:49 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
VID_ShiftPalette (unsigned char *p)
|
|
|
|
{
|
|
|
|
VID_SetPalette (p);
|
|
|
|
}
|