-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Stencil tests are automatically disabled every frame inside draw loops #7554
Comments
DEMO page (p5.Editor): DEMO Execution point of disable: https://github.com/processing/p5.js/blob/main/src/webgl/p5.RendererGL.js#L930 The commit in which this specification was introduced: Implement clip() to shapes #6306 |
I’ve been looking into this issue and traced it back to PR #6306, which introduced Root Cause
Proposed Fix To fix this, I propose modifying p5.RendererGL.js to preserve the stencil test state across frames. Instead of forcefully disabling it, we will check whether it was enabled before and restore its state accordingly. This will ensure that users who enable Let me know your thoughts! |
I think that's generally the approach we want. The nuance will be in how exactly we record the previous value, because ideally we don't want to be calling this.isStencilTestOn = false;
// Record state when enabling/disabling
const prevEnable = this.drawingContext.enable;
this.drawingContext.enable = (key) => {
if (key === this.drawingContext.STENCIL_TEST) {
this.isStencilTestOn = true;
}
return prevEnable.call(this, key);
};
const prevDisable = this.drawingContext.disable;
this.drawingContext.disable = (key) => {
if (key === this.drawingContext.STENCIL_TEST) {
this.isStencilTestOn = false;
}
return prevEnable.call(this, key);
};
// Return the cached value if we try to access it via getEnabled
const prevGetEnabled = this.drawingContext.getEnabled;
this.drawingContext.getEnabled = (key) => {
if (key === this.drawingContext.STENCIL_TEST) {
return this.isStencilTestOn;
}
return prevGetEnabled.call(this, key);
}; ...so that we can call |
Most appropriate sub-area of p5.js?
p5.js version
1.8.0
Web browser and version
Chrome
Operating system
Windows
Steps to reproduce this
Steps:
Snippet:
version 1.7.0
version 1.8.0
Of course, if you enable the stencil test inside the draw loop, you will get the desired drawing result.
However, some users may not like it when the stencil test is disabled regardless of their intentions.
The text was updated successfully, but these errors were encountered: