-
Notifications
You must be signed in to change notification settings - Fork 3
Performance best practices
richardTingle edited this page May 3, 2024
·
2 revisions
VR applications are very sensitive to any frame rate drops. These cause unpleasant stuttering and repeated frames in the VR view. One avoidable cause of frame rate drops is the first render during which a new geometry is added. Time may be spent:
- Generating the geometry in memory
- Loading models from disk
- Calculating the pick collision tree
These problems can be resolved by using the DeferredAttachmentService. This is an app state that can be registered into the application and can be used to prepare geometries on a separate thread and then attach them to the scene graph only when they are "ready".
During application initialisation:
getStateManager().attach(new DeferredAttachmentService()); // 1 thread
//or
getStateManager().attach(new DeferredAttachmentService(noOfThreadsToUse));
Then later:
DeferredAttachmentService deferredAttachmentService = getStateManager().getState(DeferredAttachmentService.ID, DeferredAttachmentService.class);
deferredAttachmentService.attachWhenReady(nodeToAttachTo, () -> {
return buildComplexScene()
}
The deferredAttachmentService will:
- Call the buildComplexScene() function in another thread meaning that that doesn't block the main render thread if its doing something expensive
- Ensure that any geometries in the scene have
geometry.getMesh().createCollisionData();called on them
And only after all of that has completed will it attach the spatial to the scene. This should mean the new geometry attaches without causing a framerate drop.