-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (70 loc) · 2.06 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var mouse = require('mouse-position')()
var triangle = require('a-big-triangle')
var throttle = require('frame-debounce')
var fit = require('canvas-fit')
var getContext = require('gl-context')
var compare = require('gl-compare')
var createShader = require('glslify')
var createFBO = require('gl-fbo')
var fs = require('fs')
var container = document.getElementById('container')
var canvas = container.appendChild(document.createElement('canvas'))
var readme = fs.readFileSync(__dirname + '/README.md', 'utf8')
var gl = getContext(canvas, render)
var comparison = compare(gl
, createLoop('actual')
, createLoop('expected')
)
comparison.mode = 'slide'
comparison.amount = 0.5
require('../common')({
description: readme
, compare: comparison
, canvas: canvas
, dirname: process.env.dirname
})
window.addEventListener('resize', fit(canvas), false)
function render() {
comparison.run()
comparison.render()
}
var shaders = {
actual: createShader({
frag: process.env.file_render_frag
, vert: './shaders/triangle.vert'
})(gl),
expected: createShader({
frag: './shaders/expected.frag'
, vert: './shaders/triangle.vert'
})(gl),
display: createShader({
frag: './shaders/display.frag'
, vert: './shaders/triangle.vert'
})(gl)
}
var outputs = {
actual: createFBO(gl, [512, 512])
, expected: createFBO(gl, [512, 512])
}
var inputs = {
actual: createFBO(gl, [512, 512])
, expected: createFBO(gl, [512, 512])
}
function createLoop(key) {
return function render(fbo) {
outputs[key].shape = [canvas.height, canvas.width]
outputs[key].bind()
shaders[key].bind()
shaders[key].uniforms.uTexture = inputs[key].color[0].bind(0)
shaders[key].uniforms.uMouse = [mouse.x, canvas.height - mouse.y]
triangle(gl)
fbo.shape = [canvas.height, canvas.width]
fbo.bind()
shaders.display.bind()
shaders.display.uniforms.uTexture = outputs[key].color[0].bind(0)
triangle(gl)
var tmp = inputs[key]
inputs[key] = outputs[key]
outputs[key] = tmp
}
}