-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRenderer.js
50 lines (42 loc) · 1.12 KB
/
Renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Renderer {
constructor(target = window, options = {}) {
this.target = target
this.fbo = target.createFramebuffer(options)
this.shader = target.createShader(this.vert(), this.frag())
}
vert() {
throw new Error('Unimplemented')
}
frag() {
throw new Error('Unimplemented')
}
getUniforms() {
return {}
}
draw(cb) {
this.fbo.draw(() => {
this.target.push()
cb()
this.target.pop()
})
const uniforms = this.getUniforms()
this.target.push()
this.target.noStroke()
this.target.rectMode(CENTER)
this.target.shader(this.shader)
for (const key in uniforms) {
this.shader.setUniform(key, uniforms[key])
}
this.target.rect(0, 0, this.target.width, -this.target.height)
this.target.pop()
}
remove() {
this.fbo.remove()
}
}
const superPerspective = p5.Camera.prototype.perspective
p5.Camera.prototype.perspective = function(fovy, aspect, near, far) {
this._near = near === undefined ? this.defaultCameraNear : near
this._far = far === undefined ? this.defaultCameraFar : far
superPerspective.call(this, fovy, aspect, near, far)
}