-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.js
65 lines (51 loc) · 1.37 KB
/
common.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module.exports.runAnimation = function (regl, cb) {
/*
var createReglRecorder = require('regl-recorder')
var recorder = createReglRecorder(regl, 500)
*/
var globalScope = regl({
attributes: {
position: [-2, 0, 0, -2, 2, 2]
},
uniforms: {
tick: ({tick}) => tick
},
count: 3,
vert: `
precision mediump float;
attribute vec2 position;
varying vec2 vUv;
void main () {
vUv = position;
gl_Position = vec4(1.0 - 2.0 * position, 0.0, 1);
}`,
depth: { enable: false }
})
regl.frame(({viewportWidth, viewportHeight}) => {
regl.clear({ color: [0, 0, 0, 1] })
globalScope(() => {
cb()
})
// recorder.frame(viewportWidth, viewportHeight)
})
return regl
}
module.exports.createRegl = function (reglLib, canvasId) {
var canvas = document.getElementById(canvasId)
if (canvas === null) {
canvas = document.body.appendChild(document.createElement('canvas'))
canvas.style.width = '480px'
canvas.style.height = '270px'
}
var context = canvas.getContext('webgl', {
antialias: false
})
return reglLib(context)
/*
// If we want to record with regl-recorder, we do this instead.
const VIDEO_WIDTH = 480
const VIDEO_HEIGHT = 270
regl = require('regl')(require('gl')(VIDEO_WIDTH, VIDEO_HEIGHT, {preserveDrawingBuffer: true, antialias: true}))
return regl
*/
}