da88eae08238575f255514307cf2cc64f3006daa
[mesa.git] / src / 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
27 #include "glheader.h"
28 #include "imports.h"
29 #include "bufferobj.h"
30 #include "context.h"
31 #include "enable.h"
32 #include "enums.h"
33 #include "hash.h"
34 #include "image.h"
35 #include "macros.h"
36 #include "mfeatures.h"
37 #include "mtypes.h"
38 #include "varray.h"
39 #include "arrayobj.h"
40 #include "main/dispatch.h"
41
42
43 /** Used to do error checking for GL_EXT_vertex_array_bgra */
44 #define BGRA_OR_4 5
45
46
47 /** Used to indicate which GL datatypes are accepted by each of the
48 * glVertex/Color/Attrib/EtcPointer() functions.
49 */
50 #define BOOL_BIT 0x1
51 #define BYTE_BIT 0x2
52 #define UNSIGNED_BYTE_BIT 0x4
53 #define SHORT_BIT 0x8
54 #define UNSIGNED_SHORT_BIT 0x10
55 #define INT_BIT 0x20
56 #define UNSIGNED_INT_BIT 0x40
57 #define HALF_BIT 0x80
58 #define FLOAT_BIT 0x100
59 #define DOUBLE_BIT 0x200
60 #define FIXED_ES_BIT 0x400
61 #define FIXED_GL_BIT 0x800
62 #define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000
63 #define INT_2_10_10_10_REV_BIT 0x2000
64
65
66 /** Convert GL datatype enum into a <type>_BIT value seen above */
67 static GLbitfield
68 type_to_bit(const struct gl_context *ctx, GLenum type)
69 {
70 switch (type) {
71 case GL_BOOL:
72 return BOOL_BIT;
73 case GL_BYTE:
74 return BYTE_BIT;
75 case GL_UNSIGNED_BYTE:
76 return UNSIGNED_BYTE_BIT;
77 case GL_SHORT:
78 return SHORT_BIT;
79 case GL_UNSIGNED_SHORT:
80 return UNSIGNED_SHORT_BIT;
81 case GL_INT:
82 return INT_BIT;
83 case GL_UNSIGNED_INT:
84 return UNSIGNED_INT_BIT;
85 case GL_HALF_FLOAT:
86 if (ctx->Extensions.ARB_half_float_vertex)
87 return HALF_BIT;
88 else
89 return 0x0;
90 case GL_FLOAT:
91 return FLOAT_BIT;
92 case GL_DOUBLE:
93 return DOUBLE_BIT;
94 case GL_FIXED:
95 return ctx->API == API_OPENGL ? FIXED_GL_BIT : FIXED_ES_BIT;
96 case GL_UNSIGNED_INT_2_10_10_10_REV:
97 return UNSIGNED_INT_2_10_10_10_REV_BIT;
98 case GL_INT_2_10_10_10_REV:
99 return INT_2_10_10_10_REV_BIT;
100 default:
101 return 0;
102 }
103 }
104
105
106 /**
107 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
108 * functions.
109 *
110 * \param func name of calling function used for error reporting
111 * \param array the array to update
112 * \param dirtyBit which bit to set in ctx->Array.NewState for this array
113 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
114 * \param sizeMin min allowable size value
115 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
116 * \param size components per element (1, 2, 3 or 4)
117 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
118 * \param stride stride between elements, in elements
119 * \param normalized are integer types converted to floats in [-1, 1]?
120 * \param integer integer-valued values (will not be normalized to [-1,1])
121 * \param ptr the address (or offset inside VBO) of the array data
122 */
123 static void
124 update_array(struct gl_context *ctx,
125 const char *func,
126 struct gl_client_array *array,
127 GLbitfield64 dirtyBit, GLbitfield legalTypesMask,
128 GLint sizeMin, GLint sizeMax,
129 GLint size, GLenum type, GLsizei stride,
130 GLboolean normalized, GLboolean integer,
131 const GLvoid *ptr)
132 {
133 GLbitfield typeBit;
134 GLsizei elementSize;
135 GLenum format = GL_RGBA;
136
137 if (ctx->API != API_OPENGLES && ctx->API != API_OPENGLES2) {
138 /* fixed point arrays / data is only allowed with OpenGL ES 1.x/2.0 */
139 legalTypesMask &= ~FIXED_ES_BIT;
140 }
141 if (!ctx->Extensions.ARB_ES2_compatibility) {
142 legalTypesMask &= ~FIXED_GL_BIT;
143 }
144 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
145 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
146 INT_2_10_10_10_REV_BIT);
147 }
148
149 typeBit = type_to_bit(ctx, type);
150 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
151 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
152 func, _mesa_lookup_enum_by_nr(type));
153 return;
154 }
155
156 /* Do size parameter checking.
157 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
158 * must be handled specially.
159 */
160 if (ctx->Extensions.EXT_vertex_array_bgra &&
161 sizeMax == BGRA_OR_4 &&
162 size == GL_BGRA) {
163 GLboolean bgra_error = GL_FALSE;
164
165 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
166 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
167 type != GL_INT_2_10_10_10_REV &&
168 type != GL_UNSIGNED_BYTE)
169 bgra_error = GL_TRUE;
170 } else if (type != GL_UNSIGNED_BYTE)
171 bgra_error = GL_TRUE;
172
173 if (bgra_error) {
174 _mesa_error(ctx, GL_INVALID_VALUE, "%s(GL_BGRA/GLubyte)", func);
175 return;
176 }
177 format = GL_BGRA;
178 size = 4;
179 }
180 else if (size < sizeMin || size > sizeMax || size > 4) {
181 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
182 return;
183 }
184
185 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
186 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
187 type == GL_INT_2_10_10_10_REV) && size != 4) {
188 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
189 }
190
191 ASSERT(size <= 4);
192
193 if (stride < 0) {
194 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
195 return;
196 }
197
198 if (ctx->Array.ArrayObj->VBOonly &&
199 ctx->Array.ArrayBufferObj->Name == 0) {
200 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs.
201 * Generate GL_INVALID_OPERATION if that's not true.
202 */
203 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
204 return;
205 }
206
207 elementSize = _mesa_sizeof_type(type) * size;
208
209 array->Size = size;
210 array->Type = type;
211 array->Format = format;
212 array->Stride = stride;
213 array->StrideB = stride ? stride : elementSize;
214 array->Normalized = normalized;
215 array->Integer = integer;
216 array->Ptr = (const GLubyte *) ptr;
217 array->_ElementSize = elementSize;
218
219 _mesa_reference_buffer_object(ctx, &array->BufferObj,
220 ctx->Array.ArrayBufferObj);
221
222 ctx->NewState |= _NEW_ARRAY;
223 ctx->Array.NewState |= dirtyBit;
224 }
225
226
227 void GLAPIENTRY
228 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
229 {
230 GLbitfield legalTypes = (SHORT_BIT | INT_BIT | FLOAT_BIT |
231 DOUBLE_BIT | HALF_BIT | FIXED_ES_BIT |
232 UNSIGNED_INT_2_10_10_10_REV_BIT |
233 INT_2_10_10_10_REV_BIT);
234 GET_CURRENT_CONTEXT(ctx);
235 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
236
237 if (ctx->API == API_OPENGLES)
238 legalTypes |= BYTE_BIT;
239
240 update_array(ctx, "glVertexPointer",
241 &ctx->Array.ArrayObj->Vertex, VERT_BIT_POS,
242 legalTypes, 2, 4,
243 size, type, stride, GL_FALSE, GL_FALSE, ptr);
244 }
245
246
247 void GLAPIENTRY
248 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
249 {
250 const GLbitfield legalTypes = (BYTE_BIT | SHORT_BIT | INT_BIT |
251 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
252 FIXED_ES_BIT |
253 UNSIGNED_INT_2_10_10_10_REV_BIT |
254 INT_2_10_10_10_REV_BIT);
255 GET_CURRENT_CONTEXT(ctx);
256 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
257
258 update_array(ctx, "glNormalPointer",
259 &ctx->Array.ArrayObj->Normal, VERT_BIT_NORMAL,
260 legalTypes, 3, 3,
261 3, type, stride, GL_TRUE, GL_FALSE, ptr);
262 }
263
264
265 void GLAPIENTRY
266 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
267 {
268 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
269 SHORT_BIT | UNSIGNED_SHORT_BIT |
270 INT_BIT | UNSIGNED_INT_BIT |
271 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
272 FIXED_ES_BIT |
273 UNSIGNED_INT_2_10_10_10_REV_BIT |
274 INT_2_10_10_10_REV_BIT);
275 GET_CURRENT_CONTEXT(ctx);
276 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
277
278 update_array(ctx, "glColorPointer",
279 &ctx->Array.ArrayObj->Color, VERT_BIT_COLOR0,
280 legalTypes, 3, BGRA_OR_4,
281 size, type, stride, GL_TRUE, GL_FALSE, ptr);
282 }
283
284
285 void GLAPIENTRY
286 _mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr)
287 {
288 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
289 GET_CURRENT_CONTEXT(ctx);
290 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
291
292 update_array(ctx, "glFogCoordPointer",
293 &ctx->Array.ArrayObj->FogCoord, VERT_BIT_FOG,
294 legalTypes, 1, 1,
295 1, type, stride, GL_FALSE, GL_FALSE, ptr);
296 }
297
298
299 void GLAPIENTRY
300 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
301 {
302 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
303 FLOAT_BIT | DOUBLE_BIT);
304 GET_CURRENT_CONTEXT(ctx);
305 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
306
307 update_array(ctx, "glIndexPointer",
308 &ctx->Array.ArrayObj->Index, VERT_BIT_COLOR_INDEX,
309 legalTypes, 1, 1,
310 1, type, stride, GL_FALSE, GL_FALSE, ptr);
311 }
312
313
314 void GLAPIENTRY
315 _mesa_SecondaryColorPointerEXT(GLint size, GLenum type,
316 GLsizei stride, const GLvoid *ptr)
317 {
318 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
319 SHORT_BIT | UNSIGNED_SHORT_BIT |
320 INT_BIT | UNSIGNED_INT_BIT |
321 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
322 UNSIGNED_INT_2_10_10_10_REV_BIT |
323 INT_2_10_10_10_REV_BIT);
324 GET_CURRENT_CONTEXT(ctx);
325 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
326
327 update_array(ctx, "glSecondaryColorPointer",
328 &ctx->Array.ArrayObj->SecondaryColor, VERT_BIT_COLOR1,
329 legalTypes, 3, BGRA_OR_4,
330 size, type, stride, GL_TRUE, GL_FALSE, ptr);
331 }
332
333
334 void GLAPIENTRY
335 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
336 const GLvoid *ptr)
337 {
338 GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
339 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
340 FIXED_ES_BIT |
341 UNSIGNED_INT_2_10_10_10_REV_BIT |
342 INT_2_10_10_10_REV_BIT);
343 GET_CURRENT_CONTEXT(ctx);
344 const GLuint unit = ctx->Array.ActiveTexture;
345 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
346
347 if (ctx->API == API_OPENGLES)
348 legalTypes |= BYTE_BIT;
349
350 ASSERT(unit < Elements(ctx->Array.ArrayObj->TexCoord));
351
352 update_array(ctx, "glTexCoordPointer",
353 &ctx->Array.ArrayObj->TexCoord[unit],
354 VERT_BIT_TEX(unit),
355 legalTypes, 1, 4,
356 size, type, stride, GL_FALSE, GL_FALSE,
357 ptr);
358 }
359
360
361 void GLAPIENTRY
362 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
363 {
364 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
365 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */
366 const GLboolean integer = GL_TRUE;
367 GET_CURRENT_CONTEXT(ctx);
368 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
369
370 update_array(ctx, "glEdgeFlagPointer",
371 &ctx->Array.ArrayObj->EdgeFlag, VERT_BIT_EDGEFLAG,
372 legalTypes, 1, 1,
373 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
374 }
375
376
377 void GLAPIENTRY
378 _mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr)
379 {
380 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
381 GET_CURRENT_CONTEXT(ctx);
382 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
383
384 if (ctx->API != API_OPENGLES) {
385 _mesa_error(ctx, GL_INVALID_OPERATION,
386 "glPointSizePointer(ES 1.x only)");
387 return;
388 }
389
390 update_array(ctx, "glPointSizePointer",
391 &ctx->Array.ArrayObj->PointSize, VERT_BIT_POINT_SIZE,
392 legalTypes, 1, 1,
393 1, type, stride, GL_FALSE, GL_FALSE, ptr);
394 }
395
396
397 #if FEATURE_NV_vertex_program
398 /**
399 * Set a vertex attribute array.
400 * Note that these arrays DO alias the conventional GL vertex arrays
401 * (position, normal, color, fog, texcoord, etc).
402 * The generic attribute slots at #16 and above are not touched.
403 */
404 void GLAPIENTRY
405 _mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type,
406 GLsizei stride, const GLvoid *ptr)
407 {
408 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT |
409 FLOAT_BIT | DOUBLE_BIT);
410 GLboolean normalized = GL_FALSE;
411 GET_CURRENT_CONTEXT(ctx);
412 ASSERT_OUTSIDE_BEGIN_END(ctx);
413
414 if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
415 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)");
416 return;
417 }
418
419 if (type == GL_UNSIGNED_BYTE && size != 4) {
420 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)");
421 return;
422 }
423
424 update_array(ctx, "glVertexAttribPointerNV",
425 &ctx->Array.ArrayObj->VertexAttrib[index],
426 VERT_BIT_GENERIC(index),
427 legalTypes, 1, BGRA_OR_4,
428 size, type, stride, normalized, GL_FALSE, ptr);
429 }
430 #endif
431
432
433 #if FEATURE_ARB_vertex_program
434 /**
435 * Set a generic vertex attribute array.
436 * Note that these arrays DO NOT alias the conventional GL vertex arrays
437 * (position, normal, color, fog, texcoord, etc).
438 */
439 void GLAPIENTRY
440 _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
441 GLboolean normalized,
442 GLsizei stride, const GLvoid *ptr)
443 {
444 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
445 SHORT_BIT | UNSIGNED_SHORT_BIT |
446 INT_BIT | UNSIGNED_INT_BIT |
447 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
448 FIXED_ES_BIT | FIXED_GL_BIT |
449 UNSIGNED_INT_2_10_10_10_REV_BIT |
450 INT_2_10_10_10_REV_BIT);
451 GET_CURRENT_CONTEXT(ctx);
452 ASSERT_OUTSIDE_BEGIN_END(ctx);
453
454 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
455 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
456 return;
457 }
458
459 update_array(ctx, "glVertexAttribPointer",
460 &ctx->Array.ArrayObj->VertexAttrib[index],
461 VERT_BIT_GENERIC(index),
462 legalTypes, 1, BGRA_OR_4,
463 size, type, stride, normalized, GL_FALSE, ptr);
464 }
465 #endif
466
467
468 /**
469 * GL_EXT_gpu_shader4 / GL 3.0.
470 * Set an integer-valued vertex attribute array.
471 * Note that these arrays DO NOT alias the conventional GL vertex arrays
472 * (position, normal, color, fog, texcoord, etc).
473 */
474 void GLAPIENTRY
475 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
476 GLsizei stride, const GLvoid *ptr)
477 {
478 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
479 SHORT_BIT | UNSIGNED_SHORT_BIT |
480 INT_BIT | UNSIGNED_INT_BIT);
481 const GLboolean normalized = GL_FALSE;
482 const GLboolean integer = GL_TRUE;
483 GET_CURRENT_CONTEXT(ctx);
484 ASSERT_OUTSIDE_BEGIN_END(ctx);
485
486 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
487 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
488 return;
489 }
490
491 update_array(ctx, "glVertexAttribIPointer",
492 &ctx->Array.ArrayObj->VertexAttrib[index],
493 VERT_BIT_GENERIC(index),
494 legalTypes, 1, 4,
495 size, type, stride, normalized, integer, ptr);
496 }
497
498
499
500 void GLAPIENTRY
501 _mesa_EnableVertexAttribArrayARB(GLuint index)
502 {
503 GET_CURRENT_CONTEXT(ctx);
504 ASSERT_OUTSIDE_BEGIN_END(ctx);
505
506 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
507 _mesa_error(ctx, GL_INVALID_VALUE,
508 "glEnableVertexAttribArrayARB(index)");
509 return;
510 }
511
512 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
513
514 FLUSH_VERTICES(ctx, _NEW_ARRAY);
515 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
516 ctx->Array.ArrayObj->_Enabled |= VERT_BIT_GENERIC(index);
517 ctx->Array.NewState |= VERT_BIT_GENERIC(index);
518 }
519
520
521 void GLAPIENTRY
522 _mesa_DisableVertexAttribArrayARB(GLuint index)
523 {
524 GET_CURRENT_CONTEXT(ctx);
525 ASSERT_OUTSIDE_BEGIN_END(ctx);
526
527 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
528 _mesa_error(ctx, GL_INVALID_VALUE,
529 "glDisableVertexAttribArrayARB(index)");
530 return;
531 }
532
533 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
534
535 FLUSH_VERTICES(ctx, _NEW_ARRAY);
536 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
537 ctx->Array.ArrayObj->_Enabled &= ~VERT_BIT_GENERIC(index);
538 ctx->Array.NewState |= VERT_BIT_GENERIC(index);
539 }
540
541
542 /**
543 * Return info for a vertex attribute array (no alias with legacy
544 * vertex attributes (pos, normal, color, etc)). This function does
545 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
546 */
547 static GLuint
548 get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
549 const char *caller)
550 {
551 const struct gl_client_array *array;
552
553 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
554 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
555 return 0;
556 }
557
558 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
559
560 array = &ctx->Array.ArrayObj->VertexAttrib[index];
561
562 switch (pname) {
563 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
564 return array->Enabled;
565 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
566 return array->Size;
567 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
568 return array->Stride;
569 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
570 return array->Type;
571 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
572 return array->Normalized;
573 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
574 return array->BufferObj->Name;
575 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
576 if (ctx->Extensions.EXT_gpu_shader4) {
577 return array->Integer;
578 }
579 goto error;
580 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
581 if (ctx->Extensions.ARB_instanced_arrays) {
582 return array->InstanceDivisor;
583 }
584 goto error;
585 default:
586 ; /* fall-through */
587 }
588
589 error:
590 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
591 return 0;
592 }
593
594
595 static const GLfloat *
596 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
597 {
598 if (index == 0) {
599 if (ctx->API != API_OPENGLES2) {
600 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
601 return NULL;
602 }
603 }
604 else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
605 _mesa_error(ctx, GL_INVALID_VALUE,
606 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
607 return NULL;
608 }
609
610 FLUSH_CURRENT(ctx, 0);
611 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index];
612 }
613
614 void GLAPIENTRY
615 _mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
616 {
617 GET_CURRENT_CONTEXT(ctx);
618 ASSERT_OUTSIDE_BEGIN_END(ctx);
619
620 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
621 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
622 if (v != NULL) {
623 COPY_4V(params, v);
624 }
625 }
626 else {
627 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
628 "glGetVertexAttribfv");
629 }
630 }
631
632
633 void GLAPIENTRY
634 _mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
635 {
636 GET_CURRENT_CONTEXT(ctx);
637 ASSERT_OUTSIDE_BEGIN_END(ctx);
638
639 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
640 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
641 if (v != NULL) {
642 params[0] = (GLdouble) v[0];
643 params[1] = (GLdouble) v[1];
644 params[2] = (GLdouble) v[2];
645 params[3] = (GLdouble) v[3];
646 }
647 }
648 else {
649 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
650 "glGetVertexAttribdv");
651 }
652 }
653
654
655 void GLAPIENTRY
656 _mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
657 {
658 GET_CURRENT_CONTEXT(ctx);
659 ASSERT_OUTSIDE_BEGIN_END(ctx);
660
661 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
662 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
663 if (v != NULL) {
664 /* XXX should floats in[0,1] be scaled to full int range? */
665 params[0] = (GLint) v[0];
666 params[1] = (GLint) v[1];
667 params[2] = (GLint) v[2];
668 params[3] = (GLint) v[3];
669 }
670 }
671 else {
672 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
673 "glGetVertexAttribiv");
674 }
675 }
676
677
678 /** GL 3.0 */
679 void GLAPIENTRY
680 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
681 {
682 GET_CURRENT_CONTEXT(ctx);
683 ASSERT_OUTSIDE_BEGIN_END(ctx);
684
685 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
686 const GLfloat *v =
687 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
688 if (v != NULL) {
689 /* XXX we don't have true integer-valued vertex attribs yet */
690 params[0] = (GLint) v[0];
691 params[1] = (GLint) v[1];
692 params[2] = (GLint) v[2];
693 params[3] = (GLint) v[3];
694 }
695 }
696 else {
697 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
698 "glGetVertexAttribIiv");
699 }
700 }
701
702
703 /** GL 3.0 */
704 void GLAPIENTRY
705 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
706 {
707 GET_CURRENT_CONTEXT(ctx);
708 ASSERT_OUTSIDE_BEGIN_END(ctx);
709
710 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
711 const GLfloat *v =
712 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
713 if (v != NULL) {
714 /* XXX we don't have true integer-valued vertex attribs yet */
715 params[0] = (GLuint) v[0];
716 params[1] = (GLuint) v[1];
717 params[2] = (GLuint) v[2];
718 params[3] = (GLuint) v[3];
719 }
720 }
721 else {
722 params[0] = get_vertex_array_attrib(ctx, index, pname,
723 "glGetVertexAttribIuiv");
724 }
725 }
726
727
728 void GLAPIENTRY
729 _mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
730 {
731 GET_CURRENT_CONTEXT(ctx);
732 ASSERT_OUTSIDE_BEGIN_END(ctx);
733
734 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
735 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
736 return;
737 }
738
739 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
740 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
741 return;
742 }
743
744 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
745
746 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
747 }
748
749
750 void GLAPIENTRY
751 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
752 GLsizei count, const GLvoid *ptr)
753 {
754 (void) count;
755 _mesa_VertexPointer(size, type, stride, ptr);
756 }
757
758
759 void GLAPIENTRY
760 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
761 const GLvoid *ptr)
762 {
763 (void) count;
764 _mesa_NormalPointer(type, stride, ptr);
765 }
766
767
768 void GLAPIENTRY
769 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
770 const GLvoid *ptr)
771 {
772 (void) count;
773 _mesa_ColorPointer(size, type, stride, ptr);
774 }
775
776
777 void GLAPIENTRY
778 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
779 const GLvoid *ptr)
780 {
781 (void) count;
782 _mesa_IndexPointer(type, stride, ptr);
783 }
784
785
786 void GLAPIENTRY
787 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
788 GLsizei count, const GLvoid *ptr)
789 {
790 (void) count;
791 _mesa_TexCoordPointer(size, type, stride, ptr);
792 }
793
794
795 void GLAPIENTRY
796 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
797 {
798 (void) count;
799 _mesa_EdgeFlagPointer(stride, ptr);
800 }
801
802
803 void GLAPIENTRY
804 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
805 {
806 GET_CURRENT_CONTEXT(ctx);
807 GLboolean tflag, cflag, nflag; /* enable/disable flags */
808 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
809 GLenum ctype = 0; /* color type */
810 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
811 const GLint toffset = 0; /* always zero */
812 GLint defstride; /* default stride */
813 GLint c, f;
814
815 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
816
817 f = sizeof(GLfloat);
818 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
819
820 if (stride < 0) {
821 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
822 return;
823 }
824
825 switch (format) {
826 case GL_V2F:
827 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
828 tcomps = 0; ccomps = 0; vcomps = 2;
829 voffset = 0;
830 defstride = 2*f;
831 break;
832 case GL_V3F:
833 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
834 tcomps = 0; ccomps = 0; vcomps = 3;
835 voffset = 0;
836 defstride = 3*f;
837 break;
838 case GL_C4UB_V2F:
839 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
840 tcomps = 0; ccomps = 4; vcomps = 2;
841 ctype = GL_UNSIGNED_BYTE;
842 coffset = 0;
843 voffset = c;
844 defstride = c + 2*f;
845 break;
846 case GL_C4UB_V3F:
847 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
848 tcomps = 0; ccomps = 4; vcomps = 3;
849 ctype = GL_UNSIGNED_BYTE;
850 coffset = 0;
851 voffset = c;
852 defstride = c + 3*f;
853 break;
854 case GL_C3F_V3F:
855 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
856 tcomps = 0; ccomps = 3; vcomps = 3;
857 ctype = GL_FLOAT;
858 coffset = 0;
859 voffset = 3*f;
860 defstride = 6*f;
861 break;
862 case GL_N3F_V3F:
863 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
864 tcomps = 0; ccomps = 0; vcomps = 3;
865 noffset = 0;
866 voffset = 3*f;
867 defstride = 6*f;
868 break;
869 case GL_C4F_N3F_V3F:
870 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
871 tcomps = 0; ccomps = 4; vcomps = 3;
872 ctype = GL_FLOAT;
873 coffset = 0;
874 noffset = 4*f;
875 voffset = 7*f;
876 defstride = 10*f;
877 break;
878 case GL_T2F_V3F:
879 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
880 tcomps = 2; ccomps = 0; vcomps = 3;
881 voffset = 2*f;
882 defstride = 5*f;
883 break;
884 case GL_T4F_V4F:
885 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
886 tcomps = 4; ccomps = 0; vcomps = 4;
887 voffset = 4*f;
888 defstride = 8*f;
889 break;
890 case GL_T2F_C4UB_V3F:
891 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
892 tcomps = 2; ccomps = 4; vcomps = 3;
893 ctype = GL_UNSIGNED_BYTE;
894 coffset = 2*f;
895 voffset = c+2*f;
896 defstride = c+5*f;
897 break;
898 case GL_T2F_C3F_V3F:
899 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
900 tcomps = 2; ccomps = 3; vcomps = 3;
901 ctype = GL_FLOAT;
902 coffset = 2*f;
903 voffset = 5*f;
904 defstride = 8*f;
905 break;
906 case GL_T2F_N3F_V3F:
907 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
908 tcomps = 2; ccomps = 0; vcomps = 3;
909 noffset = 2*f;
910 voffset = 5*f;
911 defstride = 8*f;
912 break;
913 case GL_T2F_C4F_N3F_V3F:
914 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
915 tcomps = 2; ccomps = 4; vcomps = 3;
916 ctype = GL_FLOAT;
917 coffset = 2*f;
918 noffset = 6*f;
919 voffset = 9*f;
920 defstride = 12*f;
921 break;
922 case GL_T4F_C4F_N3F_V4F:
923 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
924 tcomps = 4; ccomps = 4; vcomps = 4;
925 ctype = GL_FLOAT;
926 coffset = 4*f;
927 noffset = 8*f;
928 voffset = 11*f;
929 defstride = 15*f;
930 break;
931 default:
932 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
933 return;
934 }
935
936 if (stride==0) {
937 stride = defstride;
938 }
939
940 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
941 _mesa_DisableClientState( GL_INDEX_ARRAY );
942 /* XXX also disable secondary color and generic arrays? */
943
944 /* Texcoords */
945 if (tflag) {
946 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
947 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
948 (GLubyte *) pointer + toffset );
949 }
950 else {
951 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
952 }
953
954 /* Color */
955 if (cflag) {
956 _mesa_EnableClientState( GL_COLOR_ARRAY );
957 _mesa_ColorPointer( ccomps, ctype, stride,
958 (GLubyte *) pointer + coffset );
959 }
960 else {
961 _mesa_DisableClientState( GL_COLOR_ARRAY );
962 }
963
964
965 /* Normals */
966 if (nflag) {
967 _mesa_EnableClientState( GL_NORMAL_ARRAY );
968 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
969 }
970 else {
971 _mesa_DisableClientState( GL_NORMAL_ARRAY );
972 }
973
974 /* Vertices */
975 _mesa_EnableClientState( GL_VERTEX_ARRAY );
976 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
977 (GLubyte *) pointer + voffset );
978 }
979
980
981 void GLAPIENTRY
982 _mesa_LockArraysEXT(GLint first, GLsizei count)
983 {
984 GET_CURRENT_CONTEXT(ctx);
985 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
986
987 if (MESA_VERBOSE & VERBOSE_API)
988 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
989
990 if (first < 0) {
991 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
992 return;
993 }
994 if (count <= 0) {
995 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
996 return;
997 }
998 if (ctx->Array.LockCount != 0) {
999 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1000 return;
1001 }
1002
1003 ctx->Array.LockFirst = first;
1004 ctx->Array.LockCount = count;
1005
1006 ctx->NewState |= _NEW_ARRAY;
1007 ctx->Array.NewState |= VERT_BIT_ALL;
1008 }
1009
1010
1011 void GLAPIENTRY
1012 _mesa_UnlockArraysEXT( void )
1013 {
1014 GET_CURRENT_CONTEXT(ctx);
1015 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1016
1017 if (MESA_VERBOSE & VERBOSE_API)
1018 _mesa_debug(ctx, "glUnlockArrays\n");
1019
1020 if (ctx->Array.LockCount == 0) {
1021 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1022 return;
1023 }
1024
1025 ctx->Array.LockFirst = 0;
1026 ctx->Array.LockCount = 0;
1027 ctx->NewState |= _NEW_ARRAY;
1028 ctx->Array.NewState |= VERT_BIT_ALL;
1029 }
1030
1031
1032 /* GL_EXT_multi_draw_arrays */
1033 void GLAPIENTRY
1034 _mesa_MultiDrawArraysEXT( GLenum mode, const GLint *first,
1035 const GLsizei *count, GLsizei primcount )
1036 {
1037 GET_CURRENT_CONTEXT(ctx);
1038 GLint i;
1039
1040 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1041
1042 for (i = 0; i < primcount; i++) {
1043 if (count[i] > 0) {
1044 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
1045 }
1046 }
1047 }
1048
1049
1050 /* GL_IBM_multimode_draw_arrays */
1051 void GLAPIENTRY
1052 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1053 const GLsizei * count,
1054 GLsizei primcount, GLint modestride )
1055 {
1056 GET_CURRENT_CONTEXT(ctx);
1057 GLint i;
1058
1059 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1060
1061 for ( i = 0 ; i < primcount ; i++ ) {
1062 if ( count[i] > 0 ) {
1063 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1064 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
1065 }
1066 }
1067 }
1068
1069
1070 /* GL_IBM_multimode_draw_arrays */
1071 void GLAPIENTRY
1072 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1073 GLenum type, const GLvoid * const * indices,
1074 GLsizei primcount, GLint modestride )
1075 {
1076 GET_CURRENT_CONTEXT(ctx);
1077 GLint i;
1078
1079 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1080
1081 /* XXX not sure about ARB_vertex_buffer_object handling here */
1082
1083 for ( i = 0 ; i < primcount ; i++ ) {
1084 if ( count[i] > 0 ) {
1085 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1086 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
1087 }
1088 }
1089 }
1090
1091
1092 /**
1093 * GL_NV_primitive_restart and GL 3.1
1094 */
1095 void GLAPIENTRY
1096 _mesa_PrimitiveRestartIndex(GLuint index)
1097 {
1098 GET_CURRENT_CONTEXT(ctx);
1099
1100 if (!ctx->Extensions.NV_primitive_restart &&
1101 ctx->VersionMajor * 10 + ctx->VersionMinor < 31) {
1102 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1103 return;
1104 }
1105
1106 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1107
1108 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1109
1110 ctx->Array.RestartIndex = index;
1111 }
1112
1113
1114 /**
1115 * See GL_ARB_instanced_arrays.
1116 * Note that the instance divisor only applies to generic arrays, not
1117 * the legacy vertex arrays.
1118 */
1119 void GLAPIENTRY
1120 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1121 {
1122 GET_CURRENT_CONTEXT(ctx);
1123 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1124
1125 if (!ctx->Extensions.ARB_instanced_arrays) {
1126 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1127 return;
1128 }
1129
1130 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
1131 _mesa_error(ctx, GL_INVALID_ENUM, "glVertexAttribDivisor(index = %u)",
1132 index);
1133 return;
1134 }
1135
1136 ctx->Array.ArrayObj->VertexAttrib[index].InstanceDivisor = divisor;
1137 }
1138
1139
1140
1141 /**
1142 * Copy one client vertex array to another.
1143 */
1144 void
1145 _mesa_copy_client_array(struct gl_context *ctx,
1146 struct gl_client_array *dst,
1147 struct gl_client_array *src)
1148 {
1149 dst->Size = src->Size;
1150 dst->Type = src->Type;
1151 dst->Format = src->Format;
1152 dst->Stride = src->Stride;
1153 dst->StrideB = src->StrideB;
1154 dst->Ptr = src->Ptr;
1155 dst->Enabled = src->Enabled;
1156 dst->Normalized = src->Normalized;
1157 dst->Integer = src->Integer;
1158 dst->InstanceDivisor = src->InstanceDivisor;
1159 dst->_ElementSize = src->_ElementSize;
1160 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1161 dst->_MaxElement = src->_MaxElement;
1162 }
1163
1164
1165
1166 /**
1167 * Print vertex array's fields.
1168 */
1169 static void
1170 print_array(const char *name, GLint index, const struct gl_client_array *array)
1171 {
1172 if (index >= 0)
1173 printf(" %s[%d]: ", name, index);
1174 else
1175 printf(" %s: ", name);
1176 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1177 array->Ptr, array->Type, array->Size,
1178 array->_ElementSize, array->StrideB,
1179 array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
1180 array->_MaxElement);
1181 }
1182
1183
1184 /**
1185 * Print current vertex object/array info. For debug.
1186 */
1187 void
1188 _mesa_print_arrays(struct gl_context *ctx)
1189 {
1190 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
1191 GLuint i;
1192
1193 _mesa_update_array_object_max_element(ctx, arrayObj);
1194
1195 printf("Array Object %u\n", arrayObj->Name);
1196 if (arrayObj->Vertex.Enabled)
1197 print_array("Vertex", -1, &arrayObj->Vertex);
1198 if (arrayObj->Normal.Enabled)
1199 print_array("Normal", -1, &arrayObj->Normal);
1200 if (arrayObj->Color.Enabled)
1201 print_array("Color", -1, &arrayObj->Color);
1202 for (i = 0; i < Elements(arrayObj->TexCoord); i++)
1203 if (arrayObj->TexCoord[i].Enabled)
1204 print_array("TexCoord", i, &arrayObj->TexCoord[i]);
1205 for (i = 0; i < Elements(arrayObj->VertexAttrib); i++)
1206 if (arrayObj->VertexAttrib[i].Enabled)
1207 print_array("Attrib", i, &arrayObj->VertexAttrib[i]);
1208 printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
1209 }
1210
1211
1212 /**
1213 * Initialize vertex array state for given context.
1214 */
1215 void
1216 _mesa_init_varray(struct gl_context *ctx)
1217 {
1218 ctx->Array.DefaultArrayObj = _mesa_new_array_object(ctx, 0);
1219 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
1220 ctx->Array.DefaultArrayObj);
1221 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1222
1223 ctx->Array.Objects = _mesa_NewHashTable();
1224 }
1225
1226
1227 /**
1228 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1229 */
1230 static void
1231 delete_arrayobj_cb(GLuint id, void *data, void *userData)
1232 {
1233 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
1234 struct gl_context *ctx = (struct gl_context *) userData;
1235 _mesa_delete_array_object(ctx, arrayObj);
1236 }
1237
1238
1239 /**
1240 * Free vertex array state for given context.
1241 */
1242 void
1243 _mesa_free_varray_data(struct gl_context *ctx)
1244 {
1245 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
1246 _mesa_DeleteHashTable(ctx->Array.Objects);
1247 }