-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type {Device, RenderPassParameters} from '@luma.gl/core'; | ||
import type {Device, RenderPassParameters, Parameters} from '@luma.gl/core'; | ||
import type {Framebuffer, RenderPass} from '@luma.gl/core'; | ||
|
||
import Pass from './pass'; | ||
|
@@ -9,6 +9,8 @@ import type {Effect} from '../lib/effect'; | |
|
||
export type Rect = {x: number; y: number; width: number; height: number}; | ||
|
||
export type LayerParameters = Parameters & RenderPassParameters; | ||
|
||
export type LayersPassRenderOptions = { | ||
/** @deprecated TODO v9 recommend we rename this to framebuffer to minimize confusion */ | ||
target?: Framebuffer | null; | ||
|
@@ -36,7 +38,7 @@ type DrawLayerParameters = { | |
shouldDrawLayer: boolean; | ||
layerRenderIndex?: number; | ||
moduleParameters?: any; | ||
layerParameters?: any; | ||
layerParameters?: LayerParameters; | ||
}; | ||
|
||
export type FilterContext = { | ||
|
@@ -54,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; | ||
|
@@ -72,9 +82,6 @@ export default class LayersPass extends Pass { | |
if (options.colorMask) { | ||
parameters.colorMask = colorMask; | ||
} | ||
if (options.scissorRect) { | ||
parameters.scissorRect = options.scissorRect; | ||
} | ||
|
||
const renderPass = this.device.beginRenderPass({ | ||
framebuffer: options.target, | ||
|
@@ -125,6 +132,7 @@ export default class LayersPass extends Pass { | |
target, | ||
moduleParameters, | ||
viewport: subViewport, | ||
scissorRect: options.scissorRect, | ||
view, | ||
pass: options.pass, | ||
layers: options.layers | ||
|
@@ -191,7 +199,9 @@ export default class LayersPass extends Pass { | |
moduleParameters | ||
); | ||
layerParam.layerParameters = { | ||
...DEFAULT_PARAMETERS, | ||
...layer.context.deck?.props.parameters, | ||
...layer.props.parameters, | ||
...this.getLayerParameters(layer, layerIndex, viewport) | ||
}; | ||
} | ||
|
@@ -206,27 +216,15 @@ export default class LayersPass extends Pass { | |
/* eslint-disable max-depth, max-statements */ | ||
private _drawLayersInViewport( | ||
renderPass: RenderPass, | ||
{layers, moduleParameters: globalModuleParameters, pass, target, viewport, view}, | ||
drawLayerParams | ||
{layers, moduleParameters: globalModuleParameters, pass, target, viewport, view, scissorRect}, | ||
drawLayerParams: DrawLayerParameters[] | ||
): RenderStats { | ||
const glViewport = getGLViewport(this.device, { | ||
moduleParameters: globalModuleParameters, | ||
target, | ||
viewport | ||
}); | ||
|
||
// TODO v9 - remove WebGL specific logic | ||
if (view && view.props.clear) { | ||
const clearOpts = view.props.clear === true ? {color: true, depth: true} : view.props.clear; | ||
this.device.withParametersWebGL( | ||
{ | ||
scissorTest: true, | ||
scissor: glViewport | ||
}, | ||
() => this.device.clearWebGL(clearOpts) | ||
); | ||
} | ||
|
||
// render layers in normal colors | ||
const renderStatus = { | ||
totalCount: layers.length, | ||
|
@@ -235,7 +233,11 @@ export default class LayersPass extends Pass { | |
pickableCount: 0 | ||
}; | ||
|
||
renderPass.setParameters({viewport: glViewport}); | ||
renderPass.setParameters({viewport: glViewport, scissorRect: scissorRect || glViewport}); | ||
if (view?.props.clear) { | ||
// @ts-expect-error WEBGLRenderPass protected method | ||
renderPass.clear?.(); | ||
} | ||
|
||
// render layers in normal colors | ||
for (let layerIndex = 0; layerIndex < layers.length; layerIndex++) { | ||
|
@@ -252,8 +254,10 @@ export default class LayersPass extends Pass { | |
} else if (shouldDrawLayer) { | ||
// Draw the layer | ||
renderStatus.visibleCount++; | ||
// layerParameters and layerRenderIndex are always present in this context | ||
renderPass.setParameters(layerParameters!); | ||
|
||
this._lastRenderIndex = Math.max(this._lastRenderIndex, layerRenderIndex); | ||
this._lastRenderIndex = Math.max(this._lastRenderIndex, layerRenderIndex!); | ||
|
||
// overwrite layer.context.viewport with the sub viewport | ||
moduleParameters.viewport = viewport; | ||
|
@@ -268,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}`); | ||
|
@@ -289,8 +293,15 @@ export default class LayersPass extends Pass { | |
return null; | ||
} | ||
|
||
protected getLayerParameters(layer: Layer, layerIndex: number, viewport: Viewport): any { | ||
return layer.props.parameters; | ||
protected getLayerParameters( | ||
layer: Layer, | ||
layerIndex: number, | ||
viewport: Viewport | ||
): LayerParameters { | ||
const {getPolygonOffset} = layer.props; | ||
const offsets = (getPolygonOffset && getPolygonOffset({layerIndex})) || [0, 0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should have deprecated Is there any reason to keep the function? I think it would be clearer to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
return {depthBias: offsets[0], depthBiasSlopeScale: offsets[1]}; | ||
} | ||
|
||
/* Private */ | ||
|
There was a problem hiding this comment.
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 thePass
theLayer
could have more control: