- Improve sprite performance when there are many draw segments

This commit is contained in:
Magnus Norddahl 2017-07-01 03:31:06 +02:00
parent 44546ce16a
commit 42fedd0f4c
4 changed files with 36 additions and 11 deletions

View file

@ -134,13 +134,42 @@ namespace swrenderer
void RenderTranslucentPass::DrawMaskedSingle(bool renew)
{
RenderPortal *renderportal = Thread->Portal.get();
DrawSegmentList *drawseglist = Thread->DrawSegments.get();
int numGroups = drawseglist->SegmentGroups.Size();
for (int j = 0; j < numGroups; j++)
drawseglist->SegmentGroups[j].GroupDrawn = false;
auto &sortedSprites = Thread->SpriteList->SortedSprites;
for (int i = sortedSprites.Size(); i > 0; i--)
{
if (sortedSprites[i - 1]->IsCurrentPortalUniq(renderportal->CurrentPortalUniq))
VisibleSprite *sprite = sortedSprites[i - 1];
// Draw the draw segments known to be behind us now.
for (int j = numGroups; j > 0; j--)
{
sortedSprites[i - 1]->Render(Thread);
auto &group = drawseglist->SegmentGroups[j - 1];
if (!group.GroupDrawn && group.neardepth > sprite->DrawSegDepth())
{
for (unsigned int index = group.BeginIndex; index != group.EndIndex; index++)
{
DrawSegment *ds = drawseglist->Segment(index);
if (ds->CurrentPortalUniq != renderportal->CurrentPortalUniq) continue;
if (ds->fake) continue;
if (ds->maskedtexturecol != nullptr || ds->bFogBoundary)
{
RenderDrawSegment renderer(Thread);
renderer.Render(ds, ds->x1, ds->x2);
}
}
group.GroupDrawn = true;
}
}
if (sprite->IsCurrentPortalUniq(renderportal->CurrentPortalUniq))
{
sprite->Render(Thread);
}
}
@ -151,7 +180,6 @@ namespace swrenderer
Thread->Clip3D->fake3D |= FAKE3D_REFRESHCLIP;
}
DrawSegmentList *drawseglist = Thread->DrawSegments.get();
for (unsigned int index = 0; index != drawseglist->SegmentsCount(); index++)
{
DrawSegment *ds = drawseglist->Segment(index);

View file

@ -63,6 +63,7 @@ namespace swrenderer
short *sprbottomclip;
unsigned int BeginIndex;
unsigned int EndIndex;
bool GroupDrawn;
};
class DrawSegmentList

View file

@ -296,7 +296,7 @@ namespace swrenderer
for (unsigned int groupIndex = 0; groupIndex < segmentlist->SegmentGroups.Size(); groupIndex++)
{
auto &group = segmentlist->SegmentGroups[groupIndex];
if (group.x1 >= x2 || group.x2 <= x1)
if (group.x1 >= x2 || group.x2 <= x1 || group.neardepth > spr->depth)
continue;
if (group.fardepth < spr->depth)
@ -335,11 +335,6 @@ namespace swrenderer
{
DrawSegment *ds = segmentlist->Segment(index);
// [ZZ] portal handling here
//if (ds->CurrentPortalUniq != spr->CurrentPortalUniq)
// continue;
// [ZZ] WARNING: uncommenting the two above lines, totally breaks sprite clipping
// kg3D - no clipping on fake segs
if (ds->fake) continue;
// determine if the drawseg obscures the sprite
@ -380,8 +375,7 @@ namespace swrenderer
RenderPortal *renderportal = thread->Portal.get();
// seg is behind sprite, so draw the mid texture if it has one
if (ds->CurrentPortalUniq == renderportal->CurrentPortalUniq && // [ZZ] instead, portal uniq check is made here
(ds->maskedtexturecol != nullptr || ds->bFogBoundary))
if (ds->CurrentPortalUniq == renderportal->CurrentPortalUniq && (ds->maskedtexturecol != nullptr || ds->bFogBoundary))
{
RenderDrawSegment renderer(thread);
renderer.Render(ds, r1, r2);

View file

@ -46,6 +46,8 @@ namespace swrenderer
double SortDist2D() const { return DVector2(deltax, deltay).LengthSquared(); }
float SortDist() const { return idepth; }
float DrawSegDepth() const { return depth; }
protected:
virtual bool IsParticle() const { return false; }
virtual bool IsVoxel() const { return false; }