Skip to content

Commit

Permalink
Merge branch 'master' into felix/project-ubo
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed May 7, 2024
2 parents ae4edea + 1a9dd6f commit 1d870cd
Show file tree
Hide file tree
Showing 42 changed files with 375 additions and 349 deletions.
File renamed without changes.
13 changes: 13 additions & 0 deletions bindings/pydeck/.readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
sphinx:
configuration: docs/conf.py
python:
install:
- method: pip
path: .
extra_requirements:
- docs
build:
os: "ubuntu-22.04"
tools:
python: "3.9"
7 changes: 2 additions & 5 deletions docs/api-reference/carto/fetch-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ fetchMap({cartoMapId}).then(map => new Deck(map));
### Integration with CARTO basemaps

```js
import mapboxgl from 'mapbox-gl';

fetchMap({cartoMapId}).then(({initialViewState, mapStyle, layers}) => {
// Add Mapbox GL for the basemap. It's not a requirement if you don't need a basemap.
const MAP_STYLE = `https://basemaps.cartocdn.com/gl/${mapStyle.styleType}-gl-style/style.json`;
const deckgl = new deck.DeckGL({
container: 'container',
controller: true,
mapStyle: MAP_STYLE,
// (Optional) Include a basemap.
mapStyle: `https://basemaps.cartocdn.com/gl/${mapStyle.styleType}-gl-style/style.json`,
initialViewState,
layers
});
Expand Down
46 changes: 28 additions & 18 deletions docs/api-reference/core/attribute-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ the attributes that should be auto-calculated.
```js
attributeManager.add({
positions: {size: 2, accessor: 'getPosition', update: calculatePositions},
colors: {size: 4, type: GL.UNSIGNED_BYTE, accessor: 'getColor', update: calculateColors}
colors: {size: 4, type: 'unorm8', accessor: 'getColor', update: calculateColors}
});
```

Expand All @@ -61,13 +61,10 @@ Takes a single parameter as a map of attribute descriptor objects:
* keys are attribute names
* values are objects with attribute definitions:
- luma.gl [accessor parameters](https://luma.gl/docs/api-reference-legacy/classes/accessor):
* `type` (string, optional) - data type of the attribute, see "Remarks" section below.
* `type` (string, optional) - data type of the attribute, see "Remarks" section below. Default `'float32'`.
* `size` (number) - number of elements per vertex
* `normalized` (boolean) - default `false`
* `integer` (boolean) - WebGL2 only, default `false`
* `divisor` (boolean, optional) - `1` if this is an instanced attribute
(a.k.a. divisor). Default to `0`.
- deck.gl attribute configurations:
* `stepMode` (string, optional) - One of `'vertex'`, `'instance'` and `'dynamic'`. If set to `'dynamic'`, will be resolved to `'instance'` when this attribute is applied to an instanced model, and `'vertex'` otherwise. Default `'vertex'`.
* `isIndexed` (boolean, optional) - if this is an index attribute
(a.k.a. indices). Default to `false`.
* `accessor` (string | string[] | Function) - accessor name(s) that will
Expand All @@ -85,12 +82,10 @@ Takes a single parameter as a map of attribute descriptor objects:
* `size` (number) - number of elements per vertex
* `vertexOffset` (number) - offset of the attribute by vertex (stride). Default `0`.
* `elementOffset` (number) - offset of the attribute by element. default `0`.
* `divisor` (boolean, optional) - `1` if this is an instanced attribute
(a.k.a. divisor). Default to `0`.

#### `addInstanced` {#addinstanced}

Shorthand for `add()` in which all attributes `instanced` field are set to `true`.
Shorthand for `add()` in which all attributes `stepMode` field are set to `'instance'`.


#### `remove` {#remove}
Expand Down Expand Up @@ -152,6 +147,16 @@ Notes:
* Any preallocated buffers in "buffers" matching registered attribute names will be used. No update will happen in this case.
* Calls onUpdateStart and onUpdateEnd log callbacks before and after.

#### `getBufferLayouts`

Returns WebGPU-style buffer layout descriptors.

Parameters:

* `modelInfo` (object) - a luma.gl `Model` or a similarly shaped object
+ `isInstanced` (boolean) - used to resolve `stepMode: 'dynamic'`


## Remarks

### Attribute Type
Expand All @@ -160,15 +165,20 @@ The following `type` values are supported for attribute definitions:

| type | value array type | notes |
| ---- | ---------------- | ----- |
| `GL.FLOAT` | `Float32Array` | |
| `GL.DOUBLE` | `Float64Array` | Because 64-bit floats are not supported by WebGL, the value is converted to an interleaved `Float32Array` before uploading to the GPU. It is exposed to the vertex shader as two attributes, `<attribute_name>` and `<attribute_name>64Low`, the sum of which is the 64-bit value. |
| `GL.BYTE` | `Int8Array` | |
| `GL.SHORT` | `Int16Array` | |
| `GL.INT` | `Int32Array` | |
| `GL.UNSIGNED_BYTE` | `Uint8ClampedArray` | |
| `GL.UNSIGNED_SHORT` | `Uint16Array` | |
| `GL.UNSIGNED_INT` | `Uint32Array` | |

| `float32` | `Float32Array` | |
| `float64` | `Float64Array` | Because 64-bit floats are not supported by WebGL, the value is converted to an interleaved `Float32Array` before uploading to the GPU. It is exposed to the vertex shader as two attributes, `<attribute_name>` and `<attribute_name>64Low`, the sum of which is the 64-bit value. |
| `sint8` | `Int8Array` | |
| `snorm8` | `Int8Array` | Normalized |
| `uint8` | `Uint8ClampedArray` | |
| `unorm8` | `Uint8ClampedArray` | Normalized |
| `sint16` | `Int16Array` | |
| `snorm16` | `Int16Array` | Normalized |
| `uint16` | `Uint16Array` | |
| `unorm16` | `Uint16Array` | Normalized |
| `sint32` | `Int32Array` | |
| `uint32` | `Uint32Array` | |

## Source

[modules/core/src/lib/attribute-manager.ts](https://github.com/visgl/deck.gl/blob/master/modules/core/src/lib/attribute/attribute-manager.ts)
6 changes: 0 additions & 6 deletions docs/api-reference/widgets/zoom-widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ Default: `'vertical'`

Widget button orientation. Valid options are `vertical` or `horizontal`.

#### `container` (HTMLElement, optional) {#container}

Default: `undefined`

A [compatible DOM element](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#Compatible_elements) which should be made full screen. By default, the map container element will be made full screen.

#### `zoomInLabel` (string, optional) {#zoominlabel}

Tooltip message displayed while hovering a mouse over the zoom in button.
Expand Down
4 changes: 2 additions & 2 deletions docs/developer-guide/base-maps/using-with-maplibre.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function DeckGLOverlay(props: DeckProps) {
}

function App() {
const layers: [
const layers = [
new ScatterplotLayer({
id: 'deckgl-circle',
data: [
Expand Down Expand Up @@ -180,7 +180,7 @@ import {ScatterplotLayer} from '@deck.gl/layers';
import 'maplibre-gl/dist/maplibre-gl.css';

function App() {
const layers: [
const layers = [
new ScatterplotLayer({
id: 'deckgl-circle',
data: [
Expand Down
1 change: 1 addition & 0 deletions docs/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class MyLayer {
While the 9.0 release of deck.gl does not yet support WebGPU, our goal is to enable WebGPU soon in a 9.x release. A number of changes will be required to deck.gl curtom layers:

- deck.gl now uses uniform buffers instead of global uniforms. It is not yet required to use uniform buffers but it will be necessary if you would like to run deck.gl on WebGPU in future releases.
- When defining an attribute, `type` is now a WebGPU-style [string format](https://luma.gl/docs/api-guide/gpu/gpu-attributes#vertexformat) instead of GL constant, and `divisor` is replaced by `stepMode`. See [AttributeManager.add](./api-reference/core/attribute-manager.md#add)
- WebGL draw modes `GL.TRIANGLE_FAN` and `GL.LINE_LOOP` are not supported on WebGPU. Select a different topology when creating geometries.
- The luma picking module now [uses uniform buffers](https://github.com/visgl/luma.gl/blob/master/modules/shadertools/src/modules/engine/picking/picking.ts#L34-L50). To access picking state in shaders use `picking.isActive` rather than `picking_isActive`

Expand Down
4 changes: 2 additions & 2 deletions modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ export default class HeatmapLayer<
const viewportCorners = [
viewport.unproject([0, 0]),
viewport.unproject([viewport.width, 0]),
viewport.unproject([viewport.width, viewport.height]),
viewport.unproject([0, viewport.height])
viewport.unproject([0, viewport.height]),
viewport.unproject([viewport.width, viewport.height])
].map(p => p.map(Math.fround));

// #1: get world bounds for current viewport extends
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class TriangleLayer extends Layer<_TriangleLayerProps> {
{name: 'positions', format: 'float32x3'},
{name: 'texCoords', format: 'float32x2'}
],
topology: 'triangle-fan-webgl',
topology: 'triangle-strip',
vertexCount
});
}
Expand Down
21 changes: 12 additions & 9 deletions modules/carto/src/api/request-with-parameters.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {isPureObject} from '@loaders.gl/core';
import {CartoAPIError} from './carto-api-error';
import {DEFAULT_HEADERS, DEFAULT_PARAMETERS, MAX_GET_LENGTH} from './common';
import type {APIErrorContext} from './types';

/**
* Simple encode parameter
*/
function encodeParameter(name: string, value: string | boolean | number): string {
return `${name}=${encodeURIComponent(value)}`;
function encodeParameter(name: string, value: unknown): string {
if (isPureObject(value) || Array.isArray(value)) {
return `${name}=${encodeURIComponent(JSON.stringify(value))}`;
}
return `${name}=${encodeURIComponent(value as string | boolean | number)}`;
}

const REQUEST_CACHE = new Map<string, Promise<unknown>>();
Expand All @@ -17,10 +21,11 @@ export async function requestWithParameters<T = any>({
errorContext
}: {
baseUrl: string;
parameters?: Record<string, string>;
parameters?: Record<string, unknown>;
headers: Record<string, string>;
errorContext: APIErrorContext;
}): Promise<T> {
parameters = {...DEFAULT_PARAMETERS, ...parameters};
const key = createCacheKey(baseUrl, parameters || {}, customHeaders || {});
if (REQUEST_CACHE.has(key)) {
return REQUEST_CACHE.get(key) as Promise<T>;
Expand Down Expand Up @@ -58,19 +63,17 @@ export async function requestWithParameters<T = any>({

function createCacheKey(
baseUrl: string,
parameters: Record<string, string>,
parameters: Record<string, unknown>,
headers: Record<string, string>
): string {
const parameterEntries = Object.entries(parameters).sort(([a], [b]) => (a > b ? 1 : -1));
const headerEntries = Object.entries(headers).sort(([a], [b]) => (a > b ? 1 : -1));
return JSON.stringify({baseUrl, parameters: parameterEntries, headers: headerEntries});
}

function createURLWithParameters(baseUrl: string, parameters: Record<string, string>): string {
const encodedParameters = Object.entries({...DEFAULT_PARAMETERS, ...parameters}).map(
([key, value]) => {
return encodeParameter(key, value);
}
function createURLWithParameters(baseUrl: string, parameters: Record<string, unknown>): string {
const encodedParameters = Object.entries(parameters).map(([key, value]) =>
encodeParameter(key, value)
);
return `${baseUrl}?${encodedParameters.join('&')}`;
}
2 changes: 1 addition & 1 deletion modules/carto/src/sources/base-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const SOURCE_DEFAULTS: SourceOptionalOptions = {
headers: {}
};

export async function baseSource<UrlParameters extends Record<string, string>>(
export async function baseSource<UrlParameters extends Record<string, unknown>>(
endpoint: MapType,
options: Partial<SourceOptionalOptions> & SourceRequiredOptions,
urlParameters: UrlParameters
Expand Down
8 changes: 4 additions & 4 deletions modules/carto/src/sources/boundary-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export type BoundaryQuerySourceOptions = SourceOptions &
};
type UrlParameters = {
columns?: string;
filters?: string;
filters?: Record<string, unknown>;
tilesetTableName: string;
matchingColumn: string;
propertiesSqlQuery: string;
queryParameters?: string;
queryParameters?: Record<string, unknown> | unknown[];
};

export const boundaryQuerySource = async function (
Expand All @@ -40,10 +40,10 @@ export const boundaryQuerySource = async function (
urlParameters.columns = columns.join(',');
}
if (filters) {
urlParameters.filters = JSON.stringify(filters);
urlParameters.filters = filters;
}
if (queryParameters) {
urlParameters.queryParameters = JSON.stringify(queryParameters);
urlParameters.queryParameters = queryParameters;
}
return baseSource<UrlParameters>('boundary', options, urlParameters) as Promise<TilejsonResult>;
};
4 changes: 2 additions & 2 deletions modules/carto/src/sources/boundary-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type BoundaryTableSourceOptions = SourceOptions &
propertiesTableName: string;
};
type UrlParameters = {
filters?: string;
filters?: Record<string, unknown>;
tilesetTableName: string;
columns?: string;
matchingColumn: string;
Expand All @@ -30,7 +30,7 @@ export const boundaryTableSource = async function (
urlParameters.columns = columns.join(',');
}
if (filters) {
urlParameters.filters = JSON.stringify(filters);
urlParameters.filters = filters;
}
return baseSource<UrlParameters>('boundary', options, urlParameters) as Promise<TilejsonResult>;
};
4 changes: 2 additions & 2 deletions modules/carto/src/sources/h3-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type UrlParameters = {
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
q: string;
queryParameters?: string;
queryParameters?: Record<string, unknown> | unknown[];
};

export const h3QuerySource = async function (
Expand All @@ -40,7 +40,7 @@ export const h3QuerySource = async function (
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (queryParameters) {
urlParameters.queryParameters = JSON.stringify(queryParameters);
urlParameters.queryParameters = queryParameters;
}
return baseSource<UrlParameters>('query', options, urlParameters) as Promise<TilejsonResult>;
};
4 changes: 2 additions & 2 deletions modules/carto/src/sources/quadbin-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type UrlParameters = {
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
q: string;
queryParameters?: string;
queryParameters?: Record<string, unknown> | unknown[];
};

export const quadbinQuerySource = async function (
Expand All @@ -41,7 +41,7 @@ export const quadbinQuerySource = async function (
urlParameters.aggregationResLevel = String(aggregationResLevel);
}
if (queryParameters) {
urlParameters.queryParameters = JSON.stringify(queryParameters);
urlParameters.queryParameters = queryParameters;
}
return baseSource<UrlParameters>('query', options, urlParameters) as Promise<TilejsonResult>;
};
8 changes: 4 additions & 4 deletions modules/carto/src/sources/vector-query-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export type VectorQuerySourceOptions = SourceOptions &

type UrlParameters = {
columns?: string;
filters?: string;
filters?: Record<string, unknown>;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
tileResolution?: string;
q: string;
queryParameters?: string;
queryParameters?: Record<string, unknown> | unknown[];
};

export const vectorQuerySource = async function (
Expand All @@ -48,10 +48,10 @@ export const vectorQuerySource = async function (
urlParameters.columns = columns.join(',');
}
if (filters) {
urlParameters.filters = JSON.stringify(filters);
urlParameters.filters = filters;
}
if (queryParameters) {
urlParameters.queryParameters = JSON.stringify(queryParameters);
urlParameters.queryParameters = queryParameters;
}
return baseSource<UrlParameters>('query', options, urlParameters) as Promise<TilejsonResult>;
};
4 changes: 2 additions & 2 deletions modules/carto/src/sources/vector-table-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type VectorTableSourceOptions = SourceOptions &
ColumnsOption;
type UrlParameters = {
columns?: string;
filters?: string;
filters?: Record<string, unknown>;
spatialDataType: SpatialDataType;
spatialDataColumn?: string;
tileResolution?: string;
Expand Down Expand Up @@ -45,7 +45,7 @@ export const vectorTableSource = async function (
urlParameters.columns = columns.join(',');
}
if (filters) {
urlParameters.filters = JSON.stringify(filters);
urlParameters.filters = filters;
}
return baseSource<UrlParameters>('table', options, urlParameters) as Promise<TilejsonResult>;
};

0 comments on commit 1d870cd

Please sign in to comment.