-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hit-detection support for WebGL #3065
Add hit-detection support for WebGL #3065
Conversation
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); | ||
gl.texImage2D( | ||
gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above, texture-related, code should probably shared. It is not specific to hit detection. If we change the filtering parameters for the rendering to the screen I don't want to have to change some other code for the hit detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
I am looking forward to reviewing this in more detail, but it looks great already! Thanks a lot. |
goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT; | ||
var elementSize = context.hasOESElementIndexUint ? 4 : 2; | ||
|
||
var i, groupStart, groupEnd, numItems, start, end, feature; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The groupEnd variable is not used. And it looks like the linter (or compiler) is not able to catch this when the variables are all defined on the same line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed with tsauerwein@abb5fad
This looks very good to me. I just added two comments, one about an unused variable ( |
One thing: we need to implement "skip feature", but I think this can be done as a separate PR. |
/** | ||
* The last layer state. | ||
* @private | ||
* @type {?ol.layer.LayerState} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ?
is not needed (untested)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact it is required, because ol.layer.LayerState
is only a typedef
.
... with the atlas for the original images, so that the offsets are the same.
585fd42
to
974823d
Compare
This looks good to merge to me. Any objections? |
LGTM |
+1 |
Add hit-detection support for WebGL
Thanks for the reviews! |
This PR implements
forEachFeatureAtPixel
for WebGL. From the idea it uses the same technique as the canvas renderer: We have a 1x1px framebuffer in which we draw feature-by-feature (in reverse order) and check 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.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
onmousemove
. We came up with ahasFeatureAtPixel
method, for which I will open a separate PR (here is already an example to give you an idea).