forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle.js
61 lines (51 loc) · 1.25 KB
/
triangle.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
var createContext = require('./util/create-context')
var createREGL = require('../regl')
var tape = require('tape')
tape('triangle', function (t) {
setTimeout(function () {
var gl = createContext(16, 16)
var regl = createREGL(gl)
regl.clear({
color: [1, 0, 0, 1],
depth: 1
})
var drawTriangle = regl({
frag: [
'void main() {',
' gl_FragColor = vec4(0, 0, 1, 1);',
'}'
].join('\n'),
vert: [
'attribute vec4 position;',
'void main() {',
' gl_Position = position;',
'}'
].join('\n'),
attributes: {
position: regl.buffer([
[2, 2, 0, 1],
[2, -2, 0, 1],
[-2, -2, 0, 1]
])
},
count: 3
})
drawTriangle()
var pixels = regl.read()
for (var i = 0; i < 16; ++i) {
for (var j = 0; j < 16; ++j) {
var ptr = 4 * (16 * i + j)
if (i !== j) {
t.equals(pixels[ptr], i > j ? 255 : 0)
t.equals(pixels[ptr + 1], 0)
t.equals(pixels[ptr + 2], i > j ? 0 : 255)
t.equals(pixels[ptr + 3], 255)
}
}
}
regl.destroy()
t.equals(gl.getError(), 0, 'error ok')
createContext.destroy(gl)
t.end()
}, 120)
})