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