mesa: move error handling into disable_vertex_array_attrib() callers
[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 GLbitfield64 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 < ARRAY_SIZE(vao->VertexAttrib));
1068
1069 if (!vao->VertexAttrib[attrib].Enabled) {
1070 /* was disabled, now being enabled */
1071 FLUSH_VERTICES(ctx, _NEW_ARRAY);
1072 vao->VertexAttrib[attrib].Enabled = GL_TRUE;
1073 vao->_Enabled |= VERT_BIT(attrib);
1074 vao->NewArrays |= VERT_BIT(attrib);
1075 }
1076 }
1077
1078 static void
1079 enable_vertex_array_attrib(struct gl_context *ctx,
1080 struct gl_vertex_array_object *vao,
1081 GLuint index,
1082 const char *func)
1083 {
1084 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1085 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
1086 return;
1087 }
1088
1089 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1090 }
1091
1092
1093 void GLAPIENTRY
1094 _mesa_EnableVertexAttribArray(GLuint index)
1095 {
1096 GET_CURRENT_CONTEXT(ctx);
1097 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
1098 "glEnableVertexAttribArray");
1099 }
1100
1101
1102 void GLAPIENTRY
1103 _mesa_EnableVertexAttribArray_no_error(GLuint index)
1104 {
1105 GET_CURRENT_CONTEXT(ctx);
1106 _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO,
1107 VERT_ATTRIB_GENERIC(index));
1108 }
1109
1110
1111 void GLAPIENTRY
1112 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
1113 {
1114 GET_CURRENT_CONTEXT(ctx);
1115 struct gl_vertex_array_object *vao;
1116
1117 /* The ARB_direct_state_access specification says:
1118 *
1119 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1120 * and DisableVertexArrayAttrib if <vaobj> is not
1121 * [compatibility profile: zero or] the name of an existing vertex
1122 * array object."
1123 */
1124 vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
1125 if (!vao)
1126 return;
1127
1128 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
1129 }
1130
1131
1132 void GLAPIENTRY
1133 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1134 {
1135 GET_CURRENT_CONTEXT(ctx);
1136 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1137 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1138 }
1139
1140
1141 static void
1142 disable_vertex_array_attrib(struct gl_context *ctx,
1143 struct gl_vertex_array_object *vao,
1144 GLuint index)
1145 {
1146 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
1147
1148 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
1149 /* was enabled, now being disabled */
1150 FLUSH_VERTICES(ctx, _NEW_ARRAY);
1151 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
1152 vao->_Enabled &= ~VERT_BIT_GENERIC(index);
1153 vao->NewArrays |= VERT_BIT_GENERIC(index);
1154 }
1155 }
1156
1157
1158 void GLAPIENTRY
1159 _mesa_DisableVertexAttribArray(GLuint index)
1160 {
1161 GET_CURRENT_CONTEXT(ctx);
1162
1163 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1164 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexAttribArray(index)");
1165 return;
1166 }
1167
1168 disable_vertex_array_attrib(ctx, ctx->Array.VAO, index);
1169 }
1170
1171
1172 void GLAPIENTRY
1173 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
1174 {
1175 GET_CURRENT_CONTEXT(ctx);
1176 struct gl_vertex_array_object *vao;
1177
1178 /* The ARB_direct_state_access specification says:
1179 *
1180 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1181 * and DisableVertexArrayAttrib if <vaobj> is not
1182 * [compatibility profile: zero or] the name of an existing vertex
1183 * array object."
1184 */
1185 vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
1186 if (!vao)
1187 return;
1188
1189 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1190 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
1191 return;
1192 }
1193
1194 disable_vertex_array_attrib(ctx, vao, index);
1195 }
1196
1197
1198 /**
1199 * Return info for a vertex attribute array (no alias with legacy
1200 * vertex attributes (pos, normal, color, etc)). This function does
1201 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1202 */
1203 static GLuint
1204 get_vertex_array_attrib(struct gl_context *ctx,
1205 const struct gl_vertex_array_object *vao,
1206 GLuint index, GLenum pname,
1207 const char *caller)
1208 {
1209 const struct gl_array_attributes *array;
1210
1211 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1212 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
1213 return 0;
1214 }
1215
1216 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
1217
1218 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
1219
1220 switch (pname) {
1221 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
1222 return array->Enabled;
1223 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
1224 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
1225 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
1226 return array->Stride;
1227 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
1228 return array->Type;
1229 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
1230 return array->Normalized;
1231 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
1232 return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name;
1233 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1234 if ((_mesa_is_desktop_gl(ctx)
1235 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
1236 || _mesa_is_gles3(ctx)) {
1237 return array->Integer;
1238 }
1239 goto error;
1240 case GL_VERTEX_ATTRIB_ARRAY_LONG:
1241 if (_mesa_is_desktop_gl(ctx)) {
1242 return array->Doubles;
1243 }
1244 goto error;
1245 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
1246 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
1247 || _mesa_is_gles3(ctx)) {
1248 return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor;
1249 }
1250 goto error;
1251 case GL_VERTEX_ATTRIB_BINDING:
1252 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1253 return array->BufferBindingIndex - VERT_ATTRIB_GENERIC0;
1254 }
1255 goto error;
1256 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
1257 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1258 return array->RelativeOffset;
1259 }
1260 goto error;
1261 default:
1262 ; /* fall-through */
1263 }
1264
1265 error:
1266 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
1267 return 0;
1268 }
1269
1270
1271 static const GLfloat *
1272 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
1273 {
1274 if (index == 0) {
1275 if (_mesa_attr_zero_aliases_vertex(ctx)) {
1276 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
1277 return NULL;
1278 }
1279 }
1280 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1281 _mesa_error(ctx, GL_INVALID_VALUE,
1282 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
1283 return NULL;
1284 }
1285
1286 assert(VERT_ATTRIB_GENERIC(index) <
1287 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1288
1289 FLUSH_CURRENT(ctx, 0);
1290 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
1291 }
1292
1293 void GLAPIENTRY
1294 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
1295 {
1296 GET_CURRENT_CONTEXT(ctx);
1297
1298 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1299 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
1300 if (v != NULL) {
1301 COPY_4V(params, v);
1302 }
1303 }
1304 else {
1305 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1306 index, pname,
1307 "glGetVertexAttribfv");
1308 }
1309 }
1310
1311
1312 void GLAPIENTRY
1313 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
1314 {
1315 GET_CURRENT_CONTEXT(ctx);
1316
1317 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1318 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
1319 if (v != NULL) {
1320 params[0] = (GLdouble) v[0];
1321 params[1] = (GLdouble) v[1];
1322 params[2] = (GLdouble) v[2];
1323 params[3] = (GLdouble) v[3];
1324 }
1325 }
1326 else {
1327 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1328 index, pname,
1329 "glGetVertexAttribdv");
1330 }
1331 }
1332
1333 void GLAPIENTRY
1334 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
1335 {
1336 GET_CURRENT_CONTEXT(ctx);
1337
1338 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1339 const GLdouble *v =
1340 (const GLdouble *)get_current_attrib(ctx, index,
1341 "glGetVertexAttribLdv");
1342 if (v != NULL) {
1343 params[0] = v[0];
1344 params[1] = v[1];
1345 params[2] = v[2];
1346 params[3] = v[3];
1347 }
1348 }
1349 else {
1350 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1351 index, pname,
1352 "glGetVertexAttribLdv");
1353 }
1354 }
1355
1356 void GLAPIENTRY
1357 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1358 {
1359 GET_CURRENT_CONTEXT(ctx);
1360
1361 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1362 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1363 if (v != NULL) {
1364 /* XXX should floats in[0,1] be scaled to full int range? */
1365 params[0] = (GLint) v[0];
1366 params[1] = (GLint) v[1];
1367 params[2] = (GLint) v[2];
1368 params[3] = (GLint) v[3];
1369 }
1370 }
1371 else {
1372 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1373 index, pname,
1374 "glGetVertexAttribiv");
1375 }
1376 }
1377
1378 void GLAPIENTRY
1379 _mesa_GetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT *params)
1380 {
1381 GET_CURRENT_CONTEXT(ctx);
1382
1383 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1384 const GLuint64 *v =
1385 (const GLuint64 *)get_current_attrib(ctx, index,
1386 "glGetVertexAttribLui64vARB");
1387 if (v != NULL) {
1388 params[0] = v[0];
1389 params[1] = v[1];
1390 params[2] = v[2];
1391 params[3] = v[3];
1392 }
1393 }
1394 else {
1395 params[0] = (GLuint64) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1396 index, pname,
1397 "glGetVertexAttribLui64vARB");
1398 }
1399 }
1400
1401
1402 /** GL 3.0 */
1403 void GLAPIENTRY
1404 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1405 {
1406 GET_CURRENT_CONTEXT(ctx);
1407
1408 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1409 const GLint *v = (const GLint *)
1410 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1411 if (v != NULL) {
1412 COPY_4V(params, v);
1413 }
1414 }
1415 else {
1416 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1417 index, pname,
1418 "glGetVertexAttribIiv");
1419 }
1420 }
1421
1422
1423 /** GL 3.0 */
1424 void GLAPIENTRY
1425 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1426 {
1427 GET_CURRENT_CONTEXT(ctx);
1428
1429 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1430 const GLuint *v = (const GLuint *)
1431 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1432 if (v != NULL) {
1433 COPY_4V(params, v);
1434 }
1435 }
1436 else {
1437 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1438 index, pname,
1439 "glGetVertexAttribIuiv");
1440 }
1441 }
1442
1443
1444 void GLAPIENTRY
1445 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1446 {
1447 GET_CURRENT_CONTEXT(ctx);
1448
1449 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1450 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1451 return;
1452 }
1453
1454 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1455 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1456 return;
1457 }
1458
1459 assert(VERT_ATTRIB_GENERIC(index) <
1460 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1461
1462 *pointer = (GLvoid *)
1463 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1464 }
1465
1466
1467 /** ARB_direct_state_access */
1468 void GLAPIENTRY
1469 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1470 GLenum pname, GLint *params)
1471 {
1472 GET_CURRENT_CONTEXT(ctx);
1473 struct gl_vertex_array_object *vao;
1474
1475 /* The ARB_direct_state_access specification says:
1476 *
1477 * "An INVALID_OPERATION error is generated if <vaobj> is not
1478 * [compatibility profile: zero or] the name of an existing
1479 * vertex array object."
1480 */
1481 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1482 if (!vao)
1483 return;
1484
1485 /* The ARB_direct_state_access specification says:
1486 *
1487 * "For GetVertexArrayIndexediv, <pname> must be one of
1488 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1489 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1490 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1491 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1492 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1493 *
1494 * and:
1495 *
1496 * "Add GetVertexArrayIndexediv in 'Get Command' for
1497 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1498 * VERTEX_ATTRIB_BINDING,
1499 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1500 * VERTEX_BINDING_OFFSET, and
1501 * VERTEX_BINDING_STRIDE states"
1502 *
1503 * The only parameter name common to both lists is
1504 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1505 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1506 * pretty clear however that the intent is that it should be possible
1507 * to query all vertex attrib and binding states that can be set with
1508 * a DSA function.
1509 */
1510 switch (pname) {
1511 case GL_VERTEX_BINDING_OFFSET:
1512 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1513 break;
1514 case GL_VERTEX_BINDING_STRIDE:
1515 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1516 break;
1517 case GL_VERTEX_BINDING_DIVISOR:
1518 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1519 break;
1520 case GL_VERTEX_BINDING_BUFFER:
1521 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1522 break;
1523 default:
1524 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1525 "glGetVertexArrayIndexediv");
1526 break;
1527 }
1528 }
1529
1530
1531 void GLAPIENTRY
1532 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1533 GLenum pname, GLint64 *params)
1534 {
1535 GET_CURRENT_CONTEXT(ctx);
1536 struct gl_vertex_array_object *vao;
1537
1538 /* The ARB_direct_state_access specification says:
1539 *
1540 * "An INVALID_OPERATION error is generated if <vaobj> is not
1541 * [compatibility profile: zero or] the name of an existing
1542 * vertex array object."
1543 */
1544 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1545 if (!vao)
1546 return;
1547
1548 /* The ARB_direct_state_access specification says:
1549 *
1550 * "For GetVertexArrayIndexed64iv, <pname> must be
1551 * VERTEX_BINDING_OFFSET."
1552 *
1553 * and:
1554 *
1555 * "An INVALID_ENUM error is generated if <pname> is not one of
1556 * the valid values listed above for the corresponding command."
1557 */
1558 if (pname != GL_VERTEX_BINDING_OFFSET) {
1559 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1560 "pname != GL_VERTEX_BINDING_OFFSET)");
1561 return;
1562 }
1563
1564 /* The ARB_direct_state_access specification says:
1565 *
1566 * "An INVALID_VALUE error is generated if <index> is greater than
1567 * or equal to the value of MAX_VERTEX_ATTRIBS."
1568 *
1569 * Since the index refers to a buffer binding in this case, the intended
1570 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1571 * required to be the same, so in practice this doesn't matter.
1572 */
1573 if (index >= ctx->Const.MaxVertexAttribBindings) {
1574 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
1575 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1576 index, ctx->Const.MaxVertexAttribBindings);
1577 return;
1578 }
1579
1580 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1581 }
1582
1583
1584 void GLAPIENTRY
1585 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1586 GLsizei count, const GLvoid *ptr)
1587 {
1588 (void) count;
1589 _mesa_VertexPointer(size, type, stride, ptr);
1590 }
1591
1592
1593 void GLAPIENTRY
1594 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1595 const GLvoid *ptr)
1596 {
1597 (void) count;
1598 _mesa_NormalPointer(type, stride, ptr);
1599 }
1600
1601
1602 void GLAPIENTRY
1603 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1604 const GLvoid *ptr)
1605 {
1606 (void) count;
1607 _mesa_ColorPointer(size, type, stride, ptr);
1608 }
1609
1610
1611 void GLAPIENTRY
1612 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1613 const GLvoid *ptr)
1614 {
1615 (void) count;
1616 _mesa_IndexPointer(type, stride, ptr);
1617 }
1618
1619
1620 void GLAPIENTRY
1621 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1622 GLsizei count, const GLvoid *ptr)
1623 {
1624 (void) count;
1625 _mesa_TexCoordPointer(size, type, stride, ptr);
1626 }
1627
1628
1629 void GLAPIENTRY
1630 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1631 {
1632 (void) count;
1633 _mesa_EdgeFlagPointer(stride, ptr);
1634 }
1635
1636
1637 void GLAPIENTRY
1638 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1639 {
1640 GET_CURRENT_CONTEXT(ctx);
1641 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1642 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1643 GLenum ctype = 0; /* color type */
1644 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1645 const GLint toffset = 0; /* always zero */
1646 GLint defstride; /* default stride */
1647 GLint c, f;
1648
1649 FLUSH_VERTICES(ctx, 0);
1650
1651 f = sizeof(GLfloat);
1652 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1653
1654 if (stride < 0) {
1655 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1656 return;
1657 }
1658
1659 switch (format) {
1660 case GL_V2F:
1661 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1662 tcomps = 0; ccomps = 0; vcomps = 2;
1663 voffset = 0;
1664 defstride = 2*f;
1665 break;
1666 case GL_V3F:
1667 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1668 tcomps = 0; ccomps = 0; vcomps = 3;
1669 voffset = 0;
1670 defstride = 3*f;
1671 break;
1672 case GL_C4UB_V2F:
1673 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1674 tcomps = 0; ccomps = 4; vcomps = 2;
1675 ctype = GL_UNSIGNED_BYTE;
1676 coffset = 0;
1677 voffset = c;
1678 defstride = c + 2*f;
1679 break;
1680 case GL_C4UB_V3F:
1681 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1682 tcomps = 0; ccomps = 4; vcomps = 3;
1683 ctype = GL_UNSIGNED_BYTE;
1684 coffset = 0;
1685 voffset = c;
1686 defstride = c + 3*f;
1687 break;
1688 case GL_C3F_V3F:
1689 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1690 tcomps = 0; ccomps = 3; vcomps = 3;
1691 ctype = GL_FLOAT;
1692 coffset = 0;
1693 voffset = 3*f;
1694 defstride = 6*f;
1695 break;
1696 case GL_N3F_V3F:
1697 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1698 tcomps = 0; ccomps = 0; vcomps = 3;
1699 noffset = 0;
1700 voffset = 3*f;
1701 defstride = 6*f;
1702 break;
1703 case GL_C4F_N3F_V3F:
1704 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1705 tcomps = 0; ccomps = 4; vcomps = 3;
1706 ctype = GL_FLOAT;
1707 coffset = 0;
1708 noffset = 4*f;
1709 voffset = 7*f;
1710 defstride = 10*f;
1711 break;
1712 case GL_T2F_V3F:
1713 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1714 tcomps = 2; ccomps = 0; vcomps = 3;
1715 voffset = 2*f;
1716 defstride = 5*f;
1717 break;
1718 case GL_T4F_V4F:
1719 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1720 tcomps = 4; ccomps = 0; vcomps = 4;
1721 voffset = 4*f;
1722 defstride = 8*f;
1723 break;
1724 case GL_T2F_C4UB_V3F:
1725 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1726 tcomps = 2; ccomps = 4; vcomps = 3;
1727 ctype = GL_UNSIGNED_BYTE;
1728 coffset = 2*f;
1729 voffset = c+2*f;
1730 defstride = c+5*f;
1731 break;
1732 case GL_T2F_C3F_V3F:
1733 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1734 tcomps = 2; ccomps = 3; vcomps = 3;
1735 ctype = GL_FLOAT;
1736 coffset = 2*f;
1737 voffset = 5*f;
1738 defstride = 8*f;
1739 break;
1740 case GL_T2F_N3F_V3F:
1741 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1742 tcomps = 2; ccomps = 0; vcomps = 3;
1743 noffset = 2*f;
1744 voffset = 5*f;
1745 defstride = 8*f;
1746 break;
1747 case GL_T2F_C4F_N3F_V3F:
1748 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1749 tcomps = 2; ccomps = 4; vcomps = 3;
1750 ctype = GL_FLOAT;
1751 coffset = 2*f;
1752 noffset = 6*f;
1753 voffset = 9*f;
1754 defstride = 12*f;
1755 break;
1756 case GL_T4F_C4F_N3F_V4F:
1757 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1758 tcomps = 4; ccomps = 4; vcomps = 4;
1759 ctype = GL_FLOAT;
1760 coffset = 4*f;
1761 noffset = 8*f;
1762 voffset = 11*f;
1763 defstride = 15*f;
1764 break;
1765 default:
1766 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1767 return;
1768 }
1769
1770 if (stride==0) {
1771 stride = defstride;
1772 }
1773
1774 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1775 _mesa_DisableClientState( GL_INDEX_ARRAY );
1776 /* XXX also disable secondary color and generic arrays? */
1777
1778 /* Texcoords */
1779 if (tflag) {
1780 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1781 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1782 (GLubyte *) pointer + toffset );
1783 }
1784 else {
1785 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1786 }
1787
1788 /* Color */
1789 if (cflag) {
1790 _mesa_EnableClientState( GL_COLOR_ARRAY );
1791 _mesa_ColorPointer( ccomps, ctype, stride,
1792 (GLubyte *) pointer + coffset );
1793 }
1794 else {
1795 _mesa_DisableClientState( GL_COLOR_ARRAY );
1796 }
1797
1798
1799 /* Normals */
1800 if (nflag) {
1801 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1802 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1803 }
1804 else {
1805 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1806 }
1807
1808 /* Vertices */
1809 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1810 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1811 (GLubyte *) pointer + voffset );
1812 }
1813
1814
1815 void GLAPIENTRY
1816 _mesa_LockArraysEXT(GLint first, GLsizei count)
1817 {
1818 GET_CURRENT_CONTEXT(ctx);
1819
1820 FLUSH_VERTICES(ctx, 0);
1821
1822 if (MESA_VERBOSE & VERBOSE_API)
1823 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1824
1825 if (first < 0) {
1826 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1827 return;
1828 }
1829 if (count <= 0) {
1830 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1831 return;
1832 }
1833 if (ctx->Array.LockCount != 0) {
1834 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1835 return;
1836 }
1837
1838 ctx->Array.LockFirst = first;
1839 ctx->Array.LockCount = count;
1840
1841 ctx->NewState |= _NEW_ARRAY;
1842 }
1843
1844
1845 void GLAPIENTRY
1846 _mesa_UnlockArraysEXT( void )
1847 {
1848 GET_CURRENT_CONTEXT(ctx);
1849
1850 FLUSH_VERTICES(ctx, 0);
1851
1852 if (MESA_VERBOSE & VERBOSE_API)
1853 _mesa_debug(ctx, "glUnlockArrays\n");
1854
1855 if (ctx->Array.LockCount == 0) {
1856 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1857 return;
1858 }
1859
1860 ctx->Array.LockFirst = 0;
1861 ctx->Array.LockCount = 0;
1862 ctx->NewState |= _NEW_ARRAY;
1863 }
1864
1865
1866 /* GL_IBM_multimode_draw_arrays */
1867 void GLAPIENTRY
1868 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1869 const GLsizei * count,
1870 GLsizei primcount, GLint modestride )
1871 {
1872 GET_CURRENT_CONTEXT(ctx);
1873 GLint i;
1874
1875 FLUSH_VERTICES(ctx, 0);
1876
1877 for ( i = 0 ; i < primcount ; i++ ) {
1878 if ( count[i] > 0 ) {
1879 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1880 CALL_DrawArrays(ctx->CurrentServerDispatch, ( m, first[i], count[i] ));
1881 }
1882 }
1883 }
1884
1885
1886 /* GL_IBM_multimode_draw_arrays */
1887 void GLAPIENTRY
1888 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1889 GLenum type, const GLvoid * const * indices,
1890 GLsizei primcount, GLint modestride )
1891 {
1892 GET_CURRENT_CONTEXT(ctx);
1893 GLint i;
1894
1895 FLUSH_VERTICES(ctx, 0);
1896
1897 /* XXX not sure about ARB_vertex_buffer_object handling here */
1898
1899 for ( i = 0 ; i < primcount ; i++ ) {
1900 if ( count[i] > 0 ) {
1901 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1902 CALL_DrawElements(ctx->CurrentServerDispatch, ( m, count[i], type,
1903 indices[i] ));
1904 }
1905 }
1906 }
1907
1908
1909 /**
1910 * GL_NV_primitive_restart and GL 3.1
1911 */
1912 void GLAPIENTRY
1913 _mesa_PrimitiveRestartIndex(GLuint index)
1914 {
1915 GET_CURRENT_CONTEXT(ctx);
1916
1917 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1918 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1919 return;
1920 }
1921
1922 if (ctx->Array.RestartIndex != index) {
1923 FLUSH_VERTICES(ctx, 0);
1924 ctx->Array.RestartIndex = index;
1925 }
1926 }
1927
1928
1929 void GLAPIENTRY
1930 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor)
1931 {
1932 GET_CURRENT_CONTEXT(ctx);
1933
1934 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1935 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1936
1937 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1938
1939 /* The ARB_vertex_attrib_binding spec says:
1940 *
1941 * "The command
1942 *
1943 * void VertexAttribDivisor(uint index, uint divisor);
1944 *
1945 * is equivalent to (assuming no errors are generated):
1946 *
1947 * VertexAttribBinding(index, index);
1948 * VertexBindingDivisor(index, divisor);"
1949 */
1950 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
1951 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
1952 }
1953
1954
1955 /**
1956 * See GL_ARB_instanced_arrays.
1957 * Note that the instance divisor only applies to generic arrays, not
1958 * the legacy vertex arrays.
1959 */
1960 void GLAPIENTRY
1961 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1962 {
1963 GET_CURRENT_CONTEXT(ctx);
1964
1965 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1966 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1967
1968 if (!ctx->Extensions.ARB_instanced_arrays) {
1969 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1970 return;
1971 }
1972
1973 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1974 _mesa_error(ctx, GL_INVALID_VALUE,
1975 "glVertexAttribDivisor(index = %u)", index);
1976 return;
1977 }
1978
1979 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1980
1981 /* The ARB_vertex_attrib_binding spec says:
1982 *
1983 * "The command
1984 *
1985 * void VertexAttribDivisor(uint index, uint divisor);
1986 *
1987 * is equivalent to (assuming no errors are generated):
1988 *
1989 * VertexAttribBinding(index, index);
1990 * VertexBindingDivisor(index, divisor);"
1991 */
1992 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
1993 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
1994 }
1995
1996
1997 static ALWAYS_INLINE void
1998 vertex_array_vertex_buffer(struct gl_context *ctx,
1999 struct gl_vertex_array_object *vao,
2000 GLuint bindingIndex, GLuint buffer, GLintptr offset,
2001 GLsizei stride, bool no_error, const char *func)
2002 {
2003 struct gl_buffer_object *vbo;
2004 if (buffer ==
2005 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
2006 vbo = vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
2007 } else if (buffer != 0) {
2008 vbo = _mesa_lookup_bufferobj(ctx, buffer);
2009
2010 if (!no_error && !vbo && _mesa_is_gles31(ctx)) {
2011 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
2012 return;
2013 }
2014 /* From the GL_ARB_vertex_attrib_array spec:
2015 *
2016 * "[Core profile only:]
2017 * An INVALID_OPERATION error is generated if buffer is not zero or a
2018 * name returned from a previous call to GenBuffers, or if such a name
2019 * has since been deleted with DeleteBuffers.
2020 *
2021 * Otherwise, we fall back to the same compat profile behavior as other
2022 * object references (automatically gen it).
2023 */
2024 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
2025 return;
2026 } else {
2027 /* The ARB_vertex_attrib_binding spec says:
2028 *
2029 * "If <buffer> is zero, any buffer object attached to this
2030 * bindpoint is detached."
2031 */
2032 vbo = ctx->Shared->NullBufferObj;
2033 }
2034
2035 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
2036 vbo, offset, stride);
2037 }
2038
2039
2040 /**
2041 * GL_ARB_vertex_attrib_binding
2042 */
2043 static void
2044 vertex_array_vertex_buffer_err(struct gl_context *ctx,
2045 struct gl_vertex_array_object *vao,
2046 GLuint bindingIndex, GLuint buffer,
2047 GLintptr offset, GLsizei stride,
2048 const char *func)
2049 {
2050 ASSERT_OUTSIDE_BEGIN_END(ctx);
2051
2052 /* The ARB_vertex_attrib_binding spec says:
2053 *
2054 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2055 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2056 */
2057 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2058 _mesa_error(ctx, GL_INVALID_VALUE,
2059 "%s(bindingindex=%u > "
2060 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2061 func, bindingIndex);
2062 return;
2063 }
2064
2065 /* The ARB_vertex_attrib_binding spec says:
2066 *
2067 * "The error INVALID_VALUE is generated if <stride> or <offset>
2068 * are negative."
2069 */
2070 if (offset < 0) {
2071 _mesa_error(ctx, GL_INVALID_VALUE,
2072 "%s(offset=%" PRId64 " < 0)",
2073 func, (int64_t) offset);
2074 return;
2075 }
2076
2077 if (stride < 0) {
2078 _mesa_error(ctx, GL_INVALID_VALUE,
2079 "%s(stride=%d < 0)", func, stride);
2080 return;
2081 }
2082
2083 if (((ctx->API == API_OPENGL_CORE && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
2084 stride > ctx->Const.MaxVertexAttribStride) {
2085 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
2086 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
2087 return;
2088 }
2089
2090 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2091 stride, false, func);
2092 }
2093
2094
2095 void GLAPIENTRY
2096 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer,
2097 GLintptr offset, GLsizei stride)
2098 {
2099 GET_CURRENT_CONTEXT(ctx);
2100 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
2101 buffer, offset, stride, true,
2102 "glBindVertexBuffer");
2103 }
2104
2105
2106 void GLAPIENTRY
2107 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
2108 GLsizei stride)
2109 {
2110 GET_CURRENT_CONTEXT(ctx);
2111
2112 /* The ARB_vertex_attrib_binding spec says:
2113 *
2114 * "An INVALID_OPERATION error is generated if no vertex array object
2115 * is bound."
2116 */
2117 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2118 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2119 _mesa_error(ctx, GL_INVALID_OPERATION,
2120 "glBindVertexBuffer(No array object bound)");
2121 return;
2122 }
2123
2124 vertex_array_vertex_buffer_err(ctx, ctx->Array.VAO, bindingIndex,
2125 buffer, offset, stride,
2126 "glBindVertexBuffer");
2127 }
2128
2129
2130 void GLAPIENTRY
2131 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex,
2132 GLuint buffer, GLintptr offset,
2133 GLsizei stride)
2134 {
2135 GET_CURRENT_CONTEXT(ctx);
2136
2137 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2138 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2139 stride, true, "glVertexArrayVertexBuffer");
2140 }
2141
2142
2143 void GLAPIENTRY
2144 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
2145 GLintptr offset, GLsizei stride)
2146 {
2147 GET_CURRENT_CONTEXT(ctx);
2148 struct gl_vertex_array_object *vao;
2149
2150 /* The ARB_direct_state_access specification says:
2151 *
2152 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2153 * if <vaobj> is not [compatibility profile: zero or] the name of an
2154 * existing vertex array object."
2155 */
2156 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
2157 if (!vao)
2158 return;
2159
2160 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
2161 stride, "glVertexArrayVertexBuffer");
2162 }
2163
2164
2165 static ALWAYS_INLINE void
2166 vertex_array_vertex_buffers(struct gl_context *ctx,
2167 struct gl_vertex_array_object *vao,
2168 GLuint first, GLsizei count, const GLuint *buffers,
2169 const GLintptr *offsets, const GLsizei *strides,
2170 bool no_error, const char *func)
2171 {
2172 GLint i;
2173
2174 if (!buffers) {
2175 /**
2176 * The ARB_multi_bind spec says:
2177 *
2178 * "If <buffers> is NULL, each affected vertex buffer binding point
2179 * from <first> through <first>+<count>-1 will be reset to have no
2180 * bound buffer object. In this case, the offsets and strides
2181 * associated with the binding points are set to default values,
2182 * ignoring <offsets> and <strides>."
2183 */
2184 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
2185
2186 for (i = 0; i < count; i++)
2187 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2188 vbo, 0, 16);
2189
2190 return;
2191 }
2192
2193 /* Note that the error semantics for multi-bind commands differ from
2194 * those of other GL commands.
2195 *
2196 * The Issues section in the ARB_multi_bind spec says:
2197 *
2198 * "(11) Typically, OpenGL specifies that if an error is generated by
2199 * a command, that command has no effect. This is somewhat
2200 * unfortunate for multi-bind commands, because it would require
2201 * a first pass to scan the entire list of bound objects for
2202 * errors and then a second pass to actually perform the
2203 * bindings. Should we have different error semantics?
2204 *
2205 * RESOLVED: Yes. In this specification, when the parameters for
2206 * one of the <count> binding points are invalid, that binding
2207 * point is not updated and an error will be generated. However,
2208 * other binding points in the same command will be updated if
2209 * their parameters are valid and no other error occurs."
2210 */
2211
2212 _mesa_HashLockMutex(ctx->Shared->BufferObjects);
2213
2214 for (i = 0; i < count; i++) {
2215 struct gl_buffer_object *vbo;
2216
2217 if (!no_error) {
2218 /* The ARB_multi_bind spec says:
2219 *
2220 * "An INVALID_VALUE error is generated if any value in
2221 * <offsets> or <strides> is negative (per binding)."
2222 */
2223 if (offsets[i] < 0) {
2224 _mesa_error(ctx, GL_INVALID_VALUE,
2225 "%s(offsets[%u]=%" PRId64 " < 0)",
2226 func, i, (int64_t) offsets[i]);
2227 continue;
2228 }
2229
2230 if (strides[i] < 0) {
2231 _mesa_error(ctx, GL_INVALID_VALUE,
2232 "%s(strides[%u]=%d < 0)",
2233 func, i, strides[i]);
2234 continue;
2235 }
2236
2237 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
2238 strides[i] > ctx->Const.MaxVertexAttribStride) {
2239 _mesa_error(ctx, GL_INVALID_VALUE,
2240 "%s(strides[%u]=%d > "
2241 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
2242 continue;
2243 }
2244 }
2245
2246 if (buffers[i]) {
2247 struct gl_vertex_buffer_binding *binding =
2248 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
2249
2250 if (buffers[i] == binding->BufferObj->Name)
2251 vbo = binding->BufferObj;
2252 else
2253 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
2254
2255 if (!vbo)
2256 continue;
2257 } else {
2258 vbo = ctx->Shared->NullBufferObj;
2259 }
2260
2261 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2262 vbo, offsets[i], strides[i]);
2263 }
2264
2265 _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
2266 }
2267
2268
2269 static void
2270 vertex_array_vertex_buffers_err(struct gl_context *ctx,
2271 struct gl_vertex_array_object *vao,
2272 GLuint first, GLsizei count,
2273 const GLuint *buffers, const GLintptr *offsets,
2274 const GLsizei *strides, const char *func)
2275 {
2276 ASSERT_OUTSIDE_BEGIN_END(ctx);
2277
2278 /* The ARB_multi_bind spec says:
2279 *
2280 * "An INVALID_OPERATION error is generated if <first> + <count>
2281 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2282 */
2283 if (first + count > ctx->Const.MaxVertexAttribBindings) {
2284 _mesa_error(ctx, GL_INVALID_OPERATION,
2285 "%s(first=%u + count=%d > the value of "
2286 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2287 func, first, count, ctx->Const.MaxVertexAttribBindings);
2288 return;
2289 }
2290
2291 vertex_array_vertex_buffers(ctx, vao, first, count, buffers, offsets,
2292 strides, false, func);
2293 }
2294
2295
2296 void GLAPIENTRY
2297 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count,
2298 const GLuint *buffers, const GLintptr *offsets,
2299 const GLsizei *strides)
2300 {
2301 GET_CURRENT_CONTEXT(ctx);
2302
2303 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
2304 buffers, offsets, strides, true,
2305 "glBindVertexBuffers");
2306 }
2307
2308
2309 void GLAPIENTRY
2310 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
2311 const GLintptr *offsets, const GLsizei *strides)
2312 {
2313 GET_CURRENT_CONTEXT(ctx);
2314
2315 /* The ARB_vertex_attrib_binding spec says:
2316 *
2317 * "An INVALID_OPERATION error is generated if no
2318 * vertex array object is bound."
2319 */
2320 if (ctx->API == API_OPENGL_CORE &&
2321 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2322 _mesa_error(ctx, GL_INVALID_OPERATION,
2323 "glBindVertexBuffers(No array object bound)");
2324 return;
2325 }
2326
2327 vertex_array_vertex_buffers_err(ctx, ctx->Array.VAO, first, count,
2328 buffers, offsets, strides,
2329 "glBindVertexBuffers");
2330 }
2331
2332
2333 void GLAPIENTRY
2334 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first,
2335 GLsizei count, const GLuint *buffers,
2336 const GLintptr *offsets,
2337 const GLsizei *strides)
2338 {
2339 GET_CURRENT_CONTEXT(ctx);
2340
2341 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2342 vertex_array_vertex_buffers(ctx, vao, first, count,
2343 buffers, offsets, strides, true,
2344 "glVertexArrayVertexBuffers");
2345 }
2346
2347
2348 void GLAPIENTRY
2349 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
2350 const GLuint *buffers,
2351 const GLintptr *offsets, const GLsizei *strides)
2352 {
2353 GET_CURRENT_CONTEXT(ctx);
2354 struct gl_vertex_array_object *vao;
2355
2356 /* The ARB_direct_state_access specification says:
2357 *
2358 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2359 * if <vaobj> is not [compatibility profile: zero or] the name of an
2360 * existing vertex array object."
2361 */
2362 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
2363 if (!vao)
2364 return;
2365
2366 vertex_array_vertex_buffers_err(ctx, vao, first, count,
2367 buffers, offsets, strides,
2368 "glVertexArrayVertexBuffers");
2369 }
2370
2371
2372 static void
2373 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
2374 GLboolean normalized, GLboolean integer,
2375 GLboolean doubles, GLbitfield legalTypes,
2376 GLsizei sizeMax, GLuint relativeOffset,
2377 const char *func)
2378 {
2379 GET_CURRENT_CONTEXT(ctx);
2380 ASSERT_OUTSIDE_BEGIN_END(ctx);
2381
2382 GLenum format = get_array_format(ctx, sizeMax, &size);
2383
2384 if (!_mesa_is_no_error_enabled(ctx)) {
2385 /* The ARB_vertex_attrib_binding spec says:
2386 *
2387 * "An INVALID_OPERATION error is generated under any of the
2388 * following conditions:
2389 * - if no vertex array object is currently bound (see section
2390 * 2.10);
2391 * - ..."
2392 *
2393 * This error condition only applies to VertexAttribFormat and
2394 * VertexAttribIFormat in the extension spec, but we assume that this
2395 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2396 * to all three functions.
2397 */
2398 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2399 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2400 _mesa_error(ctx, GL_INVALID_OPERATION,
2401 "%s(No array object bound)", func);
2402 return;
2403 }
2404
2405 /* The ARB_vertex_attrib_binding spec says:
2406 *
2407 * "The error INVALID_VALUE is generated if index is greater than or
2408 * equal to the value of MAX_VERTEX_ATTRIBS."
2409 */
2410 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2411 _mesa_error(ctx, GL_INVALID_VALUE,
2412 "%s(attribindex=%u > "
2413 "GL_MAX_VERTEX_ATTRIBS)",
2414 func, attribIndex);
2415 return;
2416 }
2417
2418 if (!validate_array_format(ctx, func, ctx->Array.VAO,
2419 VERT_ATTRIB_GENERIC(attribIndex),
2420 legalTypes, 1, sizeMax, size, type,
2421 normalized, integer, doubles, relativeOffset,
2422 format)) {
2423 return;
2424 }
2425 }
2426
2427 FLUSH_VERTICES(ctx, 0);
2428
2429 _mesa_update_array_format(ctx, ctx->Array.VAO,
2430 VERT_ATTRIB_GENERIC(attribIndex), size, type,
2431 format, normalized, integer, doubles,
2432 relativeOffset);
2433 }
2434
2435
2436 void GLAPIENTRY
2437 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
2438 GLboolean normalized, GLuint relativeOffset)
2439 {
2440 vertex_attrib_format(attribIndex, size, type, normalized,
2441 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2442 BGRA_OR_4, relativeOffset,
2443 "glVertexAttribFormat");
2444 }
2445
2446
2447 void GLAPIENTRY
2448 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
2449 GLuint relativeOffset)
2450 {
2451 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2452 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2453 relativeOffset, "glVertexAttribIFormat");
2454 }
2455
2456
2457 void GLAPIENTRY
2458 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2459 GLuint relativeOffset)
2460 {
2461 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2462 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2463 relativeOffset, "glVertexAttribLFormat");
2464 }
2465
2466
2467 static void
2468 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2469 GLenum type, GLboolean normalized,
2470 GLboolean integer, GLboolean doubles,
2471 GLbitfield legalTypes, GLsizei sizeMax,
2472 GLuint relativeOffset, const char *func)
2473 {
2474 GET_CURRENT_CONTEXT(ctx);
2475 struct gl_vertex_array_object *vao;
2476
2477 ASSERT_OUTSIDE_BEGIN_END(ctx);
2478
2479 GLenum format = get_array_format(ctx, sizeMax, &size);
2480
2481 if (_mesa_is_no_error_enabled(ctx)) {
2482 vao = _mesa_lookup_vao(ctx, vaobj);
2483 if (!vao)
2484 return;
2485 } else {
2486 /* The ARB_direct_state_access spec says:
2487 *
2488 * "An INVALID_OPERATION error is generated by
2489 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2490 * zero or] the name of an existing vertex array object."
2491 */
2492 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2493 if (!vao)
2494 return;
2495
2496 /* The ARB_vertex_attrib_binding spec says:
2497 *
2498 * "The error INVALID_VALUE is generated if index is greater than or
2499 * equal to the value of MAX_VERTEX_ATTRIBS."
2500 */
2501 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2502 _mesa_error(ctx, GL_INVALID_VALUE,
2503 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2504 func, attribIndex);
2505 return;
2506 }
2507
2508 if (!validate_array_format(ctx, func, vao,
2509 VERT_ATTRIB_GENERIC(attribIndex),
2510 legalTypes, 1, sizeMax, size, type,
2511 normalized, integer, doubles, relativeOffset,
2512 format)) {
2513 return;
2514 }
2515 }
2516
2517 FLUSH_VERTICES(ctx, 0);
2518
2519 _mesa_update_array_format(ctx, vao, VERT_ATTRIB_GENERIC(attribIndex), size,
2520 type, format, normalized, integer, doubles,
2521 relativeOffset);
2522 }
2523
2524
2525 void GLAPIENTRY
2526 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2527 GLenum type, GLboolean normalized,
2528 GLuint relativeOffset)
2529 {
2530 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2531 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2532 BGRA_OR_4, relativeOffset,
2533 "glVertexArrayAttribFormat");
2534 }
2535
2536
2537 void GLAPIENTRY
2538 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2539 GLint size, GLenum type,
2540 GLuint relativeOffset)
2541 {
2542 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2543 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2544 4, relativeOffset,
2545 "glVertexArrayAttribIFormat");
2546 }
2547
2548
2549 void GLAPIENTRY
2550 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2551 GLint size, GLenum type,
2552 GLuint relativeOffset)
2553 {
2554 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2555 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2556 4, relativeOffset,
2557 "glVertexArrayAttribLFormat");
2558 }
2559
2560
2561 static void
2562 vertex_array_attrib_binding(struct gl_context *ctx,
2563 struct gl_vertex_array_object *vao,
2564 GLuint attribIndex, GLuint bindingIndex,
2565 const char *func)
2566 {
2567 ASSERT_OUTSIDE_BEGIN_END(ctx);
2568
2569 /* The ARB_vertex_attrib_binding spec says:
2570 *
2571 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2572 * <bindingindex> must be less than the value of
2573 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2574 * is generated."
2575 */
2576 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2577 _mesa_error(ctx, GL_INVALID_VALUE,
2578 "%s(attribindex=%u >= "
2579 "GL_MAX_VERTEX_ATTRIBS)",
2580 func, attribIndex);
2581 return;
2582 }
2583
2584 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2585 _mesa_error(ctx, GL_INVALID_VALUE,
2586 "%s(bindingindex=%u >= "
2587 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2588 func, bindingIndex);
2589 return;
2590 }
2591
2592 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2593
2594 vertex_attrib_binding(ctx, vao,
2595 VERT_ATTRIB_GENERIC(attribIndex),
2596 VERT_ATTRIB_GENERIC(bindingIndex));
2597 }
2598
2599
2600 void GLAPIENTRY
2601 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex)
2602 {
2603 GET_CURRENT_CONTEXT(ctx);
2604 vertex_attrib_binding(ctx, ctx->Array.VAO,
2605 VERT_ATTRIB_GENERIC(attribIndex),
2606 VERT_ATTRIB_GENERIC(bindingIndex));
2607 }
2608
2609
2610 void GLAPIENTRY
2611 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2612 {
2613 GET_CURRENT_CONTEXT(ctx);
2614
2615 /* The ARB_vertex_attrib_binding spec says:
2616 *
2617 * "An INVALID_OPERATION error is generated if no vertex array object
2618 * is bound."
2619 */
2620 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2621 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2622 _mesa_error(ctx, GL_INVALID_OPERATION,
2623 "glVertexAttribBinding(No array object bound)");
2624 return;
2625 }
2626
2627 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2628 attribIndex, bindingIndex,
2629 "glVertexAttribBinding");
2630 }
2631
2632
2633 void GLAPIENTRY
2634 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex,
2635 GLuint bindingIndex)
2636 {
2637 GET_CURRENT_CONTEXT(ctx);
2638
2639 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2640 vertex_attrib_binding(ctx, vao,
2641 VERT_ATTRIB_GENERIC(attribIndex),
2642 VERT_ATTRIB_GENERIC(bindingIndex));
2643 }
2644
2645
2646 void GLAPIENTRY
2647 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2648 {
2649 GET_CURRENT_CONTEXT(ctx);
2650 struct gl_vertex_array_object *vao;
2651
2652 /* The ARB_direct_state_access specification says:
2653 *
2654 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2655 * if <vaobj> is not [compatibility profile: zero or] the name of an
2656 * existing vertex array object."
2657 */
2658 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2659 if (!vao)
2660 return;
2661
2662 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2663 "glVertexArrayAttribBinding");
2664 }
2665
2666
2667 static void
2668 vertex_array_binding_divisor(struct gl_context *ctx,
2669 struct gl_vertex_array_object *vao,
2670 GLuint bindingIndex, GLuint divisor,
2671 const char *func)
2672 {
2673 ASSERT_OUTSIDE_BEGIN_END(ctx);
2674
2675 if (!ctx->Extensions.ARB_instanced_arrays) {
2676 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2677 return;
2678 }
2679
2680 /* The ARB_vertex_attrib_binding spec says:
2681 *
2682 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2683 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2684 */
2685 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2686 _mesa_error(ctx, GL_INVALID_VALUE,
2687 "%s(bindingindex=%u > "
2688 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2689 func, bindingIndex);
2690 return;
2691 }
2692
2693 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2694 }
2695
2696
2697 void GLAPIENTRY
2698 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2699 {
2700 GET_CURRENT_CONTEXT(ctx);
2701
2702 /* The ARB_vertex_attrib_binding spec says:
2703 *
2704 * "An INVALID_OPERATION error is generated if no vertex array object
2705 * is bound."
2706 */
2707 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2708 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2709 _mesa_error(ctx, GL_INVALID_OPERATION,
2710 "glVertexBindingDivisor(No array object bound)");
2711 return;
2712 }
2713
2714 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2715 bindingIndex, divisor,
2716 "glVertexBindingDivisor");
2717 }
2718
2719
2720 void GLAPIENTRY
2721 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
2722 GLuint divisor)
2723 {
2724 struct gl_vertex_array_object *vao;
2725 GET_CURRENT_CONTEXT(ctx);
2726
2727 /* The ARB_direct_state_access specification says:
2728 *
2729 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2730 * if <vaobj> is not [compatibility profile: zero or] the name of an
2731 * existing vertex array object."
2732 */
2733 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2734 if (!vao)
2735 return;
2736
2737 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2738 "glVertexArrayBindingDivisor");
2739 }
2740
2741
2742 /**
2743 * Copy one client vertex array to another.
2744 */
2745 void
2746 _mesa_copy_client_array(struct gl_context *ctx,
2747 struct gl_vertex_array *dst,
2748 struct gl_vertex_array *src)
2749 {
2750 dst->Size = src->Size;
2751 dst->Type = src->Type;
2752 dst->Format = src->Format;
2753 dst->StrideB = src->StrideB;
2754 dst->Ptr = src->Ptr;
2755 dst->Normalized = src->Normalized;
2756 dst->Integer = src->Integer;
2757 dst->Doubles = src->Doubles;
2758 dst->InstanceDivisor = src->InstanceDivisor;
2759 dst->_ElementSize = src->_ElementSize;
2760 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2761 }
2762
2763 void
2764 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2765 struct gl_array_attributes *dst,
2766 const struct gl_array_attributes *src)
2767 {
2768 dst->Size = src->Size;
2769 dst->Type = src->Type;
2770 dst->Format = src->Format;
2771 dst->BufferBindingIndex = src->BufferBindingIndex;
2772 dst->RelativeOffset = src->RelativeOffset;
2773 dst->Format = src->Format;
2774 dst->Integer = src->Integer;
2775 dst->Doubles = src->Doubles;
2776 dst->Normalized = src->Normalized;
2777 dst->Ptr = src->Ptr;
2778 dst->Enabled = src->Enabled;
2779 dst->_ElementSize = src->_ElementSize;
2780 }
2781
2782 void
2783 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2784 struct gl_vertex_buffer_binding *dst,
2785 const struct gl_vertex_buffer_binding *src)
2786 {
2787 dst->Offset = src->Offset;
2788 dst->Stride = src->Stride;
2789 dst->InstanceDivisor = src->InstanceDivisor;
2790 dst->_BoundArrays = src->_BoundArrays;
2791
2792 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2793 }
2794
2795 /**
2796 * Print current vertex object/array info. For debug.
2797 */
2798 void
2799 _mesa_print_arrays(struct gl_context *ctx)
2800 {
2801 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
2802
2803 fprintf(stderr, "Array Object %u\n", vao->Name);
2804
2805 unsigned i;
2806 for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
2807 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
2808 if (!array->Enabled)
2809 continue;
2810
2811 const struct gl_vertex_buffer_binding *binding =
2812 &vao->BufferBinding[array->BufferBindingIndex];
2813 const struct gl_buffer_object *bo = binding->BufferObj;
2814
2815 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2816 "Stride=%d, Buffer=%u(Size %lu)\n",
2817 gl_vert_attrib_name((gl_vert_attrib)i),
2818 array->Ptr, _mesa_enum_to_string(array->Type), array->Size,
2819 array->_ElementSize, binding->Stride, bo->Name,
2820 (unsigned long) bo->Size);
2821 }
2822 }
2823
2824
2825 /**
2826 * Initialize vertex array state for given context.
2827 */
2828 void
2829 _mesa_init_varray(struct gl_context *ctx)
2830 {
2831 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
2832 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2833 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2834
2835 ctx->Array.Objects = _mesa_NewHashTable();
2836 }
2837
2838
2839 /**
2840 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2841 */
2842 static void
2843 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2844 {
2845 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2846 struct gl_context *ctx = (struct gl_context *) userData;
2847 _mesa_delete_vao(ctx, vao);
2848 }
2849
2850
2851 /**
2852 * Free vertex array state for given context.
2853 */
2854 void
2855 _mesa_free_varray_data(struct gl_context *ctx)
2856 {
2857 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2858 _mesa_DeleteHashTable(ctx->Array.Objects);
2859 }