Commit Graph
100 Commits
Author SHA1 Message Date
Olivier Guyot fc555241ea ShaderBuilder / simplify check/parse code a bit 2019-10-23 09:22:12 +02:00
Olivier Guyot 1fe5a68e16 Fix the triangles style in the wbegl-points-layer example 2019-10-22 23:27:26 +02:00
Olivier Guyot 948003ff27 Rewrite to filter-points-webgl example to use a Webgl points layer
The demonstrated features have been recreated using a literal
style (filtering, pulse animation).
2019-10-22 23:17:00 +02:00
Olivier Guyot d837166a1b Literal Style / add new math operators 2019-10-22 23:17:00 +02:00
Olivier Guyot c659c05de8 ShaderBuilder / fix stretch operator GLSL expression 2019-10-22 23:17:00 +02:00
Olivier Guyot 485ade42b5 Literal Style / add support for color interpolation 2019-10-22 23:17:00 +02:00
Olivier Guyot 85c3aae454 ShaderBuilder / add support for color interpolation in parse 2019-10-22 23:17:00 +02:00
Olivier Guyot a29fc016f5 ShaderBuilder / formatColor/Array utilities now output vecX(...) 2019-10-22 23:17:00 +02:00
Olivier Guyot 19eadaea24 Shader Builder / add type checking in expressions parsing
All expressions will now be type checked before actually being parsed.
2019-10-22 23:17:00 +02:00
Olivier Guyot b8e8d30df0 Shader Builder / add utilities for checking an expression type
Type checking is done either against a literal value (number, string...)
or against the operator in case of an expression.

Sometimes it is not possible to infer only one type, for example
the value 'transparent' could either be a color or a string. This
is covered by the fact that all operators expect exactly one type
for their arguments.
2019-10-22 23:17:00 +02:00
Olivier Guyot f43637cc33 Shader Builder / support strings in formatColor 2019-10-22 23:17:00 +02:00
Olivier Guyot 56faf4c3ad Color / add an isStringColor utility function 2019-10-22 23:17:30 +02:00
Olivier Guyot a0b271a812 Literal Style / add support for variables in the style
These variables are accessed using the `var` operator, and are meant
to be mutated directly in the style object. When doing so,
the new value will always be used for the render.

This is intended to be used for modifying the style through external
parameters such as an input field, a slider, mouse position etc.
2019-10-22 23:17:00 +02:00
Olivier Guyot a1c00744d1 Webgl points renderer / throw if shader compilation fails
This should only happen if providing handcrafted shaders to the renderer.
2019-10-22 23:17:00 +02:00
Olivier Guyot 94b8cf6af3 Webgl / add support for a time operator in literal styles
This required adding `u_time` as one of the default uniforms provided by the
webgl helper.
2019-10-22 23:17:23 +02:00
Olivier Guyot 0c0c8c5d56 Literal Style / add support for a filter property 2019-10-22 23:17:00 +02:00
Olivier Guyot e38250ee14 ShaderBuilder / add fragment discard expression in shader params 2019-10-22 11:39:30 +02:00
Olivier Guyot 7b66b294a8 ShaderBuilder / attempt to clarify the way attributes are handled in parseSymbolStyle 2019-10-22 11:18:39 +02:00
Olivier Guyot 9ee93cd2cf ShaderBuilder / refactoring to use an actual builder pattern
There is now a ShaderBuilder class with chainable methods
to specify more easily the contents of the final shaders.
This is to avoid passing around large objects to different functions,
and allow for a richer API.

The documentation has also been corrected and clarified.
2019-10-22 11:12:06 +02:00
Olivier Guyot 87414256e2 Heatmap / use worker events instead of timeout for test 2019-10-11 14:06:27 +02:00
Olivier Guyot b44a6ab26a Heatmap / add hit detection shaders 2019-10-08 13:27:31 +02:00
Olivier Guyot 13147e0b82 Add experimental tags to a few examples & added doc in the README
Plus some typos.
2019-09-26 20:19:23 +02:00
Olivier Guyot 09134a6091 Shader builder / typecheck fix for parse fn 2019-09-26 16:30:19 +02:00
Olivier Guyot 858f0fc0cc Update the webgl-points-layer example to reflect new possibilities 2019-09-26 16:30:19 +02:00
Olivier Guyot 28d157af56 Shader builder / add circle and triangle shapes for symbols 2019-09-26 16:30:19 +02:00
Olivier Guyot 9b3a9b5eca Shader builder / add logic for transforming a style into shader params
This was previously handled by the WebGLPointsLayer class, but is now
externalized and tested.
2019-09-26 16:20:35 +02:00
Olivier Guyot d5caabbbfc Shader builder / add basic expression parsing
Only a handful of expressions for now, very loosely based on the
mapbox style spec. Also only work on numerical values.
2019-09-26 16:20:35 +02:00
Olivier Guyot 02e5e1776c Hit detection / fix test for wrapped geometries hit detection
Also restores the whole unit test suite.
2019-09-26 15:59:14 +02:00
Olivier Guyot b89c1255f7 Canvas vector / Avoid modifying the coordinates array in place 2019-09-26 15:34:31 +02:00
Olivier Guyot 7e4383f554 Webgl renderer / now accepts any kind of layer (not just vector) 2019-09-26 15:33:54 +02:00
Olivier Guyot 7da3b60061 Webgl Layer / rename literalStyle property to style 2019-09-26 14:44:32 +02:00
Olivier Guyot 0732f17fd3 Webgl layer / remove @api tag & better doc
Also the webgl layer now only inherits from the Layer class,
not the VectorLayer one.
2019-09-26 14:42:04 +02:00
Olivier Guyot 9e9aa66f5f Webgl points renderer / restore check for hit detection readiness 2019-09-25 17:22:36 +02:00
Olivier Guyot 34572da17b Webgl shader builder / expanded functionality
Now takes in a custom object with attributes, uniforms etc.
The WebGLPointsLayer uses this to handle image icons.
2019-09-25 17:22:36 +02:00
Olivier Guyot b8564d503a Webgl icon example / restore texture for icons 2019-09-25 17:22:36 +02:00
Olivier Guyot 9e55a8b2f0 Webgl / linting & test fixes 2019-09-25 17:22:36 +02:00
Olivier Guyot 610a846149 Webgl points renderer / make the hit detection optional 2019-09-25 17:22:36 +02:00
Olivier Guyot 23c2999cab Webgl points renderer / fix hit detection
Due to the fact that the points renderer does not know for sure
which attributes will be used for rendering, it is now mandatory
to provide both vertex/fragment shaders for rendering AND hit
detection.

The hit detection shaders should expect having an `a_hitColor`
that they should return to allow matching the feature uid.

This will be all one eventually by shader builders under the hood.
2019-09-25 12:11:09 +02:00
Olivier Guyot 109f9718f9 Webgl renderer / fix existing examples
The shaders were rewritten manually for those, althoughj eventually they
should use the shader builder utilities as well.
2019-09-25 11:09:07 +02:00
Olivier Guyot 2b36445ecc Webgl / Adapt the points renderer to use custom attributes
Now most attributes will be custom ones defined by the user of the renderer.
The hit detection is broken for now and still has to be fixed.
Also it is not possible anymore to give a texture to the renderer,
this will have to be fixed as well.
2019-09-25 10:11:27 +02:00
Olivier Guyot 076b674d6f Webgl helper / easier utility for binding attributes
also a bit of improvement on the doc
2019-09-24 19:10:07 +02:00
Olivier Guyot 30f19f8317 Webgl points renderer / terminates worker & dispose helper 2019-09-24 17:59:21 +02:00
Olivier Guyot cb2c596a6d Add an example for the WebGLPointsLayer with editable style 2019-09-24 17:59:21 +02:00
Olivier Guyot 4d7562fca2 Add a new WebGLPointsLayer type using the shader builder utilities
This required adding a `a_index` attribute in the points layer renderer
to be able to make the precomputed shaders to work.
2019-09-24 17:24:56 +02:00
Olivier Guyot a6b8d920b7 Webgl / add a fixed fragment shader builder for symbols 2019-09-24 15:49:07 +02:00
Olivier Guyot 4de0c0b082 Webgl / add a very simple vertex shader builder utility
This only allows including hardcoded values in the shader,
and only for symbols.
2019-09-24 15:43:26 +02:00
Olivier Guyot 167fa6b8a0 Add property to all layers api doc 2019-09-24 10:58:55 +02:00
Olivier Guyot 449686527b Document how to avoid canvas reuse for layers
This restores the `map.forEachLayerAtPixel` functionality.

This is intended to help with openlayers#9720
2019-09-24 09:46:32 +02:00
Olivier Guyot cae8c333f2 Enable https on tile layer in webgl sprite example 2019-09-23 17:51:32 +02:00
Olivier Guyot 5b5a3657f0 Fix typings in workers
The worker self object is simply cast to any to make sure typescript
does not complain.
Actual typecheck may be restored once the following issue is fixed:
https://github.com/microsoft/TypeScript/issues/20595
2019-09-23 15:37:48 +02:00
Olivier Guyot 05a0600fe5 Webgl icon example / render map when texture ready 2019-08-31 08:59:34 +02:00
Olivier Guyot 732b383b53 Webgl points / re-render when buffers have been built offthread 2019-08-31 08:41:04 +02:00
Olivier Guyot 29d07ada54 Webgl helper / skip binding texture if underlying image is not ready 2019-08-30 11:02:31 +02:00
Olivier Guyot 5c1191dd5c Webgl points / skip hit detection render when out of sync
This happens when the indices buffer has been generated by the
worker but not the hit detection vertices buffer.
2019-08-30 10:38:41 +02:00
Olivier Guyot c48350b666 Webgl buffer / add utility getSize function
Saves checking whether the buffer was initialized with
an array already
2019-08-30 10:38:02 +02:00
Olivier Guyot e57e660819 Webgl points / use default vertex shader for hit detection
Otherwise we were getting errors if the custom
vertex shader was missing varyings expected by
HIT_FRAGMENT_SHADER.
2019-08-30 10:16:55 +02:00
Olivier Guyot 2f3e8d04f1 Webgl points / fix hit detection for retina devices 2019-07-11 00:05:55 +02:00
Olivier Guyot 28b99767f8 Webgl points / read only one pixel for feature hit detection
Also implements `hasFeatureAtCoordinate`.

`hitTolerance` is not supported for now.
2019-06-28 09:12:20 +02:00
Olivier Guyot e852294938 Webgl / improve reading of render targets data
Now two methods are available: `readAll` and `readPixel`,
and the data from the render target is not re-read every time unless
`clearCachedData` is called.
2019-06-28 09:12:20 +02:00
Olivier Guyot 917950a32b Improve icon-sprite-webgl example to include hit detection 2019-06-28 09:12:20 +02:00
Olivier Guyot 5ffca0633c Webgl Points / Add support for feature hit detection
For now only `forEachFeatureAtCoordinate` is implemented.

Each time the viewport is rendered, another similar render pass is
done using the specific hit detection instructions. Feature uid's are
encoded in the r,g,b,a channels and can then be decoded on the fly.

Note: the `readPixels` operation is taking a lot of time,
around 10-20ms each frame.
2019-06-28 09:12:20 +02:00
Olivier Guyot 38920867fb Webgl Helper / Add a method to prepare drawing to render targets 2019-06-28 09:12:20 +02:00
Olivier Guyot 6224d749c4 WebGL / Introduced the WebGLRenderTarget class
This utility class simplifies rendering to a texture & reading the
results of the render.

It also allows clearing its content before a new render.
2019-06-28 09:12:20 +02:00
Olivier Guyot 1257ade199 Webgl renderer / rename function to avoid confusion
`getBlankTexture` was too close to `WebGLHelper#createTexture`
2019-06-28 09:12:20 +02:00
Olivier Guyot f25a16d90c Webgl helper / rework create texture utils
Now only one util is available: `createTexture`, which
is tested and allows binding an image and reusing an existing texture.
2019-06-28 09:12:20 +02:00
Olivier Guyot b6425187de Remove unused WebGLShader class 2019-06-28 09:06:16 +02:00
Olivier Guyot 2b5e5459ab Webgl points / add hit detection buffers generation
Hit detection is done by rendering features with their id encoded in the
color attribute. A parallel set of render instructions and a second
vertex buffer is used specifically for that.
2019-06-28 09:06:16 +02:00
Olivier Guyot 8145b358c0 Webgl renderer / add id encode/decode utils 2019-06-28 09:06:16 +02:00
Olivier Guyot 034e0be76f Vector Source / index all features by uid
Previously features were indexed by uid only when they
did not have a defined id.
A new method was added: `getFeatureByUid`. This is not part of
the public API.
This will facilitate the lookup of features for hit detection.
2019-06-28 09:06:16 +02:00
Olivier Guyot 2412fe0211 Webgl / remove handling of element_index_uint extension
From now on we will assume this extension is always enabled.

An error message have been added in the unlikely scenario of a lack
of support.
2019-06-05 14:46:15 +02:00
Olivier Guyot 98b0c65450 Rendering tests / add custom web worker loader
Also includes a change in the rollup-babel plugin to avoid
adding helpers as dependencies (which would give out errors).
2019-06-01 15:33:36 +02:00
Olivier Guyot 698816030e Webgl points / fix unit tests 2019-06-01 15:33:36 +02:00
Olivier Guyot 03e70bd10e Webgl points / handle using short instead of int for indices
This is controlled by the availability of the OES_element_index_uint
webgl extension.
2019-06-01 15:33:36 +02:00
Olivier Guyot e0983cb1c6 Webgl worker / add tests, some typing and documentation
The worker currently works by receiving GENERATE_BUFFERS messages and
will send back the same kind of message, with the generated buffers
attached. All properties of the original message are kept, so that
when a GENERATE_BUFFERS message comes back to the main thread it
is possible to know what and how the buffers where generated.

This is typically used for the `projectionTransform` matrix, and
will also be necessary when working with tiles.
2019-06-01 15:33:36 +02:00
Olivier Guyot a366803cdd Webgl / use the new buffer API in helper & the points renderer 2019-06-01 15:33:36 +02:00
Olivier Guyot 33d007ce01 Webgl buffer / now stores data in typed arrays
The `WebGLBuffer` class API was changed in order to allow populating
the internal array in different ways.
2019-06-01 15:33:31 +02:00
Olivier Guyot 8566cfc227 Webgl points / get back the instructions array from the worker
This means we won't have to recreate a binary buffer (through a typed array)
on every `rebuildBuffer` call.
2019-06-01 15:25:24 +02:00
Olivier Guyot 65be907095 Webgl points / shifts the buffer write logic in a worker
The worker receives a transferable array of instructions
and sends back two transferable arrays (vertex and index buffer).
The projection transform is also sent so that when the main thread
receives the buffers from the worker it also knows which projection to
apply when rendering the geometries.
2019-06-01 15:25:11 +02:00
Olivier Guyot 532b8194b1 Webgl points / use the new typed-array based utils for buffers
`rebuildBuffer` is still a very CPU intensive task and is blocking the
main thread.
2019-06-01 15:20:04 +02:00
Olivier Guyot eb912d95ca Webgl / refactor utilities to work only on typed arrays
The base webgl renderer module now has two types of utilities:
* `writeXFeatureInstructions` will write a series of values in a given
typed array, which represent how a given feature will be rendered; for points,
this means position, size, color, etc.
* `writeXFeatureToBuffers` will fill up the given index & vertex buffers
with values based on the provided render instructions

As such, the logic for rendering features is:
user-input style > instructions array >(*) index/vertex buffers > draw

(*) this transformation is intended to be done on a worker.
2019-06-01 15:19:37 +02:00
Olivier Guyot 442fa907ce Vector source / prevent adding features with duplicate id...
...in the collection.

Previously two features with the same id could be pushed manually in the
features collection and stay there.

This would cause an error when clearing the source.

Fixes #6183.
2019-05-24 23:29:48 +02:00
Olivier Guyot 39de2451bc Merge pull request #9537 from jahow/webgl-geojson-refactoring
WebGL / Points renderer refactoring
2019-05-15 11:44:40 +02:00
Olivier Guyot e11e3c5f6e Webgl / minor function renaming 2019-05-15 11:30:24 +02:00
Olivier Guyot c705775d75 Linting 2019-05-15 10:20:31 +02:00
Olivier Guyot 9ca75e9d43 Webgl points / rebuild buffers when source change 2019-05-15 10:18:53 +02:00
Olivier Guyot 5d2b7fe4bb Webgl points / use the helper ton compute the projection transform
The `WebGLHelper` class now provides a `makeProjectionTransform` method
that updates a transform to match the projection for a given frame state.

This also means that the WebGLHelper does not set the projection matrix
uniform anymore, this is the responsibility of the renderer as
the rendered coordinates will not be in world space from now on.
2019-05-15 10:18:47 +02:00
Olivier Guyot fb455891ce Webgl points / make coordinates in view space to avoid precision glitches
Fixes #9479
2019-05-15 10:18:47 +02:00
Olivier Guyot 3e2e45ce6d Webgl helper / add the possibility to use transforms as custom uniforms
These will be translated into 4x4 matrices in GLSL.
2019-05-15 10:18:47 +02:00
Olivier Guyot 75eb62363a WebGL points / rebuild buffers only when extent changed 2019-05-15 10:18:47 +02:00
Olivier Guyot 523097903a WebGL points / rebuild buffers on every non animation frame 2019-05-15 10:18:22 +02:00
Olivier Guyot c6d214b585 Webgl / implement support for custom attributes in webgl buffers
Only numerical attributes can be pushed in webgl buffers.
2019-05-15 10:15:55 +02:00
Olivier Guyot 27e520add4 WebGL points / use pushFeatureInBuffer util
Feature objects are converted to geoJSON with the properties
set for rendering.
2019-05-15 09:47:00 +02:00
Olivier Guyot 3a429d3f6c Webgl / add utils for pushing geojson geometries in webgl buffers
For now only point geometries are handled.
2019-05-15 09:44:41 +02:00
Olivier Guyot 5e36468245 Webgl / add a simple Layer renderer for common logic
This will eventually provides utilities for manipulating & rendering data
2019-05-15 09:43:29 +02:00
Olivier Guyot a2d83f5358 WebGL points / add minimal tests 2019-05-15 09:42:15 +02:00
Olivier GuyotandFrédéric Junod 1c13893dd1 Mapbox Example / remove es6 shorthand
thanks @fredj

Co-Authored-By: Frédéric Junod <frederic.junod@camptocamp.com>
2019-05-13 16:38:10 +02:00
Olivier Guyot 4a1cda715d Layer / update doc to reflect custom render function support 2019-05-13 16:22:27 +02:00
Olivier Guyot c9d1725f5c Composite renderer / trigger a render even when the source is undefined 2019-05-13 16:16:53 +02:00
Olivier Guyot 4bf314f9e6 Mapbox Example / simplify to use a custom render function 2019-05-13 16:16:53 +02:00
Olivier Guyot 14f580fe30 Layer / accepts a custom render function 2019-05-13 16:16:53 +02:00