DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
meshqueue.c File Reference
#include "quakedef.h"
#include "meshqueue.h"
+ Include dependency graph for meshqueue.c:

Go to the source code of this file.

Data Structures

struct  meshqueue_t
 

Functions

void R_MeshQueue_AddTransparent (dptransparentsortcategory_t category, const vec3_t center, void(*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist), const entity_render_t *ent, int surfacenumber, const rtlight_t *rtlight)
 
void R_MeshQueue_BeginScene (void)
 
void R_MeshQueue_RenderTransparent (void)
 

Variables

meshqueue_tmqt_array
 
int mqt_count
 
int mqt_total
 
float mqt_viewmaxdist
 
float mqt_viewplanedist
 
meshqueue_t ** trans_hash = NULL
 
meshqueue_t *** trans_hashpointer = NULL
 
int trans_sortarraysize
 

Function Documentation

◆ R_MeshQueue_AddTransparent()

void R_MeshQueue_AddTransparent ( dptransparentsortcategory_t category,
const vec3_t center,
void(* callback )(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist),
const entity_render_t * ent,
int surfacenumber,
const rtlight_t * rtlight )

Definition at line 33 of file meshqueue.c.

34{
35 meshqueue_t *mq;
36 if (mqt_count >= mqt_total || !mqt_array)
37 {
38 int newtotal = max(1024, mqt_total * 2);
39 meshqueue_t *newarray = (meshqueue_t *)Mem_Alloc(cls.permanentmempool, newtotal * sizeof(meshqueue_t));
40 if (mqt_array)
41 {
42 memcpy(newarray, mqt_array, mqt_total * sizeof(meshqueue_t));
44 }
45 mqt_array = newarray;
46 mqt_total = newtotal;
47 }
48 mq = &mqt_array[mqt_count++];
49 mq->callback = callback;
50 mq->ent = ent;
51 mq->surfacenumber = surfacenumber;
52 mq->rtlight = rtlight;
53 mq->category = category;
56 else
57 mq->dist = VectorDistance(center, r_refdef.view.origin);
58 mq->next = NULL;
60}
client_static_t cls
Definition cl_main.c:116
cvar_t r_transparent_useplanardistance
Definition gl_rmain.c:81
r_refdef_t r_refdef
Definition gl_rmain.c:57
#define max(A, B)
Definition mathlib.h:38
#define VectorDistance(a, b)
Definition mathlib.h:108
#define DotProduct(a, b)
Definition mathlib.h:98
int mqt_total
Definition meshqueue.c:24
float mqt_viewplanedist
Definition meshqueue.c:20
int mqt_count
Definition meshqueue.c:23
float mqt_viewmaxdist
Definition meshqueue.c:21
meshqueue_t * mqt_array
Definition meshqueue.c:22
#define NULL
Definition qtypes.h:12
mempool_t * permanentmempool
Definition client.h:572
int integer
Definition cvar.h:73
void(* callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfaceindices)
Definition meshqueue.c:7
float dist
Definition meshqueue.c:11
const entity_render_t * ent
Definition meshqueue.c:8
dptransparentsortcategory_t category
Definition meshqueue.c:12
const rtlight_t * rtlight
Definition meshqueue.c:10
struct meshqueue_s * next
Definition meshqueue.c:6
int surfacenumber
Definition meshqueue.c:9
r_refdef_view_t view
Definition render.h:406
vec3_t origin
Definition render.h:267
vec3_t forward
Definition render.h:268
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92

References meshqueue_t::callback, meshqueue_t::category, cls, meshqueue_t::dist, DotProduct, meshqueue_t::ent, r_refdef_view_t::forward, cvar_t::integer, max, Mem_Alloc, Mem_Free, mqt_array, mqt_count, mqt_total, mqt_viewmaxdist, mqt_viewplanedist, meshqueue_t::next, NULL, r_refdef_view_t::origin, client_static_t::permanentmempool, r_refdef, r_transparent_useplanardistance, meshqueue_t::rtlight, meshqueue_t::surfacenumber, VectorDistance, and r_refdef_t::view.

Referenced by R_DrawEntityBBoxes(), R_DrawExplosions(), R_DrawLocs(), R_DrawNoModel(), R_DrawParticles(), R_DrawPortals(), R_Mod_DrawLight(), R_Model_Sprite_Draw(), R_ProcessTransparentTextureSurfaceList(), and R_Shadow_DrawLightSprites().

◆ R_MeshQueue_BeginScene()

◆ R_MeshQueue_RenderTransparent()

void R_MeshQueue_RenderTransparent ( void )

Definition at line 62 of file meshqueue.c.

63{
64 int i, hashindex, maxhashindex, batchnumsurfaces;
65 float distscale;
66 const entity_render_t *ent;
67 const rtlight_t *rtlight;
68 void (*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfaceindices);
69 int batchsurfaceindex[MESHQUEUE_TRANSPARENT_BATCHSIZE];
70 meshqueue_t *mqt;
71
72 if (!mqt_count)
73 return;
74
75 // check for bad cvars
82
83 // update hash array
85 {
87 if (trans_hash)
93 }
94
95 // build index
96 memset(trans_hash, 0, sizeof(meshqueue_t *) * trans_sortarraysize);
97 for (i = 0; i < trans_sortarraysize; i++)
100 maxhashindex = trans_sortarraysize - 1;
101 for (i = 0, mqt = mqt_array; i < mqt_count; i++, mqt++)
102 {
103 switch(mqt->category)
104 {
105 default:
107 hashindex = 0;
108 break;
110 // this could use a reduced range if we need more categories
111 hashindex = bound(0, (int)(bound(0, mqt->dist - r_transparent_sortmindist.integer, r_transparent_sortmaxdist.integer) * distscale), maxhashindex);
112 break;
114 hashindex = maxhashindex;
115 break;
116 }
117 // link to tail of hash chain (to preserve render order)
118 mqt->next = NULL;
119 *trans_hashpointer[hashindex] = mqt;
120 trans_hashpointer[hashindex] = &mqt->next;
121 }
122 callback = NULL;
123 ent = NULL;
124 rtlight = NULL;
125 batchnumsurfaces = 0;
126
127 // draw
128 for (i = maxhashindex; i >= 0; i--)
129 {
130 if (trans_hash[i])
131 {
132 for (mqt = trans_hash[i]; mqt; mqt = mqt->next)
133 {
134 if (ent != mqt->ent || rtlight != mqt->rtlight || callback != mqt->callback || batchnumsurfaces >= MESHQUEUE_TRANSPARENT_BATCHSIZE)
135 {
136 if (batchnumsurfaces)
137 callback(ent, rtlight, batchnumsurfaces, batchsurfaceindex);
138 batchnumsurfaces = 0;
139 ent = mqt->ent;
140 rtlight = mqt->rtlight;
141 callback = mqt->callback;
142 }
143 batchsurfaceindex[batchnumsurfaces++] = mqt->surfacenumber;
144 }
145 }
146 }
147 if (batchnumsurfaces)
148 callback(ent, rtlight, batchnumsurfaces, batchsurfaceindex);
149 mqt_count = 0;
150}
void() predraw
void Cvar_SetValueQuick(cvar_t *var, float value)
Definition cvar.c:473
cvar_t r_transparent_sortmaxdist
Definition gl_rmain.c:142
cvar_t r_transparent_sortarraysize
Definition gl_rmain.c:143
cvar_t r_transparent_sortmindist
Definition gl_rmain.c:141
#define min(A, B)
Definition mathlib.h:37
#define bound(min, num, max)
Definition mathlib.h:34
meshqueue_t ** trans_hash
Definition meshqueue.c:17
int trans_sortarraysize
Definition meshqueue.c:16
meshqueue_t *** trans_hashpointer
Definition meshqueue.c:18
#define MESHQUEUE_TRANSPARENT_BATCHSIZE
Definition meshqueue.h:6
int i
@ TRANSPARENTSORT_DISTANCE
Definition r_qshader.h:194
@ TRANSPARENTSORT_SKY
Definition r_qshader.h:193
@ TRANSPARENTSORT_HUD
Definition r_qshader.h:195

References bound, meshqueue_t::callback, meshqueue_t::category, cls, Cvar_SetValueQuick(), meshqueue_t::dist, meshqueue_t::ent, i, cvar_t::integer, Mem_Alloc, Mem_Free, MESHQUEUE_TRANSPARENT_BATCHSIZE, min, mqt_array, mqt_count, mqt_viewmaxdist, meshqueue_t::next, NULL, client_static_t::permanentmempool, r_transparent_sortarraysize, r_transparent_sortmaxdist, r_transparent_sortmindist, meshqueue_t::rtlight, meshqueue_t::surfacenumber, trans_hash, trans_hashpointer, trans_sortarraysize, TRANSPARENTSORT_DISTANCE, TRANSPARENTSORT_HUD, TRANSPARENTSORT_SKY, and void().

Referenced by R_RenderScene().

Variable Documentation

◆ mqt_array

meshqueue_t* mqt_array

Definition at line 22 of file meshqueue.c.

Referenced by R_MeshQueue_AddTransparent(), and R_MeshQueue_RenderTransparent().

◆ mqt_count

int mqt_count

◆ mqt_total

int mqt_total

Definition at line 24 of file meshqueue.c.

Referenced by R_MeshQueue_AddTransparent().

◆ mqt_viewmaxdist

float mqt_viewmaxdist

◆ mqt_viewplanedist

float mqt_viewplanedist

Definition at line 20 of file meshqueue.c.

Referenced by R_MeshQueue_AddTransparent(), and R_MeshQueue_BeginScene().

◆ trans_hash

meshqueue_t** trans_hash = NULL

Definition at line 17 of file meshqueue.c.

Referenced by R_MeshQueue_RenderTransparent().

◆ trans_hashpointer

meshqueue_t*** trans_hashpointer = NULL

Definition at line 18 of file meshqueue.c.

Referenced by R_MeshQueue_RenderTransparent().

◆ trans_sortarraysize

int trans_sortarraysize

Definition at line 16 of file meshqueue.c.

Referenced by R_MeshQueue_RenderTransparent().