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