mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 06:51:47 +00:00
rework VID_InitBuffers to use callback to init the draw buffers.
Unfortunatly, this means that VID_InitBuffers needs to be called twice during startup (once in VID_Init, and once in D_Init).
This commit is contained in:
parent
61f369be94
commit
065649e488
4 changed files with 37 additions and 21 deletions
|
@ -45,6 +45,8 @@ typedef struct vrect_s {
|
|||
|
||||
typedef struct {
|
||||
pixel_t *buffer; // invisible buffer
|
||||
short *zbuffer;
|
||||
void *surfcache;
|
||||
pixel_t *colormap; // 256 * VID_GRADES size
|
||||
unsigned short *colormap16; // 256 * VID_GRADES size
|
||||
int fullbright; // index of first fullbright color
|
||||
|
@ -62,6 +64,9 @@ typedef struct {
|
|||
int maxwarpheight;
|
||||
pixel_t *direct; // direct drawing to framebuffer, if not
|
||||
// NULL
|
||||
int (*surf_cache_size)(int width, int height);
|
||||
void (*flush_caches)(void);
|
||||
void (*init_caches)(void *cache, int size);
|
||||
} viddef_t;
|
||||
|
||||
extern viddef_t vid; // global video state
|
||||
|
|
|
@ -30,21 +30,22 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "QF/sys.h"
|
||||
#include "QF/vid.h"
|
||||
|
||||
void
|
||||
VID_InitBuffers (void)
|
||||
{
|
||||
#if 0 //XXX not just yet
|
||||
int buffersize, zbuffersize, cachesize;
|
||||
void *vid_surfcache;
|
||||
int buffersize, zbuffersize, cachesize = 1;
|
||||
|
||||
// Calculate the sizes we want first
|
||||
buffersize = vid.rowbytes * vid.height;
|
||||
zbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
|
||||
cachesize = D_SurfaceCacheForRes (vid.width, 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 screen buffer
|
||||
if (vid.buffer) {
|
||||
|
@ -52,16 +53,16 @@ VID_InitBuffers (void)
|
|||
vid.conbuffer = vid.buffer = NULL;
|
||||
}
|
||||
// Free the old z-buffer
|
||||
if (d_pzbuffer) {
|
||||
free (d_pzbuffer);
|
||||
d_pzbuffer = NULL;
|
||||
if (vid.zbuffer) {
|
||||
free (vid.zbuffer);
|
||||
vid.zbuffer = NULL;
|
||||
}
|
||||
// Free the old surface cache
|
||||
vid_surfcache = D_SurfaceCacheAddress ();
|
||||
if (vid_surfcache) {
|
||||
D_FlushCaches ();
|
||||
free (vid_surfcache);
|
||||
vid_surfcache = NULL;
|
||||
if (vid.surfcache) {
|
||||
if (vid.flush_caches)
|
||||
vid.flush_caches ();
|
||||
free (vid.surfcache);
|
||||
vid.surfcache = NULL;
|
||||
}
|
||||
// Allocate the new screen buffer
|
||||
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
|
||||
|
@ -69,22 +70,22 @@ VID_InitBuffers (void)
|
|||
Sys_Error ("Not enough memory for video mode\n");
|
||||
}
|
||||
// Allocate the new z-buffer
|
||||
d_pzbuffer = calloc (zbuffersize, 1);
|
||||
if (!d_pzbuffer) {
|
||||
vid.zbuffer = calloc (zbuffersize, 1);
|
||||
if (!vid.zbuffer) {
|
||||
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
|
||||
vid_surfcache = calloc (cachesize, 1);
|
||||
if (!vid_surfcache) {
|
||||
vid.surfcache = calloc (cachesize, 1);
|
||||
if (!vid.surfcache) {
|
||||
free (vid.buffer);
|
||||
free (d_pzbuffer);
|
||||
free (vid.zbuffer);
|
||||
vid.conbuffer = vid.buffer = NULL;
|
||||
d_pzbuffer = NULL;
|
||||
vid.zbuffer = NULL;
|
||||
Sys_Error ("Not enough memory for video mode\n");
|
||||
}
|
||||
|
||||
D_InitCaches (vid_surfcache, cachesize);
|
||||
#endif
|
||||
if (vid.init_caches)
|
||||
vid.init_caches (vid.surfcache, cachesize);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#endif
|
||||
|
||||
#include "QF/compat.h"
|
||||
#include "QF/vid.h"
|
||||
|
||||
#include "bothdefs.h"
|
||||
#include "d_local.h"
|
||||
|
||||
|
@ -65,6 +67,12 @@ D_Init (void)
|
|||
r_recursiveaffinetriangles = true;
|
||||
r_pixbytes = 1;
|
||||
r_aliasuvscale = 1.0;
|
||||
|
||||
vid.surf_cache_size = D_SurfaceCacheForRes;
|
||||
vid.flush_caches = D_FlushCaches;
|
||||
vid.init_caches = D_InitCaches;
|
||||
|
||||
VID_InitBuffers ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -112,6 +112,8 @@ D_InitCaches (void *buffer, int size)
|
|||
sc_base->owner = NULL;
|
||||
sc_base->size = sc_size;
|
||||
|
||||
d_pzbuffer = vid.zbuffer;
|
||||
|
||||
D_ClearCacheGuard ();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue