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 #ifndef VARRAY_H 28 #define VARRAY_H 29 30 31 #include "glheader.h" 32 #include "bufferobj.h" 33 34 struct gl_vertex_array; 35 struct gl_context; 36 37 /** 38 * Returns a pointer to the vertex attribute data in a client array, 39 * or the offset into the vertex buffer for an array that resides in 40 * a vertex buffer. 41 */ 42 static inline const GLubyte * 43 _mesa_vertex_attrib_address(const struct gl_array_attributes *array, 44 const struct gl_vertex_buffer_binding *binding) 45 { 46 if (_mesa_is_bufferobj(binding->BufferObj)) 47 return (const GLubyte *) (binding->Offset + array->RelativeOffset); 48 else 49 return array->Ptr; 50 } 51 52 /** 53 * Sets the fields in a gl_vertex_array to values derived from a 54 * gl_vertex_attrib_array and a gl_vertex_buffer_binding. 55 */ 56 static inline void 57 _mesa_update_client_array(struct gl_context *ctx, 58 struct gl_vertex_array *dst, 59 const struct gl_array_attributes *src, 60 const struct gl_vertex_buffer_binding *binding) 61 { 62 dst->Size = src->Size; 63 dst->Type = src->Type; 64 dst->Format = src->Format; 65 dst->StrideB = binding->Stride; 66 dst->Ptr = _mesa_vertex_attrib_address(src, binding); 67 dst->Normalized = src->Normalized; 68 dst->Integer = src->Integer; 69 dst->Doubles = src->Doubles; 70 dst->InstanceDivisor = binding->InstanceDivisor; 71 dst->_ElementSize = src->_ElementSize; 72 _mesa_reference_buffer_object(ctx, &dst->BufferObj, binding->BufferObj); 73 } 74 75 static inline bool 76 _mesa_attr_zero_aliases_vertex(const struct gl_context *ctx) 77 { 78 return ctx->_AttribZeroAliasesVertex; 79 } 80 81 extern void 82 _mesa_update_array_format(struct gl_context *ctx, 83 struct gl_vertex_array_object *vao, 84 GLuint attrib, GLint size, GLenum type, 85 GLenum format, GLboolean normalized, 86 GLboolean integer, GLboolean doubles, 87 GLuint relativeOffset); 88 89 extern void 90 _mesa_enable_vertex_array_attrib(struct gl_context *ctx, 91 struct gl_vertex_array_object *vao, 92 unsigned attrib); 93 94 extern void 95 _mesa_bind_vertex_buffer(struct gl_context *ctx, 96 struct gl_vertex_array_object *vao, 97 GLuint index, 98 struct gl_buffer_object *vbo, 99 GLintptr offset, GLsizei stride); 100 101 extern void GLAPIENTRY 102 _mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride, 103 const GLvoid *ptr); 104 extern void GLAPIENTRY 105 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, 106 const GLvoid *ptr); 107 108 extern void GLAPIENTRY 109 _mesa_NormalPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr); 110 extern void GLAPIENTRY 111 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr); 112 113 extern void GLAPIENTRY 114 _mesa_ColorPointer_no_error(GLint size, GLenum type, GLsizei stride, 115 const GLvoid *ptr); 116 extern void GLAPIENTRY 117 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); 118 119 120 extern void GLAPIENTRY 121 _mesa_IndexPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr); 122 extern void GLAPIENTRY 123 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr); 124 125 126 extern void GLAPIENTRY 127 _mesa_TexCoordPointer_no_error(GLint size, GLenum type, GLsizei stride, 128 const GLvoid *ptr); 129 extern void GLAPIENTRY 130 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride, 131 const GLvoid *ptr); 132 133 134 extern void GLAPIENTRY 135 _mesa_EdgeFlagPointer_no_error(GLsizei stride, const GLvoid *ptr); 136 extern void GLAPIENTRY 137 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr); 138 139 140 extern void GLAPIENTRY 141 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride, 142 GLsizei count, const GLvoid *ptr); 143 144 145 extern void GLAPIENTRY 146 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count, 147 const GLvoid *ptr); 148 149 150 extern void GLAPIENTRY 151 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count, 152 const GLvoid *ptr); 153 154 155 extern void GLAPIENTRY 156 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count, 157 const GLvoid *ptr); 158 159 160 extern void GLAPIENTRY 161 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride, 162 GLsizei count, const GLvoid *ptr); 163 164 165 extern void GLAPIENTRY 166 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr); 167 168 extern void GLAPIENTRY 169 _mesa_FogCoordPointer_no_error(GLenum type, GLsizei stride, 170 const GLvoid *ptr); 171 extern void GLAPIENTRY 172 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr); 173 174 175 extern void GLAPIENTRY 176 _mesa_SecondaryColorPointer_no_error(GLint size, GLenum type, 177 GLsizei stride, const GLvoid *ptr); 178 extern void GLAPIENTRY 179 _mesa_SecondaryColorPointer(GLint size, GLenum type, 180 GLsizei stride, const GLvoid *ptr); 181 182 183 extern void GLAPIENTRY 184 _mesa_PointSizePointerOES_no_error(GLenum type, GLsizei stride, 185 const GLvoid *ptr); 186 extern void GLAPIENTRY 187 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr); 188 189 190 extern void GLAPIENTRY 191 _mesa_VertexAttribPointer_no_error(GLuint index, GLint size, GLenum type, 192 GLboolean normalized, GLsizei stride, 193 const GLvoid *pointer); 194 extern void GLAPIENTRY 195 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type, 196 GLboolean normalized, GLsizei stride, 197 const GLvoid *pointer); 198 199 void GLAPIENTRY 200 _mesa_VertexAttribIPointer_no_error(GLuint index, GLint size, GLenum type, 201 GLsizei stride, const GLvoid *ptr); 202 void GLAPIENTRY 203 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type, 204 GLsizei stride, const GLvoid *ptr); 205 206 extern void GLAPIENTRY 207 _mesa_VertexAttribLPointer_no_error(GLuint index, GLint size, GLenum type, 208 GLsizei stride, const GLvoid *pointer); 209 extern void GLAPIENTRY 210 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type, 211 GLsizei stride, const GLvoid *pointer); 212 213 extern void GLAPIENTRY 214 _mesa_EnableVertexAttribArray(GLuint index); 215 216 extern void GLAPIENTRY 217 _mesa_EnableVertexAttribArray_no_error(GLuint index); 218 219 220 extern void GLAPIENTRY 221 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index); 222 223 extern void GLAPIENTRY 224 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index); 225 226 227 228 extern void GLAPIENTRY 229 _mesa_DisableVertexAttribArray(GLuint index); 230 231 extern void GLAPIENTRY 232 _mesa_DisableVertexAttribArray_no_error(GLuint index); 233 234 235 extern void GLAPIENTRY 236 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index); 237 238 extern void GLAPIENTRY 239 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index); 240 241 242 extern void GLAPIENTRY 243 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params); 244 245 extern void GLAPIENTRY 246 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); 247 248 extern void GLAPIENTRY 249 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params); 250 251 extern void GLAPIENTRY 252 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params); 253 254 extern void GLAPIENTRY 255 _mesa_GetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT *params); 256 257 258 extern void GLAPIENTRY 259 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params); 260 261 262 extern void GLAPIENTRY 263 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params); 264 265 266 extern void GLAPIENTRY 267 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer); 268 269 270 void GLAPIENTRY 271 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index, 272 GLenum pname, GLint *param); 273 274 275 void GLAPIENTRY 276 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index, 277 GLenum pname, GLint64 *param); 278 279 280 extern void GLAPIENTRY 281 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer); 282 283 284 extern void GLAPIENTRY 285 _mesa_MultiDrawArrays( GLenum mode, const GLint *first, 286 const GLsizei *count, GLsizei primcount ); 287 288 extern void GLAPIENTRY 289 _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, 290 const GLvoid **indices, GLsizei primcount ); 291 292 extern void GLAPIENTRY 293 _mesa_MultiDrawElementsBaseVertex( GLenum mode, 294 const GLsizei *count, GLenum type, 295 const GLvoid **indices, GLsizei primcount, 296 const GLint *basevertex); 297 298 extern void GLAPIENTRY 299 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first, 300 const GLsizei * count, 301 GLsizei primcount, GLint modestride ); 302 303 304 extern void GLAPIENTRY 305 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count, 306 GLenum type, const GLvoid * const * indices, 307 GLsizei primcount, GLint modestride ); 308 309 extern void GLAPIENTRY 310 _mesa_LockArraysEXT(GLint first, GLsizei count); 311 312 extern void GLAPIENTRY 313 _mesa_UnlockArraysEXT( void ); 314 315 316 extern void GLAPIENTRY 317 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count); 318 319 extern void GLAPIENTRY 320 _mesa_DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, 321 GLsizei primcount); 322 323 extern void GLAPIENTRY 324 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type, 325 const GLvoid *indices); 326 327 extern void GLAPIENTRY 328 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, 329 GLenum type, const GLvoid *indices); 330 331 extern void GLAPIENTRY 332 _mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, 333 const GLvoid *indices, GLint basevertex); 334 335 extern void GLAPIENTRY 336 _mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end, 337 GLsizei count, GLenum type, 338 const GLvoid *indices, 339 GLint basevertex); 340 341 extern void GLAPIENTRY 342 _mesa_DrawTransformFeedback(GLenum mode, GLuint name); 343 344 void GLAPIENTRY 345 _mesa_PrimitiveRestartIndex_no_error(GLuint index); 346 347 extern void GLAPIENTRY 348 _mesa_PrimitiveRestartIndex(GLuint index); 349 350 extern void GLAPIENTRY 351 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor); 352 extern void GLAPIENTRY 353 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor); 354 355 static inline unsigned 356 _mesa_primitive_restart_index(const struct gl_context *ctx, 357 unsigned index_size) 358 { 359 /* From the OpenGL 4.3 core specification, page 302: 360 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are 361 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX 362 * is used." 363 */ 364 if (ctx->Array.PrimitiveRestartFixedIndex) { 365 /* 1 -> 0xff, 2 -> 0xffff, 4 -> 0xffffffff */ 366 return 0xffffffffu >> 8 * (4 - index_size); 367 } 368 369 return ctx->Array.RestartIndex; 370 } 371 372 extern void GLAPIENTRY 373 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer, 374 GLintptr offset, GLsizei stride); 375 extern void GLAPIENTRY 376 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset, 377 GLsizei stride); 378 379 void GLAPIENTRY 380 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex, 381 GLuint buffer, GLintptr offset, 382 GLsizei stride); 383 extern void GLAPIENTRY 384 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer, 385 GLintptr offset, GLsizei stride); 386 387 void GLAPIENTRY 388 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count, 389 const GLuint *buffers, const GLintptr *offsets, 390 const GLsizei *strides); 391 392 extern void GLAPIENTRY 393 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers, 394 const GLintptr *offsets, const GLsizei *strides); 395 396 void GLAPIENTRY 397 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first, 398 GLsizei count, const GLuint *buffers, 399 const GLintptr *offsets, 400 const GLsizei *strides); 401 402 extern void GLAPIENTRY 403 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count, 404 const GLuint *buffers, 405 const GLintptr *offsets, const GLsizei *strides); 406 407 extern void GLAPIENTRY 408 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, 409 GLboolean normalized, GLuint relativeOffset); 410 411 extern void GLAPIENTRY 412 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size, 413 GLenum type, GLboolean normalized, 414 GLuint relativeOffset); 415 416 extern void GLAPIENTRY 417 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type, 418 GLuint relativeOffset); 419 420 extern void GLAPIENTRY 421 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex, 422 GLint size, GLenum type, 423 GLuint relativeOffset); 424 425 extern void GLAPIENTRY 426 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type, 427 GLuint relativeOffset); 428 429 extern void GLAPIENTRY 430 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex, 431 GLint size, GLenum type, 432 GLuint relativeOffset); 433 434 void GLAPIENTRY 435 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex); 436 437 extern void GLAPIENTRY 438 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex); 439 440 void GLAPIENTRY 441 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex, 442 GLuint bindingIndex); 443 444 extern void GLAPIENTRY 445 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, 446 GLuint bindingIndex); 447 448 void GLAPIENTRY 449 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex, GLuint divisor); 450 451 extern void GLAPIENTRY 452 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor); 453 454 void GLAPIENTRY 455 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj, GLuint bindingIndex, 456 GLuint divisor); 457 458 extern void GLAPIENTRY 459 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex, GLuint divisor); 460 461 extern void 462 _mesa_copy_client_array(struct gl_context *ctx, 463 struct gl_vertex_array *dst, 464 struct gl_vertex_array *src); 465 466 extern void 467 _mesa_copy_vertex_attrib_array(struct gl_context *ctx, 468 struct gl_array_attributes *dst, 469 const struct gl_array_attributes *src); 470 471 extern void 472 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx, 473 struct gl_vertex_buffer_binding *dst, 474 const struct gl_vertex_buffer_binding *src); 475 476 extern void 477 _mesa_print_arrays(struct gl_context *ctx); 478 479 extern void 480 _mesa_init_varray( struct gl_context * ctx ); 481 482 extern void 483 _mesa_free_varray_data(struct gl_context *ctx); 484 485 #endif 486