@@ -23,17 +23,30 @@ GLuint VBO_Vertex::actVerts = 0;
23
23
GLuint VBO_Vertex::actNorms = 0 ;
24
24
GLuint VBO_Vertex::actTxcds = 0 ;
25
25
GLuint VBO_Vertex::actColrs = 0 ;
26
+ GLuint VBO_Vertex::actIntrs = 0 ;
26
27
GLuint VBO_Vertex::actBounded = 0 ;
27
28
28
29
VBO_Vertex::VBO_Vertex (
29
30
bool handleTexture_,
30
31
bool handleNormal_,
31
- bool handleColor_) :
32
+ bool handleColor_,
33
+ bool interlaced_) :
32
34
VBO_Handler(),
33
35
handleTexture(handleTexture_), handleNormal(handleNormal_),
34
36
handleColor(handleColor_), verts(0 ), txcds(0 ), norms(0 ), colrs(0 ),
35
- vbosReady(false )
37
+ vbosReady(false ), interlaced(interlaced_)
36
38
{
39
+ interlaced = false ;
40
+ interlacedSize = 3 ;
41
+ strideTexture = interlacedSize;
42
+ if (handleTexture)
43
+ interlacedSize += 2 ;
44
+ strideNormal = interlacedSize;
45
+ if (handleNormal)
46
+ interlacedSize += 3 ;
47
+ strideColor = interlacedSize;
48
+ if (handleColor)
49
+ interlacedSize += 4 ;
37
50
}
38
51
39
52
void VBO_Vertex::resize ()
@@ -51,6 +64,8 @@ void VBO_Vertex::resize()
51
64
hostedNormals.resize (3 * vboSize);
52
65
if (!hostedColors.empty ())
53
66
hostedColors.resize (4 * vboSize);
67
+ if (!hostedInterlaced.empty ())
68
+ hostedInterlaced.resize (interlacedSize * vboSize);
54
69
if (!vbosReady)
55
70
// Don't do anything on GL Context memory if not ready
56
71
return ;
@@ -65,6 +80,9 @@ void VBO_Vertex::init()
65
80
return ;
66
81
// GL Context is ready
67
82
// Bind all buffers
83
+ if (interlaced)
84
+ glGenBuffers (1 , &intrs);
85
+ else
68
86
{
69
87
glGenBuffers (1 , &verts);
70
88
if (handleTexture)
@@ -76,6 +94,15 @@ void VBO_Vertex::init()
76
94
}
77
95
78
96
// Copy in memory buffer to GPU
97
+ if (interlaced)
98
+ {
99
+ bindBuffer (intrs);
100
+ glBufferData (GL_ARRAY_BUFFER,
101
+ vboSize * interlacedSize * sizeof (GLfloat),
102
+ hostedInterlaced.data (),
103
+ GL_DYNAMIC_DRAW);
104
+ }
105
+ else
79
106
{
80
107
bindBuffer (verts);
81
108
glBufferData (GL_ARRAY_BUFFER,
@@ -115,6 +142,9 @@ void VBO_Vertex::destroy()
115
142
if (!vboSize)
116
143
return ;
117
144
// drop all buffers
145
+ if (interlaced)
146
+ deleteBuffer (intrs);
147
+ else
118
148
{
119
149
deleteBuffer (verts);
120
150
if (handleTexture)
@@ -140,6 +170,20 @@ std::string VBO_Vertex::vboName()
140
170
141
171
void VBO_Vertex::vertexData (int index, int size, const GLfloat vertices[])
142
172
{
173
+ if (interlaced)
174
+ {
175
+ if (hostedInterlaced.empty ())
176
+ hostedInterlaced.resize (interlacedSize * vboSize);
177
+ auto dataP = &hostedInterlaced[index * interlacedSize];
178
+ auto vertP = vertices;
179
+ for (int i = 0 ; i < size; i++)
180
+ {
181
+ memcpy (dataP, vertP, sizeof (GLfloat[3 ]));
182
+ dataP += interlacedSize;
183
+ vertP += 3 ;
184
+ }
185
+ }
186
+ else
143
187
{
144
188
if (hostedVertices.empty ())
145
189
hostedVertices.resize (3 * vboSize);
@@ -149,6 +193,15 @@ void VBO_Vertex::vertexData(int index, int size, const GLfloat vertices[])
149
193
}
150
194
if (!vbosReady)
151
195
return ;
196
+ if (interlaced)
197
+ {
198
+ bindBuffer (intrs);
199
+ glBufferSubData (GL_ARRAY_BUFFER,
200
+ index * interlacedSize * sizeof (GLfloat),
201
+ size * interlacedSize * sizeof (GLfloat),
202
+ &hostedInterlaced[index * interlacedSize]);
203
+ }
204
+ else
152
205
{
153
206
bindBuffer (verts);
154
207
glBufferSubData (GL_ARRAY_BUFFER,
@@ -162,6 +215,21 @@ void VBO_Vertex::textureData(int index, int size, const GLfloat textures[])
162
215
{
163
216
if (!handleTexture)
164
217
return ;
218
+ if (interlaced)
219
+ {
220
+ if (hostedInterlaced.empty ())
221
+ hostedInterlaced.resize (interlacedSize * vboSize);
222
+ auto dataP = &hostedInterlaced[index * interlacedSize];
223
+ auto textP = textures;
224
+ dataP += strideTexture;
225
+ for (int i = 0 ; i < size; i++)
226
+ {
227
+ memcpy (dataP, textP, sizeof (GLfloat[2 ]));
228
+ dataP += interlacedSize;
229
+ textP += 2 ;
230
+ }
231
+ }
232
+ else
165
233
{
166
234
if (hostedTextures.empty ())
167
235
hostedTextures.resize (2 * vboSize);
@@ -171,6 +239,15 @@ void VBO_Vertex::textureData(int index, int size, const GLfloat textures[])
171
239
}
172
240
if (!vbosReady)
173
241
return ;
242
+ if (interlaced)
243
+ {
244
+ bindBuffer (intrs);
245
+ glBufferSubData (GL_ARRAY_BUFFER,
246
+ index * interlacedSize * sizeof (GLfloat),
247
+ size * interlacedSize * sizeof (GLfloat),
248
+ &hostedInterlaced[index * interlacedSize]);
249
+ }
250
+ else
174
251
{
175
252
bindBuffer (txcds);
176
253
glBufferSubData (GL_ARRAY_BUFFER,
@@ -184,6 +261,21 @@ void VBO_Vertex::normalData(int index, int size, const GLfloat normals[])
184
261
{
185
262
if (!handleNormal)
186
263
return ;
264
+ if (interlaced)
265
+ {
266
+ if (hostedInterlaced.empty ())
267
+ hostedInterlaced.resize (interlacedSize * vboSize);
268
+ auto dataP = &hostedInterlaced[index * interlacedSize];
269
+ auto normP = normals;
270
+ dataP += strideNormal;
271
+ for (int i = 0 ; i < size; i++)
272
+ {
273
+ memcpy (dataP, normP, sizeof (GLfloat[3 ]));
274
+ dataP += interlacedSize;
275
+ normP += 3 ;
276
+ }
277
+ }
278
+ else
187
279
{
188
280
if (hostedNormals.empty ())
189
281
hostedNormals.resize (3 * vboSize);
@@ -193,6 +285,15 @@ void VBO_Vertex::normalData(int index, int size, const GLfloat normals[])
193
285
}
194
286
if (!vbosReady)
195
287
return ;
288
+ if (interlaced)
289
+ {
290
+ bindBuffer (intrs);
291
+ glBufferSubData (GL_ARRAY_BUFFER,
292
+ index * interlacedSize * sizeof (GLfloat),
293
+ size * interlacedSize * sizeof (GLfloat),
294
+ &hostedInterlaced[index * interlacedSize]);
295
+ }
296
+ else
196
297
{
197
298
bindBuffer (norms);
198
299
glBufferSubData (GL_ARRAY_BUFFER,
@@ -206,6 +307,21 @@ void VBO_Vertex::colorData(int index, int size, const GLfloat colors[])
206
307
{
207
308
if (!handleColor)
208
309
return ;
310
+ if (interlaced)
311
+ {
312
+ if (hostedInterlaced.empty ())
313
+ hostedInterlaced.resize (interlacedSize * vboSize);
314
+ auto dataP = &hostedInterlaced[index * interlacedSize];
315
+ auto coloP = colors;
316
+ dataP += strideColor;
317
+ for (int i = 0 ; i < size; i++)
318
+ {
319
+ memcpy (dataP, coloP, sizeof (GLfloat[4 ]));
320
+ dataP += interlacedSize;
321
+ coloP += 4 ;
322
+ }
323
+ }
324
+ else
209
325
{
210
326
if (hostedColors.empty ())
211
327
hostedColors.resize (4 * vboSize);
@@ -215,6 +331,15 @@ void VBO_Vertex::colorData(int index, int size, const GLfloat colors[])
215
331
}
216
332
if (!vbosReady)
217
333
return ;
334
+ if (interlaced)
335
+ {
336
+ bindBuffer (intrs);
337
+ glBufferSubData (GL_ARRAY_BUFFER,
338
+ index * interlacedSize * sizeof (GLfloat),
339
+ size * interlacedSize * sizeof (GLfloat),
340
+ &hostedInterlaced[index * interlacedSize]);
341
+ }
342
+ else
218
343
{
219
344
bindBuffer (colrs);
220
345
glBufferSubData (GL_ARRAY_BUFFER,
@@ -256,6 +381,24 @@ void VBO_Vertex::enableVertexOnly()
256
381
257
382
void VBO_Vertex::enableVertex ()
258
383
{
384
+ if (interlaced)
385
+ {
386
+ if (actIntrs == intrs)
387
+ return ;
388
+ actIntrs = intrs;
389
+ bindBuffer (intrs);
390
+ glVertexPointer (3 , GL_FLOAT, interlacedSize * sizeof (GLfloat), 0 );
391
+ glTexCoordPointer (2 , GL_FLOAT,
392
+ interlacedSize * sizeof (GLfloat),
393
+ (void *)(strideTexture * sizeof (GLfloat)));
394
+ glNormalPointer (GL_FLOAT,
395
+ interlacedSize * sizeof (GLfloat),
396
+ (void *)(strideNormal * sizeof (GLfloat)));
397
+ glColorPointer (4 , GL_FLOAT,
398
+ interlacedSize * sizeof (GLfloat),
399
+ (void *)(strideColor * sizeof (GLfloat)));
400
+ }
401
+ else
259
402
{
260
403
if (actVerts == verts)
261
404
return ;
@@ -282,6 +425,7 @@ void VBO_Vertex::enableTextures()
282
425
if (actTxcds == txcds)
283
426
return ;
284
427
actTxcds = txcds;
428
+ if (!interlaced)
285
429
{
286
430
bindBuffer (txcds);
287
431
glTexCoordPointer (2 , GL_FLOAT, 0 , 0 );
@@ -305,6 +449,7 @@ void VBO_Vertex::enableNormals()
305
449
if (actNorms == norms)
306
450
return ;
307
451
actNorms = norms;
452
+ if (!interlaced)
308
453
{
309
454
bindBuffer (norms);
310
455
glNormalPointer (GL_FLOAT, 0 , 0 );
@@ -328,6 +473,7 @@ void VBO_Vertex::enableColors()
328
473
if (actColrs == colrs)
329
474
return ;
330
475
actColrs = colrs;
476
+ if (!interlaced)
331
477
{
332
478
bindBuffer (colrs);
333
479
glColorPointer (4 , GL_FLOAT, 0 , 0 );
@@ -350,6 +496,12 @@ void VBO_Vertex::deleteBuffer(GLuint buffer)
350
496
// tell that this buffer is not more bounded
351
497
if (actBounded == buffer)
352
498
actBounded = 0 ;
499
+ if (interlaced)
500
+ {
501
+ if (actIntrs == buffer)
502
+ actIntrs = 0 ;
503
+ }
504
+ else
353
505
{
354
506
if (actVerts == buffer)
355
507
actVerts = 0 ;
0 commit comments