forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscissor.js
118 lines (105 loc) · 2.44 KB
/
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
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
107
108
109
110
111
112
113
114
115
116
117
118
var extend = require('../lib/util/extend')
var createContext = require('./util/create-context')
var createREGL = require('../regl')
var tape = require('tape')
tape('scissor', function (t) {
var gl = createContext(16, 16)
var regl = createREGL(gl)
function testFlags (prefix, flags) {
t.equals(gl.getParameter(gl.SCISSOR_TEST), flags.enable, prefix + ' enable')
var box = gl.getParameter(gl.SCISSOR_BOX)
var fbox = flags.box
if ('x' in fbox) {
t.equals(box[0], fbox.x, prefix + 'box.x')
} else {
t.equals(box[0], 0, prefix + 'box.x')
}
if ('y' in fbox) {
t.equals(box[1], fbox.y, prefix + 'box.y')
} else {
t.equals(box[1], 0, prefix + 'box.y')
}
if ('width' in fbox) {
t.equals(box[2], fbox.width, prefix + 'box.width')
} else {
t.equals(box[2], gl.drawingBufferWidth - box[0], prefix + 'box.width')
}
if ('height' in fbox) {
t.equals(box[3], fbox.height, prefix + 'box.height')
} else {
t.equals(box[3], gl.drawingBufferHeight - box[1], prefix + 'box.height')
}
}
var permutations = [
{
enable: true,
box: {
}
},
{
enable: false,
box: {
x: 5,
y: 1
}
},
{
enable: false,
box: {
w: 10,
h: 10
}
}
]
var staticOptions = {
frag: [
'precision mediump float;',
'void main() {',
' gl_FragColor = vec4(1, 0, 0, 1);',
'}'
].join('\n'),
vert: [
'precision mediump float;',
'attribute vec2 position;',
'void main() {',
' gl_Position = vec4(position, 0, 1);',
'}'
].join('\n'),
attributes: {
position: regl.buffer([
[0, 0],
[1, 0],
[1, 1],
[0, 1],
[1, 0],
[1, 1]
])
},
count: 6
}
var dynamicDraw = regl(extend({
scissor: {
enable: regl.prop('enable'),
box: regl.prop('box')
}
}, staticOptions))
permutations.forEach(function (params) {
dynamicDraw(params)
testFlags('dynamic 1-shot - ', params)
})
permutations.forEach(function (params) {
dynamicDraw([params])
testFlags('batch - ', params)
})
permutations.forEach(function (params) {
var staticDraw = regl(extend({
scissor: params
}, staticOptions))
staticDraw()
testFlags('static - ', params)
})
regl.destroy()
t.equals(gl.getError(), 0, 'error ok')
createContext.destroy(gl)
t.end()
})