diff --git a/include/r_internal.h b/include/r_internal.h index c25ba7271..71841b948 100644 --- a/include/r_internal.h +++ b/include/r_internal.h @@ -52,10 +52,10 @@ void R_PushDlights (const vec3_t entorigin); void R_DrawWaterSurfaces (void); void *D_SurfaceCacheAddress (void) __attribute__((pure)); -int D_SurfaceCacheForRes (void *data, int width, int height); +int D_SurfaceCacheForRes (int width, int height); void D_FlushCaches (void *data); void D_DeleteSurfaceCache (void); -void D_InitCaches (void *data, void *buffer, int size); +void D_InitCaches (void *buffer, int size); void R_SetVrect (const vrect_t *pvrect, vrect_t *pvrectin, int lineadj); void R_LoadSkys (const char *); diff --git a/include/vid_internal.h b/include/vid_internal.h index 7912dca52..0136d0cc0 100644 --- a/include/vid_internal.h +++ b/include/vid_internal.h @@ -5,9 +5,7 @@ #include "QF/plugin/vid_render.h" typedef struct vid_internal_s { - int (*surf_cache_size) (void *data, int width, int height); void (*flush_caches) (void *data); - void (*init_caches) (void *data, void *cache, int size); void (*init_buffers) (void *data); void (*set_palette) (void *data, const byte *palette); @@ -31,7 +29,6 @@ void VID_InitGamma (const byte *); qboolean VID_SetGamma (double); void VID_UpdateGamma (struct cvar_s *); -void VID_InitBuffers (void); void VID_MakeColormaps (void); #endif//__vid_internal_h diff --git a/libs/video/renderer/sw/d_init.c b/libs/video/renderer/sw/d_init.c index 9eed2bb89..349733f76 100644 --- a/libs/video/renderer/sw/d_init.c +++ b/libs/video/renderer/sw/d_init.c @@ -56,11 +56,33 @@ D_Init (void) r_worldpolysbacktofront = false; r_recursiveaffinetriangles = true; - vr_data.vid->vid_internal->surf_cache_size = D_SurfaceCacheForRes; - vr_data.vid->vid_internal->flush_caches = D_FlushCaches; - vr_data.vid->vid_internal->init_caches = D_InitCaches; + viddef_t *vid = vr_data.vid; - VID_InitBuffers (); + vid->vid_internal->flush_caches = D_FlushCaches; + + int buffersize = vid->rowbytes * vid->height; + int zbuffersize = vid->width * vid->height * sizeof (*vid->zbuffer); + int cachesize = D_SurfaceCacheForRes (vid->width, vid->height); + + if (vid->zbuffer) { + free (vid->zbuffer); + vid->zbuffer = 0; + } + if (vid->surfcache) { + D_FlushCaches (0); + free (vid->surfcache); + vid->surfcache = 0; + } + if (vid->vid_internal->init_buffers) { + vid->vid_internal->init_buffers (vid->vid_internal->data); + } else { + free (vid->buffer); + vid->buffer = calloc (buffersize, 1); + } + vid->zbuffer = calloc (zbuffersize, 1); + vid->surfcache = calloc (cachesize, 1); + + D_InitCaches (vid->surfcache, cachesize); } void diff --git a/libs/video/renderer/sw/d_surf.c b/libs/video/renderer/sw/d_surf.c index 33b4b399f..eb45010db 100644 --- a/libs/video/renderer/sw/d_surf.c +++ b/libs/video/renderer/sw/d_surf.c @@ -54,7 +54,7 @@ D_SurfaceCacheAddress (void) } int -D_SurfaceCacheForRes (void *data, int width, int height) +D_SurfaceCacheForRes (int width, int height) { int size, pix; @@ -96,7 +96,7 @@ D_ClearCacheGuard (void) } void -D_InitCaches (void *data, void *buffer, int size) +D_InitCaches (void *buffer, int size) { Sys_MaskPrintf (SYS_dev, "D_InitCaches: %ik surface cache\n", size/1024); diff --git a/libs/video/targets/vid.c b/libs/video/targets/vid.c index b918dd1b9..12aeedf99 100644 --- a/libs/video/targets/vid.c +++ b/libs/video/targets/vid.c @@ -247,73 +247,6 @@ VID_InitGamma (const byte *pal) } } -void -VID_InitBuffers (void) -{ - int buffersize, zbuffersize, cachesize = 1; - - // No console scaling in the sw renderer - viddef.conview->xlen = viddef.width; - viddef.conview->ylen = viddef.height; - Con_CheckResize (); - - // Calculate the sizes we want first - buffersize = viddef.rowbytes * viddef.height; - zbuffersize = viddef.width * viddef.height * sizeof (*viddef.zbuffer); - if (vi->surf_cache_size) { - cachesize = vi->surf_cache_size (vi->data, - 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 (vi->flush_caches) { - vi->flush_caches (vi->data); - } - free (viddef.surfcache); - viddef.surfcache = NULL; - } - if (vi->init_buffers) { - vi->init_buffers (vi->data); - } else { - // Free the old screen buffer - if (viddef.buffer) { - free (viddef.buffer); - viddef.buffer = NULL; - } - // Allocate the new screen buffer - viddef.buffer = calloc (buffersize, 1); - if (!viddef.buffer) { - 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.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.buffer = NULL; - viddef.zbuffer = NULL; - Sys_Error ("Not enough memory for video mode"); - } - - if (vi->init_caches) { - vi->init_caches (vi->data, viddef.surfcache, cachesize); - } -} - void VID_ClearMemory (void) { diff --git a/libs/video/targets/vid_x11_sw.c b/libs/video/targets/vid_x11_sw.c index 12dba8e49..cba768b8a 100644 --- a/libs/video/targets/vid_x11_sw.c +++ b/libs/video/targets/vid_x11_sw.c @@ -55,11 +55,14 @@ #include #include +#include "QF/console.h" #include "QF/cvar.h" #include "QF/qargs.h" #include "QF/sys.h" #include "QF/vid.h" +#include "QF/ui/view.h" + #include "context_x11.h" #include "r_internal.h" #include "vid_internal.h" @@ -633,6 +636,12 @@ x11_create_context (sw_ctx_t *ctx) x_shmeventtype = XShmGetEventBase (x_disp) + ShmCompletion; } + // FIXME this really shouldn't be here (ideally, scale console in sw) + // No console scaling in the sw renderer + viddef.conview->xlen = viddef.width; + viddef.conview->ylen = viddef.height; + Con_CheckResize (); + viddef.vid_internal->init_buffers = x11_init_buffers; // XSynchronize (x_disp, False); // X11_AddEvent (x_shmeventtype, event_shm);