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