Skip to content

Set interapolation to nearest when used in WebGL mode for noSmooth() #6578

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Jaivignesh-afk
Copy link
Contributor

Addresses #6554

Changes:

I have set interapolation to nearest for noSmooth() when used in WebGL Mode

Screenshots of the change:

PR Checklist

var gl = this._renderer.GL;

// Set texture interpolation to NEAREST
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These change the interpolation for the active texture I believe. There may not be an active texture at this time. I think for this to work, we have to store the texture smoothing value in RendererGL somewhere, and then right before we draw something using a texture, then we activate the texture and update its interpolation. Once we have a reference to the active texture as a p5.Texture, we can call its setInterpolation method rather htan using a raw WebGL call:

setInterpolation (downScale, upScale) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I'm new to this, and I wanted to share my understanding. Please correct me if I'm wrong:

  • It seems like I need to store the texture smoothing value in p5.RendererGL's constructor. I grasp that, but I'm curious – since there must be an active texture, should the user/artist manage that manually, or can we automate it here?
  • I have a similar question about setInterpolation as well.

I apologize if these questions seem basic. Even if you can't explain them, pointing me to some helpful resources would be greatly appreciated. Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, although it's not documented, you can set the interpolation of a specific texture by doing something like this in a sketch:

_renderer.getTexture(yourImage).setInterpolation(NEAREST, NEAREST); // or LINEAR, LINEAR

If we want it to only set the current texture, we don't need to store anything in RendererGL, and instead just have to do something like:

noSmooth() {
  if (this._tex) {
    this._tex.setInterpolation(NEAREST, NEAREST);
  }  // else maybe log a warning?
}

The reason to maybe to store something in RendererGL is if think the resulting behaviour is confusing:

texture(yourImage)
noSmooth()

texture(someOtherImage)
// this texture is not smoothed

...but that's an API decision we have to make. Do you have any preference as a user for how it should work?

@Qianqianye
Copy link
Contributor

Thanks @Jaivignesh-afk and @davepagurek. @Jaivignesh-afk, could you follow up with Dave's latest question? We'd like to move forward with this PR by either merging or closing it since it has been a while. Please let us know if you have any questions. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants