varray.c revision e5ef0cbe0e4e45df6ff74a2a40ddb83d8bc3a8cc
1/* 2 * Mesa 3-D graphics library 3 * Version: 7.6 4 * 5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, including without limitation 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * and/or sell copies of the Software, and to permit persons to whom the 13 * Software is furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included 16 * in all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26 27#include "glheader.h" 28#include "imports.h" 29#include "bufferobj.h" 30#include "context.h" 31#include "enable.h" 32#include "enums.h" 33#include "hash.h" 34#include "image.h" 35#include "macros.h" 36#include "mfeatures.h" 37#include "mtypes.h" 38#include "varray.h" 39#include "arrayobj.h" 40#include "main/dispatch.h" 41 42 43/** Used to do error checking for GL_EXT_vertex_array_bgra */ 44#define BGRA_OR_4 5 45 46 47/** Used to indicate which GL datatypes are accepted by each of the 48 * glVertex/Color/Attrib/EtcPointer() functions. 49 */ 50#define BOOL_BIT 0x1 51#define BYTE_BIT 0x2 52#define UNSIGNED_BYTE_BIT 0x4 53#define SHORT_BIT 0x8 54#define UNSIGNED_SHORT_BIT 0x10 55#define INT_BIT 0x20 56#define UNSIGNED_INT_BIT 0x40 57#define HALF_BIT 0x80 58#define FLOAT_BIT 0x100 59#define DOUBLE_BIT 0x200 60#define FIXED_ES_BIT 0x400 61#define FIXED_GL_BIT 0x800 62#define UNSIGNED_INT_2_10_10_10_REV_BIT 0x1000 63#define INT_2_10_10_10_REV_BIT 0x2000 64 65 66/** Convert GL datatype enum into a <type>_BIT value seen above */ 67static GLbitfield 68type_to_bit(const struct gl_context *ctx, GLenum type) 69{ 70 switch (type) { 71 case GL_BOOL: 72 return BOOL_BIT; 73 case GL_BYTE: 74 return BYTE_BIT; 75 case GL_UNSIGNED_BYTE: 76 return UNSIGNED_BYTE_BIT; 77 case GL_SHORT: 78 return SHORT_BIT; 79 case GL_UNSIGNED_SHORT: 80 return UNSIGNED_SHORT_BIT; 81 case GL_INT: 82 return INT_BIT; 83 case GL_UNSIGNED_INT: 84 return UNSIGNED_INT_BIT; 85 case GL_HALF_FLOAT: 86 if (ctx->Extensions.ARB_half_float_vertex) 87 return HALF_BIT; 88 else 89 return 0x0; 90 case GL_FLOAT: 91 return FLOAT_BIT; 92 case GL_DOUBLE: 93 return DOUBLE_BIT; 94 case GL_FIXED: 95 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT; 96 case GL_UNSIGNED_INT_2_10_10_10_REV: 97 return UNSIGNED_INT_2_10_10_10_REV_BIT; 98 case GL_INT_2_10_10_10_REV: 99 return INT_2_10_10_10_REV_BIT; 100 default: 101 return 0; 102 } 103} 104 105 106/** 107 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer 108 * functions. 109 * 110 * \param func name of calling function used for error reporting 111 * \param attrib the attribute array index to update 112 * \param legalTypes bitmask of *_BIT above indicating legal datatypes 113 * \param sizeMin min allowable size value 114 * \param sizeMax max allowable size value (may also be BGRA_OR_4) 115 * \param size components per element (1, 2, 3 or 4) 116 * \param type datatype of each component (GL_FLOAT, GL_INT, etc) 117 * \param stride stride between elements, in elements 118 * \param normalized are integer types converted to floats in [-1, 1]? 119 * \param integer integer-valued values (will not be normalized to [-1,1]) 120 * \param ptr the address (or offset inside VBO) of the array data 121 */ 122static void 123update_array(struct gl_context *ctx, 124 const char *func, 125 GLuint attrib, GLbitfield legalTypesMask, 126 GLint sizeMin, GLint sizeMax, 127 GLint size, GLenum type, GLsizei stride, 128 GLboolean normalized, GLboolean integer, 129 const GLvoid *ptr) 130{ 131 struct gl_client_array *array; 132 GLbitfield typeBit; 133 GLsizei elementSize; 134 GLenum format = GL_RGBA; 135 136 if (_mesa_is_gles(ctx)) { 137 /* Once Mesa gets support for GL_OES_vertex_half_float this mask will 138 * change. Adding support for this extension isn't quite as trivial as 139 * we'd like because ES uses a different enum value for GL_HALF_FLOAT. 140 */ 141 legalTypesMask &= ~(FIXED_GL_BIT | HALF_BIT | DOUBLE_BIT); 142 143 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until 144 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or 145 * GL_OES_vertex_type_10_10_10_2. 146 */ 147 if (ctx->Version < 30) { 148 legalTypesMask &= ~(UNSIGNED_INT_BIT 149 | INT_BIT 150 | UNSIGNED_INT_2_10_10_10_REV_BIT 151 | INT_2_10_10_10_REV_BIT); 152 } 153 154 /* BGRA ordering is not supported in ES contexts. 155 */ 156 if (sizeMax == BGRA_OR_4) 157 sizeMax = 4; 158 } else { 159 legalTypesMask &= ~FIXED_ES_BIT; 160 161 if (!ctx->Extensions.ARB_ES2_compatibility) 162 legalTypesMask &= ~FIXED_GL_BIT; 163 164 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) 165 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT | 166 INT_2_10_10_10_REV_BIT); 167 } 168 169 typeBit = type_to_bit(ctx, type); 170 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) { 171 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)", 172 func, _mesa_lookup_enum_by_nr(type)); 173 return; 174 } 175 176 /* Do size parameter checking. 177 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and 178 * must be handled specially. 179 */ 180 if (ctx->Extensions.EXT_vertex_array_bgra && 181 sizeMax == BGRA_OR_4 && 182 size == GL_BGRA) { 183 GLboolean bgra_error = GL_FALSE; 184 185 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) { 186 if (type != GL_UNSIGNED_INT_2_10_10_10_REV && 187 type != GL_INT_2_10_10_10_REV && 188 type != GL_UNSIGNED_BYTE) 189 bgra_error = GL_TRUE; 190 } else if (type != GL_UNSIGNED_BYTE) 191 bgra_error = GL_TRUE; 192 193 if (bgra_error) { 194 _mesa_error(ctx, GL_INVALID_VALUE, "%s(GL_BGRA/GLubyte)", func); 195 return; 196 } 197 format = GL_BGRA; 198 size = 4; 199 } 200 else if (size < sizeMin || size > sizeMax || size > 4) { 201 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size); 202 return; 203 } 204 205 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev && 206 (type == GL_UNSIGNED_INT_2_10_10_10_REV || 207 type == GL_INT_2_10_10_10_REV) && size != 4) { 208 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size); 209 return; 210 } 211 212 ASSERT(size <= 4); 213 214 if (stride < 0) { 215 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride ); 216 return; 217 } 218 219 if (ctx->Array.ArrayObj->ARBsemantics && 220 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) { 221 /* GL_ARB_vertex_array_object requires that all arrays reside in VBOs. 222 * Generate GL_INVALID_OPERATION if that's not true. 223 */ 224 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func); 225 return; 226 } 227 228 elementSize = _mesa_sizeof_type(type) * size; 229 230 array = &ctx->Array.ArrayObj->VertexAttrib[attrib]; 231 array->Size = size; 232 array->Type = type; 233 array->Format = format; 234 array->Stride = stride; 235 array->StrideB = stride ? stride : elementSize; 236 array->Normalized = normalized; 237 array->Integer = integer; 238 array->Ptr = (const GLubyte *) ptr; 239 array->_ElementSize = elementSize; 240 241 _mesa_reference_buffer_object(ctx, &array->BufferObj, 242 ctx->Array.ArrayBufferObj); 243 244 ctx->NewState |= _NEW_ARRAY; 245 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(attrib); 246} 247 248 249void GLAPIENTRY 250_mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) 251{ 252 GLbitfield legalTypes = (SHORT_BIT | INT_BIT | FLOAT_BIT | 253 DOUBLE_BIT | HALF_BIT | FIXED_ES_BIT | 254 UNSIGNED_INT_2_10_10_10_REV_BIT | 255 INT_2_10_10_10_REV_BIT); 256 GET_CURRENT_CONTEXT(ctx); 257 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 258 259 if (ctx->API == API_OPENGLES) 260 legalTypes |= BYTE_BIT; 261 262 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS, 263 legalTypes, 2, 4, 264 size, type, stride, GL_FALSE, GL_FALSE, ptr); 265} 266 267 268void GLAPIENTRY 269_mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr ) 270{ 271 GET_CURRENT_CONTEXT(ctx); 272 const GLbitfield legalTypes = (ctx->API == API_OPENGLES) 273 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT) 274 : (BYTE_BIT | SHORT_BIT | INT_BIT | 275 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | 276 UNSIGNED_INT_2_10_10_10_REV_BIT | 277 INT_2_10_10_10_REV_BIT); 278 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 279 280 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL, 281 legalTypes, 3, 3, 282 3, type, stride, GL_TRUE, GL_FALSE, ptr); 283} 284 285 286void GLAPIENTRY 287_mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr) 288{ 289 GET_CURRENT_CONTEXT(ctx); 290 const GLbitfield legalTypes = (ctx->API == API_OPENGLES) 291 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT) 292 : (BYTE_BIT | UNSIGNED_BYTE_BIT | 293 SHORT_BIT | UNSIGNED_SHORT_BIT | 294 INT_BIT | UNSIGNED_INT_BIT | 295 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | 296 UNSIGNED_INT_2_10_10_10_REV_BIT | 297 INT_2_10_10_10_REV_BIT); 298 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3; 299 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 300 301 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0, 302 legalTypes, sizeMin, BGRA_OR_4, 303 size, type, stride, GL_TRUE, GL_FALSE, ptr); 304} 305 306 307void GLAPIENTRY 308_mesa_FogCoordPointerEXT(GLenum type, GLsizei stride, const GLvoid *ptr) 309{ 310 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT); 311 GET_CURRENT_CONTEXT(ctx); 312 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 313 314 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG, 315 legalTypes, 1, 1, 316 1, type, stride, GL_FALSE, GL_FALSE, ptr); 317} 318 319 320void GLAPIENTRY 321_mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr) 322{ 323 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT | 324 FLOAT_BIT | DOUBLE_BIT); 325 GET_CURRENT_CONTEXT(ctx); 326 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 327 328 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX, 329 legalTypes, 1, 1, 330 1, type, stride, GL_FALSE, GL_FALSE, ptr); 331} 332 333 334void GLAPIENTRY 335_mesa_SecondaryColorPointerEXT(GLint size, GLenum type, 336 GLsizei stride, const GLvoid *ptr) 337{ 338 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | 339 SHORT_BIT | UNSIGNED_SHORT_BIT | 340 INT_BIT | UNSIGNED_INT_BIT | 341 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | 342 UNSIGNED_INT_2_10_10_10_REV_BIT | 343 INT_2_10_10_10_REV_BIT); 344 GET_CURRENT_CONTEXT(ctx); 345 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 346 347 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1, 348 legalTypes, 3, BGRA_OR_4, 349 size, type, stride, GL_TRUE, GL_FALSE, ptr); 350} 351 352 353void GLAPIENTRY 354_mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, 355 const GLvoid *ptr) 356{ 357 GLbitfield legalTypes = (SHORT_BIT | INT_BIT | 358 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | 359 FIXED_ES_BIT | 360 UNSIGNED_INT_2_10_10_10_REV_BIT | 361 INT_2_10_10_10_REV_BIT); 362 GET_CURRENT_CONTEXT(ctx); 363 const GLuint unit = ctx->Array.ActiveTexture; 364 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 365 366 if (ctx->API == API_OPENGLES) 367 legalTypes |= BYTE_BIT; 368 369 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit), 370 legalTypes, 1, 4, 371 size, type, stride, GL_FALSE, GL_FALSE, 372 ptr); 373} 374 375 376void GLAPIENTRY 377_mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr) 378{ 379 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT; 380 /* see table 2.4 edits in GL_EXT_gpu_shader4 spec: */ 381 const GLboolean integer = GL_TRUE; 382 GET_CURRENT_CONTEXT(ctx); 383 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 384 385 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG, 386 legalTypes, 1, 1, 387 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr); 388} 389 390 391void GLAPIENTRY 392_mesa_PointSizePointer(GLenum type, GLsizei stride, const GLvoid *ptr) 393{ 394 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT); 395 GET_CURRENT_CONTEXT(ctx); 396 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 397 398 if (ctx->API != API_OPENGLES) { 399 _mesa_error(ctx, GL_INVALID_OPERATION, 400 "glPointSizePointer(ES 1.x only)"); 401 return; 402 } 403 404 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE, 405 legalTypes, 1, 1, 406 1, type, stride, GL_FALSE, GL_FALSE, ptr); 407} 408 409 410#if FEATURE_NV_vertex_program 411/** 412 * Set a vertex attribute array. 413 * Note that these arrays DO alias the conventional GL vertex arrays 414 * (position, normal, color, fog, texcoord, etc). 415 * The generic attribute slots at #16 and above are not touched. 416 */ 417void GLAPIENTRY 418_mesa_VertexAttribPointerNV(GLuint index, GLint size, GLenum type, 419 GLsizei stride, const GLvoid *ptr) 420{ 421 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | 422 FLOAT_BIT | DOUBLE_BIT); 423 GLboolean normalized = GL_FALSE; 424 GET_CURRENT_CONTEXT(ctx); 425 ASSERT_OUTSIDE_BEGIN_END(ctx); 426 427 if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) { 428 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(index)"); 429 return; 430 } 431 432 if (type == GL_UNSIGNED_BYTE && size != 4) { 433 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerNV(size!=4)"); 434 return; 435 } 436 437 update_array(ctx, "glVertexAttribPointerNV", VERT_ATTRIB_GENERIC(index), 438 legalTypes, 1, BGRA_OR_4, 439 size, type, stride, normalized, GL_FALSE, ptr); 440} 441#endif 442 443 444#if FEATURE_ARB_vertex_program 445/** 446 * Set a generic vertex attribute array. 447 * Note that these arrays DO NOT alias the conventional GL vertex arrays 448 * (position, normal, color, fog, texcoord, etc). 449 */ 450void GLAPIENTRY 451_mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type, 452 GLboolean normalized, 453 GLsizei stride, const GLvoid *ptr) 454{ 455 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | 456 SHORT_BIT | UNSIGNED_SHORT_BIT | 457 INT_BIT | UNSIGNED_INT_BIT | 458 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | 459 FIXED_ES_BIT | FIXED_GL_BIT | 460 UNSIGNED_INT_2_10_10_10_REV_BIT | 461 INT_2_10_10_10_REV_BIT); 462 GET_CURRENT_CONTEXT(ctx); 463 ASSERT_OUTSIDE_BEGIN_END(ctx); 464 465 if (index >= ctx->Const.VertexProgram.MaxAttribs) { 466 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)"); 467 return; 468 } 469 470 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index), 471 legalTypes, 1, BGRA_OR_4, 472 size, type, stride, normalized, GL_FALSE, ptr); 473} 474#endif 475 476 477/** 478 * GL_EXT_gpu_shader4 / GL 3.0. 479 * Set an integer-valued vertex attribute array. 480 * Note that these arrays DO NOT alias the conventional GL vertex arrays 481 * (position, normal, color, fog, texcoord, etc). 482 */ 483void GLAPIENTRY 484_mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type, 485 GLsizei stride, const GLvoid *ptr) 486{ 487 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | 488 SHORT_BIT | UNSIGNED_SHORT_BIT | 489 INT_BIT | UNSIGNED_INT_BIT); 490 const GLboolean normalized = GL_FALSE; 491 const GLboolean integer = GL_TRUE; 492 GET_CURRENT_CONTEXT(ctx); 493 ASSERT_OUTSIDE_BEGIN_END(ctx); 494 495 if (index >= ctx->Const.VertexProgram.MaxAttribs) { 496 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)"); 497 return; 498 } 499 500 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index), 501 legalTypes, 1, 4, 502 size, type, stride, normalized, integer, ptr); 503} 504 505 506 507void GLAPIENTRY 508_mesa_EnableVertexAttribArrayARB(GLuint index) 509{ 510 struct gl_array_object *arrayObj; 511 GET_CURRENT_CONTEXT(ctx); 512 ASSERT_OUTSIDE_BEGIN_END(ctx); 513 514 if (index >= ctx->Const.VertexProgram.MaxAttribs) { 515 _mesa_error(ctx, GL_INVALID_VALUE, 516 "glEnableVertexAttribArrayARB(index)"); 517 return; 518 } 519 520 arrayObj = ctx->Array.ArrayObj; 521 522 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->VertexAttrib)); 523 524 if (!arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) { 525 /* was disabled, now being enabled */ 526 FLUSH_VERTICES(ctx, _NEW_ARRAY); 527 arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE; 528 arrayObj->_Enabled |= VERT_BIT_GENERIC(index); 529 arrayObj->NewArrays |= VERT_BIT_GENERIC(index); 530 } 531} 532 533 534void GLAPIENTRY 535_mesa_DisableVertexAttribArrayARB(GLuint index) 536{ 537 struct gl_array_object *arrayObj; 538 GET_CURRENT_CONTEXT(ctx); 539 ASSERT_OUTSIDE_BEGIN_END(ctx); 540 541 if (index >= ctx->Const.VertexProgram.MaxAttribs) { 542 _mesa_error(ctx, GL_INVALID_VALUE, 543 "glDisableVertexAttribArrayARB(index)"); 544 return; 545 } 546 547 arrayObj = ctx->Array.ArrayObj; 548 549 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(arrayObj->VertexAttrib)); 550 551 if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) { 552 /* was enabled, now being disabled */ 553 FLUSH_VERTICES(ctx, _NEW_ARRAY); 554 arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE; 555 arrayObj->_Enabled &= ~VERT_BIT_GENERIC(index); 556 arrayObj->NewArrays |= VERT_BIT_GENERIC(index); 557 } 558} 559 560 561/** 562 * Return info for a vertex attribute array (no alias with legacy 563 * vertex attributes (pos, normal, color, etc)). This function does 564 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query. 565 */ 566static GLuint 567get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname, 568 const char *caller) 569{ 570 const struct gl_client_array *array; 571 572 if (index >= ctx->Const.VertexProgram.MaxAttribs) { 573 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index); 574 return 0; 575 } 576 577 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib)); 578 579 array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)]; 580 581 switch (pname) { 582 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB: 583 return array->Enabled; 584 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB: 585 return array->Size; 586 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB: 587 return array->Stride; 588 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB: 589 return array->Type; 590 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB: 591 return array->Normalized; 592 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB: 593 return array->BufferObj->Name; 594 case GL_VERTEX_ATTRIB_ARRAY_INTEGER: 595 if (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4) { 596 return array->Integer; 597 } 598 goto error; 599 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB: 600 if (ctx->Extensions.ARB_instanced_arrays) { 601 return array->InstanceDivisor; 602 } 603 goto error; 604 default: 605 ; /* fall-through */ 606 } 607 608error: 609 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname); 610 return 0; 611} 612 613 614static const GLfloat * 615get_current_attrib(struct gl_context *ctx, GLuint index, const char *function) 616{ 617 if (index == 0) { 618 if (ctx->API != API_OPENGLES2) { 619 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function); 620 return NULL; 621 } 622 } 623 else if (index >= ctx->Const.VertexProgram.MaxAttribs) { 624 _mesa_error(ctx, GL_INVALID_VALUE, 625 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function); 626 return NULL; 627 } 628 629 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib)); 630 631 FLUSH_CURRENT(ctx, 0); 632 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)]; 633} 634 635void GLAPIENTRY 636_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params) 637{ 638 GET_CURRENT_CONTEXT(ctx); 639 ASSERT_OUTSIDE_BEGIN_END(ctx); 640 641 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { 642 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv"); 643 if (v != NULL) { 644 COPY_4V(params, v); 645 } 646 } 647 else { 648 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname, 649 "glGetVertexAttribfv"); 650 } 651} 652 653 654void GLAPIENTRY 655_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params) 656{ 657 GET_CURRENT_CONTEXT(ctx); 658 ASSERT_OUTSIDE_BEGIN_END(ctx); 659 660 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { 661 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv"); 662 if (v != NULL) { 663 params[0] = (GLdouble) v[0]; 664 params[1] = (GLdouble) v[1]; 665 params[2] = (GLdouble) v[2]; 666 params[3] = (GLdouble) v[3]; 667 } 668 } 669 else { 670 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname, 671 "glGetVertexAttribdv"); 672 } 673} 674 675 676void GLAPIENTRY 677_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params) 678{ 679 GET_CURRENT_CONTEXT(ctx); 680 ASSERT_OUTSIDE_BEGIN_END(ctx); 681 682 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { 683 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv"); 684 if (v != NULL) { 685 /* XXX should floats in[0,1] be scaled to full int range? */ 686 params[0] = (GLint) v[0]; 687 params[1] = (GLint) v[1]; 688 params[2] = (GLint) v[2]; 689 params[3] = (GLint) v[3]; 690 } 691 } 692 else { 693 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, 694 "glGetVertexAttribiv"); 695 } 696} 697 698 699/** GL 3.0 */ 700void GLAPIENTRY 701_mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params) 702{ 703 GET_CURRENT_CONTEXT(ctx); 704 ASSERT_OUTSIDE_BEGIN_END(ctx); 705 706 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { 707 const GLfloat *v = 708 get_current_attrib(ctx, index, "glGetVertexAttribIiv"); 709 if (v != NULL) { 710 /* XXX we don't have true integer-valued vertex attribs yet */ 711 params[0] = (GLint) v[0]; 712 params[1] = (GLint) v[1]; 713 params[2] = (GLint) v[2]; 714 params[3] = (GLint) v[3]; 715 } 716 } 717 else { 718 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, 719 "glGetVertexAttribIiv"); 720 } 721} 722 723 724/** GL 3.0 */ 725void GLAPIENTRY 726_mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params) 727{ 728 GET_CURRENT_CONTEXT(ctx); 729 ASSERT_OUTSIDE_BEGIN_END(ctx); 730 731 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { 732 const GLfloat *v = 733 get_current_attrib(ctx, index, "glGetVertexAttribIuiv"); 734 if (v != NULL) { 735 /* XXX we don't have true integer-valued vertex attribs yet */ 736 params[0] = (GLuint) v[0]; 737 params[1] = (GLuint) v[1]; 738 params[2] = (GLuint) v[2]; 739 params[3] = (GLuint) v[3]; 740 } 741 } 742 else { 743 params[0] = get_vertex_array_attrib(ctx, index, pname, 744 "glGetVertexAttribIuiv"); 745 } 746} 747 748 749void GLAPIENTRY 750_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer) 751{ 752 GET_CURRENT_CONTEXT(ctx); 753 ASSERT_OUTSIDE_BEGIN_END(ctx); 754 755 if (index >= ctx->Const.VertexProgram.MaxAttribs) { 756 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)"); 757 return; 758 } 759 760 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) { 761 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)"); 762 return; 763 } 764 765 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib)); 766 767 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr; 768} 769 770 771void GLAPIENTRY 772_mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, 773 GLsizei count, const GLvoid *ptr) 774{ 775 (void) count; 776 _mesa_VertexPointer(size, type, stride, ptr); 777} 778 779 780void GLAPIENTRY 781_mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, 782 const GLvoid *ptr) 783{ 784 (void) count; 785 _mesa_NormalPointer(type, stride, ptr); 786} 787 788 789void GLAPIENTRY 790_mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, 791 const GLvoid *ptr) 792{ 793 (void) count; 794 _mesa_ColorPointer(size, type, stride, ptr); 795} 796 797 798void GLAPIENTRY 799_mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, 800 const GLvoid *ptr) 801{ 802 (void) count; 803 _mesa_IndexPointer(type, stride, ptr); 804} 805 806 807void GLAPIENTRY 808_mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, 809 GLsizei count, const GLvoid *ptr) 810{ 811 (void) count; 812 _mesa_TexCoordPointer(size, type, stride, ptr); 813} 814 815 816void GLAPIENTRY 817_mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr) 818{ 819 (void) count; 820 _mesa_EdgeFlagPointer(stride, ptr); 821} 822 823 824void GLAPIENTRY 825_mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) 826{ 827 GET_CURRENT_CONTEXT(ctx); 828 GLboolean tflag, cflag, nflag; /* enable/disable flags */ 829 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */ 830 GLenum ctype = 0; /* color type */ 831 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */ 832 const GLint toffset = 0; /* always zero */ 833 GLint defstride; /* default stride */ 834 GLint c, f; 835 836 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 837 838 f = sizeof(GLfloat); 839 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f); 840 841 if (stride < 0) { 842 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" ); 843 return; 844 } 845 846 switch (format) { 847 case GL_V2F: 848 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; 849 tcomps = 0; ccomps = 0; vcomps = 2; 850 voffset = 0; 851 defstride = 2*f; 852 break; 853 case GL_V3F: 854 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE; 855 tcomps = 0; ccomps = 0; vcomps = 3; 856 voffset = 0; 857 defstride = 3*f; 858 break; 859 case GL_C4UB_V2F: 860 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; 861 tcomps = 0; ccomps = 4; vcomps = 2; 862 ctype = GL_UNSIGNED_BYTE; 863 coffset = 0; 864 voffset = c; 865 defstride = c + 2*f; 866 break; 867 case GL_C4UB_V3F: 868 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; 869 tcomps = 0; ccomps = 4; vcomps = 3; 870 ctype = GL_UNSIGNED_BYTE; 871 coffset = 0; 872 voffset = c; 873 defstride = c + 3*f; 874 break; 875 case GL_C3F_V3F: 876 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE; 877 tcomps = 0; ccomps = 3; vcomps = 3; 878 ctype = GL_FLOAT; 879 coffset = 0; 880 voffset = 3*f; 881 defstride = 6*f; 882 break; 883 case GL_N3F_V3F: 884 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE; 885 tcomps = 0; ccomps = 0; vcomps = 3; 886 noffset = 0; 887 voffset = 3*f; 888 defstride = 6*f; 889 break; 890 case GL_C4F_N3F_V3F: 891 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE; 892 tcomps = 0; ccomps = 4; vcomps = 3; 893 ctype = GL_FLOAT; 894 coffset = 0; 895 noffset = 4*f; 896 voffset = 7*f; 897 defstride = 10*f; 898 break; 899 case GL_T2F_V3F: 900 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; 901 tcomps = 2; ccomps = 0; vcomps = 3; 902 voffset = 2*f; 903 defstride = 5*f; 904 break; 905 case GL_T4F_V4F: 906 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE; 907 tcomps = 4; ccomps = 0; vcomps = 4; 908 voffset = 4*f; 909 defstride = 8*f; 910 break; 911 case GL_T2F_C4UB_V3F: 912 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; 913 tcomps = 2; ccomps = 4; vcomps = 3; 914 ctype = GL_UNSIGNED_BYTE; 915 coffset = 2*f; 916 voffset = c+2*f; 917 defstride = c+5*f; 918 break; 919 case GL_T2F_C3F_V3F: 920 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE; 921 tcomps = 2; ccomps = 3; vcomps = 3; 922 ctype = GL_FLOAT; 923 coffset = 2*f; 924 voffset = 5*f; 925 defstride = 8*f; 926 break; 927 case GL_T2F_N3F_V3F: 928 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE; 929 tcomps = 2; ccomps = 0; vcomps = 3; 930 noffset = 2*f; 931 voffset = 5*f; 932 defstride = 8*f; 933 break; 934 case GL_T2F_C4F_N3F_V3F: 935 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; 936 tcomps = 2; ccomps = 4; vcomps = 3; 937 ctype = GL_FLOAT; 938 coffset = 2*f; 939 noffset = 6*f; 940 voffset = 9*f; 941 defstride = 12*f; 942 break; 943 case GL_T4F_C4F_N3F_V4F: 944 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE; 945 tcomps = 4; ccomps = 4; vcomps = 4; 946 ctype = GL_FLOAT; 947 coffset = 4*f; 948 noffset = 8*f; 949 voffset = 11*f; 950 defstride = 15*f; 951 break; 952 default: 953 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" ); 954 return; 955 } 956 957 if (stride==0) { 958 stride = defstride; 959 } 960 961 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY ); 962 _mesa_DisableClientState( GL_INDEX_ARRAY ); 963 /* XXX also disable secondary color and generic arrays? */ 964 965 /* Texcoords */ 966 if (tflag) { 967 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY ); 968 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride, 969 (GLubyte *) pointer + toffset ); 970 } 971 else { 972 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY ); 973 } 974 975 /* Color */ 976 if (cflag) { 977 _mesa_EnableClientState( GL_COLOR_ARRAY ); 978 _mesa_ColorPointer( ccomps, ctype, stride, 979 (GLubyte *) pointer + coffset ); 980 } 981 else { 982 _mesa_DisableClientState( GL_COLOR_ARRAY ); 983 } 984 985 986 /* Normals */ 987 if (nflag) { 988 _mesa_EnableClientState( GL_NORMAL_ARRAY ); 989 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset ); 990 } 991 else { 992 _mesa_DisableClientState( GL_NORMAL_ARRAY ); 993 } 994 995 /* Vertices */ 996 _mesa_EnableClientState( GL_VERTEX_ARRAY ); 997 _mesa_VertexPointer( vcomps, GL_FLOAT, stride, 998 (GLubyte *) pointer + voffset ); 999} 1000 1001 1002void GLAPIENTRY 1003_mesa_LockArraysEXT(GLint first, GLsizei count) 1004{ 1005 GET_CURRENT_CONTEXT(ctx); 1006 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1007 1008 if (MESA_VERBOSE & VERBOSE_API) 1009 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count); 1010 1011 if (first < 0) { 1012 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" ); 1013 return; 1014 } 1015 if (count <= 0) { 1016 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" ); 1017 return; 1018 } 1019 if (ctx->Array.LockCount != 0) { 1020 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" ); 1021 return; 1022 } 1023 1024 ctx->Array.LockFirst = first; 1025 ctx->Array.LockCount = count; 1026 1027 ctx->NewState |= _NEW_ARRAY; 1028} 1029 1030 1031void GLAPIENTRY 1032_mesa_UnlockArraysEXT( void ) 1033{ 1034 GET_CURRENT_CONTEXT(ctx); 1035 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1036 1037 if (MESA_VERBOSE & VERBOSE_API) 1038 _mesa_debug(ctx, "glUnlockArrays\n"); 1039 1040 if (ctx->Array.LockCount == 0) { 1041 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" ); 1042 return; 1043 } 1044 1045 ctx->Array.LockFirst = 0; 1046 ctx->Array.LockCount = 0; 1047 ctx->NewState |= _NEW_ARRAY; 1048} 1049 1050 1051/* GL_EXT_multi_draw_arrays */ 1052void GLAPIENTRY 1053_mesa_MultiDrawArraysEXT( GLenum mode, const GLint *first, 1054 const GLsizei *count, GLsizei primcount ) 1055{ 1056 GET_CURRENT_CONTEXT(ctx); 1057 GLint i; 1058 1059 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1060 1061 for (i = 0; i < primcount; i++) { 1062 if (count[i] > 0) { 1063 CALL_DrawArrays(ctx->Exec, (mode, first[i], count[i])); 1064 } 1065 } 1066} 1067 1068 1069/* GL_IBM_multimode_draw_arrays */ 1070void GLAPIENTRY 1071_mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, 1072 const GLsizei * count, 1073 GLsizei primcount, GLint modestride ) 1074{ 1075 GET_CURRENT_CONTEXT(ctx); 1076 GLint i; 1077 1078 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1079 1080 for ( i = 0 ; i < primcount ; i++ ) { 1081 if ( count[i] > 0 ) { 1082 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); 1083 CALL_DrawArrays(ctx->Exec, ( m, first[i], count[i] )); 1084 } 1085 } 1086} 1087 1088 1089/* GL_IBM_multimode_draw_arrays */ 1090void GLAPIENTRY 1091_mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count, 1092 GLenum type, const GLvoid * const * indices, 1093 GLsizei primcount, GLint modestride ) 1094{ 1095 GET_CURRENT_CONTEXT(ctx); 1096 GLint i; 1097 1098 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 1099 1100 /* XXX not sure about ARB_vertex_buffer_object handling here */ 1101 1102 for ( i = 0 ; i < primcount ; i++ ) { 1103 if ( count[i] > 0 ) { 1104 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride)); 1105 CALL_DrawElements(ctx->Exec, ( m, count[i], type, indices[i] )); 1106 } 1107 } 1108} 1109 1110 1111/** 1112 * GL_NV_primitive_restart and GL 3.1 1113 */ 1114void GLAPIENTRY 1115_mesa_PrimitiveRestartIndex(GLuint index) 1116{ 1117 GET_CURRENT_CONTEXT(ctx); 1118 1119 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) { 1120 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()"); 1121 return; 1122 } 1123 1124 ASSERT_OUTSIDE_BEGIN_END(ctx); 1125 1126 if (ctx->Array.RestartIndex != index) { 1127 FLUSH_VERTICES(ctx, _NEW_TRANSFORM); 1128 ctx->Array.RestartIndex = index; 1129 } 1130} 1131 1132 1133/** 1134 * See GL_ARB_instanced_arrays. 1135 * Note that the instance divisor only applies to generic arrays, not 1136 * the legacy vertex arrays. 1137 */ 1138void GLAPIENTRY 1139_mesa_VertexAttribDivisor(GLuint index, GLuint divisor) 1140{ 1141 struct gl_client_array *array; 1142 GET_CURRENT_CONTEXT(ctx); 1143 ASSERT_OUTSIDE_BEGIN_END(ctx); 1144 1145 if (!ctx->Extensions.ARB_instanced_arrays) { 1146 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()"); 1147 return; 1148 } 1149 1150 if (index >= ctx->Const.VertexProgram.MaxAttribs) { 1151 _mesa_error(ctx, GL_INVALID_ENUM, "glVertexAttribDivisor(index = %u)", 1152 index); 1153 return; 1154 } 1155 1156 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.ArrayObj->VertexAttrib)); 1157 1158 array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(index)]; 1159 if (array->InstanceDivisor != divisor) { 1160 FLUSH_VERTICES(ctx, _NEW_ARRAY); 1161 array->InstanceDivisor = divisor; 1162 ctx->Array.ArrayObj->NewArrays |= VERT_BIT(VERT_ATTRIB_GENERIC(index)); 1163 } 1164} 1165 1166 1167 1168/** 1169 * Copy one client vertex array to another. 1170 */ 1171void 1172_mesa_copy_client_array(struct gl_context *ctx, 1173 struct gl_client_array *dst, 1174 struct gl_client_array *src) 1175{ 1176 dst->Size = src->Size; 1177 dst->Type = src->Type; 1178 dst->Format = src->Format; 1179 dst->Stride = src->Stride; 1180 dst->StrideB = src->StrideB; 1181 dst->Ptr = src->Ptr; 1182 dst->Enabled = src->Enabled; 1183 dst->Normalized = src->Normalized; 1184 dst->Integer = src->Integer; 1185 dst->InstanceDivisor = src->InstanceDivisor; 1186 dst->_ElementSize = src->_ElementSize; 1187 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj); 1188 dst->_MaxElement = src->_MaxElement; 1189} 1190 1191 1192 1193/** 1194 * Print vertex array's fields. 1195 */ 1196static void 1197print_array(const char *name, GLint index, const struct gl_client_array *array) 1198{ 1199 if (index >= 0) 1200 printf(" %s[%d]: ", name, index); 1201 else 1202 printf(" %s: ", name); 1203 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu), MaxElem=%u\n", 1204 array->Ptr, array->Type, array->Size, 1205 array->_ElementSize, array->StrideB, 1206 array->BufferObj->Name, (unsigned long) array->BufferObj->Size, 1207 array->_MaxElement); 1208} 1209 1210 1211/** 1212 * Print current vertex object/array info. For debug. 1213 */ 1214void 1215_mesa_print_arrays(struct gl_context *ctx) 1216{ 1217 struct gl_array_object *arrayObj = ctx->Array.ArrayObj; 1218 GLuint i; 1219 1220 _mesa_update_array_object_max_element(ctx, arrayObj); 1221 1222 printf("Array Object %u\n", arrayObj->Name); 1223 if (arrayObj->VertexAttrib[VERT_ATTRIB_POS].Enabled) 1224 print_array("Vertex", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_POS]); 1225 if (arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) 1226 print_array("Normal", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_NORMAL]); 1227 if (arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) 1228 print_array("Color", -1, &arrayObj->VertexAttrib[VERT_ATTRIB_COLOR0]); 1229 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) 1230 if (arrayObj->VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled) 1231 print_array("TexCoord", i, &arrayObj->VertexAttrib[VERT_ATTRIB_TEX(i)]); 1232 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) 1233 if (arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled) 1234 print_array("Attrib", i, &arrayObj->VertexAttrib[VERT_ATTRIB_GENERIC(i)]); 1235 printf(" _MaxElement = %u\n", arrayObj->_MaxElement); 1236} 1237 1238 1239/** 1240 * Initialize vertex array state for given context. 1241 */ 1242void 1243_mesa_init_varray(struct gl_context *ctx) 1244{ 1245 ctx->Array.DefaultArrayObj = ctx->Driver.NewArrayObject(ctx, 0); 1246 _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj, 1247 ctx->Array.DefaultArrayObj); 1248 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ 1249 1250 ctx->Array.Objects = _mesa_NewHashTable(); 1251} 1252 1253 1254/** 1255 * Callback for deleting an array object. Called by _mesa_HashDeleteAll(). 1256 */ 1257static void 1258delete_arrayobj_cb(GLuint id, void *data, void *userData) 1259{ 1260 struct gl_array_object *arrayObj = (struct gl_array_object *) data; 1261 struct gl_context *ctx = (struct gl_context *) userData; 1262 _mesa_delete_array_object(ctx, arrayObj); 1263} 1264 1265 1266/** 1267 * Free vertex array state for given context. 1268 */ 1269void 1270_mesa_free_varray_data(struct gl_context *ctx) 1271{ 1272 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx); 1273 _mesa_DeleteHashTable(ctx->Array.Objects); 1274} 1275