-
Notifications
You must be signed in to change notification settings - Fork 18
/
Buffer.hx
154 lines (129 loc) · 4.17 KB
/
Buffer.hx
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
package defold;
import defold.types.util.LuaArray;
import defold.types.BufferData;
import defold.types.BufferStream;
import defold.types.HashOrString;
/**
Functions for manipulating buffers and streams.
**/
@:native("_G.buffer")
extern final class Buffer
{
/**
Copy all data streams from one buffer to another, element wise.
Each of the source streams must have a matching stream in the
destination buffer. The streams must match in both type and size.
The source and destination buffer can be the same.
@param dst the destination buffer
@param dstoffset the offset to start copying data to
@param src the source data buffer
@param srcoffset the offset to start copying data from
@param count the number of elements to copy
**/
@:native('copy_buffer')
static function copyBuffer(dst:defold.types.Buffer, dstoffset:Int, src:defold.types.Buffer, srcoffset:Int, count:Int):Void;
/**
Copy a specified amount of data from one stream to another.
The value type and size must match between source and destination streams.
The source and destination streams can be the same.
@param dst the destination stream
@param dstoffset the offset to start copying data to (measured in value type)
@param src the source data stream
@param srcoffset the offset to start copying data from (measured in value type)
@param count the number of values to copy (measured in value type)
**/
@:native('copy_stream')
static function copyStream(dst:BufferStream, dstoffset:Int, src:BufferStream, srcoffset:Int, count:Int):Void;
/**
Create a new data buffer containing a specified set of streams. A data buffer
can contain one or more streams with typed data. This is useful for managing
compound data, for instance a vertex buffer could contain separate streams for
vertex position, color, normal etc.
@param element_count The number of elements the buffer should hold
@param declaration A table where each entry (table) describes a stream
**/
static function create(element_count:Int, declaration:LuaArray<BufferStreamDeclaration>):defold.types.Buffer;
/**
Get a copy of all the bytes from a specified stream as a Lua string.
@param buffer the source buffer
@param stream_name the name of the stream
@return the buffer data as a Lua string
**/
@:native('get_bytes')
static function getBytes(buffer:defold.types.Buffer, stream_name:HashOrString):BufferData;
/**
Get a specified stream from a buffer.
@param buffer the buffer to get the stream from
@param stream_name the stream name
@return the data stream
**/
@:native('get_stream')
static function getStream(buffer:defold.types.Buffer, stream_name:HashOrString):BufferStream;
}
/**
Structure for buffer stream declaration used in `Buffer.create`.
**/
typedef BufferStreamDeclaration =
{
/**
The name of the stream.
**/
var name:HashOrString;
/**
The data type of the stream.
**/
var type:BufferStreamType;
/**
The number of values each element should hold.
**/
var count:Int;
}
@:native("_G.buffer")
extern enum abstract BufferStreamType(Int)
{
/**
Float, single precision, 4 bytes
**/
@:native('VALUE_TYPE_FLOAT32')
var Float32;
/**
Signed integer, 2 bytes
**/
@:native('VALUE_TYPE_INT16')
var Int16;
/**
Signed integer, 4 bytes
**/
@:native('VALUE_TYPE_INT32')
var Int32;
/**
Signed integer, 8 bytes
**/
@:native('VALUE_TYPE_INT64')
var Int64;
/**
Signed integer, 1 byte
**/
@:native('VALUE_TYPE_INT8')
var Int8;
/**
Unsigned integer, 2 bytes
**/
@:native('VALUE_TYPE_UINT16')
var Uint16;
/**
Unsigned integer, 4 bytes
**/
@:native('VALUE_TYPE_UINT32')
var Uint32;
/**
Unsigned integer, 8 bytes
**/
@:native('VALUE_TYPE_UINT64')
var Uint64;
/**
Unsigned integer, 1 byte
**/
@:native('VALUE_TYPE_UINT8')
var Uint8;
}