Copies the shader from one drawing context to another.
Each p5.Shader
object must be compiled by calling shader() before it can run. Compilation happens in a drawing context which is usually the main canvas or an instance of p5.Graphics. A shader can only be used in the context where it was compiled. The copyToContext()
method compiles the shader again and copies it to another drawing context where it can be reused.
The parameter, context
, is the drawing context where the shader will be used. The shader can be copied to an instance of p5.Graphics, as in myShader.copyToContext(pg)
. The shader can also be copied from a p5.Graphics object to the main canvas using the window
variable, as in myShader.copyToContext(window)
.
Note: A p5.Shader object created with createShader(), createFilterShader(), or loadShader() can be used directly with a p5.Framebuffer object created with createFramebuffer(). Both objects have the same context as the main canvas.
Examples
Syntax
copyToContext(context)
Parameters
WebGL context for the copied shader.
Returns
Related References
copyToContext
Copies the shader from one drawing context to another.
inspectHooks
Logs the hooks available in this shader, and their current implementation.
modify
Returns a new shader, based on the original, but with custom snippets of shader code replacing default behaviour.
setUniform
Sets the shader’s uniform (global) variables.