mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-11-10 23:02:03 +00:00
Second attempt to fix polymost sprite sorting issue
This commit is contained in:
parent
402d9b8f02
commit
9deb486626
1 changed files with 174 additions and 83 deletions
|
@ -8834,6 +8834,112 @@ static inline int32_t sameside(const _equation *eq, const vec2f_t *p1, c
|
|||
int32_t g_maskDrawMode = 0;
|
||||
#endif
|
||||
|
||||
static void sortsprites(int const start, int const end)
|
||||
{
|
||||
int32_t i, gap, y, ys;
|
||||
|
||||
if (start >= end)
|
||||
return;
|
||||
|
||||
gap = 1; while (gap < end - start) gap = (gap<<1)+1;
|
||||
for (gap>>=1; gap>0; gap>>=1) //Sort sprite list
|
||||
for (i=start; i<end-gap; i++)
|
||||
for (bssize_t l=i; l>=start; l-=gap)
|
||||
{
|
||||
if (spritesxyz[l].y <= spritesxyz[l+gap].y) break;
|
||||
swapptr(&tspriteptr[l],&tspriteptr[l+gap]);
|
||||
swaplong(&spritesxyz[l].x,&spritesxyz[l+gap].x);
|
||||
swaplong(&spritesxyz[l].y,&spritesxyz[l+gap].y);
|
||||
}
|
||||
|
||||
ys = spritesxyz[start].y; i = start;
|
||||
for (bssize_t j=start+1; j<=end; j++)
|
||||
{
|
||||
if (j < end)
|
||||
{
|
||||
y = spritesxyz[j].y;
|
||||
if (y == ys)
|
||||
continue;
|
||||
|
||||
ys = y;
|
||||
}
|
||||
|
||||
if (j > i+1)
|
||||
{
|
||||
for (bssize_t k=i; k<j; k++)
|
||||
{
|
||||
auto const s = tspriteptr[k];
|
||||
|
||||
spritesxyz[k].z = s->z;
|
||||
if ((s->cstat&48) != 32)
|
||||
{
|
||||
int32_t yoff = picanm[s->picnum].yofs + s->yoffset;
|
||||
int32_t yspan = (tilesiz[s->picnum].y*s->yrepeat<<2);
|
||||
|
||||
spritesxyz[k].z -= (yoff*s->yrepeat)<<2;
|
||||
|
||||
if (!(s->cstat&128))
|
||||
spritesxyz[k].z -= (yspan>>1);
|
||||
if (klabs(spritesxyz[k].z-globalposz) < (yspan>>1))
|
||||
spritesxyz[k].z = globalposz;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_OPENGL
|
||||
if (videoGetRenderMode() == REND_POLYMOST)
|
||||
{
|
||||
for (bssize_t k=i+1; k<j; k++)
|
||||
for (bssize_t l=i; l<k; l++)
|
||||
if ((tspriteptr[k]->cstat & 48) < (tspriteptr[l]->cstat & 48)
|
||||
|| ((tspriteptr[k]->cstat & 48) == 16 && (tspriteptr[l]->cstat & 48) == 16
|
||||
&& tspriteptr[k]->ang < tspriteptr[l]->ang))
|
||||
{
|
||||
swapptr(&tspriteptr[k], &tspriteptr[l]);
|
||||
vec3_t tv3 = spritesxyz[k];
|
||||
spritesxyz[k] = spritesxyz[l];
|
||||
spritesxyz[l] = tv3;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (bssize_t k=i+1; k<j; k++)
|
||||
for (bssize_t l=i; l<k; l++)
|
||||
if (klabs(spritesxyz[k].z-globalposz) < klabs(spritesxyz[l].z-globalposz))
|
||||
{
|
||||
swapptr(&tspriteptr[k],&tspriteptr[l]);
|
||||
vec3_t tv3 = spritesxyz[k];
|
||||
spritesxyz[k] = spritesxyz[l];
|
||||
spritesxyz[l] = tv3;
|
||||
}
|
||||
|
||||
for (bssize_t k=i+1; k<j; k++)
|
||||
for (bssize_t l=i; l<k; l++)
|
||||
if (tspriteptr[k]->x == tspriteptr[l]->x &&
|
||||
tspriteptr[k]->y == tspriteptr[l]->y &&
|
||||
tspriteptr[k]->z == tspriteptr[l]->z &&
|
||||
(tspriteptr[k]->cstat & 48) == (tspriteptr[l]->cstat & 48) &&
|
||||
tspriteptr[k]->owner < tspriteptr[l]->owner)
|
||||
{
|
||||
swapptr(&tspriteptr[k], &tspriteptr[l]);
|
||||
vec3_t tv3 = spritesxyz[k];
|
||||
spritesxyz[k] = spritesxyz[l];
|
||||
spritesxyz[l] = tv3;
|
||||
}
|
||||
|
||||
for (bssize_t k=i+1; k<j; k++)
|
||||
for (bssize_t l=i; l<k; l++)
|
||||
if (tspriteptr[k]->statnum < tspriteptr[l]->statnum)
|
||||
{
|
||||
swapptr(&tspriteptr[k], &tspriteptr[l]);
|
||||
vec3_t tv3 = spritesxyz[k];
|
||||
spritesxyz[k] = spritesxyz[l];
|
||||
spritesxyz[l] = tv3;
|
||||
}
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// drawmasks
|
||||
//
|
||||
|
@ -8885,7 +8991,7 @@ void renderDrawMasks(void)
|
|||
}
|
||||
}
|
||||
|
||||
for (i=spritesortcnt-1; i>=0; --i)
|
||||
for (i=numSprites-1; i>=0; --i)
|
||||
{
|
||||
const int32_t xs = tspriteptr[i]->x-globalposx, ys = tspriteptr[i]->y-globalposy;
|
||||
const int32_t yp = dmulscale6(xs,cosviewingrangeglobalang,ys,sinviewingrangeglobalang);
|
||||
|
@ -8910,6 +9016,18 @@ killsprite:
|
|||
#endif
|
||||
{
|
||||
//Delete face sprite if on wrong side!
|
||||
if (i >= spritesortcnt)
|
||||
{
|
||||
--numSprites;
|
||||
if (i != numSprites)
|
||||
{
|
||||
tspriteptr[i] = tspriteptr[numSprites];
|
||||
spritesxyz[i].x = spritesxyz[numSprites].x;
|
||||
spritesxyz[i].y = spritesxyz[numSprites].y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
--numSprites;
|
||||
--spritesortcnt;
|
||||
if (i != numSprites)
|
||||
|
@ -8921,80 +9039,15 @@ killsprite:
|
|||
spritesxyz[spritesortcnt].x = spritesxyz[numSprites].x;
|
||||
spritesxyz[spritesortcnt].y = spritesxyz[numSprites].y;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
spritesxyz[i].y = yp;
|
||||
}
|
||||
|
||||
int32_t gap, y, ys;
|
||||
|
||||
gap = 1; while (gap < spritesortcnt) gap = (gap<<1)+1;
|
||||
for (gap>>=1; gap>0; gap>>=1) //Sort sprite list
|
||||
for (i=0; i<spritesortcnt-gap; i++)
|
||||
for (bssize_t l=i; l>=0; l-=gap)
|
||||
{
|
||||
if (spritesxyz[l].y <= spritesxyz[l+gap].y) break;
|
||||
swapptr(&tspriteptr[l],&tspriteptr[l+gap]);
|
||||
swaplong(&spritesxyz[l].x,&spritesxyz[l+gap].x);
|
||||
swaplong(&spritesxyz[l].y,&spritesxyz[l+gap].y);
|
||||
}
|
||||
|
||||
ys = spritesxyz[0].y; i = 0;
|
||||
for (bssize_t j=1; j<=spritesortcnt; j++)
|
||||
{
|
||||
y = spritesxyz[j].y^(j == spritesortcnt);
|
||||
if (y == ys)
|
||||
continue;
|
||||
|
||||
ys = y;
|
||||
|
||||
if (j > i+1)
|
||||
{
|
||||
for (bssize_t k=i; k<j; k++)
|
||||
{
|
||||
auto const s = tspriteptr[k];
|
||||
|
||||
spritesxyz[k].z = s->z;
|
||||
if ((s->cstat&48) != 32)
|
||||
{
|
||||
int32_t yoff = picanm[s->picnum].yofs + s->yoffset;
|
||||
int32_t yspan = (tilesiz[s->picnum].y*s->yrepeat<<2);
|
||||
|
||||
spritesxyz[k].z -= (yoff*s->yrepeat)<<2;
|
||||
|
||||
if (!(s->cstat&128))
|
||||
spritesxyz[k].z -= (yspan>>1);
|
||||
if (klabs(spritesxyz[k].z-globalposz) < (yspan>>1))
|
||||
spritesxyz[k].z = globalposz;
|
||||
}
|
||||
}
|
||||
|
||||
for (bssize_t k=i+1; k<j; k++)
|
||||
for (bssize_t l=i; l<k; l++)
|
||||
if (klabs(spritesxyz[k].z-globalposz) < klabs(spritesxyz[l].z-globalposz))
|
||||
{
|
||||
swapptr(&tspriteptr[k],&tspriteptr[l]);
|
||||
vec3_t tv3 = spritesxyz[k];
|
||||
spritesxyz[k] = spritesxyz[l];
|
||||
spritesxyz[l] = tv3;
|
||||
}
|
||||
|
||||
for (bssize_t k=i+1; k<j; k++)
|
||||
for (bssize_t l=i; l<k; l++)
|
||||
if (tspriteptr[k]->x == tspriteptr[l]->x &&
|
||||
tspriteptr[k]->y == tspriteptr[l]->y &&
|
||||
(tspriteptr[k]->cstat & 48) == (tspriteptr[l]->cstat & 48) &&
|
||||
(bloodhack ? tspriteptr[k]->statnum < tspriteptr[l]->statnum : tspriteptr[k]->owner < tspriteptr[l]->owner))
|
||||
{
|
||||
swapptr(&tspriteptr[k], &tspriteptr[l]);
|
||||
vec3_t tv3 = spritesxyz[k];
|
||||
spritesxyz[k] = spritesxyz[l];
|
||||
spritesxyz[l] = tv3;
|
||||
}
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
sortsprites(0, spritesortcnt);
|
||||
sortsprites(spritesortcnt, numSprites);
|
||||
|
||||
videoBeginDrawing(); //{{{
|
||||
|
||||
|
@ -9005,15 +9058,53 @@ killsprite:
|
|||
glEnable(GL_ALPHA_TEST);
|
||||
polymost_setClamp(1+2);
|
||||
|
||||
for (i = spritesortcnt; i < numSprites; ++i)
|
||||
if (spritesortcnt < numSprites)
|
||||
{
|
||||
if (tspriteptr[i] != NULL)
|
||||
int32_t py = spritesxyz[spritesortcnt].y;
|
||||
int32_t pcstat = tspriteptr[spritesortcnt]->cstat & 48;
|
||||
int32_t pangle = tspriteptr[spritesortcnt]->ang;
|
||||
i = spritesortcnt;
|
||||
for (bssize_t j = spritesortcnt + 1; j <= numSprites; j++)
|
||||
{
|
||||
if (j < numSprites)
|
||||
{
|
||||
if (py == spritesxyz[j].y && pcstat == (tspriteptr[j]->cstat & 48) && (pcstat != 16 || pangle == tspriteptr[j]->ang))
|
||||
continue;
|
||||
py = spritesxyz[j].y;
|
||||
pcstat = (tspriteptr[j]->cstat & 48);
|
||||
pangle = tspriteptr[j]->ang;
|
||||
}
|
||||
if (j - i == 1)
|
||||
{
|
||||
debugmask_add(i | 32768, tspriteptr[i]->owner);
|
||||
renderDrawSprite(i);
|
||||
|
||||
tspriteptr[i] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
for (bssize_t k = j-1; k >= i; k--)
|
||||
{
|
||||
debugmask_add(k | 32768, tspriteptr[k]->owner);
|
||||
renderDrawSprite(k);
|
||||
}
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
||||
|
||||
for (bssize_t k = j-1; k >= i; k--)
|
||||
{
|
||||
renderDrawSprite(k);
|
||||
tspriteptr[k] = NULL;
|
||||
}
|
||||
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
polymost_setClamp(0);
|
||||
|
|
Loading…
Reference in a new issue