processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.72k stars 3.34k forks source link

WebGL `setAttributes` causes image interpolation to default to LINEAR #7304

Open RandomGamingDev opened 1 month ago

RandomGamingDev commented 1 month ago

Most appropriate sub-area of p5.js?

p5.js version

1.11

Web browser and version

129.0.6668.58 & 115.15.0esr

Operating system

Debian 12

Steps to reproduce this

Steps:

  1. Call setAttributes
  2. setInterpolation on a texture to NEAREST
  3. Render the texture and watch it not work

Example (working sketch located at https://editor.p5js.org/PotatoBoy/sketches/tFXOSAnZV):

let img;
let canvas;

function preload() {
  img = loadImage('test.png');
}

function setup() {
  canvas = createCanvas(400, 400, WEBGL);
  setAttributes({ alpha: true });

  canvas.getTexture(img).setInterpolation(NEAREST, NEAREST);
}

function draw() {
  background(0);
  image(img, -width / 2, -height / 2, width, height);
}

Result: image Expected Result: image

Note: Related to https://github.com/processing/p5.js/issues/6325 which is encompassed by this issue

RandomGamingDev commented 1 month ago

Calling _renderer.getTexture(img).setInterpolation(NEAREST, NEAREST); fixes it for both Chrome and Firefox unlike #6325 where it only fixes it for Chrome and Firefox works by default.

samarsrivastav commented 1 month ago

hey @RandomGamingDev !! I was trying to reproduce the issue, and found out that adding the setAttribite like this setAttributes('alpha' ,true); instead of a key value pair generates the desired output

demo

davepagurek commented 1 month ago

The core issue here is that setAttributes invalidates previous returned values from createCanvas. We're refactoring the rendering system in p5 2.0 to not do this any more, so we can check back in on this issue when that's further along 🙂

samarsrivastav commented 1 month ago

Thanks for the clarification! Looking forward to the p5 2.0 update — I’ll keep an eye on the progress. Appreciate the heads-up!