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-04-15 04:18:22 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
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
|
|
|
|
2011-06-14 08:54:53 +00:00
|
|
|
#include "QF/console.h"
|
2011-12-24 01:04:33 +00:00
|
|
|
#include "QF/mathlib.h"
|
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
|
|
|
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
|
|
|
|
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
|
|
|
|
2009-12-22 13:12:03 +00:00
|
|
|
// No console scaling in the sw renderer
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.conwidth = viddef.width;
|
|
|
|
viddef.conheight = viddef.height;
|
2011-06-14 08:54:53 +00:00
|
|
|
Con_CheckResize ();
|
2009-12-22 13:12:03 +00:00
|
|
|
|
2001-04-15 07:18:04 +00:00
|
|
|
// Calculate the sizes we want first
|
2012-02-14 10:47:02 +00:00
|
|
|
buffersize = viddef.rowbytes * viddef.height;
|
|
|
|
zbuffersize = viddef.width * viddef.height * sizeof (*viddef.zbuffer);
|
|
|
|
if (viddef.surf_cache_size)
|
|
|
|
cachesize = viddef.surf_cache_size (viddef.width, viddef.height);
|
2001-04-15 07:18:04 +00:00
|
|
|
|
|
|
|
// Free the old z-buffer
|
2012-02-14 10:47:02 +00:00
|
|
|
if (viddef.zbuffer) {
|
|
|
|
free (viddef.zbuffer);
|
|
|
|
viddef.zbuffer = NULL;
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
// Free the old surface cache
|
2012-02-14 10:47:02 +00:00
|
|
|
if (viddef.surfcache) {
|
|
|
|
if (viddef.flush_caches)
|
|
|
|
viddef.flush_caches ();
|
|
|
|
free (viddef.surfcache);
|
|
|
|
viddef.surfcache = NULL;
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
2012-02-14 10:47:02 +00:00
|
|
|
if (viddef.do_screen_buffer) {
|
|
|
|
viddef.do_screen_buffer ();
|
2001-04-16 19:25:55 +00:00
|
|
|
} else {
|
|
|
|
// Free the old screen buffer
|
2012-02-14 10:47:02 +00:00
|
|
|
if (viddef.buffer) {
|
|
|
|
free (viddef.buffer);
|
|
|
|
viddef.conbuffer = viddef.buffer = NULL;
|
2001-04-16 19:25:55 +00:00
|
|
|
}
|
|
|
|
// Allocate the new screen buffer
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.conbuffer = viddef.buffer = calloc (buffersize, 1);
|
|
|
|
if (!viddef.conbuffer) {
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Not enough memory for video mode");
|
2001-04-16 19:25:55 +00:00
|
|
|
}
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
// Allocate the new z-buffer
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.zbuffer = calloc (zbuffersize, 1);
|
|
|
|
if (!viddef.zbuffer) {
|
|
|
|
free (viddef.buffer);
|
|
|
|
viddef.conbuffer = viddef.buffer = NULL;
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Not enough memory for video mode");
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
// Allocate the new surface cache; free the z-buffer if we fail
|
2012-02-14 10:47:02 +00:00
|
|
|
viddef.surfcache = calloc (cachesize, 1);
|
|
|
|
if (!viddef.surfcache) {
|
|
|
|
free (viddef.buffer);
|
|
|
|
free (viddef.zbuffer);
|
|
|
|
viddef.conbuffer = viddef.buffer = NULL;
|
|
|
|
viddef.zbuffer = NULL;
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Not enough memory for video mode");
|
2001-04-15 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 10:47:02 +00:00
|
|
|
if (viddef.init_caches)
|
|
|
|
viddef.init_caches (viddef.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);
|
|
|
|
}
|