a8b2b395c1709bccbccb945960f5c31e5c6a3230
[reactos.git] / reactos / 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_HALF_FLOAT:
63 if (ctx->Extensions.ARB_half_float_vertex)
64 return HALF_BIT;
65 else
66 return 0x0;
67 case GL_FLOAT:
68 return FLOAT_BIT;
69 case GL_DOUBLE:
70 return DOUBLE_BIT;
71 default:
72 return 0;
73 }
74 }
75
76
77 /**
78 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
79 * functions.
80 *
81 * \param func name of calling function used for error reporting
82 * \param attrib the attribute array index to update
83 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
84 * \param sizeMin min allowable size value
85 * \param sizeMax max allowable size value
86 * \param size components per element (1, 2, 3 or 4)
87 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
88 * \param stride stride between elements, in elements
89 * \param normalized are integer types converted to floats in [-1, 1]?
90 * \param integer integer-valued values (will not be normalized to [-1,1])
91 * \param ptr the address (or offset inside VBO) of the array data
92 */
93 static void
94 update_array(struct gl_context *ctx,
95 const char *func,
96 GLuint attrib, GLbitfield legalTypesMask,
97 GLint sizeMin, GLint sizeMax,
98 GLint size, GLenum type, GLsizei stride,
99 GLboolean normalized, GLboolean integer,
100 const GLvoid *ptr)
101 {
102 struct gl_client_array *array;
103 GLbitfield typeBit;
104 GLsizei elementSize;
105
106 typeBit = type_to_bit(ctx, type);
107 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
108 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
109 func, _mesa_lookup_enum_by_nr(type));
110 return;
111 }
112
113 /* Do size parameter checking. */
114 if (size < sizeMin || size > sizeMax || size > 4) {
115 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
116 return;
117 }
118
119 ASSERT(size <= 4);
120
121 if (stride < 0) {
122 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
123 return;
124 }
125
126 if (ctx->Array.ArrayObj->ARBsemantics &&
127 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
128 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
129 * Generate GL_INVALID_OPERATION if that's not true.
130 */
131 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
132 return;
133 }
134
135 elementSize = _mesa_sizeof_type(type) * size;
136
137 array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
138 array->Size = size;
139 array->Type = type;
140 array->Stride = stride;
141 array->StrideB = stride ? stride : elementSize;
142 array->Normalized = normalized;
143 array->Integer = integer;
144 array->Ptr = (const GLubyte *) ptr;
145 array->_ElementSize = elementSize;
146
147 _mesa_reference_buffer_object(ctx, &array->BufferObj,
148 ctx->Array.ArrayBufferObj);
149
150 ctx->NewState |= _NEW_ARRAY;
151 ctx->Array.NewState |= VERT_BIT(attrib);
152 }
153
154
155 void GLAPIENTRY
156 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
157 {
158 GLbitfield legalTypes = (SHORT_BIT | INT_BIT | FLOAT_BIT |
159 DOUBLE_BIT | HALF_BIT);
160 GET_CURRENT_CONTEXT(ctx);
161 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
162
163 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
164 legalTypes, 2, 4,
165 size, type, stride, GL_FALSE, GL_FALSE, ptr);
166 }
167
168
169 void GLAPIENTRY
170 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
171 {
172 const GLbitfield legalTypes = (BYTE_BIT | SHORT_BIT | INT_BIT |
173 HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
174 GET_CURRENT_CONTEXT(ctx);
175 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
176
177 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
178 legalTypes, 3, 3,
179 3, type, stride, GL_TRUE, GL_FALSE, ptr);
180 }
181
182
183 void GLAPIENTRY
184 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
185 {
186 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
187 SHORT_BIT | UNSIGNED_SHORT_BIT |
188 INT_BIT | UNSIGNED_INT_BIT |
189 HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
190 GET_CURRENT_CONTEXT(ctx);
191 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
192
193 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
194 legalTypes, 3, 4,
195 size, type, stride, GL_TRUE, GL_FALSE, ptr);
196 }
197
198
199 void GLAPIENTRY
200 _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
201 {
202 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
203 GET_CURRENT_CONTEXT(ctx);
204 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
205
206 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
207 legalTypes, 1, 1,
208 1, type, stride, GL_FALSE, GL_FALSE, ptr);
209 }
210
211
212 void GLAPIENTRY
213 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
214 {
215 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
216 FLOAT_BIT | DOUBLE_BIT);
217 GET_CURRENT_CONTEXT(ctx);
218 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
219
220 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
221 legalTypes, 1, 1,
222 1, type, stride, GL_FALSE, GL_FALSE, ptr);
223 }
224
225
226 void GLAPIENTRY
227 _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
228 GLsizei stride, const GLvoid *ptr)
229 {
230 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
231 SHORT_BIT | UNSIGNED_SHORT_BIT |
232 INT_BIT | UNSIGNED_INT_BIT |
233 HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
234 GET_CURRENT_CONTEXT(ctx);
235 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
236
237 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
238 legalTypes, 3, 4,
239 size, type, stride, GL_TRUE, GL_FALSE, ptr);
240 }
241
242
243 void GLAPIENTRY
244 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
245 const GLvoid *ptr)
246 {
247 GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
248 HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
249 GET_CURRENT_CONTEXT(ctx);
250 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
251
252 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX,
253 legalTypes, 1, 4,
254 size, type, stride, GL_FALSE, GL_FALSE,
255 ptr);
256 }
257
258
259 void GLAPIENTRY
260 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
261 {
262 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
263 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
264 const GLboolean integer = GL_TRUE;
265 GET_CURRENT_CONTEXT(ctx);
266 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
267
268 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
269 legalTypes, 1, 1,
270 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
271 }
272
273 void GLAPIENTRY
274 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
275 GLsizei count, const GLvoid *ptr)
276 {
277 (void) count;
278 _mesa_VertexPointer(size, type, stride, ptr);
279 }
280
281
282 void GLAPIENTRY
283 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
284 const GLvoid *ptr)
285 {
286 (void) count;
287 _mesa_NormalPointer(type, stride, ptr);
288 }
289
290
291 void GLAPIENTRY
292 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
293 const GLvoid *ptr)
294 {
295 (void) count;
296 _mesa_ColorPointer(size, type, stride, ptr);
297 }
298
299
300 void GLAPIENTRY
301 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
302 const GLvoid *ptr)
303 {
304 (void) count;
305 _mesa_IndexPointer(type, stride, ptr);
306 }
307
308
309 void GLAPIENTRY
310 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
311 GLsizei count, const GLvoid *ptr)
312 {
313 (void) count;
314 _mesa_TexCoordPointer(size, type, stride, ptr);
315 }
316
317
318 void GLAPIENTRY
319 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
320 {
321 (void) count;
322 _mesa_EdgeFlagPointer(stride, ptr);
323 }
324
325
326 void GLAPIENTRY
327 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
328 {
329 GET_CURRENT_CONTEXT(ctx);
330 GLboolean tflag, cflag, nflag; /* enable/disable flags */
331 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
332 GLenum ctype = 0; /* color type */
333 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
334 const GLint toffset = 0; /* always zero */
335 GLint defstride; /* default stride */
336 GLint c, f;
337
338 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
339
340 f = sizeof(GLfloat);
341 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
342
343 if (stride < 0) {
344 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
345 return;
346 }
347
348 switch (format) {
349 case GL_V2F:
350 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
351 tcomps = 0; ccomps = 0; vcomps = 2;
352 voffset = 0;
353 defstride = 2*f;
354 break;
355 case GL_V3F:
356 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
357 tcomps = 0; ccomps = 0; vcomps = 3;
358 voffset = 0;
359 defstride = 3*f;
360 break;
361 case GL_C4UB_V2F:
362 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
363 tcomps = 0; ccomps = 4; vcomps = 2;
364 ctype = GL_UNSIGNED_BYTE;
365 coffset = 0;
366 voffset = c;
367 defstride = c + 2*f;
368 break;
369 case GL_C4UB_V3F:
370 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
371 tcomps = 0; ccomps = 4; vcomps = 3;
372 ctype = GL_UNSIGNED_BYTE;
373 coffset = 0;
374 voffset = c;
375 defstride = c + 3*f;
376 break;
377 case GL_C3F_V3F:
378 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
379 tcomps = 0; ccomps = 3; vcomps = 3;
380 ctype = GL_FLOAT;
381 coffset = 0;
382 voffset = 3*f;
383 defstride = 6*f;
384 break;
385 case GL_N3F_V3F:
386 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
387 tcomps = 0; ccomps = 0; vcomps = 3;
388 noffset = 0;
389 voffset = 3*f;
390 defstride = 6*f;
391 break;
392 case GL_C4F_N3F_V3F:
393 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
394 tcomps = 0; ccomps = 4; vcomps = 3;
395 ctype = GL_FLOAT;
396 coffset = 0;
397 noffset = 4*f;
398 voffset = 7*f;
399 defstride = 10*f;
400 break;
401 case GL_T2F_V3F:
402 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
403 tcomps = 2; ccomps = 0; vcomps = 3;
404 voffset = 2*f;
405 defstride = 5*f;
406 break;
407 case GL_T4F_V4F:
408 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
409 tcomps = 4; ccomps = 0; vcomps = 4;
410 voffset = 4*f;
411 defstride = 8*f;
412 break;
413 case GL_T2F_C4UB_V3F:
414 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
415 tcomps = 2; ccomps = 4; vcomps = 3;
416 ctype = GL_UNSIGNED_BYTE;
417 coffset = 2*f;
418 voffset = c+2*f;
419 defstride = c+5*f;
420 break;
421 case GL_T2F_C3F_V3F:
422 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
423 tcomps = 2; ccomps = 3; vcomps = 3;
424 ctype = GL_FLOAT;
425 coffset = 2*f;
426 voffset = 5*f;
427 defstride = 8*f;
428 break;
429 case GL_T2F_N3F_V3F:
430 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
431 tcomps = 2; ccomps = 0; vcomps = 3;
432 noffset = 2*f;
433 voffset = 5*f;
434 defstride = 8*f;
435 break;
436 case GL_T2F_C4F_N3F_V3F:
437 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
438 tcomps = 2; ccomps = 4; vcomps = 3;
439 ctype = GL_FLOAT;
440 coffset = 2*f;
441 noffset = 6*f;
442 voffset = 9*f;
443 defstride = 12*f;
444 break;
445 case GL_T4F_C4F_N3F_V4F:
446 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
447 tcomps = 4; ccomps = 4; vcomps = 4;
448 ctype = GL_FLOAT;
449 coffset = 4*f;
450 noffset = 8*f;
451 voffset = 11*f;
452 defstride = 15*f;
453 break;
454 default:
455 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
456 return;
457 }
458
459 if (stride==0) {
460 stride = defstride;
461 }
462
463 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
464 _mesa_DisableClientState( GL_INDEX_ARRAY );
465 /* XXX also disable secondary color and generic arrays? */
466
467 /* Texcoords */
468 if (tflag) {
469 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
470 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
471 (GLubyte *) pointer + toffset );
472 }
473 else {
474 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
475 }
476
477 /* Color */
478 if (cflag) {
479 _mesa_EnableClientState( GL_COLOR_ARRAY );
480 _mesa_ColorPointer( ccomps, ctype, stride,
481 (GLubyte *) pointer + coffset );
482 }
483 else {
484 _mesa_DisableClientState( GL_COLOR_ARRAY );
485 }
486
487
488 /* Normals */
489 if (nflag) {
490 _mesa_EnableClientState( GL_NORMAL_ARRAY );
491 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
492 }
493 else {
494 _mesa_DisableClientState( GL_NORMAL_ARRAY );
495 }
496
497 /* Vertices */
498 _mesa_EnableClientState( GL_VERTEX_ARRAY );
499 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
500 (GLubyte *) pointer + voffset );
501 }
502
503
504 void GLAPIENTRY
505 _mesa_LockArraysEXT(GLint first, GLsizei count)
506 {
507 GET_CURRENT_CONTEXT(ctx);
508 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
509
510 if (MESA_VERBOSE & VERBOSE_API)
511 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
512
513 if (first < 0) {
514 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
515 return;
516 }
517 if (count <= 0) {
518 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
519 return;
520 }
521 if (ctx->Array.LockCount != 0) {
522 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
523 return;
524 }
525
526 ctx->Array.LockFirst = first;
527 ctx->Array.LockCount = count;
528
529 ctx->NewState |= _NEW_ARRAY;
530 ctx->Array.NewState |= VERT_BIT_ALL;
531 }
532
533
534 void GLAPIENTRY
535 _mesa_UnlockArraysEXT( void )
536 {
537 GET_CURRENT_CONTEXT(ctx);
538 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
539
540 if (MESA_VERBOSE & VERBOSE_API)
541 _mesa_debug(ctx, "glUnlockArrays\n");
542
543 if (ctx->Array.LockCount == 0) {
544 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
545 return;
546 }
547
548 ctx->Array.LockFirst = 0;
549 ctx->Array.LockCount = 0;
550 ctx->NewState |= _NEW_ARRAY;
551 ctx->Array.NewState |= VERT_BIT_ALL;
552 }
553
554 /* GL_IBM_multimode_draw_arrays */
555 void GLAPIENTRY
556 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
557 const GLsizei * count,
558 GLsizei primcount, GLint modestride )
559 {
560 GET_CURRENT_CONTEXT(ctx);
561 GLint i;
562
563 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
564
565 for ( i = 0 ; i < primcount ; i++ ) {
566 if ( count[i] > 0 ) {
567 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
568 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
569 }
570 }
571 }
572
573
574 /* GL_IBM_multimode_draw_arrays */
575 void GLAPIENTRY
576 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
577 GLenum type, const GLvoid * const * indices,
578 GLsizei primcount, GLint modestride )
579 {
580 GET_CURRENT_CONTEXT(ctx);
581 GLint i;
582
583 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
584
585 /* XXX not sure about ARB_vertex_buffer_object handling here */
586
587 for ( i = 0 ; i < primcount ; i++ ) {
588 if ( count[i] > 0 ) {
589 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
590 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
591 }
592 }
593 }
594
595
596 /**
597 * Copy one client vertex array to another.
598 */
599 void
600 _mesa_copy_client_array(struct gl_context *ctx,
601 struct gl_client_array *dst,
602 struct gl_client_array *src)
603 {
604 dst->Size = src->Size;
605 dst->Type = src->Type;
606 dst->Stride = src->Stride;
607 dst->StrideB = src->StrideB;
608 dst->Ptr = src->Ptr;
609 dst->Enabled = src->Enabled;
610 dst->Normalized = src->Normalized;
611 dst->Integer = src->Integer;
612 dst->_ElementSize = src->_ElementSize;
613 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
614 dst->_MaxElement = src->_MaxElement;
615 }
616
617
618
619 /**
620 * Print vertex array's fields.
621 */
622 static void
623 print_array(const char *name, GLint index, const struct gl_client_array *array)
624 {
625 if (index >= 0)
626 printf(" %s[%d]: ", name, index);
627 else
628 printf(" %s: ", name);
629 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
630 array->Ptr, array->Type, array->Size,
631 array->_ElementSize, array->StrideB,
632 array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
633 array->_MaxElement);
634 }
635
636
637 /**
638 * Print current vertex object/array info. For debug.
639 */
640 void
641 _mesa_print_arrays(struct gl_context *ctx)
642 {
643 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
644
645 _mesa_update_array_object_max_element(ctx, arrayObj);
646
647 printf("Array Object %u\n", arrayObj->Name);
648 if (arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled)
649 print_array("Vertex", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_POS]);
650 if (arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
651 print_array("Normal", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]);
652 if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
653 print_array("Color", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]);
654 if (arrayObj->VertexAttrib[VERT_ATTRIB_TEX].Enabled)
655 print_array("TexCoord", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_TEX]);
656 printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
657 }
658
659
660 /**
661 * Initialize vertex array state for given context.
662 */
663 void
664 _mesa_init_varray(struct gl_context *ctx)
665 {
666 ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
667 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
668 ctx->Array.DefaultArrayObj);
669
670 ctx->Array.Objects = _mesa_NewHashTable();
671 }
672
673
674 /**
675 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
676 */
677 static void
678 delete_arrayobj_cb(GLuint id, void *data, void *userData)
679 {
680 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
681 struct gl_context *ctx = (struct gl_context *) userData;
682 _mesa_delete_array_object(ctx, arrayObj);
683 }
684
685
686 /**
687 * Free vertex array state for given context.
688 */
689 void
690 _mesa_free_varray_data(struct gl_context *ctx)
691 {
692 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
693 _mesa_DeleteHashTable(ctx->Array.Objects);
694 }