forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththis.js
106 lines (93 loc) · 2.36 KB
/
this.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var createContext = require('./util/create-context')
var createREGL = require('../regl')
var tape = require('tape')
tape('this / state variables', function (t) {
var gl = createContext(8, 8)
var regl = createREGL(gl)
function checkPixmap (slots, args, expected, remark) {
var base = {
frag: [
'precision mediump float;',
'void main() {',
'gl_FragColor = vec4(1, 1, 1, 1);',
'}'
].join('\n'),
vert: [
'precision mediump float;',
'attribute vec2 position;',
'varying vec4 fragColor;',
'uniform vec2 offset;',
'void main() {',
'gl_Position=vec4(0.25 * (offset + position - 3.5), 0, 1);',
'gl_PointSize=1.;',
'}'
].join('\n'),
attributes: {
position: regl.buffer([0, 0, 4, 0, 4, 4, 0, 4])
},
depth: {enable: false, mask: false}
}
Object.keys(slots).forEach(function (x) {
base[x] = slots[x]
})
var command = regl(base)
function checkPixels (suffix) {
var pixels = regl.read()
var actual = new Array(64)
for (var i = 0; i < 64; ++i) {
actual[i] = Math.min(1, pixels[4 * i])
}
t.same(actual, expected, remark + ' - ' + suffix)
}
regl.clear({color: [0, 0, 0, 0]})
command.call(args)
checkPixels('draw')
regl.clear({color: [0, 0, 0, 0]})
command.call(args, 1)
checkPixels('batch')
}
checkPixmap({
primitive: regl.this('primitive'),
count: regl.this('count'),
offset: regl.this('_offset'),
uniforms: {
offset: [0, 0]
}
}, {
primitive: 'points',
count: 3,
_offset: 1,
__offset: [0, 0]
}, [
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
], 'draw state')
checkPixmap({
uniforms: {
offset: regl.this('offset')
},
count: 1,
primitive: 'points'
}, {
offset: [2, 2]
}, [
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
], 'uniforms')
regl.destroy()
t.equals(gl.getError(), 0, 'error ok')
createContext.destroy(gl)
t.end()
})