openlayers/ol3 — pull request #3065 by tsauerwein (2014-12-19 16:59:59+00:00)
Title: Add hit-detection support for WebGL

This PR implements `forEachFeatureAtPixel` for WebGL. From the idea it uses the same technique as the canvas renderer: We have a 1x1px [framebuffer](https://github.com/tsauerwein/ol3/blob/e01e556e3ab1a3ae4af2334d2bb23a84a22614f4/src/ol/webgl/context.js#L301) in which we [draw feature-by-feature](https://github.com/tsauerwein/ol3/blob/e01e556e3ab1a3ae4af2334d2bb23a84a22614f4/src/ol/render/webgl/webglreplay.js#L732) (in reverse order) and [check](https://github.com/tsauerwein/ol3/blob/e01e556e3ab1a3ae4af2334d2bb23a84a22614f4/src/ol/render/webgl/webglreplay.js#L1063) if there is some color.

Commit e01e556 uses an optimization, that should also be used for the canvas hit-detection: Using the new `renderBuffer` we build a box around the given position. And then we only check those features that intersect this box. This drastically improves the performance for WebGL.

Speaking about performance, canvas gives better results. I made some tests showing 1000, 5000, ... features on a map (zoomed-out so that really all features are shown). Then I measured the time to do a `forEachFeatureAtPixel` call.

# of features Canvas WebGL
1000 10 ms 20 - 80 ms
5000 35 ms 70 - 350 ms
10000 60 ms 140 - 650 ms
20000 120 ms 340 - 1400 ms
50000 320 ms 800 - 3000 ms

For WebGL I have given a range, because it depends on where you click with the optimization made in e01e556. If you click somewhere in the map where are no features, it's faster.

But still, for WebGL, it's too slow to run `forEachFeatureAtPixel` on `mousemove`. We came up with a `hasFeatureAtPixel` method, for which I will open a separate PR ([here](http://tsauerwein.github.io/ol3/webgl-point-hasFeatureAtPixel/examples/icon-sprite-webgl.html) is already an example to give you an idea).