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 *
537ec681f3Smrg_mesa_lookup_vao_err(struct gl_context *ctx, GLuint id,
547ec681f3Smrg                     bool is_ext_dsa, const char *caller);
5501e04c3fSmrg
56af69d88dSmrgextern struct gl_vertex_array_object *
57af69d88dSmrg_mesa_new_vao(struct gl_context *ctx, GLuint name);
587117f1b4Smrg
597ec681f3Smrgextern void
607ec681f3Smrg_mesa_unbind_array_object_vbos(struct gl_context *ctx,
617ec681f3Smrg                               struct gl_vertex_array_object *obj);
627ec681f3Smrg
634a49301eSmrgextern void
64af69d88dSmrg_mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj);
657117f1b4Smrg
664a49301eSmrgextern void
67af69d88dSmrg_mesa_reference_vao_(struct gl_context *ctx,
68af69d88dSmrg                     struct gl_vertex_array_object **ptr,
69af69d88dSmrg                     struct gl_vertex_array_object *vao);
70af69d88dSmrg
71af69d88dSmrgstatic inline void
72af69d88dSmrg_mesa_reference_vao(struct gl_context *ctx,
73af69d88dSmrg                    struct gl_vertex_array_object **ptr,
74af69d88dSmrg                    struct gl_vertex_array_object *vao)
75af69d88dSmrg{
76af69d88dSmrg   if (*ptr != vao)
77af69d88dSmrg      _mesa_reference_vao_(ctx, ptr, vao);
78af69d88dSmrg}
79af69d88dSmrg
807117f1b4Smrg
814a49301eSmrgextern void
82af69d88dSmrg_mesa_initialize_vao(struct gl_context *ctx,
83af69d88dSmrg                     struct gl_vertex_array_object *obj, GLuint name);
847117f1b4Smrg
857117f1b4Smrg
864a49301eSmrgextern void
8701e04c3fSmrg_mesa_update_vao_derived_arrays(struct gl_context *ctx,
8801e04c3fSmrg                                struct gl_vertex_array_object *vao);
89af69d88dSmrg
9001e04c3fSmrg
9101e04c3fSmrg/**
9201e04c3fSmrg * Mark the vao as shared and immutable, do remaining updates.
9301e04c3fSmrg */
94af69d88dSmrgextern void
9501e04c3fSmrg_mesa_set_vao_immutable(struct gl_context *ctx,
9601e04c3fSmrg                        struct gl_vertex_array_object *vao);
9701e04c3fSmrg
9801e04c3fSmrg
9901e04c3fSmrg/* Returns true if all varying arrays reside in vbos */
10001e04c3fSmrgextern bool
10101e04c3fSmrg_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);
10201e04c3fSmrg
10301e04c3fSmrg/* Returns true if all vbos are unmapped */
10401e04c3fSmrgextern bool
10501e04c3fSmrg_mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
106af69d88dSmrg
107af69d88dSmrg
108a8bb7a65Smayaextern void
109a8bb7a65Smaya_mesa_vao_map_arrays(struct gl_context *ctx, struct gl_vertex_array_object *vao,
110a8bb7a65Smaya                     GLbitfield access);
111a8bb7a65Smaya
112a8bb7a65Smayaextern void
113a8bb7a65Smaya_mesa_vao_map(struct gl_context *ctx, struct gl_vertex_array_object *vao,
114a8bb7a65Smaya              GLbitfield access);
115a8bb7a65Smaya
116a8bb7a65Smaya
117a8bb7a65Smayaextern void
118a8bb7a65Smaya_mesa_vao_unmap_arrays(struct gl_context *ctx,
119a8bb7a65Smaya                       struct gl_vertex_array_object *vao);
120a8bb7a65Smaya
121a8bb7a65Smayaextern void
122a8bb7a65Smaya_mesa_vao_unmap(struct gl_context *ctx,
123a8bb7a65Smaya                struct gl_vertex_array_object *vao);
124a8bb7a65Smaya
125a8bb7a65Smaya
12601e04c3fSmrg/**
12701e04c3fSmrg * Array to apply the position/generic0 aliasing map to
12801e04c3fSmrg * an attribute value used in vertex processing inputs to an attribute
12901e04c3fSmrg * as they appear in the vao.
13001e04c3fSmrg */
13101e04c3fSmrgextern const GLubyte
13201e04c3fSmrg_mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX];
13301e04c3fSmrg
13401e04c3fSmrg
13501e04c3fSmrg/**
13601e04c3fSmrg * Apply the position/generic0 aliasing map to a bitfield from the vao.
137a8bb7a65Smaya * Use for example to convert gl_vertex_array_object::Enabled
13801e04c3fSmrg * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
13901e04c3fSmrg * the numbering used with vertex processing inputs.
14001e04c3fSmrg */
14101e04c3fSmrgstatic inline GLbitfield
14201e04c3fSmrg_mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled)
14301e04c3fSmrg{
14401e04c3fSmrg   switch (mode) {
14501e04c3fSmrg   case ATTRIBUTE_MAP_MODE_IDENTITY:
14601e04c3fSmrg      return enabled;
14701e04c3fSmrg   case ATTRIBUTE_MAP_MODE_POSITION:
14801e04c3fSmrg      /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */
14901e04c3fSmrg      return (enabled & ~VERT_BIT_GENERIC0)
15001e04c3fSmrg         | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0);
15101e04c3fSmrg   case ATTRIBUTE_MAP_MODE_GENERIC0:
15201e04c3fSmrg      /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */
15301e04c3fSmrg      return (enabled & ~VERT_BIT_POS)
15401e04c3fSmrg         | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0);
15501e04c3fSmrg   default:
15601e04c3fSmrg      return 0;
15701e04c3fSmrg   }
15801e04c3fSmrg}
15901e04c3fSmrg
16001e04c3fSmrg
16101e04c3fSmrg/**
16201e04c3fSmrg * Helper functions for consuming backends to walk the
16301e04c3fSmrg * ctx->Array._DrawVAO for driver side array setup.
16401e04c3fSmrg * Note that mesa provides preprocessed minimal binding information
16501e04c3fSmrg * in the VAO. See _mesa_update_vao_derived_arrays for documentation.
16601e04c3fSmrg */
16701e04c3fSmrg
16801e04c3fSmrg/**
16901e04c3fSmrg * Return enabled vertex attribute bits for draw.
17001e04c3fSmrg */
17101e04c3fSmrgstatic inline GLbitfield
17201e04c3fSmrg_mesa_draw_array_bits(const struct gl_context *ctx)
17301e04c3fSmrg{
17401e04c3fSmrg   return ctx->Array._DrawVAOEnabledAttribs;
17501e04c3fSmrg}
17601e04c3fSmrg
17701e04c3fSmrg
17801e04c3fSmrg/**
17901e04c3fSmrg * Return enabled buffer object vertex attribute bits for draw.
18001e04c3fSmrg *
18101e04c3fSmrg * Needs the a fully updated VAO ready for draw.
18201e04c3fSmrg */
18301e04c3fSmrgstatic inline GLbitfield
18401e04c3fSmrg_mesa_draw_vbo_array_bits(const struct gl_context *ctx)
18501e04c3fSmrg{
18601e04c3fSmrg   const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
18701e04c3fSmrg   assert(vao->NewArrays == 0);
18801e04c3fSmrg   return vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs;
18901e04c3fSmrg}
19001e04c3fSmrg
19101e04c3fSmrg
19201e04c3fSmrg/**
19301e04c3fSmrg * Return enabled user space vertex attribute bits for draw.
194af69d88dSmrg *
19501e04c3fSmrg * Needs the a fully updated VAO ready for draw.
19601e04c3fSmrg */
19701e04c3fSmrgstatic inline GLbitfield
19801e04c3fSmrg_mesa_draw_user_array_bits(const struct gl_context *ctx)
19901e04c3fSmrg{
20001e04c3fSmrg   const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
20101e04c3fSmrg   assert(vao->NewArrays == 0);
20201e04c3fSmrg   return ~vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs;
20301e04c3fSmrg}
20401e04c3fSmrg
20501e04c3fSmrg
2067ec681f3Smrg/**
2077ec681f3Smrg * Return which enabled vertex attributes have a non-zero instance divisor.
2087ec681f3Smrg *
2097ec681f3Smrg * Needs the a fully updated VAO ready for draw.
2107ec681f3Smrg */
2117ec681f3Smrgstatic inline GLbitfield
2127ec681f3Smrg_mesa_draw_nonzero_divisor_bits(const struct gl_context *ctx)
2137ec681f3Smrg{
2147ec681f3Smrg   const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
2157ec681f3Smrg   assert(vao->NewArrays == 0);
2167ec681f3Smrg   return vao->_EffEnabledNonZeroDivisor & ctx->Array._DrawVAOEnabledAttribs;
2177ec681f3Smrg}
2187ec681f3Smrg
2197ec681f3Smrg
22001e04c3fSmrg/**
22101e04c3fSmrg * Return enabled current values attribute bits for draw.
222af69d88dSmrg */
22301e04c3fSmrgstatic inline GLbitfield
22401e04c3fSmrg_mesa_draw_current_bits(const struct gl_context *ctx)
225af69d88dSmrg{
22601e04c3fSmrg   return ~ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_ALL;
227af69d88dSmrg}
228af69d88dSmrg
22901e04c3fSmrg
23001e04c3fSmrg/**
23101e04c3fSmrg * Return vertex buffer binding provided the attribute struct.
232af69d88dSmrg *
23301e04c3fSmrg * Needs the a fully updated VAO ready for draw.
23401e04c3fSmrg */
23501e04c3fSmrgstatic inline const struct gl_vertex_buffer_binding*
23601e04c3fSmrg_mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object *vao,
23701e04c3fSmrg                                      const struct gl_array_attributes *attrib)
23801e04c3fSmrg{
23901e04c3fSmrg   assert(vao->NewArrays == 0);
24001e04c3fSmrg   return &vao->BufferBinding[attrib->_EffBufferBindingIndex];
24101e04c3fSmrg}
24201e04c3fSmrg
24301e04c3fSmrg
24401e04c3fSmrg/**
24501e04c3fSmrg * Return vertex array attribute provided the attribute number.
246af69d88dSmrg */
24701e04c3fSmrgstatic inline const struct gl_array_attributes*
24801e04c3fSmrg_mesa_draw_array_attrib(const struct gl_vertex_array_object *vao,
24901e04c3fSmrg                        gl_vert_attrib attr)
250af69d88dSmrg{
25101e04c3fSmrg   assert(vao->NewArrays == 0);
25201e04c3fSmrg   const gl_attribute_map_mode map_mode = vao->_AttributeMapMode;
25301e04c3fSmrg   return &vao->VertexAttrib[_mesa_vao_attribute_map[map_mode][attr]];
25401e04c3fSmrg}
25501e04c3fSmrg
25601e04c3fSmrg
2577ec681f3Smrg/**
2587ec681f3Smrg * Return a vertex array vertex format provided the attribute number.
2597ec681f3Smrg */
2607ec681f3Smrgstatic inline const struct gl_vertex_format *
2617ec681f3Smrg_mesa_draw_array_format(const struct gl_vertex_array_object *vao,
2627ec681f3Smrg                        gl_vert_attrib attr)
2637ec681f3Smrg{
2647ec681f3Smrg   return &_mesa_draw_array_attrib(vao, attr)->Format;
2657ec681f3Smrg}
2667ec681f3Smrg
2677ec681f3Smrg
26801e04c3fSmrg/**
26901e04c3fSmrg * Return vertex buffer binding provided an attribute number.
27001e04c3fSmrg */
27101e04c3fSmrgstatic inline const struct gl_vertex_buffer_binding*
27201e04c3fSmrg_mesa_draw_buffer_binding(const struct gl_vertex_array_object *vao,
27301e04c3fSmrg                          gl_vert_attrib attr)
27401e04c3fSmrg{
27501e04c3fSmrg   const struct gl_array_attributes *const attrib
27601e04c3fSmrg      = _mesa_draw_array_attrib(vao, attr);
27701e04c3fSmrg   return _mesa_draw_buffer_binding_from_attrib(vao, attrib);
27801e04c3fSmrg}
27901e04c3fSmrg
28001e04c3fSmrg
28101e04c3fSmrg/**
28201e04c3fSmrg * Return vertex attribute bits bound at the provided binding.
28301e04c3fSmrg *
28401e04c3fSmrg * Needs the a fully updated VAO ready for draw.
28501e04c3fSmrg */
28601e04c3fSmrgstatic inline GLbitfield
28701e04c3fSmrg_mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding *binding)
28801e04c3fSmrg{
28901e04c3fSmrg   return binding->_EffBoundArrays;
29001e04c3fSmrg}
29101e04c3fSmrg
29201e04c3fSmrg
29301e04c3fSmrg/**
29401e04c3fSmrg * Return the vertex offset bound at the provided binding.
29501e04c3fSmrg *
29601e04c3fSmrg * Needs the a fully updated VAO ready for draw.
29701e04c3fSmrg */
29801e04c3fSmrgstatic inline GLintptr
29901e04c3fSmrg_mesa_draw_binding_offset(const struct gl_vertex_buffer_binding *binding)
30001e04c3fSmrg{
30101e04c3fSmrg   return binding->_EffOffset;
30201e04c3fSmrg}
30301e04c3fSmrg
30401e04c3fSmrg
30501e04c3fSmrg/**
30601e04c3fSmrg * Return the relative offset of the provided attrib.
30701e04c3fSmrg *
30801e04c3fSmrg * Needs the a fully updated VAO ready for draw.
30901e04c3fSmrg */
31001e04c3fSmrgstatic inline GLushort
31101e04c3fSmrg_mesa_draw_attributes_relative_offset(const struct gl_array_attributes *attrib)
31201e04c3fSmrg{
31301e04c3fSmrg   return attrib->_EffRelativeOffset;
31401e04c3fSmrg}
31501e04c3fSmrg
31601e04c3fSmrg
31701e04c3fSmrg/**
31801e04c3fSmrg * Return a current value vertex array attribute provided the attribute number.
31901e04c3fSmrg */
32001e04c3fSmrgstatic inline const struct gl_array_attributes*
32101e04c3fSmrg_mesa_draw_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr)
32201e04c3fSmrg{
32301e04c3fSmrg   return _vbo_current_attrib(ctx, attr);
32401e04c3fSmrg}
32501e04c3fSmrg
32601e04c3fSmrg
32701e04c3fSmrg/**
3287ec681f3Smrg * Return a current value vertex format provided the attribute number.
32901e04c3fSmrg */
3307ec681f3Smrgstatic inline const struct gl_vertex_format *
3317ec681f3Smrg_mesa_draw_current_format(const struct gl_context *ctx, gl_vert_attrib attr)
33201e04c3fSmrg{
3337ec681f3Smrg   return &_vbo_current_attrib(ctx, attr)->Format;
33401e04c3fSmrg}
33501e04c3fSmrg
33601e04c3fSmrg
33701e04c3fSmrg/**
3387ec681f3Smrg * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled.
33901e04c3fSmrg */
3407ec681f3Smrgstatic inline bool
3417ec681f3Smrg_mesa_draw_edge_flag_array_enabled(const struct gl_context *ctx)
34201e04c3fSmrg{
3437ec681f3Smrg   return ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_EDGEFLAG;
344af69d88dSmrg}
3457117f1b4Smrg
3467117f1b4Smrg
3477117f1b4Smrg/*
3487117f1b4Smrg * API functions
3497117f1b4Smrg */
3507117f1b4Smrg
3514a49301eSmrg
35201e04c3fSmrgvoid GLAPIENTRY
35301e04c3fSmrg_mesa_BindVertexArray_no_error(GLuint id);
35401e04c3fSmrg
3554a49301eSmrgvoid GLAPIENTRY _mesa_BindVertexArray( GLuint id );
3564a49301eSmrg
35701e04c3fSmrgvoid GLAPIENTRY
35801e04c3fSmrg_mesa_DeleteVertexArrays_no_error(GLsizei n, const GLuint *ids);
3597117f1b4Smrg
360af69d88dSmrgvoid GLAPIENTRY _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids);
3617117f1b4Smrg
36201e04c3fSmrgvoid GLAPIENTRY
36301e04c3fSmrg_mesa_GenVertexArrays_no_error(GLsizei n, GLuint *arrays);
36401e04c3fSmrg
3654a49301eSmrgvoid GLAPIENTRY _mesa_GenVertexArrays(GLsizei n, GLuint *arrays);
3664a49301eSmrg
36701e04c3fSmrgvoid GLAPIENTRY
36801e04c3fSmrg_mesa_CreateVertexArrays_no_error(GLsizei n, GLuint *arrays);
36901e04c3fSmrg
37001e04c3fSmrgvoid GLAPIENTRY _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays);
3717117f1b4Smrg
372af69d88dSmrgGLboolean GLAPIENTRY _mesa_IsVertexArray( GLuint id );
3737117f1b4Smrg
37401e04c3fSmrgvoid GLAPIENTRY
37501e04c3fSmrg_mesa_VertexArrayElementBuffer_no_error(GLuint vaobj, GLuint buffer);
37601e04c3fSmrg
37701e04c3fSmrgvoid GLAPIENTRY _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer);
37801e04c3fSmrg
37901e04c3fSmrgvoid GLAPIENTRY _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param);
38001e04c3fSmrg
3817117f1b4Smrg#endif /* ARRAYOBJ_H */
382