Sync with trunk r63637.
[reactos.git] / dll / opengl / mesa / main / varray.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.6
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include <precomp.h>
27
28 /** Used to indicate which GL datatypes are accepted by each of the
29 * glVertex/Color/Attrib/EtcPointer() functions.
30 */
31 #define BOOL_BIT 0x1
32 #define BYTE_BIT 0x2
33 #define UNSIGNED_BYTE_BIT 0x4
34 #define SHORT_BIT 0x8
35 #define UNSIGNED_SHORT_BIT 0x10
36 #define INT_BIT 0x20
37 #define UNSIGNED_INT_BIT 0x40
38 #define HALF_BIT 0x80
39 #define FLOAT_BIT 0x100
40 #define DOUBLE_BIT 0x200
41
42
43 /** Convert GL datatype enum into a <type>_BIT value seen above */
44 static GLbitfield
45 type_to_bit(const struct gl_context *ctx, GLenum type)
46 {
47 switch (type) {
48 case GL_BOOL:
49 return BOOL_BIT;
50 case GL_BYTE:
51 return BYTE_BIT;
52 case GL_UNSIGNED_BYTE:
53 return UNSIGNED_BYTE_BIT;
54 case GL_SHORT:
55 return SHORT_BIT;
56 case GL_UNSIGNED_SHORT:
57 return UNSIGNED_SHORT_BIT;
58 case GL_INT:
59 return INT_BIT;
60 case GL_UNSIGNED_INT:
61 return UNSIGNED_INT_BIT;
62 case GL_FLOAT:
63 return FLOAT_BIT;
64 case GL_DOUBLE:
65 return DOUBLE_BIT;
66 default:
67 return 0;
68 }
69 }
70
71
72 /**
73 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
74 * functions.
75 *
76 * \param func name of calling function used for error reporting
77 * \param attrib the attribute array index to update
78 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
79 * \param sizeMin min allowable size value
80 * \param sizeMax max allowable size value
81 * \param size components per element (1, 2, 3 or 4)
82 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
83 * \param stride stride between elements, in elements
84 * \param normalized are integer types converted to floats in [-1, 1]?
85 * \param integer integer-valued values (will not be normalized to [-1,1])
86 * \param ptr the address (or offset inside VBO) of the array data
87 */
88 static void
89 update_array(struct gl_context *ctx,
90 const char *func,
91 GLuint attrib, GLbitfield legalTypesMask,
92 GLint sizeMin, GLint sizeMax,
93 GLint size, GLenum type, GLsizei stride,
94 GLboolean normalized, GLboolean integer,
95 const GLvoid *ptr)
96 {
97 struct gl_client_array *array;
98 GLbitfield typeBit;
99 GLsizei elementSize;
100
101 typeBit = type_to_bit(ctx, type);
102 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
103 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
104 func, _mesa_lookup_enum_by_nr(type));
105 return;
106 }
107
108 /* Do size parameter checking. */
109 if (size < sizeMin || size > sizeMax || size > 4) {
110 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
111 return;
112 }
113
114 ASSERT(size <= 4);
115
116 if (stride < 0) {
117 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
118 return;
119 }
120
121 elementSize = _mesa_sizeof_type(type) * size;
122
123 array = &ctx->Array.VertexAttrib[attrib];
124 array->Size = size;
125 array->Type = type;
126 array->Stride = stride;
127 array->StrideB = stride ? stride : elementSize;
128 array->Normalized = normalized;
129 array->Integer = integer;
130 array->Ptr = (const GLubyte *) ptr;
131 array->_ElementSize = elementSize;
132
133 ctx->NewState |= _NEW_ARRAY;
134 ctx->Array.NewState |= VERT_BIT(attrib);
135 }
136
137
138 void GLAPIENTRY
139 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
140 {
141 GLbitfield legalTypes = (SHORT_BIT | INT_BIT | FLOAT_BIT |
142 DOUBLE_BIT | HALF_BIT);
143 GET_CURRENT_CONTEXT(ctx);
144 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
145
146 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
147 legalTypes, 2, 4,
148 size, type, stride, GL_FALSE, GL_FALSE, ptr);
149 }
150
151
152 void GLAPIENTRY
153 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
154 {
155 const GLbitfield legalTypes = (BYTE_BIT | SHORT_BIT | INT_BIT |
156 HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
157 GET_CURRENT_CONTEXT(ctx);
158 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
159
160 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
161 legalTypes, 3, 3,
162 3, type, stride, GL_TRUE, GL_FALSE, ptr);
163 }
164
165
166 void GLAPIENTRY
167 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
168 {
169 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
170 SHORT_BIT | UNSIGNED_SHORT_BIT |
171 INT_BIT | UNSIGNED_INT_BIT |
172 HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
173 GET_CURRENT_CONTEXT(ctx);
174 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
175
176 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR,
177 legalTypes, 3, 4,
178 size, type, stride, GL_TRUE, GL_FALSE, ptr);
179 }
180
181
182 void GLAPIENTRY
183 _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
184 {
185 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
186 GET_CURRENT_CONTEXT(ctx);
187 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
188
189 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
190 legalTypes, 1, 1,
191 1, type, stride, GL_FALSE, GL_FALSE, ptr);
192 }
193
194
195 void GLAPIENTRY
196 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
197 {
198 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
199 FLOAT_BIT | DOUBLE_BIT);
200 GET_CURRENT_CONTEXT(ctx);
201 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
202
203 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
204 legalTypes, 1, 1,
205 1, type, stride, GL_FALSE, GL_FALSE, ptr);
206 }
207
208
209 void GLAPIENTRY
210 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
211 const GLvoid *ptr)
212 {
213 GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
214 HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
215 GET_CURRENT_CONTEXT(ctx);
216 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
217
218 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX,
219 legalTypes, 1, 4,
220 size, type, stride, GL_FALSE, GL_FALSE,
221 ptr);
222 }
223
224
225 void GLAPIENTRY
226 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
227 {
228 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
229 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
230 const GLboolean integer = GL_TRUE;
231 GET_CURRENT_CONTEXT(ctx);
232 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
233
234 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
235 legalTypes, 1, 1,
236 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
237 }
238
239 void GLAPIENTRY
240 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
241 GLsizei count, const GLvoid *ptr)
242 {
243 (void) count;
244 _mesa_VertexPointer(size, type, stride, ptr);
245 }
246
247
248 void GLAPIENTRY
249 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
250 const GLvoid *ptr)
251 {
252 (void) count;
253 _mesa_NormalPointer(type, stride, ptr);
254 }
255
256
257 void GLAPIENTRY
258 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
259 const GLvoid *ptr)
260 {
261 (void) count;
262 _mesa_ColorPointer(size, type, stride, ptr);
263 }
264
265
266 void GLAPIENTRY
267 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
268 const GLvoid *ptr)
269 {
270 (void) count;
271 _mesa_IndexPointer(type, stride, ptr);
272 }
273
274
275 void GLAPIENTRY
276 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
277 GLsizei count, const GLvoid *ptr)
278 {
279 (void) count;
280 _mesa_TexCoordPointer(size, type, stride, ptr);
281 }
282
283
284 void GLAPIENTRY
285 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
286 {
287 (void) count;
288 _mesa_EdgeFlagPointer(stride, ptr);
289 }
290
291
292 void GLAPIENTRY
293 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
294 {
295 GET_CURRENT_CONTEXT(ctx);
296 GLboolean tflag, cflag, nflag; /* enable/disable flags */
297 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
298 GLenum ctype = 0; /* color type */
299 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
300 const GLint toffset = 0; /* always zero */
301 GLint defstride; /* default stride */
302 GLint c, f;
303
304 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
305
306 f = sizeof(GLfloat);
307 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
308
309 if (stride < 0) {
310 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
311 return;
312 }
313
314 switch (format) {
315 case GL_V2F:
316 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
317 tcomps = 0; ccomps = 0; vcomps = 2;
318 voffset = 0;
319 defstride = 2*f;
320 break;
321 case GL_V3F:
322 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
323 tcomps = 0; ccomps = 0; vcomps = 3;
324 voffset = 0;
325 defstride = 3*f;
326 break;
327 case GL_C4UB_V2F:
328 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
329 tcomps = 0; ccomps = 4; vcomps = 2;
330 ctype = GL_UNSIGNED_BYTE;
331 coffset = 0;
332 voffset = c;
333 defstride = c + 2*f;
334 break;
335 case GL_C4UB_V3F:
336 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
337 tcomps = 0; ccomps = 4; vcomps = 3;
338 ctype = GL_UNSIGNED_BYTE;
339 coffset = 0;
340 voffset = c;
341 defstride = c + 3*f;
342 break;
343 case GL_C3F_V3F:
344 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
345 tcomps = 0; ccomps = 3; vcomps = 3;
346 ctype = GL_FLOAT;
347 coffset = 0;
348 voffset = 3*f;
349 defstride = 6*f;
350 break;
351 case GL_N3F_V3F:
352 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
353 tcomps = 0; ccomps = 0; vcomps = 3;
354 noffset = 0;
355 voffset = 3*f;
356 defstride = 6*f;
357 break;
358 case GL_C4F_N3F_V3F:
359 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
360 tcomps = 0; ccomps = 4; vcomps = 3;
361 ctype = GL_FLOAT;
362 coffset = 0;
363 noffset = 4*f;
364 voffset = 7*f;
365 defstride = 10*f;
366 break;
367 case GL_T2F_V3F:
368 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
369 tcomps = 2; ccomps = 0; vcomps = 3;
370 voffset = 2*f;
371 defstride = 5*f;
372 break;
373 case GL_T4F_V4F:
374 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
375 tcomps = 4; ccomps = 0; vcomps = 4;
376 voffset = 4*f;
377 defstride = 8*f;
378 break;
379 case GL_T2F_C4UB_V3F:
380 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
381 tcomps = 2; ccomps = 4; vcomps = 3;
382 ctype = GL_UNSIGNED_BYTE;
383 coffset = 2*f;
384 voffset = c+2*f;
385 defstride = c+5*f;
386 break;
387 case GL_T2F_C3F_V3F:
388 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
389 tcomps = 2; ccomps = 3; vcomps = 3;
390 ctype = GL_FLOAT;
391 coffset = 2*f;
392 voffset = 5*f;
393 defstride = 8*f;
394 break;
395 case GL_T2F_N3F_V3F:
396 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
397 tcomps = 2; ccomps = 0; vcomps = 3;
398 noffset = 2*f;
399 voffset = 5*f;
400 defstride = 8*f;
401 break;
402 case GL_T2F_C4F_N3F_V3F:
403 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
404 tcomps = 2; ccomps = 4; vcomps = 3;
405 ctype = GL_FLOAT;
406 coffset = 2*f;
407 noffset = 6*f;
408 voffset = 9*f;
409 defstride = 12*f;
410 break;
411 case GL_T4F_C4F_N3F_V4F:
412 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
413 tcomps = 4; ccomps = 4; vcomps = 4;
414 ctype = GL_FLOAT;
415 coffset = 4*f;
416 noffset = 8*f;
417 voffset = 11*f;
418 defstride = 15*f;
419 break;
420 default:
421 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
422 return;
423 }
424
425 if (stride==0) {
426 stride = defstride;
427 }
428
429 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
430 _mesa_DisableClientState( GL_INDEX_ARRAY );
431 /* XXX also disable secondary color and generic arrays? */
432
433 /* Texcoords */
434 if (tflag) {
435 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
436 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
437 (GLubyte *) pointer + toffset );
438 }
439 else {
440 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
441 }
442
443 /* Color */
444 if (cflag) {
445 _mesa_EnableClientState( GL_COLOR_ARRAY );
446 _mesa_ColorPointer( ccomps, ctype, stride,
447 (GLubyte *) pointer + coffset );
448 }
449 else {
450 _mesa_DisableClientState( GL_COLOR_ARRAY );
451 }
452
453
454 /* Normals */
455 if (nflag) {
456 _mesa_EnableClientState( GL_NORMAL_ARRAY );
457 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
458 }
459 else {
460 _mesa_DisableClientState( GL_NORMAL_ARRAY );
461 }
462
463 /* Vertices */
464 _mesa_EnableClientState( GL_VERTEX_ARRAY );
465 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
466 (GLubyte *) pointer + voffset );
467 }
468
469
470 void GLAPIENTRY
471 _mesa_LockArraysEXT(GLint first, GLsizei count)
472 {
473 GET_CURRENT_CONTEXT(ctx);
474 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
475
476 if (MESA_VERBOSE & VERBOSE_API)
477 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
478
479 if (first < 0) {
480 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
481 return;
482 }
483 if (count <= 0) {
484 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
485 return;
486 }
487 if (ctx->Array.LockCount != 0) {
488 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
489 return;
490 }
491
492 ctx->Array.LockFirst = first;
493 ctx->Array.LockCount = count;
494
495 ctx->NewState |= _NEW_ARRAY;
496 ctx->Array.NewState |= VERT_BIT_ALL;
497 }
498
499
500 void GLAPIENTRY
501 _mesa_UnlockArraysEXT( void )
502 {
503 GET_CURRENT_CONTEXT(ctx);
504 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
505
506 if (MESA_VERBOSE & VERBOSE_API)
507 _mesa_debug(ctx, "glUnlockArrays\n");
508
509 if (ctx->Array.LockCount == 0) {
510 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
511 return;
512 }
513
514 ctx->Array.LockFirst = 0;
515 ctx->Array.LockCount = 0;
516 ctx->NewState |= _NEW_ARRAY;
517 ctx->Array.NewState |= VERT_BIT_ALL;
518 }
519
520 /* GL_IBM_multimode_draw_arrays */
521 void GLAPIENTRY
522 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
523 const GLsizei * count,
524 GLsizei primcount, GLint modestride )
525 {
526 GET_CURRENT_CONTEXT(ctx);
527 GLint i;
528
529 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
530
531 for ( i = 0 ; i < primcount ; i++ ) {
532 if ( count[i] > 0 ) {
533 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
534 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
535 }
536 }
537 }
538
539
540 /* GL_IBM_multimode_draw_arrays */
541 void GLAPIENTRY
542 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
543 GLenum type, const GLvoid * const * indices,
544 GLsizei primcount, GLint modestride )
545 {
546 GET_CURRENT_CONTEXT(ctx);
547 GLint i;
548
549 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
550
551 /* XXX not sure about ARB_vertex_buffer_object handling here */
552
553 for ( i = 0 ; i < primcount ; i++ ) {
554 if ( count[i] > 0 ) {
555 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
556 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
557 }
558 }
559 }
560
561
562 /**
563 * Copy one client vertex array to another.
564 */
565 void
566 _mesa_copy_client_array(struct gl_context *ctx,
567 struct gl_client_array *dst,
568 struct gl_client_array *src)
569 {
570 dst->Size = src->Size;
571 dst->Type = src->Type;
572 dst->Stride = src->Stride;
573 dst->StrideB = src->StrideB;
574 dst->Ptr = src->Ptr;
575 dst->Enabled = src->Enabled;
576 dst->Normalized = src->Normalized;
577 dst->Integer = src->Integer;
578 dst->_ElementSize = src->_ElementSize;
579 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
580 dst->_MaxElement = src->_MaxElement;
581 }
582
583 static void
584 init_array(struct gl_context *ctx,
585 struct gl_client_array *array, GLint size, GLint type)
586 {
587 array->Size = size;
588 array->Type = type;
589 array->Stride = 0;
590 array->StrideB = 0;
591 array->Ptr = NULL;
592 array->Enabled = GL_FALSE;
593 array->Normalized = GL_FALSE;
594 array->Integer = GL_FALSE;
595 array->_ElementSize = size * _mesa_sizeof_type(type);
596 /* Vertex array buffers */
597 _mesa_reference_buffer_object(ctx, &array->BufferObj,
598 ctx->Shared->NullBufferObj);
599 }
600
601
602 /**
603 * Initialize vertex array state for given context.
604 */
605 void
606 _mesa_init_varray(struct gl_context *ctx, struct gl_array_attrib *array)
607 {
608 GLuint i;
609
610 /* Init the individual arrays */
611 for (i = 0; i < Elements(array->VertexAttrib); i++) {
612 switch (i) {
613 case VERT_ATTRIB_WEIGHT:
614 init_array(ctx, &array->VertexAttrib[VERT_ATTRIB_WEIGHT], 1, GL_FLOAT);
615 break;
616 case VERT_ATTRIB_NORMAL:
617 init_array(ctx, &array->VertexAttrib[VERT_ATTRIB_NORMAL], 3, GL_FLOAT);
618 break;
619 case VERT_ATTRIB_FOG:
620 init_array(ctx, &array->VertexAttrib[VERT_ATTRIB_FOG], 1, GL_FLOAT);
621 break;
622 case VERT_ATTRIB_COLOR_INDEX:
623 init_array(ctx, &array->VertexAttrib[VERT_ATTRIB_COLOR_INDEX], 1, GL_FLOAT);
624 break;
625 case VERT_ATTRIB_EDGEFLAG:
626 init_array(ctx, &array->VertexAttrib[VERT_ATTRIB_EDGEFLAG], 1, GL_BOOL);
627 break;
628 default:
629 init_array(ctx, &array->VertexAttrib[i], 4, GL_FLOAT);
630 break;
631 }
632 }
633 }
634
635
636 /**
637 * Free vertex array state for given context.
638 */
639 void
640 _mesa_free_varray_data(struct gl_context *ctx, struct gl_array_attrib* array)
641 {
642 GLuint i;
643
644 /* Uninit the individual arrays */
645 for (i = 0; i < Elements(array->VertexAttrib); i++)
646 {
647 _mesa_reference_buffer_object(ctx, &array->VertexAttrib[i].BufferObj, NULL);
648 memset(&array->VertexAttrib[i], 0, sizeof(struct gl_client_array));
649 }
650 }