AnalyticalGraphicsInc/cesium — pull request #1737 by kring (2014-05-23 02:26:45+00:00)
Title: Add QuadtreePrimitive

This change may look big and intimidating, but look at it this way: all I've done is to refactor `GlobeSurface` into two classes, `QuadtreePrimitive` and `GlobeSurfaceTileProvider`.

`QuadtreePrimitive` has all the logic for traversing a quadtree of tiles, selecting the ones to render based on projection of a tile error estimate to the screen, culling tiles that are not visible, initiating loading of tiles that are needed but not yet resident, and replacing tiles when the cache is full.

All of the actual tile loading (`loadTile`), distance computation (`getDistanceToTile`), visibility computation (`isTileVisible`), and rendering (`renderTile`) is delegated to an instance implementing the `QuadtreeTileProvider` interface. `GlobeSurfaceTileProvider` implements that interface for rendering terrain and imagery.

The point of all this rejuggling is that it lets us use the quadtree-based LOD algorithm in more places than just regular terrain. Some examples (none of these implemented in this pull request):
* Tile up OpenStreetMap building data, do LOD and culling, and render it using Geometries and Appearances.
* Same as above except for enormous polygons like national borders. Lots of other variations on this theme are possible.
* Render multiple terrain surfaces to show different layers of the Earth.
* Implement something like [KML regions](https://developers.google.com/kml/documentation/regions).

Bonus feature 1: this branch also adds the ability to render an unlimited number of imagery layers (at appropriate performance cost, of course), regardless of the number of texture units available on the hardware.

Bonus feature 2: adds a `getBoundingSphere` method to `Primitive` that gets the bounding sphere for a given scene mode. Adds a `complete` property that returns true when the `Primitive` is in the `COMPLETE` state. Both of these are very helpful when using Geometries and Appearances inside `QuadtreePrimitive` tiles. See the new `QuadtreePrimitive` Sandcastle example.