Skip to content

Commit 107fee4

Browse files
authored
[docs] Updater luma.gl v9 and API changes (#9786)
* Update docs for luma.gl v9 and API changes Revised documentation to reflect luma.gl v9 updates, including changes to GPU parameter handling, device initialization, and usage of string constants over WebGL constants. * Sections and better formatting * Update upgrade-guide.md * Remove outdated note about setting GPU parameters Deleted a note referencing the use of the `onDeviceInitialized` callback and luma.gl's `setParameters` method as an alternative way to set GPU parameters, likely due to deprecation or changes in recommended practices.
1 parent 754d85c commit 107fee4

File tree

3 files changed

+134
-21
lines changed

3 files changed

+134
-21
lines changed

docs/api-reference/core/deck.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,35 +147,39 @@ Note:
147147

148148
#### `parameters` (object) {#parameters}
149149

150-
Expects an object with GPU parameters. Before each frame is rendered, this object will be passed to luma.gl's `setParameters` function to reset the GPU context parameters, e.g. to disable depth testing, change blending modes etc. The default parameters set by `Deck` on initialization are the following:
150+
Expects an object with GPU parameters. Before each frame is rendered, this object will be passed to luma.gl's `RenderPass` to reset the GPU context parameters, e.g. to disable depth testing, change blending modes etc. The default parameters set by `Deck` on initialization are the following:
151151

152152
```js
153153
{
154154
blend: true,
155-
blendFunc: [GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA],
155+
blendColorSrcFactor: 'src-alpha',
156+
blendColorDstFactor: 'one-minus-src-alpha',
157+
blendAlphaSrcFactor: 'one',
158+
blendAlphaDstFactor: 'one-minus-src-alpha'
156159
polygonOffsetFill: true,
157-
depthTest: true,
158-
depthFunc: GL.LEQUAL
160+
depthWriteEnabled: true,
161+
depthCompare: 'less-equal'
159162
}
160163
```
161164

162-
Refer to the luma.gl [setParameters](https://github.com/visgl/luma.gl/blob/8.5-release/modules/gltools/docs/api-reference/parameter-setting.md) API for documentation on supported parameters and values.
165+
Refer to the luma.gl [GPU parameters](https://luma.gl/docs/api-reference/core/parameters) API for documentation on supported parameters and values.
163166

164167
```js
165-
import GL from '@luma.gl/constants';
166168
new Deck({
167169
// ...
168170
parameters: {
169-
blendFunc: [GL.ONE, GL.ONE, GL.ONE, GL.ONE],
170-
depthTest: false
171+
blendColorSrcFactor: 'one',
172+
blendColorDstFactor: 'one',
173+
blendAlphaSrcFactor: 'one',
174+
blendAlphaDstFactor: 'one'
175+
depthWriteEnabled: false
171176
}
172177
});
173178
```
174179

175180
Notes:
176181

177182
- Any GPU `parameters` prop supplied to individual layers will still override the global `parameters` when that layer is rendered.
178-
- An alternative way to set `parameters` is to instead define the `onWebGLInitialized` callback (it receives the `gl` context as parameter) and call the luma.gl `setParameters` method inside it.
179183

180184
#### `layers` (LayersList) {#layers}
181185

docs/api-reference/mesh-layers/simple-mesh-layer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import TabItem from '@theme/TabItem';
1616
```js
1717
import {Deck} from '@deck.gl/core';
1818
import {SimpleMeshLayer} from '@deck.gl/mesh-layers';
19-
import {OBJLoader} from '@deck.gl/obj';
19+
import {OBJLoader} from '@loaders.gl/obj';
2020

2121
const layer = new SimpleMeshLayer({
2222
id: 'SimpleMeshLayer',
@@ -49,7 +49,7 @@ new Deck({
4949
```ts
5050
import {Deck, PickingInfo} from '@deck.gl/core';
5151
import {SimpleMeshLayer} from '@deck.gl/mesh-layers';
52-
import {OBJLoader} from '@deck.gl/obj';
52+
import {OBJLoader} from '@loaders.gl/obj';
5353

5454
type BartStation = {
5555
name: string;
@@ -90,7 +90,7 @@ new Deck({
9090
import React from 'react';
9191
import {DeckGL} from '@deck.gl/react';
9292
import {SimpleMeshLayer} from '@deck.gl/mesh-layers';
93-
import {OBJLoader} from '@deck.gl/obj';
93+
import {OBJLoader} from '@loaders.gl/obj';
9494
import type {PickingInfo} from '@deck.gl/core';
9595

9696
type BartStation = {

docs/upgrade-guide.md

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,125 @@ The following issues are known and can be expected to resolve in a 9.0 patch:
7272

7373
### Typescript
7474

75-
Typescript is now enabled on all modules. The `'@deck.gl/xxx/typed'` packages are removed.
75+
Typescript is now enabled on all modules. The `'@deck.gl/xxx/typed'` packages are removed.
7676

77-
### luma.gl v9 Updates
77+
```ts
78+
// deck.gl v9
79+
import {Deck} from '@deck.gl/core'
80+
81+
// deck.gl v8
82+
import {Deck} from '@deck.gl/core/typed'
83+
```
84+
85+
### @deck.gl/core and luma.gl v9 Updates
7886

7987
The biggest changes in deck.gl v9 are due to the upgrade to the luma.gl v9 API. Fortunately, deck.gl encapsulates most of the luma.gl API so the changes to deck.gl applications should be limited, in particular if the application does not directly interact with GPU resources.
8088

81-
Quick summary:
89+
For more information read the [luma v9 porting guide](https://luma.gl/docs/legacy/porting-guide)
90+
91+
#### External GL Context
92+
93+
`DeckProps.gl (WebGLRenderingContext)` should be replaced with `device`: [Device](https://luma.gl/docs/api-reference/core/device):
94+
95+
```ts
96+
// deck.gl v9
97+
import {Deck} from '@deck.gl/core'
98+
import {luma} from '@luma.gl/core'
99+
import {webgl2Adapter}'@luma.gl/webgl'
100+
101+
new Deck({
102+
device: await luma.createDevice({adapters: [webgl2Adapter]})
103+
});
104+
105+
// deck.gl v8
106+
import {Deck} from '@deck.gl/core/typed'
107+
108+
const canvas = document.getElementById('myCanvas');
82109

83-
- `DeckProps.gl (WebGLRenderingContext)` should be replaced with `device`: [Device](https://luma.gl/docs/api-reference/core/device).
84-
- `DeckProps.glOptions (WebGLContextAttributes)` should be replaced with `DeckProps.deviceProps.webgl`: `deviceProps: {type: 'webgl', webgl: ...glOptions}`: [WebGLDeviceProps](https://luma.gl/docs/api-reference/webgl/#webgldeviceprops)
110+
new Deck({
111+
gl: canvas.getContext('webgl2')
112+
});
113+
```
114+
115+
#### GL Options and Device Initialization
116+
117+
- `DeckProps.glOptions (WebGLContextAttributes)` should be replaced with `DeckProps.deviceProps.webgl`: [WebGLContextAttributes](https://luma.gl/docs/api-reference/core/device#webglcontextattributes)
85118
- `DeckProps.glOptions.preserveDrawingBuffers` is now set by default, and does not need to be overridden.
119+
- `DeckProps.glOptions.powerPreference` is now set to `'high-performance'` by default, and does not need to be overridden.
86120
- `DeckProps.onWebGLInitialized` callback is now `DeckProps.onDeviceInitialized`.
87-
- `LayerProps.parameters` and `LayerProps.textureParameters` no longer use WebGL constants, but instead use (WebGPU style) [string constants](https://luma.gl/docs/api-reference/core/parameters/).
88-
- When providing [binary data attributes](./api-reference/core/layer.md#data), `type` is now a WebGPU-style [string format](https://luma.gl/docs/api-guide/gpu/gpu-attributes#vertexformat) instead of a GL constant.
89-
- GPU resources should no longer be created by directly instantiating classes. For example, instead of `new Buffer(gl)` use `device.createBuffer()`, instead of `new Texture()` use `device.createTexture()`. See [Device methods](https://luma.gl/docs/api-reference/core/device#methods).
121+
122+
```ts
123+
// deck.gl v9
124+
import {Deck} from '@deck.gl/core'
125+
126+
new Deck({
127+
deviceProps: {
128+
type: 'webgl',
129+
// powerPreference: 'high-performance' is now set by default
130+
webgl: {
131+
stencil: true
132+
// preserveDrawingBuffers: true is now set by default
133+
}
134+
},
135+
onDeviceInitialized: (device) => {
136+
const gl = device.handle // WebGL2RenderingContext when using a webgl device
137+
}
138+
});
139+
140+
// deck.gl v8
141+
import {Deck} from '@deck.gl/core/typed'
142+
143+
new Deck({
144+
glOptions: {
145+
stencil: true,
146+
preserveDrawingBuffers: true,
147+
powerPreference: 'high-performance'
148+
},
149+
onWebGLInitialized: (gl) => {}
150+
});
151+
```
152+
153+
#### GPU Parameters
154+
155+
`DeckProps.parameters`, `LayerProps.parameters`, and `LayerProps.textureParameters` no longer use WebGL constants, but instead use (WebGPU style) [string constants](https://luma.gl/docs/api-reference/core/parameters/):
156+
157+
```ts
158+
// deck.gl v9 using string constants (preferred)
159+
import {Deck} from '@deck.gl/core'
160+
new Deck({
161+
parameters: {
162+
blendColorOperation: 'add',
163+
blendColorSrcFactor: 'src-alpha',
164+
blendColorDstFactor: 'one',
165+
blendAlphaOperation: 'add',
166+
blendAlphaSrcFactor: 'one-minus-dst-alpha',
167+
blendAlphaDstFactor: 'one'
168+
}
169+
})
170+
171+
// deck.gl v9 using GL constants
172+
// The constant module remains but is now considered an internal luma.gl module, and is no longer intended to be imported by applications.
173+
import {Deck} from '@deck.gl/core'
174+
import {GL} from '@luma.gl/constants' // Note the ESM import
175+
176+
new Deck({
177+
parameters: {
178+
blendEquation: [GL.ADD, GL.ADD],
179+
blendFunc: [GL.ONE, GL.ONE, GL.ONE, GL.ONE],
180+
}
181+
})
182+
183+
// deck.gl v8
184+
import {Deck} from '@deck.gl/core/typed'
185+
import GL from '@luma.gl/constants';
186+
187+
new Deck({
188+
parameters: {
189+
blendEquation: [GL.ADD, GL.ADD],
190+
blendFunc: [GL.ONE, GL.ONE, GL.ONE, GL.ONE],
191+
}
192+
})
193+
```
90194

91195
#### Custom Layers
92196

@@ -112,14 +216,19 @@ class MyLayer {
112216
}
113217
```
114218

115-
116219
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:
117220

118221
- 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.
119222
- 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)
120223
- WebGL draw modes `GL.TRIANGLE_FAN` and `GL.LINE_LOOP` are not supported on WebGPU. Select a different topology when creating geometries.
121224
- 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`
122225

226+
#### Additional Changes
227+
228+
- When providing [binary data attributes](./api-reference/core/layer.md#data), `type` is now a WebGPU-style [string format](https://luma.gl/docs/api-guide/gpu/gpu-attributes#vertexformat) instead of a GL constant.
229+
- GPU resources should no longer be created by directly instantiating classes. For example, instead of `new Buffer(gl)` use `device.createBuffer()`, instead of `new Texture()` use `device.createTexture()`. See [Device methods](https://luma.gl/docs/api-reference/core/device#methods).
230+
231+
123232
### @deck.gl/mapbox
124233

125234
`MapboxLayer` has been removed. Use `MapboxOverlay` instead.

0 commit comments

Comments
 (0)