Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For discussion: remove withParametersWebGL #8731

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/website/geojson/app.jsx
Expand Up @@ -94,6 +94,7 @@ export default function App({data = DATA_URL, mapStyle = MAP_STYLE}) {
new GeoJsonLayer({
id: 'geojson',
data,
autoHighlight: true,
opacity: 0.8,
stroked: false,
filled: true,
Expand Down
12 changes: 2 additions & 10 deletions modules/core/src/lib/deck.ts
Expand Up @@ -35,7 +35,6 @@ import {luma} from '@luma.gl/core';
import {WebGLDevice} from '@luma.gl/webgl';
import {Timeline} from '@luma.gl/engine';
import {AnimationLoop} from '@luma.gl/engine';
import {GL} from '@luma.gl/constants';
import type {Device, DeviceProps, Framebuffer} from '@luma.gl/core';
import type {ShaderModule} from '@luma.gl/shadertools';

Expand All @@ -54,6 +53,7 @@ import type {RecognizerOptions, MjolnirGestureEvent, MjolnirPointerEvent} from '
import type {TypedArrayManagerOptions} from '../utils/typed-array-manager';
import type {ViewStateChangeParameters, InteractionState} from '../controllers/controller';
import type {PickingInfo} from './picking/pick-info';
import type {LayerParameters} from '../passes/layers-pass';
import type {PickByPointOptions, PickByRectOptions} from './deck-picker';
import type {LayersList} from './layer-manager';
import type {TooltipContent} from './tooltip';
Expand Down Expand Up @@ -114,7 +114,7 @@ export type DeckProps<ViewsT extends ViewOrViews = ViewOrViews> = {
pickingRadius?: number;

/** WebGL parameters to be set before each frame is rendered. */
parameters?: any;
parameters?: LayerParameters;
/** If supplied, will be called before a layer is drawn to determine whether it should be rendered. */
layerFilter?: ((context: FilterContext) => boolean) | null;

Expand Down Expand Up @@ -946,14 +946,6 @@ export default class Deck<ViewsT extends ViewOrViews = ViewOrViews> {
// instrumentGLContext(this.device.gl, {enable: true, copyState: true});
}

this.device.setParametersWebGL({
blend: true,
blendFunc: [GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA, GL.ONE, GL.ONE_MINUS_SRC_ALPHA],
polygonOffsetFill: true,
depthTest: true,
depthFunc: GL.LEQUAL
});

this.props.onDeviceInitialized(this.device);
if (this.device instanceof WebGLDevice) {
// Legacy callback - warn?
Expand Down
10 changes: 2 additions & 8 deletions modules/core/src/lib/layer.ts
Expand Up @@ -43,6 +43,7 @@ import {load} from '@loaders.gl/core';

import type {Loader} from '@loaders.gl/loader-utils';
import type {CoordinateSystem} from './constants';
import type {LayerParameters} from '../passes/layers-pass';
import type Attribute from './attribute/attribute';
import type {Model} from '@luma.gl/engine';
import type {PickingInfo, GetPickingInfoParams} from './picking/pick-info';
Expand Down Expand Up @@ -1046,7 +1047,7 @@ export default abstract class Layer<PropsT extends {} = {}> extends Component<
renderPass: RenderPass;
moduleParameters: any;
uniforms: any;
parameters: any;
parameters: LayerParameters;
}): void {
this._updateAttributeTransition();

Expand All @@ -1069,13 +1070,6 @@ export default abstract class Layer<PropsT extends {} = {}> extends Component<
this.setShaderModuleProps({picking: {isActive, isAttribute}});
}

// Apply polygon offset to avoid z-fighting
// TODO - move to draw-layers
const {getPolygonOffset} = this.props;
const offsets = (getPolygonOffset && getPolygonOffset(uniforms)) || [0, 0];

context.device.setParametersWebGL({polygonOffset: offsets});

for (const model of this.getModels()) {
model.setParameters(parameters);
}
Expand Down
17 changes: 15 additions & 2 deletions modules/core/src/passes/layers-pass.ts
Expand Up @@ -56,6 +56,14 @@ export type RenderStats = {
pickableCount: number;
};

const DEFAULT_PARAMETERS: LayerParameters = {
blendColorSrcFactor: 'src-alpha',
blendColorDstFactor: 'one-minus-src-alpha',
blendAlphaSrcFactor: 'one',
blendAlphaDstFactor: 'one-minus-src-alpha',
depthCompare: 'less-equal'
};

/** A Pass that renders all layers */
export default class LayersPass extends Pass {
_lastRenderIndex: number = -1;
Expand Down Expand Up @@ -191,7 +199,9 @@ export default class LayersPass extends Pass {
moduleParameters
);
layerParam.layerParameters = {
...DEFAULT_PARAMETERS,
...layer.context.deck?.props.parameters,
...layer.props.parameters,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea: would it be useful if props.parameters could also accept a function to allow the application to control the final parameters? By passing in the Pass the Layer could have more control:

new Layer({
  ...,
  parameters: (pass: Pass, parameters: Parameters): Parameters {...}

})

...this.getLayerParameters(layer, layerIndex, viewport)
};
}
Expand Down Expand Up @@ -262,7 +272,7 @@ export default class LayersPass extends Pass {
renderPass,
moduleParameters,
uniforms: {layerIndex: layerRenderIndex},
parameters: layerParameters
parameters: layerParameters!
});
} catch (err) {
layer.raiseError(err as Error, `drawing ${layer} to ${pass}`);
Expand All @@ -288,7 +298,10 @@ export default class LayersPass extends Pass {
layerIndex: number,
viewport: Viewport
): LayerParameters {
return layer.props.parameters;
const {getPolygonOffset} = layer.props;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have deprecated getPolygonOffset in v9. It is strange that it is called and accessor in the docs, but is in fact a roundabout way of setting GPU parameters.

Is there any reason to keep the function? I think it would be clearer to pass depthBias(SlopeScale) in props.parameters. In addition if depthBias is passed in props.parameters it will be overwritten even if getPolygonOffset isn't specified.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly agree that it should not be called an "accessor" if that is really the case, as accessors operate on data rows and this function operates on a layer.

We can still deprecate a function at any time. But I believe the functionality of being able to adjust depth bias based on layer index is needed to address Z fighting so we can't just drop it, we need to have a replacement for this function.

const offsets = (getPolygonOffset && getPolygonOffset({layerIndex})) || [0, 0];

return {depthBias: offsets[0], depthBiasSlopeScale: offsets[1]};
}

/* Private */
Expand Down
8 changes: 1 addition & 7 deletions modules/core/src/passes/pick-layers-pass.ts
Expand Up @@ -133,17 +133,11 @@
layerIndex: number,
viewport: Viewport
): LayerParameters {
const pickParameters: LayerParameters = {
// TODO - When used as a custom layer in older Mapbox versions, context
// state was dirty. Mapbox fixed that; we should test and remove the workaround.
// https://github.com/mapbox/mapbox-gl-js/issues/7801
depthCompare: 'less-equal',
...layer.props.parameters
};
const pickParameters: LayerParameters = super.getLayerParameters(layer, layerIndex, viewport);
const {pickable, operation} = layer.props;

if (!this._colorEncoderState || operation.includes('terrain')) {
pickParameters.blendColorOperation = 'none';

Check failure on line 140 in modules/core/src/passes/pick-layers-pass.ts

View workflow job for this annotation

GitHub Actions / test-node

Type '"none"' is not assignable to type 'BlendOperation | undefined'.

Check failure on line 140 in modules/core/src/passes/pick-layers-pass.ts

View workflow job for this annotation

GitHub Actions / test-python (3.8)

Type '"none"' is not assignable to type 'BlendOperation | undefined'.
} else if (pickable && operation.includes('draw')) {
Object.assign(pickParameters, PICKING_BLENDING);
pickParameters.blendConstant = encodeColor(this._colorEncoderState, layer, viewport);
Expand Down
6 changes: 5 additions & 1 deletion modules/core/src/passes/shadow-pass.ts
Expand Up @@ -72,7 +72,11 @@
layerIndex: number,
viewport: Viewport
): LayerParameters {
return {...layer.props.parameters, blendColorOperation: 'none', depthCompare: 'less-equal'};
return {
...super.getLayerParameters(layer, layerIndex, viewport),
blendColorOperation: 'none',

Check failure on line 77 in modules/core/src/passes/shadow-pass.ts

View workflow job for this annotation

GitHub Actions / test-node

Type '"none"' is not assignable to type 'BlendOperation | undefined'.

Check failure on line 77 in modules/core/src/passes/shadow-pass.ts

View workflow job for this annotation

GitHub Actions / test-python (3.8)

Type '"none"' is not assignable to type 'BlendOperation | undefined'.
depthCompare: 'less-equal'
};
}

shouldDrawLayer(layer) {
Expand Down
Expand Up @@ -23,7 +23,7 @@ export default class CollisionFilterPass extends LayersPass {
layerIndex: number,
viewport: Viewport
): LayerParameters {
return {...layer.props.parameters, blendColorOperation: 'none', depthCompare: 'less-equal'};
return {blendColorOperation: 'none', depthCompare: 'less-equal'};
}

getModuleParameters() {
Expand Down
6 changes: 1 addition & 5 deletions modules/extensions/src/mask/mask-pass.ts
Expand Up @@ -61,11 +61,7 @@ export default class MaskPass extends LayersPass {
layerIndex: number,
viewport: Viewport
): LayerParameters {
return {
...layer.props.parameters,
depthCompare: 'less-equal',
...MASK_BLENDING
};
return {depthCompare: 'less-equal', ...MASK_BLENDING};
}

shouldDrawLayer(layer) {
Expand Down
1 change: 0 additions & 1 deletion modules/extensions/src/terrain/terrain-pass.ts
Expand Up @@ -87,7 +87,6 @@ export class TerrainPass extends LayersPass {
viewport: Viewport
): LayerParameters {
return {
...layer.props.parameters,
depthCompare: 'always',
...(layer.props.operation.includes('terrain') && TERRAIN_BLENDING)
};
Expand Down