forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGLBufferAttribute.js
159 lines (128 loc) · 3.27 KB
/
GLBufferAttribute.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
/**
* An alternative version of a buffer attribute with more control over the VBO.
*
* The renderer does not construct a VBO for this kind of attribute. Instead, it uses
* whatever VBO is passed in constructor and can later be altered via the `buffer` property.
*
* The most common use case for this class is when some kind of GPGPU calculation interferes
* or even produces the VBOs in question.
*
* Notice that this class can only be used with {@link WebGLRenderer}.
*/
class GLBufferAttribute {
/**
* Constructs a new GL buffer attribute.
*
* @param {WebGLBuffer} buffer - The native WebGL buffer.
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
* @param {number} itemSize - The item size.
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
* @param {number} count - The expected number of vertices in VBO.
*/
constructor( buffer, type, itemSize, elementSize, count ) {
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isGLBufferAttribute = true;
/**
* The name of the buffer attribute.
*
* @type {string}
*/
this.name = '';
/**
* The native WebGL buffer.
*
* @type {WebGLBuffer}
*/
this.buffer = buffer;
/**
* The native data type.
*
* @type {number}
*/
this.type = type;
/**
* The item size, see {@link BufferAttribute#itemSize}.
*
* @type {number}
*/
this.itemSize = itemSize;
/**
* The corresponding size (in bytes) for the given `type` parameter.
*
* @type {number}
*/
this.elementSize = elementSize;
/**
* The expected number of vertices in VBO.
*
* @type {number}
*/
this.count = count;
/**
* A version number, incremented every time the `needsUpdate` is set to `true`.
*
* @type {number}
*/
this.version = 0;
}
/**
* Flag to indicate that this attribute has changed and should be re-sent to
* the GPU. Set this to `true` when you modify the value of the array.
*
* @type {number}
* @default false
* @param {boolean} value
*/
set needsUpdate( value ) {
if ( value === true ) this.version ++;
}
/**
* Sets the given native WebGL buffer.
*
* @param {WebGLBuffer} buffer - The buffer to set.
* @return {BufferAttribute} A reference to this instance.
*/
setBuffer( buffer ) {
this.buffer = buffer;
return this;
}
/**
* Sets the given native data type and element size.
*
* @param {number} type - The native data type (e.g. `gl.FLOAT`).
* @param {number} elementSize - The corresponding size (in bytes) for the given `type` parameter.
* @return {BufferAttribute} A reference to this instance.
*/
setType( type, elementSize ) {
this.type = type;
this.elementSize = elementSize;
return this;
}
/**
* Sets the item size.
*
* @param {number} itemSize - The item size.
* @return {BufferAttribute} A reference to this instance.
*/
setItemSize( itemSize ) {
this.itemSize = itemSize;
return this;
}
/**
* Sets the count (the expected number of vertices in VBO).
*
* @param {number} count - The count.
* @return {BufferAttribute} A reference to this instance.
*/
setCount( count ) {
this.count = count;
return this;
}
}
export { GLBufferAttribute };