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