2004-08-23 00:15:46 +00:00
|
|
|
//this is to render transparent things in a distance oriented order
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
#include "renderque.h"
|
|
|
|
|
|
|
|
#define NUMGRADUATIONS 0x400
|
|
|
|
static renderque_t *freerque;
|
|
|
|
static renderque_t *activerque;
|
|
|
|
static renderque_t *initialque;
|
|
|
|
|
|
|
|
static renderque_t *distlastarque[NUMGRADUATIONS];
|
|
|
|
static renderque_t *distrque[NUMGRADUATIONS];
|
|
|
|
|
|
|
|
int rqmaxgrad, rqmingrad;
|
|
|
|
|
|
|
|
int rquesize = 0x2000;
|
2010-07-11 02:22:39 +00:00
|
|
|
float rquepivot;
|
|
|
|
|
|
|
|
void RQ_BeginFrame(void)
|
|
|
|
{
|
|
|
|
rquepivot = DotProduct(r_refdef.vieworg, vpn);
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2008-12-23 02:55:20 +00:00
|
|
|
void RQ_AddDistReorder(void (*render) (int count, void **objects, void *objtype), void *object, void *objtype, float *pos)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int dist;
|
|
|
|
renderque_t *rq;
|
|
|
|
if (!freerque)
|
|
|
|
{
|
2008-12-23 02:55:20 +00:00
|
|
|
render(1, &object, objtype);
|
2004-08-23 00:15:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
dist = DotProduct(pos, vpn)-rquepivot;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (dist > rqmaxgrad)
|
|
|
|
{
|
|
|
|
if (dist >= NUMGRADUATIONS)
|
|
|
|
dist = NUMGRADUATIONS-1;
|
|
|
|
rqmaxgrad = dist;
|
|
|
|
}
|
|
|
|
if (dist < rqmingrad)
|
|
|
|
{
|
|
|
|
if (dist < 0) //hmm... value wrapped? shouldn't happen
|
2010-07-11 02:22:39 +00:00
|
|
|
return;
|
|
|
|
// dist = 0;
|
2004-08-23 00:15:46 +00:00
|
|
|
rqmingrad = dist;
|
|
|
|
}
|
|
|
|
|
|
|
|
rq = freerque;
|
|
|
|
freerque = freerque->next;
|
|
|
|
rq->next = NULL;
|
|
|
|
if (distlastarque[dist])
|
|
|
|
distlastarque[dist]->next = rq;
|
|
|
|
distlastarque[dist] = rq;
|
|
|
|
|
|
|
|
rq->render = render;
|
2008-12-23 02:55:20 +00:00
|
|
|
rq->data1 = object;
|
|
|
|
rq->data2 = objtype;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (!distrque[dist])
|
|
|
|
distrque[dist] = rq;
|
|
|
|
}
|
2010-07-11 02:22:39 +00:00
|
|
|
/*
|
2004-08-23 00:15:46 +00:00
|
|
|
void RQ_RenderDistAndClear(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
renderque_t *rq;
|
|
|
|
for (i = rqmaxgrad; i>=rqmingrad; i--)
|
2005-07-14 01:57:34 +00:00
|
|
|
// for (i = rqmingrad; i<=rqmaxgrad; i++)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
for (rq = distrque[i]; rq; rq=rq->next)
|
|
|
|
{
|
2008-12-23 02:55:20 +00:00
|
|
|
rq->render(1, &rq->data1, rq->data2);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
if (distlastarque[i])
|
|
|
|
{
|
|
|
|
distlastarque[i]->next = freerque;
|
|
|
|
freerque = distrque[i];
|
|
|
|
distrque[i] = NULL;
|
|
|
|
distlastarque[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rqmaxgrad=0;
|
|
|
|
rqmingrad = NUMGRADUATIONS-1;
|
|
|
|
}
|
2010-07-11 02:22:39 +00:00
|
|
|
*/
|
2008-12-23 02:55:20 +00:00
|
|
|
void RQ_RenderBatchClear(void)
|
|
|
|
{
|
|
|
|
#define SLOTS 512
|
|
|
|
void *slot[SLOTS];
|
|
|
|
void *typeptr = NULL;
|
|
|
|
int maxslot = SLOTS;
|
|
|
|
void (*lr) (int count, void **objects, void *objtype) = NULL;
|
|
|
|
int i;
|
|
|
|
renderque_t *rq;
|
|
|
|
|
|
|
|
for (i = rqmaxgrad; i>=rqmingrad; i--)
|
|
|
|
// for (i = rqmingrad; i<=rqmaxgrad; i++)
|
|
|
|
{
|
|
|
|
for (rq = distrque[i]; rq; rq=rq->next)
|
|
|
|
{
|
|
|
|
if (!maxslot || rq->render != lr || typeptr != rq->data2)
|
|
|
|
{
|
|
|
|
if (maxslot != SLOTS)
|
|
|
|
lr(SLOTS - maxslot, &slot[maxslot], typeptr);
|
|
|
|
maxslot = SLOTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot[--maxslot] = rq->data1;
|
|
|
|
typeptr = rq->data2;
|
|
|
|
lr = rq->render;
|
|
|
|
}
|
|
|
|
if (distlastarque[i])
|
|
|
|
{
|
|
|
|
distlastarque[i]->next = freerque;
|
|
|
|
freerque = distrque[i];
|
|
|
|
distrque[i] = NULL;
|
|
|
|
distlastarque[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (maxslot != SLOTS)
|
|
|
|
lr(SLOTS - maxslot, &slot[maxslot], typeptr);
|
|
|
|
rqmaxgrad=0;
|
|
|
|
rqmingrad = NUMGRADUATIONS-1;
|
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2012-11-27 03:23:19 +00:00
|
|
|
//render without clearing
|
|
|
|
void RQ_RenderBatch(void)
|
|
|
|
{
|
|
|
|
#define SLOTS 512
|
|
|
|
void *slot[SLOTS];
|
|
|
|
void *typeptr = NULL;
|
|
|
|
int maxslot = SLOTS;
|
|
|
|
void (*lr) (int count, void **objects, void *objtype) = NULL;
|
|
|
|
int i;
|
|
|
|
renderque_t *rq;
|
|
|
|
|
|
|
|
for (i = rqmaxgrad; i>=rqmingrad; i--)
|
|
|
|
// for (i = rqmingrad; i<=rqmaxgrad; i++)
|
|
|
|
{
|
|
|
|
for (rq = distrque[i]; rq; rq=rq->next)
|
|
|
|
{
|
|
|
|
if (!maxslot || rq->render != lr || typeptr != rq->data2)
|
|
|
|
{
|
|
|
|
if (maxslot != SLOTS)
|
|
|
|
lr(SLOTS - maxslot, &slot[maxslot], typeptr);
|
|
|
|
maxslot = SLOTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
slot[--maxslot] = rq->data1;
|
|
|
|
typeptr = rq->data2;
|
|
|
|
lr = rq->render;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (maxslot != SLOTS)
|
|
|
|
lr(SLOTS - maxslot, &slot[maxslot], typeptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-30 05:52:03 +00:00
|
|
|
void RQ_Shutdown(void)
|
|
|
|
{
|
|
|
|
Z_Free(initialque);
|
|
|
|
initialque = NULL;
|
|
|
|
freerque = NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
void RQ_Init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (initialque)
|
|
|
|
return;
|
|
|
|
|
2012-08-04 01:35:52 +00:00
|
|
|
initialque = (renderque_t *) Z_Malloc (rquesize * sizeof(renderque_t));
|
|
|
|
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
freerque = &initialque[0];
|
|
|
|
activerque = NULL;
|
|
|
|
|
|
|
|
for (i=0 ;i<rquesize-1 ; i++)
|
|
|
|
initialque[i].next = &initialque[i+1];
|
|
|
|
initialque[rquesize-1].next = NULL;
|
|
|
|
}
|