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