mesa: Track position/generic0 aliasing in the VAO.
[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 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
73 FIXED_GL_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
77
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
81
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
83
84
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
86 static GLbitfield
87 type_to_bit(const struct gl_context *ctx, GLenum type)
88 {
89 switch (type) {
90 case GL_BOOL:
91 return BOOL_BIT;
92 case GL_BYTE:
93 return BYTE_BIT;
94 case GL_UNSIGNED_BYTE:
95 return UNSIGNED_BYTE_BIT;
96 case GL_SHORT:
97 return SHORT_BIT;
98 case GL_UNSIGNED_SHORT:
99 return UNSIGNED_SHORT_BIT;
100 case GL_INT:
101 return INT_BIT;
102 case GL_UNSIGNED_INT:
103 return UNSIGNED_INT_BIT;
104 case GL_HALF_FLOAT:
105 case GL_HALF_FLOAT_OES:
106 if (ctx->Extensions.ARB_half_float_vertex)
107 return HALF_BIT;
108 else
109 return 0x0;
110 case GL_FLOAT:
111 return FLOAT_BIT;
112 case GL_DOUBLE:
113 return DOUBLE_BIT;
114 case GL_FIXED:
115 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
116 case GL_UNSIGNED_INT_2_10_10_10_REV:
117 return UNSIGNED_INT_2_10_10_10_REV_BIT;
118 case GL_INT_2_10_10_10_REV:
119 return INT_2_10_10_10_REV_BIT;
120 case GL_UNSIGNED_INT_10F_11F_11F_REV:
121 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
122 default:
123 return 0;
124 }
125 }
126
127
128 /**
129 * Sets the BufferBindingIndex field for the vertex attribute given by
130 * attribIndex.
131 */
132 static void
133 vertex_attrib_binding(struct gl_context *ctx,
134 struct gl_vertex_array_object *vao,
135 gl_vert_attrib attribIndex,
136 GLuint bindingIndex)
137 {
138 struct gl_array_attributes *array = &vao->VertexAttrib[attribIndex];
139
140 if (array->BufferBindingIndex != bindingIndex) {
141 const GLbitfield array_bit = VERT_BIT(attribIndex);
142
143 if (_mesa_is_bufferobj(vao->BufferBinding[bindingIndex].BufferObj))
144 vao->VertexAttribBufferMask |= array_bit;
145
146 FLUSH_VERTICES(ctx, _NEW_ARRAY);
147
148 vao->BufferBinding[array->BufferBindingIndex]._BoundArrays &= ~array_bit;
149 vao->BufferBinding[bindingIndex]._BoundArrays |= array_bit;
150
151 array->BufferBindingIndex = bindingIndex;
152
153 vao->NewArrays |= array_bit;
154 }
155 }
156
157
158 /**
159 * Binds a buffer object to the vertex buffer binding point given by index,
160 * and sets the Offset and Stride fields.
161 */
162 void
163 _mesa_bind_vertex_buffer(struct gl_context *ctx,
164 struct gl_vertex_array_object *vao,
165 GLuint index,
166 struct gl_buffer_object *vbo,
167 GLintptr offset, GLsizei stride)
168 {
169 assert(index < ARRAY_SIZE(vao->BufferBinding));
170 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
171
172 if (binding->BufferObj != vbo ||
173 binding->Offset != offset ||
174 binding->Stride != stride) {
175
176 FLUSH_VERTICES(ctx, _NEW_ARRAY);
177
178 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
179
180 binding->Offset = offset;
181 binding->Stride = stride;
182
183 if (!_mesa_is_bufferobj(vbo))
184 vao->VertexAttribBufferMask &= ~binding->_BoundArrays;
185 else
186 vao->VertexAttribBufferMask |= binding->_BoundArrays;
187
188 vao->NewArrays |= binding->_BoundArrays;
189 }
190 }
191
192
193 /**
194 * Sets the InstanceDivisor field in the vertex buffer binding point
195 * given by bindingIndex.
196 */
197 static void
198 vertex_binding_divisor(struct gl_context *ctx,
199 struct gl_vertex_array_object *vao,
200 GLuint bindingIndex,
201 GLuint divisor)
202 {
203 struct gl_vertex_buffer_binding *binding =
204 &vao->BufferBinding[bindingIndex];
205
206 if (binding->InstanceDivisor != divisor) {
207 FLUSH_VERTICES(ctx, _NEW_ARRAY);
208 binding->InstanceDivisor = divisor;
209 vao->NewArrays |= binding->_BoundArrays;
210 }
211 }
212
213
214 /**
215 * Examine the API profile and extensions to determine which types are legal
216 * for vertex arrays. This is called once from update_array_format().
217 */
218 static GLbitfield
219 get_legal_types_mask(const struct gl_context *ctx)
220 {
221 GLbitfield legalTypesMask = ALL_TYPE_BITS;
222
223 if (_mesa_is_gles(ctx)) {
224 legalTypesMask &= ~(FIXED_GL_BIT |
225 DOUBLE_BIT |
226 UNSIGNED_INT_10F_11F_11F_REV_BIT);
227
228 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
229 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
230 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
231 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
232 * quite as trivial as we'd like because it uses a different enum value
233 * for GL_HALF_FLOAT_OES.
234 */
235 if (ctx->Version < 30) {
236 legalTypesMask &= ~(UNSIGNED_INT_BIT |
237 INT_BIT |
238 UNSIGNED_INT_2_10_10_10_REV_BIT |
239 INT_2_10_10_10_REV_BIT);
240
241 if (!_mesa_has_OES_vertex_half_float(ctx))
242 legalTypesMask &= ~HALF_BIT;
243 }
244 }
245 else {
246 legalTypesMask &= ~FIXED_ES_BIT;
247
248 if (!ctx->Extensions.ARB_ES2_compatibility)
249 legalTypesMask &= ~FIXED_GL_BIT;
250
251 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
252 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
253 INT_2_10_10_10_REV_BIT);
254
255 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
256 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
257 }
258
259 return legalTypesMask;
260 }
261
262 static GLenum
263 get_array_format(const struct gl_context *ctx, GLint sizeMax, GLint *size)
264 {
265 GLenum format = GL_RGBA;
266
267 /* Do size parameter checking.
268 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
269 * must be handled specially.
270 */
271 if (ctx->Extensions.EXT_vertex_array_bgra && sizeMax == BGRA_OR_4 &&
272 *size == GL_BGRA) {
273 format = GL_BGRA;
274 *size = 4;
275 }
276
277 return format;
278 }
279
280
281 /**
282 * \param attrib The index of the attribute array
283 * \param size Components per element (1, 2, 3 or 4)
284 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
285 * \param format Either GL_RGBA or GL_BGRA.
286 * \param normalized Whether integer types are converted to floats in [-1, 1]
287 * \param integer Integer-valued values (will not be normalized to [-1, 1])
288 * \param doubles Double values not reduced to floats
289 * \param relativeOffset Offset of the first element relative to the binding
290 * offset.
291 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
292 * state?
293 */
294 void
295 _mesa_update_array_format(struct gl_context *ctx,
296 struct gl_vertex_array_object *vao,
297 gl_vert_attrib attrib, GLint size, GLenum type,
298 GLenum format, GLboolean normalized,
299 GLboolean integer, GLboolean doubles,
300 GLuint relativeOffset)
301 {
302 struct gl_array_attributes *const array = &vao->VertexAttrib[attrib];
303 GLint elementSize;
304
305 assert(size <= 4);
306
307 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
308 assert(elementSize != -1);
309
310 array->Size = size;
311 array->Type = type;
312 array->Format = format;
313 array->Normalized = normalized;
314 array->Integer = integer;
315 array->Doubles = doubles;
316 array->RelativeOffset = relativeOffset;
317 array->_ElementSize = elementSize;
318
319 vao->NewArrays |= VERT_BIT(attrib);
320 ctx->NewState |= _NEW_ARRAY;
321 }
322
323 /**
324 * Does error checking of the format in an attrib array.
325 *
326 * Called by *Pointer() and VertexAttrib*Format().
327 *
328 * \param func Name of calling function used for error reporting
329 * \param attrib The index of the attribute array
330 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
331 * \param sizeMin Min allowable size value
332 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
333 * \param size Components per element (1, 2, 3 or 4)
334 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
335 * \param normalized Whether integer types are converted to floats in [-1, 1]
336 * \param integer Integer-valued values (will not be normalized to [-1, 1])
337 * \param doubles Double values not reduced to floats
338 * \param relativeOffset Offset of the first element relative to the binding offset.
339 * \return bool True if validation is successful, False otherwise.
340 */
341 static bool
342 validate_array_format(struct gl_context *ctx, const char *func,
343 struct gl_vertex_array_object *vao,
344 GLuint attrib, GLbitfield legalTypesMask,
345 GLint sizeMin, GLint sizeMax,
346 GLint size, GLenum type, GLboolean normalized,
347 GLboolean integer, GLboolean doubles,
348 GLuint relativeOffset, GLenum format)
349 {
350 GLbitfield typeBit;
351
352 /* at most, one of these bools can be true */
353 assert((int) normalized + (int) integer + (int) doubles <= 1);
354
355 if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
356 /* Compute the LegalTypesMask only once, unless the context API has
357 * changed, in which case we want to compute it again. We can't do this
358 * in _mesa_init_varrays() below because extensions are not yet enabled
359 * at that point.
360 */
361 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
362 ctx->Array.LegalTypesMaskAPI = ctx->API;
363 }
364
365 legalTypesMask &= ctx->Array.LegalTypesMask;
366
367 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
368 /* BGRA ordering is not supported in ES contexts.
369 */
370 sizeMax = 4;
371 }
372
373 typeBit = type_to_bit(ctx, type);
374 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
375 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
376 func, _mesa_enum_to_string(type));
377 return false;
378 }
379
380 if (format == GL_BGRA) {
381 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
382 *
383 * "An INVALID_OPERATION error is generated under any of the following
384 * conditions:
385 * ...
386 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
387 * or UNSIGNED_INT_2_10_10_10_REV;
388 * ...
389 * • size is BGRA and normalized is FALSE;"
390 */
391 bool bgra_error = false;
392
393 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
394 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
395 type != GL_INT_2_10_10_10_REV &&
396 type != GL_UNSIGNED_BYTE)
397 bgra_error = true;
398 } else if (type != GL_UNSIGNED_BYTE)
399 bgra_error = true;
400
401 if (bgra_error) {
402 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
403 func, _mesa_enum_to_string(type));
404 return false;
405 }
406
407 if (!normalized) {
408 _mesa_error(ctx, GL_INVALID_OPERATION,
409 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
410 return false;
411 }
412 }
413 else if (size < sizeMin || size > sizeMax || size > 4) {
414 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
415 return false;
416 }
417
418 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
419 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
420 type == GL_INT_2_10_10_10_REV) && size != 4) {
421 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
422 return false;
423 }
424
425 /* The ARB_vertex_attrib_binding_spec says:
426 *
427 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
428 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
429 */
430 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
431 _mesa_error(ctx, GL_INVALID_VALUE,
432 "%s(relativeOffset=%d > "
433 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
434 func, relativeOffset);
435 return false;
436 }
437
438 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
439 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
440 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
441 return false;
442 }
443
444 return true;
445 }
446
447 /**
448 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
449 *
450 * \param func name of calling function used for error reporting
451 * \param attrib the attribute array index to update
452 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
453 * \param sizeMin min allowable size value
454 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
455 * \param size components per element (1, 2, 3 or 4)
456 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
457 * \param stride stride between elements, in elements
458 * \param normalized are integer types converted to floats in [-1, 1]?
459 * \param integer integer-valued values (will not be normalized to [-1,1])
460 * \param doubles Double values not reduced to floats
461 * \param ptr the address (or offset inside VBO) of the array data
462 */
463 static void
464 validate_array(struct gl_context *ctx, const char *func,
465 GLuint attrib, GLbitfield legalTypesMask,
466 GLint sizeMin, GLint sizeMax,
467 GLint size, GLenum type, GLsizei stride,
468 GLboolean normalized, GLboolean integer, GLboolean doubles,
469 const GLvoid *ptr)
470 {
471 struct gl_vertex_array_object *vao = ctx->Array.VAO;
472
473 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
474 *
475 * "Client vertex arrays - all vertex array attribute pointers must
476 * refer to buffer objects (section 2.9.2). The default vertex array
477 * object (the name zero) is also deprecated. Calling
478 * VertexAttribPointer when no buffer object or no vertex array object
479 * is bound will generate an INVALID_OPERATION error..."
480 *
481 * The check for VBOs is handled below.
482 */
483 if (ctx->API == API_OPENGL_CORE && (vao == ctx->Array.DefaultVAO)) {
484 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
485 func);
486 return;
487 }
488
489 if (stride < 0) {
490 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
491 return;
492 }
493
494 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
495 stride > ctx->Const.MaxVertexAttribStride) {
496 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
497 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
498 return;
499 }
500
501 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
502 *
503 * "An INVALID_OPERATION error is generated under any of the following
504 * conditions:
505 *
506 * ...
507 *
508 * * any of the *Pointer commands specifying the location and
509 * organization of vertex array data are called while zero is bound
510 * to the ARRAY_BUFFER buffer object binding point (see section
511 * 2.9.6), and the pointer argument is not NULL."
512 */
513 if (ptr != NULL && vao != ctx->Array.DefaultVAO &&
514 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
515 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
516 return;
517 }
518 }
519
520
521 static bool
522 validate_array_and_format(struct gl_context *ctx, const char *func,
523 GLuint attrib, GLbitfield legalTypes,
524 GLint sizeMin, GLint sizeMax,
525 GLint size, GLenum type, GLsizei stride,
526 GLboolean normalized, GLboolean integer,
527 GLboolean doubles, GLenum format, const GLvoid *ptr,
528 struct gl_vertex_array_object *vao)
529 {
530 validate_array(ctx, func, attrib, legalTypes, sizeMin, sizeMax, size,
531 type, stride, normalized, integer, doubles, ptr);
532
533 return validate_array_format(ctx, func, vao, attrib, legalTypes, sizeMin,
534 sizeMax, size, type, normalized, integer,
535 doubles, 0, format);
536 }
537
538
539 /**
540 * Update state for glVertex/Color/TexCoord/...Pointer functions.
541 *
542 * \param attrib the attribute array index to update
543 * \param format Either GL_RGBA or GL_BGRA.
544 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
545 * \param size components per element (1, 2, 3 or 4)
546 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
547 * \param stride stride between elements, in elements
548 * \param normalized are integer types converted to floats in [-1, 1]?
549 * \param integer integer-valued values (will not be normalized to [-1,1])
550 * \param doubles Double values not reduced to floats
551 * \param ptr the address (or offset inside VBO) of the array data
552 */
553 static void
554 update_array(struct gl_context *ctx,
555 GLuint attrib, GLenum format,
556 GLint sizeMax,
557 GLint size, GLenum type, GLsizei stride,
558 GLboolean normalized, GLboolean integer, GLboolean doubles,
559 const GLvoid *ptr)
560 {
561 struct gl_vertex_array_object *vao = ctx->Array.VAO;
562
563 _mesa_update_array_format(ctx, vao, attrib, size, type, format,
564 normalized, integer, doubles, 0);
565
566 /* Reset the vertex attrib binding */
567 vertex_attrib_binding(ctx, vao, attrib, attrib);
568
569 /* The Stride and Ptr fields are not set by update_array_format() */
570 struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
571 array->Stride = stride;
572 array->Ptr = ptr;
573
574 /* Update the vertex buffer binding */
575 GLsizei effectiveStride = stride != 0 ? stride : array->_ElementSize;
576 _mesa_bind_vertex_buffer(ctx, vao, attrib,
577 ctx->Array.ArrayBufferObj, (GLintptr) ptr,
578 effectiveStride);
579 }
580
581 void GLAPIENTRY
582 _mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride,
583 const GLvoid *ptr)
584 {
585 GET_CURRENT_CONTEXT(ctx);
586 FLUSH_VERTICES(ctx, 0);
587
588 update_array(ctx, VERT_ATTRIB_POS, GL_RGBA, 4, size, type, stride,
589 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
590 }
591
592
593 void GLAPIENTRY
594 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
595 {
596 GET_CURRENT_CONTEXT(ctx);
597
598 FLUSH_VERTICES(ctx, 0);
599
600 GLenum format = GL_RGBA;
601 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
602 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
603 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
604 DOUBLE_BIT | HALF_BIT |
605 UNSIGNED_INT_2_10_10_10_REV_BIT |
606 INT_2_10_10_10_REV_BIT);
607
608 if (!validate_array_and_format(ctx, "glVertexPointer", VERT_ATTRIB_POS,
609 legalTypes, 2, 4, size, type, stride,
610 GL_FALSE, GL_FALSE, GL_FALSE, format,
611 ptr, ctx->Array.VAO))
612 return;
613
614 update_array(ctx, VERT_ATTRIB_POS, format, 4, size, type, stride,
615 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
616 }
617
618
619 void GLAPIENTRY
620 _mesa_NormalPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr )
621 {
622 GET_CURRENT_CONTEXT(ctx);
623 FLUSH_VERTICES(ctx, 0);
624
625 update_array(ctx, VERT_ATTRIB_NORMAL, GL_RGBA, 3, 3, type, stride, GL_TRUE,
626 GL_FALSE, GL_FALSE, ptr);
627 }
628
629
630 void GLAPIENTRY
631 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
632 {
633 GET_CURRENT_CONTEXT(ctx);
634
635 FLUSH_VERTICES(ctx, 0);
636
637 GLenum format = GL_RGBA;
638 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
639 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
640 : (BYTE_BIT | SHORT_BIT | INT_BIT |
641 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
642 UNSIGNED_INT_2_10_10_10_REV_BIT |
643 INT_2_10_10_10_REV_BIT);
644
645 if (!validate_array_and_format(ctx, "glNormalPointer",
646 VERT_ATTRIB_NORMAL, legalTypes, 3, 3, 3,
647 type, stride, GL_TRUE, GL_FALSE,
648 GL_FALSE, format, ptr, ctx->Array.VAO))
649 return;
650
651 update_array(ctx, VERT_ATTRIB_NORMAL, format, 3, 3, type, stride, GL_TRUE,
652 GL_FALSE, GL_FALSE, ptr);
653 }
654
655
656 void GLAPIENTRY
657 _mesa_ColorPointer_no_error(GLint size, GLenum type, GLsizei stride,
658 const GLvoid *ptr)
659 {
660 GET_CURRENT_CONTEXT(ctx);
661 FLUSH_VERTICES(ctx, 0);
662
663 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
664 update_array(ctx, VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
665 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
666 }
667
668
669 void GLAPIENTRY
670 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
671 {
672 GET_CURRENT_CONTEXT(ctx);
673 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
674
675 FLUSH_VERTICES(ctx, 0);
676
677 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
678 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
679 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
680 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
681 SHORT_BIT | UNSIGNED_SHORT_BIT |
682 INT_BIT | UNSIGNED_INT_BIT |
683 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
684 UNSIGNED_INT_2_10_10_10_REV_BIT |
685 INT_2_10_10_10_REV_BIT);
686
687 if (!validate_array_and_format(ctx, "glColorPointer",
688 VERT_ATTRIB_COLOR0, legalTypes, sizeMin,
689 BGRA_OR_4, size, type, stride, GL_TRUE,
690 GL_FALSE, GL_FALSE, format, ptr,
691 ctx->Array.VAO))
692 return;
693
694 update_array(ctx, VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
695 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
696 }
697
698
699 void GLAPIENTRY
700 _mesa_FogCoordPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
701 {
702 GET_CURRENT_CONTEXT(ctx);
703 FLUSH_VERTICES(ctx, 0);
704
705 update_array(ctx, VERT_ATTRIB_FOG, GL_RGBA, 1, 1, type, stride, GL_FALSE,
706 GL_FALSE, GL_FALSE, ptr);
707 }
708
709
710 void GLAPIENTRY
711 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
712 {
713 GET_CURRENT_CONTEXT(ctx);
714
715 FLUSH_VERTICES(ctx, 0);
716
717 GLenum format = GL_RGBA;
718 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
719
720 if (!validate_array_and_format(ctx, "glFogCoordPointer",
721 VERT_ATTRIB_FOG, legalTypes, 1, 1, 1,
722 type, stride, GL_FALSE, GL_FALSE,
723 GL_FALSE, format, ptr, ctx->Array.VAO))
724 return;
725
726 update_array(ctx, VERT_ATTRIB_FOG, format, 1, 1, type, stride, GL_FALSE,
727 GL_FALSE, GL_FALSE, ptr);
728 }
729
730
731 void GLAPIENTRY
732 _mesa_IndexPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
733 {
734 GET_CURRENT_CONTEXT(ctx);
735 FLUSH_VERTICES(ctx, 0);
736
737 update_array(ctx, VERT_ATTRIB_COLOR_INDEX, GL_RGBA, 1, 1, type, stride,
738 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
739 }
740
741
742 void GLAPIENTRY
743 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
744 {
745 GET_CURRENT_CONTEXT(ctx);
746
747 FLUSH_VERTICES(ctx, 0);
748
749 GLenum format = GL_RGBA;
750 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
751 FLOAT_BIT | DOUBLE_BIT);
752
753 if (!validate_array_and_format(ctx, "glIndexPointer",
754 VERT_ATTRIB_COLOR_INDEX,
755 legalTypes, 1, 1, 1, type, stride,
756 GL_FALSE, GL_FALSE, GL_FALSE, format,
757 ptr, ctx->Array.VAO))
758 return;
759
760 update_array(ctx, VERT_ATTRIB_COLOR_INDEX, format, 1, 1, type, stride,
761 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
762 }
763
764
765 void GLAPIENTRY
766 _mesa_SecondaryColorPointer_no_error(GLint size, GLenum type,
767 GLsizei stride, const GLvoid *ptr)
768 {
769 GET_CURRENT_CONTEXT(ctx);
770 FLUSH_VERTICES(ctx, 0);
771
772 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
773 update_array(ctx, VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
774 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
775 }
776
777
778 void GLAPIENTRY
779 _mesa_SecondaryColorPointer(GLint size, GLenum type,
780 GLsizei stride, const GLvoid *ptr)
781 {
782 GET_CURRENT_CONTEXT(ctx);
783
784 FLUSH_VERTICES(ctx, 0);
785
786 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
787 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
788 SHORT_BIT | UNSIGNED_SHORT_BIT |
789 INT_BIT | UNSIGNED_INT_BIT |
790 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
791 UNSIGNED_INT_2_10_10_10_REV_BIT |
792 INT_2_10_10_10_REV_BIT);
793
794 if (!validate_array_and_format(ctx, "glSecondaryColorPointer",
795 VERT_ATTRIB_COLOR1, legalTypes, 3,
796 BGRA_OR_4, size, type, stride,
797 GL_TRUE, GL_FALSE, GL_FALSE, format, ptr,
798 ctx->Array.VAO))
799 return;
800
801 update_array(ctx, VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
802 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
803 }
804
805
806 void GLAPIENTRY
807 _mesa_TexCoordPointer_no_error(GLint size, GLenum type, GLsizei stride,
808 const GLvoid *ptr)
809 {
810 GET_CURRENT_CONTEXT(ctx);
811 const GLuint unit = ctx->Array.ActiveTexture;
812 FLUSH_VERTICES(ctx, 0);
813
814 update_array(ctx, VERT_ATTRIB_TEX(unit), GL_RGBA, 4, size, type,
815 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
816 }
817
818
819 void GLAPIENTRY
820 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
821 const GLvoid *ptr)
822 {
823 GET_CURRENT_CONTEXT(ctx);
824 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
825 const GLuint unit = ctx->Array.ActiveTexture;
826
827 FLUSH_VERTICES(ctx, 0);
828
829 GLenum format = GL_RGBA;
830 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
831 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
832 : (SHORT_BIT | INT_BIT |
833 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
834 UNSIGNED_INT_2_10_10_10_REV_BIT |
835 INT_2_10_10_10_REV_BIT);
836
837 if (!validate_array_and_format(ctx, "glTexCoordPointer",
838 VERT_ATTRIB_TEX(unit), legalTypes,
839 sizeMin, 4, size, type, stride,
840 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr,
841 ctx->Array.VAO))
842 return;
843
844 update_array(ctx, VERT_ATTRIB_TEX(unit), format, 4, size, type,
845 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
846 }
847
848
849 void GLAPIENTRY
850 _mesa_EdgeFlagPointer_no_error(GLsizei stride, const GLvoid *ptr)
851 {
852 /* this is the same type that glEdgeFlag uses */
853 const GLboolean integer = GL_FALSE;
854 GET_CURRENT_CONTEXT(ctx);
855 FLUSH_VERTICES(ctx, 0);
856
857 update_array(ctx, VERT_ATTRIB_EDGEFLAG, GL_RGBA, 1, 1, GL_UNSIGNED_BYTE,
858 stride, GL_FALSE, integer, GL_FALSE, ptr);
859 }
860
861
862 void GLAPIENTRY
863 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
864 {
865 /* this is the same type that glEdgeFlag uses */
866 const GLboolean integer = GL_FALSE;
867 GET_CURRENT_CONTEXT(ctx);
868
869 FLUSH_VERTICES(ctx, 0);
870
871 GLenum format = GL_RGBA;
872 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
873
874 if (!validate_array_and_format(ctx, "glEdgeFlagPointer",
875 VERT_ATTRIB_EDGEFLAG, legalTypes,
876 1, 1, 1, GL_UNSIGNED_BYTE, stride,
877 GL_FALSE, integer, GL_FALSE, format, ptr,
878 ctx->Array.VAO))
879 return;
880
881 update_array(ctx, VERT_ATTRIB_EDGEFLAG, format, 1, 1, GL_UNSIGNED_BYTE,
882 stride, GL_FALSE, integer, GL_FALSE, ptr);
883 }
884
885
886 void GLAPIENTRY
887 _mesa_PointSizePointerOES_no_error(GLenum type, GLsizei stride,
888 const GLvoid *ptr)
889 {
890 GET_CURRENT_CONTEXT(ctx);
891 FLUSH_VERTICES(ctx, 0);
892
893 update_array(ctx, VERT_ATTRIB_POINT_SIZE, GL_RGBA, 1, 1, type, stride,
894 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
895 }
896
897
898 void GLAPIENTRY
899 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
900 {
901 GET_CURRENT_CONTEXT(ctx);
902
903 FLUSH_VERTICES(ctx, 0);
904
905 GLenum format = GL_RGBA;
906 if (ctx->API != API_OPENGLES) {
907 _mesa_error(ctx, GL_INVALID_OPERATION,
908 "glPointSizePointer(ES 1.x only)");
909 return;
910 }
911
912 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
913
914 if (!validate_array_and_format(ctx, "glPointSizePointer",
915 VERT_ATTRIB_POINT_SIZE, legalTypes,
916 1, 1, 1, type, stride, GL_FALSE, GL_FALSE,
917 GL_FALSE, format, ptr, ctx->Array.VAO))
918 return;
919
920 update_array(ctx, VERT_ATTRIB_POINT_SIZE, format, 1, 1, type, stride,
921 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
922 }
923
924
925 void GLAPIENTRY
926 _mesa_VertexAttribPointer_no_error(GLuint index, GLint size, GLenum type,
927 GLboolean normalized,
928 GLsizei stride, const GLvoid *ptr)
929 {
930 GET_CURRENT_CONTEXT(ctx);
931
932 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
933 update_array(ctx, VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
934 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
935 }
936
937
938 /**
939 * Set a generic vertex attribute array.
940 * Note that these arrays DO NOT alias the conventional GL vertex arrays
941 * (position, normal, color, fog, texcoord, etc).
942 */
943 void GLAPIENTRY
944 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
945 GLboolean normalized,
946 GLsizei stride, const GLvoid *ptr)
947 {
948 GET_CURRENT_CONTEXT(ctx);
949
950 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
951 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
952 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(idx)");
953 return;
954 }
955
956 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
957 SHORT_BIT | UNSIGNED_SHORT_BIT |
958 INT_BIT | UNSIGNED_INT_BIT |
959 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
960 FIXED_ES_BIT | FIXED_GL_BIT |
961 UNSIGNED_INT_2_10_10_10_REV_BIT |
962 INT_2_10_10_10_REV_BIT |
963 UNSIGNED_INT_10F_11F_11F_REV_BIT);
964
965 if (!validate_array_and_format(ctx, "glVertexAttribPointer",
966 VERT_ATTRIB_GENERIC(index), legalTypes,
967 1, BGRA_OR_4, size, type, stride,
968 normalized, GL_FALSE, GL_FALSE, format,
969 ptr, ctx->Array.VAO))
970 return;
971
972 update_array(ctx, VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
973 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
974 }
975
976
977 void GLAPIENTRY
978 _mesa_VertexAttribIPointer_no_error(GLuint index, GLint size, GLenum type,
979 GLsizei stride, const GLvoid *ptr)
980 {
981 const GLboolean normalized = GL_FALSE;
982 const GLboolean integer = GL_TRUE;
983 GET_CURRENT_CONTEXT(ctx);
984
985 update_array(ctx, VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
986 stride, normalized, integer, GL_FALSE, ptr);
987 }
988
989
990 /**
991 * GL_EXT_gpu_shader4 / GL 3.0.
992 * Set an integer-valued vertex attribute array.
993 * Note that these arrays DO NOT alias the conventional GL vertex arrays
994 * (position, normal, color, fog, texcoord, etc).
995 */
996 void GLAPIENTRY
997 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
998 GLsizei stride, const GLvoid *ptr)
999 {
1000 const GLboolean normalized = GL_FALSE;
1001 const GLboolean integer = GL_TRUE;
1002 GET_CURRENT_CONTEXT(ctx);
1003
1004 GLenum format = GL_RGBA;
1005 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1006 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
1007 return;
1008 }
1009
1010 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1011 SHORT_BIT | UNSIGNED_SHORT_BIT |
1012 INT_BIT | UNSIGNED_INT_BIT);
1013
1014 if (!validate_array_and_format(ctx, "glVertexAttribIPointer",
1015 VERT_ATTRIB_GENERIC(index), legalTypes,
1016 1, 4, size, type, stride,
1017 normalized, integer, GL_FALSE, format,
1018 ptr, ctx->Array.VAO))
1019 return;
1020
1021 update_array(ctx, VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1022 stride, normalized, integer, GL_FALSE, ptr);
1023 }
1024
1025
1026 void GLAPIENTRY
1027 _mesa_VertexAttribLPointer_no_error(GLuint index, GLint size, GLenum type,
1028 GLsizei stride, const GLvoid *ptr)
1029 {
1030 GET_CURRENT_CONTEXT(ctx);
1031
1032 update_array(ctx, VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
1033 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1034 }
1035
1036
1037 void GLAPIENTRY
1038 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
1039 GLsizei stride, const GLvoid *ptr)
1040 {
1041 GET_CURRENT_CONTEXT(ctx);
1042
1043 GLenum format = GL_RGBA;
1044 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1045 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
1046 return;
1047 }
1048
1049 const GLbitfield legalTypes = DOUBLE_BIT;
1050
1051 if (!validate_array_and_format(ctx, "glVertexAttribLPointer",
1052 VERT_ATTRIB_GENERIC(index), legalTypes,
1053 1, 4, size, type, stride,
1054 GL_FALSE, GL_FALSE, GL_TRUE, format,
1055 ptr, ctx->Array.VAO))
1056 return;
1057
1058 update_array(ctx, VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1059 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1060 }
1061
1062
1063 void
1064 _mesa_enable_vertex_array_attrib(struct gl_context *ctx,
1065 struct gl_vertex_array_object *vao,
1066 gl_vert_attrib attrib)
1067 {
1068 assert(attrib < ARRAY_SIZE(vao->VertexAttrib));
1069
1070 if (!vao->VertexAttrib[attrib].Enabled) {
1071 /* was disabled, now being enabled */
1072 FLUSH_VERTICES(ctx, _NEW_ARRAY);
1073 vao->VertexAttrib[attrib].Enabled = GL_TRUE;
1074 const GLbitfield array_bit = VERT_BIT(attrib);
1075 vao->_Enabled |= array_bit;
1076 vao->NewArrays |= array_bit;
1077
1078 /* Update the map mode if needed */
1079 if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1080 _mesa_update_attribute_map_mode(ctx, vao);
1081 }
1082 }
1083
1084 static void
1085 enable_vertex_array_attrib(struct gl_context *ctx,
1086 struct gl_vertex_array_object *vao,
1087 GLuint index,
1088 const char *func)
1089 {
1090 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1091 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
1092 return;
1093 }
1094
1095 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1096 }
1097
1098
1099 void GLAPIENTRY
1100 _mesa_EnableVertexAttribArray(GLuint index)
1101 {
1102 GET_CURRENT_CONTEXT(ctx);
1103 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
1104 "glEnableVertexAttribArray");
1105 }
1106
1107
1108 void GLAPIENTRY
1109 _mesa_EnableVertexAttribArray_no_error(GLuint index)
1110 {
1111 GET_CURRENT_CONTEXT(ctx);
1112 _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO,
1113 VERT_ATTRIB_GENERIC(index));
1114 }
1115
1116
1117 void GLAPIENTRY
1118 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
1119 {
1120 GET_CURRENT_CONTEXT(ctx);
1121 struct gl_vertex_array_object *vao;
1122
1123 /* The ARB_direct_state_access specification says:
1124 *
1125 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1126 * and DisableVertexArrayAttrib if <vaobj> is not
1127 * [compatibility profile: zero or] the name of an existing vertex
1128 * array object."
1129 */
1130 vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
1131 if (!vao)
1132 return;
1133
1134 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
1135 }
1136
1137
1138 void GLAPIENTRY
1139 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1140 {
1141 GET_CURRENT_CONTEXT(ctx);
1142 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1143 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1144 }
1145
1146
1147 static void
1148 disable_vertex_array_attrib(struct gl_context *ctx,
1149 struct gl_vertex_array_object *vao,
1150 GLuint index)
1151 {
1152 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
1153
1154 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
1155 /* was enabled, now being disabled */
1156 FLUSH_VERTICES(ctx, _NEW_ARRAY);
1157 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
1158 const GLbitfield array_bit = VERT_BIT_GENERIC(index);
1159 vao->_Enabled &= ~array_bit;
1160 vao->NewArrays |= array_bit;
1161
1162 /* Update the map mode if needed */
1163 if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1164 _mesa_update_attribute_map_mode(ctx, vao);
1165 }
1166 }
1167
1168
1169 void GLAPIENTRY
1170 _mesa_DisableVertexAttribArray(GLuint index)
1171 {
1172 GET_CURRENT_CONTEXT(ctx);
1173
1174 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1175 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexAttribArray(index)");
1176 return;
1177 }
1178
1179 disable_vertex_array_attrib(ctx, ctx->Array.VAO, index);
1180 }
1181
1182
1183 void GLAPIENTRY
1184 _mesa_DisableVertexAttribArray_no_error(GLuint index)
1185 {
1186 GET_CURRENT_CONTEXT(ctx);
1187 disable_vertex_array_attrib(ctx, ctx->Array.VAO, index);
1188 }
1189
1190
1191 void GLAPIENTRY
1192 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
1193 {
1194 GET_CURRENT_CONTEXT(ctx);
1195 struct gl_vertex_array_object *vao;
1196
1197 /* The ARB_direct_state_access specification says:
1198 *
1199 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1200 * and DisableVertexArrayAttrib if <vaobj> is not
1201 * [compatibility profile: zero or] the name of an existing vertex
1202 * array object."
1203 */
1204 vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
1205 if (!vao)
1206 return;
1207
1208 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1209 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
1210 return;
1211 }
1212
1213 disable_vertex_array_attrib(ctx, vao, index);
1214 }
1215
1216
1217 void GLAPIENTRY
1218 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1219 {
1220 GET_CURRENT_CONTEXT(ctx);
1221 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1222 disable_vertex_array_attrib(ctx, vao, index);
1223 }
1224
1225
1226 /**
1227 * Return info for a vertex attribute array (no alias with legacy
1228 * vertex attributes (pos, normal, color, etc)). This function does
1229 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1230 */
1231 static GLuint
1232 get_vertex_array_attrib(struct gl_context *ctx,
1233 const struct gl_vertex_array_object *vao,
1234 GLuint index, GLenum pname,
1235 const char *caller)
1236 {
1237 const struct gl_array_attributes *array;
1238
1239 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1240 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
1241 return 0;
1242 }
1243
1244 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
1245
1246 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
1247
1248 switch (pname) {
1249 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
1250 return array->Enabled;
1251 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
1252 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
1253 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
1254 return array->Stride;
1255 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
1256 return array->Type;
1257 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
1258 return array->Normalized;
1259 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
1260 return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name;
1261 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1262 if ((_mesa_is_desktop_gl(ctx)
1263 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
1264 || _mesa_is_gles3(ctx)) {
1265 return array->Integer;
1266 }
1267 goto error;
1268 case GL_VERTEX_ATTRIB_ARRAY_LONG:
1269 if (_mesa_is_desktop_gl(ctx)) {
1270 return array->Doubles;
1271 }
1272 goto error;
1273 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
1274 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
1275 || _mesa_is_gles3(ctx)) {
1276 return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor;
1277 }
1278 goto error;
1279 case GL_VERTEX_ATTRIB_BINDING:
1280 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1281 return array->BufferBindingIndex - VERT_ATTRIB_GENERIC0;
1282 }
1283 goto error;
1284 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
1285 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1286 return array->RelativeOffset;
1287 }
1288 goto error;
1289 default:
1290 ; /* fall-through */
1291 }
1292
1293 error:
1294 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
1295 return 0;
1296 }
1297
1298
1299 static const GLfloat *
1300 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
1301 {
1302 if (index == 0) {
1303 if (_mesa_attr_zero_aliases_vertex(ctx)) {
1304 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
1305 return NULL;
1306 }
1307 }
1308 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1309 _mesa_error(ctx, GL_INVALID_VALUE,
1310 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
1311 return NULL;
1312 }
1313
1314 assert(VERT_ATTRIB_GENERIC(index) <
1315 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1316
1317 FLUSH_CURRENT(ctx, 0);
1318 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
1319 }
1320
1321 void GLAPIENTRY
1322 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
1323 {
1324 GET_CURRENT_CONTEXT(ctx);
1325
1326 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1327 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
1328 if (v != NULL) {
1329 COPY_4V(params, v);
1330 }
1331 }
1332 else {
1333 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1334 index, pname,
1335 "glGetVertexAttribfv");
1336 }
1337 }
1338
1339
1340 void GLAPIENTRY
1341 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
1342 {
1343 GET_CURRENT_CONTEXT(ctx);
1344
1345 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1346 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
1347 if (v != NULL) {
1348 params[0] = (GLdouble) v[0];
1349 params[1] = (GLdouble) v[1];
1350 params[2] = (GLdouble) v[2];
1351 params[3] = (GLdouble) v[3];
1352 }
1353 }
1354 else {
1355 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1356 index, pname,
1357 "glGetVertexAttribdv");
1358 }
1359 }
1360
1361 void GLAPIENTRY
1362 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
1363 {
1364 GET_CURRENT_CONTEXT(ctx);
1365
1366 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1367 const GLdouble *v =
1368 (const GLdouble *)get_current_attrib(ctx, index,
1369 "glGetVertexAttribLdv");
1370 if (v != NULL) {
1371 params[0] = v[0];
1372 params[1] = v[1];
1373 params[2] = v[2];
1374 params[3] = v[3];
1375 }
1376 }
1377 else {
1378 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1379 index, pname,
1380 "glGetVertexAttribLdv");
1381 }
1382 }
1383
1384 void GLAPIENTRY
1385 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1386 {
1387 GET_CURRENT_CONTEXT(ctx);
1388
1389 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1390 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1391 if (v != NULL) {
1392 /* XXX should floats in[0,1] be scaled to full int range? */
1393 params[0] = (GLint) v[0];
1394 params[1] = (GLint) v[1];
1395 params[2] = (GLint) v[2];
1396 params[3] = (GLint) v[3];
1397 }
1398 }
1399 else {
1400 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1401 index, pname,
1402 "glGetVertexAttribiv");
1403 }
1404 }
1405
1406 void GLAPIENTRY
1407 _mesa_GetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT *params)
1408 {
1409 GET_CURRENT_CONTEXT(ctx);
1410
1411 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1412 const GLuint64 *v =
1413 (const GLuint64 *)get_current_attrib(ctx, index,
1414 "glGetVertexAttribLui64vARB");
1415 if (v != NULL) {
1416 params[0] = v[0];
1417 params[1] = v[1];
1418 params[2] = v[2];
1419 params[3] = v[3];
1420 }
1421 }
1422 else {
1423 params[0] = (GLuint64) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1424 index, pname,
1425 "glGetVertexAttribLui64vARB");
1426 }
1427 }
1428
1429
1430 /** GL 3.0 */
1431 void GLAPIENTRY
1432 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1433 {
1434 GET_CURRENT_CONTEXT(ctx);
1435
1436 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1437 const GLint *v = (const GLint *)
1438 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1439 if (v != NULL) {
1440 COPY_4V(params, v);
1441 }
1442 }
1443 else {
1444 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1445 index, pname,
1446 "glGetVertexAttribIiv");
1447 }
1448 }
1449
1450
1451 /** GL 3.0 */
1452 void GLAPIENTRY
1453 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1454 {
1455 GET_CURRENT_CONTEXT(ctx);
1456
1457 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1458 const GLuint *v = (const GLuint *)
1459 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1460 if (v != NULL) {
1461 COPY_4V(params, v);
1462 }
1463 }
1464 else {
1465 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1466 index, pname,
1467 "glGetVertexAttribIuiv");
1468 }
1469 }
1470
1471
1472 void GLAPIENTRY
1473 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1474 {
1475 GET_CURRENT_CONTEXT(ctx);
1476
1477 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1478 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1479 return;
1480 }
1481
1482 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1483 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1484 return;
1485 }
1486
1487 assert(VERT_ATTRIB_GENERIC(index) <
1488 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1489
1490 *pointer = (GLvoid *)
1491 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1492 }
1493
1494
1495 /** ARB_direct_state_access */
1496 void GLAPIENTRY
1497 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1498 GLenum pname, GLint *params)
1499 {
1500 GET_CURRENT_CONTEXT(ctx);
1501 struct gl_vertex_array_object *vao;
1502
1503 /* The ARB_direct_state_access specification says:
1504 *
1505 * "An INVALID_OPERATION error is generated if <vaobj> is not
1506 * [compatibility profile: zero or] the name of an existing
1507 * vertex array object."
1508 */
1509 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1510 if (!vao)
1511 return;
1512
1513 /* The ARB_direct_state_access specification says:
1514 *
1515 * "For GetVertexArrayIndexediv, <pname> must be one of
1516 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1517 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1518 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1519 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1520 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1521 *
1522 * and:
1523 *
1524 * "Add GetVertexArrayIndexediv in 'Get Command' for
1525 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1526 * VERTEX_ATTRIB_BINDING,
1527 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1528 * VERTEX_BINDING_OFFSET, and
1529 * VERTEX_BINDING_STRIDE states"
1530 *
1531 * The only parameter name common to both lists is
1532 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1533 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1534 * pretty clear however that the intent is that it should be possible
1535 * to query all vertex attrib and binding states that can be set with
1536 * a DSA function.
1537 */
1538 switch (pname) {
1539 case GL_VERTEX_BINDING_OFFSET:
1540 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1541 break;
1542 case GL_VERTEX_BINDING_STRIDE:
1543 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1544 break;
1545 case GL_VERTEX_BINDING_DIVISOR:
1546 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1547 break;
1548 case GL_VERTEX_BINDING_BUFFER:
1549 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1550 break;
1551 default:
1552 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1553 "glGetVertexArrayIndexediv");
1554 break;
1555 }
1556 }
1557
1558
1559 void GLAPIENTRY
1560 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1561 GLenum pname, GLint64 *params)
1562 {
1563 GET_CURRENT_CONTEXT(ctx);
1564 struct gl_vertex_array_object *vao;
1565
1566 /* The ARB_direct_state_access specification says:
1567 *
1568 * "An INVALID_OPERATION error is generated if <vaobj> is not
1569 * [compatibility profile: zero or] the name of an existing
1570 * vertex array object."
1571 */
1572 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1573 if (!vao)
1574 return;
1575
1576 /* The ARB_direct_state_access specification says:
1577 *
1578 * "For GetVertexArrayIndexed64iv, <pname> must be
1579 * VERTEX_BINDING_OFFSET."
1580 *
1581 * and:
1582 *
1583 * "An INVALID_ENUM error is generated if <pname> is not one of
1584 * the valid values listed above for the corresponding command."
1585 */
1586 if (pname != GL_VERTEX_BINDING_OFFSET) {
1587 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1588 "pname != GL_VERTEX_BINDING_OFFSET)");
1589 return;
1590 }
1591
1592 /* The ARB_direct_state_access specification says:
1593 *
1594 * "An INVALID_VALUE error is generated if <index> is greater than
1595 * or equal to the value of MAX_VERTEX_ATTRIBS."
1596 *
1597 * Since the index refers to a buffer binding in this case, the intended
1598 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1599 * required to be the same, so in practice this doesn't matter.
1600 */
1601 if (index >= ctx->Const.MaxVertexAttribBindings) {
1602 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
1603 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1604 index, ctx->Const.MaxVertexAttribBindings);
1605 return;
1606 }
1607
1608 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1609 }
1610
1611
1612 void GLAPIENTRY
1613 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1614 GLsizei count, const GLvoid *ptr)
1615 {
1616 (void) count;
1617 _mesa_VertexPointer(size, type, stride, ptr);
1618 }
1619
1620
1621 void GLAPIENTRY
1622 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1623 const GLvoid *ptr)
1624 {
1625 (void) count;
1626 _mesa_NormalPointer(type, stride, ptr);
1627 }
1628
1629
1630 void GLAPIENTRY
1631 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1632 const GLvoid *ptr)
1633 {
1634 (void) count;
1635 _mesa_ColorPointer(size, type, stride, ptr);
1636 }
1637
1638
1639 void GLAPIENTRY
1640 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1641 const GLvoid *ptr)
1642 {
1643 (void) count;
1644 _mesa_IndexPointer(type, stride, ptr);
1645 }
1646
1647
1648 void GLAPIENTRY
1649 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1650 GLsizei count, const GLvoid *ptr)
1651 {
1652 (void) count;
1653 _mesa_TexCoordPointer(size, type, stride, ptr);
1654 }
1655
1656
1657 void GLAPIENTRY
1658 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1659 {
1660 (void) count;
1661 _mesa_EdgeFlagPointer(stride, ptr);
1662 }
1663
1664
1665 void GLAPIENTRY
1666 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1667 {
1668 GET_CURRENT_CONTEXT(ctx);
1669 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1670 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1671 GLenum ctype = 0; /* color type */
1672 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1673 const GLint toffset = 0; /* always zero */
1674 GLint defstride; /* default stride */
1675 GLint c, f;
1676
1677 FLUSH_VERTICES(ctx, 0);
1678
1679 f = sizeof(GLfloat);
1680 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1681
1682 if (stride < 0) {
1683 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1684 return;
1685 }
1686
1687 switch (format) {
1688 case GL_V2F:
1689 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1690 tcomps = 0; ccomps = 0; vcomps = 2;
1691 voffset = 0;
1692 defstride = 2*f;
1693 break;
1694 case GL_V3F:
1695 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1696 tcomps = 0; ccomps = 0; vcomps = 3;
1697 voffset = 0;
1698 defstride = 3*f;
1699 break;
1700 case GL_C4UB_V2F:
1701 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1702 tcomps = 0; ccomps = 4; vcomps = 2;
1703 ctype = GL_UNSIGNED_BYTE;
1704 coffset = 0;
1705 voffset = c;
1706 defstride = c + 2*f;
1707 break;
1708 case GL_C4UB_V3F:
1709 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1710 tcomps = 0; ccomps = 4; vcomps = 3;
1711 ctype = GL_UNSIGNED_BYTE;
1712 coffset = 0;
1713 voffset = c;
1714 defstride = c + 3*f;
1715 break;
1716 case GL_C3F_V3F:
1717 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1718 tcomps = 0; ccomps = 3; vcomps = 3;
1719 ctype = GL_FLOAT;
1720 coffset = 0;
1721 voffset = 3*f;
1722 defstride = 6*f;
1723 break;
1724 case GL_N3F_V3F:
1725 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1726 tcomps = 0; ccomps = 0; vcomps = 3;
1727 noffset = 0;
1728 voffset = 3*f;
1729 defstride = 6*f;
1730 break;
1731 case GL_C4F_N3F_V3F:
1732 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1733 tcomps = 0; ccomps = 4; vcomps = 3;
1734 ctype = GL_FLOAT;
1735 coffset = 0;
1736 noffset = 4*f;
1737 voffset = 7*f;
1738 defstride = 10*f;
1739 break;
1740 case GL_T2F_V3F:
1741 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1742 tcomps = 2; ccomps = 0; vcomps = 3;
1743 voffset = 2*f;
1744 defstride = 5*f;
1745 break;
1746 case GL_T4F_V4F:
1747 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1748 tcomps = 4; ccomps = 0; vcomps = 4;
1749 voffset = 4*f;
1750 defstride = 8*f;
1751 break;
1752 case GL_T2F_C4UB_V3F:
1753 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1754 tcomps = 2; ccomps = 4; vcomps = 3;
1755 ctype = GL_UNSIGNED_BYTE;
1756 coffset = 2*f;
1757 voffset = c+2*f;
1758 defstride = c+5*f;
1759 break;
1760 case GL_T2F_C3F_V3F:
1761 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1762 tcomps = 2; ccomps = 3; vcomps = 3;
1763 ctype = GL_FLOAT;
1764 coffset = 2*f;
1765 voffset = 5*f;
1766 defstride = 8*f;
1767 break;
1768 case GL_T2F_N3F_V3F:
1769 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1770 tcomps = 2; ccomps = 0; vcomps = 3;
1771 noffset = 2*f;
1772 voffset = 5*f;
1773 defstride = 8*f;
1774 break;
1775 case GL_T2F_C4F_N3F_V3F:
1776 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1777 tcomps = 2; ccomps = 4; vcomps = 3;
1778 ctype = GL_FLOAT;
1779 coffset = 2*f;
1780 noffset = 6*f;
1781 voffset = 9*f;
1782 defstride = 12*f;
1783 break;
1784 case GL_T4F_C4F_N3F_V4F:
1785 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1786 tcomps = 4; ccomps = 4; vcomps = 4;
1787 ctype = GL_FLOAT;
1788 coffset = 4*f;
1789 noffset = 8*f;
1790 voffset = 11*f;
1791 defstride = 15*f;
1792 break;
1793 default:
1794 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1795 return;
1796 }
1797
1798 if (stride==0) {
1799 stride = defstride;
1800 }
1801
1802 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1803 _mesa_DisableClientState( GL_INDEX_ARRAY );
1804 /* XXX also disable secondary color and generic arrays? */
1805
1806 /* Texcoords */
1807 if (tflag) {
1808 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1809 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1810 (GLubyte *) pointer + toffset );
1811 }
1812 else {
1813 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1814 }
1815
1816 /* Color */
1817 if (cflag) {
1818 _mesa_EnableClientState( GL_COLOR_ARRAY );
1819 _mesa_ColorPointer( ccomps, ctype, stride,
1820 (GLubyte *) pointer + coffset );
1821 }
1822 else {
1823 _mesa_DisableClientState( GL_COLOR_ARRAY );
1824 }
1825
1826
1827 /* Normals */
1828 if (nflag) {
1829 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1830 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1831 }
1832 else {
1833 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1834 }
1835
1836 /* Vertices */
1837 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1838 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1839 (GLubyte *) pointer + voffset );
1840 }
1841
1842
1843 void GLAPIENTRY
1844 _mesa_LockArraysEXT(GLint first, GLsizei count)
1845 {
1846 GET_CURRENT_CONTEXT(ctx);
1847
1848 FLUSH_VERTICES(ctx, 0);
1849
1850 if (MESA_VERBOSE & VERBOSE_API)
1851 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1852
1853 if (first < 0) {
1854 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1855 return;
1856 }
1857 if (count <= 0) {
1858 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1859 return;
1860 }
1861 if (ctx->Array.LockCount != 0) {
1862 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1863 return;
1864 }
1865
1866 ctx->Array.LockFirst = first;
1867 ctx->Array.LockCount = count;
1868
1869 ctx->NewState |= _NEW_ARRAY;
1870 }
1871
1872
1873 void GLAPIENTRY
1874 _mesa_UnlockArraysEXT( void )
1875 {
1876 GET_CURRENT_CONTEXT(ctx);
1877
1878 FLUSH_VERTICES(ctx, 0);
1879
1880 if (MESA_VERBOSE & VERBOSE_API)
1881 _mesa_debug(ctx, "glUnlockArrays\n");
1882
1883 if (ctx->Array.LockCount == 0) {
1884 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1885 return;
1886 }
1887
1888 ctx->Array.LockFirst = 0;
1889 ctx->Array.LockCount = 0;
1890 ctx->NewState |= _NEW_ARRAY;
1891 }
1892
1893
1894 /* GL_IBM_multimode_draw_arrays */
1895 void GLAPIENTRY
1896 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1897 const GLsizei * count,
1898 GLsizei primcount, GLint modestride )
1899 {
1900 GET_CURRENT_CONTEXT(ctx);
1901 GLint i;
1902
1903 FLUSH_VERTICES(ctx, 0);
1904
1905 for ( i = 0 ; i < primcount ; i++ ) {
1906 if ( count[i] > 0 ) {
1907 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1908 CALL_DrawArrays(ctx->CurrentServerDispatch, ( m, first[i], count[i] ));
1909 }
1910 }
1911 }
1912
1913
1914 /* GL_IBM_multimode_draw_arrays */
1915 void GLAPIENTRY
1916 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1917 GLenum type, const GLvoid * const * indices,
1918 GLsizei primcount, GLint modestride )
1919 {
1920 GET_CURRENT_CONTEXT(ctx);
1921 GLint i;
1922
1923 FLUSH_VERTICES(ctx, 0);
1924
1925 /* XXX not sure about ARB_vertex_buffer_object handling here */
1926
1927 for ( i = 0 ; i < primcount ; i++ ) {
1928 if ( count[i] > 0 ) {
1929 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1930 CALL_DrawElements(ctx->CurrentServerDispatch, ( m, count[i], type,
1931 indices[i] ));
1932 }
1933 }
1934 }
1935
1936
1937 static void
1938 primitive_restart_index(struct gl_context *ctx, GLuint index)
1939 {
1940 if (ctx->Array.RestartIndex != index) {
1941 FLUSH_VERTICES(ctx, 0);
1942 ctx->Array.RestartIndex = index;
1943 }
1944 }
1945
1946
1947 /**
1948 * GL_NV_primitive_restart and GL 3.1
1949 */
1950 void GLAPIENTRY
1951 _mesa_PrimitiveRestartIndex_no_error(GLuint index)
1952 {
1953 GET_CURRENT_CONTEXT(ctx);
1954 primitive_restart_index(ctx, index);
1955 }
1956
1957
1958 void GLAPIENTRY
1959 _mesa_PrimitiveRestartIndex(GLuint index)
1960 {
1961 GET_CURRENT_CONTEXT(ctx);
1962
1963 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1964 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1965 return;
1966 }
1967
1968 primitive_restart_index(ctx, index);
1969 }
1970
1971
1972 void GLAPIENTRY
1973 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor)
1974 {
1975 GET_CURRENT_CONTEXT(ctx);
1976
1977 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
1978 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1979
1980 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1981
1982 /* The ARB_vertex_attrib_binding spec says:
1983 *
1984 * "The command
1985 *
1986 * void VertexAttribDivisor(uint index, uint divisor);
1987 *
1988 * is equivalent to (assuming no errors are generated):
1989 *
1990 * VertexAttribBinding(index, index);
1991 * VertexBindingDivisor(index, divisor);"
1992 */
1993 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
1994 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
1995 }
1996
1997
1998 /**
1999 * See GL_ARB_instanced_arrays.
2000 * Note that the instance divisor only applies to generic arrays, not
2001 * the legacy vertex arrays.
2002 */
2003 void GLAPIENTRY
2004 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
2005 {
2006 GET_CURRENT_CONTEXT(ctx);
2007
2008 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2009 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2010
2011 if (!ctx->Extensions.ARB_instanced_arrays) {
2012 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
2013 return;
2014 }
2015
2016 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2017 _mesa_error(ctx, GL_INVALID_VALUE,
2018 "glVertexAttribDivisor(index = %u)", index);
2019 return;
2020 }
2021
2022 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2023
2024 /* The ARB_vertex_attrib_binding spec says:
2025 *
2026 * "The command
2027 *
2028 * void VertexAttribDivisor(uint index, uint divisor);
2029 *
2030 * is equivalent to (assuming no errors are generated):
2031 *
2032 * VertexAttribBinding(index, index);
2033 * VertexBindingDivisor(index, divisor);"
2034 */
2035 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2036 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2037 }
2038
2039
2040 static ALWAYS_INLINE void
2041 vertex_array_vertex_buffer(struct gl_context *ctx,
2042 struct gl_vertex_array_object *vao,
2043 GLuint bindingIndex, GLuint buffer, GLintptr offset,
2044 GLsizei stride, bool no_error, const char *func)
2045 {
2046 struct gl_buffer_object *vbo;
2047 if (buffer ==
2048 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
2049 vbo = vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
2050 } else if (buffer != 0) {
2051 vbo = _mesa_lookup_bufferobj(ctx, buffer);
2052
2053 if (!no_error && !vbo && _mesa_is_gles31(ctx)) {
2054 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
2055 return;
2056 }
2057 /* From the GL_ARB_vertex_attrib_array spec:
2058 *
2059 * "[Core profile only:]
2060 * An INVALID_OPERATION error is generated if buffer is not zero or a
2061 * name returned from a previous call to GenBuffers, or if such a name
2062 * has since been deleted with DeleteBuffers.
2063 *
2064 * Otherwise, we fall back to the same compat profile behavior as other
2065 * object references (automatically gen it).
2066 */
2067 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
2068 return;
2069 } else {
2070 /* The ARB_vertex_attrib_binding spec says:
2071 *
2072 * "If <buffer> is zero, any buffer object attached to this
2073 * bindpoint is detached."
2074 */
2075 vbo = ctx->Shared->NullBufferObj;
2076 }
2077
2078 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
2079 vbo, offset, stride);
2080 }
2081
2082
2083 /**
2084 * GL_ARB_vertex_attrib_binding
2085 */
2086 static void
2087 vertex_array_vertex_buffer_err(struct gl_context *ctx,
2088 struct gl_vertex_array_object *vao,
2089 GLuint bindingIndex, GLuint buffer,
2090 GLintptr offset, GLsizei stride,
2091 const char *func)
2092 {
2093 ASSERT_OUTSIDE_BEGIN_END(ctx);
2094
2095 /* The ARB_vertex_attrib_binding spec says:
2096 *
2097 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2098 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2099 */
2100 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2101 _mesa_error(ctx, GL_INVALID_VALUE,
2102 "%s(bindingindex=%u > "
2103 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2104 func, bindingIndex);
2105 return;
2106 }
2107
2108 /* The ARB_vertex_attrib_binding spec says:
2109 *
2110 * "The error INVALID_VALUE is generated if <stride> or <offset>
2111 * are negative."
2112 */
2113 if (offset < 0) {
2114 _mesa_error(ctx, GL_INVALID_VALUE,
2115 "%s(offset=%" PRId64 " < 0)",
2116 func, (int64_t) offset);
2117 return;
2118 }
2119
2120 if (stride < 0) {
2121 _mesa_error(ctx, GL_INVALID_VALUE,
2122 "%s(stride=%d < 0)", func, stride);
2123 return;
2124 }
2125
2126 if (((ctx->API == API_OPENGL_CORE && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
2127 stride > ctx->Const.MaxVertexAttribStride) {
2128 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
2129 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
2130 return;
2131 }
2132
2133 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2134 stride, false, func);
2135 }
2136
2137
2138 void GLAPIENTRY
2139 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer,
2140 GLintptr offset, GLsizei stride)
2141 {
2142 GET_CURRENT_CONTEXT(ctx);
2143 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
2144 buffer, offset, stride, true,
2145 "glBindVertexBuffer");
2146 }
2147
2148
2149 void GLAPIENTRY
2150 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
2151 GLsizei stride)
2152 {
2153 GET_CURRENT_CONTEXT(ctx);
2154
2155 /* The ARB_vertex_attrib_binding spec says:
2156 *
2157 * "An INVALID_OPERATION error is generated if no vertex array object
2158 * is bound."
2159 */
2160 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2161 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2162 _mesa_error(ctx, GL_INVALID_OPERATION,
2163 "glBindVertexBuffer(No array object bound)");
2164 return;
2165 }
2166
2167 vertex_array_vertex_buffer_err(ctx, ctx->Array.VAO, bindingIndex,
2168 buffer, offset, stride,
2169 "glBindVertexBuffer");
2170 }
2171
2172
2173 void GLAPIENTRY
2174 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex,
2175 GLuint buffer, GLintptr offset,
2176 GLsizei stride)
2177 {
2178 GET_CURRENT_CONTEXT(ctx);
2179
2180 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2181 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2182 stride, true, "glVertexArrayVertexBuffer");
2183 }
2184
2185
2186 void GLAPIENTRY
2187 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
2188 GLintptr offset, GLsizei stride)
2189 {
2190 GET_CURRENT_CONTEXT(ctx);
2191 struct gl_vertex_array_object *vao;
2192
2193 /* The ARB_direct_state_access specification says:
2194 *
2195 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2196 * if <vaobj> is not [compatibility profile: zero or] the name of an
2197 * existing vertex array object."
2198 */
2199 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
2200 if (!vao)
2201 return;
2202
2203 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
2204 stride, "glVertexArrayVertexBuffer");
2205 }
2206
2207
2208 static ALWAYS_INLINE void
2209 vertex_array_vertex_buffers(struct gl_context *ctx,
2210 struct gl_vertex_array_object *vao,
2211 GLuint first, GLsizei count, const GLuint *buffers,
2212 const GLintptr *offsets, const GLsizei *strides,
2213 bool no_error, const char *func)
2214 {
2215 GLint i;
2216
2217 if (!buffers) {
2218 /**
2219 * The ARB_multi_bind spec says:
2220 *
2221 * "If <buffers> is NULL, each affected vertex buffer binding point
2222 * from <first> through <first>+<count>-1 will be reset to have no
2223 * bound buffer object. In this case, the offsets and strides
2224 * associated with the binding points are set to default values,
2225 * ignoring <offsets> and <strides>."
2226 */
2227 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
2228
2229 for (i = 0; i < count; i++)
2230 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2231 vbo, 0, 16);
2232
2233 return;
2234 }
2235
2236 /* Note that the error semantics for multi-bind commands differ from
2237 * those of other GL commands.
2238 *
2239 * The Issues section in the ARB_multi_bind spec says:
2240 *
2241 * "(11) Typically, OpenGL specifies that if an error is generated by
2242 * a command, that command has no effect. This is somewhat
2243 * unfortunate for multi-bind commands, because it would require
2244 * a first pass to scan the entire list of bound objects for
2245 * errors and then a second pass to actually perform the
2246 * bindings. Should we have different error semantics?
2247 *
2248 * RESOLVED: Yes. In this specification, when the parameters for
2249 * one of the <count> binding points are invalid, that binding
2250 * point is not updated and an error will be generated. However,
2251 * other binding points in the same command will be updated if
2252 * their parameters are valid and no other error occurs."
2253 */
2254
2255 _mesa_HashLockMutex(ctx->Shared->BufferObjects);
2256
2257 for (i = 0; i < count; i++) {
2258 struct gl_buffer_object *vbo;
2259
2260 if (!no_error) {
2261 /* The ARB_multi_bind spec says:
2262 *
2263 * "An INVALID_VALUE error is generated if any value in
2264 * <offsets> or <strides> is negative (per binding)."
2265 */
2266 if (offsets[i] < 0) {
2267 _mesa_error(ctx, GL_INVALID_VALUE,
2268 "%s(offsets[%u]=%" PRId64 " < 0)",
2269 func, i, (int64_t) offsets[i]);
2270 continue;
2271 }
2272
2273 if (strides[i] < 0) {
2274 _mesa_error(ctx, GL_INVALID_VALUE,
2275 "%s(strides[%u]=%d < 0)",
2276 func, i, strides[i]);
2277 continue;
2278 }
2279
2280 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
2281 strides[i] > ctx->Const.MaxVertexAttribStride) {
2282 _mesa_error(ctx, GL_INVALID_VALUE,
2283 "%s(strides[%u]=%d > "
2284 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
2285 continue;
2286 }
2287 }
2288
2289 if (buffers[i]) {
2290 struct gl_vertex_buffer_binding *binding =
2291 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
2292
2293 if (buffers[i] == binding->BufferObj->Name)
2294 vbo = binding->BufferObj;
2295 else
2296 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
2297
2298 if (!vbo)
2299 continue;
2300 } else {
2301 vbo = ctx->Shared->NullBufferObj;
2302 }
2303
2304 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2305 vbo, offsets[i], strides[i]);
2306 }
2307
2308 _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
2309 }
2310
2311
2312 static void
2313 vertex_array_vertex_buffers_err(struct gl_context *ctx,
2314 struct gl_vertex_array_object *vao,
2315 GLuint first, GLsizei count,
2316 const GLuint *buffers, const GLintptr *offsets,
2317 const GLsizei *strides, const char *func)
2318 {
2319 ASSERT_OUTSIDE_BEGIN_END(ctx);
2320
2321 /* The ARB_multi_bind spec says:
2322 *
2323 * "An INVALID_OPERATION error is generated if <first> + <count>
2324 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2325 */
2326 if (first + count > ctx->Const.MaxVertexAttribBindings) {
2327 _mesa_error(ctx, GL_INVALID_OPERATION,
2328 "%s(first=%u + count=%d > the value of "
2329 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2330 func, first, count, ctx->Const.MaxVertexAttribBindings);
2331 return;
2332 }
2333
2334 vertex_array_vertex_buffers(ctx, vao, first, count, buffers, offsets,
2335 strides, false, func);
2336 }
2337
2338
2339 void GLAPIENTRY
2340 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count,
2341 const GLuint *buffers, const GLintptr *offsets,
2342 const GLsizei *strides)
2343 {
2344 GET_CURRENT_CONTEXT(ctx);
2345
2346 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
2347 buffers, offsets, strides, true,
2348 "glBindVertexBuffers");
2349 }
2350
2351
2352 void GLAPIENTRY
2353 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
2354 const GLintptr *offsets, const GLsizei *strides)
2355 {
2356 GET_CURRENT_CONTEXT(ctx);
2357
2358 /* The ARB_vertex_attrib_binding spec says:
2359 *
2360 * "An INVALID_OPERATION error is generated if no
2361 * vertex array object is bound."
2362 */
2363 if (ctx->API == API_OPENGL_CORE &&
2364 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2365 _mesa_error(ctx, GL_INVALID_OPERATION,
2366 "glBindVertexBuffers(No array object bound)");
2367 return;
2368 }
2369
2370 vertex_array_vertex_buffers_err(ctx, ctx->Array.VAO, first, count,
2371 buffers, offsets, strides,
2372 "glBindVertexBuffers");
2373 }
2374
2375
2376 void GLAPIENTRY
2377 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first,
2378 GLsizei count, const GLuint *buffers,
2379 const GLintptr *offsets,
2380 const GLsizei *strides)
2381 {
2382 GET_CURRENT_CONTEXT(ctx);
2383
2384 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2385 vertex_array_vertex_buffers(ctx, vao, first, count,
2386 buffers, offsets, strides, true,
2387 "glVertexArrayVertexBuffers");
2388 }
2389
2390
2391 void GLAPIENTRY
2392 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
2393 const GLuint *buffers,
2394 const GLintptr *offsets, const GLsizei *strides)
2395 {
2396 GET_CURRENT_CONTEXT(ctx);
2397 struct gl_vertex_array_object *vao;
2398
2399 /* The ARB_direct_state_access specification says:
2400 *
2401 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2402 * if <vaobj> is not [compatibility profile: zero or] the name of an
2403 * existing vertex array object."
2404 */
2405 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
2406 if (!vao)
2407 return;
2408
2409 vertex_array_vertex_buffers_err(ctx, vao, first, count,
2410 buffers, offsets, strides,
2411 "glVertexArrayVertexBuffers");
2412 }
2413
2414
2415 static void
2416 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
2417 GLboolean normalized, GLboolean integer,
2418 GLboolean doubles, GLbitfield legalTypes,
2419 GLsizei sizeMax, GLuint relativeOffset,
2420 const char *func)
2421 {
2422 GET_CURRENT_CONTEXT(ctx);
2423 ASSERT_OUTSIDE_BEGIN_END(ctx);
2424
2425 GLenum format = get_array_format(ctx, sizeMax, &size);
2426
2427 if (!_mesa_is_no_error_enabled(ctx)) {
2428 /* The ARB_vertex_attrib_binding spec says:
2429 *
2430 * "An INVALID_OPERATION error is generated under any of the
2431 * following conditions:
2432 * - if no vertex array object is currently bound (see section
2433 * 2.10);
2434 * - ..."
2435 *
2436 * This error condition only applies to VertexAttribFormat and
2437 * VertexAttribIFormat in the extension spec, but we assume that this
2438 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2439 * to all three functions.
2440 */
2441 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2442 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2443 _mesa_error(ctx, GL_INVALID_OPERATION,
2444 "%s(No array object bound)", func);
2445 return;
2446 }
2447
2448 /* The ARB_vertex_attrib_binding spec says:
2449 *
2450 * "The error INVALID_VALUE is generated if index is greater than or
2451 * equal to the value of MAX_VERTEX_ATTRIBS."
2452 */
2453 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2454 _mesa_error(ctx, GL_INVALID_VALUE,
2455 "%s(attribindex=%u > "
2456 "GL_MAX_VERTEX_ATTRIBS)",
2457 func, attribIndex);
2458 return;
2459 }
2460
2461 if (!validate_array_format(ctx, func, ctx->Array.VAO,
2462 VERT_ATTRIB_GENERIC(attribIndex),
2463 legalTypes, 1, sizeMax, size, type,
2464 normalized, integer, doubles, relativeOffset,
2465 format)) {
2466 return;
2467 }
2468 }
2469
2470 FLUSH_VERTICES(ctx, 0);
2471
2472 _mesa_update_array_format(ctx, ctx->Array.VAO,
2473 VERT_ATTRIB_GENERIC(attribIndex), size, type,
2474 format, normalized, integer, doubles,
2475 relativeOffset);
2476 }
2477
2478
2479 void GLAPIENTRY
2480 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
2481 GLboolean normalized, GLuint relativeOffset)
2482 {
2483 vertex_attrib_format(attribIndex, size, type, normalized,
2484 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2485 BGRA_OR_4, relativeOffset,
2486 "glVertexAttribFormat");
2487 }
2488
2489
2490 void GLAPIENTRY
2491 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
2492 GLuint relativeOffset)
2493 {
2494 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2495 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2496 relativeOffset, "glVertexAttribIFormat");
2497 }
2498
2499
2500 void GLAPIENTRY
2501 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2502 GLuint relativeOffset)
2503 {
2504 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2505 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2506 relativeOffset, "glVertexAttribLFormat");
2507 }
2508
2509
2510 static void
2511 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2512 GLenum type, GLboolean normalized,
2513 GLboolean integer, GLboolean doubles,
2514 GLbitfield legalTypes, GLsizei sizeMax,
2515 GLuint relativeOffset, const char *func)
2516 {
2517 GET_CURRENT_CONTEXT(ctx);
2518 struct gl_vertex_array_object *vao;
2519
2520 ASSERT_OUTSIDE_BEGIN_END(ctx);
2521
2522 GLenum format = get_array_format(ctx, sizeMax, &size);
2523
2524 if (_mesa_is_no_error_enabled(ctx)) {
2525 vao = _mesa_lookup_vao(ctx, vaobj);
2526 if (!vao)
2527 return;
2528 } else {
2529 /* The ARB_direct_state_access spec says:
2530 *
2531 * "An INVALID_OPERATION error is generated by
2532 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2533 * zero or] the name of an existing vertex array object."
2534 */
2535 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2536 if (!vao)
2537 return;
2538
2539 /* The ARB_vertex_attrib_binding spec says:
2540 *
2541 * "The error INVALID_VALUE is generated if index is greater than or
2542 * equal to the value of MAX_VERTEX_ATTRIBS."
2543 */
2544 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2545 _mesa_error(ctx, GL_INVALID_VALUE,
2546 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2547 func, attribIndex);
2548 return;
2549 }
2550
2551 if (!validate_array_format(ctx, func, vao,
2552 VERT_ATTRIB_GENERIC(attribIndex),
2553 legalTypes, 1, sizeMax, size, type,
2554 normalized, integer, doubles, relativeOffset,
2555 format)) {
2556 return;
2557 }
2558 }
2559
2560 FLUSH_VERTICES(ctx, 0);
2561
2562 _mesa_update_array_format(ctx, vao, VERT_ATTRIB_GENERIC(attribIndex), size,
2563 type, format, normalized, integer, doubles,
2564 relativeOffset);
2565 }
2566
2567
2568 void GLAPIENTRY
2569 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2570 GLenum type, GLboolean normalized,
2571 GLuint relativeOffset)
2572 {
2573 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2574 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2575 BGRA_OR_4, relativeOffset,
2576 "glVertexArrayAttribFormat");
2577 }
2578
2579
2580 void GLAPIENTRY
2581 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2582 GLint size, GLenum type,
2583 GLuint relativeOffset)
2584 {
2585 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2586 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2587 4, relativeOffset,
2588 "glVertexArrayAttribIFormat");
2589 }
2590
2591
2592 void GLAPIENTRY
2593 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2594 GLint size, GLenum type,
2595 GLuint relativeOffset)
2596 {
2597 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2598 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2599 4, relativeOffset,
2600 "glVertexArrayAttribLFormat");
2601 }
2602
2603
2604 static void
2605 vertex_array_attrib_binding(struct gl_context *ctx,
2606 struct gl_vertex_array_object *vao,
2607 GLuint attribIndex, GLuint bindingIndex,
2608 const char *func)
2609 {
2610 ASSERT_OUTSIDE_BEGIN_END(ctx);
2611
2612 /* The ARB_vertex_attrib_binding spec says:
2613 *
2614 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2615 * <bindingindex> must be less than the value of
2616 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2617 * is generated."
2618 */
2619 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2620 _mesa_error(ctx, GL_INVALID_VALUE,
2621 "%s(attribindex=%u >= "
2622 "GL_MAX_VERTEX_ATTRIBS)",
2623 func, attribIndex);
2624 return;
2625 }
2626
2627 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2628 _mesa_error(ctx, GL_INVALID_VALUE,
2629 "%s(bindingindex=%u >= "
2630 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2631 func, bindingIndex);
2632 return;
2633 }
2634
2635 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2636
2637 vertex_attrib_binding(ctx, vao,
2638 VERT_ATTRIB_GENERIC(attribIndex),
2639 VERT_ATTRIB_GENERIC(bindingIndex));
2640 }
2641
2642
2643 void GLAPIENTRY
2644 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex)
2645 {
2646 GET_CURRENT_CONTEXT(ctx);
2647 vertex_attrib_binding(ctx, ctx->Array.VAO,
2648 VERT_ATTRIB_GENERIC(attribIndex),
2649 VERT_ATTRIB_GENERIC(bindingIndex));
2650 }
2651
2652
2653 void GLAPIENTRY
2654 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2655 {
2656 GET_CURRENT_CONTEXT(ctx);
2657
2658 /* The ARB_vertex_attrib_binding spec says:
2659 *
2660 * "An INVALID_OPERATION error is generated if no vertex array object
2661 * is bound."
2662 */
2663 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2664 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2665 _mesa_error(ctx, GL_INVALID_OPERATION,
2666 "glVertexAttribBinding(No array object bound)");
2667 return;
2668 }
2669
2670 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2671 attribIndex, bindingIndex,
2672 "glVertexAttribBinding");
2673 }
2674
2675
2676 void GLAPIENTRY
2677 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex,
2678 GLuint bindingIndex)
2679 {
2680 GET_CURRENT_CONTEXT(ctx);
2681
2682 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2683 vertex_attrib_binding(ctx, vao,
2684 VERT_ATTRIB_GENERIC(attribIndex),
2685 VERT_ATTRIB_GENERIC(bindingIndex));
2686 }
2687
2688
2689 void GLAPIENTRY
2690 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2691 {
2692 GET_CURRENT_CONTEXT(ctx);
2693 struct gl_vertex_array_object *vao;
2694
2695 /* The ARB_direct_state_access specification says:
2696 *
2697 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2698 * if <vaobj> is not [compatibility profile: zero or] the name of an
2699 * existing vertex array object."
2700 */
2701 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2702 if (!vao)
2703 return;
2704
2705 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2706 "glVertexArrayAttribBinding");
2707 }
2708
2709
2710 static void
2711 vertex_array_binding_divisor(struct gl_context *ctx,
2712 struct gl_vertex_array_object *vao,
2713 GLuint bindingIndex, GLuint divisor,
2714 const char *func)
2715 {
2716 ASSERT_OUTSIDE_BEGIN_END(ctx);
2717
2718 if (!ctx->Extensions.ARB_instanced_arrays) {
2719 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2720 return;
2721 }
2722
2723 /* The ARB_vertex_attrib_binding spec says:
2724 *
2725 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2726 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2727 */
2728 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2729 _mesa_error(ctx, GL_INVALID_VALUE,
2730 "%s(bindingindex=%u > "
2731 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2732 func, bindingIndex);
2733 return;
2734 }
2735
2736 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2737 }
2738
2739
2740 void GLAPIENTRY
2741 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex, GLuint divisor)
2742 {
2743 GET_CURRENT_CONTEXT(ctx);
2744 vertex_binding_divisor(ctx, ctx->Array.VAO,
2745 VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2746 }
2747
2748
2749 void GLAPIENTRY
2750 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2751 {
2752 GET_CURRENT_CONTEXT(ctx);
2753
2754 /* The ARB_vertex_attrib_binding spec says:
2755 *
2756 * "An INVALID_OPERATION error is generated if no vertex array object
2757 * is bound."
2758 */
2759 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2760 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2761 _mesa_error(ctx, GL_INVALID_OPERATION,
2762 "glVertexBindingDivisor(No array object bound)");
2763 return;
2764 }
2765
2766 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2767 bindingIndex, divisor,
2768 "glVertexBindingDivisor");
2769 }
2770
2771
2772 void GLAPIENTRY
2773 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj, GLuint bindingIndex,
2774 GLuint divisor)
2775 {
2776 GET_CURRENT_CONTEXT(ctx);
2777
2778 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2779 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2780 }
2781
2782
2783 void GLAPIENTRY
2784 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
2785 GLuint divisor)
2786 {
2787 struct gl_vertex_array_object *vao;
2788 GET_CURRENT_CONTEXT(ctx);
2789
2790 /* The ARB_direct_state_access specification says:
2791 *
2792 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2793 * if <vaobj> is not [compatibility profile: zero or] the name of an
2794 * existing vertex array object."
2795 */
2796 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2797 if (!vao)
2798 return;
2799
2800 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2801 "glVertexArrayBindingDivisor");
2802 }
2803
2804
2805 /**
2806 * Copy one vertex array to another.
2807 */
2808 void
2809 _mesa_copy_vertex_array(struct gl_context *ctx,
2810 struct gl_vertex_array *dst,
2811 struct gl_vertex_array *src)
2812 {
2813 dst->Size = src->Size;
2814 dst->Type = src->Type;
2815 dst->Format = src->Format;
2816 dst->StrideB = src->StrideB;
2817 dst->Ptr = src->Ptr;
2818 dst->Normalized = src->Normalized;
2819 dst->Integer = src->Integer;
2820 dst->Doubles = src->Doubles;
2821 dst->InstanceDivisor = src->InstanceDivisor;
2822 dst->_ElementSize = src->_ElementSize;
2823 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2824 }
2825
2826 void
2827 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2828 struct gl_array_attributes *dst,
2829 const struct gl_array_attributes *src)
2830 {
2831 dst->Size = src->Size;
2832 dst->Type = src->Type;
2833 dst->Format = src->Format;
2834 dst->BufferBindingIndex = src->BufferBindingIndex;
2835 dst->RelativeOffset = src->RelativeOffset;
2836 dst->Format = src->Format;
2837 dst->Integer = src->Integer;
2838 dst->Doubles = src->Doubles;
2839 dst->Normalized = src->Normalized;
2840 dst->Ptr = src->Ptr;
2841 dst->Enabled = src->Enabled;
2842 dst->_ElementSize = src->_ElementSize;
2843 }
2844
2845 void
2846 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2847 struct gl_vertex_buffer_binding *dst,
2848 const struct gl_vertex_buffer_binding *src)
2849 {
2850 dst->Offset = src->Offset;
2851 dst->Stride = src->Stride;
2852 dst->InstanceDivisor = src->InstanceDivisor;
2853 dst->_BoundArrays = src->_BoundArrays;
2854
2855 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2856 }
2857
2858 /**
2859 * Print current vertex object/array info. For debug.
2860 */
2861 void
2862 _mesa_print_arrays(struct gl_context *ctx)
2863 {
2864 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
2865
2866 fprintf(stderr, "Array Object %u\n", vao->Name);
2867
2868 gl_vert_attrib i;
2869 for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
2870 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
2871 if (!array->Enabled)
2872 continue;
2873
2874 const struct gl_vertex_buffer_binding *binding =
2875 &vao->BufferBinding[array->BufferBindingIndex];
2876 const struct gl_buffer_object *bo = binding->BufferObj;
2877
2878 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2879 "Stride=%d, Buffer=%u(Size %lu)\n",
2880 gl_vert_attrib_name((gl_vert_attrib)i),
2881 array->Ptr, _mesa_enum_to_string(array->Type), array->Size,
2882 array->_ElementSize, binding->Stride, bo->Name,
2883 (unsigned long) bo->Size);
2884 }
2885 }
2886
2887
2888 /**
2889 * Initialize vertex array state for given context.
2890 */
2891 void
2892 _mesa_init_varray(struct gl_context *ctx)
2893 {
2894 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
2895 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2896 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2897
2898 ctx->Array.Objects = _mesa_NewHashTable();
2899 }
2900
2901
2902 /**
2903 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2904 */
2905 static void
2906 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2907 {
2908 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2909 struct gl_context *ctx = (struct gl_context *) userData;
2910 _mesa_delete_vao(ctx, vao);
2911 }
2912
2913
2914 /**
2915 * Free vertex array state for given context.
2916 */
2917 void
2918 _mesa_free_varray_data(struct gl_context *ctx)
2919 {
2920 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2921 _mesa_DeleteHashTable(ctx->Array.Objects);
2922 }