From 617b6cd987a80e139e57fbb4b997bebcd587590b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 15 Feb 2020 09:22:30 +0100 Subject: [PATCH] - use floats for sprite depth sorting in the hardware renderer. Fixed point is clearly insufficient here. --- src/rendering/hwrenderer/scene/hw_drawlist.cpp | 7 +++---- src/rendering/hwrenderer/scene/hw_drawstructs.h | 6 +++--- src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_drawlist.cpp b/src/rendering/hwrenderer/scene/hw_drawlist.cpp index a5a6d7b1d..37ff4006b 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlist.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlist.cpp @@ -585,10 +585,9 @@ inline int HWDrawList::CompareSprites(SortNode * a,SortNode * b) HWSprite * s1= sprites[drawitems[a->itemindex].index]; HWSprite * s2= sprites[drawitems[b->itemindex].index]; - int res = s1->depth - s2->depth; - - if (res != 0) return -res; - else return reverseSort? s2->index-s1->index : s1->index-s2->index; + if (s1->depth < s2->depth) return 1; + if (s1->depth > s2->depth) return -1; + return reverseSort? s2->index-s1->index : s1->index-s2->index; } //========================================================================== diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 5550a2d46..4c9730844 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -354,7 +354,7 @@ public: int translation; int index; - int depth; + float depth; int vertexindex; float topclip; @@ -366,15 +366,15 @@ public: float vt,vb; float x1,y1,z1; float x2,y2,z2; + float trans; + int dynlightindex; FMaterial *gltexture; - float trans; AActor * actor; particle_t * particle; TArray *lightlist; DRotator Angles; - int dynlightindex; void SplitSprite(HWDrawInfo *di, sector_t * frontsector, bool translucent); void PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingpos, float spriteheight); diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index d2104c7d1..4d44f29ef 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -903,7 +903,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t gltexture = nullptr; } - depth = FloatToFixed((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin); + depth = (float)((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin); // light calculation