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