xxxxxxxxxx
46
// https://github.com/processing/p5.js/blob/846a0825847c23a1022d5ffdbbfc8a4fe63cf30b/src/webgl/p5.RendererGL.js#L257
// getContext('webgl') >> getContext('webgl2')
p5.RendererGL.prototype._initContext = function() {
try {
this.drawingContext =
this.canvas.getContext('webgl2', this._pInst._glAttributes) ||
this.canvas.getContext('experimental-webgl', this._pInst._glAttributes);
if (this.drawingContext === null) {
throw new Error('Error creating webgl context');
} else {
const gl = this.drawingContext;
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
this._viewport = this.drawingContext.getParameter(
this.drawingContext.VIEWPORT
);
}
} catch (er) {
throw er;
}
};
// p5.RendererGL.prototype._initContext = function() {
// this.drawingContext=this.elt.getContext('webgl2');
// }
function preload() {
s = loadShader('a.vert','a.frag');
}
function setup() {
pixelDensity(1);
createCanvas(400,400);
p = createGraphics(400,400,WEBGL).noStroke();
}
function draw() {
background(220)
s.setUniform("r",[p.width,p.height]);
s.setUniform("t",millis()/1000.);
s.setUniform("m",[mouseX/width,mouseY/height]);
p.shader(s);
image(p,0,0)
}