Skip to content
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

Adding a settings argument to p5.Texture #5556

Closed
1 of 17 tasks
aferriss opened this issue Jan 15, 2022 · 2 comments
Closed
1 of 17 tasks

Adding a settings argument to p5.Texture #5556

aferriss opened this issue Jan 15, 2022 · 2 comments

Comments

@aferriss
Copy link
Contributor

aferriss commented Jan 15, 2022

Feature enhancement details:

I'd like to add an additional argument to the p5.Texture constructor that would allow more of the internal settings to be changed. I'm working on p5Fbo, and one thing I'd like to enable is floating point textures. Float textures would allow more complex general purpose GPU programming, by allowing the texture to store values outside of a normalized [0,1] range. Currently, p5.Texture has UNSIGNED_BYTE as it's data type hard coded in.

I'm proposing that we add an optional settings argument to the p5.Texture constructor that would allow the user some additional control over the texture settings. The settings that I'm currently including in that object are:

  • format: defaults to gl.RGBA, but could also be gl.RGB, or gl.ALPHA, or gl.LUMINANCE
  • minFilter: either gl.LINEAR or gl.NEAREST
  • magFilter: either gl.LINEAR or gl.NEAREST
  • wrapS: one of gl.CLAMP_TO_EDGE, gl.MIRROR, or gl.MIRROR_REPEAT
  • wrapR: one of gl.CLAMP_TO_EDGE, gl.MIRROR, or gl.MIRROR_REPEAT
  • dataType: gl.UNSIGNED_BYTE or gl.FLOAT (there are more types but they are not very common)

So if someone wanted to use p5.Texture with this new argument they could write something like:

const renderer = createCanvas(100, 100, WEBGL);
const tex = new p5.Texture(renderer, new p5.Image(100, 100), {dataType: renderer.GL.FLOAT });

I'm open to suggestions about other ways to accomplish this, or if there's a way anyone can think of that doesn't require altering p5.Texture, I'm open to that as well. I'd also be fine with simplifying this change to just include the dataType as an optional argument, since that's really the thing I care about here.

One thing I'm not sure about is how this would fit into p5.Graphics. I believe currently p5.Graphics just makes a regular texture as it's backing canvas, but it might be possible to allow that canvas to be backed by a float texture as well.

I've opened a draft PR, if anyone has some time to take a quick look :)

How would this new feature help [increase access]

(https://github.com/processing/p5.js/blob/main/contributor_docs/access.md) to p5.js?

This is mainly a change geared towards making the webGL functions slightly more extensible, especially for people looking to extend p5 with their own add-ons and libraries. Since p5.Texture is mainly used under the hood by the renderer, it's unlikely that most folks would ever end up touching this. However for those that wish to extend the library, this makes it possible to access and alter some of the settings that were previously hard coded in.

In general it seems like the recommendation for adding more niche features to p5 is to make your own add on. But in this case, the add on is blocked by hard coded values in p5.

Most appropriate sub-area of p5.js?

  • Accessibility (Web Accessibility)
  • Build tools and processes
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Friendly error system
  • Image
  • IO (Input/Output)
  • Localization
  • Math
  • Unit Testing
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)
@Qianqianye
Copy link
Contributor

Thanks @aferriss. Adding an optional settings argument to the p5.Texture constructor sounds interesting.
@stalgiag and @kjhollen, can you share some thoughts on this issue? Thanks!

@stalgiag
Copy link
Contributor

closed by #5557

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

No branches or pull requests

3 participants