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