X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=meshqueue.c;h=69bb69198e2fcc65406b5e3324f6d855535d831e;hb=467b8463f5376945d355117aed6372d3cf7b4e58;hp=d21ba627aec464dc0e7fa359d06e169319b5bb9f;hpb=c9b9e2d6bd061e255c0418b44f8ec3e251642c16;p=xonotic%2Fdarkplaces.git diff --git a/meshqueue.c b/meshqueue.c index d21ba627..69bb6919 100644 --- a/meshqueue.c +++ b/meshqueue.c @@ -10,14 +10,13 @@ typedef struct meshqueue_s int surfacenumber; const rtlight_t *rtlight; float dist; + meshqueue_sortcategory_t category; } meshqueue_t; int trans_sortarraysize; meshqueue_t **trans_hash = NULL; meshqueue_t ***trans_hashpointer = NULL; -extern cvar_t r_transparent_sortarraysize; -extern cvar_t r_transparent_sortmaxdist; float mqt_viewplanedist; float mqt_viewmaxdist; @@ -32,7 +31,7 @@ void R_MeshQueue_BeginScene(void) mqt_viewmaxdist = 0; } -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) +void R_MeshQueue_AddTransparent(meshqueue_sortcategory_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) { meshqueue_t *mq; if (mqt_count >= mqt_total || !mqt_array) @@ -52,7 +51,11 @@ void R_MeshQueue_AddTransparent(const vec3_t center, void (*callback)(const enti mq->ent = ent; mq->surfacenumber = surfacenumber; mq->rtlight = rtlight; - mq->dist = DotProduct(center, r_refdef.view.forward) - mqt_viewplanedist; + mq->category = category; + if (r_transparent_useplanardistance.integer) + mq->dist = DotProduct(center, r_refdef.view.forward) - mqt_viewplanedist; + else + mq->dist = VectorDistance(center, r_refdef.view.origin); mq->next = NULL; mqt_viewmaxdist = max(mqt_viewmaxdist, mq->dist); } @@ -73,8 +76,10 @@ void R_MeshQueue_RenderTransparent(void) // check for bad cvars if (r_transparent_sortarraysize.integer < 1 || r_transparent_sortarraysize.integer > 32768) Cvar_SetValueQuick(&r_transparent_sortarraysize, bound(1, r_transparent_sortarraysize.integer, 32768)); - if (r_transparent_sortmaxdist.integer < 1 || r_transparent_sortmaxdist.integer > 32768) - Cvar_SetValueQuick(&r_transparent_sortmaxdist, bound(1, r_transparent_sortmaxdist.integer, 32768)); + if (r_transparent_sortmindist.integer < 1 || r_transparent_sortmindist.integer >= r_transparent_sortmaxdist.integer) + Cvar_SetValueQuick(&r_transparent_sortmindist, 0); + if (r_transparent_sortmaxdist.integer < r_transparent_sortmindist.integer || r_transparent_sortmaxdist.integer > 32768) + Cvar_SetValueQuick(&r_transparent_sortmaxdist, bound(r_transparent_sortmindist.integer, r_transparent_sortmaxdist.integer, 32768)); // update hash array if (trans_sortarraysize != r_transparent_sortarraysize.integer) @@ -96,7 +101,20 @@ void R_MeshQueue_RenderTransparent(void) maxhashindex = trans_sortarraysize - 1; for (i = 0, mqt = mqt_array; i < mqt_count; i++, mqt++) { - hashindex = bound(0, (int)(min(mqt->dist, r_transparent_sortmaxdist.integer) * distscale), maxhashindex); + switch(mqt->category) + { + default: + case MESHQUEUE_SORT_HUD: + hashindex = 0; + break; + case MESHQUEUE_SORT_DISTANCE: + // this could use a reduced range if we need more categories + hashindex = bound(0, (int)(bound(0, mqt->dist - r_transparent_sortmindist.integer, r_transparent_sortmaxdist.integer) * distscale), maxhashindex); + break; + case MESHQUEUE_SORT_SKY: + hashindex = maxhashindex; + break; + } // link to tail of hash chain (to preserve render order) mqt->next = NULL; *trans_hashpointer[hashindex] = mqt;