Thanks, @Evgeni_Popov I understand that keeping track of WebGL global states is tough.
The scene.resetCachedMaterial()
again raises the depth issue.
This is an experimental project, and I learned how to better use Babylon with external context. Thanks for your help. I am closing this issue.