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