I'm attempting to add around 4.5k SCNNode objects to a scene. Their geometries are one of two SCNPlanes, whose materials are rendered by CALayers (but I don't think that matters, the CALayerDelegates are only called once each, so that doesn't seem to be an issue.) Performance is terrible (< 1fps.)
With .showsStatistics enabled I see I'm doing almost 3.5k draw calls, which is my problem according to this WWDC video from 2017. So, as suggested, I add all my nodes to one parent node and call .flattenedClone() on it before adding that to the scene's root node. That gets me graphical corruption and a repeating error on my console:
2019-08-28 14:50:39.122937+0200 Breadboard[867:53252] [SceneKit] Error: C3DProgramHashCodeStoreRegisterProgramForRendererElement - index out of capacity (8192 > 8192)
(The x in "x > 8192" goes up by one every line)
If I split the nodes into two groups and call .flattenedClone() on them before adding the results to the root node the error goes away but my draw call count goes up to almost 5k!
What's going on? Why does calling .flattenedClone() on a node with around 2.5k nodes not... flatten it?