Posterous theme by Cory Watilo

Caching WebGL Calls in SceneJS 2.0

SceneJS 2.0 does a ton of caching to efficiently adapt its abstract JSON-based scene graph API to WebGL. 

I just added another layer of caching, which turned out to give a major performance boost - anyone who's not getting high enough FPS should try the latest build and see if it improves things.

The engine now compiles its internal draw list to a cached list of WebGL function calls, which execute very quickly. The calls are generated by higher-order functions, which cache parameters for the calls in their closures, such as variable locations in programs etc. A classic JavaScript optimisation strategy. 

  1. Scene definition - a JSON definition is parsed to create a scene graph with resources buffered for its nodes on the GPU (VBOs, textures etc). 
  2. Draw list compilation - the scene graph is traversed to compile a sequence of WebGL state changes.
  3. Call list compilation - the draw list is compiled into a fast list of WebGL calls with arguments prepared from the draw list states. Call list nodes are functions that wrap WebGL calls, and are created by higher-order functions which prepare and memoize their arguments in closures.
  4. State sorting - the call list nodes are sorted on their corresponding draw list states to minimize the number of state changes that will go down the OpenGL pipeline.
  5. The call list is executed to render the frame.

 

House-smaller