From 89458064cbb926b55561148d3063329b3c203e9c Mon Sep 17 00:00:00 2001 From: felixpalmer Date: Thu, 26 Sep 2024 11:35:08 +0200 Subject: [PATCH] Remove updateModuleSettings from codebase (#9160) --- .../src/heatmap-layer/heatmap-layer.ts | 1 - modules/core/src/lib/layer.ts | 37 ++++++++++++------- .../shaderlib/project/viewport-uniforms.ts | 21 +++++------ modules/core/src/types/layer-props.ts | 3 +- modules/extensions/src/fp64/fp64-extension.ts | 7 +--- test/modules/extensions/fp64.spec.ts | 4 +- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts b/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts index 258c0301e9a..3ea2f082dc9 100644 --- a/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts +++ b/modules/aggregation-layers/src/heatmap-layer/heatmap-layer.ts @@ -615,7 +615,6 @@ export default class HeatmapLayer< const moduleSettings = this.getModuleSettings(); this._setModelAttributes(weightsTransform.model, attributes); weightsTransform.model.setVertexCount(this.getNumInstances()); - weightsTransform.model.updateModuleSettings(moduleSettings); const weightProps: WeightProps = { radiusPixels, diff --git a/modules/core/src/lib/layer.ts b/modules/core/src/lib/layer.ts index 57abce9de42..ed7db558791 100644 --- a/modules/core/src/lib/layer.ts +++ b/modules/core/src/lib/layer.ts @@ -342,7 +342,8 @@ export default abstract class Layer extends Component< /** Update shader module parameters */ setModuleParameters(moduleParameters: any): void { for (const model of this.getModels()) { - model.updateModuleSettings(moduleParameters); + // HACK as fp64 is not yet ported to UBO + model.uniforms = {ONE: 1}; } } @@ -1081,12 +1082,13 @@ export default abstract class Layer extends Component< // @ts-expect-error material is not a Layer prop const {material, modelMatrix} = this.props; - // Do not pass picking module to avoid crash - // TODO remove `setModuleParameters` from codebase - const {picking: _, ...rest} = moduleParameters; - this.setModuleParameters(rest); + this.setModuleParameters({}); const { + // mask + maskChannels, + maskMap, + maskSources, // shadow shadowEnabled, drawToShadowMap, @@ -1108,6 +1110,12 @@ export default abstract class Layer extends Component< lightSources } = moduleParameters; + const maskProps = { + maskChannels, + maskMap, + maskSources + }; + const shadowProps = { viewport, shadowEnabled, @@ -1130,22 +1138,25 @@ export default abstract class Layer extends Component< terrainSkipRender }; + const projectProps = { + viewport, + devicePixelRatio, + modelMatrix, + coordinateSystem, + coordinateOrigin + } as ProjectProps; + this.setShaderModuleProps({ // TODO Revisit whether this is necessary once all layers ported to UBO + mask: maskProps, shadow: shadowProps, terrain: terrainProps, layer: {opacity}, lighting: lightSources, phongMaterial: material, gouraudMaterial: material, - picking: {isActive, isAttribute} as PickingProps, - project: { - viewport, - devicePixelRatio, - modelMatrix, - coordinateSystem, - coordinateOrigin - } as ProjectProps + picking: {isActive, isAttribute} as const satisfies PickingProps, + project: projectProps }); } diff --git a/modules/core/src/shaderlib/project/viewport-uniforms.ts b/modules/core/src/shaderlib/project/viewport-uniforms.ts index 81e09aa869b..e2797de3f5d 100644 --- a/modules/core/src/shaderlib/project/viewport-uniforms.ts +++ b/modules/core/src/shaderlib/project/viewport-uniforms.ts @@ -19,8 +19,7 @@ // THE SOFTWARE. /* eslint-disable complexity, camelcase */ -import {mat4, vec4} from '@math.gl/core'; -import type {NumberArray16} from '@math.gl/types'; +import {mat4, Matrix4Like, vec4} from '@math.gl/core'; import {COORDINATE_SYSTEM, PROJECTION_MODE} from '../../lib/constants'; @@ -35,8 +34,8 @@ type Vec4 = [number, number, number, number]; // To quickly set a vector to zero const ZERO_VECTOR: Vec4 = [0, 0, 0, 0]; // 4x4 matrix that drops 4th component of vector -const VECTOR_TO_POINT_MATRIX: NumberArray16 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]; -const IDENTITY_MATRIX: NumberArray16 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; +const VECTOR_TO_POINT_MATRIX: Matrix4Like = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]; +const IDENTITY_MATRIX: Matrix4Like = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; const DEFAULT_PIXELS_PER_UNIT2: Vec3 = [0, 0, 0]; const DEFAULT_COORDINATE_ORIGIN: Vec3 = [0, 0, 0]; @@ -127,8 +126,8 @@ function calculateMatrixAndOffset( coordinateSystem: CoordinateSystem, coordinateOrigin: Vec3 ): { - viewMatrix: NumberArray16; - viewProjectionMatrix: NumberArray16; + viewMatrix: Matrix4Like; + viewProjectionMatrix: Matrix4Like; projectionCenter: Vec4; originCommon: Vec4; cameraPosCommon: Vec3; @@ -177,8 +176,8 @@ function calculateMatrixAndOffset( } return { - viewMatrix: viewMatrix as NumberArray16, - viewProjectionMatrix: viewProjectionMatrix as NumberArray16, + viewMatrix: viewMatrix as Matrix4Like, + viewProjectionMatrix: viewProjectionMatrix as Matrix4Like, projectionCenter, originCommon, cameraPosCommon, @@ -209,8 +208,8 @@ export type ProjectUniforms = { scale: number; wrapLongitude: boolean; - viewProjectionMatrix: NumberArray16; - modelMatrix: NumberArray16; + viewProjectionMatrix: Matrix4Like; + modelMatrix: Matrix4Like; // This is for lighting calculations cameraPosition: Vec3; @@ -219,7 +218,7 @@ export type ProjectUniforms = { export type ProjectProps = { viewport: Viewport; devicePixelRatio?: number; - modelMatrix?: NumberArray16 | null; + modelMatrix?: Matrix4Like | null; coordinateSystem?: CoordinateSystem; coordinateOrigin?: Vec3; autoWrapLongitude?: boolean; diff --git a/modules/core/src/types/layer-props.ts b/modules/core/src/types/layer-props.ts index 2d8005561bd..3b015359c12 100644 --- a/modules/core/src/types/layer-props.ts +++ b/modules/core/src/types/layer-props.ts @@ -10,6 +10,7 @@ import type {Texture, TextureProps} from '@luma.gl/core'; import type {Buffer, Parameters} from '@luma.gl/core'; import type {Loader} from '@loaders.gl/loader-utils'; import type {LightingModuleSettings} from '../shaderlib/index'; +import type {Matrix4Like} from '@math.gl/core'; export type LayerData = | Iterable @@ -169,7 +170,7 @@ export type LayerProps = { /** * A 4x4 matrix to transform local coordianates to the world space. */ - modelMatrix?: NumericArray | null; + modelMatrix?: Matrix4Like | null; /** * (Geospatial only) normalize geometries that cross the 180th meridian. Default false. */ diff --git a/modules/extensions/src/fp64/fp64-extension.ts b/modules/extensions/src/fp64/fp64-extension.ts index 9912758d9dd..6ba81633e51 100644 --- a/modules/extensions/src/fp64/fp64-extension.ts +++ b/modules/extensions/src/fp64/fp64-extension.ts @@ -42,10 +42,7 @@ export default class Fp64Extension extends LayerExtension { } draw(this: Layer, params: any, extension: this): void { - const {moduleParameters} = params; - if (moduleParameters) { - const {viewport} = moduleParameters; - this.setShaderModuleProps({project64: {viewport}}); - } + const {viewport} = params.context; + this.setShaderModuleProps({project64: {viewport}}); } } diff --git a/test/modules/extensions/fp64.spec.ts b/test/modules/extensions/fp64.spec.ts index 463aa43ed46..c45d5a7da69 100644 --- a/test/modules/extensions/fp64.spec.ts +++ b/test/modules/extensions/fp64.spec.ts @@ -2,7 +2,7 @@ import test from 'tape-promise/tape'; import {Fp64Extension} from '@deck.gl/extensions'; import {COORDINATE_SYSTEM} from '@deck.gl/core'; import {ScatterplotLayer} from '@deck.gl/layers'; -import {testLayer} from '@deck.gl/test-utils'; +import {getLayerUniforms, testLayer} from '@deck.gl/test-utils'; test('Fp64Extension', t => { const testCases = [ @@ -22,7 +22,7 @@ test('Fp64Extension', t => { extensions: [new Fp64Extension()] }, onAfterUpdate: ({layer}) => { - const {uniforms} = layer.state.model; + const uniforms = getLayerUniforms(layer); t.ok(uniforms.viewProjectionMatrix, 'has fp64 uniforms'); t.ok(uniforms.viewProjectionMatrix64Low, 'has fp64 uniforms'); }