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