Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpux_vbo.c « intern « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 84d2697cbb273495cfcb58c7816437648b5173ad (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618

#include "GPUx_vbo.h"
#include "gpux_buffer_id.h"
#include "GPU_extensions.h"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
#include <string.h>

#ifdef PRINT
  #include <stdio.h>
#endif

/* VBOs are guaranteed for any GL >= 1.5
 * They can be turned off here (mostly for comparison). */
#define USE_VBO

#ifdef USE_VBO
  /* VAOs are part of GL 3.0, and optionally available in 2.1 as an extension:
   * APPLE_vertex_array_object or ARB_vertex_array_object
   * the ARB version of VAOs *must* use VBOs for vertex data
   * so we should follow that restriction on all platforms. */
  #define USE_VAO

  /* keep vertex data in main mem or VRAM (not both) */
  #define KEEP_SINGLE_COPY

  #ifdef __linux__
    #define MESA_WORKAROUND
    /* For padded attributes (stride > size) Mesa likes the VBO to have some extra
     * space at the end, else it drops those attributes of our final vertex.
     * noticed this on Mesa 10.4.3 */
  #endif
#endif

typedef unsigned char byte;

typedef struct {
	GLenum comp_type;
	unsigned comp_ct; /* 1 to 4 */
	unsigned sz; /* size in bytes, 1 to 16 */
	unsigned stride; /* natural stride in bytes, 1 to 16 */
	VertexFetchMode fetch_mode;
#ifdef GENERIC_ATTRIB
	char *name;
#else
	GLenum array;
#endif
	void *data;
	/* TODO: more storage options
	 * - single VBO for all attribs (sequential)
	 * - single VBO, attribs interleaved
	 * - distinguish between static & dynamic attribs, w/ separate storage */
#ifdef USE_VBO
	GLuint vbo_id;
#endif /* USE_VBO */
} Attrib;

static unsigned comp_sz(GLenum type)
{
	const GLubyte sizes[] = {1,1,2,2,4,4,4}; /* uint32 might result in smaller code? */
#ifdef TRUST_NO_ONE
	BLI_assert(type >= GL_BYTE && type <= GL_FLOAT);
#endif /* TRUST_NO_ONE */
	return sizes[type - GL_BYTE];
}

static unsigned attrib_sz(const Attrib *a)
{
	return a->comp_ct * comp_sz(a->comp_type);
}

static unsigned attrib_align(const Attrib *a)
{
	const unsigned c = comp_sz(a->comp_type);
	/* AMD HW can't fetch these well, so pad it out (other vendors too?) */
	if (a->comp_ct == 3 && c <= 2)
		return 4 * c;
	else
		return a->comp_ct * c;
}

struct VertexBuffer
{
	unsigned attrib_ct; /* 1 to 16 */
	unsigned vertex_ct;
#ifdef USE_VAO
	GLuint vao_id;
#endif /* USE_VAO */
	Attrib attribs[]; /* flexible array */
};

#ifdef PRINT
void GPUx_attrib_print(const VertexBuffer *buff, unsigned attrib_num)
{
	unsigned int comp_size, v;
	Attrib *a = buff->attribs + attrib_num;
	unsigned type_idx = a->comp_type - GL_BYTE;
	/* use GLSL names when they exist, or type_count for the others */
	const char *singular[] = {"byte","ubyte","short","ushort","int","uint","float"};
	const char *plural[] = {"byte_","ubyte_","short_","ushort_","ivec","uint_","vec"};
#ifdef GENERIC_ATTRIB
	const char *var_name = a->name ? a->name : "foo";
#else
	const char* var_name = "foo";
	switch (a->array) {
		case GL_VERTEX_ARRAY:
			var_name = "gl_Vertex";
			break;
		case GL_NORMAL_ARRAY:
			var_name = "gl_Normal";
			break;
		case GL_COLOR_ARRAY:
			var_name = "gl_Color";
			break;
		case GL_TEXTURE_COORD_ARRAY:
			var_name = "gl_MultiTexCoord0";
			break;
		default:
			;
	}
#endif
#ifdef TRUST_NO_ONE
	BLI_assert(attrib_num < buff->attrib_ct);
	BLI_assert(a->comp_type >= GL_BYTE && a->comp_type <= GL_FLOAT);
	BLI_assert(a->data != NULL); /* attribute must be specified & in main mem */
#endif /* TRUST_NO_ONE */
	if (a->comp_ct == 1)
		printf("attrib %s %s = {\n", singular[type_idx], var_name);
	else
		printf("attrib %s%d %s = {\n", plural[type_idx], a->comp_ct, var_name);

	comp_size = comp_sz(a->comp_type);
	for (v = 0; v < buff->vertex_ct; ++v) {
		unsigned int offset;
		const void *data = (byte*)a->data + v * a->stride;
		for (offset = 0; offset < a->sz; ++offset) {
			if (offset % comp_size == 0)
				putchar(' ');
			printf("%02X", *(const byte*)data + offset);
		}
		putchar('\n');
	}
	puts("}");
}
#endif /* PRINT */

VertexBuffer *GPUx_vertex_buffer_create(unsigned a_ct, unsigned v_ct)
{
	VertexBuffer *buff;
#ifdef TRUST_NO_ONE
	BLI_assert(a_ct >= 1 && a_ct <= 16);
  #ifdef USE_VAO
	BLI_assert(GPU_vertex_array_object_support());
  #endif /* USE_VBO */
#endif /* TRUST_NO_ONE */
	buff = MEM_callocN(offsetof(VertexBuffer, attribs) + a_ct * sizeof(Attrib), "VertexBuffer");
	buff->attrib_ct = a_ct;
	buff->vertex_ct = v_ct;
	return buff;
}

void GPUx_vertex_buffer_discard(VertexBuffer *buff)
{
	unsigned a_idx;
	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
		Attrib *a = buff->attribs + a_idx;
#ifdef USE_VBO
		if (a->vbo_id)
			buffer_id_free(a->vbo_id);
#endif /* USE_VBO */
#ifdef GENERIC_ATTRIB
		MEM_freeN(a->name);
#endif /* GENERIC_ATTRIB */
		if (a->data)
			MEM_freeN(a->data);
	}
#ifdef USE_VAO
	if (buff->vao_id)
		vao_id_free(buff->vao_id);
#endif /* USE_VAO */
	MEM_freeN(buff);
}

static unsigned attrib_total_size(const VertexBuffer *buff, unsigned attrib_num)
{
	const Attrib *attrib = buff->attribs + attrib_num;
#ifdef TRUST_NO_ONE
	BLI_assert(attrib_num < buff->attrib_ct);
#endif /* TRUST_NO_ONE */

#ifdef MESA_WORKAROUND
	/* an over-estimate, with padding after each vertex */
	return buff->vertex_ct * attrib->stride;
#else
	/* just enough space for every vertex, with padding between but not after the last */
	return (buff->vertex_ct - 1) * attrib->stride + attrib->sz;
#endif /*  MESA_WORKAROUND */
}

unsigned GPUx_vertex_buffer_size(const VertexBuffer *buff)
{
	unsigned sz = 0;
	unsigned a_idx;
	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx)
		sz += attrib_total_size(buff, a_idx);
	return sz;
}

void GPUx_specify_attrib(VertexBuffer *buff, unsigned attrib_num,
#ifdef GENERIC_ATTRIB
                    const char *name,
#else
                    GLenum attrib_array,
#endif
                    GLenum comp_type, unsigned comp_ct, VertexFetchMode fetch_mode)
{
	Attrib *attrib;
#ifdef TRUST_NO_ONE
	BLI_assert(attrib_num < buff->attrib_ct);
	BLI_assert(comp_type >= GL_BYTE && comp_type <= GL_FLOAT);
	BLI_assert(comp_ct >= 1 && comp_ct <= 4);

	if (comp_type == GL_FLOAT)
		BLI_assert(fetch_mode == KEEP_FLOAT);
	else {
		BLI_assert(fetch_mode != KEEP_FLOAT);
		if (fetch_mode == KEEP_INT)
			BLI_assert(GPU_shader4_support());
	}

  #ifndef GENERIC_ATTRIB
	/* classic (non-generic) attributes each have their quirks
	 * handle below */
	switch (attrib_array) {
		case GL_VERTEX_ARRAY:
			BLI_assert(comp_type == GL_FLOAT || comp_type == GL_SHORT || comp_type == GL_INT);
			if (comp_type != GL_FLOAT)
				BLI_assert(fetch_mode == CONVERT_INT_TO_FLOAT);
			BLI_assert(comp_ct >= 2);
			break;
		case GL_NORMAL_ARRAY:
			BLI_assert(comp_type == GL_FLOAT || comp_type == GL_BYTE || comp_type == GL_SHORT || comp_type == GL_INT);
			if (comp_type != GL_FLOAT)
				BLI_assert(fetch_mode == NORMALIZE_INT_TO_FLOAT);
			BLI_assert(comp_ct == 3);
			break;
		case GL_COLOR_ARRAY:
			/* any comp_type allowed */
			if (comp_type != GL_FLOAT)
				BLI_assert(fetch_mode == NORMALIZE_INT_TO_FLOAT);
			BLI_assert(comp_ct >= 3);
			break;
		case GL_TEXTURE_COORD_ARRAY:
			BLI_assert(comp_type == GL_FLOAT || comp_type == GL_SHORT || comp_type == GL_INT);
			if (comp_type != GL_FLOAT)
				BLI_assert(fetch_mode == CONVERT_INT_TO_FLOAT);
			break;
		/* not supporting these:
		 * GL_INDEX_ARRAY
		 * GL_SECONDARY_COLOR_ARRAY
		 * GL_EDGE_FLAG_ARRAY
		 * GL_FOG_COORD_ARRAY
		 */
		default:
			BLI_assert(false); /* bad or unsupported array */
	}
	BLI_assert(fetch_mode != KEEP_INT); /* glVertexPointer and friends have no int variants */
	/* TODO: allow only one of each type of array (scan other attribs) */
  #endif
#endif /* TRUST_NO_ONE */
	attrib = buff->attribs + attrib_num;
#ifdef GENERIC_ATTRIB
	attrib->name = strdup(name);
#else
	attrib->array = attrib_array;
#endif /* GENERIC_ATTRIB */
	attrib->comp_type = comp_type;
	attrib->comp_ct = comp_ct;
	attrib->sz = attrib_sz(attrib);
	attrib->stride = attrib_align(attrib);
	attrib->fetch_mode = fetch_mode;
	attrib->data = MEM_mallocN(attrib_total_size(buff, attrib_num), "Attrib.data");
#ifdef PRINT
	GPUx_attrib_print(buff, attrib_num);
#endif /* PRINT */
}

void GPUx_set_attrib(VertexBuffer *buff, unsigned attrib_num, unsigned vertex_num, const void *data)
{
	Attrib *attrib = buff->attribs + attrib_num;
#ifdef TRUST_NO_ONE
	BLI_assert(attrib_num < buff->attrib_ct);
	BLI_assert(vertex_num < buff->vertex_ct);
	BLI_assert(attrib->data != NULL); /* attribute must be specified & in main mem */
#endif /* TRUST_NO_ONE */
	memcpy((byte*)attrib->data + vertex_num * attrib->stride, data, attrib->sz);
}

void GPUx_set_attrib_2f(VertexBuffer *buff, unsigned attrib_num, unsigned vertex_num, float x, float y)
{
	const GLfloat data[] = { x, y };
#ifdef TRUST_NO_ONE
	Attrib *attrib = buff->attribs + attrib_num;
	BLI_assert(attrib->comp_type == GL_FLOAT);
	BLI_assert(attrib->comp_ct == 2);
#endif /* TRUST_NO_ONE */
	GPUx_set_attrib(buff, attrib_num, vertex_num, data);
}

void GPUx_set_attrib_3f(VertexBuffer *buff, unsigned attrib_num, unsigned vertex_num, float x, float y, float z)
{
	const GLfloat data[] = { x, y, z };
#ifdef TRUST_NO_ONE
	Attrib *attrib = buff->attribs + attrib_num;
	BLI_assert(attrib->comp_type == GL_FLOAT);
	BLI_assert(attrib->comp_ct == 3);
#endif /* TRUST_NO_ONE */
	GPUx_set_attrib(buff, attrib_num, vertex_num, data);
}

void GPUx_fill_attrib(VertexBuffer *buff, unsigned attrib_num, const void *data)
	{
	Attrib *attrib = buff->attribs + attrib_num;
#ifdef TRUST_NO_ONE
	BLI_assert(attrib_num < buff->attrib_ct);
	BLI_assert(attrib->data != NULL); /* attribute must be specified & in main mem */
#endif /* TRUST_NO_ONE */
	if (attrib->sz == attrib->stride) {
		/* tightly packed, so we can copy it all at once */
		memcpy(attrib->data, data, buff->vertex_ct * attrib->sz);
	}
	else {
		unsigned v;
		/* not tightly packed, so we must copy it per vertex
		 * (this is begging for vector (SSE) coding) */
		for (v = 0; v < buff->vertex_ct; ++v)
			memcpy((byte*)attrib->data + v * attrib->stride, (byte*)data + v * attrib->sz, attrib->sz);
	}
}

void GPUx_fill_attrib_stride(VertexBuffer *buff, unsigned attrib_num, const void *data, unsigned stride)
{
	Attrib *attrib = buff->attribs + attrib_num;
#ifdef TRUST_NO_ONE
	BLI_assert(attrib_num < buff->attrib_ct);
	BLI_assert(attrib->data != NULL); /* attribute must be specified & in main mem */
	BLI_assert(stride >= attrib->sz); /* no overlapping attributes (legal but weird) */
#endif /* TRUST_NO_ONE */
	if (stride == attrib->stride) {
		/* natural stride used, so we can copy it all at once */
		memcpy(attrib->data, data, buff->vertex_ct * attrib->sz);
	}
	else {
		unsigned v;
		/* we must copy it per vertex */
		for (v = 0; v < buff->vertex_ct; ++v)
			memcpy((byte*)attrib->data + v * attrib->stride, (byte*)data + v * stride, attrib->sz);
	}
}

void GPUx_vertex_buffer_use(VertexBuffer *buff)
{
	unsigned a_idx;
	const void *data;
#ifdef USE_VAO
	if (buff->vao_id) {
		/* simply bind & exit */
		glBindVertexArray(buff->vao_id);
		return;
	}
	else {
		buff->vao_id = vao_id_alloc();
		glBindVertexArray(buff->vao_id);
	}
#endif /* USE_VAO */

	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
		Attrib *a = buff->attribs + a_idx;

#ifdef GENERIC_ATTRIB
		glEnableVertexAttribArray(a_idx);
#else
		glEnableClientState(a->array);
#endif /* GENERIC_ATTRIB */

#ifdef USE_VBO
		if (a->vbo_id)
			glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
		else {
			a->vbo_id = buffer_id_alloc();
			glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
			/* fill with delicious data & send to GPU the first time only */
			glBufferData(GL_ARRAY_BUFFER, attrib_total_size(buff, a_idx), a->data, GL_STATIC_DRAW);
  #ifdef KEEP_SINGLE_COPY
			/* now that GL has a copy, discard original */
			MEM_freeN(a->data);
			a->data = NULL;
  #endif /* KEEP_SINGLE_COPY */
		}

		data = 0;
#else /* client vertex array */
		data = a->data;
#endif /* USE_VBO */

#ifdef GENERIC_ATTRIB
		switch (a->fetch_mode) {
			case KEEP_FLOAT:
			case CONVERT_INT_TO_FLOAT:
				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_FALSE, a->stride, data);
				break;
			case NORMALIZE_INT_TO_FLOAT:
				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_TRUE, a->stride, data);
				break;
			case KEEP_INT:
				glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, data);
		}
#else /* classic (non-generic) attributes */
		switch (a->array) {
			case GL_VERTEX_ARRAY:
				glVertexPointer(a->comp_ct, a->comp_type, a->stride, data);
				break;
			case GL_NORMAL_ARRAY:
				glNormalPointer(a->comp_type, a->stride, data);
				break;
			case GL_COLOR_ARRAY:
				glColorPointer(a->comp_ct, a->comp_type, a->stride, data);
				break;
			case GL_TEXTURE_COORD_ARRAY:
				glTexCoordPointer(a->comp_ct, a->comp_type, a->stride, data);
				/* TODO: transition to glMultiTexCoordPointer? */
				break;
			default:
				;
		}
#endif /* GENERIC_ATTRIB */
	}

#ifdef USE_VBO
	glBindBuffer(GL_ARRAY_BUFFER, 0);
#endif /* USE_VBO */
}

void GPUx_vertex_buffer_prime(VertexBuffer *buff)
{
	unsigned a_idx;
#ifdef USE_VAO
  #ifdef TRUST_NO_ONE
	BLI_assert(buff->vao_id == 0);
  #endif /* TRUST_NO_ONE */

	buff->vao_id = vao_id_alloc();
	glBindVertexArray(buff->vao_id);
#endif /* USE_VAO */

#ifdef USE_VBO
	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
		Attrib *a = buff->attribs + a_idx;

  #ifdef USE_VAO
    #ifdef GENERIC_ATTRIB
		glEnableVertexAttribArray(a_idx);
    #else
		glEnableClientState(a->array);
    #endif /* GENERIC_ATTRIB */
  #endif /* USE_VAO */

  #ifdef TRUST_NO_ONE
		BLI_assert(a->vbo_id == 0);
  #endif /* TRUST_NO_ONE */

		a->vbo_id = buffer_id_alloc();
		glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);
		/* fill with delicious data & send to GPU the first time only */
		glBufferData(GL_ARRAY_BUFFER, attrib_total_size(buff, a_idx), a->data, GL_STATIC_DRAW);
  #ifdef KEEP_SINGLE_COPY
		/* now that GL has a copy, discard original */
		MEM_freeN(a->data);
		a->data = NULL;
  #endif /* KEEP_SINGLE_COPY */

  #ifdef USE_VAO
    #ifdef GENERIC_ATTRIB
		switch (a->fetch_mode) {
			case KEEP_FLOAT:
			case CONVERT_INT_TO_FLOAT:
				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_FALSE, a->stride, 0);
				break;
			case NORMALIZE_INT_TO_FLOAT:
				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_TRUE, a->stride, 0);
				break;
			case KEEP_INT:
				glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, 0);
		}
    #else /* classic (non-generic) attributes */
		switch (a->array) {
			case GL_VERTEX_ARRAY:
				glVertexPointer(a->comp_ct, a->comp_type, a->stride, 0);
				break;
			case GL_NORMAL_ARRAY:
				glNormalPointer(a->comp_type, a->stride, 0);
				break;
			case GL_COLOR_ARRAY:
				glColorPointer(a->comp_ct, a->comp_type, a->stride, 0);
				break;
			case GL_TEXTURE_COORD_ARRAY:
				glTexCoordPointer(a->comp_ct, a->comp_type, a->stride, 0);
				break;
			default:
				;
		}
    #endif /* GENERIC_ATTRIB */
  #endif /* USE_VAO */
	}

	glBindBuffer(GL_ARRAY_BUFFER, 0);
#else
	UNUSED_VARS(a_idx, buff);
#endif /* USE_VBO */

#ifdef USE_VAO
	glBindVertexArray(0);
#endif /* USE_VAO */
}

void GPUx_vertex_buffer_use_primed(const VertexBuffer *buff)
{
#ifdef USE_VAO
  #ifdef TRUST_NO_ONE
	BLI_assert(buff->vao_id);
  #endif /* TRUST_NO_ONE */

	/* simply bind & exit */
	glBindVertexArray(buff->vao_id);
#else
	unsigned int a_idx;

	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
		Attrib *a = buff->attribs + a_idx;
		const void *data;

  #ifdef GENERIC_ATTRIB
		glEnableVertexAttribArray(a_idx);
  #else
		glEnableClientState(a->array);
  #endif /* GENERIC_ATTRIB */

  #ifdef USE_VBO
    #ifdef TRUST_NO_ONE
		BLI_assert(a->vbo_id);
    #endif /* TRUST_NO_ONE */
		glBindBuffer(GL_ARRAY_BUFFER, a->vbo_id);

		data = 0;
  #else /* client vertex array */
		data = a->data;
  #endif /* USE_VBO */

  #ifdef GENERIC_ATTRIB
		switch (a->fetch_mode) {
			case KEEP_FLOAT:
			case CONVERT_INT_TO_FLOAT:
				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_FALSE, a->stride, data);
				break;
			case NORMALIZE_INT_TO_FLOAT:
				glVertexAttribPointer(a_idx, a->comp_ct, a->comp_type, GL_TRUE, a->stride, data);
				break;
			case KEEP_INT:
				glVertexAttribIPointerEXT(a_idx, a->comp_ct, a->comp_type, a->stride, data);
		}
  #else /* classic (non-generic) attributes */
		switch (a->array) {
			case GL_VERTEX_ARRAY:
				glVertexPointer(a->comp_ct, a->comp_type, a->stride, data);
				break;
			case GL_NORMAL_ARRAY:
				glNormalPointer(a->comp_type, a->stride, data);
				break;
			case GL_COLOR_ARRAY:
				glColorPointer(a->comp_ct, a->comp_type, a->stride, data);
				break;
			case GL_TEXTURE_COORD_ARRAY:
				glTexCoordPointer(a->comp_ct, a->comp_type, a->stride, data);
				break;
			default:
				;
		}
  #endif /* GENERIC_ATTRIB */
	}

  #ifdef USE_VBO
	glBindBuffer(GL_ARRAY_BUFFER, 0);
  #endif /* USE_VBO */
#endif /* USE_VAO */
}

void GPUx_vertex_buffer_done_using(const VertexBuffer *buff)
{
#ifdef USE_VAO
	UNUSED_VARS(buff);
	glBindVertexArray(0);
#else
	unsigned int a_idx;

	for (a_idx = 0; a_idx < buff->attrib_ct; ++a_idx) {
  #ifdef GENERIC_ATTRIB
		glDisableVertexAttribArray(a_idx);
  #else
		glDisableClientState(buff->attribs[a_idx].array);
  #endif /* GENERIC_ATTRIB */
	}
#endif /* USE_VAO */
}

unsigned GPUx_vertex_ct(const VertexBuffer *buff)
{
	return buff->vertex_ct;
}