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