mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[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 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 "mtypes.h"
37 #include "varray.h"
38 #include "arrayobj.h"
39 #include "main/dispatch.h"
40
41
42 /** Used to do error checking for GL_EXT_vertex_array_bgra */
43 #define BGRA_OR_4 5
44
45
46 /** Used to indicate which GL datatypes are accepted by each of the
47 * glVertex/Color/Attrib/EtcPointer() functions.
48 */
49 #define BOOL_BIT 0x1
50 #define BYTE_BIT 0x2
51 #define UNSIGNED_BYTE_BIT 0x4
52 #define SHORT_BIT 0x8
53 #define UNSIGNED_SHORT_BIT 0x10
54 #define INT_BIT 0x20
55 #define UNSIGNED_INT_BIT 0x40
56 #define HALF_BIT 0x80
57 #define FLOAT_BIT 0x100
58 #define DOUBLE_BIT 0x200
59 #define FIXED_ES_BIT 0x400
60 #define FIXED_GL_BIT 0x800
61 #define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000
62 #define INT_2_10_10_10_REV_BIT 0x2000
63
64
65 /** Convert GL datatype enum into a <type>_BIT value seen above */
66 static GLbitfield
67 type_to_bit(const struct gl_context *ctx, GLenum type)
68 {
69 switch (type) {
70 case GL_BOOL:
71 return BOOL_BIT;
72 case GL_BYTE:
73 return BYTE_BIT;
74 case GL_UNSIGNED_BYTE:
75 return UNSIGNED_BYTE_BIT;
76 case GL_SHORT:
77 return SHORT_BIT;
78 case GL_UNSIGNED_SHORT:
79 return UNSIGNED_SHORT_BIT;
80 case GL_INT:
81 return INT_BIT;
82 case GL_UNSIGNED_INT:
83 return UNSIGNED_INT_BIT;
84 case GL_HALF_FLOAT:
85 if (ctx->Extensions.ARB_half_float_vertex)
86 return HALF_BIT;
87 else
88 return 0x0;
89 case GL_FLOAT:
90 return FLOAT_BIT;
91 case GL_DOUBLE:
92 return DOUBLE_BIT;
93 case GL_FIXED:
94 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
95 case GL_UNSIGNED_INT_2_10_10_10_REV:
96 return UNSIGNED_INT_2_10_10_10_REV_BIT;
97 case GL_INT_2_10_10_10_REV:
98 return INT_2_10_10_10_REV_BIT;
99 default:
100 return 0;
101 }
102 }
103
104
105 /**
106 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
107 * functions.
108 *
109 * \param func name of calling function used for error reporting
110 * \param attrib the attribute array index to update
111 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
112 * \param sizeMin min allowable size value
113 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
114 * \param size components per element (1, 2, 3 or 4)
115 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
116 * \param stride stride between elements, in elements
117 * \param normalized are integer types converted to floats in [-1, 1]?
118 * \param integer integer-valued values (will not be normalized to [-1,1])
119 * \param ptr the address (or offset inside VBO) of the array data
120 */
121 static void
122 update_array(struct gl_context *ctx,
123 const char *func,
124 GLuint attrib, GLbitfield legalTypesMask,
125 GLint sizeMin, GLint sizeMax,
126 GLint size, GLenum type, GLsizei stride,
127 GLboolean normalized, GLboolean integer,
128 const GLvoid *ptr)
129 {
130 struct gl_client_array *array;
131 GLbitfield typeBit;
132 GLsizei elementSize;
133 GLenum format = GL_RGBA;
134
135 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
136 *
137 * "Client vertex arrays - all vertex array attribute pointers must
138 * refer to buffer objects (section 2.9.2). The default vertex array
139 * object (the name zero) is also deprecated. Calling
140 * VertexAttribPointer when no buffer object or no vertex array object
141 * is bound will generate an INVALID_OPERATION error..."
142 *
143 * The check for VBOs is handled below.
144 */
145 if (ctx->API == API_OPENGL_CORE
146 && (ctx->Array.ArrayObj == ctx->Array.DefaultArrayObj)) {
147 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
148 func);
149 return;
150 }
151
152 if (_mesa_is_gles(ctx)) {
153 legalTypesMask &= ~(FIXED_GL_BIT | DOUBLE_BIT);
154
155 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
156 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
157 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
158 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
159 * quite as trivial as we'd like because it uses a different enum value
160 * for GL_HALF_FLOAT_OES.
161 */
162 if (ctx->Version < 30) {
163 legalTypesMask &= ~(UNSIGNED_INT_BIT
164 | INT_BIT
165 | UNSIGNED_INT_2_10_10_10_REV_BIT
166 | INT_2_10_10_10_REV_BIT
167 | HALF_BIT);
168 }
169
170 /* BGRA ordering is not supported in ES contexts.
171 */
172 if (sizeMax == BGRA_OR_4)
173 sizeMax = 4;
174 } else {
175 legalTypesMask &= ~FIXED_ES_BIT;
176
177 if (!ctx->Extensions.ARB_ES2_compatibility)
178 legalTypesMask &= ~FIXED_GL_BIT;
179
180 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
181 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
182 INT_2_10_10_10_REV_BIT);
183 }
184
185 typeBit = type_to_bit(ctx, type);
186 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
187 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
188 func, _mesa_lookup_enum_by_nr(type));
189 return;
190 }
191
192 /* Do size parameter checking.
193 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
194 * must be handled specially.
195 */
196 if (ctx->Extensions.EXT_vertex_array_bgra &&
197 sizeMax == BGRA_OR_4 &&
198 size == GL_BGRA) {
199 GLboolean bgra_error = GL_FALSE;
200
201 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
202 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
203 type != GL_INT_2_10_10_10_REV &&
204 type != GL_UNSIGNED_BYTE)
205 bgra_error = GL_TRUE;
206 } else if (type != GL_UNSIGNED_BYTE)
207 bgra_error = GL_TRUE;
208
209 if (bgra_error) {
210 _mesa_error(ctx, GL_INVALID_VALUE, "%s(GL_BGRA/GLubyte)", func);
211 return;
212 }
213 format = GL_BGRA;
214 size = 4;
215 }
216 else if (size < sizeMin || size > sizeMax || size > 4) {
217 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
218 return;
219 }
220
221 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
222 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
223 type == GL_INT_2_10_10_10_REV) && size != 4) {
224 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
225 return;
226 }
227
228 ASSERT(size <= 4);
229
230 if (stride < 0) {
231 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
232 return;
233 }
234
235 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
236 *
237 * "An INVALID_OPERATION error is generated under any of the following
238 * conditions:
239 *
240 * ...
241 *
242 * * any of the *Pointer commands specifying the location and
243 * organization of vertex array data are called while zero is bound
244 * to the ARRAY_BUFFER buffer object binding point (see section
245 * 2.9.6), and the pointer argument is not NULL."
246 */
247 if (ptr != NULL && ctx->Array.ArrayObj->ARBsemantics &&
248 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
249 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
250 return;
251 }
252
253 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
254 assert(elementSize != -1);
255
256 array = &ctx->Array.ArrayObj->VertexAttrib[attrib];
257 array->Size = size;
258 array->Type = type;
259 array->Format = format;
260 array->Stride = stride;
261 array->StrideB = stride ? stride : elementSize;
262 array->Normalized = normalized;
263 array->Integer = integer;
264 array->Ptr = (const GLubyte *) ptr;
265 array->_ElementSize = elementSize;
266
267 _mesa_reference_buffer_object(ctx, &array->BufferObj,
268 ctx->Array.ArrayBufferObj);
269
270 ctx->NewState |= _NEW_ARRAY;
271 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(attrib);
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 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
524 }
525 }
526
527
528 void GLAPIENTRY
529 _mesa_DisableVertexAttribArray(GLuint index)
530 {
531 struct gl_array_object *arrayObj;
532 GET_CURRENT_CONTEXT(ctx);
533
534 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
535 _mesa_error(ctx, GL_INVALID_VALUE,
536 "glDisableVertexAttribArrayARB(index)");
537 return;
538 }
539
540 arrayObj = ctx->Array.ArrayObj;
541
542 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->VertexAttrib));
543
544 if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
545 /* was enabled, now being disabled */
546 FLUSH_VERTICES(ctx, _NEW_ARRAY);
547 arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
548 arrayObj->_Enabled &= ~VERT_BIT_GENERIC(index);
549 arrayObj->NewArrays |= VERT_BIT_GENERIC(index);
550 }
551 }
552
553
554 /**
555 * Return info for a vertex attribute array (no alias with legacy
556 * vertex attributes (pos, normal, color, etc)). This function does
557 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
558 */
559 static GLuint
560 get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
561 const char *caller)
562 {
563 const struct gl_client_array *array;
564
565 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
566 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
567 return 0;
568 }
569
570 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib));
571
572 array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
573
574 switch (pname) {
575 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
576 return array->Enabled;
577 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
578 return array->Size;
579 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
580 return array->Stride;
581 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
582 return array->Type;
583 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
584 return array->Normalized;
585 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
586 return array->BufferObj->Name;
587 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
588 if ((_mesa_is_desktop_gl(ctx)
589 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
590 || _mesa_is_gles3(ctx)) {
591 return array->Integer;
592 }
593 goto error;
594 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
595 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
596 || _mesa_is_gles3(ctx)) {
597 return array->InstanceDivisor;
598 }
599 goto error;
600 default:
601 ; /* fall-through */
602 }
603
604 error:
605 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
606 return 0;
607 }
608
609
610 static const GLfloat *
611 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
612 {
613 if (index == 0) {
614 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
615 * 2.0. Note that we cannot just check for API_OPENGL_CORE here because
616 * that will erroneously allow this usage in a 3.0 forward-compatible
617 * context too.
618 */
619 if ((ctx->API != API_OPENGL_CORE || ctx->Version < 31)
620 && ctx->API != API_OPENGLES2) {
621 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
622 return NULL;
623 }
624 }
625 else if (index >= ctx->Const.VertexProgram.MaxAttribs) {
626 _mesa_error(ctx, GL_INVALID_VALUE,
627 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
628 return NULL;
629 }
630
631 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib));
632
633 FLUSH_CURRENT(ctx, 0);
634 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
635 }
636
637 void GLAPIENTRY
638 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
639 {
640 GET_CURRENT_CONTEXT(ctx);
641
642 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
643 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
644 if (v != NULL) {
645 COPY_4V(params, v);
646 }
647 }
648 else {
649 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
650 "glGetVertexAttribfv");
651 }
652 }
653
654
655 void GLAPIENTRY
656 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
657 {
658 GET_CURRENT_CONTEXT(ctx);
659
660 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
661 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
662 if (v != NULL) {
663 params[0] = (GLdouble) v[0];
664 params[1] = (GLdouble) v[1];
665 params[2] = (GLdouble) v[2];
666 params[3] = (GLdouble) v[3];
667 }
668 }
669 else {
670 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
671 "glGetVertexAttribdv");
672 }
673 }
674
675
676 void GLAPIENTRY
677 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
678 {
679 GET_CURRENT_CONTEXT(ctx);
680
681 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
682 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
683 if (v != NULL) {
684 /* XXX should floats in[0,1] be scaled to full int range? */
685 params[0] = (GLint) v[0];
686 params[1] = (GLint) v[1];
687 params[2] = (GLint) v[2];
688 params[3] = (GLint) v[3];
689 }
690 }
691 else {
692 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
693 "glGetVertexAttribiv");
694 }
695 }
696
697
698 /** GL 3.0 */
699 void GLAPIENTRY
700 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
701 {
702 GET_CURRENT_CONTEXT(ctx);
703
704 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
705 const GLint *v = (const GLint *)
706 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
707 if (v != NULL) {
708 COPY_4V(params, v);
709 }
710 }
711 else {
712 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
713 "glGetVertexAttribIiv");
714 }
715 }
716
717
718 /** GL 3.0 */
719 void GLAPIENTRY
720 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
721 {
722 GET_CURRENT_CONTEXT(ctx);
723
724 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
725 const GLuint *v = (const GLuint *)
726 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
727 if (v != NULL) {
728 COPY_4V(params, v);
729 }
730 }
731 else {
732 params[0] = get_vertex_array_attrib(ctx, index, pname,
733 "glGetVertexAttribIuiv");
734 }
735 }
736
737
738 void GLAPIENTRY
739 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
740 {
741 GET_CURRENT_CONTEXT(ctx);
742
743 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
744 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
745 return;
746 }
747
748 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
749 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
750 return;
751 }
752
753 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib));
754
755 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
756 }
757
758
759 void GLAPIENTRY
760 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
761 GLsizei count, const GLvoid *ptr)
762 {
763 (void) count;
764 _mesa_VertexPointer(size, type, stride, ptr);
765 }
766
767
768 void GLAPIENTRY
769 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
770 const GLvoid *ptr)
771 {
772 (void) count;
773 _mesa_NormalPointer(type, stride, ptr);
774 }
775
776
777 void GLAPIENTRY
778 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
779 const GLvoid *ptr)
780 {
781 (void) count;
782 _mesa_ColorPointer(size, type, stride, ptr);
783 }
784
785
786 void GLAPIENTRY
787 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
788 const GLvoid *ptr)
789 {
790 (void) count;
791 _mesa_IndexPointer(type, stride, ptr);
792 }
793
794
795 void GLAPIENTRY
796 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
797 GLsizei count, const GLvoid *ptr)
798 {
799 (void) count;
800 _mesa_TexCoordPointer(size, type, stride, ptr);
801 }
802
803
804 void GLAPIENTRY
805 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
806 {
807 (void) count;
808 _mesa_EdgeFlagPointer(stride, ptr);
809 }
810
811
812 void GLAPIENTRY
813 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
814 {
815 GET_CURRENT_CONTEXT(ctx);
816 GLboolean tflag, cflag, nflag; /* enable/disable flags */
817 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
818 GLenum ctype = 0; /* color type */
819 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
820 const GLint toffset = 0; /* always zero */
821 GLint defstride; /* default stride */
822 GLint c, f;
823
824 FLUSH_VERTICES(ctx, 0);
825
826 f = sizeof(GLfloat);
827 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
828
829 if (stride < 0) {
830 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
831 return;
832 }
833
834 switch (format) {
835 case GL_V2F:
836 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
837 tcomps = 0; ccomps = 0; vcomps = 2;
838 voffset = 0;
839 defstride = 2*f;
840 break;
841 case GL_V3F:
842 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
843 tcomps = 0; ccomps = 0; vcomps = 3;
844 voffset = 0;
845 defstride = 3*f;
846 break;
847 case GL_C4UB_V2F:
848 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
849 tcomps = 0; ccomps = 4; vcomps = 2;
850 ctype = GL_UNSIGNED_BYTE;
851 coffset = 0;
852 voffset = c;
853 defstride = c + 2*f;
854 break;
855 case GL_C4UB_V3F:
856 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
857 tcomps = 0; ccomps = 4; vcomps = 3;
858 ctype = GL_UNSIGNED_BYTE;
859 coffset = 0;
860 voffset = c;
861 defstride = c + 3*f;
862 break;
863 case GL_C3F_V3F:
864 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
865 tcomps = 0; ccomps = 3; vcomps = 3;
866 ctype = GL_FLOAT;
867 coffset = 0;
868 voffset = 3*f;
869 defstride = 6*f;
870 break;
871 case GL_N3F_V3F:
872 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
873 tcomps = 0; ccomps = 0; vcomps = 3;
874 noffset = 0;
875 voffset = 3*f;
876 defstride = 6*f;
877 break;
878 case GL_C4F_N3F_V3F:
879 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
880 tcomps = 0; ccomps = 4; vcomps = 3;
881 ctype = GL_FLOAT;
882 coffset = 0;
883 noffset = 4*f;
884 voffset = 7*f;
885 defstride = 10*f;
886 break;
887 case GL_T2F_V3F:
888 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
889 tcomps = 2; ccomps = 0; vcomps = 3;
890 voffset = 2*f;
891 defstride = 5*f;
892 break;
893 case GL_T4F_V4F:
894 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
895 tcomps = 4; ccomps = 0; vcomps = 4;
896 voffset = 4*f;
897 defstride = 8*f;
898 break;
899 case GL_T2F_C4UB_V3F:
900 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
901 tcomps = 2; ccomps = 4; vcomps = 3;
902 ctype = GL_UNSIGNED_BYTE;
903 coffset = 2*f;
904 voffset = c+2*f;
905 defstride = c+5*f;
906 break;
907 case GL_T2F_C3F_V3F:
908 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
909 tcomps = 2; ccomps = 3; vcomps = 3;
910 ctype = GL_FLOAT;
911 coffset = 2*f;
912 voffset = 5*f;
913 defstride = 8*f;
914 break;
915 case GL_T2F_N3F_V3F:
916 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
917 tcomps = 2; ccomps = 0; vcomps = 3;
918 noffset = 2*f;
919 voffset = 5*f;
920 defstride = 8*f;
921 break;
922 case GL_T2F_C4F_N3F_V3F:
923 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
924 tcomps = 2; ccomps = 4; vcomps = 3;
925 ctype = GL_FLOAT;
926 coffset = 2*f;
927 noffset = 6*f;
928 voffset = 9*f;
929 defstride = 12*f;
930 break;
931 case GL_T4F_C4F_N3F_V4F:
932 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
933 tcomps = 4; ccomps = 4; vcomps = 4;
934 ctype = GL_FLOAT;
935 coffset = 4*f;
936 noffset = 8*f;
937 voffset = 11*f;
938 defstride = 15*f;
939 break;
940 default:
941 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
942 return;
943 }
944
945 if (stride==0) {
946 stride = defstride;
947 }
948
949 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
950 _mesa_DisableClientState( GL_INDEX_ARRAY );
951 /* XXX also disable secondary color and generic arrays? */
952
953 /* Texcoords */
954 if (tflag) {
955 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
956 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
957 (GLubyte *) pointer + toffset );
958 }
959 else {
960 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
961 }
962
963 /* Color */
964 if (cflag) {
965 _mesa_EnableClientState( GL_COLOR_ARRAY );
966 _mesa_ColorPointer( ccomps, ctype, stride,
967 (GLubyte *) pointer + coffset );
968 }
969 else {
970 _mesa_DisableClientState( GL_COLOR_ARRAY );
971 }
972
973
974 /* Normals */
975 if (nflag) {
976 _mesa_EnableClientState( GL_NORMAL_ARRAY );
977 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
978 }
979 else {
980 _mesa_DisableClientState( GL_NORMAL_ARRAY );
981 }
982
983 /* Vertices */
984 _mesa_EnableClientState( GL_VERTEX_ARRAY );
985 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
986 (GLubyte *) pointer + voffset );
987 }
988
989
990 void GLAPIENTRY
991 _mesa_LockArraysEXT(GLint first, GLsizei count)
992 {
993 GET_CURRENT_CONTEXT(ctx);
994
995 FLUSH_VERTICES(ctx, 0);
996
997 if (MESA_VERBOSE & VERBOSE_API)
998 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
999
1000 if (first < 0) {
1001 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1002 return;
1003 }
1004 if (count <= 0) {
1005 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1006 return;
1007 }
1008 if (ctx->Array.LockCount != 0) {
1009 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1010 return;
1011 }
1012
1013 ctx->Array.LockFirst = first;
1014 ctx->Array.LockCount = count;
1015
1016 ctx->NewState |= _NEW_ARRAY;
1017 }
1018
1019
1020 void GLAPIENTRY
1021 _mesa_UnlockArraysEXT( void )
1022 {
1023 GET_CURRENT_CONTEXT(ctx);
1024
1025 FLUSH_VERTICES(ctx, 0);
1026
1027 if (MESA_VERBOSE & VERBOSE_API)
1028 _mesa_debug(ctx, "glUnlockArrays\n");
1029
1030 if (ctx->Array.LockCount == 0) {
1031 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1032 return;
1033 }
1034
1035 ctx->Array.LockFirst = 0;
1036 ctx->Array.LockCount = 0;
1037 ctx->NewState |= _NEW_ARRAY;
1038 }
1039
1040
1041 /* GL_EXT_multi_draw_arrays */
1042 void GLAPIENTRY
1043 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
1044 const GLsizei *count, GLsizei primcount )
1045 {
1046 GET_CURRENT_CONTEXT(ctx);
1047 GLint i;
1048
1049 FLUSH_VERTICES(ctx, 0);
1050
1051 for (i = 0; i < primcount; i++) {
1052 if (count[i] > 0) {
1053 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i]));
1054 }
1055 }
1056 }
1057
1058
1059 /* GL_IBM_multimode_draw_arrays */
1060 void GLAPIENTRY
1061 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1062 const GLsizei * count,
1063 GLsizei primcount, GLint modestride )
1064 {
1065 GET_CURRENT_CONTEXT(ctx);
1066 GLint i;
1067
1068 FLUSH_VERTICES(ctx, 0);
1069
1070 for ( i = 0 ; i < primcount ; i++ ) {
1071 if ( count[i] > 0 ) {
1072 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1073 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] ));
1074 }
1075 }
1076 }
1077
1078
1079 /* GL_IBM_multimode_draw_arrays */
1080 void GLAPIENTRY
1081 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1082 GLenum type, const GLvoid * const * indices,
1083 GLsizei primcount, GLint modestride )
1084 {
1085 GET_CURRENT_CONTEXT(ctx);
1086 GLint i;
1087
1088 FLUSH_VERTICES(ctx, 0);
1089
1090 /* XXX not sure about ARB_vertex_buffer_object handling here */
1091
1092 for ( i = 0 ; i < primcount ; i++ ) {
1093 if ( count[i] > 0 ) {
1094 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1095 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] ));
1096 }
1097 }
1098 }
1099
1100
1101 /**
1102 * GL_NV_primitive_restart and GL 3.1
1103 */
1104 void GLAPIENTRY
1105 _mesa_PrimitiveRestartIndex(GLuint index)
1106 {
1107 GET_CURRENT_CONTEXT(ctx);
1108
1109 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1110 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1111 return;
1112 }
1113
1114 ctx->Array.RestartIndex = index;
1115 if (ctx->Array.PrimitiveRestart && ctx->Array._RestartIndex != index) {
1116 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1117 ctx->Array._RestartIndex = index;
1118 }
1119 }
1120
1121
1122 /**
1123 * See GL_ARB_instanced_arrays.
1124 * Note that the instance divisor only applies to generic arrays, not
1125 * the legacy vertex arrays.
1126 */
1127 void GLAPIENTRY
1128 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1129 {
1130 struct gl_client_array *array;
1131 GET_CURRENT_CONTEXT(ctx);
1132
1133 if (!ctx->Extensions.ARB_instanced_arrays) {
1134 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1135 return;
1136 }
1137
1138 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
1139 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
1140 index);
1141 return;
1142 }
1143
1144 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib));
1145
1146 array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
1147 if (array->InstanceDivisor != divisor) {
1148 FLUSH_VERTICES(ctx, _NEW_ARRAY);
1149 array->InstanceDivisor = divisor;
1150 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(VERT_ATTRIB_GENERIC(index));
1151 }
1152 }
1153
1154
1155
1156 /**
1157 * Copy one client vertex array to another.
1158 */
1159 void
1160 _mesa_copy_client_array(struct gl_context *ctx,
1161 struct gl_client_array *dst,
1162 struct gl_client_array *src)
1163 {
1164 dst->Size = src->Size;
1165 dst->Type = src->Type;
1166 dst->Format = src->Format;
1167 dst->Stride = src->Stride;
1168 dst->StrideB = src->StrideB;
1169 dst->Ptr = src->Ptr;
1170 dst->Enabled = src->Enabled;
1171 dst->Normalized = src->Normalized;
1172 dst->Integer = src->Integer;
1173 dst->InstanceDivisor = src->InstanceDivisor;
1174 dst->_ElementSize = src->_ElementSize;
1175 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1176 dst->_MaxElement = src->_MaxElement;
1177 }
1178
1179
1180
1181 /**
1182 * Print vertex array's fields.
1183 */
1184 static void
1185 print_array(const char *name, GLint index, const struct gl_client_array *array)
1186 {
1187 if (index >= 0)
1188 printf(" %s[%d]: ", name, index);
1189 else
1190 printf(" %s: ", name);
1191 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n",
1192 array->Ptr, array->Type, array->Size,
1193 array->_ElementSize, array->StrideB,
1194 array->BufferObj->Name, (unsigned long) array->BufferObj->Size,
1195 array->_MaxElement);
1196 }
1197
1198
1199 /**
1200 * Print current vertex object/array info. For debug.
1201 */
1202 void
1203 _mesa_print_arrays(struct gl_context *ctx)
1204 {
1205 struct gl_array_object *arrayObj = ctx->Array.ArrayObj;
1206 GLuint i;
1207
1208 _mesa_update_array_object_max_element(ctx, arrayObj);
1209
1210 printf("Array Object %u\n", arrayObj->Name);
1211 if (arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled)
1212 print_array("Vertex", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_POS]);
1213 if (arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
1214 print_array("Normal", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]);
1215 if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
1216 print_array("Color", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]);
1217 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
1218 if (arrayObj->VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
1219 print_array("TexCoord", i, &arrayObj->VertexAttrib[VERT_ATTRIB_TEX(i)]);
1220 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
1221 if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
1222 print_array("Attrib", i, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
1223 printf(" _MaxElement = %u\n", arrayObj->_MaxElement);
1224 }
1225
1226
1227 /**
1228 * Initialize vertex array state for given context.
1229 */
1230 void
1231 _mesa_init_varray(struct gl_context *ctx)
1232 {
1233 ctx->Array.DefaultArrayObj = ctx->Driver.NewArrayObject(ctx, 0);
1234 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj,
1235 ctx->Array.DefaultArrayObj);
1236 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1237
1238 ctx->Array.Objects = _mesa_NewHashTable();
1239 }
1240
1241
1242 /**
1243 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1244 */
1245 static void
1246 delete_arrayobj_cb(GLuint id, void *data, void *userData)
1247 {
1248 struct gl_array_object *arrayObj = (struct gl_array_object *) data;
1249 struct gl_context *ctx = (struct gl_context *) userData;
1250 _mesa_delete_array_object(ctx, arrayObj);
1251 }
1252
1253
1254 /**
1255 * Free vertex array state for given context.
1256 */
1257 void
1258 _mesa_free_varray_data(struct gl_context *ctx)
1259 {
1260 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
1261 _mesa_DeleteHashTable(ctx->Array.Objects);
1262 }