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