5 typedef struct meshqueue_s
7 struct meshqueue_s *next;
8 void (*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfaceindices);
9 const entity_render_t *ent;
11 const rtlight_t *rtlight;
16 float mqt_viewplanedist;
17 float mqt_viewmaxdist;
18 meshqueue_t *mqt_array;
22 void R_MeshQueue_BeginScene(void)
25 mqt_viewplanedist = DotProduct(r_refdef.view.origin, r_refdef.view.forward);
29 void R_MeshQueue_AddTransparent(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)
32 if (mqt_count >= mqt_total || !mqt_array)
34 int newtotal = max(1024, mqt_total * 2);
35 meshqueue_t *newarray = (meshqueue_t *)Mem_Alloc(cls.permanentmempool, newtotal * sizeof(meshqueue_t));
38 memcpy(newarray, mqt_array, mqt_total * sizeof(meshqueue_t));
44 mq = &mqt_array[mqt_count++];
45 mq->callback = callback;
47 mq->surfacenumber = surfacenumber;
48 mq->rtlight = rtlight;
49 mq->dist = DotProduct(center, r_refdef.view.forward) - mqt_viewplanedist;
51 mqt_viewmaxdist = max(mqt_viewmaxdist, mq->dist);
54 void R_MeshQueue_RenderTransparent(void)
60 const entity_render_t *ent;
61 const rtlight_t *rtlight;
62 void (*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfaceindices);
64 static meshqueue_t *hash[4096], **hashpointer[4096];
65 int batchsurfaceindex[256];
68 memset(hash, 0, sizeof(hash));
69 for (i = 0;i < 4096;i++)
70 hashpointer[i] = &hash[i];
71 distscale = 4095.0f / max(mqt_viewmaxdist, 4095);
72 for (i = 0, mqt = mqt_array;i < mqt_count;i++, mqt++)
75 hashdist = (int) (mqt->dist * distscale);
76 hashdist = bound(0, hashdist, 4095);
77 // link to tail of hash chain (to preserve render order)
79 *hashpointer[hashdist] = mqt;
80 hashpointer[hashdist] = &mqt->next;
86 for (i = 4095;i >= 0;i--)
90 for (mqt = hash[i];mqt;mqt = mqt->next)
92 if (ent != mqt->ent || rtlight != mqt->rtlight || callback != mqt->callback || batchnumsurfaces >= 256)
95 callback(ent, rtlight, batchnumsurfaces, batchsurfaceindex);
98 rtlight = mqt->rtlight;
99 callback = mqt->callback;
101 batchsurfaceindex[batchnumsurfaces++] = mqt->surfacenumber;
105 if (batchnumsurfaces)
106 callback(ent, rtlight, batchnumsurfaces, batchsurfaceindex);