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