forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBuffer32.js
More file actions
56 lines (44 loc) · 1.17 KB
/
Copy pathDataBuffer32.js
File metadata and controls
56 lines (44 loc) · 1.17 KB
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
var Class = require('../../../utils/Class');
var DataBuffer32 = new Class({
initialize:
function DataBuffer32 (byteSize)
{
this.dwordLength = 0;
this.dwordCapacity = byteSize / 4;
this.buffer = new ArrayBuffer(byteSize);
this.floatView = new Float32Array(this.buffer);
this.intView = new Int32Array(this.buffer);
this.uintView = new Uint32Array(this.buffer);
},
clear: function ()
{
this.dwordLength = 0;
},
getByteLength: function ()
{
return this.dwordLength * 4;
},
getByteCapacity: function ()
{
return this.buffer.byteLength;
},
allocate: function (dwordSize)
{
var currentLength = this.dwordLength;
this.dwordLength += dwordSize;
return currentLength;
},
getUsedBufferAsFloat: function ()
{
return this.floatView.subarray(0, this.dwordLength);
},
getUsedBufferAsInt: function ()
{
return this.intView.subarray(0, this.dwordLength);
},
getUsedBufferAsUint: function ()
{
return this.uintView.subarray(0, this.dwordLength);
}
});
module.exports = DataBuffer32;