processing4 icon indicating copy to clipboard operation
processing4 copied to clipboard

Request: add a createShader( String [] vertSrc, String [] fragSrc ) function like p5.js has

Open processing-bot opened this issue 3 years ago • 2 comments

Created by: scudly

Now that we have multi-line strings, it is practical to include shader code directly in sketches (or even to construct them programmatically) rather than reading from an external file. The current publicly supported and documented loadShader() API only cleanly supports reading shaders from files. Ideally, we would also have a createShader( String[] fragSrc ) that infers the type and provides a vertex shader as the current loadShader() does.

Passing the source as an array of strings seems more general than taking it as a single, multi-line string and is trivial enough to express in code. It also matches the existing PShader constructors.

processing-bot avatar Feb 08 '22 22:02 processing-bot

Yes, this would be a nice enhancement, thanks for suggesting!

codeanticode avatar Feb 27 '22 16:02 codeanticode

@scudly the PShader class already has a public constructor that takes string arrays as inputs:

https://github.com/processing/processing4/blob/master/core/src/processing/opengl/PShader.java#L285

So you could use that for the time being.

@benfry In order for this functionality to be properly incorporated into the API we could need to add a a a couple of createShader() methods to PApplet, as @scudly suggested. Those should be pretty straightforward to implement, I can create a PR for inclusion in the next beta.

codeanticode avatar Mar 06 '22 18:03 codeanticode