-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Adding framebuffer support for filter() + CreateFilterShader for 2D mode #6559
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
Changes from 14 commits
198e456
8b71469
0ec719e
96bc262
72cd97b
6f0b715
2789e2a
2df0b03
f42da57
cefc285
9a86b19
75b0042
ae37304
e807740
1af2155
7fa39f6
683ed18
c250531
e4291cd
b073664
a353711
4a9bef9
2a330bf
6d04ec6
b1ec441
c01235f
8df7437
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,28 @@ class Renderer2D extends p5.Renderer{ | |
this._pInst._setProperty('drawingContext', this.drawingContext); | ||
} | ||
|
||
getFilterGraphicsLayer() { | ||
// create hidden webgl renderer if it doesn't exist | ||
if (!this.filterGraphicsLayer) { | ||
// the real _pInst is buried when this is a secondary p5.Graphics | ||
const pInst = | ||
this._pInst instanceof p5.Graphics ? | ||
this._pInst._pInst : | ||
this._pInst; | ||
|
||
// create secondary layer | ||
this.filterGraphicsLayer = | ||
new p5.Graphics( | ||
this.width, | ||
this.height, | ||
constants.WEBGL, | ||
pInst | ||
); | ||
} | ||
|
||
return this.filterGraphicsLayer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this, we might want to do a similar size matching to what we do in RendererGL with its framebuffer so that we ensure Maybe we can also copy and paste the current unit test that checks that the framebuffer gets resized in WebGL mode, and adapt it to check the size of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, i will do the changes asap. |
||
} | ||
|
||
_applyDefaults() { | ||
this._cachedFillStyle = this._cachedStrokeStyle = undefined; | ||
this._cachedBlendMode = constants.BLEND; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a case where these conditions weren't met?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, during testing, there seems to be an issue where, after a resize operation, logging
console.log(this._pInst)
sometimes results in the valueundefined
. This occurrence leads to errors of the form "cannot read properties of undefined (reading_pixelDensity
)". To address this, a check has been added to verify whetherthis._pInst
is defined before attempting to access its properties. This check helps prevent the errors encountered during the testing process. It was actually failing the test given below. Am I doing the correct way....Or this still have limitations?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for pointing out the test case! I was asking because it seems like it might be indicative of a bigger problem if something is getting resized without having a
_pInst
, and maybe we want to see how it got into that state and maybe fix it at the source instead of here. I'll take a look at that test and get back to you soon!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's coming from these lines:
p5.js/src/webgl/p5.RendererGL.js
Lines 1432 to 1435 in 28740f9
These were added when
filterGraphicsLayer
was a graphic, but now it's a framebuffer. I think we don't need those lines at all any more since we handle the resizing when we callfilter
, so maybe we can take it out, and check instead that the size changes after callingfilter
:test('secondary graphics layer matches main canvas size', function() { let g1 = myp5.createCanvas(5, 5, myp5.WEBGL); let s = myp5.createShader(vert, frag); myp5.filter(s); let g2 = g1.filterGraphicsLayer; assert.deepEqual([g1.width, g1.height], [g2.width, g2.height]); myp5.resizeCanvas(4, 4); + myp5.filter(s); assert.deepEqual([g1.width, g1.height], [g2.width, g2.height]); });
Also as a side note, we should still rename
filterGraphicsLayer
andfilterGraphicsLayerTemp
inRendererGL
to remove the wordgraphic
(justfilterLayer
andfilterLayerTemp
probably)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, i have done a little testing myself, I think it's working now. I have made the required changes.