forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattributes-nested.js
96 lines (82 loc) · 1.86 KB
/
attributes-nested.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
var tape = require('tape')
var createContext = require('./util/create-context')
var createREGL = require('../regl')
tape('attributes nested', function (t) {
var gl = createContext(5, 5)
var regl = createREGL(gl)
var FRAG = [
'precision mediump float;',
'void main() {',
'gl_FragColor = vec4(1, 1, 1, 1);',
'}'
].join('\n')
var VERT = [
'precision mediump float;',
'attribute vec2 position;',
'varying vec4 fragColor;',
'void main() {',
'gl_Position=vec4(2.0 * (position + 0.5) / 5.0 - 1.0, 0, 1);',
'gl_PointSize=1.;',
'}'
].join('\n')
var expected = [
0, 1, 0, 1, 0,
0, 0, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0
]
var input = {
buffer: regl.buffer(new Uint8Array([
0, 0,
1, 0,
2, 0,
3, 0,
4, 0,
2, 2
])),
offset: 2,
stride: 4
}
function checkPixels (expected) {
var actual = regl.read()
// console.log('actual: ', actual)
// console.log('expected: ', expected)
for (var i = 0; i < 5 * 5; ++i) {
if (!!actual[4 * i] !== !!expected[i]) {
console.log('fail at: ', i)
return false
}
}
return true
}
var nestedDynamicDraw = regl({
frag: FRAG,
vert: VERT,
primitive: 'points',
count: 3,
depth: {enable: false},
attributes: {
position: {
buffer: regl.prop('position.buffer'),
offset: regl.prop('position.offset'),
stride: regl.prop('position.stride')
}
}
})
var cmd = nestedDynamicDraw
regl.clear({
color: [0, 0, 0, 0]
})
cmd({position: input})
t.ok(checkPixels(expected), 'dynamic 1-shot draw')
regl.clear({
color: [0, 0, 0, 0]
})
cmd([{ position: input }])
t.ok(checkPixels(expected), 'batch')
regl.destroy()
t.equals(gl.getError(), 0, 'error ok')
createContext.destroy(gl)
t.end()
})