You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
942 B
46 lines
942 B
#include "common.h"
|
|
#include "memory.h"
|
|
|
|
#define PRIMBUFLEN 131072 // TODO: optimize this for a typical scene
|
|
|
|
static char primbuff[2][PRIMBUFLEN]; // Primitive buffer, just a raw buffer of bytes to use as a pool for primitives
|
|
static char *nextpri;
|
|
static char *primbuff_bounds;
|
|
|
|
static char* const scratch_start = (char*)0x1F800000;
|
|
static char *scratch = scratch_start;
|
|
|
|
void mem_scratch_reset()
|
|
{
|
|
scratch = scratch_start;
|
|
}
|
|
|
|
void *mem_scratch(unsigned short size)
|
|
{
|
|
#if _DEBUG
|
|
if (scratch + size > scratch_start + 1024)
|
|
return NULL;
|
|
#endif
|
|
|
|
void *result = scratch;
|
|
scratch += size;
|
|
return result;
|
|
}
|
|
|
|
void mem_prim_reset(int db)
|
|
{
|
|
nextpri = primbuff[db];
|
|
primbuff_bounds = nextpri + PRIMBUFLEN;
|
|
}
|
|
|
|
void *mem_prim(size_t size)
|
|
{
|
|
#if _DEBUG
|
|
if (nextpri + size > primbuff_bounds)
|
|
return NULL; // TODO: report error
|
|
#endif
|
|
|
|
void *prim = nextpri;
|
|
nextpri += size;
|
|
return prim;
|
|
}
|