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