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

fix: use stencil.func.ref for each pipeline #2471

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions __tests__/integration/mask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const TEST_CASES = [
{
name: 'single',
},
{
name: 'multi',
sleepTime: 2500,
},
];

describe('Mask Snapshot', () => {
Expand Down
Binary file added __tests__/integration/snapshots/Mask_multi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/Point_billboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/Point_fill_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/Point_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions examples/demos/mask/multi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
});

scene.on('loaded', async () => {
const colors = [

Check warning on line 55 in examples/demos/mask/multi.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'colors' is assigned a value but never used
'#d73027',
'#f46d43',
'#fdae61',
Expand All @@ -72,18 +72,6 @@
)
).json();

// 影像地图图层
const baseLayer = new RasterLayer({ zIndex: -1 }).source(
'https://www.google.com/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}',
{
parser: {
type: 'rasterTile',
tileSize: 256,
zoomOffset: 0,
},
},
);

const polygonLayer = new PolygonLayer({
visible: true,
name: 'china',
Expand Down Expand Up @@ -131,8 +119,6 @@

leftLayer.addMask(maskLayer);

scene.addLayer(baseLayer);

scene.addLayer(leftLayer);
scene.addLayer(polygonLayer);
scene.addLayer(maskLayer);
Expand Down
18 changes: 15 additions & 3 deletions packages/renderer/src/device/DeviceModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
stencilFuncMap,
stencilOpMap,
} from './constants';
const { isPlainObject, isTypedArray } = lodashUtil;
const { isPlainObject, isTypedArray, isNil } = lodashUtil;

export default class DeviceModel implements IModel {
private destroyed: boolean = false;
Expand Down Expand Up @@ -156,7 +156,7 @@ export default class DeviceModel implements IModel {
const stencilParams = this.getStencilDrawParams({ stencil });
const stencilEnabled = !!(stencilParams && stencilParams.enable);

return this.device.createRenderPipeline({
const pipeline = this.device.createRenderPipeline({
// return this.service.renderCache.createRenderPipeline({
inputLayout: this.inputLayout,
program: this.program,
Expand Down Expand Up @@ -219,6 +219,14 @@ export default class DeviceModel implements IModel {
},
},
});

// Save stencil reference on pipeline for later use.
if (stencilEnabled && !isNil(stencil?.func?.ref)) {
// @ts-ignore
pipeline.stencilFuncReference = stencil.func.ref;
}

return pipeline;
}

updateAttributesAndElements() {}
Expand Down Expand Up @@ -285,7 +293,11 @@ export default class DeviceModel implements IModel {
device['swapChainHeight'] = tmpHeight;

renderPass.setPipeline(this.pipeline);
renderPass.setStencilReference(1);
// @ts-ignore
if (!isNil(this.pipeline.stencilFuncReference)) {
// @ts-ignore
renderPass.setStencilReference(this.pipeline.stencilFuncReference);
}
renderPass.setVertexInput(
this.inputLayout,
this.vertexBuffers.map((buffer) => ({
Expand Down
Loading