Skip to content

Commit

Permalink
fix: use stencil.func.ref for each pipeline (#2471)
Browse files Browse the repository at this point in the history
* fix: use stencil.func.ref for each pipeline

* chore: add multi stencil mask example

* chore(CI): update snapshots (#2472)

Co-authored-by: lvisei <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: lvisei <[email protected]>
  • Loading branch information
3 people authored May 16, 2024
1 parent d403440 commit b9f4d02
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
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 @@ -72,18 +72,6 @@ export function MapRender(options: RenderDemoOptions) {
)
).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 @@ export function MapRender(options: RenderDemoOptions) {

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

0 comments on commit b9f4d02

Please sign in to comment.