Open RandomGamingDev opened 1 year ago
Some added context: It looks blurry for me in Chrome, but crisp in Firefox:
Same for me after checking.
Oh I think I know what's going on here. noSmooth()
for WebGL calls setAttributes('antialias', false)
(which may or may not be the right thing to do, but that's an aside.) Setting attributes recreates the canvas and invalidates previous references to it. The recreation is hard to avoid, as far as I'm aware there isn't an API to change those other than in getContext
on a new canvas. We can maybe still make the return value of createCanvas
be aware of this and update itself internally though (see https://github.com/processing/p5.js/issues/5902).
For now, calling _renderer.getTexture(img).setInterpolation(NEAREST, NEAREST);
works in Chrome, since _renderer
is always a reference to the current canvas.
Ah, alr
Hi! I went through the existing discussions on this issue and similar ones. I was thinking if making these changes would solve the issue?
p5.prototype.noSmooth = function() {
if (!this._renderer.isP3D) {
if ('imageSmoothingEnabled' in this.drawingContext) {
this.drawingContext.imageSmoothingEnabled = false;
}
} else {
const currentRenderer = this._renderer;
if (this._renderer !== currentRenderer) {
this._renderer.parent = this;
this._renderer.drawingContext = this.drawingContext;
}
}
return this;
};
This would avoid canvas recreation, reassigning current renderer's parent and drawing context.
I think unfortunately if we need to change the attributes of the canvas, we need to recreate the canvas, since MDN says:
[
getContext
] returns a drawing context on the canvas, or null if [...] the canvas has already been set to a different context mode. [...] It is not possible to get a different drawing context object on a given canvas element.
...but that said, your idea of updating the properties of old renderer objects could be a good approach to fixing https://github.com/processing/p5.js/issues/5902! I would probably do it in setAttributes
rather than noSmooth
, since that method is called by noSmooth
, and both have the same problem of invalidating references to renderers. What I'd maybe do is:
p5
or p5.Graphics
), keep an array of past rendererssetAttributes
or even the initial createCanvas
maybe):
elt
property of all the old renderers to the new canvas elementdrawingContext
propertyGL
property too (same as drawingContext
)That said, although this is necessary for setAttributes
regardless (https://github.com/processing/p5.js/issues/5902), there's also the separate issue of whether or not noSmooth
should turn off antialiasing or just change the texture filtering of whichever texture you use next. Anyone have any opinions on that?
Most appropriate sub-area of p5.js?
p5.js version
1.7.0
Web browser and version
115.0.5790.111
Operating System
Windows 10
Steps to reproduce this
Steps:
noSmooth()
Snippet:
In case you don't want to copy and paste it here's the sketch: https://editor.p5js.org/PotatoBoy/sketches/vgaD3vTok