mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 05:00:35 +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 {
|
typedef struct {
|
||||||
pixel_t *buffer; // invisible buffer
|
pixel_t *buffer; // invisible buffer
|
||||||
|
short *zbuffer;
|
||||||
|
void *surfcache;
|
||||||
pixel_t *colormap; // 256 * VID_GRADES size
|
pixel_t *colormap; // 256 * VID_GRADES size
|
||||||
unsigned short *colormap16; // 256 * VID_GRADES size
|
unsigned short *colormap16; // 256 * VID_GRADES size
|
||||||
int fullbright; // index of first fullbright color
|
int fullbright; // index of first fullbright color
|
||||||
|
@ -62,6 +64,9 @@ typedef struct {
|
||||||
int maxwarpheight;
|
int maxwarpheight;
|
||||||
pixel_t *direct; // direct drawing to framebuffer, if not
|
pixel_t *direct; // direct drawing to framebuffer, if not
|
||||||
// NULL
|
// NULL
|
||||||
|
int (*surf_cache_size)(int width, int height);
|
||||||
|
void (*flush_caches)(void);
|
||||||
|
void (*init_caches)(void *cache, int size);
|
||||||
} viddef_t;
|
} viddef_t;
|
||||||
|
|
||||||
extern viddef_t vid; // global video state
|
extern viddef_t vid; // global video state
|
||||||
|
|
|
@ -30,21 +30,22 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "QF/sys.h"
|
||||||
#include "QF/vid.h"
|
#include "QF/vid.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
VID_InitBuffers (void)
|
VID_InitBuffers (void)
|
||||||
{
|
{
|
||||||
#if 0 //XXX not just yet
|
int buffersize, zbuffersize, cachesize = 1;
|
||||||
int buffersize, zbuffersize, cachesize;
|
|
||||||
void *vid_surfcache;
|
|
||||||
|
|
||||||
// Calculate the sizes we want first
|
// Calculate the sizes we want first
|
||||||
buffersize = vid.rowbytes * vid.height;
|
buffersize = vid.rowbytes * vid.height;
|
||||||
zbuffersize = vid.width * vid.height * sizeof (*d_pzbuffer);
|
zbuffersize = vid.width * vid.height * sizeof (*vid.zbuffer);
|
||||||
cachesize = D_SurfaceCacheForRes (vid.width, vid.height);
|
if (vid.surf_cache_size)
|
||||||
|
cachesize = vid.surf_cache_size (vid.width, vid.height);
|
||||||
|
|
||||||
// Free the old screen buffer
|
// Free the old screen buffer
|
||||||
if (vid.buffer) {
|
if (vid.buffer) {
|
||||||
|
@ -52,16 +53,16 @@ VID_InitBuffers (void)
|
||||||
vid.conbuffer = vid.buffer = NULL;
|
vid.conbuffer = vid.buffer = NULL;
|
||||||
}
|
}
|
||||||
// Free the old z-buffer
|
// Free the old z-buffer
|
||||||
if (d_pzbuffer) {
|
if (vid.zbuffer) {
|
||||||
free (d_pzbuffer);
|
free (vid.zbuffer);
|
||||||
d_pzbuffer = NULL;
|
vid.zbuffer = NULL;
|
||||||
}
|
}
|
||||||
// Free the old surface cache
|
// Free the old surface cache
|
||||||
vid_surfcache = D_SurfaceCacheAddress ();
|
if (vid.surfcache) {
|
||||||
if (vid_surfcache) {
|
if (vid.flush_caches)
|
||||||
D_FlushCaches ();
|
vid.flush_caches ();
|
||||||
free (vid_surfcache);
|
free (vid.surfcache);
|
||||||
vid_surfcache = NULL;
|
vid.surfcache = NULL;
|
||||||
}
|
}
|
||||||
// Allocate the new screen buffer
|
// Allocate the new screen buffer
|
||||||
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
|
vid.conbuffer = vid.buffer = calloc (buffersize, 1);
|
||||||
|
@ -69,22 +70,22 @@ VID_InitBuffers (void)
|
||||||
Sys_Error ("Not enough memory for video mode\n");
|
Sys_Error ("Not enough memory for video mode\n");
|
||||||
}
|
}
|
||||||
// Allocate the new z-buffer
|
// Allocate the new z-buffer
|
||||||
d_pzbuffer = calloc (zbuffersize, 1);
|
vid.zbuffer = calloc (zbuffersize, 1);
|
||||||
if (!d_pzbuffer) {
|
if (!vid.zbuffer) {
|
||||||
free (vid.buffer);
|
free (vid.buffer);
|
||||||
vid.conbuffer = vid.buffer = NULL;
|
vid.conbuffer = vid.buffer = NULL;
|
||||||
Sys_Error ("Not enough memory for video mode\n");
|
Sys_Error ("Not enough memory for video mode\n");
|
||||||
}
|
}
|
||||||
// Allocate the new surface cache; free the z-buffer if we fail
|
// Allocate the new surface cache; free the z-buffer if we fail
|
||||||
vid_surfcache = calloc (cachesize, 1);
|
vid.surfcache = calloc (cachesize, 1);
|
||||||
if (!vid_surfcache) {
|
if (!vid.surfcache) {
|
||||||
free (vid.buffer);
|
free (vid.buffer);
|
||||||
free (d_pzbuffer);
|
free (vid.zbuffer);
|
||||||
vid.conbuffer = vid.buffer = NULL;
|
vid.conbuffer = vid.buffer = NULL;
|
||||||
d_pzbuffer = NULL;
|
vid.zbuffer = NULL;
|
||||||
Sys_Error ("Not enough memory for video mode\n");
|
Sys_Error ("Not enough memory for video mode\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
D_InitCaches (vid_surfcache, cachesize);
|
if (vid.init_caches)
|
||||||
#endif
|
vid.init_caches (vid.surfcache, cachesize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "QF/compat.h"
|
#include "QF/compat.h"
|
||||||
|
#include "QF/vid.h"
|
||||||
|
|
||||||
#include "bothdefs.h"
|
#include "bothdefs.h"
|
||||||
#include "d_local.h"
|
#include "d_local.h"
|
||||||
|
|
||||||
|
@ -65,6 +67,12 @@ D_Init (void)
|
||||||
r_recursiveaffinetriangles = true;
|
r_recursiveaffinetriangles = true;
|
||||||
r_pixbytes = 1;
|
r_pixbytes = 1;
|
||||||
r_aliasuvscale = 1.0;
|
r_aliasuvscale = 1.0;
|
||||||
|
|
||||||
|
vid.surf_cache_size = D_SurfaceCacheForRes;
|
||||||
|
vid.flush_caches = D_FlushCaches;
|
||||||
|
vid.init_caches = D_InitCaches;
|
||||||
|
|
||||||
|
VID_InitBuffers ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -112,6 +112,8 @@ D_InitCaches (void *buffer, int size)
|
||||||
sc_base->owner = NULL;
|
sc_base->owner = NULL;
|
||||||
sc_base->size = sc_size;
|
sc_base->size = sc_size;
|
||||||
|
|
||||||
|
d_pzbuffer = vid.zbuffer;
|
||||||
|
|
||||||
D_ClearCacheGuard ();
|
D_ClearCacheGuard ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue