arrayobj.h revision 01e04c3f
17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * 47117f1b4Smrg * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 57117f1b4Smrg * (C) Copyright IBM Corporation 2006 64a49301eSmrg * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 77117f1b4Smrg * 87117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 97117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 107117f1b4Smrg * to deal in the Software without restriction, including without limitation 117117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 127117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 137117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 147117f1b4Smrg * 157117f1b4Smrg * The above copyright notice and this permission notice shall be included 167117f1b4Smrg * in all copies or substantial portions of the Software. 177117f1b4Smrg * 187117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 197117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 207117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 22af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 257117f1b4Smrg */ 267117f1b4Smrg 277117f1b4Smrg#ifndef ARRAYOBJ_H 287117f1b4Smrg#define ARRAYOBJ_H 297117f1b4Smrg 303464ebd5Sriastradh#include "glheader.h" 31af69d88dSmrg#include "mtypes.h" 32af69d88dSmrg#include "glformats.h" 3301e04c3fSmrg#include "vbo/vbo.h" 343464ebd5Sriastradh 353464ebd5Sriastradhstruct gl_context; 367117f1b4Smrg 377117f1b4Smrg/** 387117f1b4Smrg * \file arrayobj.h 3901e04c3fSmrg * Functions for the GL_ARB_vertex_array_object extension. 407117f1b4Smrg * 417117f1b4Smrg * \author Ian Romanick <idr@us.ibm.com> 427117f1b4Smrg * \author Brian Paul 437117f1b4Smrg */ 447117f1b4Smrg 457117f1b4Smrg/* 467117f1b4Smrg * Internal functions 477117f1b4Smrg */ 487117f1b4Smrg 49af69d88dSmrgextern struct gl_vertex_array_object * 50af69d88dSmrg_mesa_lookup_vao(struct gl_context *ctx, GLuint id); 51af69d88dSmrg 5201e04c3fSmrgextern struct gl_vertex_array_object * 5301e04c3fSmrg_mesa_lookup_vao_err(struct gl_context *ctx, GLuint id, const char *caller); 5401e04c3fSmrg 55af69d88dSmrgextern struct gl_vertex_array_object * 56af69d88dSmrg_mesa_new_vao(struct gl_context *ctx, GLuint name); 577117f1b4Smrg 584a49301eSmrgextern void 59af69d88dSmrg_mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj); 607117f1b4Smrg 614a49301eSmrgextern void 62af69d88dSmrg_mesa_reference_vao_(struct gl_context *ctx, 63af69d88dSmrg struct gl_vertex_array_object **ptr, 64af69d88dSmrg struct gl_vertex_array_object *vao); 65af69d88dSmrg 66af69d88dSmrgstatic inline void 67af69d88dSmrg_mesa_reference_vao(struct gl_context *ctx, 68af69d88dSmrg struct gl_vertex_array_object **ptr, 69af69d88dSmrg struct gl_vertex_array_object *vao) 70af69d88dSmrg{ 71af69d88dSmrg if (*ptr != vao) 72af69d88dSmrg _mesa_reference_vao_(ctx, ptr, vao); 73af69d88dSmrg} 74af69d88dSmrg 757117f1b4Smrg 764a49301eSmrgextern void 77af69d88dSmrg_mesa_initialize_vao(struct gl_context *ctx, 78af69d88dSmrg struct gl_vertex_array_object *obj, GLuint name); 797117f1b4Smrg 807117f1b4Smrg 814a49301eSmrgextern void 8201e04c3fSmrg_mesa_update_vao_derived_arrays(struct gl_context *ctx, 8301e04c3fSmrg struct gl_vertex_array_object *vao); 84af69d88dSmrg 8501e04c3fSmrg 8601e04c3fSmrg/** 8701e04c3fSmrg * Mark the vao as shared and immutable, do remaining updates. 8801e04c3fSmrg */ 89af69d88dSmrgextern void 9001e04c3fSmrg_mesa_set_vao_immutable(struct gl_context *ctx, 9101e04c3fSmrg struct gl_vertex_array_object *vao); 9201e04c3fSmrg 9301e04c3fSmrg 9401e04c3fSmrg/* Returns true if all varying arrays reside in vbos */ 9501e04c3fSmrgextern bool 9601e04c3fSmrg_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao); 9701e04c3fSmrg 9801e04c3fSmrg/* Returns true if all vbos are unmapped */ 9901e04c3fSmrgextern bool 10001e04c3fSmrg_mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao); 101af69d88dSmrg 102af69d88dSmrg 10301e04c3fSmrg/** 10401e04c3fSmrg * Array to apply the position/generic0 aliasing map to 10501e04c3fSmrg * an attribute value used in vertex processing inputs to an attribute 10601e04c3fSmrg * as they appear in the vao. 10701e04c3fSmrg */ 10801e04c3fSmrgextern const GLubyte 10901e04c3fSmrg_mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX]; 11001e04c3fSmrg 11101e04c3fSmrg 11201e04c3fSmrg/** 11301e04c3fSmrg * Apply the position/generic0 aliasing map to a bitfield from the vao. 11401e04c3fSmrg * Use for example to convert gl_vertex_array_object::_Enabled 11501e04c3fSmrg * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to 11601e04c3fSmrg * the numbering used with vertex processing inputs. 11701e04c3fSmrg */ 11801e04c3fSmrgstatic inline GLbitfield 11901e04c3fSmrg_mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled) 12001e04c3fSmrg{ 12101e04c3fSmrg switch (mode) { 12201e04c3fSmrg case ATTRIBUTE_MAP_MODE_IDENTITY: 12301e04c3fSmrg return enabled; 12401e04c3fSmrg case ATTRIBUTE_MAP_MODE_POSITION: 12501e04c3fSmrg /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */ 12601e04c3fSmrg return (enabled & ~VERT_BIT_GENERIC0) 12701e04c3fSmrg | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0); 12801e04c3fSmrg case ATTRIBUTE_MAP_MODE_GENERIC0: 12901e04c3fSmrg /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */ 13001e04c3fSmrg return (enabled & ~VERT_BIT_POS) 13101e04c3fSmrg | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0); 13201e04c3fSmrg default: 13301e04c3fSmrg return 0; 13401e04c3fSmrg } 13501e04c3fSmrg} 13601e04c3fSmrg 13701e04c3fSmrg 13801e04c3fSmrg/** 13901e04c3fSmrg * Return the vp_inputs enabled bitmask after application of 14001e04c3fSmrg * the position/generic0 aliasing map. 14101e04c3fSmrg */ 14201e04c3fSmrgstatic inline GLbitfield 14301e04c3fSmrg_mesa_get_vao_vp_inputs(const struct gl_vertex_array_object *vao) 14401e04c3fSmrg{ 14501e04c3fSmrg const gl_attribute_map_mode mode = vao->_AttributeMapMode; 14601e04c3fSmrg return _mesa_vao_enable_to_vp_inputs(mode, vao->_Enabled); 14701e04c3fSmrg} 14801e04c3fSmrg 14901e04c3fSmrg 15001e04c3fSmrg/** 15101e04c3fSmrg * Helper functions for consuming backends to walk the 15201e04c3fSmrg * ctx->Array._DrawVAO for driver side array setup. 15301e04c3fSmrg * Note that mesa provides preprocessed minimal binding information 15401e04c3fSmrg * in the VAO. See _mesa_update_vao_derived_arrays for documentation. 15501e04c3fSmrg */ 15601e04c3fSmrg 15701e04c3fSmrg/** 15801e04c3fSmrg * Return enabled vertex attribute bits for draw. 15901e04c3fSmrg */ 16001e04c3fSmrgstatic inline GLbitfield 16101e04c3fSmrg_mesa_draw_array_bits(const struct gl_context *ctx) 16201e04c3fSmrg{ 16301e04c3fSmrg return ctx->Array._DrawVAOEnabledAttribs; 16401e04c3fSmrg} 16501e04c3fSmrg 16601e04c3fSmrg 16701e04c3fSmrg/** 16801e04c3fSmrg * Return enabled buffer object vertex attribute bits for draw. 16901e04c3fSmrg * 17001e04c3fSmrg * Needs the a fully updated VAO ready for draw. 17101e04c3fSmrg */ 17201e04c3fSmrgstatic inline GLbitfield 17301e04c3fSmrg_mesa_draw_vbo_array_bits(const struct gl_context *ctx) 17401e04c3fSmrg{ 17501e04c3fSmrg const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO; 17601e04c3fSmrg assert(vao->NewArrays == 0); 17701e04c3fSmrg return vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs; 17801e04c3fSmrg} 17901e04c3fSmrg 18001e04c3fSmrg 18101e04c3fSmrg/** 18201e04c3fSmrg * Return enabled user space vertex attribute bits for draw. 183af69d88dSmrg * 18401e04c3fSmrg * Needs the a fully updated VAO ready for draw. 18501e04c3fSmrg */ 18601e04c3fSmrgstatic inline GLbitfield 18701e04c3fSmrg_mesa_draw_user_array_bits(const struct gl_context *ctx) 18801e04c3fSmrg{ 18901e04c3fSmrg const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO; 19001e04c3fSmrg assert(vao->NewArrays == 0); 19101e04c3fSmrg return ~vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs; 19201e04c3fSmrg} 19301e04c3fSmrg 19401e04c3fSmrg 19501e04c3fSmrg/** 19601e04c3fSmrg * Return enabled current values attribute bits for draw. 197af69d88dSmrg */ 19801e04c3fSmrgstatic inline GLbitfield 19901e04c3fSmrg_mesa_draw_current_bits(const struct gl_context *ctx) 200af69d88dSmrg{ 20101e04c3fSmrg return ~ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_ALL; 202af69d88dSmrg} 203af69d88dSmrg 20401e04c3fSmrg 20501e04c3fSmrg/** 20601e04c3fSmrg * Return vertex buffer binding provided the attribute struct. 207af69d88dSmrg * 20801e04c3fSmrg * Needs the a fully updated VAO ready for draw. 20901e04c3fSmrg */ 21001e04c3fSmrgstatic inline const struct gl_vertex_buffer_binding* 21101e04c3fSmrg_mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object *vao, 21201e04c3fSmrg const struct gl_array_attributes *attrib) 21301e04c3fSmrg{ 21401e04c3fSmrg assert(vao->NewArrays == 0); 21501e04c3fSmrg return &vao->BufferBinding[attrib->_EffBufferBindingIndex]; 21601e04c3fSmrg} 21701e04c3fSmrg 21801e04c3fSmrg 21901e04c3fSmrg/** 22001e04c3fSmrg * Return vertex array attribute provided the attribute number. 221af69d88dSmrg */ 22201e04c3fSmrgstatic inline const struct gl_array_attributes* 22301e04c3fSmrg_mesa_draw_array_attrib(const struct gl_vertex_array_object *vao, 22401e04c3fSmrg gl_vert_attrib attr) 225af69d88dSmrg{ 22601e04c3fSmrg assert(vao->NewArrays == 0); 22701e04c3fSmrg const gl_attribute_map_mode map_mode = vao->_AttributeMapMode; 22801e04c3fSmrg return &vao->VertexAttrib[_mesa_vao_attribute_map[map_mode][attr]]; 22901e04c3fSmrg} 23001e04c3fSmrg 23101e04c3fSmrg 23201e04c3fSmrg/** 23301e04c3fSmrg * Return vertex buffer binding provided an attribute number. 23401e04c3fSmrg */ 23501e04c3fSmrgstatic inline const struct gl_vertex_buffer_binding* 23601e04c3fSmrg_mesa_draw_buffer_binding(const struct gl_vertex_array_object *vao, 23701e04c3fSmrg gl_vert_attrib attr) 23801e04c3fSmrg{ 23901e04c3fSmrg const struct gl_array_attributes *const attrib 24001e04c3fSmrg = _mesa_draw_array_attrib(vao, attr); 24101e04c3fSmrg return _mesa_draw_buffer_binding_from_attrib(vao, attrib); 24201e04c3fSmrg} 24301e04c3fSmrg 24401e04c3fSmrg 24501e04c3fSmrg/** 24601e04c3fSmrg * Return vertex attribute bits bound at the provided binding. 24701e04c3fSmrg * 24801e04c3fSmrg * Needs the a fully updated VAO ready for draw. 24901e04c3fSmrg */ 25001e04c3fSmrgstatic inline GLbitfield 25101e04c3fSmrg_mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding *binding) 25201e04c3fSmrg{ 25301e04c3fSmrg return binding->_EffBoundArrays; 25401e04c3fSmrg} 25501e04c3fSmrg 25601e04c3fSmrg 25701e04c3fSmrg/** 25801e04c3fSmrg * Return the vertex offset bound at the provided binding. 25901e04c3fSmrg * 26001e04c3fSmrg * Needs the a fully updated VAO ready for draw. 26101e04c3fSmrg */ 26201e04c3fSmrgstatic inline GLintptr 26301e04c3fSmrg_mesa_draw_binding_offset(const struct gl_vertex_buffer_binding *binding) 26401e04c3fSmrg{ 26501e04c3fSmrg return binding->_EffOffset; 26601e04c3fSmrg} 26701e04c3fSmrg 26801e04c3fSmrg 26901e04c3fSmrg/** 27001e04c3fSmrg * Return the relative offset of the provided attrib. 27101e04c3fSmrg * 27201e04c3fSmrg * Needs the a fully updated VAO ready for draw. 27301e04c3fSmrg */ 27401e04c3fSmrgstatic inline GLushort 27501e04c3fSmrg_mesa_draw_attributes_relative_offset(const struct gl_array_attributes *attrib) 27601e04c3fSmrg{ 27701e04c3fSmrg return attrib->_EffRelativeOffset; 27801e04c3fSmrg} 27901e04c3fSmrg 28001e04c3fSmrg 28101e04c3fSmrg/** 28201e04c3fSmrg * Return a current value vertex array attribute provided the attribute number. 28301e04c3fSmrg */ 28401e04c3fSmrgstatic inline const struct gl_array_attributes* 28501e04c3fSmrg_mesa_draw_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr) 28601e04c3fSmrg{ 28701e04c3fSmrg return _vbo_current_attrib(ctx, attr); 28801e04c3fSmrg} 28901e04c3fSmrg 29001e04c3fSmrg 29101e04c3fSmrg/** 29201e04c3fSmrg * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled. 29301e04c3fSmrg */ 29401e04c3fSmrgstatic inline bool 29501e04c3fSmrg_mesa_draw_edge_flag_array_enabled(const struct gl_context *ctx) 29601e04c3fSmrg{ 29701e04c3fSmrg return ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_EDGEFLAG; 29801e04c3fSmrg} 29901e04c3fSmrg 30001e04c3fSmrg 30101e04c3fSmrg/** 30201e04c3fSmrg * Return the attrib for the given attribute. 30301e04c3fSmrg */ 30401e04c3fSmrgstatic inline const struct gl_array_attributes* 30501e04c3fSmrg_mesa_draw_attrib(const struct gl_context *ctx, gl_vert_attrib attr) 30601e04c3fSmrg{ 30701e04c3fSmrg if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) { 30801e04c3fSmrg const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO; 30901e04c3fSmrg return _mesa_draw_array_attrib(vao, attr); 31001e04c3fSmrg } else { 31101e04c3fSmrg return _vbo_current_attrib(ctx, attr); 31201e04c3fSmrg } 31301e04c3fSmrg} 31401e04c3fSmrg 31501e04c3fSmrg 31601e04c3fSmrg/** 31701e04c3fSmrg * Return the attrib, binding pair for the given attribute. 31801e04c3fSmrg */ 31901e04c3fSmrgstatic inline void 32001e04c3fSmrg_mesa_draw_attrib_and_binding(const struct gl_context *ctx, gl_vert_attrib attr, 32101e04c3fSmrg const struct gl_array_attributes **attrib, 32201e04c3fSmrg const struct gl_vertex_buffer_binding **binding) 32301e04c3fSmrg{ 32401e04c3fSmrg if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) { 32501e04c3fSmrg const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO; 32601e04c3fSmrg *attrib = _mesa_draw_array_attrib(vao, attr); 32701e04c3fSmrg *binding = _mesa_draw_buffer_binding_from_attrib(vao, *attrib); 32801e04c3fSmrg } else { 32901e04c3fSmrg *attrib = _vbo_current_attrib(ctx, attr); 33001e04c3fSmrg *binding = _vbo_current_binding(ctx); 33101e04c3fSmrg } 332af69d88dSmrg} 3337117f1b4Smrg 3347117f1b4Smrg 3357117f1b4Smrg/* 3367117f1b4Smrg * API functions 3377117f1b4Smrg */ 3387117f1b4Smrg 3394a49301eSmrg 34001e04c3fSmrgvoid GLAPIENTRY 34101e04c3fSmrg_mesa_BindVertexArray_no_error(GLuint id); 34201e04c3fSmrg 3434a49301eSmrgvoid GLAPIENTRY _mesa_BindVertexArray( GLuint id ); 3444a49301eSmrg 34501e04c3fSmrgvoid GLAPIENTRY 34601e04c3fSmrg_mesa_DeleteVertexArrays_no_error(GLsizei n, const GLuint *ids); 3477117f1b4Smrg 348af69d88dSmrgvoid GLAPIENTRY _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids); 3497117f1b4Smrg 35001e04c3fSmrgvoid GLAPIENTRY 35101e04c3fSmrg_mesa_GenVertexArrays_no_error(GLsizei n, GLuint *arrays); 35201e04c3fSmrg 3534a49301eSmrgvoid GLAPIENTRY _mesa_GenVertexArrays(GLsizei n, GLuint *arrays); 3544a49301eSmrg 35501e04c3fSmrgvoid GLAPIENTRY 35601e04c3fSmrg_mesa_CreateVertexArrays_no_error(GLsizei n, GLuint *arrays); 35701e04c3fSmrg 35801e04c3fSmrgvoid GLAPIENTRY _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays); 3597117f1b4Smrg 360af69d88dSmrgGLboolean GLAPIENTRY _mesa_IsVertexArray( GLuint id ); 3617117f1b4Smrg 36201e04c3fSmrgvoid GLAPIENTRY 36301e04c3fSmrg_mesa_VertexArrayElementBuffer_no_error(GLuint vaobj, GLuint buffer); 36401e04c3fSmrg 36501e04c3fSmrgvoid GLAPIENTRY _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer); 36601e04c3fSmrg 36701e04c3fSmrgvoid GLAPIENTRY _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param); 36801e04c3fSmrg 3697117f1b4Smrg#endif /* ARRAYOBJ_H */ 370