Add a read-only flag to indicate if the current canvas is Web GL#5844
Conversation
|
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page! |
davepagurek
left a comment
There was a problem hiding this comment.
Thanks for taking this issue on! I think before we merge this in, it would be great if:
- we can add this property to
p5.Graphicsas well as to the main p5 instance (I also left a comment about maybe defining it a slightly different way to make it easier to set up, let me know what you think!) - we could add a small unit test that check that it works for p5 and for graphics so that we don't accidentally break it in the future
I'm happy to explain more about my suggestions or how to set up and run unit tests for this sort of thing if it would help 🙂
| //isWebGL flag is set and made read-only | ||
| if (this.isWebGL == false) { | ||
| Object.defineProperty(this,"isWebGL" , { | ||
| value: this._renderer.drawingContext instanceof WebGLRenderingContext, |
There was a problem hiding this comment.
If we use a get accessor here instead of value directly, then we can put this in the constructor for p5 and not have to worry about handling createCanvas not being called or being called more than once, since the value will be determined at runtime. i.e., Object.defineProperty(this, 'webgl', { get: () => this._renderer.drawingContext instanceof WebGLRenderingContext, writable: false }).
There was a problem hiding this comment.
Can we also add the same accessor to the p5.Graphics constructor?
| value: this._renderer.drawingContext instanceof WebGLRenderingContext, | ||
| writable: false | ||
| }); | ||
| } |
There was a problem hiding this comment.
Also, it looks like the spacing and equal signs aren't quite lined up here. Can you double check that npm run lint passes after making changes?
|
Thanks @spikyMalkallam for working on it. Will you be able to make the changes based on @davepagurek's suggestion? Please let us know if you need any help. |
Resolves #5750
Changes:
Added a read-only
.isWebGLflag to p5 instances. This flag is set in createCavnas. Included comments, no inline docs.Usage screenshot:

PR Checklist
npm run lintpasses