Skip to content

Commit

Permalink
Fixed|Renderer: Light decorations are not visible
Browse files Browse the repository at this point in the history
IssueID #2365
  • Loading branch information
skyjake committed Dec 10, 2019
1 parent d951c62 commit 8aea604
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 27 deletions.
84 changes: 62 additions & 22 deletions doomsday/apps/client/src/client/clientsubsector.cpp
Expand Up @@ -187,6 +187,13 @@ DENG2_PIMPL(ClientSubsector)
if (::ddMapSetup) return;
needUpdate = yes;
}

void clear()
{
markForUpdate(false);
qDeleteAll(decorations);
decorations.clear();
}
};

dint validFrame;
Expand Down Expand Up @@ -274,6 +281,11 @@ DENG2_PIMPL(ClientSubsector)
}
}

static bool hasDecoratedMaterial(const Surface &surface)
{
return surface.hasMaterial() && surface.material().as<ClientMaterial>().hasDecorations();
}

void observeSurface(Surface *surface, bool yes = true)
{
if (!surface) return;
Expand All @@ -283,12 +295,19 @@ DENG2_PIMPL(ClientSubsector)
surface->audienceForMaterialChange () += this;
surface->audienceForOriginChange () += this;
surface->audienceForOriginSmoothedChange() += this;

if (hasDecoratedMaterial(*surface))
{
allocDecorationState(*surface);
}
}
else
{
surface->audienceForOriginSmoothedChange() -= this;
surface->audienceForOriginChange () -= this;
surface->audienceForMaterialChange () -= this;

decorSurfaces.remove(surface);
}
}

Expand Down Expand Up @@ -521,6 +540,8 @@ DENG2_PIMPL(ClientSubsector)

void remapVisPlanes()
{
/// @todo Has performance issues -- disabled; needs reworking.

// By default both planes are mapped to the parent sector.
if (!floorIsMapped()) map(Sector::Floor, thisPublic);
if (!ceilingIsMapped()) map(Sector::Ceiling, thisPublic);
Expand Down Expand Up @@ -1014,7 +1035,18 @@ DENG2_PIMPL(ClientSubsector)
}

void decorate(Surface &surface)
{
{
if (!hasDecoratedMaterial(surface))
{
// Just clear the state.
if (surface.decorationState())
{
static_cast<DecoratedSurface *>(surface.decorationState())->clear();
}
return;
}

// Has a decorated material, so needs decoration state.
auto &ds = allocDecorationState(surface);

if (!ds.needUpdate) return;
Expand All @@ -1025,21 +1057,14 @@ DENG2_PIMPL(ClientSubsector)
&& &surface.parent() == mappedPlane(surface.parent().as<Plane>().indexInSector()) ? " (mapped)" : "")
);

ds.markForUpdate(false);
ds.clear();

qDeleteAll(ds.decorations);
ds.decorations.clear();

// Clear any existing decorations.
if (surface.hasMaterial())
Vector2f materialOrigin;
Vector3d bottomRight, topLeft;
if (prepareGeometry(surface, topLeft, bottomRight, materialOrigin))
{
Vector2f materialOrigin;
Vector3d bottomRight, topLeft;
if (prepareGeometry(surface, topLeft, bottomRight, materialOrigin))
{
MaterialAnimator &animator = *surface.materialAnimator();
projectDecorations(surface, animator, materialOrigin, topLeft, bottomRight);
}
MaterialAnimator &animator = *surface.materialAnimator();
projectDecorations(surface, animator, materialOrigin, topLeft, bottomRight);
}
}

Expand Down Expand Up @@ -1312,17 +1337,30 @@ DENG2_PIMPL(ClientSubsector)
void surfaceMaterialChanged(Surface &surface)
{
LOG_AS("ClientSubsector");
//DecoratedSurface &ds = decorSurfaces[surface.uniqueId()];

DecoratedSurface &ds = allocDecorationState(surface);
if (auto *ds = static_cast<DecoratedSurface *>(surface.decorationState()))
{
// Clear any existing decorations (now invalid).
ds->clear();
// qDeleteAll(ds->decorations);
// ds->decorations.clear();
// ds->markForUpdate();
}

// Clear any existing decorations (now invalid).
qDeleteAll(ds.decorations);
ds.decorations.clear();
ds.markForUpdate();
if (hasDecoratedMaterial(surface))
{
auto &ds = allocDecorationState(surface);
ds.markForUpdate();
}

// Begin observing the new material (if any).
/// @todo fixme: stop observing the old one!? -ds
//
// Note that the subsector keeps observing all the materials of all surfaces.
// To stop observing old ones, one needs to make sure that no surface in the
// subsector is no longer using the material.
//
/// @todo Stop observing unused materials.
//
observeMaterial(surface.materialPtr());
}

Expand Down Expand Up @@ -1889,6 +1927,8 @@ void ClientSubsector::decorate()

bool ClientSubsector::hasDecorations() const
{
return !d.getConst()->decorSurfaces.isEmpty();
/*
for (Surface *surface : d.getConst()->decorSurfaces)
{
if (!static_cast<Impl::DecoratedSurface const *>
Expand All @@ -1897,7 +1937,7 @@ bool ClientSubsector::hasDecorations() const
return true;
}
}
return false;
return false;*/
}

void ClientSubsector::generateLumobjs()
Expand Down
4 changes: 1 addition & 3 deletions doomsday/apps/client/src/render/rend_main.cpp
Expand Up @@ -5426,8 +5426,8 @@ static void drawLumobjs(Map &map)

if (!devDrawLums) return;

DGL_PushState();
DGL_Disable(DGL_DEPTH_TEST);
//glDisable(GL_CULL_FACE);
DGL_CullFace(DGL_NONE);

map.forAllLumobjs([] (Lumobj &lob)
Expand Down Expand Up @@ -5471,9 +5471,7 @@ static void drawLumobjs(Map &map)
return LoopContinue;
});

//glEnable(GL_CULL_FACE);
DGL_PopState();
DGL_Enable(DGL_DEPTH_TEST);
}

static String labelForLineSideSection(LineSide &side, dint sectionId)
Expand Down
6 changes: 4 additions & 2 deletions doomsday/apps/client/src/world/base/surface.cpp
Expand Up @@ -267,8 +267,10 @@ Surface &Surface::setMaterial(Material *newMaterial, bool isMissingFix)
#endif

// Notify interested parties.
DENG2_FOR_AUDIENCE2(MaterialChange, i) i->surfaceMaterialChanged(*this);

DENG2_FOR_AUDIENCE2(MaterialChange, i)
{
i->surfaceMaterialChanged(*this);
}
return *this;
}

Expand Down

0 comments on commit 8aea604

Please sign in to comment.