1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 5 * (C) Copyright IBM Corporation 2006 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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 * OTHER DEALINGS IN THE SOFTWARE. 25 */ 26 27#ifndef ARRAYOBJ_H 28#define ARRAYOBJ_H 29 30#include "glheader.h" 31#include "mtypes.h" 32#include "glformats.h" 33#include "vbo/vbo.h" 34 35struct gl_context; 36 37/** 38 * \file arrayobj.h 39 * Functions for the GL_ARB_vertex_array_object extension. 40 * 41 * \author Ian Romanick <idr@us.ibm.com> 42 * \author Brian Paul 43 */ 44 45/* 46 * Internal functions 47 */ 48 49extern struct gl_vertex_array_object * 50_mesa_lookup_vao(struct gl_context *ctx, GLuint id); 51 52extern struct gl_vertex_array_object * 53_mesa_lookup_vao_err(struct gl_context *ctx, GLuint id, 54 bool is_ext_dsa, const char *caller); 55 56extern struct gl_vertex_array_object * 57_mesa_new_vao(struct gl_context *ctx, GLuint name); 58 59extern void 60_mesa_unbind_array_object_vbos(struct gl_context *ctx, 61 struct gl_vertex_array_object *obj); 62 63extern void 64_mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj); 65 66extern void 67_mesa_reference_vao_(struct gl_context *ctx, 68 struct gl_vertex_array_object **ptr, 69 struct gl_vertex_array_object *vao); 70 71static inline void 72_mesa_reference_vao(struct gl_context *ctx, 73 struct gl_vertex_array_object **ptr, 74 struct gl_vertex_array_object *vao) 75{ 76 if (*ptr != vao) 77 _mesa_reference_vao_(ctx, ptr, vao); 78} 79 80 81extern void 82_mesa_initialize_vao(struct gl_context *ctx, 83 struct gl_vertex_array_object *obj, GLuint name); 84 85 86extern void 87_mesa_update_vao_derived_arrays(struct gl_context *ctx, 88 struct gl_vertex_array_object *vao); 89 90 91/** 92 * Mark the vao as shared and immutable, do remaining updates. 93 */ 94extern void 95_mesa_set_vao_immutable(struct gl_context *ctx, 96 struct gl_vertex_array_object *vao); 97 98 99/* Returns true if all varying arrays reside in vbos */ 100extern bool 101_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao); 102 103/* Returns true if all vbos are unmapped */ 104extern bool 105_mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao); 106 107 108extern void 109_mesa_vao_map_arrays(struct gl_context *ctx, struct gl_vertex_array_object *vao, 110 GLbitfield access); 111 112extern void 113_mesa_vao_map(struct gl_context *ctx, struct gl_vertex_array_object *vao, 114 GLbitfield access); 115 116 117extern void 118_mesa_vao_unmap_arrays(struct gl_context *ctx, 119 struct gl_vertex_array_object *vao); 120 121extern void 122_mesa_vao_unmap(struct gl_context *ctx, 123 struct gl_vertex_array_object *vao); 124 125 126/** 127 * Array to apply the position/generic0 aliasing map to 128 * an attribute value used in vertex processing inputs to an attribute 129 * as they appear in the vao. 130 */ 131extern const GLubyte 132_mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX]; 133 134 135/** 136 * Apply the position/generic0 aliasing map to a bitfield from the vao. 137 * Use for example to convert gl_vertex_array_object::Enabled 138 * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to 139 * the numbering used with vertex processing inputs. 140 */ 141static inline GLbitfield 142_mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled) 143{ 144 switch (mode) { 145 case ATTRIBUTE_MAP_MODE_IDENTITY: 146 return enabled; 147 case ATTRIBUTE_MAP_MODE_POSITION: 148 /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */ 149 return (enabled & ~VERT_BIT_GENERIC0) 150 | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0); 151 case ATTRIBUTE_MAP_MODE_GENERIC0: 152 /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */ 153 return (enabled & ~VERT_BIT_POS) 154 | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0); 155 default: 156 return 0; 157 } 158} 159 160 161/** 162 * Helper functions for consuming backends to walk the 163 * ctx->Array._DrawVAO for driver side array setup. 164 * Note that mesa provides preprocessed minimal binding information 165 * in the VAO. See _mesa_update_vao_derived_arrays for documentation. 166 */ 167 168/** 169 * Return enabled vertex attribute bits for draw. 170 */ 171static inline GLbitfield 172_mesa_draw_array_bits(const struct gl_context *ctx) 173{ 174 return ctx->Array._DrawVAOEnabledAttribs; 175} 176 177 178/** 179 * Return enabled buffer object vertex attribute bits for draw. 180 * 181 * Needs the a fully updated VAO ready for draw. 182 */ 183static inline GLbitfield 184_mesa_draw_vbo_array_bits(const struct gl_context *ctx) 185{ 186 const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO; 187 assert(vao->NewArrays == 0); 188 return vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs; 189} 190 191 192/** 193 * Return enabled user space vertex attribute bits for draw. 194 * 195 * Needs the a fully updated VAO ready for draw. 196 */ 197static inline GLbitfield 198_mesa_draw_user_array_bits(const struct gl_context *ctx) 199{ 200 const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO; 201 assert(vao->NewArrays == 0); 202 return ~vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs; 203} 204 205 206/** 207 * Return which enabled vertex attributes have a non-zero instance divisor. 208 * 209 * Needs the a fully updated VAO ready for draw. 210 */ 211static inline GLbitfield 212_mesa_draw_nonzero_divisor_bits(const struct gl_context *ctx) 213{ 214 const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO; 215 assert(vao->NewArrays == 0); 216 return vao->_EffEnabledNonZeroDivisor & ctx->Array._DrawVAOEnabledAttribs; 217} 218 219 220/** 221 * Return enabled current values attribute bits for draw. 222 */ 223static inline GLbitfield 224_mesa_draw_current_bits(const struct gl_context *ctx) 225{ 226 return ~ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_ALL; 227} 228 229 230/** 231 * Return vertex buffer binding provided the attribute struct. 232 * 233 * Needs the a fully updated VAO ready for draw. 234 */ 235static inline const struct gl_vertex_buffer_binding* 236_mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object *vao, 237 const struct gl_array_attributes *attrib) 238{ 239 assert(vao->NewArrays == 0); 240 return &vao->BufferBinding[attrib->_EffBufferBindingIndex]; 241} 242 243 244/** 245 * Return vertex array attribute provided the attribute number. 246 */ 247static inline const struct gl_array_attributes* 248_mesa_draw_array_attrib(const struct gl_vertex_array_object *vao, 249 gl_vert_attrib attr) 250{ 251 assert(vao->NewArrays == 0); 252 const gl_attribute_map_mode map_mode = vao->_AttributeMapMode; 253 return &vao->VertexAttrib[_mesa_vao_attribute_map[map_mode][attr]]; 254} 255 256 257/** 258 * Return a vertex array vertex format provided the attribute number. 259 */ 260static inline const struct gl_vertex_format * 261_mesa_draw_array_format(const struct gl_vertex_array_object *vao, 262 gl_vert_attrib attr) 263{ 264 return &_mesa_draw_array_attrib(vao, attr)->Format; 265} 266 267 268/** 269 * Return vertex buffer binding provided an attribute number. 270 */ 271static inline const struct gl_vertex_buffer_binding* 272_mesa_draw_buffer_binding(const struct gl_vertex_array_object *vao, 273 gl_vert_attrib attr) 274{ 275 const struct gl_array_attributes *const attrib 276 = _mesa_draw_array_attrib(vao, attr); 277 return _mesa_draw_buffer_binding_from_attrib(vao, attrib); 278} 279 280 281/** 282 * Return vertex attribute bits bound at the provided binding. 283 * 284 * Needs the a fully updated VAO ready for draw. 285 */ 286static inline GLbitfield 287_mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding *binding) 288{ 289 return binding->_EffBoundArrays; 290} 291 292 293/** 294 * Return the vertex offset bound at the provided binding. 295 * 296 * Needs the a fully updated VAO ready for draw. 297 */ 298static inline GLintptr 299_mesa_draw_binding_offset(const struct gl_vertex_buffer_binding *binding) 300{ 301 return binding->_EffOffset; 302} 303 304 305/** 306 * Return the relative offset of the provided attrib. 307 * 308 * Needs the a fully updated VAO ready for draw. 309 */ 310static inline GLushort 311_mesa_draw_attributes_relative_offset(const struct gl_array_attributes *attrib) 312{ 313 return attrib->_EffRelativeOffset; 314} 315 316 317/** 318 * Return a current value vertex array attribute provided the attribute number. 319 */ 320static inline const struct gl_array_attributes* 321_mesa_draw_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr) 322{ 323 return _vbo_current_attrib(ctx, attr); 324} 325 326 327/** 328 * Return a current value vertex format provided the attribute number. 329 */ 330static inline const struct gl_vertex_format * 331_mesa_draw_current_format(const struct gl_context *ctx, gl_vert_attrib attr) 332{ 333 return &_vbo_current_attrib(ctx, attr)->Format; 334} 335 336 337/** 338 * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled. 339 */ 340static inline bool 341_mesa_draw_edge_flag_array_enabled(const struct gl_context *ctx) 342{ 343 return ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_EDGEFLAG; 344} 345 346 347/* 348 * API functions 349 */ 350 351 352void GLAPIENTRY 353_mesa_BindVertexArray_no_error(GLuint id); 354 355void GLAPIENTRY _mesa_BindVertexArray( GLuint id ); 356 357void GLAPIENTRY 358_mesa_DeleteVertexArrays_no_error(GLsizei n, const GLuint *ids); 359 360void GLAPIENTRY _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids); 361 362void GLAPIENTRY 363_mesa_GenVertexArrays_no_error(GLsizei n, GLuint *arrays); 364 365void GLAPIENTRY _mesa_GenVertexArrays(GLsizei n, GLuint *arrays); 366 367void GLAPIENTRY 368_mesa_CreateVertexArrays_no_error(GLsizei n, GLuint *arrays); 369 370void GLAPIENTRY _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays); 371 372GLboolean GLAPIENTRY _mesa_IsVertexArray( GLuint id ); 373 374void GLAPIENTRY 375_mesa_VertexArrayElementBuffer_no_error(GLuint vaobj, GLuint buffer); 376 377void GLAPIENTRY _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer); 378 379void GLAPIENTRY _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param); 380 381#endif /* ARRAYOBJ_H */ 382