Reference copyToContext()

copyToContext()

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

context
p5|p5.Graphics:

WebGL context for the copied shader.

Returns

p5.Shader: new shader compiled for the target context.
Notice any errors or typos? Please let us know. Please feel free to edit src/webgl/p5.Shader.js and open a pull request!

Related References