Skip to content

Commit

Permalink
fix: use stencil.func.ref for each pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed May 16, 2024
1 parent d403440 commit c3b32a8
Showing 1 changed file with 15 additions and 3 deletions.
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 c3b32a8

Please sign in to comment.