forked from regl-project/regl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer.js
162 lines (151 loc) Β· 3.21 KB
/
buffer.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var createContext = require('./util/create-context')
var createREGL = require('../../regl')
var tape = require('tape')
tape('buffer arg parsing', function (t) {
var gl = createContext(16, 16)
var regl = createREGL(gl)
function checkProperties (buffer, props, prefix) {
var bufferProps = buffer._buffer
Object.keys(props).forEach(function (prop) {
if (prop === 'data') {
return
}
t.same(bufferProps[prop], props[prop], prefix + '.' + prop)
})
gl.bindBuffer(gl.ARRAY_BUFFER, bufferProps.buffer)
gl.getBufferParameter(
gl.ARRAY_BUFFER,
gl.BUFFER_SIZE,
bufferProps.byteLength)
gl.getBufferParameter(
gl.ARRAY_BUFFER,
gl.BUFFER_USAGE,
bufferProps.usage)
}
checkProperties(
regl.buffer(),
{
type: gl.ARRAY_BUFFER,
dtype: gl.UNSIGNED_BYTE,
dimension: 1,
usage: gl.STATIC_DRAW,
byteLength: 0,
data: null
},
'empty')
checkProperties(
regl.buffer(100),
{
type: gl.ARRAY_BUFFER,
dtype: gl.UNSIGNED_BYTE,
dimension: 1,
usage: gl.STATIC_DRAW,
byteLength: 100,
data: null
},
'length only')
checkProperties(
regl.buffer(new Uint16Array([1, 2, 3])),
{
type: gl.ARRAY_BUFFER,
dtype: gl.UNSIGNED_SHORT,
dimension: 1,
usage: gl.STATIC_DRAW,
byteLength: 3 * 2,
data: new Uint16Array([1, 2, 3])
},
'typed array')
checkProperties(
regl.buffer([1, 2, 3, 4]),
{
type: gl.ARRAY_BUFFER,
dtype: gl.FLOAT,
dimension: 1,
usage: gl.STATIC_DRAW,
byteLength: 4 * 4,
data: new Float32Array([1, 2, 3, 4])
},
'array')
checkProperties(
regl.buffer({
type: 'uint32',
dimension: 3,
usage: 'dynamic',
data: [1, 2, 3]
}),
{
type: gl.ARRAY_BUFFER,
dtype: gl.UNSIGNED_INT,
dimension: 3,
usage: gl.DYNAMIC_DRAW,
byteLength: 3 * 4,
data: new Uint32Array([1, 2, 3])
},
'type spec')
checkProperties(
regl.buffer([
[1, 2, 3, 4],
[5, 6, 7, 8]
]),
{
type: gl.ARRAY_BUFFER,
dtype: gl.FLOAT,
dimension: 4,
usage: gl.STATIC_DRAW,
byteLength: 8 * 4,
data: new Float32Array([
1, 2, 3, 4,
5, 6, 7, 8
])
},
'nested array')
checkProperties(
regl.buffer({
usage: 'stream',
type: 'int32',
data: [
[1, 2],
[3, 4],
[5, 6]
]
}),
{
type: gl.ARRAY_BUFFER,
dtype: gl.INT,
dimension: 2,
usage: gl.STREAM_DRAW,
byteLength: 6 * 4,
data: new Int32Array([
1, 2,
3, 4,
5, 6
])
},
'nested array with types')
checkProperties(
regl.buffer({
data: new Float32Array([
4, 0, 3, 0,
2, 0, 1, 0
]),
shape: [2, 2],
stride: [-4, -2],
offset: 6
}),
{
type: gl.ARRAY_BUFFER,
dtype: gl.FLOAT,
dimension: 2,
usage: gl.STATIC_DRAW,
byteLength: 4 * 4,
data: new Float32Array([
1, 2,
3, 4
])
},
'ndarray-like input')
regl.destroy()
t.equals(gl.getError(), 0, 'error ok')
createContext.destroy(gl)
t.end()
})