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.
38 lines
868 B
38 lines
868 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;
|
|
|
|
u_char* const scratchpad_root = (char*)0x1F800000;
|
|
|
|
void *mem_scratch(char **scratch_offset, unsigned short size)
|
|
{
|
|
#if _DEBUG
|
|
if (*scratch_offset + size > scratchpad + 1024)
|
|
return NULL;
|
|
#endif
|
|
|
|
void *result = *scratch_offset;
|
|
*scratch_offset += size;
|
|
return result;
|
|
}
|
|
|
|
void mem_prim_reset(int db)
|
|
{
|
|
nextpri = primbuff[db];
|
|
primbuff_bounds = nextpri + PRIMBUFLEN;
|
|
}
|
|
|
|
void *mem_prim(size_t size)
|
|
{
|
|
if (nextpri + size > primbuff_bounds)
|
|
return NULL; // TODO: report error
|
|
|
|
void *prim = nextpri;
|
|
nextpri += size;
|
|
return prim;
|
|
}
|