mesa/vbo: add support for 64-bit vertex attributes. (v1)
[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 <stdio.h>
28 #include <inttypes.h> /* for PRId64 macro */
29
30 #include "glheader.h"
31 #include "imports.h"
32 #include "bufferobj.h"
33 #include "context.h"
34 #include "enable.h"
35 #include "enums.h"
36 #include "hash.h"
37 #include "image.h"
38 #include "macros.h"
39 #include "mtypes.h"
40 #include "varray.h"
41 #include "arrayobj.h"
42 #include "main/dispatch.h"
43
44
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
46 #define BGRA_OR_4 5
47
48
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
51 */
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
68
69
70 /** Convert GL datatype enum into a <type>_BIT value seen above */
71 static GLbitfield
72 type_to_bit(const struct gl_context *ctx, GLenum type)
73 {
74 switch (type) {
75 case GL_BOOL:
76 return BOOL_BIT;
77 case GL_BYTE:
78 return BYTE_BIT;
79 case GL_UNSIGNED_BYTE:
80 return UNSIGNED_BYTE_BIT;
81 case GL_SHORT:
82 return SHORT_BIT;
83 case GL_UNSIGNED_SHORT:
84 return UNSIGNED_SHORT_BIT;
85 case GL_INT:
86 return INT_BIT;
87 case GL_UNSIGNED_INT:
88 return UNSIGNED_INT_BIT;
89 case GL_HALF_FLOAT:
90 if (ctx->Extensions.ARB_half_float_vertex)
91 return HALF_BIT;
92 else
93 return 0x0;
94 case GL_FLOAT:
95 return FLOAT_BIT;
96 case GL_DOUBLE:
97 return DOUBLE_BIT;
98 case GL_FIXED:
99 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
100 case GL_UNSIGNED_INT_2_10_10_10_REV:
101 return UNSIGNED_INT_2_10_10_10_REV_BIT;
102 case GL_INT_2_10_10_10_REV:
103 return INT_2_10_10_10_REV_BIT;
104 case GL_UNSIGNED_INT_10F_11F_11F_REV:
105 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
106 default:
107 return 0;
108 }
109 }
110
111
112 /**
113 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
114 */
115 static void
116 vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
117 GLuint bindingIndex)
118 {
119 struct gl_vertex_array_object *vao = ctx->Array.VAO;
120 struct gl_vertex_attrib_array *array = &vao->VertexAttrib[attribIndex];
121
122 if (array->VertexBinding != bindingIndex) {
123 const GLbitfield64 array_bit = VERT_BIT(attribIndex);
124
125 FLUSH_VERTICES(ctx, _NEW_ARRAY);
126
127 vao->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit;
128 vao->VertexBinding[bindingIndex]._BoundArrays |= array_bit;
129
130 array->VertexBinding = bindingIndex;
131
132 vao->NewArrays |= array_bit;
133 }
134 }
135
136
137 /**
138 * Binds a buffer object to the vertex buffer binding point given by index,
139 * and sets the Offset and Stride fields.
140 */
141 static void
142 bind_vertex_buffer(struct gl_context *ctx, GLuint index,
143 struct gl_buffer_object *vbo,
144 GLintptr offset, GLsizei stride)
145 {
146 struct gl_vertex_array_object *vao = ctx->Array.VAO;
147 struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[index];
148
149 if (binding->BufferObj != vbo ||
150 binding->Offset != offset ||
151 binding->Stride != stride) {
152
153 FLUSH_VERTICES(ctx, _NEW_ARRAY);
154
155 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
156
157 binding->Offset = offset;
158 binding->Stride = stride;
159
160 vao->NewArrays |= binding->_BoundArrays;
161 }
162 }
163
164
165 /**
166 * Sets the InstanceDivisor field in the vertex buffer binding point
167 * given by bindingIndex.
168 */
169 static void
170 vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,
171 GLuint divisor)
172 {
173 struct gl_vertex_array_object *vao = ctx->Array.VAO;
174 struct gl_vertex_buffer_binding *binding =
175 &vao->VertexBinding[bindingIndex];
176
177 if (binding->InstanceDivisor != divisor) {
178 FLUSH_VERTICES(ctx, _NEW_ARRAY);
179 binding->InstanceDivisor = divisor;
180 vao->NewArrays |= binding->_BoundArrays;
181 }
182 }
183
184
185 /**
186 * Examine the API profile and extensions to determine which types are legal
187 * for vertex arrays. This is called once from update_array_format().
188 */
189 static GLbitfield
190 get_legal_types_mask(const struct gl_context *ctx)
191 {
192 GLbitfield legalTypesMask = ALL_TYPE_BITS;
193
194 if (_mesa_is_gles(ctx)) {
195 legalTypesMask &= ~(FIXED_GL_BIT |
196 DOUBLE_BIT |
197 UNSIGNED_INT_10F_11F_11F_REV_BIT);
198
199 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
200 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
201 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
202 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
203 * quite as trivial as we'd like because it uses a different enum value
204 * for GL_HALF_FLOAT_OES.
205 */
206 if (ctx->Version < 30) {
207 legalTypesMask &= ~(UNSIGNED_INT_BIT |
208 INT_BIT |
209 UNSIGNED_INT_2_10_10_10_REV_BIT |
210 INT_2_10_10_10_REV_BIT |
211 HALF_BIT);
212 }
213 }
214 else {
215 legalTypesMask &= ~FIXED_ES_BIT;
216
217 if (!ctx->Extensions.ARB_ES2_compatibility)
218 legalTypesMask &= ~FIXED_GL_BIT;
219
220 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
221 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
222 INT_2_10_10_10_REV_BIT);
223
224 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
225 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
226 }
227
228 return legalTypesMask;
229 }
230
231
232 /**
233 * Does error checking and updates the format in an attrib array.
234 *
235 * Called by update_array() and VertexAttrib*Format().
236 *
237 * \param func Name of calling function used for error reporting
238 * \param attrib The index of the attribute array
239 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
240 * \param sizeMin Min allowable size value
241 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
242 * \param size Components per element (1, 2, 3 or 4)
243 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
244 * \param normalized Whether integer types are converted to floats in [-1, 1]
245 * \param integer Integer-valued values (will not be normalized to [-1, 1])
246 * \param doubles Double values not reduced to floats
247 * \param relativeOffset Offset of the first element relative to the binding offset.
248 */
249 static bool
250 update_array_format(struct gl_context *ctx,
251 const char *func,
252 GLuint attrib, GLbitfield legalTypesMask,
253 GLint sizeMin, GLint sizeMax,
254 GLint size, GLenum type,
255 GLboolean normalized, GLboolean integer, GLboolean doubles,
256 GLuint relativeOffset)
257 {
258 struct gl_vertex_attrib_array *array;
259 GLbitfield typeBit;
260 GLint elementSize;
261 GLenum format = GL_RGBA;
262
263 if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
264 /* Compute the LegalTypesMask only once, unless the context API has
265 * changed, in which case we want to compute it again. We can't do this
266 * in _mesa_init_varrays() below because extensions are not yet enabled
267 * at that point.
268 */
269 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
270 ctx->Array.LegalTypesMaskAPI = ctx->API;
271 }
272
273 legalTypesMask &= ctx->Array.LegalTypesMask;
274
275 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
276 /* BGRA ordering is not supported in ES contexts.
277 */
278 sizeMax = 4;
279 }
280
281 typeBit = type_to_bit(ctx, type);
282 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
283 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
284 func, _mesa_lookup_enum_by_nr(type));
285 return false;
286 }
287
288 /* Do size parameter checking.
289 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
290 * must be handled specially.
291 */
292 if (ctx->Extensions.EXT_vertex_array_bgra &&
293 sizeMax == BGRA_OR_4 &&
294 size == GL_BGRA) {
295 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
296 *
297 * "An INVALID_OPERATION error is generated under any of the following
298 * conditions:
299 * ...
300 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
301 * or UNSIGNED_INT_2_10_10_10_REV;
302 * ...
303 * • size is BGRA and normalized is FALSE;"
304 */
305 bool bgra_error = false;
306
307 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
308 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
309 type != GL_INT_2_10_10_10_REV &&
310 type != GL_UNSIGNED_BYTE)
311 bgra_error = true;
312 } else if (type != GL_UNSIGNED_BYTE)
313 bgra_error = true;
314
315 if (bgra_error) {
316 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
317 func, _mesa_lookup_enum_by_nr(type));
318 return false;
319 }
320
321 if (!normalized) {
322 _mesa_error(ctx, GL_INVALID_OPERATION,
323 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
324 return false;
325 }
326
327 format = GL_BGRA;
328 size = 4;
329 }
330 else if (size < sizeMin || size > sizeMax || size > 4) {
331 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
332 return false;
333 }
334
335 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
336 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
337 type == GL_INT_2_10_10_10_REV) && size != 4) {
338 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
339 return false;
340 }
341
342 /* The ARB_vertex_attrib_binding_spec says:
343 *
344 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
345 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
346 */
347 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
348 _mesa_error(ctx, GL_INVALID_VALUE,
349 "%s(relativeOffset=%d > "
350 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
351 func, relativeOffset);
352 return false;
353 }
354
355 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
356 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
357 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
358 return false;
359 }
360
361 assert(size <= 4);
362
363 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
364 assert(elementSize != -1);
365
366 array = &ctx->Array.VAO->VertexAttrib[attrib];
367 array->Size = size;
368 array->Type = type;
369 array->Format = format;
370 array->Normalized = normalized;
371 array->Integer = integer;
372 array->Doubles = doubles;
373 array->RelativeOffset = relativeOffset;
374 array->_ElementSize = elementSize;
375
376 ctx->Array.VAO->NewArrays |= VERT_BIT(attrib);
377 ctx->NewState |= _NEW_ARRAY;
378
379 return true;
380 }
381
382
383 /**
384 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
385 * functions.
386 *
387 * \param func name of calling function used for error reporting
388 * \param attrib the attribute array index to update
389 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
390 * \param sizeMin min allowable size value
391 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
392 * \param size components per element (1, 2, 3 or 4)
393 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
394 * \param stride stride between elements, in elements
395 * \param normalized are integer types converted to floats in [-1, 1]?
396 * \param integer integer-valued values (will not be normalized to [-1,1])
397 * \param doubles Double values not reduced to floats
398 * \param ptr the address (or offset inside VBO) of the array data
399 */
400 static void
401 update_array(struct gl_context *ctx,
402 const char *func,
403 GLuint attrib, GLbitfield legalTypesMask,
404 GLint sizeMin, GLint sizeMax,
405 GLint size, GLenum type, GLsizei stride,
406 GLboolean normalized, GLboolean integer, GLboolean doubles,
407 const GLvoid *ptr)
408 {
409 struct gl_vertex_attrib_array *array;
410 GLsizei effectiveStride;
411
412 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
413 *
414 * "Client vertex arrays - all vertex array attribute pointers must
415 * refer to buffer objects (section 2.9.2). The default vertex array
416 * object (the name zero) is also deprecated. Calling
417 * VertexAttribPointer when no buffer object or no vertex array object
418 * is bound will generate an INVALID_OPERATION error..."
419 *
420 * The check for VBOs is handled below.
421 */
422 if (ctx->API == API_OPENGL_CORE
423 && (ctx->Array.VAO == ctx->Array.DefaultVAO)) {
424 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
425 func);
426 return;
427 }
428
429 if (stride < 0) {
430 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
431 return;
432 }
433
434 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
435 stride > ctx->Const.MaxVertexAttribStride) {
436 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
437 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
438 return;
439 }
440
441 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
442 *
443 * "An INVALID_OPERATION error is generated under any of the following
444 * conditions:
445 *
446 * ...
447 *
448 * * any of the *Pointer commands specifying the location and
449 * organization of vertex array data are called while zero is bound
450 * to the ARRAY_BUFFER buffer object binding point (see section
451 * 2.9.6), and the pointer argument is not NULL."
452 */
453 if (ptr != NULL && ctx->Array.VAO->ARBsemantics &&
454 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
455 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
456 return;
457 }
458
459 if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin,
460 sizeMax, size, type, normalized, integer, doubles, 0)) {
461 return;
462 }
463
464 /* Reset the vertex attrib binding */
465 vertex_attrib_binding(ctx, attrib, attrib);
466
467 /* The Stride and Ptr fields are not set by update_array_format() */
468 array = &ctx->Array.VAO->VertexAttrib[attrib];
469 array->Stride = stride;
470 array->Ptr = (const GLvoid *) ptr;
471
472 /* Update the vertex buffer binding */
473 effectiveStride = stride != 0 ? stride : array->_ElementSize;
474 bind_vertex_buffer(ctx, attrib, ctx->Array.ArrayBufferObj,
475 (GLintptr) ptr, effectiveStride);
476 }
477
478
479 void GLAPIENTRY
480 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
481 {
482 GET_CURRENT_CONTEXT(ctx);
483 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
484 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
485 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
486 DOUBLE_BIT | HALF_BIT |
487 UNSIGNED_INT_2_10_10_10_REV_BIT |
488 INT_2_10_10_10_REV_BIT);
489
490 FLUSH_VERTICES(ctx, 0);
491
492 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
493 legalTypes, 2, 4,
494 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
495 }
496
497
498 void GLAPIENTRY
499 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
500 {
501 GET_CURRENT_CONTEXT(ctx);
502 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
503 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
504 : (BYTE_BIT | SHORT_BIT | INT_BIT |
505 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
506 UNSIGNED_INT_2_10_10_10_REV_BIT |
507 INT_2_10_10_10_REV_BIT);
508
509 FLUSH_VERTICES(ctx, 0);
510
511 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
512 legalTypes, 3, 3,
513 3, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
514 }
515
516
517 void GLAPIENTRY
518 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
519 {
520 GET_CURRENT_CONTEXT(ctx);
521 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
522 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
523 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
524 SHORT_BIT | UNSIGNED_SHORT_BIT |
525 INT_BIT | UNSIGNED_INT_BIT |
526 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
527 UNSIGNED_INT_2_10_10_10_REV_BIT |
528 INT_2_10_10_10_REV_BIT);
529 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
530
531 FLUSH_VERTICES(ctx, 0);
532
533 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
534 legalTypes, sizeMin, BGRA_OR_4,
535 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
536 }
537
538
539 void GLAPIENTRY
540 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
541 {
542 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
543 GET_CURRENT_CONTEXT(ctx);
544
545 FLUSH_VERTICES(ctx, 0);
546
547 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
548 legalTypes, 1, 1,
549 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
550 }
551
552
553 void GLAPIENTRY
554 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
555 {
556 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
557 FLOAT_BIT | DOUBLE_BIT);
558 GET_CURRENT_CONTEXT(ctx);
559
560 FLUSH_VERTICES(ctx, 0);
561
562 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
563 legalTypes, 1, 1,
564 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
565 }
566
567
568 void GLAPIENTRY
569 _mesa_SecondaryColorPointer(GLint size, GLenum type,
570 GLsizei stride, const GLvoid *ptr)
571 {
572 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
573 SHORT_BIT | UNSIGNED_SHORT_BIT |
574 INT_BIT | UNSIGNED_INT_BIT |
575 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
576 UNSIGNED_INT_2_10_10_10_REV_BIT |
577 INT_2_10_10_10_REV_BIT);
578 GET_CURRENT_CONTEXT(ctx);
579
580 FLUSH_VERTICES(ctx, 0);
581
582 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
583 legalTypes, 3, BGRA_OR_4,
584 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
585 }
586
587
588 void GLAPIENTRY
589 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
590 const GLvoid *ptr)
591 {
592 GET_CURRENT_CONTEXT(ctx);
593 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
594 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
595 : (SHORT_BIT | INT_BIT |
596 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
597 UNSIGNED_INT_2_10_10_10_REV_BIT |
598 INT_2_10_10_10_REV_BIT);
599 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
600 const GLuint unit = ctx->Array.ActiveTexture;
601
602 FLUSH_VERTICES(ctx, 0);
603
604 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
605 legalTypes, sizeMin, 4,
606 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
607 ptr);
608 }
609
610
611 void GLAPIENTRY
612 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
613 {
614 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
615 /* this is the same type that glEdgeFlag uses */
616 const GLboolean integer = GL_FALSE;
617 GET_CURRENT_CONTEXT(ctx);
618
619 FLUSH_VERTICES(ctx, 0);
620
621 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
622 legalTypes, 1, 1,
623 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, GL_FALSE, ptr);
624 }
625
626
627 void GLAPIENTRY
628 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
629 {
630 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
631 GET_CURRENT_CONTEXT(ctx);
632
633 FLUSH_VERTICES(ctx, 0);
634
635 if (ctx->API != API_OPENGLES) {
636 _mesa_error(ctx, GL_INVALID_OPERATION,
637 "glPointSizePointer(ES 1.x only)");
638 return;
639 }
640
641 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
642 legalTypes, 1, 1,
643 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
644 }
645
646
647 /**
648 * Set a generic vertex attribute array.
649 * Note that these arrays DO NOT alias the conventional GL vertex arrays
650 * (position, normal, color, fog, texcoord, etc).
651 */
652 void GLAPIENTRY
653 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
654 GLboolean normalized,
655 GLsizei stride, const GLvoid *ptr)
656 {
657 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
658 SHORT_BIT | UNSIGNED_SHORT_BIT |
659 INT_BIT | UNSIGNED_INT_BIT |
660 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
661 FIXED_ES_BIT | FIXED_GL_BIT |
662 UNSIGNED_INT_2_10_10_10_REV_BIT |
663 INT_2_10_10_10_REV_BIT |
664 UNSIGNED_INT_10F_11F_11F_REV_BIT);
665 GET_CURRENT_CONTEXT(ctx);
666
667 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
668 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
669 return;
670 }
671
672 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
673 legalTypes, 1, BGRA_OR_4,
674 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
675 }
676
677
678 /**
679 * GL_EXT_gpu_shader4 / GL 3.0.
680 * Set an integer-valued vertex attribute array.
681 * Note that these arrays DO NOT alias the conventional GL vertex arrays
682 * (position, normal, color, fog, texcoord, etc).
683 */
684 void GLAPIENTRY
685 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
686 GLsizei stride, const GLvoid *ptr)
687 {
688 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
689 SHORT_BIT | UNSIGNED_SHORT_BIT |
690 INT_BIT | UNSIGNED_INT_BIT);
691 const GLboolean normalized = GL_FALSE;
692 const GLboolean integer = GL_TRUE;
693 GET_CURRENT_CONTEXT(ctx);
694
695 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
696 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
697 return;
698 }
699
700 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
701 legalTypes, 1, 4,
702 size, type, stride, normalized, integer, GL_FALSE, ptr);
703 }
704
705 void GLAPIENTRY
706 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
707 GLsizei stride, const GLvoid *ptr)
708 {
709 GET_CURRENT_CONTEXT(ctx);
710 const GLbitfield legalTypes = (DOUBLE_BIT);
711 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
712 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
713 return;
714 }
715
716 update_array(ctx, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index),
717 legalTypes, 1, 4,
718 size, type, stride, GL_TRUE, GL_FALSE, GL_TRUE, ptr);
719 }
720
721 void GLAPIENTRY
722 _mesa_EnableVertexAttribArray(GLuint index)
723 {
724 struct gl_vertex_array_object *vao;
725 GET_CURRENT_CONTEXT(ctx);
726
727 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
728 _mesa_error(ctx, GL_INVALID_VALUE,
729 "glEnableVertexAttribArrayARB(index)");
730 return;
731 }
732
733 vao = ctx->Array.VAO;
734
735 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
736
737 if (!vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
738 /* was disabled, now being enabled */
739 FLUSH_VERTICES(ctx, _NEW_ARRAY);
740 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
741 vao->_Enabled |= VERT_BIT_GENERIC(index);
742 vao->NewArrays |= VERT_BIT_GENERIC(index);
743 }
744 }
745
746
747 void GLAPIENTRY
748 _mesa_DisableVertexAttribArray(GLuint index)
749 {
750 struct gl_vertex_array_object *vao;
751 GET_CURRENT_CONTEXT(ctx);
752
753 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
754 _mesa_error(ctx, GL_INVALID_VALUE,
755 "glDisableVertexAttribArrayARB(index)");
756 return;
757 }
758
759 vao = ctx->Array.VAO;
760
761 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
762
763 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
764 /* was enabled, now being disabled */
765 FLUSH_VERTICES(ctx, _NEW_ARRAY);
766 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
767 vao->_Enabled &= ~VERT_BIT_GENERIC(index);
768 vao->NewArrays |= VERT_BIT_GENERIC(index);
769 }
770 }
771
772
773 /**
774 * Return info for a vertex attribute array (no alias with legacy
775 * vertex attributes (pos, normal, color, etc)). This function does
776 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
777 */
778 static GLuint
779 get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
780 const char *caller)
781 {
782 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
783 const struct gl_vertex_attrib_array *array;
784
785 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
786 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
787 return 0;
788 }
789
790 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
791
792 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
793
794 switch (pname) {
795 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
796 return array->Enabled;
797 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
798 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
799 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
800 return array->Stride;
801 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
802 return array->Type;
803 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
804 return array->Normalized;
805 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
806 return vao->VertexBinding[array->VertexBinding].BufferObj->Name;
807 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
808 if ((_mesa_is_desktop_gl(ctx)
809 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
810 || _mesa_is_gles3(ctx)) {
811 return array->Integer;
812 }
813 goto error;
814 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
815 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
816 || _mesa_is_gles3(ctx)) {
817 return vao->VertexBinding[array->VertexBinding].InstanceDivisor;
818 }
819 goto error;
820 case GL_VERTEX_ATTRIB_BINDING:
821 if (_mesa_is_desktop_gl(ctx)) {
822 return array->VertexBinding - VERT_ATTRIB_GENERIC0;
823 }
824 goto error;
825 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
826 if (_mesa_is_desktop_gl(ctx)) {
827 return array->RelativeOffset;
828 }
829 goto error;
830 default:
831 ; /* fall-through */
832 }
833
834 error:
835 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
836 return 0;
837 }
838
839
840 static const GLfloat *
841 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
842 {
843 if (index == 0) {
844 if (_mesa_attr_zero_aliases_vertex(ctx)) {
845 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
846 return NULL;
847 }
848 }
849 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
850 _mesa_error(ctx, GL_INVALID_VALUE,
851 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
852 return NULL;
853 }
854
855 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
856
857 FLUSH_CURRENT(ctx, 0);
858 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
859 }
860
861 void GLAPIENTRY
862 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
863 {
864 GET_CURRENT_CONTEXT(ctx);
865
866 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
867 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
868 if (v != NULL) {
869 COPY_4V(params, v);
870 }
871 }
872 else {
873 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
874 "glGetVertexAttribfv");
875 }
876 }
877
878
879 void GLAPIENTRY
880 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
881 {
882 GET_CURRENT_CONTEXT(ctx);
883
884 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
885 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
886 if (v != NULL) {
887 params[0] = (GLdouble) v[0];
888 params[1] = (GLdouble) v[1];
889 params[2] = (GLdouble) v[2];
890 params[3] = (GLdouble) v[3];
891 }
892 }
893 else {
894 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
895 "glGetVertexAttribdv");
896 }
897 }
898
899 void GLAPIENTRY
900 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
901 {
902 GET_CURRENT_CONTEXT(ctx);
903
904 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
905 const GLdouble *v = (const GLdouble *)get_current_attrib(ctx, index, "glGetVertexAttribLdv");
906 if (v != NULL) {
907 params[0] = v[0];
908 params[1] = v[1];
909 params[2] = v[2];
910 params[3] = v[3];
911 }
912 }
913 else {
914 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
915 "glGetVertexAttribLdv");
916 }
917 }
918
919 void GLAPIENTRY
920 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
921 {
922 GET_CURRENT_CONTEXT(ctx);
923
924 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
925 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
926 if (v != NULL) {
927 /* XXX should floats in[0,1] be scaled to full int range? */
928 params[0] = (GLint) v[0];
929 params[1] = (GLint) v[1];
930 params[2] = (GLint) v[2];
931 params[3] = (GLint) v[3];
932 }
933 }
934 else {
935 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
936 "glGetVertexAttribiv");
937 }
938 }
939
940
941 /** GL 3.0 */
942 void GLAPIENTRY
943 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
944 {
945 GET_CURRENT_CONTEXT(ctx);
946
947 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
948 const GLint *v = (const GLint *)
949 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
950 if (v != NULL) {
951 COPY_4V(params, v);
952 }
953 }
954 else {
955 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
956 "glGetVertexAttribIiv");
957 }
958 }
959
960
961 /** GL 3.0 */
962 void GLAPIENTRY
963 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
964 {
965 GET_CURRENT_CONTEXT(ctx);
966
967 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
968 const GLuint *v = (const GLuint *)
969 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
970 if (v != NULL) {
971 COPY_4V(params, v);
972 }
973 }
974 else {
975 params[0] = get_vertex_array_attrib(ctx, index, pname,
976 "glGetVertexAttribIuiv");
977 }
978 }
979
980
981 void GLAPIENTRY
982 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
983 {
984 GET_CURRENT_CONTEXT(ctx);
985
986 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
987 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
988 return;
989 }
990
991 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
992 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
993 return;
994 }
995
996 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
997
998 *pointer = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
999 }
1000
1001
1002 void GLAPIENTRY
1003 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1004 GLsizei count, const GLvoid *ptr)
1005 {
1006 (void) count;
1007 _mesa_VertexPointer(size, type, stride, ptr);
1008 }
1009
1010
1011 void GLAPIENTRY
1012 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1013 const GLvoid *ptr)
1014 {
1015 (void) count;
1016 _mesa_NormalPointer(type, stride, ptr);
1017 }
1018
1019
1020 void GLAPIENTRY
1021 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1022 const GLvoid *ptr)
1023 {
1024 (void) count;
1025 _mesa_ColorPointer(size, type, stride, ptr);
1026 }
1027
1028
1029 void GLAPIENTRY
1030 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1031 const GLvoid *ptr)
1032 {
1033 (void) count;
1034 _mesa_IndexPointer(type, stride, ptr);
1035 }
1036
1037
1038 void GLAPIENTRY
1039 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1040 GLsizei count, const GLvoid *ptr)
1041 {
1042 (void) count;
1043 _mesa_TexCoordPointer(size, type, stride, ptr);
1044 }
1045
1046
1047 void GLAPIENTRY
1048 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1049 {
1050 (void) count;
1051 _mesa_EdgeFlagPointer(stride, ptr);
1052 }
1053
1054
1055 void GLAPIENTRY
1056 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1057 {
1058 GET_CURRENT_CONTEXT(ctx);
1059 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1060 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1061 GLenum ctype = 0; /* color type */
1062 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1063 const GLint toffset = 0; /* always zero */
1064 GLint defstride; /* default stride */
1065 GLint c, f;
1066
1067 FLUSH_VERTICES(ctx, 0);
1068
1069 f = sizeof(GLfloat);
1070 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1071
1072 if (stride < 0) {
1073 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1074 return;
1075 }
1076
1077 switch (format) {
1078 case GL_V2F:
1079 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1080 tcomps = 0; ccomps = 0; vcomps = 2;
1081 voffset = 0;
1082 defstride = 2*f;
1083 break;
1084 case GL_V3F:
1085 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1086 tcomps = 0; ccomps = 0; vcomps = 3;
1087 voffset = 0;
1088 defstride = 3*f;
1089 break;
1090 case GL_C4UB_V2F:
1091 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1092 tcomps = 0; ccomps = 4; vcomps = 2;
1093 ctype = GL_UNSIGNED_BYTE;
1094 coffset = 0;
1095 voffset = c;
1096 defstride = c + 2*f;
1097 break;
1098 case GL_C4UB_V3F:
1099 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1100 tcomps = 0; ccomps = 4; vcomps = 3;
1101 ctype = GL_UNSIGNED_BYTE;
1102 coffset = 0;
1103 voffset = c;
1104 defstride = c + 3*f;
1105 break;
1106 case GL_C3F_V3F:
1107 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1108 tcomps = 0; ccomps = 3; vcomps = 3;
1109 ctype = GL_FLOAT;
1110 coffset = 0;
1111 voffset = 3*f;
1112 defstride = 6*f;
1113 break;
1114 case GL_N3F_V3F:
1115 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1116 tcomps = 0; ccomps = 0; vcomps = 3;
1117 noffset = 0;
1118 voffset = 3*f;
1119 defstride = 6*f;
1120 break;
1121 case GL_C4F_N3F_V3F:
1122 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1123 tcomps = 0; ccomps = 4; vcomps = 3;
1124 ctype = GL_FLOAT;
1125 coffset = 0;
1126 noffset = 4*f;
1127 voffset = 7*f;
1128 defstride = 10*f;
1129 break;
1130 case GL_T2F_V3F:
1131 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1132 tcomps = 2; ccomps = 0; vcomps = 3;
1133 voffset = 2*f;
1134 defstride = 5*f;
1135 break;
1136 case GL_T4F_V4F:
1137 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1138 tcomps = 4; ccomps = 0; vcomps = 4;
1139 voffset = 4*f;
1140 defstride = 8*f;
1141 break;
1142 case GL_T2F_C4UB_V3F:
1143 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1144 tcomps = 2; ccomps = 4; vcomps = 3;
1145 ctype = GL_UNSIGNED_BYTE;
1146 coffset = 2*f;
1147 voffset = c+2*f;
1148 defstride = c+5*f;
1149 break;
1150 case GL_T2F_C3F_V3F:
1151 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1152 tcomps = 2; ccomps = 3; vcomps = 3;
1153 ctype = GL_FLOAT;
1154 coffset = 2*f;
1155 voffset = 5*f;
1156 defstride = 8*f;
1157 break;
1158 case GL_T2F_N3F_V3F:
1159 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1160 tcomps = 2; ccomps = 0; vcomps = 3;
1161 noffset = 2*f;
1162 voffset = 5*f;
1163 defstride = 8*f;
1164 break;
1165 case GL_T2F_C4F_N3F_V3F:
1166 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1167 tcomps = 2; ccomps = 4; vcomps = 3;
1168 ctype = GL_FLOAT;
1169 coffset = 2*f;
1170 noffset = 6*f;
1171 voffset = 9*f;
1172 defstride = 12*f;
1173 break;
1174 case GL_T4F_C4F_N3F_V4F:
1175 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1176 tcomps = 4; ccomps = 4; vcomps = 4;
1177 ctype = GL_FLOAT;
1178 coffset = 4*f;
1179 noffset = 8*f;
1180 voffset = 11*f;
1181 defstride = 15*f;
1182 break;
1183 default:
1184 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1185 return;
1186 }
1187
1188 if (stride==0) {
1189 stride = defstride;
1190 }
1191
1192 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1193 _mesa_DisableClientState( GL_INDEX_ARRAY );
1194 /* XXX also disable secondary color and generic arrays? */
1195
1196 /* Texcoords */
1197 if (tflag) {
1198 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1199 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1200 (GLubyte *) pointer + toffset );
1201 }
1202 else {
1203 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1204 }
1205
1206 /* Color */
1207 if (cflag) {
1208 _mesa_EnableClientState( GL_COLOR_ARRAY );
1209 _mesa_ColorPointer( ccomps, ctype, stride,
1210 (GLubyte *) pointer + coffset );
1211 }
1212 else {
1213 _mesa_DisableClientState( GL_COLOR_ARRAY );
1214 }
1215
1216
1217 /* Normals */
1218 if (nflag) {
1219 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1220 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1221 }
1222 else {
1223 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1224 }
1225
1226 /* Vertices */
1227 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1228 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1229 (GLubyte *) pointer + voffset );
1230 }
1231
1232
1233 void GLAPIENTRY
1234 _mesa_LockArraysEXT(GLint first, GLsizei count)
1235 {
1236 GET_CURRENT_CONTEXT(ctx);
1237
1238 FLUSH_VERTICES(ctx, 0);
1239
1240 if (MESA_VERBOSE & VERBOSE_API)
1241 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1242
1243 if (first < 0) {
1244 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1245 return;
1246 }
1247 if (count <= 0) {
1248 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1249 return;
1250 }
1251 if (ctx->Array.LockCount != 0) {
1252 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1253 return;
1254 }
1255
1256 ctx->Array.LockFirst = first;
1257 ctx->Array.LockCount = count;
1258
1259 ctx->NewState |= _NEW_ARRAY;
1260 }
1261
1262
1263 void GLAPIENTRY
1264 _mesa_UnlockArraysEXT( void )
1265 {
1266 GET_CURRENT_CONTEXT(ctx);
1267
1268 FLUSH_VERTICES(ctx, 0);
1269
1270 if (MESA_VERBOSE & VERBOSE_API)
1271 _mesa_debug(ctx, "glUnlockArrays\n");
1272
1273 if (ctx->Array.LockCount == 0) {
1274 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1275 return;
1276 }
1277
1278 ctx->Array.LockFirst = 0;
1279 ctx->Array.LockCount = 0;
1280 ctx->NewState |= _NEW_ARRAY;
1281 }
1282
1283
1284 /* GL_EXT_multi_draw_arrays */
1285 void GLAPIENTRY
1286 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
1287 const GLsizei *count, GLsizei primcount )
1288 {
1289 GET_CURRENT_CONTEXT(ctx);
1290 GLint i;
1291
1292 FLUSH_VERTICES(ctx, 0);
1293
1294 for (i = 0; i < primcount; i++) {
1295 if (count[i] > 0) {
1296 CALL_DrawArrays(ctx->CurrentDispatch, (mode, first[i], count[i]));
1297 }
1298 }
1299 }
1300
1301
1302 /* GL_IBM_multimode_draw_arrays */
1303 void GLAPIENTRY
1304 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1305 const GLsizei * count,
1306 GLsizei primcount, GLint modestride )
1307 {
1308 GET_CURRENT_CONTEXT(ctx);
1309 GLint i;
1310
1311 FLUSH_VERTICES(ctx, 0);
1312
1313 for ( i = 0 ; i < primcount ; i++ ) {
1314 if ( count[i] > 0 ) {
1315 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1316 CALL_DrawArrays(ctx->CurrentDispatch, ( m, first[i], count[i] ));
1317 }
1318 }
1319 }
1320
1321
1322 /* GL_IBM_multimode_draw_arrays */
1323 void GLAPIENTRY
1324 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1325 GLenum type, const GLvoid * const * indices,
1326 GLsizei primcount, GLint modestride )
1327 {
1328 GET_CURRENT_CONTEXT(ctx);
1329 GLint i;
1330
1331 FLUSH_VERTICES(ctx, 0);
1332
1333 /* XXX not sure about ARB_vertex_buffer_object handling here */
1334
1335 for ( i = 0 ; i < primcount ; i++ ) {
1336 if ( count[i] > 0 ) {
1337 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1338 CALL_DrawElements(ctx->CurrentDispatch, ( m, count[i], type,
1339 indices[i] ));
1340 }
1341 }
1342 }
1343
1344
1345 /**
1346 * GL_NV_primitive_restart and GL 3.1
1347 */
1348 void GLAPIENTRY
1349 _mesa_PrimitiveRestartIndex(GLuint index)
1350 {
1351 GET_CURRENT_CONTEXT(ctx);
1352
1353 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1354 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1355 return;
1356 }
1357
1358 if (ctx->Array.RestartIndex != index) {
1359 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1360 ctx->Array.RestartIndex = index;
1361 }
1362 }
1363
1364
1365 /**
1366 * See GL_ARB_instanced_arrays.
1367 * Note that the instance divisor only applies to generic arrays, not
1368 * the legacy vertex arrays.
1369 */
1370 void GLAPIENTRY
1371 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1372 {
1373 GET_CURRENT_CONTEXT(ctx);
1374
1375 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1376
1377 if (!ctx->Extensions.ARB_instanced_arrays) {
1378 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1379 return;
1380 }
1381
1382 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1383 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
1384 index);
1385 return;
1386 }
1387
1388 assert(genericIndex < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1389
1390 /* The ARB_vertex_attrib_binding spec says:
1391 *
1392 * "The command
1393 *
1394 * void VertexAttribDivisor(uint index, uint divisor);
1395 *
1396 * is equivalent to (assuming no errors are generated):
1397 *
1398 * VertexAttribBinding(index, index);
1399 * VertexBindingDivisor(index, divisor);"
1400 */
1401 vertex_attrib_binding(ctx, genericIndex, genericIndex);
1402 vertex_binding_divisor(ctx, genericIndex, divisor);
1403 }
1404
1405
1406 unsigned
1407 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1408 {
1409 /* From the OpenGL 4.3 core specification, page 302:
1410 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1411 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1412 * is used."
1413 */
1414 if (ctx->Array.PrimitiveRestartFixedIndex) {
1415 switch (ib_type) {
1416 case GL_UNSIGNED_BYTE:
1417 return 0xff;
1418 case GL_UNSIGNED_SHORT:
1419 return 0xffff;
1420 case GL_UNSIGNED_INT:
1421 return 0xffffffff;
1422 default:
1423 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1424 }
1425 }
1426
1427 return ctx->Array.RestartIndex;
1428 }
1429
1430
1431 /**
1432 * GL_ARB_vertex_attrib_binding
1433 */
1434 void GLAPIENTRY
1435 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1436 GLsizei stride)
1437 {
1438 GET_CURRENT_CONTEXT(ctx);
1439 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
1440 struct gl_buffer_object *vbo;
1441
1442 ASSERT_OUTSIDE_BEGIN_END(ctx);
1443
1444 /* The ARB_vertex_attrib_binding spec says:
1445 *
1446 * "An INVALID_OPERATION error is generated if no vertex array object
1447 * is bound."
1448 */
1449 if (ctx->API == API_OPENGL_CORE &&
1450 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1451 _mesa_error(ctx, GL_INVALID_OPERATION,
1452 "glBindVertexBuffer(No array object bound)");
1453 return;
1454 }
1455
1456 /* The ARB_vertex_attrib_binding spec says:
1457 *
1458 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1459 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1460 */
1461 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1462 _mesa_error(ctx, GL_INVALID_VALUE,
1463 "glBindVertexBuffer(bindingindex=%u > "
1464 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1465 bindingIndex);
1466 return;
1467 }
1468
1469 /* The ARB_vertex_attrib_binding spec says:
1470 *
1471 * "The error INVALID_VALUE is generated if <stride> or <offset>
1472 * are negative."
1473 */
1474 if (offset < 0) {
1475 _mesa_error(ctx, GL_INVALID_VALUE,
1476 "glBindVertexBuffer(offset=%" PRId64 " < 0)",
1477 (int64_t) offset);
1478 return;
1479 }
1480
1481 if (stride < 0) {
1482 _mesa_error(ctx, GL_INVALID_VALUE,
1483 "glBindVertexBuffer(stride=%d < 0)", stride);
1484 return;
1485 }
1486
1487 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1488 stride > ctx->Const.MaxVertexAttribStride) {
1489 _mesa_error(ctx, GL_INVALID_VALUE, "glBindVertexBuffer(stride=%d > "
1490 "GL_MAX_VERTEX_ATTRIB_STRIDE)", stride);
1491 return;
1492 }
1493
1494 if (buffer == vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1495 vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
1496 } else if (buffer != 0) {
1497 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1498
1499 /* From the GL_ARB_vertex_attrib_array spec:
1500 *
1501 * "[Core profile only:]
1502 * An INVALID_OPERATION error is generated if buffer is not zero or a
1503 * name returned from a previous call to GenBuffers, or if such a name
1504 * has since been deleted with DeleteBuffers.
1505 *
1506 * Otherwise, we fall back to the same compat profile behavior as other
1507 * object references (automatically gen it).
1508 */
1509 if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer,
1510 &vbo, "glBindVertexBuffer"))
1511 return;
1512 } else {
1513 /* The ARB_vertex_attrib_binding spec says:
1514 *
1515 * "If <buffer> is zero, any buffer object attached to this
1516 * bindpoint is detached."
1517 */
1518 vbo = ctx->Shared->NullBufferObj;
1519 }
1520
1521 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(bindingIndex),
1522 vbo, offset, stride);
1523 }
1524
1525
1526 void GLAPIENTRY
1527 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
1528 const GLintptr *offsets, const GLsizei *strides)
1529 {
1530 GET_CURRENT_CONTEXT(ctx);
1531 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1532 GLuint i;
1533
1534 ASSERT_OUTSIDE_BEGIN_END(ctx);
1535
1536 /* The ARB_vertex_attrib_binding spec says:
1537 *
1538 * "An INVALID_OPERATION error is generated if no
1539 * vertex array object is bound."
1540 */
1541 if (ctx->API == API_OPENGL_CORE &&
1542 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1543 _mesa_error(ctx, GL_INVALID_OPERATION,
1544 "glBindVertexBuffers(No array object bound)");
1545 return;
1546 }
1547
1548 /* The ARB_multi_bind spec says:
1549 *
1550 * "An INVALID_OPERATION error is generated if <first> + <count>
1551 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1552 */
1553 if (first + count > ctx->Const.MaxVertexAttribBindings) {
1554 _mesa_error(ctx, GL_INVALID_OPERATION,
1555 "glBindVertexBuffers(first=%u + count=%d > the value of "
1556 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1557 first, count, ctx->Const.MaxVertexAttribBindings);
1558 return;
1559 }
1560
1561 if (!buffers) {
1562 /**
1563 * The ARB_multi_bind spec says:
1564 *
1565 * "If <buffers> is NULL, each affected vertex buffer binding point
1566 * from <first> through <first>+<count>-1 will be reset to have no
1567 * bound buffer object. In this case, the offsets and strides
1568 * associated with the binding points are set to default values,
1569 * ignoring <offsets> and <strides>."
1570 */
1571 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
1572
1573 for (i = 0; i < count; i++)
1574 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo, 0, 16);
1575
1576 return;
1577 }
1578
1579 /* Note that the error semantics for multi-bind commands differ from
1580 * those of other GL commands.
1581 *
1582 * The Issues section in the ARB_multi_bind spec says:
1583 *
1584 * "(11) Typically, OpenGL specifies that if an error is generated by
1585 * a command, that command has no effect. This is somewhat
1586 * unfortunate for multi-bind commands, because it would require
1587 * a first pass to scan the entire list of bound objects for
1588 * errors and then a second pass to actually perform the
1589 * bindings. Should we have different error semantics?
1590 *
1591 * RESOLVED: Yes. In this specification, when the parameters for
1592 * one of the <count> binding points are invalid, that binding
1593 * point is not updated and an error will be generated. However,
1594 * other binding points in the same command will be updated if
1595 * their parameters are valid and no other error occurs."
1596 */
1597
1598 _mesa_begin_bufferobj_lookups(ctx);
1599
1600 for (i = 0; i < count; i++) {
1601 struct gl_buffer_object *vbo;
1602
1603 /* The ARB_multi_bind spec says:
1604 *
1605 * "An INVALID_VALUE error is generated if any value in
1606 * <offsets> or <strides> is negative (per binding)."
1607 */
1608 if (offsets[i] < 0) {
1609 _mesa_error(ctx, GL_INVALID_VALUE,
1610 "glBindVertexBuffers(offsets[%u]=%" PRId64 " < 0)",
1611 i, (int64_t) offsets[i]);
1612 continue;
1613 }
1614
1615 if (strides[i] < 0) {
1616 _mesa_error(ctx, GL_INVALID_VALUE,
1617 "glBindVertexBuffers(strides[%u]=%d < 0)",
1618 i, strides[i]);
1619 continue;
1620 }
1621
1622 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1623 strides[i] > ctx->Const.MaxVertexAttribStride) {
1624 _mesa_error(ctx, GL_INVALID_VALUE,
1625 "glBindVertexBuffers(strides[%u]=%d > "
1626 "GL_MAX_VERTEX_ATTRIB_STRIDE)", i, strides[i]);
1627 continue;
1628 }
1629
1630 if (buffers[i]) {
1631 struct gl_vertex_buffer_binding *binding =
1632 &vao->VertexBinding[VERT_ATTRIB_GENERIC(first + i)];
1633
1634 if (buffers[i] == binding->BufferObj->Name)
1635 vbo = binding->BufferObj;
1636 else
1637 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i,
1638 "glBindVertexBuffers");
1639
1640 if (!vbo)
1641 continue;
1642 } else {
1643 vbo = ctx->Shared->NullBufferObj;
1644 }
1645
1646 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo,
1647 offsets[i], strides[i]);
1648 }
1649
1650 _mesa_end_bufferobj_lookups(ctx);
1651 }
1652
1653
1654 void GLAPIENTRY
1655 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1656 GLboolean normalized, GLuint relativeOffset)
1657 {
1658 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1659 SHORT_BIT | UNSIGNED_SHORT_BIT |
1660 INT_BIT | UNSIGNED_INT_BIT |
1661 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1662 FIXED_GL_BIT |
1663 UNSIGNED_INT_2_10_10_10_REV_BIT |
1664 INT_2_10_10_10_REV_BIT |
1665 UNSIGNED_INT_10F_11F_11F_REV_BIT);
1666
1667 GET_CURRENT_CONTEXT(ctx);
1668 ASSERT_OUTSIDE_BEGIN_END(ctx);
1669
1670 /* The ARB_vertex_attrib_binding spec says:
1671 *
1672 * "An INVALID_OPERATION error is generated under any of the following
1673 * conditions:
1674 * - if no vertex array object is currently bound (see section 2.10);
1675 * - ..."
1676 */
1677 if (ctx->API == API_OPENGL_CORE &&
1678 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1679 _mesa_error(ctx, GL_INVALID_OPERATION,
1680 "glVertexAttribFormat(No array object bound)");
1681 return;
1682 }
1683
1684 /* The ARB_vertex_attrib_binding spec says:
1685 *
1686 * "The error INVALID_VALUE is generated if index is greater than or equal
1687 * to the value of MAX_VERTEX_ATTRIBS."
1688 */
1689 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1690 _mesa_error(ctx, GL_INVALID_VALUE,
1691 "glVertexAttribFormat(attribindex=%u > "
1692 "GL_MAX_VERTEX_ATTRIBS)",
1693 attribIndex);
1694 return;
1695 }
1696
1697 FLUSH_VERTICES(ctx, 0);
1698
1699 update_array_format(ctx, "glVertexAttribFormat",
1700 VERT_ATTRIB_GENERIC(attribIndex),
1701 legalTypes, 1, BGRA_OR_4, size, type, normalized,
1702 GL_FALSE, GL_FALSE, relativeOffset);
1703 }
1704
1705
1706 void GLAPIENTRY
1707 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1708 GLuint relativeOffset)
1709 {
1710 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1711 SHORT_BIT | UNSIGNED_SHORT_BIT |
1712 INT_BIT | UNSIGNED_INT_BIT);
1713
1714 GET_CURRENT_CONTEXT(ctx);
1715 ASSERT_OUTSIDE_BEGIN_END(ctx);
1716
1717 /* The ARB_vertex_attrib_binding spec says:
1718 *
1719 * "An INVALID_OPERATION error is generated under any of the following
1720 * conditions:
1721 * - if no vertex array object is currently bound (see section 2.10);
1722 * - ..."
1723 */
1724 if (ctx->API == API_OPENGL_CORE &&
1725 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1726 _mesa_error(ctx, GL_INVALID_OPERATION,
1727 "glVertexAttribIFormat(No array object bound)");
1728 return;
1729 }
1730
1731 /* The ARB_vertex_attrib_binding spec says:
1732 *
1733 * "The error INVALID_VALUE is generated if index is greater than
1734 * or equal to the value of MAX_VERTEX_ATTRIBS."
1735 */
1736 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1737 _mesa_error(ctx, GL_INVALID_VALUE,
1738 "glVertexAttribIFormat(attribindex=%u > "
1739 "GL_MAX_VERTEX_ATTRIBS)",
1740 attribIndex);
1741 return;
1742 }
1743
1744 FLUSH_VERTICES(ctx, 0);
1745
1746 update_array_format(ctx, "glVertexAttribIFormat",
1747 VERT_ATTRIB_GENERIC(attribIndex),
1748 legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE, GL_FALSE,
1749 relativeOffset);
1750 }
1751
1752
1753 void GLAPIENTRY
1754 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
1755 GLuint relativeOffset)
1756 {
1757 const GLbitfield legalTypes = DOUBLE_BIT;
1758
1759 GET_CURRENT_CONTEXT(ctx);
1760 ASSERT_OUTSIDE_BEGIN_END(ctx);
1761
1762 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1763 *
1764 * "An INVALID_OPERATION error is generated under any of the following
1765 * conditions:
1766 * • if no vertex array object is currently bound (see section 10.4);
1767 * • ..."
1768 *
1769 * This language is missing from the extension spec, but we assume
1770 * that this is an oversight.
1771 */
1772 if (ctx->API == API_OPENGL_CORE &&
1773 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1774 _mesa_error(ctx, GL_INVALID_OPERATION,
1775 "glVertexAttribLFormat(No array object bound)");
1776 return;
1777 }
1778
1779 /* The ARB_vertex_attrib_binding spec says:
1780 *
1781 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1782 * or equal to the value of MAX_VERTEX_ATTRIBS."
1783 */
1784 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1785 _mesa_error(ctx, GL_INVALID_VALUE,
1786 "glVertexAttribLFormat(attribindex=%u > "
1787 "GL_MAX_VERTEX_ATTRIBS)",
1788 attribIndex);
1789 return;
1790 }
1791
1792 FLUSH_VERTICES(ctx, 0);
1793
1794 update_array_format(ctx, "glVertexAttribLFormat",
1795 VERT_ATTRIB_GENERIC(attribIndex),
1796 legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE, GL_TRUE,
1797 relativeOffset);
1798 }
1799
1800
1801 void GLAPIENTRY
1802 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
1803 {
1804 GET_CURRENT_CONTEXT(ctx);
1805 ASSERT_OUTSIDE_BEGIN_END(ctx);
1806
1807 /* The ARB_vertex_attrib_binding spec says:
1808 *
1809 * "An INVALID_OPERATION error is generated if no vertex array object
1810 * is bound."
1811 */
1812 if (ctx->API == API_OPENGL_CORE &&
1813 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1814 _mesa_error(ctx, GL_INVALID_OPERATION,
1815 "glVertexAttribBinding(No array object bound)");
1816 return;
1817 }
1818
1819 /* The ARB_vertex_attrib_binding spec says:
1820 *
1821 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1822 * <bindingindex> must be less than the value of
1823 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1824 * is generated."
1825 */
1826 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1827 _mesa_error(ctx, GL_INVALID_VALUE,
1828 "glVertexAttribBinding(attribindex=%u >= "
1829 "GL_MAX_VERTEX_ATTRIBS)",
1830 attribIndex);
1831 return;
1832 }
1833
1834 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1835 _mesa_error(ctx, GL_INVALID_VALUE,
1836 "glVertexAttribBinding(bindingindex=%u >= "
1837 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1838 bindingIndex);
1839 return;
1840 }
1841
1842 assert(VERT_ATTRIB_GENERIC(attribIndex) <
1843 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1844
1845 vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex),
1846 VERT_ATTRIB_GENERIC(bindingIndex));
1847 }
1848
1849
1850 void GLAPIENTRY
1851 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1852 {
1853 GET_CURRENT_CONTEXT(ctx);
1854 ASSERT_OUTSIDE_BEGIN_END(ctx);
1855
1856 if (!ctx->Extensions.ARB_instanced_arrays) {
1857 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()");
1858 return;
1859 }
1860
1861 /* The ARB_vertex_attrib_binding spec says:
1862 *
1863 * "An INVALID_OPERATION error is generated if no vertex array object
1864 * is bound."
1865 */
1866 if (ctx->API == API_OPENGL_CORE &&
1867 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1868 _mesa_error(ctx, GL_INVALID_OPERATION,
1869 "glVertexBindingDivisor(No array object bound)");
1870 return;
1871 }
1872
1873 /* The ARB_vertex_attrib_binding spec says:
1874 *
1875 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1876 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1877 */
1878 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1879 _mesa_error(ctx, GL_INVALID_VALUE,
1880 "glVertexBindingDivisor(bindingindex=%u > "
1881 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1882 bindingIndex);
1883 return;
1884 }
1885
1886 vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
1887 }
1888
1889
1890 /**
1891 * Copy one client vertex array to another.
1892 */
1893 void
1894 _mesa_copy_client_array(struct gl_context *ctx,
1895 struct gl_client_array *dst,
1896 struct gl_client_array *src)
1897 {
1898 dst->Size = src->Size;
1899 dst->Type = src->Type;
1900 dst->Format = src->Format;
1901 dst->Stride = src->Stride;
1902 dst->StrideB = src->StrideB;
1903 dst->Ptr = src->Ptr;
1904 dst->Enabled = src->Enabled;
1905 dst->Normalized = src->Normalized;
1906 dst->Integer = src->Integer;
1907 dst->Doubles = src->Doubles;
1908 dst->InstanceDivisor = src->InstanceDivisor;
1909 dst->_ElementSize = src->_ElementSize;
1910 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1911 }
1912
1913 void
1914 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
1915 struct gl_vertex_attrib_array *dst,
1916 const struct gl_vertex_attrib_array *src)
1917 {
1918 dst->Size = src->Size;
1919 dst->Type = src->Type;
1920 dst->Format = src->Format;
1921 dst->VertexBinding = src->VertexBinding;
1922 dst->RelativeOffset = src->RelativeOffset;
1923 dst->Format = src->Format;
1924 dst->Integer = src->Integer;
1925 dst->Doubles = src->Doubles;
1926 dst->Normalized = src->Normalized;
1927 dst->Ptr = src->Ptr;
1928 dst->Enabled = src->Enabled;
1929 dst->_ElementSize = src->_ElementSize;
1930 }
1931
1932 void
1933 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
1934 struct gl_vertex_buffer_binding *dst,
1935 const struct gl_vertex_buffer_binding *src)
1936 {
1937 dst->Offset = src->Offset;
1938 dst->Stride = src->Stride;
1939 dst->InstanceDivisor = src->InstanceDivisor;
1940 dst->_BoundArrays = src->_BoundArrays;
1941
1942 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1943 }
1944
1945 /**
1946 * Print vertex array's fields.
1947 */
1948 static void
1949 print_array(const char *name, GLint index, const struct gl_client_array *array)
1950 {
1951 if (index >= 0)
1952 fprintf(stderr, " %s[%d]: ", name, index);
1953 else
1954 fprintf(stderr, " %s: ", name);
1955 fprintf(stderr, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
1956 array->Ptr, array->Type, array->Size,
1957 array->_ElementSize, array->StrideB,
1958 array->BufferObj->Name, (unsigned long) array->BufferObj->Size);
1959 }
1960
1961
1962 /**
1963 * Print current vertex object/array info. For debug.
1964 */
1965 void
1966 _mesa_print_arrays(struct gl_context *ctx)
1967 {
1968 struct gl_vertex_array_object *vao = ctx->Array.VAO;
1969 GLuint i;
1970
1971 printf("Array Object %u\n", vao->Name);
1972 if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
1973 print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]);
1974 if (vao->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
1975 print_array("Normal", -1, &vao->_VertexAttrib[VERT_ATTRIB_NORMAL]);
1976 if (vao->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
1977 print_array("Color", -1, &vao->_VertexAttrib[VERT_ATTRIB_COLOR0]);
1978 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
1979 if (vao->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
1980 print_array("TexCoord", i, &vao->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
1981 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
1982 if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
1983 print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
1984 }
1985
1986
1987 /**
1988 * Initialize vertex array state for given context.
1989 */
1990 void
1991 _mesa_init_varray(struct gl_context *ctx)
1992 {
1993 ctx->Array.DefaultVAO = ctx->Driver.NewArrayObject(ctx, 0);
1994 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
1995 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1996
1997 ctx->Array.Objects = _mesa_NewHashTable();
1998 }
1999
2000
2001 /**
2002 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2003 */
2004 static void
2005 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2006 {
2007 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2008 struct gl_context *ctx = (struct gl_context *) userData;
2009 _mesa_delete_vao(ctx, vao);
2010 }
2011
2012
2013 /**
2014 * Free vertex array state for given context.
2015 */
2016 void
2017 _mesa_free_varray_data(struct gl_context *ctx)
2018 {
2019 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2020 _mesa_DeleteHashTable(ctx->Array.Objects);
2021 }