Skip to content

Commit 97aae18

Browse files
(feat): Upgrade deck.gl and luma.gl (#805)
* chore: wip attempt to upgrade deck&luma * (fix): set `UNPACK_ALIGNMENT` and `PACK_ALIGNMENT` correctly * (fix): use `float64` string instead of `GL.DOUBLE` * (fix): `parameters` -> `sampler` and fix some consts related to `getRenderingAttrs` * change Geometry drawMode to topology * use triangle-list rather than fan (not verified to be correct) * use setBindings in place of setUniforms * correct size of texCoord attribute * add bufferLayout to model, texCoords to attributeManager, rename shaderAssembler. * chore: apply biome fix & remove unused GL imports * chore: remove some dead code, rename (unused) gl arg, add comments * rename 'device' to 'gl' (and comment that it's unused) * set log level, allows us to see shader compilation errors * change 'attribute' & 'varying' to 'in' & 'out', don't use gl_FragColor * make sure opts are passed through draw, no null textures and 'uniform' object was spurious. * (fix) geometry indices, remove bad texCoord attribute val * no more cursed shader version patching * correct format of setParametersWebGL args * check if texture format is filterable * use setBindings for textures, setUniforms for uniforms. * remove references to WebGL1 * (fix): less wrong null texture handling * (fix): remove filterable check * passing simpler texture format, 3D still not working seemingly because of luma bug * (chore) update luma&deck * (chore): `model.delete` -> `model.destroy` * chore: update zustand * fix warning about deprecated 'import shallow' * fix typo 'magFilterFilter' * add comments on format to source-info * SizeZ comments * attempt to upgrade to luma.gl 9.0.16, dodgy lock file * regenerate pnpm-lock to fix multiple luma.gl versions * update deck & luma * apply work-around for null textures * (fix): rgb images, add alpha channel * lensSelection was being set as string when it should be int * (chore) update luma.gl * (chore) update deck.gl * allow newer react * remove apparently redundant and deprecated gl alignment parameter setting. * (chore) cleanup some old comments and unused imports * (fix) move null texture patching to a more appropriate place * remove commented code Co-authored-by: Ilan Gold <[email protected]> * (chore) remove redundant comments * (chore) remove more redundant comments * fix issue with scale-bar empty layer test by passing viewState width and height in defaultProps * fix glsl-colormap needed to be a non-dev dependency * Revert "chore: update zustand" This reverts commit 2cf31b0. * Revert "fix warning about deprecated 'import shallow'" This reverts commit e2b5d50. * Revert "remove apparently redundant and deprecated gl alignment parameter setting." This reverts commit 7a1dd44. * change comment on setParametersWebGL * Revert "fix glsl-colormap needed to be a non-dev dependency" This reverts commit f4be45b. * fix missing GL import * update type and documentation of 'interpolation' prop in line with luma changes * fix type of interpolation in defaultProps * (chore) update deck.gl * (chore): rgb comment * (fix): lint --------- Co-authored-by: ilan-gold <[email protected]>
1 parent 6a4f915 commit 97aae18

File tree

24 files changed

+1711
-1257
lines changed

24 files changed

+1711
-1257
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,4 @@ The [Changesets GitHub Action](https://github.com/changesets/action) will create
102102

103103
## 🌎 Browser Support
104104

105-
Viv supports both [WebGL1](https://caniuse.com/?search=webgl) and [WebGL2](https://caniuse.com/?search=webgl2)
106-
contexts, to provides coverage across Safari, Firefox, Chrome, and Edge. Please
107-
[file an issue](https://github.com/hms-dbmi/viv/issues/new) if you find a browser
108-
in which Viv does not work.
105+
Viv supports coverage across Safari, Firefox, Chrome, and Edge. Please [file an issue](https://github.com/hms-dbmi/viv/issues/new) if you find a browser in which Viv does not work.

packages/constants/src/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import GL from '@luma.gl/constants';
1+
import { GL } from '@luma.gl/constants';
22

33
export const MAX_COLOR_INTENSITY = 255;
44

@@ -18,28 +18,28 @@ export const DEFAULT_FONT_FAMILY =
1818
*/
1919
export const DTYPE_VALUES = {
2020
Uint8: {
21-
format: GL.R8UI,
21+
format: 'r8uint',
2222
dataFormat: GL.RED_INTEGER,
2323
type: GL.UNSIGNED_BYTE,
2424
max: 2 ** 8 - 1,
2525
sampler: 'usampler2D'
2626
},
2727
Uint16: {
28-
format: GL.R16UI,
28+
format: 'r16uint',
2929
dataFormat: GL.RED_INTEGER,
3030
type: GL.UNSIGNED_SHORT,
3131
max: 2 ** 16 - 1,
3232
sampler: 'usampler2D'
3333
},
3434
Uint32: {
35-
format: GL.R32UI,
35+
format: 'r32uint',
3636
dataFormat: GL.RED_INTEGER,
3737
type: GL.UNSIGNED_INT,
3838
max: 2 ** 32 - 1,
3939
sampler: 'usampler2D'
4040
},
4141
Float32: {
42-
format: GL.R32F,
42+
format: 'r32float',
4343
dataFormat: GL.RED,
4444
type: GL.FLOAT,
4545
// Not sure what to do about this one - a good use case for channel stats, I suppose:
@@ -48,29 +48,29 @@ export const DTYPE_VALUES = {
4848
sampler: 'sampler2D'
4949
},
5050
Int8: {
51-
format: GL.R8I,
51+
format: 'r8int',
5252
dataFormat: GL.RED_INTEGER,
5353
type: GL.BYTE,
5454
max: 2 ** (8 - 1) - 1,
5555
sampler: 'isampler2D'
5656
},
5757
Int16: {
58-
format: GL.R16I,
58+
format: 'r16int',
5959
dataFormat: GL.RED_INTEGER,
6060
type: GL.SHORT,
6161
max: 2 ** (16 - 1) - 1,
6262
sampler: 'isampler2D'
6363
},
6464
Int32: {
65-
format: GL.R32I,
65+
format: 'r32int',
6666
dataFormat: GL.RED_INTEGER,
6767
type: GL.INT,
6868
max: 2 ** (32 - 1) - 1,
6969
sampler: 'isampler2D'
7070
},
7171
// Cast Float64 as 32 bit float point so it can be rendered.
7272
Float64: {
73-
format: GL.R32F,
73+
format: 'r32float',
7474
dataFormat: GL.RED,
7575
type: GL.FLOAT,
7676
// Not sure what to do about this one - a good use case for channel stats, I suppose:

packages/extensions/src/additive-colormap-3d-extensions/base-extension.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ const BaseExtension = class extends LayerExtension {
5858
updateState({ props, oldProps, changeFlags, ...rest }) {
5959
super.updateState({ props, oldProps, changeFlags, ...rest });
6060
if (props.colormap !== oldProps.colormap) {
61-
const { gl } = this.context;
61+
const { device } = this.context;
6262
if (this.state.model) {
63-
this.state.model.delete();
64-
this.setState({ model: this._getModel(gl) });
63+
this.state.model.destroy();
64+
this.setState({ model: this._getModel(device) });
6565
}
6666
}
6767
}

packages/extensions/src/additive-colormap-extension/additive-colormap-extension.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ const AdditiveColormapExtension = class extends LayerExtension {
7373
updateState({ props, oldProps, changeFlags, ...rest }) {
7474
super.updateState({ props, oldProps, changeFlags, ...rest });
7575
if (props.colormap !== oldProps.colormap) {
76-
const { gl } = this.context;
76+
const { device } = this.context;
7777
if (this.state.model) {
78-
this.state.model.delete();
79-
this.setState({ model: this._getModel(gl) });
78+
this.state.model.destroy();
79+
this.setState({ model: this._getModel(device) });
8080
}
8181
}
8282
}

packages/extensions/src/lens-extension/lens-module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default {
7171
`,
7272
'fs:#main-end': `
7373
bool isFragOnLensBounds = frag_on_lens_bounds(vTexCoord);
74-
gl_FragColor = (lensEnabled && isFragOnLensBounds) ? vec4(lensBorderColor, 1.) : gl_FragColor;
74+
fragColor = (lensEnabled && isFragOnLensBounds) ? vec4(lensBorderColor, 1.) : fragColor;
7575
`
7676
}
7777
};

packages/layers/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@deck.gl/geo-layers": "catalog:",
2828
"@deck.gl/layers": "catalog:",
2929
"@luma.gl/constants": "catalog:",
30+
"@luma.gl/shadertools": "catalog:",
3031
"@luma.gl/core": "catalog:",
3132
"@luma.gl/engine": "catalog:",
3233
"@luma.gl/webgl": "catalog:"

packages/layers/src/bitmap-layer.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { COORDINATE_SYSTEM, CompositeLayer } from '@deck.gl/core';
22
import { BitmapLayer as BaseBitmapLayer } from '@deck.gl/layers';
3-
import GL from '@luma.gl/constants';
4-
import { Geometry, Model } from '@luma.gl/core';
3+
import { GL } from '@luma.gl/constants';
4+
import { Model } from '@luma.gl/engine';
5+
import { addAlpha } from './utils';
56

67
const PHOTOMETRIC_INTERPRETATIONS = {
78
WhiteIsZero: 0,
@@ -88,22 +89,11 @@ class BitmapLayerWrapper extends BaseBitmapLayer {
8889
photometricInterpretation,
8990
transparentColorInHook
9091
);
91-
if (!gl) {
92-
return null;
93-
}
94-
95-
/*
96-
0,0 --- 1,0
97-
| |
98-
0,1 --- 1,1
99-
*/
100-
return new Model(gl, {
92+
return new Model(this.context.device, {
10193
...this.getShaders(),
10294
id: this.props.id,
103-
geometry: new Geometry({
104-
drawMode: GL.TRIANGLES,
105-
vertexCount: 6
106-
}),
95+
bufferLayout: this.getAttributeManager().getBufferLayouts(),
96+
topology: 'triangle-list',
10797
isInstanced: false,
10898
inject: {
10999
'fs:DECKGL_FILTER_COLOR': photometricInterpretationShader
@@ -131,15 +121,17 @@ class BitmapLayerWrapper extends BaseBitmapLayer {
131121
*/
132122
const BitmapLayer = class extends CompositeLayer {
133123
initializeState(args) {
134-
const { gl } = this.context;
124+
const { device } = this.context;
135125
// This tells WebGL how to read row data from the texture. For example, the default here is 4 (i.e for RGBA, one byte per channel) so
136126
// each row of data is expected to be a multiple of 4. This setting (i.e 1) allows us to have non-multiple-of-4 row sizes. For example, for 2 byte (16 bit data),
137127
// we could use 2 as the value and it would still work, but 1 also works fine (and is more flexible for 8 bit - 1 byte - textures as well).
138128
// https://stackoverflow.com/questions/42789896/webgl-error-arraybuffer-not-big-enough-for-request-in-case-of-gl-luminance
139129
// This needs to be called here and not in the BitmapLayerWrapper because the `image` prop is converted to a texture outside of the layer, as controlled by the `image` type.
140130
// See: https://github.com/visgl/deck.gl/pull/5197
141-
gl.pixelStorei(GL.UNPACK_ALIGNMENT, 1);
142-
gl.pixelStorei(GL.PACK_ALIGNMENT, 1);
131+
device.setParametersWebGL({
132+
[GL.UNPACK_ALIGNMENT]: 1,
133+
[GL.PACK_ALIGNMENT]: 1
134+
});
143135
super.initializeState(args);
144136
}
145137

@@ -149,6 +141,7 @@ const BitmapLayer = class extends CompositeLayer {
149141
transparentColor: transparentColorInHook
150142
} = this.props;
151143
const transparentColor = getTransparentColor(photometricInterpretation);
144+
this.props.image.data = addAlpha(this.props.image.data);
152145
return new BitmapLayerWrapper(this.props, {
153146
// transparentColor is a prop applied to the original image data by deck.gl's
154147
// BitmapLayer and needs to be in the original colorspace. It is used to determine

packages/layers/src/image-layer.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { COORDINATE_SYSTEM, CompositeLayer } from '@deck.gl/core';
2-
import GL from '@luma.gl/constants';
2+
import { GL } from '@luma.gl/constants';
33

44
import { ColorPaletteExtension } from '@vivjs/extensions';
55
import { SIGNAL_ABORTED, isInterleaved } from '@vivjs/loaders';
@@ -27,7 +27,7 @@ const defaultProps = {
2727
onViewportLoad: { type: 'function', value: null, compare: true },
2828
interpolation: {
2929
type: 'number',
30-
value: GL.NEAREST,
30+
value: 'nearest',
3131
compare: true
3232
},
3333
extensions: {
@@ -88,9 +88,8 @@ const ImageLayer = class extends CompositeLayer {
8888
// data is for BitmapLayer and needs to be of form { data: Uint8Array, width, height };
8989
raster.data = raster.data[0];
9090
if (raster.data.length === raster.width * raster.height * 3) {
91-
// data is RGB (not RGBA) and need to update texture formats
92-
raster.format = GL.RGB;
93-
raster.dataFormat = GL.RGB;
91+
// Previously there was a rgb format, but now we only convert to rgba in BitmapLater
92+
raster.format = 'rgba8unorm';
9493
}
9594
}
9695

packages/layers/src/multiscale-image-layer/multiscale-image-layer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CompositeLayer } from '@deck.gl/core';
2-
import GL from '@luma.gl/constants';
2+
import { GL } from '@luma.gl/constants';
33
import { Matrix4 } from '@math.gl/core';
44

55
import { ColorPaletteExtension } from '@vivjs/extensions';
@@ -108,8 +108,8 @@ const MultiscaleImageLayer = class extends CompositeLayer {
108108
if (isInterleaved(loader[resolution].shape)) {
109109
tile.data = tile.data[0];
110110
if (tile.data.length === tile.width * tile.height * 3) {
111-
tile.format = GL.RGB;
112-
tile.dataFormat = GL.RGB; // is this not properly inferred?
111+
// This indicates the data is RGB but it will be converted to RGBA
112+
tile.format = 'rgba8unorm';
113113
}
114114
// can just return early, no need to check for webgl2
115115
return tile;
@@ -179,7 +179,7 @@ const MultiscaleImageLayer = class extends CompositeLayer {
179179
onHover,
180180
onClick,
181181
// Background image is nicest when LINEAR in my opinion.
182-
interpolation: GL.LINEAR,
182+
interpolation: 'linear',
183183
onViewportLoad: null
184184
});
185185
const layers = [baseLayer, tiledLayer];

packages/layers/src/multiscale-image-layer/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import GL from '@luma.gl/constants';
21
import { getImageSize, isInterleaved } from '@vivjs/loaders';
32

43
import BitmapLayer from '../bitmap-layer';
@@ -50,6 +49,6 @@ export function renderSubLayers(props) {
5049
id: `tile-sub-layer-${bounds}-${id}`,
5150
tileId: { x, y, z },
5251
// The auto setting is NEAREST at the highest resolution but LINEAR otherwise.
53-
interpolation: z === maxZoom ? GL.NEAREST : GL.LINEAR
52+
interpolation: z === maxZoom ? 'nearest' : 'linear'
5453
});
5554
}

0 commit comments

Comments
 (0)