gwaldron / osgearth

3D Maps for OpenSceneGraph / C++14
https://www.pelicanmapping.com/home-1/opensource
Other
1.47k stars 772 forks source link

SamplerBindings are not pruned when Shared Layer is Removed from REX Engine #2568

Closed cruseDD closed 2 months ago

cruseDD commented 2 months ago

osgEarth Version (required): 3.4, maybe also master

What is the problem? We are using shared ImageLayer with Rex and a custom shader effect to render a gloss effect. When removing the gloss layer, the sampler bindings seem to remain and can interfere with other rendering passes.

The problem seems to come from RexTerrainEngineNode::removeImageLayer where binding usage is cleared, and the unit is unassigned. However, the binding keeps its sourceUID. However, when purging orphaned layers PurgeOrphanedLayers::apply, the method TileNode::refreshSharedSamplers is called which in turn does:

if (bindings[i].isActive() == false) { _renderModel.clearSharedSampler(i); }

isActive returns true, as long as the sourceUID is assigned and thus the sampler is not cleared.

How have you tried to resolve it?

I suggest to make RexTerrainEngineNode::removeImageLayer also unassign the sourceUID

cruseDD commented 2 months ago

I could create a PR but it seems i am lacking permissions to create a branch.

gwaldron commented 2 months ago

To submit a PR you need to fork the repository and create the branch from your fork.

cruseDD commented 2 months ago

Thanks. I have added a minimal PR.

gwaldron commented 2 months ago

Thank you! Merged.