Skip to content

Commit

Permalink
refactor(mask): opt code
Browse files Browse the repository at this point in the history
  • Loading branch information
singlecoder committed Oct 18, 2024
1 parent bc21358 commit e2efa9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/BasicResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export class BasicResources {
renderStates[RenderStateElementKey.StencilStateEnabled] = true;
renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
const failStencilOperation = StencilOperation.Keep;
renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
Expand All @@ -94,8 +96,6 @@ export class BasicResources {
renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
renderStates[RenderStateElementKey.DepthStateEnabled] = false;
renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;

Check warning on line 98 in packages/core/src/BasicResources.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/BasicResources.ts#L86-L98

Added lines #L86 - L98 were not covered by tests
renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;

return renderStates;

Check warning on line 100 in packages/core/src/BasicResources.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/BasicResources.ts#L100

Added line #L100 was not covered by tests
}
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/RenderPipeline/RenderQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ export class RenderQueue {
const maskInteraction = renderer._maskInteraction;
const needMaskInteraction = maskInteraction !== SpriteMaskInteraction.None;
const needMaskType = maskType !== RenderQueueMaskType.No;
if (needMaskInteraction) {
maskManager.drawMask(context, pipelineStageTagValue, subElement.component._maskLayer);
} else {
maskManager.isReadStencil(material) && maskManager.clearMask(context, pipelineStageTagValue);
}
needMaskType || (maskManager.isStencilWritten(material) && (maskManager.hasStencilWritten = true));

let customStates: RenderStateElementMap = null;
if (needMaskInteraction) {
customStates = BasicResources.getMaskInteractionRenderStates(maskInteraction);
} else if (needMaskType) {

if (needMaskType) {
customStates = BasicResources.getMaskTypeRenderStates(maskType);

Check warning on line 83 in packages/core/src/RenderPipeline/RenderQueue.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/RenderPipeline/RenderQueue.ts#L83

Added line #L83 was not covered by tests
} else {
if (needMaskInteraction) {
maskManager.drawMask(context, pipelineStageTagValue, subElement.component._maskLayer);
customStates = BasicResources.getMaskInteractionRenderStates(maskInteraction);

Check warning on line 87 in packages/core/src/RenderPipeline/RenderQueue.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/RenderPipeline/RenderQueue.ts#L86-L87

Added lines #L86 - L87 were not covered by tests
} else {
maskManager.isReadStencil(material) && maskManager.clearMask(context, pipelineStageTagValue);
}
maskManager.isStencilWritten(material) && (maskManager.hasStencilWritten = true);
}

const compileMacros = Shader._compileMacros;
Expand Down

0 comments on commit e2efa9d

Please sign in to comment.