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