Skip to content

Commit e4d44d3

Browse files
committed
biome fix, some comments
1 parent 5fe5de4 commit e4d44d3

File tree

10 files changed

+83
-36
lines changed

10 files changed

+83
-36
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function colormapModuleFactory(name, apply_cmap) {
2424
return {
2525
name: extensionName,
2626
uniformTypes: {
27-
opacity: "f32",
28-
useTransparentColor: "u32",
27+
opacity: 'f32',
28+
useTransparentColor: 'u32'
2929
},
3030
fs: `\
3131
// uniform float opacity;
@@ -95,7 +95,7 @@ const AdditiveColormapExtension = class extends LayerExtension {
9595
opacity: this.props.opacity,
9696
useTransparentColor: this.props.useTransparentColor
9797
}
98-
})
98+
});
9999
}
100100
}
101101
};

packages/extensions/src/color-palette-3d-extensions/base-extension.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const BaseExtension = class extends LayerExtension {
1818
this.opts = this.opts || {};
1919
}
2020

21-
updateState({props, oldProps, changeFlags, ...rest}) {
22-
super.updateState({props, oldProps, changeFlags, ...rest});
21+
updateState({ props, oldProps, changeFlags, ...rest }) {
22+
super.updateState({ props, oldProps, changeFlags, ...rest });
2323
const { colors, channelsVisible } = this.props;
2424
const paddedColors = padColors({
2525
// probably can't have these as booleans in the shader?

packages/extensions/src/shader-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export function generateNumChannelsCode() {
1414
// First pass of this can be to make things work with a fixed NUM_CHANNELS...
1515
// prototyping what will need to be done for varying NUM_CHANNELS,
1616
// and what the semantics for extensions will need to be.
17-
}
17+
}

packages/layers/src/bitmap-layer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { COORDINATE_SYSTEM, CompositeLayer } from '@deck.gl/core';
22
import { BitmapLayer as BaseBitmapLayer } from '@deck.gl/layers';
33
import { GL } from '@luma.gl/constants';
44
import { Model } from '@luma.gl/engine';
5+
import { MAX_CHANNELS } from '@vivjs/constants';
56
import { addAlpha } from './utils';
67
import VivShaderAssembler from './xr-layer/viv-shader-assembler';
7-
import { MAX_CHANNELS } from '@vivjs/constants';
88

99
const PHOTOMETRIC_INTERPRETATIONS = {
1010
WhiteIsZero: 0,

packages/layers/src/xr-3d-layer/xr-3d-layer-fragment.glsl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { VIV_CHANNEL_INDEX_PLACEHOLDER } from "../xr-layer/viv-shader-assembler";
2-
const I = VIV_CHANNEL_INDEX_PLACEHOLDER.toString();
1+
import { VIV_CHANNEL_INDEX_PLACEHOLDER } from '../xr-layer/viv-shader-assembler';
2+
const I = String(VIV_CHANNEL_INDEX_PLACEHOLDER);
33
export default `\
44
#version 300 es
55
precision highp int;

packages/layers/src/xr-3d-layer/xr-3d-layer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import { Plane } from '@math.gl/culling';
3535
import fs from './xr-3d-layer-fragment.glsl';
3636
import vs from './xr-3d-layer-vertex.glsl';
3737

38+
import { MAX_CHANNELS } from '@vivjs/constants';
3839
import { ColorPalette3DExtensions } from '@vivjs/extensions';
3940
import { getDtypeValues, padContrastLimits, padWithDefault } from '../utils';
4041
import VivShaderAssembler from '../xr-layer/viv-shader-assembler';
41-
import { MAX_CHANNELS } from '@vivjs/constants';
4242

4343
const channelsModule = {
4444
name: 'channel-intensity-module',

packages/layers/src/xr-layer/utils.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import { MAX_CHANNELS } from '@vivjs/constants';
12
import { getDtypeValues } from '../utils';
2-
import { MAX_CHANNELS } from "@vivjs/constants";
33

44
import fs from './xr-layer-fragment.glsl';
55
import vs from './xr-layer-vertex.glsl';
66

77
// still figuring out how to get bindings to work properly
8-
const coreShaderModule = { fs, vs, name: "xrLayer" };
8+
const coreShaderModule = { fs, vs, name: 'xrLayer' };
99

10-
export function getRenderingAttrs(dtype, interpolation, numChannels = MAX_CHANNELS) {
10+
export function getRenderingAttrs(
11+
dtype,
12+
interpolation,
13+
numChannels = MAX_CHANNELS
14+
) {
1115
/// - WebGL1 is no longer supported by lumagl etc.
1216
/// 'device' is no longer used, possible in future we want to distinguish between WebGL and WebGPU?
1317
// Linear filtering only works when the data type is cast to Float32.
@@ -18,11 +22,11 @@ export function getRenderingAttrs(dtype, interpolation, numChannels = MAX_CHANNE
1822
// we probably want to move this kind of uniformTypes generation to some kind of helper
1923
// nb - this particular code isn't actually doing anything functionally useful as I write this
2024
const uniformTypes = {};
21-
for (let i=0; i<numChannels; i++) {
25+
for (let i = 0; i < numChannels; i++) {
2226
uniformTypes[`contrastLimits${i}`] = 'vec2<f32>';
2327
}
2428
return {
25-
shaderModule: {...coreShaderModule, uniformTypes},
29+
shaderModule: { ...coreShaderModule, uniformTypes },
2630
filter: interpolation,
2731
cast: isLinear ? data => new Float32Array(data) : data => data,
2832
...values

packages/layers/src/xr-layer/viv-shader-assembler.ts

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ShaderAssembler } from "@luma.gl/shadertools";
1+
import { ShaderAssembler } from '@luma.gl/shadertools';
22
// oops, this may cause problems for publishing... or maybe not if this is only internal.
3-
import type { AssembleShaderProps } from "@luma.gl/shadertools/dist/lib/shader-assembly/assemble-shaders";
4-
import { MAX_CHANNELS } from "@vivjs/constants";
3+
import type { AssembleShaderProps } from '@luma.gl/shadertools/dist/lib/shader-assembly/assemble-shaders';
4+
import { MAX_CHANNELS } from '@vivjs/constants';
55

66
// open question - should VivShaderAssembler be exposed as public API?
77
// I doubt many people would have a reason to want it... but I likely will.
@@ -10,29 +10,59 @@ import { MAX_CHANNELS } from "@vivjs/constants";
1010
// Users should probably be discouraged from managing their own ShaderAssemblers
1111
// especially until we are more confident in their use.
1212
// So in deciding the public form of viv extension API (which should be ergonic/well-typed & stable),
13-
// it should also allow where possible for somewhat arbitrary extensibility
13+
// it should also allow where possible for somewhat arbitrary extensibility
1414
// without getting too complex... i.e. some kind of shader generation pipeline thing.
1515
// Viv shouldn't be the place where any complex functionality along those lines
1616
// is maintained... but it should expose enough to allow other applications to experiment
1717
// with appropriate documentation on what is considered stable & supported,
1818
// vs what is there for experimental purposes.
1919

20-
export const VIV_CHANNEL_INDEX_PLACEHOLDER = Symbol('<VIV_CHANNEL_INDEX>');
20+
//may want to keep this as something that wouldn't make unprocessed shader code invalid syntax
21+
//maybe we want to use a parser to process the shader code?
22+
//(probably viv is not the layer at which we introduce something like that)
23+
export const VIV_CHANNEL_INDEX_PLACEHOLDER = Symbol('VIV_CHANNEL_INDEX');
24+
const I = String(VIV_CHANNEL_INDEX_PLACEHOLDER);
25+
//not a practical example, but the line-duplication will not work if there's a multiline expression
26+
//with mutable state. Not clear how we'd handle that in a simple way.
27+
`
28+
float mutableThing = 0.;
29+
mutableThing = opacity${I};
30+
float value${I} = mutableThing;
31+
32+
mutableThing = opacity0;
33+
float value0 = mutableThing;
34+
mutableThing = opacity1;
35+
float value1 = mutableThing;
36+
37+
mutableThing = opacity0;
38+
mutableThing = opacity1;
39+
float value0 = mutableThing;
40+
float value1 = mutableThing;
41+
`;
2142

2243
/**
23-
* Tagged-template function that expands the VIV_CHANNEL_INDEX_PLACEHOLDER symbol to the given number of channels.
24-
*
25-
* This is probably more appropriate for a public API once it's working.
44+
* (totally broken) Tagged-template function that expands the VIV_CHANNEL_INDEX_PLACEHOLDER symbol to the given number of channels.
45+
*
46+
* Something like this may be more appropriate for a public API once it's working.
2647
*/
2748
export function vivShader(numChannels: number) {
28-
return (strings: TemplateStringsArray, ...expressions: (string | symbol)[]): string => {
49+
// this is not doing remotely the right thing...
50+
// maybe the proper approach is indeed rather than trying to have something that wraps an entire shader
51+
// having ways of processing more local blocks of code
52+
// consider that repeating individual lines may be undesirable - have a way of grouping that makes sense
53+
//... comments in string above...
54+
return (
55+
strings: TemplateStringsArray,
56+
...expressions: (string | symbol)[]
57+
): string => {
2958
let result = '';
3059
for (let i = 0; i < strings.length; i++) {
3160
const str = strings[i];
3261
const expr = i < expressions.length ? expressions[i] : null;
3362

3463
// Check if this line contains the channel index placeholder
35-
const hasPlaceholder = expr === VIV_CHANNEL_INDEX_PLACEHOLDER ||
64+
const hasPlaceholder =
65+
expr === VIV_CHANNEL_INDEX_PLACEHOLDER ||
3666
(typeof expr === 'string' && expr.includes('<VIV_CHANNEL_INDEX>'));
3767

3868
if (hasPlaceholder) {
@@ -63,9 +93,9 @@ export function vivShader(numChannels: number) {
6393

6494
function processGLSLShaderLine(line: string, numChannels: number) {
6595
if (!line.includes(VIV_CHANNEL_INDEX_PLACEHOLDER.toString())) return line;
66-
let str = "";
67-
for (let i=0; i<numChannels; i++) {
68-
str += `${line.replaceAll(VIV_CHANNEL_INDEX_PLACEHOLDER.toString(), i.toString())}\n`
96+
let str = '';
97+
for (let i = 0; i < numChannels; i++) {
98+
str += `${line.replaceAll(VIV_CHANNEL_INDEX_PLACEHOLDER.toString(), i.toString())}\n`;
6999
}
70100
// Remove the trailing comma if present
71101
if (str.endsWith(',\n')) {
@@ -74,7 +104,10 @@ function processGLSLShaderLine(line: string, numChannels: number) {
74104
return str;
75105
}
76106
function processGLSLShader(shader: string, n: number) {
77-
return shader.split('\n').map(line => processGLSLShaderLine(line, n)).join('\n')
107+
return shader
108+
.split('\n')
109+
.map(line => processGLSLShaderLine(line, n))
110+
.join('\n');
78111
}
79112
export default class VivShaderAssembler extends ShaderAssembler {
80113
static defaultVivAssemblers: Record<number, VivShaderAssembler> = {};
@@ -102,7 +135,8 @@ export default class VivShaderAssembler extends ShaderAssembler {
102135
}
103136
static getVivAssembler(NUM_CHANNELS = MAX_CHANNELS) {
104137
if (!VivShaderAssembler.defaultVivAssemblers[NUM_CHANNELS]) {
105-
VivShaderAssembler.defaultVivAssemblers[NUM_CHANNELS] = new VivShaderAssembler(NUM_CHANNELS);
138+
VivShaderAssembler.defaultVivAssemblers[NUM_CHANNELS] =
139+
new VivShaderAssembler(NUM_CHANNELS);
106140
}
107141
return VivShaderAssembler.defaultVivAssemblers[NUM_CHANNELS];
108142
// return ShaderAssembler.getDefaultShaderAssembler();

packages/layers/src/xr-layer/xr-layer-fragment.glsl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { VIV_CHANNEL_INDEX_PLACEHOLDER } from "../xr-layer/viv-shader-assembler";
2-
const I = VIV_CHANNEL_INDEX_PLACEHOLDER.toString();
1+
import {
2+
VIV_CHANNEL_INDEX_PLACEHOLDER,
3+
// vivShader
4+
} from '../xr-layer/viv-shader-assembler';
5+
const I = String(VIV_CHANNEL_INDEX_PLACEHOLDER);
36
export default `\
47
#version 300 es
58
#define SHADER_NAME xr-layer-fragment-shader

packages/layers/src/xr-layer/xr-layer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import { COORDINATE_SYSTEM, Layer, picking, project32 } from '@deck.gl/core';
44
// ... needed to destructure for it to build with luma.gl 9, but we probably need to change these anyway
55
import { GL } from '@luma.gl/constants';
66
import { Geometry, Model } from '@luma.gl/engine';
7-
import { ShaderAssembler } from '@luma.gl/shadertools';
7+
import { MAX_CHANNELS } from '@vivjs/constants';
88
import { padContrastLimits } from '../utils';
99
import channels from './shader-modules/channel-intensity';
1010
import { getRenderingAttrs } from './utils';
11-
import { MAX_CHANNELS } from '@vivjs/constants';
1211
import VivShaderAssembler from './viv-shader-assembler';
1312

1413
const defaultProps = {
@@ -51,7 +50,11 @@ const XRLayer = class extends Layer {
5150
*/
5251
getShaders() {
5352
const { dtype, interpolation } = this.props;
54-
const { shaderModule, sampler } = getRenderingAttrs(dtype, interpolation, MAX_CHANNELS);
53+
const { shaderModule, sampler } = getRenderingAttrs(
54+
dtype,
55+
interpolation,
56+
MAX_CHANNELS
57+
);
5558
const extensionDefinesDeckglProcessIntensity =
5659
this._isHookDefinedByExtensions('fs:DECKGL_PROCESS_INTENSITY');
5760
const newChannelsModule = { ...channels, inject: {} };
@@ -193,7 +196,10 @@ const XRLayer = class extends Layer {
193196
});
194197
const xrLayer = {};
195198
for (let i = 0; i < MAX_CHANNELS; i++) {
196-
xrLayer[`contrastLimits${i}`] = [paddedContrastLimits[i*2], paddedContrastLimits[1 + i*2]];
199+
xrLayer[`contrastLimits${i}`] = [
200+
paddedContrastLimits[i * 2],
201+
paddedContrastLimits[1 + i * 2]
202+
];
197203
}
198204
//>>>> this is the problem I have currently, although it seems like what I pass here should be reasonable
199205
//webgl-render-pipeline.ts:412 luma.gl: Binding xrLayerUniforms not found in image-sub-layer-0,240,240,0-Background-Image-TiffPixelSource-#detail#-cached

0 commit comments

Comments
 (0)