Move VID_InitBuffers back from the renderer to targets.

First, it was nearly identical between sw and sw32 (one paranoia line in
sw32), and second, it's common enough.
This commit is contained in:
Bill Currie 2012-02-23 10:06:30 +09:00
parent a093e6af97
commit 6f7b4276e9
3 changed files with 65 additions and 131 deletions

View file

@ -22,14 +22,13 @@
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static __attribute__ ((used)) const char rcsid[] =
"$Id$";
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include <stdlib.h>
#include <math.h>
@ -40,66 +39,3 @@ static __attribute__ ((used)) const char rcsid[] =
#include "QF/vid.h"
#include "vid_internal.h"
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize = 1;
// No console scaling in the sw renderer
viddef.conwidth = viddef.width;
viddef.conheight = viddef.height;
Con_CheckResize ();
// Calculate the sizes we want first
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);
// Free the old z-buffer
if (viddef.zbuffer) {
free (viddef.zbuffer);
viddef.zbuffer = NULL;
}
// Free the old surface cache
if (viddef.surfcache) {
if (viddef.flush_caches)
viddef.flush_caches ();
free (viddef.surfcache);
viddef.surfcache = NULL;
}
if (viddef.do_screen_buffer) {
viddef.do_screen_buffer ();
} else {
// Free the old screen buffer
if (viddef.buffer) {
free (viddef.buffer);
viddef.conbuffer = viddef.buffer = NULL;
}
// Allocate the new screen buffer
viddef.conbuffer = viddef.buffer = calloc (buffersize, 1);
if (!viddef.conbuffer) {
Sys_Error ("Not enough memory for video mode");
}
}
// Allocate the new z-buffer
viddef.zbuffer = calloc (zbuffersize, 1);
if (!viddef.zbuffer) {
free (viddef.buffer);
viddef.conbuffer = viddef.buffer = NULL;
Sys_Error ("Not enough memory for video mode");
}
// Allocate the new surface cache; free the z-buffer if we fail
viddef.surfcache = calloc (cachesize, 1);
if (!viddef.surfcache) {
free (viddef.buffer);
free (viddef.zbuffer);
viddef.conbuffer = viddef.buffer = NULL;
viddef.zbuffer = NULL;
Sys_Error ("Not enough memory for video mode");
}
if (viddef.init_caches)
viddef.init_caches (viddef.surfcache, cachesize);
}

View file

@ -30,9 +30,6 @@
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#define NH_DEFINE
#include "namehack.h"
#include "QF/console.h"
#include "QF/cvar.h"
#include "QF/mathlib.h"
@ -205,65 +202,3 @@ VID_MakeColormaps (int fullbrights, byte *pal)
VID_MakeColormap16(vid.colormap16, pal);
VID_MakeColormap32(vid.colormap32, pal);
}
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize = 1;
// No console scaling in the sw renderer
vid.conwidth = vid.width;
vid.conheight = vid.height;
Con_CheckResize ();
// Calculate the sizes we want first
buffersize = vid.rowbytes * vid.height;
zbuffersize = vid.width * vid.height * sizeof (*vid.zbuffer);
if (vid.surf_cache_size)
cachesize = vid.surf_cache_size (vid.width, vid.height);
// Free the old z-buffer
if (vid.zbuffer) {
free (vid.zbuffer);
vid.zbuffer = NULL;
}
// Free the old surface cache
if (vid.surfcache) {
if (vid.flush_caches)
vid.flush_caches ();
free (vid.surfcache);
vid.surfcache = NULL;
}
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");
}
}
// Allocate the new z-buffer
vid.zbuffer = calloc (zbuffersize, 1);
if (!vid.zbuffer) {
free (vid.buffer);
vid.conbuffer = vid.buffer = NULL;
Sys_Error ("Not enough memory for video mode");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid.surfcache = calloc (cachesize, 1);
if (!vid.surfcache) {
free (vid.buffer);
free (vid.zbuffer);
vid.zbuffer = NULL;
Sys_Error ("Not enough memory for video mode");
}
if (vid.init_caches)
vid.init_caches (vid.surfcache, cachesize);
}

View file

@ -245,3 +245,66 @@ VID_InitGamma (unsigned char *pal)
VID_BuildGammaTable (vid_gamma->value);
}
void
VID_InitBuffers (void)
{
int buffersize, zbuffersize, cachesize = 1;
// No console scaling in the sw renderer
viddef.conwidth = viddef.width;
viddef.conheight = viddef.height;
Con_CheckResize ();
// Calculate the sizes we want first
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);
// Free the old z-buffer
if (viddef.zbuffer) {
free (viddef.zbuffer);
viddef.zbuffer = NULL;
}
// Free the old surface cache
if (viddef.surfcache) {
if (viddef.flush_caches)
viddef.flush_caches ();
free (viddef.surfcache);
viddef.surfcache = NULL;
}
if (viddef.do_screen_buffer) {
viddef.do_screen_buffer ();
} else {
// Free the old screen buffer
if (viddef.buffer) {
free (viddef.buffer);
viddef.conbuffer = viddef.buffer = NULL;
}
// Allocate the new screen buffer
viddef.conbuffer = viddef.buffer = calloc (buffersize, 1);
if (!viddef.conbuffer) {
Sys_Error ("Not enough memory for video mode");
}
}
// Allocate the new z-buffer
viddef.zbuffer = calloc (zbuffersize, 1);
if (!viddef.zbuffer) {
free (viddef.buffer);
viddef.conbuffer = viddef.buffer = NULL;
Sys_Error ("Not enough memory for video mode");
}
// Allocate the new surface cache; free the z-buffer if we fail
viddef.surfcache = calloc (cachesize, 1);
if (!viddef.surfcache) {
free (viddef.buffer);
free (viddef.zbuffer);
viddef.conbuffer = viddef.buffer = NULL;
viddef.zbuffer = NULL;
Sys_Error ("Not enough memory for video mode");
}
if (viddef.init_caches)
viddef.init_caches (viddef.surfcache, cachesize);
}