diff --git a/include/QF/vid.h b/include/QF/vid.h index 0a7ef60b1..99c6dd8ef 100644 --- a/include/QF/vid.h +++ b/include/QF/vid.h @@ -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 diff --git a/libs/video/targets/vid_common_sw.c b/libs/video/targets/vid_common_sw.c index 23f995eb9..44c885c1c 100644 --- a/libs/video/targets/vid_common_sw.c +++ b/libs/video/targets/vid_common_sw.c @@ -30,21 +30,22 @@ # include "config.h" #endif +#include #include +#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); } diff --git a/qw/source/d_init.c b/qw/source/d_init.c index 22b47b87e..113d921e3 100644 --- a/qw/source/d_init.c +++ b/qw/source/d_init.c @@ -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 diff --git a/qw/source/d_surf.c b/qw/source/d_surf.c index f5a7d74a8..12e5e4319 100644 --- a/qw/source/d_surf.c +++ b/qw/source/d_surf.c @@ -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 (); }