forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic-scissor.js
77 lines (71 loc) · 1.54 KB
/
dynamic-scissor.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
var tape = require('tape')
var createREGL = require('../regl')
var createContext = require('./util/create-context')
tape('dynamic scissor bug', function (t) {
var gl = createContext(8, 8)
var regl = createREGL(gl)
var command = regl({
context: {
height: 4
},
frag: [
'void main () {',
' gl_FragColor = vec4(1, 1, 1, 1);',
'}'
].join('\n'),
vert: [
'precision highp float;',
'attribute vec2 position;',
'void main () {',
' gl_Position = vec4(position, 0, 1);',
'}'
].join('\n'),
attributes: {
position: [
-4, 0,
4, -4,
4, 4
]
},
count: 3,
primitive: 'triangles',
scissor: {
enable: true,
box: {
x: function () {
return 1
},
y: regl.this('y'),
width: regl.prop('width'),
height: regl.context('height')
}
}
})
regl.clear({
color: [0, 0, 0, 0],
depth: 1
})
command.call({
y: 2
}, { width: 3 })
var pixels = regl.read()
var expected = []
var actual = []
for (var j = 0; j < 8; ++j) {
for (var i = 0; i < 8; ++i) {
if (i > 0 && i < 4 && j > 1 && j < 6) {
expected.push('*')
} else {
expected.push('_')
}
actual.push(pixels[4 * (8 * j + i)] ? '*' : '_')
}
actual.push('\n')
expected.push('\n')
}
t.equals(actual.join(''), expected.join(''), 'scissor set correctly')
regl.destroy()
t.equals(gl.getError(), 0, 'no error code set')
createContext.destroy(gl)
t.end()
})